diff --git a/include/mbgl/shaders/mtl/common.hpp b/include/mbgl/shaders/mtl/common.hpp index de61c8a0c..e211f50d3 100644 --- a/include/mbgl/shaders/mtl/common.hpp +++ b/include/mbgl/shaders/mtl/common.hpp @@ -60,7 +60,7 @@ float2 unpack_float(const float packedValue) { return float2(v0, packedIntValue - v0 * 256); } float2 unpack_opacity(const float packedOpacity) { - return float2(float(int(packedOpacity) / 2) / 127.0, fmod(packedOpacity, 2.0)); + return float2(float(int(packedOpacity) / 2) / 127.0, glMod(packedOpacity, 2.0)); } // To minimize the number of attributes needed, we encode a 4-component // color into a pair of floats (i.e. a vec2) as follows: @@ -220,11 +220,17 @@ struct alignas(16) SymbolDrawableUBO { float pitch; /*bool*/ int rotate_symbol; float aspect_ratio; - float fade_change; - float pad; + float2 pad; }; static_assert(sizeof(SymbolDrawableUBO) == 15 * 16, "unexpected padding"); +struct alignas(16) SymbolDynamicUBO { + float fade_change; + float pad1; + float2 pad2; +}; +static_assert(sizeof(SymbolDynamicUBO) == 16, "unexpected padding"); + struct alignas(16) SymbolDrawablePaintUBO { float4 fill_color; float4 halo_color; diff --git a/include/mbgl/shaders/mtl/symbol_icon.hpp b/include/mbgl/shaders/mtl/symbol_icon.hpp index 0cd4ada77..ffe5e96ad 100644 --- a/include/mbgl/shaders/mtl/symbol_icon.hpp +++ b/include/mbgl/shaders/mtl/symbol_icon.hpp @@ -15,7 +15,7 @@ struct ShaderSource { static constexpr auto fragmentMainFunction = "fragmentMain"; static const std::array attributes; - static const std::array uniforms; + static const std::array uniforms; static const std::array textures; static constexpr auto source = R"( @@ -37,11 +37,12 @@ struct FragmentStage { FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], device const SymbolDrawableUBO& drawable [[buffer(8)]], - device const SymbolDrawablePaintUBO& paint [[buffer(9)]], - device const SymbolDrawableTilePropsUBO& props [[buffer(10)]], - device const SymbolDrawableInterpolateUBO& interp [[buffer(11)]], - device const SymbolPermutationUBO& permutation [[buffer(12)]], - device const ExpressionInputsUBO& expr [[buffer(13)]]) { + device const SymbolDynamicUBO& dynamic [[buffer(9)]], + device const SymbolDrawablePaintUBO& paint [[buffer(10)]], + device const SymbolDrawableTilePropsUBO& props [[buffer(11)]], + device const SymbolDrawableInterpolateUBO& interp [[buffer(12)]], + device const SymbolPermutationUBO& permutation [[buffer(13)]], + device const ExpressionInputsUBO& expr [[buffer(14)]]) { const auto opacity = valueFor(permutation.opacity, paint.opacity, vertx.opacity, interp.opacity_t, expr); @@ -101,7 +102,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], const float4 position = drawable.coord_matrix * float4(pos0 + rotation_matrix * posOffset, 0.0, 1.0); const float2 fade_opacity = unpack_opacity(vertx.fade_opacity); - const float fade_change = fade_opacity[1] > 0.5 ? drawable.fade_change : -drawable.fade_change; + const float fade_change = fade_opacity[1] > 0.5 ? dynamic.fade_change : -dynamic.fade_change; return { .position = position, @@ -113,7 +114,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], half4 fragment fragmentMain(FragmentStage in [[stage_in]], device const SymbolDrawableUBO& drawable [[buffer(8)]], - device const SymbolPermutationUBO& permutation [[buffer(12)]], + device const SymbolPermutationUBO& permutation [[buffer(13)]], texture2d image [[texture(0)]], sampler image_sampler [[sampler(0)]]) { if (permutation.overdrawInspector) { diff --git a/include/mbgl/shaders/mtl/symbol_sdf.hpp b/include/mbgl/shaders/mtl/symbol_sdf.hpp index c9858636b..f7a540e12 100644 --- a/include/mbgl/shaders/mtl/symbol_sdf.hpp +++ b/include/mbgl/shaders/mtl/symbol_sdf.hpp @@ -15,7 +15,7 @@ struct ShaderSource { static constexpr auto fragmentMainFunction = "fragmentMain"; static const std::array attributes; - static const std::array uniforms; + static const std::array uniforms; static const std::array textures; static constexpr auto source = R"( @@ -46,11 +46,12 @@ struct FragmentStage { FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], device const SymbolDrawableUBO& drawable [[buffer(10)]], - device const SymbolDrawablePaintUBO& paint [[buffer(11)]], - device const SymbolDrawableTilePropsUBO& props [[buffer(12)]], - device const SymbolDrawableInterpolateUBO& interp [[buffer(13)]], - device const SymbolPermutationUBO& permutation [[buffer(14)]], - device const ExpressionInputsUBO& expr [[buffer(15)]]) { + device const SymbolDynamicUBO& dynamic [[buffer(11)]], + device const SymbolDrawablePaintUBO& paint [[buffer(12)]], + device const SymbolDrawableTilePropsUBO& props [[buffer(13)]], + device const SymbolDrawableInterpolateUBO& interp [[buffer(14)]], + device const SymbolPermutationUBO& permutation [[buffer(15)]], + device const ExpressionInputsUBO& expr [[buffer(16)]]) { const auto fill_color = colorFor(permutation.fill_color, paint.fill_color, vertx.fill_color, interp.fill_color_t, expr); const auto halo_color = colorFor(permutation.halo_color, paint.halo_color, vertx.halo_color, interp.halo_color_t, expr); @@ -122,7 +123,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], const float gamma_scale = position.w; const float2 fade_opacity = unpack_opacity(vertx.fade_opacity); - const float fade_change = (fade_opacity[1] > 0.5) ? drawable.fade_change : -drawable.fade_change; + const float fade_change = (fade_opacity[1] > 0.5) ? dynamic.fade_change : -dynamic.fade_change; const float interpolated_fade_opacity = max(0.0, min(1.0, fade_opacity[0] + fade_change)); return { @@ -139,8 +140,8 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], half4 fragment fragmentMain(FragmentStage in [[stage_in]], device const SymbolDrawableUBO& drawable [[buffer(10)]], - device const SymbolDrawableTilePropsUBO& props [[buffer(12)]], - device const SymbolPermutationUBO& permutation [[buffer(14)]], + device const SymbolDrawableTilePropsUBO& props [[buffer(13)]], + device const SymbolPermutationUBO& permutation [[buffer(15)]], texture2d image [[texture(0)]], sampler image_sampler [[sampler(0)]]) { if (permutation.overdrawInspector) { diff --git a/include/mbgl/shaders/mtl/symbol_text_and_icon.hpp b/include/mbgl/shaders/mtl/symbol_text_and_icon.hpp index f0d68a52f..4281907eb 100644 --- a/include/mbgl/shaders/mtl/symbol_text_and_icon.hpp +++ b/include/mbgl/shaders/mtl/symbol_text_and_icon.hpp @@ -15,7 +15,7 @@ struct ShaderSource static constexpr auto fragmentMainFunction = "fragmentMain"; static const std::array attributes; - static const std::array uniforms; + static const std::array uniforms; static const std::array textures; static constexpr auto source = R"( @@ -48,11 +48,12 @@ struct FragmentStage { FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], device const SymbolDrawableUBO& drawable [[buffer(9)]], - device const SymbolDrawablePaintUBO& paint [[buffer(10)]], - device const SymbolDrawableTilePropsUBO& props [[buffer(11)]], - device const SymbolDrawableInterpolateUBO& interp [[buffer(12)]], - device const SymbolPermutationUBO& permutation [[buffer(13)]], - device const ExpressionInputsUBO& expr [[buffer(14)]]) { + device const SymbolDynamicUBO& dynamic [[buffer(10)]], + device const SymbolDrawablePaintUBO& paint [[buffer(11)]], + device const SymbolDrawableTilePropsUBO& props [[buffer(12)]], + device const SymbolDrawableInterpolateUBO& interp [[buffer(13)]], + device const SymbolPermutationUBO& permutation [[buffer(14)]], + device const ExpressionInputsUBO& expr [[buffer(15)]]) { const auto fill_color = colorFor(permutation.fill_color, paint.fill_color, vertx.fill_color, interp.fill_color_t, expr); const auto halo_color = colorFor(permutation.halo_color, paint.halo_color, vertx.halo_color, interp.halo_color_t, expr); @@ -124,7 +125,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], const float gamma_scale = position.w; const float2 fade_opacity = unpack_opacity(vertx.fade_opacity); - const float fade_change = (fade_opacity[1] > 0.5) ? drawable.fade_change : -drawable.fade_change; + const float fade_change = (fade_opacity[1] > 0.5) ? dynamic.fade_change : -dynamic.fade_change; const float interpolated_fade_opacity = max(0.0, min(1.0, fade_opacity[0] + fade_change)); return { @@ -141,8 +142,8 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], half4 fragment fragmentMain(FragmentStage in [[stage_in]], device const SymbolDrawableUBO& drawable [[buffer(9)]], - device const SymbolDrawableTilePropsUBO& props [[buffer(11)]], - device const SymbolPermutationUBO& permutation [[buffer(13)]], + device const SymbolDrawableTilePropsUBO& props [[buffer(12)]], + device const SymbolPermutationUBO& permutation [[buffer(14)]], texture2d glyph_image [[texture(0)]], texture2d icon_image [[texture(1)]], sampler glyph_sampler [[sampler(0)]], diff --git a/src/mbgl/shaders/mtl/symbol_icon.cpp b/src/mbgl/shaders/mtl/symbol_icon.cpp index 7a2b8242e..566f38887 100644 --- a/src/mbgl/shaders/mtl/symbol_icon.cpp +++ b/src/mbgl/shaders/mtl/symbol_icon.cpp @@ -14,13 +14,14 @@ const std::array ShaderSource ShaderSource::uniforms = { +const std::array ShaderSource::uniforms = { UniformBlockInfo{8, true, true, sizeof(SymbolDrawableUBO), "SymbolDrawableUBO"}, - UniformBlockInfo{9, true, true, sizeof(SymbolDrawablePaintUBO), "SymbolDrawablePaintUBO"}, - UniformBlockInfo{10, true, false, sizeof(SymbolDrawableTilePropsUBO), "SymbolDrawableTilePropsUBO"}, - UniformBlockInfo{11, true, false, sizeof(SymbolDrawableInterpolateUBO), "SymbolDrawableInterpolateUBO"}, - UniformBlockInfo{12, true, true, sizeof(SymbolPermutationUBO), "SymbolPermutationUBO"}, - UniformBlockInfo{13, true, false, sizeof(ExpressionInputsUBO), "ExpressionInputsUBO"}, + UniformBlockInfo{9, true, false, sizeof(SymbolDynamicUBO), "SymbolDynamicUBO"}, + UniformBlockInfo{10, true, true, sizeof(SymbolDrawablePaintUBO), "SymbolDrawablePaintUBO"}, + UniformBlockInfo{11, true, false, sizeof(SymbolDrawableTilePropsUBO), "SymbolDrawableTilePropsUBO"}, + UniformBlockInfo{12, true, false, sizeof(SymbolDrawableInterpolateUBO), "SymbolDrawableInterpolateUBO"}, + UniformBlockInfo{13, true, true, sizeof(SymbolPermutationUBO), "SymbolPermutationUBO"}, + UniformBlockInfo{14, true, false, sizeof(ExpressionInputsUBO), "ExpressionInputsUBO"}, }; const std::array ShaderSource::textures = { TextureInfo{0, "u_texture"}, diff --git a/src/mbgl/shaders/mtl/symbol_sdf.cpp b/src/mbgl/shaders/mtl/symbol_sdf.cpp index b1cf6d428..f5a45a7f8 100644 --- a/src/mbgl/shaders/mtl/symbol_sdf.cpp +++ b/src/mbgl/shaders/mtl/symbol_sdf.cpp @@ -19,14 +19,15 @@ const std::array ShaderSource ShaderSource::uniforms = +const std::array ShaderSource::uniforms = { UniformBlockInfo{10, true, true, sizeof(SymbolDrawableUBO), "SymbolDrawableUBO"}, - UniformBlockInfo{11, true, false, sizeof(SymbolDrawablePaintUBO), "SymbolDrawablePaintUBO"}, - UniformBlockInfo{12, true, true, sizeof(SymbolDrawableTilePropsUBO), "SymbolDrawableTilePropsUBO"}, - UniformBlockInfo{13, true, false, sizeof(SymbolDrawableInterpolateUBO), "SymbolDrawableInterpolateUBO"}, - UniformBlockInfo{14, true, true, sizeof(SymbolPermutationUBO), "SymbolPermutationUBO"}, - UniformBlockInfo{15, true, false, sizeof(ExpressionInputsUBO), "ExpressionInputsUBO"}, + UniformBlockInfo{11, true, false, sizeof(SymbolDynamicUBO), "SymbolDynamicUBO"}, + UniformBlockInfo{12, true, false, sizeof(SymbolDrawablePaintUBO), "SymbolDrawablePaintUBO"}, + UniformBlockInfo{13, true, true, sizeof(SymbolDrawableTilePropsUBO), "SymbolDrawableTilePropsUBO"}, + UniformBlockInfo{14, true, false, sizeof(SymbolDrawableInterpolateUBO), "SymbolDrawableInterpolateUBO"}, + UniformBlockInfo{15, true, true, sizeof(SymbolPermutationUBO), "SymbolPermutationUBO"}, + UniformBlockInfo{16, true, false, sizeof(ExpressionInputsUBO), "ExpressionInputsUBO"}, }; const std::array ShaderSource::textures = { TextureInfo{0, "u_texture"}, diff --git a/src/mbgl/shaders/mtl/symbol_text_and_icon.cpp b/src/mbgl/shaders/mtl/symbol_text_and_icon.cpp index d735e1862..69023d4fc 100644 --- a/src/mbgl/shaders/mtl/symbol_text_and_icon.cpp +++ b/src/mbgl/shaders/mtl/symbol_text_and_icon.cpp @@ -18,14 +18,15 @@ const std::array AttributeInfo{7, gfx::AttributeDataType::Float, 1, "a_halo_width"}, AttributeInfo{8, gfx::AttributeDataType::Float, 1, "a_halo_blur"}, }; -const std::array +const std::array ShaderSource::uniforms = { UniformBlockInfo{9, true, true, sizeof(SymbolDrawableUBO), "SymbolDrawableUBO"}, - UniformBlockInfo{10, true, false, sizeof(SymbolDrawablePaintUBO), "SymbolDrawablePaintUBO"}, - UniformBlockInfo{11, true, true, sizeof(SymbolDrawableTilePropsUBO), "SymbolDrawableTilePropsUBO"}, - UniformBlockInfo{12, true, false, sizeof(SymbolDrawableInterpolateUBO), "SymbolDrawableInterpolateUBO"}, - UniformBlockInfo{13, true, true, sizeof(SymbolPermutationUBO), "SymbolPermutationUBO"}, - UniformBlockInfo{14, true, false, sizeof(ExpressionInputsUBO), "ExpressionInputsUBO"}, + UniformBlockInfo{10, true, false, sizeof(SymbolDynamicUBO), "SymbolDynamicUBO"}, + UniformBlockInfo{11, true, false, sizeof(SymbolDrawablePaintUBO), "SymbolDrawablePaintUBO"}, + UniformBlockInfo{12, true, true, sizeof(SymbolDrawableTilePropsUBO), "SymbolDrawableTilePropsUBO"}, + UniformBlockInfo{13, true, false, sizeof(SymbolDrawableInterpolateUBO), "SymbolDrawableInterpolateUBO"}, + UniformBlockInfo{14, true, true, sizeof(SymbolPermutationUBO), "SymbolPermutationUBO"}, + UniformBlockInfo{15, true, false, sizeof(ExpressionInputsUBO), "ExpressionInputsUBO"}, }; const std::array ShaderSource::textures = { TextureInfo{0, "u_texture"},