Symbol improve UBO (#1893)

This commit is contained in:
Alex Cristici
2023-11-28 08:16:11 +02:00
committed by GitHub
parent 178454bdba
commit db2e95a59b
16 changed files with 61 additions and 109 deletions

View File

@@ -23,19 +23,15 @@ layout (std140) uniform SymbolDrawableUBO {
highp vec2 u_texsize_icon;
highp float u_gamma_scale;
highp float u_device_pixel_ratio;
highp float u_camera_to_center_distance;
highp float u_pitch;
bool u_rotate_symbol;
highp float u_aspect_ratio;
highp vec2 u_pad1;
};
layout (std140) uniform SymbolDynamicUBO {
highp float u_fade_change;
highp float u_pad7;
highp vec2 u_pad8;
highp float u_camera_to_center_distance;
highp float u_device_pixel_ratio;
highp float u_aspect_ratio;
};
layout (std140) uniform SymbolDrawablePaintUBO {

View File

@@ -31,19 +31,15 @@ layout (std140) uniform SymbolDrawableUBO {
highp vec2 u_texsize_icon;
highp float u_gamma_scale;
highp float u_device_pixel_ratio;
highp float u_camera_to_center_distance;
highp float u_pitch;
bool u_rotate_symbol;
highp float u_aspect_ratio;
highp vec2 u_pad1;
};
layout (std140) uniform SymbolDynamicUBO {
highp float u_fade_change;
highp float u_pad7;
highp vec2 u_pad8;
highp float u_camera_to_center_distance;
highp float u_device_pixel_ratio;
highp float u_aspect_ratio;
};
layout (std140) uniform SymbolDrawablePaintUBO {
@@ -206,19 +202,15 @@ layout (std140) uniform SymbolDrawableUBO {
highp vec2 u_texsize_icon;
highp float u_gamma_scale;
highp float u_device_pixel_ratio;
highp float u_camera_to_center_distance;
highp float u_pitch;
bool u_rotate_symbol;
highp float u_aspect_ratio;
highp vec2 u_pad1;
};
layout (std140) uniform SymbolDynamicUBO {
highp float u_fade_change;
highp float u_pad7;
highp vec2 u_pad8;
highp float u_camera_to_center_distance;
highp float u_device_pixel_ratio;
highp float u_aspect_ratio;
};
layout (std140) uniform SymbolDrawablePaintUBO {

View File

@@ -30,19 +30,15 @@ layout (std140) uniform SymbolDrawableUBO {
highp vec2 u_texsize_icon;
highp float u_gamma_scale;
highp float u_device_pixel_ratio;
highp float u_camera_to_center_distance;
highp float u_pitch;
bool u_rotate_symbol;
highp float u_aspect_ratio;
highp vec2 u_pad1;
};
layout (std140) uniform SymbolDynamicUBO {
highp float u_fade_change;
highp float u_pad7;
highp vec2 u_pad8;
highp float u_camera_to_center_distance;
highp float u_device_pixel_ratio;
highp float u_aspect_ratio;
};
layout (std140) uniform SymbolDrawablePaintUBO {
@@ -209,19 +205,15 @@ layout (std140) uniform SymbolDrawableUBO {
highp vec2 u_texsize_icon;
highp float u_gamma_scale;
highp float u_device_pixel_ratio;
highp float u_camera_to_center_distance;
highp float u_pitch;
bool u_rotate_symbol;
highp float u_aspect_ratio;
highp vec2 u_pad1;
};
layout (std140) uniform SymbolDynamicUBO {
highp float u_fade_change;
highp float u_pad7;
highp vec2 u_pad8;
highp float u_camera_to_center_distance;
highp float u_device_pixel_ratio;
highp float u_aspect_ratio;
};
layout (std140) uniform SymbolDrawablePaintUBO {

View File

@@ -228,20 +228,16 @@ struct alignas(16) SymbolDrawableUBO {
float2 texsize_icon;
float gamma_scale;
float device_pixel_ratio;
float camera_to_center_distance;
float pitch;
/*bool*/ int rotate_symbol;
float aspect_ratio;
float2 pad;
};
static_assert(sizeof(SymbolDrawableUBO) == 15 * 16, "unexpected padding");
static_assert(sizeof(SymbolDrawableUBO) == 14 * 16, "unexpected padding");
struct alignas(16) SymbolDynamicUBO {
float fade_change;
float pad1;
float2 pad2;
float camera_to_center_distance;
float device_pixel_ratio;
float aspect_ratio;
};
static_assert(sizeof(SymbolDynamicUBO) == 16, "unexpected padding");

View File

@@ -71,8 +71,8 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
const float camera_to_anchor_distance = projectedPoint.w;
// See comments in symbol_sdf.vertex
const float distance_ratio = props.pitch_with_map ?
camera_to_anchor_distance / drawable.camera_to_center_distance :
drawable.camera_to_center_distance / camera_to_anchor_distance;
camera_to_anchor_distance / dynamic.camera_to_center_distance :
dynamic.camera_to_center_distance / camera_to_anchor_distance;
const float perspective_ratio = clamp(
0.5 + 0.5 * distance_ratio,
0.0, // Prevents oversized near-field symbols in pitched/overzoomed tiles
@@ -89,7 +89,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
const float2 a = projectedPoint.xy / projectedPoint.w;
const float2 b = offsetProjectedPoint.xy / offsetProjectedPoint.w;
symbol_rotation = atan2((b.y - a.y) / drawable.aspect_ratio, b.x - a.x);
symbol_rotation = atan2((b.y - a.y) / dynamic.aspect_ratio, b.x - a.x);
}
const float angle_sin = sin(segment_angle + symbol_rotation);

View File

@@ -88,8 +88,8 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
// which makes labels in the distance larger relative to the features around
// them. We counteract part of that effect by dividing by the perspective ratio.
const float distance_ratio = props.pitch_with_map ?
camera_to_anchor_distance / drawable.camera_to_center_distance :
drawable.camera_to_center_distance / camera_to_anchor_distance;
camera_to_anchor_distance / dynamic.camera_to_center_distance :
dynamic.camera_to_center_distance / camera_to_anchor_distance;
const float perspective_ratio = clamp(
0.5 + 0.5 * distance_ratio,
0.0, // Prevents oversized near-field symbols in pitched/overzoomed tiles
@@ -109,7 +109,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
const float2 a = projectedPoint.xy / projectedPoint.w;
const float2 b = offsetProjectedPoint.xy / offsetProjectedPoint.w;
symbol_rotation = atan2((b.y - a.y) / drawable.aspect_ratio, b.x - a.x);
symbol_rotation = atan2((b.y - a.y) / dynamic.aspect_ratio, b.x - a.x);
}
const float angle_sin = sin(segment_angle + symbol_rotation);
@@ -140,6 +140,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
half4 fragment fragmentMain(FragmentStage in [[stage_in]],
device const SymbolDrawableUBO& drawable [[buffer(10)]],
device const SymbolDynamicUBO& dynamic [[buffer(11)]],
device const SymbolDrawableTilePropsUBO& props [[buffer(13)]],
device const SymbolPermutationUBO& permutation [[buffer(15)]],
texture2d<float, access::sample> image [[texture(0)]],
@@ -148,7 +149,7 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]],
return half4(1.0);
}
const float EDGE_GAMMA = 0.105 / drawable.device_pixel_ratio;
const float EDGE_GAMMA = 0.105 / dynamic.device_pixel_ratio;
const float2 tex = in.data0.xy;
const float gamma_scale = in.data1.x;

View File

@@ -90,8 +90,8 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
// which makes labels in the distance larger relative to the features around
// them. We counteract part of that effect by dividing by the perspective ratio.
const float distance_ratio = props.pitch_with_map ?
camera_to_anchor_distance / drawable.camera_to_center_distance :
drawable.camera_to_center_distance / camera_to_anchor_distance;
camera_to_anchor_distance / dynamic.camera_to_center_distance :
dynamic.camera_to_center_distance / camera_to_anchor_distance;
const float perspective_ratio = clamp(
0.5 + 0.5 * distance_ratio,
0.0, // Prevents oversized near-field symbols in pitched/overzoomed tiles
@@ -111,7 +111,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
const float2 a = projectedPoint.xy / projectedPoint.w;
const float2 b = offsetProjectedPoint.xy / offsetProjectedPoint.w;
symbol_rotation = atan2((b.y - a.y) / drawable.aspect_ratio, b.x - a.x);
symbol_rotation = atan2((b.y - a.y) / dynamic.aspect_ratio, b.x - a.x);
}
const float angle_sin = sin(segment_angle + symbol_rotation);
@@ -142,6 +142,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
half4 fragment fragmentMain(FragmentStage in [[stage_in]],
device const SymbolDrawableUBO& drawable [[buffer(9)]],
device const SymbolDynamicUBO& dynamic [[buffer(10)]],
device const SymbolDrawableTilePropsUBO& props [[buffer(12)]],
device const SymbolPermutationUBO& permutation [[buffer(14)]],
texture2d<float, access::sample> glyph_image [[texture(0)]],
@@ -161,7 +162,7 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]],
}
const float2 tex = in.data0.xy;
const float EDGE_GAMMA = 0.105 / drawable.device_pixel_ratio;
const float EDGE_GAMMA = 0.105 / dynamic.device_pixel_ratio;
const float gamma_scale = in.data1.x;
const float size = in.data1.y;

View File

@@ -40,22 +40,19 @@ struct alignas(16) SymbolDrawableUBO {
/* 200 */ std::array<float, 2> texsize_icon;
/* 208 */ float gamma_scale;
/* 212 */ float device_pixel_ratio;
/* 212 */ /*bool*/ int rotate_symbol;
/* 216 */ float camera_to_center_distance;
/* 220 */ float pitch;
/* 224 */ /*bool*/ int rotate_symbol;
/* 228 */ float aspect_ratio;
/* 232 */ std::array<float, 2> pad;
/* 240 */
/* 216 */ std::array<float, 2> pad;
/* 224 */
};
static_assert(sizeof(SymbolDrawableUBO) == 15 * 16);
static_assert(sizeof(SymbolDrawableUBO) == 14 * 16);
/// Dynamic UBO
struct alignas(16) SymbolDynamicUBO {
/* 0 */ float fade_change;
/* 4 */ float pad1;
/* 8 */ std::array<float, 2> pad2;
/* 4 */ float camera_to_center_distance;
/* 8 */ float device_pixel_ratio;
/* 12 */ float aspect_ratio;
/* 16 */
};
static_assert(sizeof(SymbolDynamicUBO) == 16);

View File

@@ -13,19 +13,15 @@ layout (std140) uniform SymbolDrawableUBO {
highp vec2 u_texsize_icon;
highp float u_gamma_scale;
highp float u_device_pixel_ratio;
highp float u_camera_to_center_distance;
highp float u_pitch;
bool u_rotate_symbol;
highp float u_aspect_ratio;
highp vec2 u_pad1;
};
layout (std140) uniform SymbolDynamicUBO {
highp float u_fade_change;
highp float u_pad7;
highp vec2 u_pad8;
highp float u_camera_to_center_distance;
highp float u_device_pixel_ratio;
highp float u_aspect_ratio;
};
layout (std140) uniform SymbolDrawablePaintUBO {

View File

@@ -9,19 +9,15 @@ layout (std140) uniform SymbolDrawableUBO {
highp vec2 u_texsize_icon;
highp float u_gamma_scale;
highp float u_device_pixel_ratio;
highp float u_camera_to_center_distance;
highp float u_pitch;
bool u_rotate_symbol;
highp float u_aspect_ratio;
highp vec2 u_pad1;
};
layout (std140) uniform SymbolDynamicUBO {
highp float u_fade_change;
highp float u_pad7;
highp vec2 u_pad8;
highp float u_camera_to_center_distance;
highp float u_device_pixel_ratio;
highp float u_aspect_ratio;
};
layout (std140) uniform SymbolDrawablePaintUBO {

View File

@@ -21,19 +21,15 @@ layout (std140) uniform SymbolDrawableUBO {
highp vec2 u_texsize_icon;
highp float u_gamma_scale;
highp float u_device_pixel_ratio;
highp float u_camera_to_center_distance;
highp float u_pitch;
bool u_rotate_symbol;
highp float u_aspect_ratio;
highp vec2 u_pad1;
};
layout (std140) uniform SymbolDynamicUBO {
highp float u_fade_change;
highp float u_pad7;
highp vec2 u_pad8;
highp float u_camera_to_center_distance;
highp float u_device_pixel_ratio;
highp float u_aspect_ratio;
};
layout (std140) uniform SymbolDrawablePaintUBO {

View File

@@ -12,19 +12,15 @@ layout (std140) uniform SymbolDrawableUBO {
highp vec2 u_texsize_icon;
highp float u_gamma_scale;
highp float u_device_pixel_ratio;
highp float u_camera_to_center_distance;
highp float u_pitch;
bool u_rotate_symbol;
highp float u_aspect_ratio;
highp vec2 u_pad1;
};
layout (std140) uniform SymbolDynamicUBO {
highp float u_fade_change;
highp float u_pad7;
highp vec2 u_pad8;
highp float u_camera_to_center_distance;
highp float u_device_pixel_ratio;
highp float u_aspect_ratio;
};
layout (std140) uniform SymbolDrawablePaintUBO {

View File

@@ -20,19 +20,15 @@ layout (std140) uniform SymbolDrawableUBO {
highp vec2 u_texsize_icon;
highp float u_gamma_scale;
highp float u_device_pixel_ratio;
highp float u_camera_to_center_distance;
highp float u_pitch;
bool u_rotate_symbol;
highp float u_aspect_ratio;
highp vec2 u_pad1;
};
layout (std140) uniform SymbolDynamicUBO {
highp float u_fade_change;
highp float u_pad7;
highp vec2 u_pad8;
highp float u_camera_to_center_distance;
highp float u_device_pixel_ratio;
highp float u_aspect_ratio;
};
layout (std140) uniform SymbolDrawablePaintUBO {

View File

@@ -101,9 +101,12 @@ void SymbolLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParamete
propertiesUpdated = false;
}
const auto camDist = state.getCameraToCenterDistance();
const SymbolDynamicUBO dynamicUBO = {/*.fade_change=*/parameters.symbolFadeChange,
/*.pad1=*/0,
/*.pad2=*/{0, 0}};
/*.camera_to_center_distance=*/camDist,
/*.device_pixel_ratio=*/parameters.pixelRatio,
/*.aspect_ratio=*/state.getSize().aspectRatio()};
if (!dynamicBuffer) {
dynamicBuffer = parameters.context.createUniformBuffer(&dynamicUBO, sizeof(dynamicUBO));
@@ -153,7 +156,6 @@ void SymbolLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParamete
matrix, pitchWithMap, rotateWithMap, state, pixelsToTileUnits);
const mat4 glCoordMatrix = getGlCoordMatrix(matrix, pitchWithMap, rotateWithMap, state, pixelsToTileUnits);
const auto camDist = state.getCameraToCenterDistance();
const float gammaScale = (symbolData.pitchAlignment == AlignmentType::Map
? static_cast<float>(std::cos(state.getPitch())) * camDist
: 1.0f);
@@ -172,12 +174,7 @@ void SymbolLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParamete
/*.texsize_icon=*/toArray(getTexSize(drawable, idTexIconUniformName)),
/*.gamma_scale=*/gammaScale,
/*.device_pixel_ratio=*/parameters.pixelRatio,
/*.camera_to_center_distance=*/camDist,
/*.pitch=*/static_cast<float>(state.getPitch()),
/*.rotate_symbol=*/rotateInShader,
/*.aspect_ratio=*/state.getSize().aspectRatio(),
/*.pad=*/{0},
};

View File

@@ -22,7 +22,7 @@ const std::array<AttributeInfo, 10> ShaderSource<BuiltIn::SymbolSDFIconShader, g
const std::array<UniformBlockInfo, 7> ShaderSource<BuiltIn::SymbolSDFIconShader, gfx::Backend::Type::Metal>::uniforms =
{
UniformBlockInfo{10, true, true, sizeof(SymbolDrawableUBO), "SymbolDrawableUBO"},
UniformBlockInfo{11, true, false, sizeof(SymbolDynamicUBO), "SymbolDynamicUBO"},
UniformBlockInfo{11, true, true, sizeof(SymbolDynamicUBO), "SymbolDynamicUBO"},
UniformBlockInfo{12, true, false, sizeof(SymbolDrawablePaintUBO), "SymbolDrawablePaintUBO"},
UniformBlockInfo{13, true, true, sizeof(SymbolDrawableTilePropsUBO), "SymbolDrawableTilePropsUBO"},
UniformBlockInfo{14, true, false, sizeof(SymbolDrawableInterpolateUBO), "SymbolDrawableInterpolateUBO"},

View File

@@ -21,7 +21,7 @@ const std::array<AttributeInfo, 9>
const std::array<UniformBlockInfo, 7>
ShaderSource<BuiltIn::SymbolTextAndIconShader, gfx::Backend::Type::Metal>::uniforms = {
UniformBlockInfo{9, true, true, sizeof(SymbolDrawableUBO), "SymbolDrawableUBO"},
UniformBlockInfo{10, true, false, sizeof(SymbolDynamicUBO), "SymbolDynamicUBO"},
UniformBlockInfo{10, true, true, sizeof(SymbolDynamicUBO), "SymbolDynamicUBO"},
UniformBlockInfo{11, true, false, sizeof(SymbolDrawablePaintUBO), "SymbolDrawablePaintUBO"},
UniformBlockInfo{12, true, true, sizeof(SymbolDrawableTilePropsUBO), "SymbolDrawableTilePropsUBO"},
UniformBlockInfo{13, true, false, sizeof(SymbolDrawableInterpolateUBO), "SymbolDrawableInterpolateUBO"},