From d22362ab22ac274cac64b9d32eb8100cfb81b85f Mon Sep 17 00:00:00 2001 From: Alex Cristici Date: Wed, 24 Apr 2024 17:14:18 +0300 Subject: [PATCH] Global UBO (#2292) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- include/mbgl/gfx/context.hpp | 11 ++ include/mbgl/mtl/context.hpp | 15 ++ include/mbgl/shaders/background_layer_ubo.hpp | 20 ++- include/mbgl/shaders/circle_layer_ubo.hpp | 3 +- include/mbgl/shaders/collision_layer_ubo.hpp | 4 +- .../shaders/custom_drawable_layer_ubo.hpp | 2 +- include/mbgl/shaders/debug_layer_ubo.hpp | 2 +- .../mbgl/shaders/fill_extrusion_layer_ubo.hpp | 23 +-- include/mbgl/shaders/fill_layer_ubo.hpp | 43 +++--- .../gl/drawable_background_pattern.hpp | 21 ++- include/mbgl/shaders/gl/drawable_circle.hpp | 17 ++- .../shaders/gl/drawable_collision_box.hpp | 19 ++- .../shaders/gl/drawable_collision_circle.hpp | 30 +++- include/mbgl/shaders/gl/drawable_fill.hpp | 8 +- .../shaders/gl/drawable_fill_extrusion.hpp | 7 +- .../gl/drawable_fill_extrusion_pattern.hpp | 33 +++-- .../mbgl/shaders/gl/drawable_fill_outline.hpp | 24 ++-- .../gl/drawable_fill_outline_pattern.hpp | 38 +++-- .../gl/drawable_fill_outline_triangulated.hpp | 21 ++- .../mbgl/shaders/gl/drawable_fill_pattern.hpp | 34 +++-- .../shaders/gl/drawable_heatmap_texture.hpp | 18 ++- include/mbgl/shaders/gl/drawable_line.hpp | 10 +- .../shaders/gl/drawable_line_gradient.hpp | 10 +- .../mbgl/shaders/gl/drawable_line_pattern.hpp | 10 +- include/mbgl/shaders/gl/drawable_line_sdf.hpp | 10 +- .../mbgl/shaders/gl/drawable_symbol_icon.hpp | 12 +- .../mbgl/shaders/gl/drawable_symbol_sdf.hpp | 19 ++- .../gl/drawable_symbol_text_and_icon.hpp | 19 ++- include/mbgl/shaders/heatmap_layer_ubo.hpp | 2 +- .../shaders/heatmap_texture_layer_ubo.hpp | 5 +- include/mbgl/shaders/hillshade_layer_ubo.hpp | 2 +- .../shaders/hillshade_prepare_layer_ubo.hpp | 2 +- include/mbgl/shaders/layer_ubo.hpp | 20 +++ include/mbgl/shaders/line_layer_ubo.hpp | 10 +- include/mbgl/shaders/mtl/background.hpp | 6 +- .../mbgl/shaders/mtl/background_pattern.hpp | 18 +-- include/mbgl/shaders/mtl/circle.hpp | 9 +- include/mbgl/shaders/mtl/clipping_mask.hpp | 4 +- include/mbgl/shaders/mtl/collision_box.hpp | 19 +-- include/mbgl/shaders/mtl/collision_circle.hpp | 19 +-- include/mbgl/shaders/mtl/common.hpp | 51 +++---- .../mbgl/shaders/mtl/custom_symbol_icon.hpp | 8 +- include/mbgl/shaders/mtl/debug.hpp | 10 +- include/mbgl/shaders/mtl/fill.hpp | 131 +++++++++--------- include/mbgl/shaders/mtl/fill_extrusion.hpp | 18 +-- .../shaders/mtl/fill_extrusion_pattern.hpp | 49 +++---- include/mbgl/shaders/mtl/heatmap.hpp | 14 +- include/mbgl/shaders/mtl/heatmap_texture.hpp | 15 +- include/mbgl/shaders/mtl/hillshade.hpp | 10 +- .../mbgl/shaders/mtl/hillshade_prepare.hpp | 8 +- include/mbgl/shaders/mtl/line.hpp | 16 +-- include/mbgl/shaders/mtl/raster.hpp | 16 +-- include/mbgl/shaders/mtl/symbol_icon.hpp | 11 +- include/mbgl/shaders/mtl/symbol_sdf.hpp | 11 +- .../mbgl/shaders/mtl/symbol_text_and_icon.hpp | 11 +- include/mbgl/shaders/mtl/widevector.hpp | 22 +-- include/mbgl/shaders/raster_layer_ubo.hpp | 2 +- include/mbgl/shaders/shader_defines.hpp | 2 +- include/mbgl/shaders/symbol_layer_ubo.hpp | 13 +- include/mbgl/shaders/widevector_ubo.hpp | 2 +- .../drawable.background_pattern.fragment.glsl | 17 ++- .../drawable.background_pattern.vertex.glsl | 2 - shaders/drawable.circle.vertex.glsl | 17 ++- shaders/drawable.collision_box.fragment.glsl | 4 +- shaders/drawable.collision_box.vertex.glsl | 15 +- .../drawable.collision_circle.fragment.glsl | 15 +- shaders/drawable.collision_circle.vertex.glsl | 15 +- shaders/drawable.fill.fragment.glsl | 4 +- shaders/drawable.fill.vertex.glsl | 4 +- shaders/drawable.fill_extrusion.vertex.glsl | 7 +- ...wable.fill_extrusion_pattern.fragment.glsl | 7 +- ...rawable.fill_extrusion_pattern.vertex.glsl | 26 +++- shaders/drawable.fill_outline.fragment.glsl | 4 +- shaders/drawable.fill_outline.vertex.glsl | 18 ++- ...rawable.fill_outline_pattern.fragment.glsl | 8 +- .../drawable.fill_outline_pattern.vertex.glsl | 28 ++-- ...le.fill_outline_triangulated.fragment.glsl | 4 +- ...able.fill_outline_triangulated.vertex.glsl | 17 ++- shaders/drawable.fill_pattern.fragment.glsl | 7 +- shaders/drawable.fill_pattern.vertex.glsl | 25 ++-- .../drawable.heatmap_texture.fragment.glsl | 3 +- shaders/drawable.heatmap_texture.vertex.glsl | 15 +- shaders/drawable.line.vertex.glsl | 10 +- shaders/drawable.line_gradient.vertex.glsl | 10 +- shaders/drawable.line_pattern.vertex.glsl | 10 +- shaders/drawable.line_sdf.vertex.glsl | 10 +- shaders/drawable.symbol_icon.vertex.glsl | 12 +- shaders/drawable.symbol_sdf.fragment.glsl | 7 - shaders/drawable.symbol_sdf.vertex.glsl | 12 +- ...rawable.symbol_text_and_icon.fragment.glsl | 7 - .../drawable.symbol_text_and_icon.vertex.glsl | 12 +- src/mbgl/gl/context.cpp | 23 +++ src/mbgl/gl/context.hpp | 14 ++ src/mbgl/mtl/context.cpp | 16 +++ .../layers/background_layer_tweaker.cpp | 26 ++-- .../renderer/layers/circle_layer_tweaker.cpp | 11 +- .../layers/collision_layer_tweaker.cpp | 4 +- .../layers/fill_extrusion_layer_tweaker.cpp | 10 +- .../renderer/layers/fill_layer_tweaker.cpp | 24 ++-- .../layers/heatmap_texture_layer_tweaker.cpp | 16 +-- .../renderer/layers/line_layer_tweaker.cpp | 5 - .../renderer/layers/symbol_layer_tweaker.cpp | 10 +- src/mbgl/renderer/renderer_impl.cpp | 17 +++ .../renderer/sources/render_tile_source.cpp | 6 - src/mbgl/shaders/gl/shader_info.cpp | 27 ++-- src/mbgl/shaders/mtl/background_pattern.cpp | 3 +- src/mbgl/shaders/mtl/circle.cpp | 2 +- src/mbgl/shaders/mtl/fill.cpp | 12 +- .../shaders/mtl/fill_extrusion_pattern.cpp | 3 +- src/mbgl/shaders/mtl/heatmap_texture.cpp | 3 +- src/mbgl/shaders/mtl/line.cpp | 8 +- src/mbgl/shaders/mtl/symbol_icon.cpp | 2 +- src/mbgl/shaders/mtl/symbol_sdf.cpp | 2 +- src/mbgl/shaders/mtl/symbol_text_and_icon.cpp | 2 +- .../style/layers/custom_drawable_layer.cpp | 8 +- 115 files changed, 966 insertions(+), 659 deletions(-) diff --git a/include/mbgl/gfx/context.hpp b/include/mbgl/gfx/context.hpp index b6f95fe14..d2300a4d3 100644 --- a/include/mbgl/gfx/context.hpp +++ b/include/mbgl/gfx/context.hpp @@ -155,6 +155,17 @@ public: return emplaceOrUpdateUniformBuffer(ptr, data, sizeof(T), persistent); } + /// Get the global uniform buffers + virtual const gfx::UniformBufferArray& getGlobalUniformBuffers() const = 0; + + /// Get the mutable global uniform buffer array + virtual gfx::UniformBufferArray& mutableGlobalUniformBuffers() = 0; + + /// Bind the global uniform buffers + virtual void bindGlobalUniformBuffers(gfx::RenderPass&) const noexcept = 0; + + /// Unbind the global uniform buffers + virtual void unbindGlobalUniformBuffers(gfx::RenderPass&) const noexcept = 0; #endif protected: diff --git a/include/mbgl/mtl/context.hpp b/include/mbgl/mtl/context.hpp index 83e73d3b5..ce95fc45f 100644 --- a/include/mbgl/mtl/context.hpp +++ b/include/mbgl/mtl/context.hpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -144,6 +145,18 @@ public: RenderStaticData& staticData, const std::vector& tileUBOs); + /// Get the global uniform buffers + const gfx::UniformBufferArray& getGlobalUniformBuffers() const override { return globalUniformBuffers; }; + + /// Get the mutable global uniform buffer array + gfx::UniformBufferArray& mutableGlobalUniformBuffers() override { return globalUniformBuffers; }; + + /// Bind the global uniform buffers + void bindGlobalUniformBuffers(gfx::RenderPass&) const noexcept override; + + /// Unbind the global uniform buffers + void unbindGlobalUniformBuffers(gfx::RenderPass&) const noexcept override {} + private: RendererBackend& backend; bool cleanupOnDestruction = true; @@ -160,6 +173,8 @@ private: std::optional clipMaskUniformsBuffer; bool clipMaskUniformsBufferUsed = false; const gfx::Renderable* stencilStateRenderable = nullptr; + + UniformBufferArray globalUniformBuffers; }; } // namespace mtl diff --git a/include/mbgl/shaders/background_layer_ubo.hpp b/include/mbgl/shaders/background_layer_ubo.hpp index 903a47487..0903dcbd4 100644 --- a/include/mbgl/shaders/background_layer_ubo.hpp +++ b/include/mbgl/shaders/background_layer_ubo.hpp @@ -40,20 +40,18 @@ struct alignas(16) BackgroundPatternLayerUBO { /* 8 */ std::array pattern_br_a; /* 16 */ std::array pattern_tl_b; /* 24 */ std::array pattern_br_b; - /* 32 */ std::array texsize; - /* 40 */ std::array pattern_size_a; - /* 48 */ std::array pattern_size_b; - /* 56 */ float scale_a; - /* 60 */ float scale_b; - /* 64 */ float mix; - /* 68 */ float opacity; - /* 72 */ float pad1, pad2; - /* 80 */ + /* 32 */ std::array pattern_size_a; + /* 40 */ std::array pattern_size_b; + /* 48 */ float scale_a; + /* 52 */ float scale_b; + /* 56 */ float mix; + /* 60 */ float opacity; + /* 64 */ }; -static_assert(sizeof(BackgroundPatternLayerUBO) == 80); +static_assert(sizeof(BackgroundPatternLayerUBO) == 64); enum { - idBackgroundDrawableUBO, + idBackgroundDrawableUBO = globalUBOCount, idBackgroundLayerUBO, backgroundUBOCount }; diff --git a/include/mbgl/shaders/circle_layer_ubo.hpp b/include/mbgl/shaders/circle_layer_ubo.hpp index 7b52c4c5c..f06187969 100644 --- a/include/mbgl/shaders/circle_layer_ubo.hpp +++ b/include/mbgl/shaders/circle_layer_ubo.hpp @@ -47,8 +47,7 @@ struct alignas(16) CircleInterpolateUBO { static_assert(sizeof(CircleInterpolateUBO) % 16 == 0); enum { - idCircleDrawableUBO, - idCirclePaintParamsUBO, + idCircleDrawableUBO = globalUBOCount, idCircleEvaluatedPropsUBO, idCircleInterpolateUBO, circleUBOCount diff --git a/include/mbgl/shaders/collision_layer_ubo.hpp b/include/mbgl/shaders/collision_layer_ubo.hpp index ea1c9d790..89530becb 100644 --- a/include/mbgl/shaders/collision_layer_ubo.hpp +++ b/include/mbgl/shaders/collision_layer_ubo.hpp @@ -8,14 +8,14 @@ namespace shaders { struct alignas(16) CollisionUBO { std::array matrix; std::array extrude_scale; - float camera_to_center_distance; float overscale_factor; + float pad; }; static_assert(sizeof(CollisionUBO) % 16 == 0); static_assert(sizeof(CollisionUBO) == 80); enum { - idCollisionUBO, + idCollisionUBO = globalUBOCount, collisionUBOCount }; diff --git a/include/mbgl/shaders/custom_drawable_layer_ubo.hpp b/include/mbgl/shaders/custom_drawable_layer_ubo.hpp index 8742c4bbb..feeb3edc4 100644 --- a/include/mbgl/shaders/custom_drawable_layer_ubo.hpp +++ b/include/mbgl/shaders/custom_drawable_layer_ubo.hpp @@ -27,7 +27,7 @@ struct alignas(16) CustomSymbolIconParametersUBO { static_assert(sizeof(CustomSymbolIconParametersUBO) == 3 * 16); enum { - idCustomSymbolDrawableUBO, + idCustomSymbolDrawableUBO = globalUBOCount, idCustomSymbolParametersUBO, customSymbolUBOCount }; diff --git a/include/mbgl/shaders/debug_layer_ubo.hpp b/include/mbgl/shaders/debug_layer_ubo.hpp index 11ef0edf9..57b4449b5 100644 --- a/include/mbgl/shaders/debug_layer_ubo.hpp +++ b/include/mbgl/shaders/debug_layer_ubo.hpp @@ -14,7 +14,7 @@ struct alignas(16) DebugUBO { static_assert(sizeof(DebugUBO) % 16 == 0); enum { - idDebugUBO, + idDebugUBO = globalUBOCount, debugUBOCount }; diff --git a/include/mbgl/shaders/fill_extrusion_layer_ubo.hpp b/include/mbgl/shaders/fill_extrusion_layer_ubo.hpp index 81772721e..c9321718e 100644 --- a/include/mbgl/shaders/fill_extrusion_layer_ubo.hpp +++ b/include/mbgl/shaders/fill_extrusion_layer_ubo.hpp @@ -8,16 +8,15 @@ namespace mbgl { namespace shaders { struct alignas(16) FillExtrusionDrawableUBO { - /* 0 */ std::array matrix; - /* 64 */ std::array scale; - /* 80 */ std::array texsize; - /* 88 */ std::array pixel_coord_upper; - /* 96 */ std::array pixel_coord_lower; - /* 104 */ float height_factor; - /* 108 */ float pad; - /* 112 */ + /* 0 */ std::array matrix; + /* 64 */ std::array texsize; + /* 72 */ std::array pixel_coord_upper; + /* 80 */ std::array pixel_coord_lower; + /* 88 */ float height_factor; + /* 92 */ float tile_ratio; + /* 96 */ }; -static_assert(sizeof(FillExtrusionDrawableUBO) == 7 * 16); +static_assert(sizeof(FillExtrusionDrawableUBO) == 6 * 16); /// Evaluated properties that do not depend on the tile struct alignas(16) FillExtrusionPropsUBO { @@ -31,7 +30,9 @@ struct alignas(16) FillExtrusionPropsUBO { /* 56 */ float vertical_gradient; /* 60 */ float opacity; /* 64 */ float fade; - /* 68 */ float pad2, pad3, pad4; + /* 68 */ float from_scale; + /* 72 */ float to_scale; + /* 76 */ float pad2; /* 80 */ }; static_assert(sizeof(FillExtrusionPropsUBO) == 5 * 16); @@ -57,7 +58,7 @@ struct alignas(16) FillExtrusionInterpolateUBO { static_assert(sizeof(FillExtrusionInterpolateUBO) == 2 * 16); enum { - idFillExtrusionDrawableUBO, + idFillExtrusionDrawableUBO = globalUBOCount, idFillExtrusionPropsUBO, idFillExtrusionTilePropsUBO, idFillExtrusionInterpolateUBO, diff --git a/include/mbgl/shaders/fill_layer_ubo.hpp b/include/mbgl/shaders/fill_layer_ubo.hpp index c88013c08..496d29502 100644 --- a/include/mbgl/shaders/fill_layer_ubo.hpp +++ b/include/mbgl/shaders/fill_layer_ubo.hpp @@ -10,6 +10,7 @@ namespace shaders { struct alignas(16) FillDrawableUBO { /* 0 */ std::array matrix; // composite model-view-projection matrix + /* 64 */ }; static_assert(sizeof(FillDrawableUBO) == 4 * 16); @@ -25,11 +26,9 @@ static_assert(sizeof(FillInterpolateUBO) % 16 == 0); struct alignas(16) FillOutlineDrawableUBO { /* 0 */ std::array matrix; // composite model-view-projection matrix - /* 64 */ std::array world; - /* 72 */ float pad1, pad2; - /* 80 */ + /* 64 */ }; -static_assert(sizeof(FillOutlineDrawableUBO) == 5 * 16); +static_assert(sizeof(FillOutlineDrawableUBO) == 4 * 16); struct alignas(16) FillOutlineInterpolateUBO { float outline_color_t; @@ -43,14 +42,14 @@ static_assert(sizeof(FillOutlineInterpolateUBO) == 1 * 16); struct alignas(16) FillPatternDrawableUBO { /* 0 */ std::array matrix; // composite model-view-projection matrix - /* 64 */ std::array scale; - /* 80 */ std::array pixel_coord_upper; - /* 88 */ std::array pixel_coord_lower; - /* 96 */ std::array texsize; - /* 104 */ float pad1, pad2; - /* 112 */ + /* 64 */ std::array pixel_coord_upper; + /* 72 */ std::array pixel_coord_lower; + /* 80 */ std::array texsize; + /* 88 */ float tile_ratio; + /* 92 */ float pad; + /* 96 */ }; -static_assert(sizeof(FillPatternDrawableUBO) == 7 * 16); +static_assert(sizeof(FillPatternDrawableUBO) == 6 * 16); struct alignas(16) FillPatternTilePropsUBO { std::array pattern_from; @@ -71,13 +70,14 @@ static_assert(sizeof(FillPatternInterpolateUBO) == 1 * 16); struct alignas(16) FillOutlinePatternDrawableUBO { /* 0 */ std::array matrix; // composite model-view-projection matrix - /* 64 */ std::array scale; - /* 80 */ std::array world; - /* 88 */ std::array pixel_coord_upper; - /* 96 */ std::array pixel_coord_lower; - /* 104 */ std::array texsize; + /* 64 */ std::array pixel_coord_upper; + /* 72 */ std::array pixel_coord_lower; + /* 80 */ std::array texsize; + /* 88 */ float tile_ratio; + /* 92 */ float pad; + /* 96 */ }; -static_assert(sizeof(FillOutlinePatternDrawableUBO) == 7 * 16); +static_assert(sizeof(FillOutlinePatternDrawableUBO) == 6 * 16); struct alignas(16) FillOutlinePatternTilePropsUBO { std::array pattern_from; @@ -98,9 +98,8 @@ static_assert(sizeof(FillOutlinePatternInterpolateUBO) == 1 * 16); struct alignas(16) FillOutlineTriangulatedDrawableUBO { std::array matrix; - std::array units_to_pixels; float ratio; - float pad; + float pad1, pad2, pad3; }; static_assert(sizeof(FillOutlineTriangulatedDrawableUBO) % 16 == 0); @@ -112,13 +111,13 @@ struct alignas(16) FillEvaluatedPropsUBO { Color outline_color; float opacity; float fade; - float width; - float pad1; + float from_scale; + float to_scale; }; static_assert(sizeof(FillEvaluatedPropsUBO) == 3 * 16); enum { - idFillDrawableUBO, + idFillDrawableUBO = globalUBOCount, idFillTilePropsUBO, idFillInterpolateUBO, idFillEvaluatedPropsUBO, diff --git a/include/mbgl/shaders/gl/drawable_background_pattern.hpp b/include/mbgl/shaders/gl/drawable_background_pattern.hpp index 424e011e3..d8edc98c1 100644 --- a/include/mbgl/shaders/gl/drawable_background_pattern.hpp +++ b/include/mbgl/shaders/gl/drawable_background_pattern.hpp @@ -20,14 +20,12 @@ layout (std140) uniform BackgroundPatternLayerUBO { highp vec2 u_pattern_br_a; highp vec2 u_pattern_tl_b; highp vec2 u_pattern_br_b; - highp vec2 u_texsize; highp vec2 u_pattern_size_a; highp vec2 u_pattern_size_b; highp float u_scale_a; highp float u_scale_b; highp float u_mix; highp float u_opacity; - highp float layer_pad1, layer_pad2; }; layout (location = 0) in vec2 a_pos; @@ -41,19 +39,28 @@ void main() { v_pos_b = get_pattern_pos(u_pixel_coord_upper, u_pixel_coord_lower, u_scale_b * u_pattern_size_b, u_tile_units_to_pixels, a_pos); } )"; - static constexpr const char* fragment = R"(layout (std140) uniform BackgroundPatternLayerUBO { + static constexpr const char* fragment = R"(layout (std140) uniform GlobalPaintParamsUBO { + highp vec2 u_pattern_atlas_texsize; + highp vec2 u_units_to_pixels; + highp vec2 u_world_size; + highp float u_camera_to_center_distance; + highp float u_symbol_fade_change; + highp float u_aspect_ratio; + highp float u_pixel_ratio; + highp float global_pad1, global_pad2; +}; + +layout (std140) uniform BackgroundPatternLayerUBO { highp vec2 u_pattern_tl_a; highp vec2 u_pattern_br_a; highp vec2 u_pattern_tl_b; highp vec2 u_pattern_br_b; - highp vec2 u_texsize; highp vec2 u_pattern_size_a; highp vec2 u_pattern_size_b; highp float u_scale_a; highp float u_scale_b; highp float u_mix; highp float u_opacity; - highp float layer_pad1, layer_pad2; }; uniform sampler2D u_image; @@ -63,11 +70,11 @@ in mediump vec2 v_pos_b; void main() { vec2 imagecoord = mod(v_pos_a, 1.0); - vec2 pos = mix(u_pattern_tl_a / u_texsize, u_pattern_br_a / u_texsize, imagecoord); + vec2 pos = mix(u_pattern_tl_a / u_pattern_atlas_texsize, u_pattern_br_a / u_pattern_atlas_texsize, imagecoord); vec4 color1 = texture(u_image, pos); vec2 imagecoord_b = mod(v_pos_b, 1.0); - vec2 pos2 = mix(u_pattern_tl_b / u_texsize, u_pattern_br_b / u_texsize, imagecoord_b); + vec2 pos2 = mix(u_pattern_tl_b / u_pattern_atlas_texsize, u_pattern_br_b / u_pattern_atlas_texsize, imagecoord_b); vec4 color2 = texture(u_image, pos2); fragColor = mix(color1, color2, u_mix) * u_opacity; diff --git a/include/mbgl/shaders/gl/drawable_circle.hpp b/include/mbgl/shaders/gl/drawable_circle.hpp index 058613dfb..fe9562b01 100644 --- a/include/mbgl/shaders/gl/drawable_circle.hpp +++ b/include/mbgl/shaders/gl/drawable_circle.hpp @@ -11,18 +11,23 @@ struct ShaderSource { static constexpr const char* vertex = R"(layout (location = 0) in vec2 a_pos; out vec3 v_data; +layout (std140) uniform GlobalPaintParamsUBO { + highp vec2 u_pattern_atlas_texsize; + highp vec2 u_units_to_pixels; + highp vec2 u_world_size; + highp float u_camera_to_center_distance; + highp float u_symbol_fade_change; + highp float u_aspect_ratio; + highp float u_pixel_ratio; + highp float global_pad1, global_pad2; +}; + layout (std140) uniform CircleDrawableUBO { highp mat4 u_matrix; highp vec2 u_extrude_scale; lowp vec2 drawable_pad1; }; -layout (std140) uniform CirclePaintParamsUBO { - highp float u_camera_to_center_distance; - lowp float params_pad1; - lowp vec2 params_pad2; -}; - layout (std140) uniform CircleEvaluatedPropsUBO { highp vec4 u_color; highp vec4 u_stroke_color; diff --git a/include/mbgl/shaders/gl/drawable_collision_box.hpp b/include/mbgl/shaders/gl/drawable_collision_box.hpp index 83cbe7d62..a6800ba7e 100644 --- a/include/mbgl/shaders/gl/drawable_collision_box.hpp +++ b/include/mbgl/shaders/gl/drawable_collision_box.hpp @@ -14,10 +14,21 @@ layout (location = 2) in vec2 a_extrude; layout (location = 3) in vec2 a_placed; layout (location = 4) in vec2 a_shift; -layout (std140) uniform CollisionBoxUBO { +layout (std140) uniform GlobalPaintParamsUBO { + highp vec2 u_pattern_atlas_texsize; + highp vec2 u_units_to_pixels; + highp vec2 u_world_size; + highp float u_camera_to_center_distance; + highp float u_symbol_fade_change; + highp float u_aspect_ratio; + highp float u_pixel_ratio; + highp float global_pad1, global_pad2; +}; + +layout (std140) uniform CollisionUBO { highp mat4 u_matrix; highp vec2 u_extrude_scale; - highp float u_camera_to_center_distance; + highp float u_overscale_factor; highp float pad1; }; @@ -39,10 +50,10 @@ void main() { v_notUsed = a_placed.y; } )"; - static constexpr const char* fragment = R"(layout (std140) uniform CollisionBoxUBO { + static constexpr const char* fragment = R"(layout (std140) uniform CollisionUBO { highp mat4 u_matrix; highp vec2 u_extrude_scale; - highp float u_camera_to_center_distance; + highp float u_overscale_factor; highp float pad1; }; diff --git a/include/mbgl/shaders/gl/drawable_collision_circle.hpp b/include/mbgl/shaders/gl/drawable_collision_circle.hpp index d743ce43a..2f05252ec 100644 --- a/include/mbgl/shaders/gl/drawable_collision_circle.hpp +++ b/include/mbgl/shaders/gl/drawable_collision_circle.hpp @@ -13,11 +13,22 @@ layout (location = 1) in vec2 a_anchor_pos; layout (location = 2) in vec2 a_extrude; layout (location = 3) in vec2 a_placed; -layout (std140) uniform CollisionCircleUBO { +layout (std140) uniform GlobalPaintParamsUBO { + highp vec2 u_pattern_atlas_texsize; + highp vec2 u_units_to_pixels; + highp vec2 u_world_size; + highp float u_camera_to_center_distance; + highp float u_symbol_fade_change; + highp float u_aspect_ratio; + highp float u_pixel_ratio; + highp float global_pad1, global_pad2; +}; + +layout (std140) uniform CollisionUBO { highp mat4 u_matrix; highp vec2 u_extrude_scale; - highp float u_camera_to_center_distance; highp float u_overscale_factor; + highp float pad1; }; out float v_placed; @@ -47,11 +58,22 @@ void main() { v_extrude_scale = u_extrude_scale * u_camera_to_center_distance * collision_perspective_ratio; } )"; - static constexpr const char* fragment = R"(layout (std140) uniform CollisionCircleUBO { + static constexpr const char* fragment = R"(layout (std140) uniform GlobalPaintParamsUBO { + highp vec2 u_pattern_atlas_texsize; + highp vec2 u_units_to_pixels; + highp vec2 u_world_size; + highp float u_camera_to_center_distance; + highp float u_symbol_fade_change; + highp float u_aspect_ratio; + highp float u_pixel_ratio; + highp float global_pad1, global_pad2; +}; + +layout (std140) uniform CollisionUBO { highp mat4 u_matrix; highp vec2 u_extrude_scale; - highp float u_camera_to_center_distance; highp float u_overscale_factor; + highp float pad1; }; in float v_placed; diff --git a/include/mbgl/shaders/gl/drawable_fill.hpp b/include/mbgl/shaders/gl/drawable_fill.hpp index 38dff9f4a..98ef7e21e 100644 --- a/include/mbgl/shaders/gl/drawable_fill.hpp +++ b/include/mbgl/shaders/gl/drawable_fill.hpp @@ -21,8 +21,8 @@ layout (std140) uniform FillEvaluatedPropsUBO { highp vec4 u_outline_color; highp float u_opacity; highp float u_fade; - highp float u_width; - highp float props_pad1; + highp float u_from_scale; + highp float u_to_scale; }; layout (location = 0) in vec2 a_pos; @@ -61,8 +61,8 @@ layout (std140) uniform FillEvaluatedPropsUBO { highp vec4 u_outline_color; highp float u_opacity; highp float u_fade; - highp float u_width; - highp float props_pad1; + highp float u_from_scale; + highp float u_to_scale; }; #ifndef HAS_UNIFORM_u_color diff --git a/include/mbgl/shaders/gl/drawable_fill_extrusion.hpp b/include/mbgl/shaders/gl/drawable_fill_extrusion.hpp index e4ad268f3..76b83e8fc 100644 --- a/include/mbgl/shaders/gl/drawable_fill_extrusion.hpp +++ b/include/mbgl/shaders/gl/drawable_fill_extrusion.hpp @@ -14,12 +14,11 @@ out vec4 v_color; layout (std140) uniform FillExtrusionDrawableUBO { highp mat4 u_matrix; - highp vec4 u_scale; highp vec2 u_texsize; highp vec2 u_pixel_coord_upper; highp vec2 u_pixel_coord_lower; highp float u_height_factor; - highp float drawable_pad1; + highp float u_tile_ratio; }; layout (std140) uniform FillExtrusionPropsUBO { highp vec4 u_color; @@ -32,7 +31,9 @@ layout (std140) uniform FillExtrusionPropsUBO { highp float u_vertical_gradient; highp float u_opacity; highp float u_fade; - highp float props_pad2, props_pad3, props_pad4; + highp float u_from_scale; + highp float u_to_scale; + highp float props_pad2; }; layout (std140) uniform FillExtrusionTilePropsUBO { highp vec4 u_pattern_from; diff --git a/include/mbgl/shaders/gl/drawable_fill_extrusion_pattern.hpp b/include/mbgl/shaders/gl/drawable_fill_extrusion_pattern.hpp index 72a648281..df273b63d 100644 --- a/include/mbgl/shaders/gl/drawable_fill_extrusion_pattern.hpp +++ b/include/mbgl/shaders/gl/drawable_fill_extrusion_pattern.hpp @@ -15,14 +15,24 @@ out vec2 v_pos_a; out vec2 v_pos_b; out vec4 v_lighting; +layout (std140) uniform GlobalPaintParamsUBO { + highp vec2 u_pattern_atlas_texsize; + highp vec2 u_units_to_pixels; + highp vec2 u_world_size; + highp float u_camera_to_center_distance; + highp float u_symbol_fade_change; + highp float u_aspect_ratio; + highp float u_pixel_ratio; + highp float global_pad1, global_pad2; +}; + layout (std140) uniform FillExtrusionDrawableUBO { highp mat4 u_matrix; - highp vec4 u_scale; highp vec2 u_texsize; highp vec2 u_pixel_coord_upper; highp vec2 u_pixel_coord_lower; highp float u_height_factor; - highp float drawable_pad1; + highp float u_tile_ratio; }; layout (std140) uniform FillExtrusionPropsUBO { highp vec4 u_color; @@ -35,7 +45,9 @@ layout (std140) uniform FillExtrusionPropsUBO { highp float u_vertical_gradient; highp float u_opacity; highp float u_fade; - highp float props_pad2, props_pad3, props_pad4; + highp float u_from_scale; + highp float u_to_scale; + highp float props_pad2; }; layout (std140) uniform FillExtrusionTilePropsUBO { highp vec4 u_pattern_from; @@ -94,10 +106,10 @@ mediump vec4 pattern_to = u_pattern_to; vec2 pattern_tl_b = pattern_to.xy; vec2 pattern_br_b = pattern_to.zw; - float pixelRatio = u_scale.x; - float tileRatio = u_scale.y; - float fromScale = u_scale.z; - float toScale = u_scale.w; + float pixelRatio = u_pixel_ratio; + float tileRatio = u_tile_ratio; + float fromScale = u_from_scale; + float toScale = u_to_scale; vec3 normal = a_normal_ed.xyz; float edgedistance = a_normal_ed.w; @@ -142,12 +154,11 @@ in vec4 v_lighting; layout (std140) uniform FillExtrusionDrawableUBO { highp mat4 u_matrix; - highp vec4 u_scale; highp vec2 u_texsize; highp vec2 u_pixel_coord_upper; highp vec2 u_pixel_coord_lower; highp float u_height_factor; - highp float drawable_pad1; + highp float u_tile_ratio; }; layout (std140) uniform FillExtrusionPropsUBO { highp vec4 u_color; @@ -160,7 +171,9 @@ layout (std140) uniform FillExtrusionPropsUBO { highp float u_vertical_gradient; highp float u_opacity; highp float u_fade; - highp float props_pad2, props_pad3, props_pad4; + highp float u_from_scale; + highp float u_to_scale; + highp float props_pad2; }; layout (std140) uniform FillExtrusionTilePropsUBO { highp vec4 u_pattern_from; diff --git a/include/mbgl/shaders/gl/drawable_fill_outline.hpp b/include/mbgl/shaders/gl/drawable_fill_outline.hpp index fc742ca36..08082a443 100644 --- a/include/mbgl/shaders/gl/drawable_fill_outline.hpp +++ b/include/mbgl/shaders/gl/drawable_fill_outline.hpp @@ -8,10 +8,18 @@ namespace shaders { template <> struct ShaderSource { static constexpr const char* name = "FillOutlineShader"; - static constexpr const char* vertex = R"(layout (std140) uniform FillOutlineDrawableUBO { + static constexpr const char* vertex = R"(layout (std140) uniform GlobalPaintParamsUBO { + highp vec2 u_pattern_atlas_texsize; + highp vec2 u_units_to_pixels; + highp vec2 u_world_size; + highp float u_camera_to_center_distance; + highp float u_symbol_fade_change; + highp float u_aspect_ratio; + highp float u_pixel_ratio; + highp float global_pad1, global_pad2; +}; +layout (std140) uniform FillOutlineDrawableUBO { highp mat4 u_matrix; - highp vec2 u_world; - highp vec2 drawable_pad1; }; layout (std140) uniform FillOutlineInterpolateUBO { highp float u_outline_color_t; @@ -24,8 +32,8 @@ layout (std140) uniform FillEvaluatedPropsUBO { highp vec4 u_outline_color; highp float u_opacity; highp float u_fade; - highp float u_width; - highp float props_pad1; + highp float u_from_scale; + highp float u_to_scale; }; layout (location = 0) in vec2 a_pos; @@ -54,7 +62,7 @@ lowp float opacity = u_opacity; #endif gl_Position = u_matrix * vec4(a_pos, 0, 1); - v_pos = (gl_Position.xy / gl_Position.w + 1.0) / 2.0 * u_world; + v_pos = (gl_Position.xy / gl_Position.w + 1.0) / 2.0 * u_world_size; } )"; static constexpr const char* fragment = R"(layout (std140) uniform FillOutlineInterpolateUBO { @@ -68,8 +76,8 @@ layout (std140) uniform FillEvaluatedPropsUBO { highp vec4 u_outline_color; highp float u_opacity; highp float u_fade; - highp float u_width; - highp float props_pad1; + highp float u_from_scale; + highp float u_to_scale; }; in vec2 v_pos; diff --git a/include/mbgl/shaders/gl/drawable_fill_outline_pattern.hpp b/include/mbgl/shaders/gl/drawable_fill_outline_pattern.hpp index 864e29ed7..caaac3803 100644 --- a/include/mbgl/shaders/gl/drawable_fill_outline_pattern.hpp +++ b/include/mbgl/shaders/gl/drawable_fill_outline_pattern.hpp @@ -8,13 +8,23 @@ namespace shaders { template <> struct ShaderSource { static constexpr const char* name = "FillOutlinePatternShader"; - static constexpr const char* vertex = R"(layout (std140) uniform FillOutlinePatternDrawableUBO { + static constexpr const char* vertex = R"(layout (std140) uniform GlobalPaintParamsUBO { + highp vec2 u_pattern_atlas_texsize; + highp vec2 u_units_to_pixels; + highp vec2 u_world_size; + highp float u_camera_to_center_distance; + highp float u_symbol_fade_change; + highp float u_aspect_ratio; + highp float u_pixel_ratio; + highp float global_pad1, global_pad2; +}; +layout (std140) uniform FillOutlinePatternDrawableUBO { highp mat4 u_matrix; - highp vec4 u_scale; - highp vec2 u_world; highp vec2 u_pixel_coord_upper; highp vec2 u_pixel_coord_lower; highp vec2 u_texsize; + highp float u_tile_ratio; + highp float drawable_pad1; }; layout (std140) uniform FillOutlinePatternTilePropsUBO { highp vec4 u_pattern_from; @@ -31,8 +41,8 @@ layout (std140) uniform FillEvaluatedPropsUBO { highp vec4 u_outline_color; highp float u_opacity; highp float u_fade; - highp float u_width; - highp float props_pad1; + highp float u_from_scale; + highp float u_to_scale; }; layout (location = 0) in vec2 a_pos; @@ -76,10 +86,10 @@ mediump vec4 pattern_to = u_pattern_to; vec2 pattern_tl_b = pattern_to.xy; vec2 pattern_br_b = pattern_to.zw; - float pixelRatio = u_scale.x; - float tileRatio = u_scale.y; - float fromScale = u_scale.z; - float toScale = u_scale.w; + float pixelRatio = u_pixel_ratio; + float tileRatio = u_tile_ratio; + float fromScale = u_from_scale; + float toScale = u_to_scale; gl_Position = u_matrix * vec4(a_pos, 0, 1); @@ -89,16 +99,16 @@ mediump vec4 pattern_to = u_pattern_to; v_pos_a = get_pattern_pos(u_pixel_coord_upper, u_pixel_coord_lower, fromScale * display_size_a, tileRatio, a_pos); v_pos_b = get_pattern_pos(u_pixel_coord_upper, u_pixel_coord_lower, toScale * display_size_b, tileRatio, a_pos); - v_pos = (gl_Position.xy / gl_Position.w + 1.0) / 2.0 * u_world; + v_pos = (gl_Position.xy / gl_Position.w + 1.0) / 2.0 * u_world_size; } )"; static constexpr const char* fragment = R"(layout (std140) uniform FillOutlinePatternDrawableUBO { highp mat4 u_matrix; - highp vec4 u_scale; - highp vec2 u_world; highp vec2 u_pixel_coord_upper; highp vec2 u_pixel_coord_lower; highp vec2 u_texsize; + highp float u_tile_ratio; + highp float drawable_pad1; }; layout (std140) uniform FillOutlinePatternTilePropsUBO { highp vec4 u_pattern_from; @@ -115,8 +125,8 @@ layout (std140) uniform FillEvaluatedPropsUBO { highp vec4 u_outline_color; highp float u_opacity; highp float u_fade; - highp float u_width; - highp float props_pad1; + highp float u_from_scale; + highp float u_to_scale; }; uniform sampler2D u_image; diff --git a/include/mbgl/shaders/gl/drawable_fill_outline_triangulated.hpp b/include/mbgl/shaders/gl/drawable_fill_outline_triangulated.hpp index 4c6b19ca2..73c26f195 100644 --- a/include/mbgl/shaders/gl/drawable_fill_outline_triangulated.hpp +++ b/include/mbgl/shaders/gl/drawable_fill_outline_triangulated.hpp @@ -19,19 +19,28 @@ struct ShaderSource struct ShaderSource { static constexpr const char* name = "FillPatternShader"; - static constexpr const char* vertex = R"(layout (std140) uniform FillPatternDrawableUBO { + static constexpr const char* vertex = R"(layout (std140) uniform GlobalPaintParamsUBO { + highp vec2 u_pattern_atlas_texsize; + highp vec2 u_units_to_pixels; + highp vec2 u_world_size; + highp float u_camera_to_center_distance; + highp float u_symbol_fade_change; + highp float u_aspect_ratio; + highp float u_pixel_ratio; + highp float global_pad1, global_pad2; +}; +layout (std140) uniform FillPatternDrawableUBO { highp mat4 u_matrix; - highp vec4 u_scale; highp vec2 u_pixel_coord_upper; highp vec2 u_pixel_coord_lower; highp vec2 u_texsize; + highp float u_tile_ratio; highp float drawable_pad1; - highp float drawable_pad2; }; layout (std140) uniform FillPatternTilePropsUBO { highp vec4 u_pattern_from; @@ -32,8 +41,8 @@ layout (std140) uniform FillEvaluatedPropsUBO { highp vec4 u_outline_color; highp float u_opacity; highp float u_fade; - highp float u_width; - highp float props_pad1; + highp float u_from_scale; + highp float u_to_scale; }; layout (location = 0) in vec2 a_pos; @@ -76,10 +85,10 @@ mediump vec4 pattern_to = u_pattern_to; vec2 pattern_tl_b = pattern_to.xy; vec2 pattern_br_b = pattern_to.zw; - float pixelRatio = u_scale.x; - float tileZoomRatio = u_scale.y; - float fromScale = u_scale.z; - float toScale = u_scale.w; + float pixelRatio = u_pixel_ratio; + float tileZoomRatio = u_tile_ratio; + float fromScale = u_from_scale; + float toScale = u_to_scale; vec2 display_size_a = vec2((pattern_br_a.x - pattern_tl_a.x) / pixelRatio, (pattern_br_a.y - pattern_tl_a.y) / pixelRatio); vec2 display_size_b = vec2((pattern_br_b.x - pattern_tl_b.x) / pixelRatio, (pattern_br_b.y - pattern_tl_b.y) / pixelRatio); @@ -91,12 +100,11 @@ mediump vec4 pattern_to = u_pattern_to; )"; static constexpr const char* fragment = R"(layout (std140) uniform FillPatternDrawableUBO { highp mat4 u_matrix; - highp vec4 u_scale; highp vec2 u_pixel_coord_upper; highp vec2 u_pixel_coord_lower; highp vec2 u_texsize; + highp float u_tile_ratio; highp float drawable_pad1; - highp float drawable_pad2; }; layout (std140) uniform FillPatternTilePropsUBO { highp vec4 u_pattern_from; @@ -113,8 +121,8 @@ layout (std140) uniform FillEvaluatedPropsUBO { highp vec4 u_outline_color; highp float u_opacity; highp float u_fade; - highp float u_width; - highp float props_pad1; + highp float u_from_scale; + highp float u_to_scale; }; uniform sampler2D u_image; diff --git a/include/mbgl/shaders/gl/drawable_heatmap_texture.hpp b/include/mbgl/shaders/gl/drawable_heatmap_texture.hpp index 8c019a1cd..c1593d005 100644 --- a/include/mbgl/shaders/gl/drawable_heatmap_texture.hpp +++ b/include/mbgl/shaders/gl/drawable_heatmap_texture.hpp @@ -11,15 +11,24 @@ struct ShaderSource { static constexpr const char* vertex = R"(layout (location = 0) in vec2 a_pos; out vec2 v_pos; +layout (std140) uniform GlobalPaintParamsUBO { + highp vec2 u_pattern_atlas_texsize; + highp vec2 u_units_to_pixels; + highp vec2 u_world_size; + highp float u_camera_to_center_distance; + highp float u_symbol_fade_change; + highp float u_aspect_ratio; + highp float u_pixel_ratio; + highp float global_pad1, global_pad2; +}; layout (std140) uniform HeatmapTexturePropsUBO { highp mat4 u_matrix; - highp vec2 u_world; highp float u_opacity; - lowp float props_pad1; + lowp float props_pad1, props_pad2, props_pad3; }; void main() { - gl_Position = u_matrix * vec4(a_pos * u_world, 0, 1); + gl_Position = u_matrix * vec4(a_pos * u_world_size, 0, 1); v_pos.x = a_pos.x; v_pos.y = 1.0 - a_pos.y; @@ -31,9 +40,8 @@ uniform sampler2D u_color_ramp; layout (std140) uniform HeatmapTexturePropsUBO { highp mat4 u_matrix; - highp vec2 u_world; highp float u_opacity; - lowp float props_pad1; + lowp float props_pad1, props_pad2, props_pad3; }; void main() { diff --git a/include/mbgl/shaders/gl/drawable_line.hpp b/include/mbgl/shaders/gl/drawable_line.hpp index f3868060b..ac8a9cabf 100644 --- a/include/mbgl/shaders/gl/drawable_line.hpp +++ b/include/mbgl/shaders/gl/drawable_line.hpp @@ -19,9 +19,15 @@ struct ShaderSource { layout (location = 0) in vec2 a_pos_normal; layout (location = 1) in vec4 a_data; -layout (std140) uniform LineDynamicUBO { +layout (std140) uniform GlobalPaintParamsUBO { + highp vec2 u_pattern_atlas_texsize; highp vec2 u_units_to_pixels; - lowp float dynamic_pad1, dynamic_pad2; + highp vec2 u_world_size; + highp float u_camera_to_center_distance; + highp float u_symbol_fade_change; + highp float u_aspect_ratio; + highp float u_pixel_ratio; + highp float global_pad1, global_pad2; }; layout (std140) uniform LineDrawableUBO { diff --git a/include/mbgl/shaders/gl/drawable_line_gradient.hpp b/include/mbgl/shaders/gl/drawable_line_gradient.hpp index f3c0b7725..0ddae503a 100644 --- a/include/mbgl/shaders/gl/drawable_line_gradient.hpp +++ b/include/mbgl/shaders/gl/drawable_line_gradient.hpp @@ -23,9 +23,15 @@ struct ShaderSource { layout (location = 0) in vec2 a_pos_normal; layout (location = 1) in vec4 a_data; -layout (std140) uniform LineDynamicUBO { +layout (std140) uniform GlobalPaintParamsUBO { + highp vec2 u_pattern_atlas_texsize; highp vec2 u_units_to_pixels; - lowp float dynamic_pad1, dynamic_pad2; + highp vec2 u_world_size; + highp float u_camera_to_center_distance; + highp float u_symbol_fade_change; + highp float u_aspect_ratio; + highp float u_pixel_ratio; + highp float global_pad1, global_pad2; }; layout (std140) uniform LineGradientDrawableUBO { diff --git a/include/mbgl/shaders/gl/drawable_line_pattern.hpp b/include/mbgl/shaders/gl/drawable_line_pattern.hpp index 666206c1b..cc03b8ffc 100644 --- a/include/mbgl/shaders/gl/drawable_line_pattern.hpp +++ b/include/mbgl/shaders/gl/drawable_line_pattern.hpp @@ -23,9 +23,15 @@ struct ShaderSource { layout (location = 0) in vec2 a_pos_normal; layout (location = 1) in vec4 a_data; -layout (std140) uniform LineDynamicUBO { +layout (std140) uniform GlobalPaintParamsUBO { + highp vec2 u_pattern_atlas_texsize; highp vec2 u_units_to_pixels; - lowp float dynamic_pad1, dynamic_pad2; + highp vec2 u_world_size; + highp float u_camera_to_center_distance; + highp float u_symbol_fade_change; + highp float u_aspect_ratio; + highp float u_pixel_ratio; + highp float global_pad1, global_pad2; }; layout (std140) uniform LinePatternDrawableUBO { diff --git a/include/mbgl/shaders/gl/drawable_line_sdf.hpp b/include/mbgl/shaders/gl/drawable_line_sdf.hpp index d14664510..7fef18b07 100644 --- a/include/mbgl/shaders/gl/drawable_line_sdf.hpp +++ b/include/mbgl/shaders/gl/drawable_line_sdf.hpp @@ -23,9 +23,15 @@ struct ShaderSource { layout (location = 0) in vec2 a_pos_normal; layout (location = 1) in vec4 a_data; -layout (std140) uniform LineDynamicUBO { +layout (std140) uniform GlobalPaintParamsUBO { + highp vec2 u_pattern_atlas_texsize; highp vec2 u_units_to_pixels; - lowp float dynamic_pad1, dynamic_pad2; + highp vec2 u_world_size; + highp float u_camera_to_center_distance; + highp float u_symbol_fade_change; + highp float u_aspect_ratio; + highp float u_pixel_ratio; + highp float global_pad1, global_pad2; }; layout (std140) uniform LineSDFDrawableUBO { diff --git a/include/mbgl/shaders/gl/drawable_symbol_icon.hpp b/include/mbgl/shaders/gl/drawable_symbol_icon.hpp index 9d3bc3fa9..5a9b14ac0 100644 --- a/include/mbgl/shaders/gl/drawable_symbol_icon.hpp +++ b/include/mbgl/shaders/gl/drawable_symbol_icon.hpp @@ -14,11 +14,15 @@ layout (location = 2) in vec4 a_pixeloffset; layout (location = 3) in vec3 a_projected_pos; layout (location = 4) in float a_fade_opacity; -layout (std140) uniform SymbolDynamicUBO { - highp float u_fade_change; +layout (std140) uniform GlobalPaintParamsUBO { + highp vec2 u_pattern_atlas_texsize; + highp vec2 u_units_to_pixels; + highp vec2 u_world_size; highp float u_camera_to_center_distance; + highp float u_symbol_fade_change; highp float u_aspect_ratio; - highp float dynamic_pad1; + highp float u_pixel_ratio; + highp float global_pad1, global_pad2; }; layout (std140) uniform SymbolDrawableUBO { @@ -142,7 +146,7 @@ lowp float opacity = u_opacity; v_tex = a_tex / u_texsize; vec2 fade_opacity = unpack_opacity(a_fade_opacity); - float fade_change = fade_opacity[1] > 0.5 ? u_fade_change : -u_fade_change; + float fade_change = fade_opacity[1] > 0.5 ? u_symbol_fade_change : -u_symbol_fade_change; v_fade_opacity = max(0.0, min(1.0, fade_opacity[0] + fade_change)); } )"; diff --git a/include/mbgl/shaders/gl/drawable_symbol_sdf.hpp b/include/mbgl/shaders/gl/drawable_symbol_sdf.hpp index a67272d10..a0ce6a101 100644 --- a/include/mbgl/shaders/gl/drawable_symbol_sdf.hpp +++ b/include/mbgl/shaders/gl/drawable_symbol_sdf.hpp @@ -22,11 +22,15 @@ layout (location = 4) in float a_fade_opacity; // [ text-size(lowerZoomStop, feature), // text-size(upperZoomStop, feature) ] -layout (std140) uniform SymbolDynamicUBO { - highp float u_fade_change; +layout (std140) uniform GlobalPaintParamsUBO { + highp vec2 u_pattern_atlas_texsize; + highp vec2 u_units_to_pixels; + highp vec2 u_world_size; highp float u_camera_to_center_distance; + highp float u_symbol_fade_change; highp float u_aspect_ratio; - highp float dynamic_pad1; + highp float u_pixel_ratio; + highp float global_pad1, global_pad2; }; layout (std140) uniform SymbolDrawableUBO { @@ -196,7 +200,7 @@ lowp float halo_blur = u_halo_blur; float gamma_scale = gl_Position.w; vec2 fade_opacity = unpack_opacity(a_fade_opacity); - float fade_change = fade_opacity[1] > 0.5 ? u_fade_change : -u_fade_change; + float fade_change = fade_opacity[1] > 0.5 ? u_symbol_fade_change : -u_symbol_fade_change; float interpolated_fade_opacity = max(0.0, min(1.0, fade_opacity[0] + fade_change)); v_data0 = a_tex / u_texsize; @@ -205,13 +209,6 @@ lowp float halo_blur = u_halo_blur; )"; static constexpr const char* fragment = R"(#define SDF_PX 8.0 -layout (std140) uniform SymbolDynamicUBO { - highp float u_fade_change; - highp float u_camera_to_center_distance; - highp float u_aspect_ratio; - highp float dynamic_pad1; -}; - layout (std140) uniform SymbolDrawableUBO { highp mat4 u_matrix; highp mat4 u_label_plane_matrix; diff --git a/include/mbgl/shaders/gl/drawable_symbol_text_and_icon.hpp b/include/mbgl/shaders/gl/drawable_symbol_text_and_icon.hpp index 657bffbc1..fffa38067 100644 --- a/include/mbgl/shaders/gl/drawable_symbol_text_and_icon.hpp +++ b/include/mbgl/shaders/gl/drawable_symbol_text_and_icon.hpp @@ -21,11 +21,15 @@ layout (location = 3) in float a_fade_opacity; // [ text-size(lowerZoomStop, feature), // text-size(upperZoomStop, feature) ] -layout (std140) uniform SymbolDynamicUBO { - highp float u_fade_change; +layout (std140) uniform GlobalPaintParamsUBO { + highp vec2 u_pattern_atlas_texsize; + highp vec2 u_units_to_pixels; + highp vec2 u_world_size; highp float u_camera_to_center_distance; + highp float u_symbol_fade_change; highp float u_aspect_ratio; - highp float dynamic_pad1; + highp float u_pixel_ratio; + highp float global_pad1, global_pad2; }; layout (std140) uniform SymbolDrawableUBO { @@ -195,7 +199,7 @@ lowp float halo_blur = u_halo_blur; float gamma_scale = gl_Position.w; vec2 fade_opacity = unpack_opacity(a_fade_opacity); - float fade_change = fade_opacity[1] > 0.5 ? u_fade_change : -u_fade_change; + float fade_change = fade_opacity[1] > 0.5 ? u_symbol_fade_change : -u_symbol_fade_change; float interpolated_fade_opacity = max(0.0, min(1.0, fade_opacity[0] + fade_change)); v_data0.xy = a_tex / u_texsize; @@ -208,13 +212,6 @@ lowp float halo_blur = u_halo_blur; #define SDF 1.0 #define ICON 0.0 -layout (std140) uniform SymbolDynamicUBO { - highp float u_fade_change; - highp float u_camera_to_center_distance; - highp float u_aspect_ratio; - highp float dynamic_pad1; -}; - layout (std140) uniform SymbolDrawableUBO { highp mat4 u_matrix; highp mat4 u_label_plane_matrix; diff --git a/include/mbgl/shaders/heatmap_layer_ubo.hpp b/include/mbgl/shaders/heatmap_layer_ubo.hpp index 5b6bce58d..840439148 100644 --- a/include/mbgl/shaders/heatmap_layer_ubo.hpp +++ b/include/mbgl/shaders/heatmap_layer_ubo.hpp @@ -28,7 +28,7 @@ struct alignas(16) HeatmapInterpolateUBO { static_assert(sizeof(HeatmapInterpolateUBO) % 16 == 0); enum { - idHeatmapDrawableUBO, + idHeatmapDrawableUBO = globalUBOCount, idHeatmapEvaluatedPropsUBO, idHeatmapInterpolateUBO, heatmapUBOCount diff --git a/include/mbgl/shaders/heatmap_texture_layer_ubo.hpp b/include/mbgl/shaders/heatmap_texture_layer_ubo.hpp index fdc941e02..4bf428be9 100644 --- a/include/mbgl/shaders/heatmap_texture_layer_ubo.hpp +++ b/include/mbgl/shaders/heatmap_texture_layer_ubo.hpp @@ -7,14 +7,13 @@ namespace shaders { struct alignas(16) HeatmapTexturePropsUBO { std::array matrix; - std::array world; float opacity; - float pad1; + float pad1, pad2, pad3; }; static_assert(sizeof(HeatmapTexturePropsUBO) % 16 == 0); enum { - idHeatmapTexturePropsUBO, + idHeatmapTexturePropsUBO = globalUBOCount, heatmapTextureUBOCount }; diff --git a/include/mbgl/shaders/hillshade_layer_ubo.hpp b/include/mbgl/shaders/hillshade_layer_ubo.hpp index 89d3f118c..0ec6f4004 100644 --- a/include/mbgl/shaders/hillshade_layer_ubo.hpp +++ b/include/mbgl/shaders/hillshade_layer_ubo.hpp @@ -20,7 +20,7 @@ struct alignas(16) HillshadeEvaluatedPropsUBO { static_assert(sizeof(HillshadeEvaluatedPropsUBO) % 16 == 0); enum { - idHillshadeDrawableUBO, + idHillshadeDrawableUBO = globalUBOCount, idHillshadeEvaluatedPropsUBO, hillshadeUBOCount }; diff --git a/include/mbgl/shaders/hillshade_prepare_layer_ubo.hpp b/include/mbgl/shaders/hillshade_prepare_layer_ubo.hpp index 7daa8338f..5f4a6f925 100644 --- a/include/mbgl/shaders/hillshade_prepare_layer_ubo.hpp +++ b/include/mbgl/shaders/hillshade_prepare_layer_ubo.hpp @@ -15,7 +15,7 @@ struct alignas(16) HillshadePrepareDrawableUBO { static_assert(sizeof(HillshadePrepareDrawableUBO) % 16 == 0); enum { - idHillshadePrepareDrawableUBO, + idHillshadePrepareDrawableUBO = globalUBOCount, hillshadePrepareUBOCount }; diff --git a/include/mbgl/shaders/layer_ubo.hpp b/include/mbgl/shaders/layer_ubo.hpp index 52d85880a..3a07caf5d 100644 --- a/include/mbgl/shaders/layer_ubo.hpp +++ b/include/mbgl/shaders/layer_ubo.hpp @@ -33,5 +33,25 @@ struct Attribute { }; static_assert(sizeof(Attribute) == 8); +// +// Global UBOs + +struct alignas(16) GlobalPaintParamsUBO { + std::array pattern_atlas_texsize; + std::array units_to_pixels; + std::array world_size; + float camera_to_center_distance; + float symbol_fade_change; + float aspect_ratio; + float pixel_ratio; + float pad1, pad2; +}; +static_assert(sizeof(GlobalPaintParamsUBO) == 3 * 16); + +enum { + idGlobalPaintParamsUBO, + globalUBOCount +}; + } // namespace shaders } // namespace mbgl diff --git a/include/mbgl/shaders/line_layer_ubo.hpp b/include/mbgl/shaders/line_layer_ubo.hpp index be3bf1442..f2632115c 100644 --- a/include/mbgl/shaders/line_layer_ubo.hpp +++ b/include/mbgl/shaders/line_layer_ubo.hpp @@ -8,13 +8,6 @@ namespace shaders { // // Line -struct alignas(16) LineDynamicUBO { - /* 0 */ std::array units_to_pixels; - /* 8 */ float pad1, pad2; - /* 16 */ -}; -static_assert(sizeof(LineDynamicUBO) == 16); - struct alignas(16) LineDrawableUBO { std::array matrix; float ratio; @@ -122,8 +115,7 @@ struct alignas(16) LineEvaluatedPropsUBO { static_assert(sizeof(LineEvaluatedPropsUBO) % 16 == 0); enum { - idLineDynamicUBO, - idLineDrawableUBO, + idLineDrawableUBO = globalUBOCount, idLineInterpolationUBO, idLineTilePropertiesUBO, idLineEvaluatedPropsUBO, diff --git a/include/mbgl/shaders/mtl/background.hpp b/include/mbgl/shaders/mtl/background.hpp index 41a85e893..45211edbd 100644 --- a/include/mbgl/shaders/mtl/background.hpp +++ b/include/mbgl/shaders/mtl/background.hpp @@ -24,7 +24,7 @@ struct ShaderSource { using namespace metal; struct VertexStage { - short2 position [[attribute(2)]]; + short2 position [[attribute(3)]]; }; struct FragmentStage { @@ -41,14 +41,14 @@ struct alignas(16) BackgroundLayerUBO { }; FragmentStage vertex vertexMain(VertexStage in [[stage_in]], - device const BackgroundDrawableUBO& drawableUBO [[buffer(0)]]) { + device const BackgroundDrawableUBO& drawableUBO [[buffer(1)]]) { return { .position = drawableUBO.matrix * float4(float2(in.position.xy), 0, 1) }; } half4 fragment fragmentMain(FragmentStage in [[stage_in]], - device const BackgroundLayerUBO& layerUBO [[buffer(1)]]) { + device const BackgroundLayerUBO& layerUBO [[buffer(2)]]) { #if defined(OVERDRAW_INSPECTOR) return half4(1.0); #endif diff --git a/include/mbgl/shaders/mtl/background_pattern.hpp b/include/mbgl/shaders/mtl/background_pattern.hpp index 747b016cd..408cbd2fe 100644 --- a/include/mbgl/shaders/mtl/background_pattern.hpp +++ b/include/mbgl/shaders/mtl/background_pattern.hpp @@ -11,7 +11,7 @@ struct ShaderSource static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; - static const std::array uniforms; + static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; @@ -21,7 +21,7 @@ struct ShaderSource using namespace metal; struct VertexStage { - short2 position [[attribute(2)]]; + short2 position [[attribute(3)]]; }; struct FragmentStage { @@ -42,19 +42,17 @@ struct alignas(16) BackgroundPatternLayerUBO { float2 pattern_br_a; float2 pattern_tl_b; float2 pattern_br_b; - float2 texsize; float2 pattern_size_a; float2 pattern_size_b; float scale_a; float scale_b; float mix; float opacity; - float pad1, pad2; }; FragmentStage vertex vertexMain(VertexStage in [[stage_in]], - device const BackgroundPatternDrawableUBO& drawableUBO [[buffer(0)]], - device const BackgroundPatternLayerUBO& layerUBO [[buffer(1)]]) { + device const BackgroundPatternDrawableUBO& drawableUBO [[buffer(1)]], + device const BackgroundPatternLayerUBO& layerUBO [[buffer(2)]]) { const float2 pos = float2(in.position); const float2 pos_a = get_pattern_pos(drawableUBO.pixel_coord_upper, drawableUBO.pixel_coord_lower, @@ -74,18 +72,20 @@ FragmentStage vertex vertexMain(VertexStage in [[stage_in]], } half4 fragment fragmentMain(FragmentStage in [[stage_in]], - device const BackgroundPatternLayerUBO& layerUBO [[buffer(1)]], + device const GlobalPaintParamsUBO& paintParamsUBO [[buffer(0)]], + device const BackgroundPatternLayerUBO& layerUBO [[buffer(2)]], texture2d image [[texture(0)]], sampler image_sampler [[sampler(0)]]) { #if defined(OVERDRAW_INSPECTOR) return half4(1.0); #endif + const float2 texsize = paintParamsUBO.pattern_atlas_texsize; const float2 imagecoord = glMod(float2(in.pos_a), 1.0); - const float2 pos = mix(layerUBO.pattern_tl_a / layerUBO.texsize, layerUBO.pattern_br_a / layerUBO.texsize, imagecoord); + const float2 pos = mix(layerUBO.pattern_tl_a / texsize, layerUBO.pattern_br_a / texsize, imagecoord); const float4 color1 = image.sample(image_sampler, pos); const float2 imagecoord_b = glMod(float2(in.pos_b), 1.0); - const float2 pos2 = mix(layerUBO.pattern_tl_b / layerUBO.texsize, layerUBO.pattern_br_b / layerUBO.texsize, imagecoord_b); + const float2 pos2 = mix(layerUBO.pattern_tl_b / texsize, layerUBO.pattern_br_b / texsize, imagecoord_b); const float4 color2 = image.sample(image_sampler, pos2); return half4(mix(color1, color2, layerUBO.mix) * layerUBO.opacity); diff --git a/include/mbgl/shaders/mtl/circle.hpp b/include/mbgl/shaders/mtl/circle.hpp index 156616c7a..182ff712e 100644 --- a/include/mbgl/shaders/mtl/circle.hpp +++ b/include/mbgl/shaders/mtl/circle.hpp @@ -108,8 +108,8 @@ struct alignas(16) CircleInterpolateUBO { }; FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], - device const CircleDrawableUBO& drawable [[buffer(0)]], - device const CirclePaintParamsUBO& params [[buffer(1)]], + device const GlobalPaintParamsUBO& paintParams [[buffer(0)]], + device const CircleDrawableUBO& drawable [[buffer(1)]], device const CircleEvaluatedPropsUBO& props [[buffer(2)]], device const CircleInterpolateUBO& interp [[buffer(3)]]) { @@ -143,14 +143,14 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], // whole circle based on the pitch scaling effect at its central point const float4 projected_center = drawable.matrix * float4(circle_center, 0, 1); corner_position += scaled_extrude * (radius + stroke_width) * - (projected_center.w / params.camera_to_center_distance); + (projected_center.w / paintParams.camera_to_center_distance); } position = drawable.matrix * float4(corner_position, 0, 1); } else { position = drawable.matrix * float4(circle_center, 0, 1); - const float factor = props.scale_with_map ? params.camera_to_center_distance : position.w; + const float factor = props.scale_with_map ? paintParams.camera_to_center_distance : position.w; position.xy += scaled_extrude * (radius + stroke_width) * factor; } @@ -189,7 +189,6 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], } half4 fragment fragmentMain(FragmentStage in [[stage_in]], - device const CirclePaintParamsUBO& params [[buffer(1)]], device const CircleEvaluatedPropsUBO& props [[buffer(2)]]) { #if defined(OVERDRAW_INSPECTOR) return half4(1.0); diff --git a/include/mbgl/shaders/mtl/clipping_mask.hpp b/include/mbgl/shaders/mtl/clipping_mask.hpp index a331c2687..6791cd46c 100644 --- a/include/mbgl/shaders/mtl/clipping_mask.hpp +++ b/include/mbgl/shaders/mtl/clipping_mask.hpp @@ -38,7 +38,7 @@ struct alignas(16) ClipUBO { static_assert(sizeof(ClipUBO) == 5 * 16, "unexpected padding"); struct VertexStage { - short2 position [[attribute(1)]]; + short2 position [[attribute(2)]]; }; struct FragmentStage { @@ -51,7 +51,7 @@ struct FragmentResult { }; FragmentStage vertex vertexMain(VertexStage in [[stage_in]], - device const ClipUBO& clipUBO [[buffer(0)]]) { + device const ClipUBO& clipUBO [[buffer(1)]]) { return { clipUBO.matrix * float4(float2(in.position.xy), 0, 1) }; } diff --git a/include/mbgl/shaders/mtl/collision_box.hpp b/include/mbgl/shaders/mtl/collision_box.hpp index b99d15eee..1ae672a07 100644 --- a/include/mbgl/shaders/mtl/collision_box.hpp +++ b/include/mbgl/shaders/mtl/collision_box.hpp @@ -22,11 +22,11 @@ struct ShaderSource { static constexpr auto source = R"( struct VertexStage { - short2 pos [[attribute(1)]]; - short2 anchor_pos [[attribute(2)]]; - short2 extrude [[attribute(3)]]; - ushort2 placed [[attribute(4)]]; - float2 shift [[attribute(5)]]; + short2 pos [[attribute(2)]]; + short2 anchor_pos [[attribute(3)]]; + short2 extrude [[attribute(4)]]; + ushort2 placed [[attribute(5)]]; + float2 shift [[attribute(6)]]; }; struct FragmentStage { @@ -38,17 +38,18 @@ struct FragmentStage { struct alignas(16) CollisionBoxUBO { float4x4 matrix; float2 extrude_scale; - float camera_to_center_distance; + float overscale_factor; float pad1; }; FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], - device const CollisionBoxUBO& drawable [[buffer(0)]]) { + device const GlobalPaintParamsUBO& paintParams [[buffer(0)]], + device const CollisionBoxUBO& drawable [[buffer(1)]]) { float4 projectedPoint = drawable.matrix * float4(float2(vertx.anchor_pos), 0, 1); float camera_to_anchor_distance = projectedPoint.w; float collision_perspective_ratio = clamp( - 0.5 + 0.5 * (drawable.camera_to_center_distance / camera_to_anchor_distance), + 0.5 + 0.5 * (paintParams.camera_to_center_distance / camera_to_anchor_distance), 0.0, // Prevents oversized near-field boxes in pitched/overzoomed tiles 4.0); @@ -66,7 +67,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], } half4 fragment fragmentMain(FragmentStage in [[stage_in]], - device const CollisionBoxUBO& drawable [[buffer(0)]]) { + device const CollisionBoxUBO& drawable [[buffer(1)]]) { float alpha = 0.5; diff --git a/include/mbgl/shaders/mtl/collision_circle.hpp b/include/mbgl/shaders/mtl/collision_circle.hpp index 712dedce1..ecd009bc9 100644 --- a/include/mbgl/shaders/mtl/collision_circle.hpp +++ b/include/mbgl/shaders/mtl/collision_circle.hpp @@ -22,10 +22,10 @@ struct ShaderSource { static constexpr auto source = R"( struct VertexStage { - short2 pos [[attribute(1)]]; - short2 anchor_pos [[attribute(2)]]; - short2 extrude [[attribute(3)]]; - ushort2 placed [[attribute(4)]]; + short2 pos [[attribute(2)]]; + short2 anchor_pos [[attribute(3)]]; + short2 extrude [[attribute(4)]]; + ushort2 placed [[attribute(5)]]; }; struct FragmentStage { @@ -40,17 +40,18 @@ struct FragmentStage { struct alignas(16) CollisionCircleUBO { float4x4 matrix; float2 extrude_scale; - float camera_to_center_distance; float overscale_factor; + float pad1; }; FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], - device const CollisionCircleUBO& drawable [[buffer(0)]]) { + device const GlobalPaintParamsUBO& paintParams [[buffer(0)]], + device const CollisionCircleUBO& drawable [[buffer(1)]]) { float4 projectedPoint = drawable.matrix * float4(float2(vertx.anchor_pos), 0, 1); float camera_to_anchor_distance = projectedPoint.w; float collision_perspective_ratio = clamp( - 0.5 + 0.5 * (drawable.camera_to_center_distance / camera_to_anchor_distance), + 0.5 + 0.5 * (paintParams.camera_to_center_distance / camera_to_anchor_distance), 0.0, // Prevents oversized near-field circles in pitched/overzoomed tiles 4.0); @@ -64,7 +65,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], float radius = abs(float(vertx.extrude.y)); // We don't pitch the circles, so both units of the extrusion vector are equal in magnitude to the radius float2 extrude = float2(vertx.extrude) * padding_factor; - float2 extrude_scale = drawable.extrude_scale * drawable.camera_to_center_distance * collision_perspective_ratio; + float2 extrude_scale = drawable.extrude_scale * paintParams.camera_to_center_distance * collision_perspective_ratio; return { .position = position, @@ -77,7 +78,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], } half4 fragment fragmentMain(FragmentStage in [[stage_in]], - device const CollisionCircleUBO& drawable [[buffer(0)]]) { + device const CollisionCircleUBO& drawable [[buffer(1)]]) { float alpha = 0.5; diff --git a/include/mbgl/shaders/mtl/common.hpp b/include/mbgl/shaders/mtl/common.hpp index 02a6f825a..eb717c614 100644 --- a/include/mbgl/shaders/mtl/common.hpp +++ b/include/mbgl/shaders/mtl/common.hpp @@ -54,26 +54,38 @@ float4 unpack_mix_color(const float4 packedColors, const float t) { decode_color(float2(packedColors[2], packedColors[3])), t); } +struct alignas(16) GlobalPaintParamsUBO { + /* 0 */ float2 pattern_atlas_texsize; + /* 8 */ float2 units_to_pixels; + /* 16 */ float2 world_size; + /* 24 */ float camera_to_center_distance; + /* 28 */ float symbol_fade_change; + /* 32 */ float aspect_ratio; + /* 36 */ float pixel_ratio; + /* 40 */ float pad1, pad2; + /* 48 */ +}; +static_assert(sizeof(GlobalPaintParamsUBO) == 3 * 16, "unexpected padding"); + struct alignas(16) FillEvaluatedPropsUBO { float4 color; float4 outline_color; float opacity; float fade; - float width; - float pad1; + float from_scale; + float to_scale; }; struct alignas(16) FillExtrusionDrawableUBO { - /* 0 */ float4x4 matrix; - /* 64 */ float4 scale; - /* 80 */ float2 texsize; - /* 88 */ float2 pixel_coord_upper; - /* 96 */ float2 pixel_coord_lower; - /* 104 */ float height_factor; - /* 108 */ float pad; - /* 112 */ + /* 0 */ float4x4 matrix; + /* 64 */ float2 texsize; + /* 72 */ float2 pixel_coord_upper; + /* 80 */ float2 pixel_coord_lower; + /* 88 */ float height_factor; + /* 92 */ float tile_ratio; + /* 96 */ }; -static_assert(sizeof(FillExtrusionDrawableUBO) == 7 * 16, "unexpected padding"); +static_assert(sizeof(FillExtrusionDrawableUBO) == 6 * 16, "unexpected padding"); struct alignas(16) FillExtrusionPropsUBO { /* 0 */ float4 color; @@ -84,7 +96,9 @@ struct alignas(16) FillExtrusionPropsUBO { /* 56 */ float vertical_gradient; /* 60 */ float opacity; /* 64 */ float fade; - /* 68 */ float pad2, pad3, pad4; + /* 68 */ float from_scale; + /* 72 */ float to_scale; + /* 76 */ float pad2; /* 80 */ }; static_assert(sizeof(FillExtrusionPropsUBO) == 5 * 16, "unexpected padding"); @@ -107,11 +121,6 @@ struct alignas(16) FillExtrusionInterpolateUBO { }; static_assert(sizeof(FillExtrusionInterpolateUBO) == 2 * 16, "unexpected padding"); -struct alignas(16) LineDynamicUBO { - float2 units_to_pixels; - float pad1, pad2; -}; - struct alignas(16) LineEvaluatedPropsUBO { float4 color; float blur; @@ -123,14 +132,6 @@ struct alignas(16) LineEvaluatedPropsUBO { float pad1, pad2; }; -struct alignas(16) SymbolDynamicUBO { - float fade_change; - float camera_to_center_distance; - float aspect_ratio; - float pad; -}; -static_assert(sizeof(SymbolDynamicUBO) == 16, "unexpected padding"); - struct alignas(16) SymbolDrawableUBO { float4x4 matrix; float4x4 label_plane_matrix; diff --git a/include/mbgl/shaders/mtl/custom_symbol_icon.hpp b/include/mbgl/shaders/mtl/custom_symbol_icon.hpp index db149f3a4..eec04b816 100644 --- a/include/mbgl/shaders/mtl/custom_symbol_icon.hpp +++ b/include/mbgl/shaders/mtl/custom_symbol_icon.hpp @@ -36,8 +36,8 @@ struct alignas(16) CustomSymbolIconParametersUBO { }; struct VertexStage { - float2 a_pos [[attribute(2)]]; - float2 a_tex [[attribute(3)]]; + float2 a_pos [[attribute(3)]]; + float2 a_tex [[attribute(4)]]; }; struct FragmentStage { @@ -59,8 +59,8 @@ float2 ellipseRotateVec2(float2 v, float angle, float radiusRatio /* A/B */) { } FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], - device const CustomSymbolIconDrawableUBO& drawable [[buffer(0)]], - device const CustomSymbolIconParametersUBO& parameters [[buffer(1)]]) { + device const CustomSymbolIconDrawableUBO& drawable [[buffer(1)]], + device const CustomSymbolIconParametersUBO& parameters [[buffer(2)]]) { const float2 extrude = glMod(float2(vertx.a_pos), 2.0) * 2.0 - 1.0; const float2 anchor = (parameters.anchor - float2(0.5, 0.5)) * 2.0; diff --git a/include/mbgl/shaders/mtl/debug.hpp b/include/mbgl/shaders/mtl/debug.hpp index dd0362108..162b48003 100644 --- a/include/mbgl/shaders/mtl/debug.hpp +++ b/include/mbgl/shaders/mtl/debug.hpp @@ -22,7 +22,7 @@ struct ShaderSource { static constexpr auto source = R"( struct VertexStage { - short2 pos [[attribute(1)]]; + short2 pos [[attribute(2)]]; }; struct FragmentStage { @@ -38,9 +38,9 @@ struct alignas(16) DebugUBO { }; FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], - device const DebugUBO& debugUBO [[buffer(0)]]) { + device const DebugUBO& debug [[buffer(1)]]) { - const float4 position = debugUBO.matrix * float4(float2(vertx.pos) * debugUBO.overlay_scale, 0, 1); + const float4 position = debug.matrix * float4(float2(vertx.pos) * debug.overlay_scale, 0, 1); // This vertex shader expects a EXTENT x EXTENT quad, // The UV co-ordinates for the overlay texture can be calculated using that knowledge @@ -53,12 +53,12 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], } half4 fragment fragmentMain(FragmentStage in [[stage_in]], - device const DebugUBO& debugUBO [[buffer(0)]], + device const DebugUBO& debug [[buffer(1)]], texture2d overlay [[texture(0)]], sampler overlay_sampler [[sampler(0)]]) { float4 overlay_color = overlay.sample(overlay_sampler, in.uv); - float4 color = mix(debugUBO.color, overlay_color, overlay_color.a); + float4 color = mix(debug.color, overlay_color, overlay_color.a); return half4(color); } )"; diff --git a/include/mbgl/shaders/mtl/fill.hpp b/include/mbgl/shaders/mtl/fill.hpp index a00a2548e..5cf49dc87 100644 --- a/include/mbgl/shaders/mtl/fill.hpp +++ b/include/mbgl/shaders/mtl/fill.hpp @@ -22,13 +22,13 @@ struct ShaderSource { static constexpr auto source = R"( struct VertexStage { - short2 position [[attribute(4)]]; + short2 position [[attribute(5)]]; #if !defined(HAS_UNIFORM_u_color) - float4 color [[attribute(5)]]; + float4 color [[attribute(6)]]; #endif #if !defined(HAS_UNIFORM_u_opacity) - float2 opacity [[attribute(6)]]; + float2 opacity [[attribute(7)]]; #endif }; @@ -53,9 +53,9 @@ struct alignas(16) FillInterpolateUBO { }; FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], - device const FillDrawableUBO& drawable [[buffer(0)]], - device const FillInterpolateUBO& interp [[buffer(2)]], - device const FillEvaluatedPropsUBO& props [[buffer(3)]]) { + device const FillDrawableUBO& drawable [[buffer(1)]], + device const FillInterpolateUBO& interp [[buffer(3)]], + device const FillEvaluatedPropsUBO& props [[buffer(4)]]) { return { .position = drawable.matrix * float4(float2(vertx.position), 0.0f, 1.0f), #if !defined(HAS_UNIFORM_u_color) @@ -68,7 +68,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], } half4 fragment fragmentMain(FragmentStage in [[stage_in]], - device const FillEvaluatedPropsUBO& props [[buffer(3)]]) { + device const FillEvaluatedPropsUBO& props [[buffer(4)]]) { #if defined(OVERDRAW_INSPECTOR) return half4(1.0); #endif @@ -96,16 +96,16 @@ struct ShaderSource { static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; - static const std::array uniforms; + static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; static constexpr auto source = R"( struct VertexStage { - short2 position [[attribute(4)]]; - float4 outline_color [[attribute(5)]]; - float2 opacity [[attribute(6)]]; + short2 position [[attribute(5)]]; + float4 outline_color [[attribute(6)]]; + float2 opacity [[attribute(7)]]; }; struct FragmentStage { @@ -121,8 +121,6 @@ struct FragmentStage { struct alignas(16) FillOutlineDrawableUBO { float4x4 matrix; - float2 world; - float2 pad1; }; struct alignas(16) FillOutlineInterpolateUBO { @@ -131,13 +129,14 @@ struct alignas(16) FillOutlineInterpolateUBO { }; FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], - device const FillOutlineDrawableUBO& drawable [[buffer(0)]], - device const FillOutlineInterpolateUBO& interp [[buffer(2)]], - device const FillEvaluatedPropsUBO& props [[buffer(3)]]) { + device const GlobalPaintParamsUBO& paintParams [[buffer(0)]], + device const FillOutlineDrawableUBO& drawable [[buffer(1)]], + device const FillOutlineInterpolateUBO& interp [[buffer(3)]], + device const FillEvaluatedPropsUBO& props [[buffer(4)]]) { const float4 position = drawable.matrix * float4(float2(vertx.position), 0.0f, 1.0f); return { .position = position, - .pos = (position.xy / position.w + 1.0) / 2.0 * drawable.world, + .pos = (position.xy / position.w + 1.0) / 2.0 * paintParams.world_size, #if !defined(HAS_UNIFORM_u_outline_color) .outline_color = half4(unpack_mix_color(vertx.outline_color, interp.outline_color_t)), #endif @@ -148,7 +147,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], } half4 fragment fragmentMain(FragmentStage in [[stage_in]], - device const FillEvaluatedPropsUBO& props [[buffer(3)]]) { + device const FillEvaluatedPropsUBO& props [[buffer(4)]]) { #if defined(OVERDRAW_INSPECTOR) return half4(1.0); #endif @@ -182,23 +181,23 @@ struct ShaderSource { static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; - static const std::array uniforms; + static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; static constexpr auto source = R"( struct VertexStage { - short2 position [[attribute(4)]]; + short2 position [[attribute(5)]]; #if !defined(HAS_UNIFORM_u_pattern_from) - ushort4 pattern_from [[attribute(5)]]; + ushort4 pattern_from [[attribute(6)]]; #endif #if !defined(HAS_UNIFORM_u_pattern_to) - ushort4 pattern_to [[attribute(6)]]; + ushort4 pattern_to [[attribute(7)]]; #endif #if !defined(HAS_UNIFORM_u_opacity) - float2 opacity [[attribute(7)]]; + float2 opacity [[attribute(8)]]; #endif }; @@ -220,10 +219,11 @@ struct FragmentStage { struct alignas(16) FillPatternDrawableUBO { float4x4 matrix; - float4 scale; float2 pixel_coord_upper; float2 pixel_coord_lower; float2 texsize; + float tile_ratio; + float pad; }; struct alignas(16) FillPatternTilePropsUBO { @@ -238,10 +238,11 @@ struct alignas(16) FillPatternInterpolateUBO { }; FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], - device const FillPatternDrawableUBO& drawable [[buffer(0)]], - device const FillPatternTilePropsUBO& tileProps [[buffer(1)]], - device const FillPatternInterpolateUBO& interp [[buffer(2)]], - device const FillEvaluatedPropsUBO& props [[buffer(3)]]) { + device const GlobalPaintParamsUBO& paintParams [[buffer(0)]], + device const FillPatternDrawableUBO& drawable [[buffer(1)]], + device const FillPatternTilePropsUBO& tileProps [[buffer(2)]], + device const FillPatternInterpolateUBO& interp [[buffer(3)]], + device const FillEvaluatedPropsUBO& props [[buffer(4)]]) { #if defined(HAS_UNIFORM_u_pattern_from) const auto pattern_from = float4(tileProps.pattern_from); #else @@ -259,10 +260,10 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], const float2 pattern_tl_b = pattern_to.xy; const float2 pattern_br_b = pattern_to.zw; - const float pixelRatio = drawable.scale.x; - const float tileZoomRatio = drawable.scale.y; - const float fromScale = drawable.scale.z; - const float toScale = drawable.scale.w; + const float pixelRatio = paintParams.pixel_ratio; + const float tileZoomRatio = drawable.tile_ratio; + const float fromScale = props.from_scale; + const float toScale = props.to_scale; const float2 display_size_a = float2((pattern_br_a.x - pattern_tl_a.x) / pixelRatio, (pattern_br_a.y - pattern_tl_a.y) / pixelRatio); const float2 display_size_b = float2((pattern_br_b.x - pattern_tl_b.x) / pixelRatio, (pattern_br_b.y - pattern_tl_b.y) / pixelRatio); @@ -285,9 +286,9 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], } half4 fragment fragmentMain(FragmentStage in [[stage_in]], - device const FillPatternDrawableUBO& drawable [[buffer(0)]], - device const FillPatternTilePropsUBO& tileProps [[buffer(1)]], - device const FillEvaluatedPropsUBO& props [[buffer(3)]], + device const FillPatternDrawableUBO& drawable [[buffer(1)]], + device const FillPatternTilePropsUBO& tileProps [[buffer(2)]], + device const FillEvaluatedPropsUBO& props [[buffer(4)]], texture2d image0 [[texture(0)]], sampler image0_sampler [[sampler(0)]]) { #if defined(OVERDRAW_INSPECTOR) @@ -336,7 +337,7 @@ struct ShaderSource uniforms; + static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; @@ -344,16 +345,16 @@ struct ShaderSource image0 [[texture(0)]], sampler image0_sampler [[sampler(0)]]) { #if defined(OVERDRAW_INSPECTOR) @@ -504,15 +506,15 @@ struct ShaderSource uniforms; + static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; static constexpr auto source = R"( struct VertexStage { - short2 pos_normal [[attribute(4)]]; - uchar4 data [[attribute(5)]]; + short2 pos_normal [[attribute(5)]]; + uchar4 data [[attribute(6)]]; }; struct FragmentStage { @@ -524,14 +526,14 @@ struct FragmentStage { struct alignas(16) FillOutlineTriangulatedDrawableUBO { float4x4 matrix; - float2 units_to_pixels; float ratio; - float pad; + float pad1, pad2, pad3; }; FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], - device const FillOutlineTriangulatedDrawableUBO& drawable [[buffer(0)]], - device const FillEvaluatedPropsUBO& props [[buffer(3)]]) { + device const GlobalPaintParamsUBO& paintParams [[buffer(0)]], + device const FillOutlineTriangulatedDrawableUBO& drawable [[buffer(1)]], + device const FillEvaluatedPropsUBO& props [[buffer(4)]]) { // the distance over which the line edge fades out. // Retina devices need a smaller distance to avoid aliasing. @@ -546,7 +548,8 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], const float2 normal = float2(vertx.pos_normal) - 2.0 * pos; const float2 v_normal = float2(normal.x, normal.y * 2.0 - 1.0); - const float halfwidth = props.width / 2.0; + const float width = 1.0; //Should come from props ubo + const float halfwidth = width / 2.0; const float outset = halfwidth + (halfwidth == 0.0 ? 0.0 : ANTIALIASING); // Scale the extrusion vector down to a normal and then up by the line width of this vertex. @@ -557,7 +560,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], // calculate how much the perspective view squishes or stretches the extrude const float extrude_length_without_perspective = length(dist); - const float extrude_length_with_perspective = length(projected_extrude.xy / position.w * drawable.units_to_pixels); + const float extrude_length_with_perspective = length(projected_extrude.xy / position.w * paintParams.units_to_pixels); return { .position = position, @@ -568,7 +571,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], } half4 fragment fragmentMain(FragmentStage in [[stage_in]], - device const FillEvaluatedPropsUBO& props [[buffer(3)]]) { + device const FillEvaluatedPropsUBO& props [[buffer(4)]]) { // Calculate the distance of the pixel from the line in pixels. const float dist = length(in.normal) * in.width2; diff --git a/include/mbgl/shaders/mtl/fill_extrusion.hpp b/include/mbgl/shaders/mtl/fill_extrusion.hpp index 191e0aff0..2cbae0701 100644 --- a/include/mbgl/shaders/mtl/fill_extrusion.hpp +++ b/include/mbgl/shaders/mtl/fill_extrusion.hpp @@ -21,17 +21,17 @@ struct ShaderSource { static constexpr auto source = R"( struct VertexStage { - short2 pos [[attribute(4)]]; - short4 normal_ed [[attribute(5)]]; + short2 pos [[attribute(5)]]; + short4 normal_ed [[attribute(6)]]; #if !defined(HAS_UNIFORM_u_color) - float4 color [[attribute(6)]]; + float4 color [[attribute(7)]]; #endif #if !defined(HAS_UNIFORM_u_base) - float base [[attribute(7)]]; + float base [[attribute(8)]]; #endif #if !defined(HAS_UNIFORM_u_height) - float height [[attribute(8)]]; + float height [[attribute(9)]]; #endif }; @@ -46,9 +46,9 @@ struct FragmentOutput { }; FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], - device const FillExtrusionDrawableUBO& fill [[buffer(0)]], - device const FillExtrusionPropsUBO& props [[buffer(1)]], - device const FillExtrusionInterpolateUBO& interp [[buffer(3)]]) { + device const FillExtrusionDrawableUBO& drawable [[buffer(1)]], + device const FillExtrusionPropsUBO& props [[buffer(2)]], + device const FillExtrusionInterpolateUBO& interp [[buffer(4)]]) { #if defined(HAS_UNIFORM_u_base) const auto base = props.light_position_base.w; @@ -64,7 +64,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], const float3 normal = float3(vertx.normal_ed.xyz); const float t = glMod(normal.x, 2.0); const float z = (t != 0.0) ? height : base; // TODO: This would come out wrong on GL for negative values, check it... - const float4 position = fill.matrix * float4(float2(vertx.pos), z, 1); + const float4 position = drawable.matrix * float4(float2(vertx.pos), z, 1); #if defined(OVERDRAW_INSPECTOR) return { diff --git a/include/mbgl/shaders/mtl/fill_extrusion_pattern.hpp b/include/mbgl/shaders/mtl/fill_extrusion_pattern.hpp index bb61f9c25..7079e4f7a 100644 --- a/include/mbgl/shaders/mtl/fill_extrusion_pattern.hpp +++ b/include/mbgl/shaders/mtl/fill_extrusion_pattern.hpp @@ -14,27 +14,27 @@ struct ShaderSource uniforms; + static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; static constexpr auto source = R"( struct VertexStage { - short2 pos [[attribute(4)]]; - short4 normal_ed [[attribute(5)]]; + short2 pos [[attribute(5)]]; + short4 normal_ed [[attribute(6)]]; #if !defined(HAS_UNIFORM_u_base) - float base [[attribute(6)]]; + float base [[attribute(7)]]; #endif #if !defined(HAS_UNIFORM_u_height) - float height [[attribute(7)]]; + float height [[attribute(8)]]; #endif #if !defined(HAS_UNIFORM_u_pattern_from) - ushort4 pattern_from [[attribute(8)]]; + ushort4 pattern_from [[attribute(9)]]; #endif #if !defined(HAS_UNIFORM_u_pattern_to) - ushort4 pattern_to [[attribute(9)]]; + ushort4 pattern_to [[attribute(10)]]; #endif }; @@ -58,10 +58,11 @@ struct FragmentOutput { }; FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], - device const FillExtrusionDrawableUBO& fill [[buffer(0)]], - device const FillExtrusionPropsUBO& props [[buffer(1)]], - device const FillExtrusionTilePropsUBO& tileProps [[buffer(2)]], - device const FillExtrusionInterpolateUBO& interp [[buffer(3)]]) { + device const GlobalPaintParamsUBO& paintParams [[buffer(0)]], + device const FillExtrusionDrawableUBO& drawable [[buffer(1)]], + device const FillExtrusionPropsUBO& props [[buffer(2)]], + device const FillExtrusionTilePropsUBO& tileProps [[buffer(3)]], + device const FillExtrusionInterpolateUBO& interp [[buffer(4)]]) { #if defined(HAS_UNIFORM_u_base) const auto base = props.light_position_base.w; @@ -78,7 +79,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], const float edgedistance = vertx.normal_ed.w; const float t = glMod(normal.x, 2.0); const float z = (t != 0.0) ? height : base; // TODO: This would come out wrong on GL for negative values, check it... - const float4 position = fill.matrix * float4(float2(vertx.pos), z, 1); + const float4 position = drawable.matrix * float4(float2(vertx.pos), z, 1); #if defined(OVERDRAW_INSPECTOR) return { @@ -107,17 +108,17 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], const float2 pattern_tl_b = pattern_to.xy; const float2 pattern_br_b = pattern_to.zw; - const float pixelRatio = fill.scale.x; - const float tileZoomRatio = fill.scale.y; - const float fromScale = fill.scale.z; - const float toScale = fill.scale.w; + const float pixelRatio = paintParams.pixel_ratio; + const float tileZoomRatio = drawable.tile_ratio; + const float fromScale = props.from_scale; + const float toScale = props.to_scale; const float2 display_size_a = float2((pattern_br_a.x - pattern_tl_a.x) / pixelRatio, (pattern_br_a.y - pattern_tl_a.y) / pixelRatio); const float2 display_size_b = float2((pattern_br_b.x - pattern_tl_b.x) / pixelRatio, (pattern_br_b.y - pattern_tl_b.y) / pixelRatio); const float2 pos = normal.x == 1.0 && normal.y == 0.0 && normal.z == 16384.0 ? float2(vertx.pos) // extrusion top - : float2(edgedistance, z * fill.height_factor); // extrusion side + : float2(edgedistance, z * drawable.height_factor); // extrusion side float4 lighting = float4(0.0, 0.0, 0.0, 1.0); float directional = clamp(dot(normal / 16383.0, props.light_position_base.xyz), 0.0, 1.0); @@ -143,15 +144,15 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], #if !defined(HAS_UNIFORM_u_pattern_from) .pattern_to = half4(pattern_to), #endif - .pos_a = get_pattern_pos(fill.pixel_coord_upper, fill.pixel_coord_lower, fromScale * display_size_a, tileZoomRatio, pos), - .pos_b = get_pattern_pos(fill.pixel_coord_upper, fill.pixel_coord_lower, toScale * display_size_b, tileZoomRatio, pos), + .pos_a = get_pattern_pos(drawable.pixel_coord_upper, drawable.pixel_coord_lower, fromScale * display_size_a, tileZoomRatio, pos), + .pos_b = get_pattern_pos(drawable.pixel_coord_upper, drawable.pixel_coord_lower, toScale * display_size_b, tileZoomRatio, pos), }; } fragment FragmentOutput fragmentMain(FragmentStage in [[stage_in]], - device const FillExtrusionDrawableUBO& fill [[buffer(0)]], - device const FillExtrusionPropsUBO& props [[buffer(1)]], - device const FillExtrusionTilePropsUBO& tileProps [[buffer(2)]], + device const FillExtrusionDrawableUBO& drawable [[buffer(1)]], + device const FillExtrusionPropsUBO& props [[buffer(2)]], + device const FillExtrusionTilePropsUBO& tileProps [[buffer(3)]], texture2d image0 [[texture(0)]], sampler image0_sampler [[sampler(0)]]) { #if defined(OVERDRAW_INSPECTOR) @@ -175,11 +176,11 @@ fragment FragmentOutput fragmentMain(FragmentStage in [[stage_in]], const float2 pattern_br_b = pattern_to.zw; const float2 imagecoord = glMod(in.pos_a, 1.0); - const float2 pos = mix(pattern_tl_a / fill.texsize, pattern_br_a / fill.texsize, imagecoord); + const float2 pos = mix(pattern_tl_a / drawable.texsize, pattern_br_a / drawable.texsize, imagecoord); const float4 color1 = image0.sample(image0_sampler, pos); const float2 imagecoord_b = glMod(in.pos_b, 1.0); - const float2 pos2 = mix(pattern_tl_b / fill.texsize, pattern_br_b / fill.texsize, imagecoord_b); + const float2 pos2 = mix(pattern_tl_b / drawable.texsize, pattern_br_b / drawable.texsize, imagecoord_b); const float4 color2 = image0.sample(image0_sampler, pos2); return {half4(mix(color1, color2, props.fade) * in.lighting)/*, in.position.z*/}; diff --git a/include/mbgl/shaders/mtl/heatmap.hpp b/include/mbgl/shaders/mtl/heatmap.hpp index 8bd7feb4d..5e613169a 100644 --- a/include/mbgl/shaders/mtl/heatmap.hpp +++ b/include/mbgl/shaders/mtl/heatmap.hpp @@ -22,13 +22,13 @@ struct ShaderSource { static constexpr auto source = R"( struct VertexStage { - short2 pos [[attribute(3)]]; + short2 pos [[attribute(4)]]; #if !defined(HAS_UNIFORM_u_weight) - float2 weight [[attribute(4)]]; + float2 weight [[attribute(5)]]; #endif #if !defined(HAS_UNIFORM_u_radius) - float2 radius [[attribute(5)]]; + float2 radius [[attribute(6)]]; #endif }; @@ -67,9 +67,9 @@ constant const float ZERO = 1.0 / 255.0 / 16.0; #define GAUSS_COEF 0.3989422804014327 FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], - device const HeatmapDrawableUBO& drawable [[buffer(0)]], - device const HeatmapEvaluatedPropsUBO& props [[buffer(1)]], - device const HeatmapInterpolateUBO& interp [[buffer(2)]]) { + device const HeatmapDrawableUBO& drawable [[buffer(1)]], + device const HeatmapEvaluatedPropsUBO& props [[buffer(2)]], + device const HeatmapInterpolateUBO& interp [[buffer(3)]]) { #if defined(HAS_UNIFORM_u_weight) const auto weight = props.weight; @@ -117,7 +117,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], } half4 fragment fragmentMain(FragmentStage in [[stage_in]], - device const HeatmapEvaluatedPropsUBO& props [[buffer(1)]]) { + device const HeatmapEvaluatedPropsUBO& props [[buffer(2)]]) { #if defined(OVERDRAW_INSPECTOR) return half4(1.0); #endif diff --git a/include/mbgl/shaders/mtl/heatmap_texture.hpp b/include/mbgl/shaders/mtl/heatmap_texture.hpp index 4446ed215..0406676c5 100644 --- a/include/mbgl/shaders/mtl/heatmap_texture.hpp +++ b/include/mbgl/shaders/mtl/heatmap_texture.hpp @@ -14,7 +14,7 @@ struct ShaderSource { static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; - static const std::array uniforms; + static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; @@ -22,7 +22,7 @@ struct ShaderSource { static constexpr auto source = R"( struct VertexStage { - short2 pos [[attribute(1)]]; + short2 pos [[attribute(2)]]; }; struct FragmentStage { @@ -32,17 +32,16 @@ struct FragmentStage { struct alignas(16) HeatmapTexturePropsUBO { float4x4 matrix; - float2 world; float opacity; - bool overdrawInspector; - uint8_t pad1, pad2, pad3; + float pad1, pad2, pad3; }; FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], - device const HeatmapTexturePropsUBO& props [[buffer(0)]]) { + device const GlobalPaintParamsUBO& paintParams [[buffer(0)]], + device const HeatmapTexturePropsUBO& props [[buffer(1)]]) { const float2 pos = float2(vertx.pos); - const float4 position = props.matrix * float4(pos * props.world, 0, 1); + const float4 position = props.matrix * float4(pos * paintParams.world_size, 0, 1); return { .position = position, @@ -51,7 +50,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], } half4 fragment fragmentMain(FragmentStage in [[stage_in]], - device const HeatmapTexturePropsUBO& props [[buffer(0)]], + device const HeatmapTexturePropsUBO& props [[buffer(1)]], texture2d image [[texture(0)]], texture2d color_ramp [[texture(1)]], sampler image_sampler [[sampler(0)]], diff --git a/include/mbgl/shaders/mtl/hillshade.hpp b/include/mbgl/shaders/mtl/hillshade.hpp index d42414a4f..612954d94 100644 --- a/include/mbgl/shaders/mtl/hillshade.hpp +++ b/include/mbgl/shaders/mtl/hillshade.hpp @@ -22,8 +22,8 @@ struct ShaderSource { static constexpr auto source = R"( struct VertexStage { - short2 pos [[attribute(2)]]; - short2 texture_pos [[attribute(3)]]; + short2 pos [[attribute(3)]]; + short2 texture_pos [[attribute(4)]]; }; struct FragmentStage { @@ -44,7 +44,7 @@ struct alignas(16) HillshadeEvaluatedPropsUBO { }; FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], - device const HillshadeDrawableUBO& drawable [[buffer(0)]]) { + device const HillshadeDrawableUBO& drawable [[buffer(1)]]) { const float4 position = drawable.matrix * float4(float2(vertx.pos), 0, 1); float2 pos = float2(vertx.texture_pos) / 8192.0; @@ -57,8 +57,8 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], } half4 fragment fragmentMain(FragmentStage in [[stage_in]], - device const HillshadeDrawableUBO& drawable [[buffer(0)]], - device const HillshadeEvaluatedPropsUBO& props [[buffer(1)]], + device const HillshadeDrawableUBO& drawable [[buffer(1)]], + device const HillshadeEvaluatedPropsUBO& props [[buffer(2)]], texture2d image [[texture(0)]], sampler image_sampler [[sampler(0)]]) { #if defined(OVERDRAW_INSPECTOR) diff --git a/include/mbgl/shaders/mtl/hillshade_prepare.hpp b/include/mbgl/shaders/mtl/hillshade_prepare.hpp index 107640a8a..6a74245ff 100644 --- a/include/mbgl/shaders/mtl/hillshade_prepare.hpp +++ b/include/mbgl/shaders/mtl/hillshade_prepare.hpp @@ -21,8 +21,8 @@ struct ShaderSource static constexpr auto source = R"( struct VertexStage { - short2 pos [[attribute(1)]]; - short2 texture_pos [[attribute(2)]]; + short2 pos [[attribute(2)]]; + short2 texture_pos [[attribute(3)]]; }; struct FragmentStage { @@ -39,7 +39,7 @@ struct alignas(16) HillshadePrepareDrawableUBO { }; FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], - device const HillshadePrepareDrawableUBO& drawable [[buffer(0)]]) { + device const HillshadePrepareDrawableUBO& drawable [[buffer(1)]]) { const float4 position = drawable.matrix * float4(float2(vertx.pos), 0, 1); @@ -61,7 +61,7 @@ float getElevation(float2 coord, float bias, texture2d im } half4 fragment fragmentMain(FragmentStage in [[stage_in]], - device const HillshadePrepareDrawableUBO& drawable [[buffer(0)]], + device const HillshadePrepareDrawableUBO& drawable [[buffer(1)]], texture2d image [[texture(0)]], sampler image_sampler [[sampler(0)]]) { #if defined(OVERDRAW_INSPECTOR) diff --git a/include/mbgl/shaders/mtl/line.hpp b/include/mbgl/shaders/mtl/line.hpp index 9e345842a..a975c0797 100644 --- a/include/mbgl/shaders/mtl/line.hpp +++ b/include/mbgl/shaders/mtl/line.hpp @@ -78,7 +78,7 @@ struct alignas(16) LineInterpolationUBO { }; FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], - device const LineDynamicUBO& dynamic [[buffer(0)]], + device const GlobalPaintParamsUBO& paintParams [[buffer(0)]], device const LineDrawableUBO& drawable [[buffer(1)]], device const LineInterpolationUBO& interp [[buffer(2)]], device const LineEvaluatedPropsUBO& props [[buffer(4)]]) { @@ -133,7 +133,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], // calculate how much the perspective view squishes or stretches the extrude const float extrude_length_without_perspective = length(dist); - const float extrude_length_with_perspective = length(projected_extrude.xy / position.w * dynamic.units_to_pixels); + const float extrude_length_with_perspective = length(projected_extrude.xy / position.w * paintParams.units_to_pixels); return { .position = position, @@ -241,7 +241,7 @@ struct alignas(16) LineGradientInterpolationUBO { }; FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], - device const LineDynamicUBO& dynamic [[buffer(0)]], + device const GlobalPaintParamsUBO& paintParams [[buffer(0)]], device const LineGradientDrawableUBO& drawable [[buffer(1)]], device const LineGradientInterpolationUBO& interp [[buffer(2)]], device const LineEvaluatedPropsUBO& props [[buffer(4)]]) { @@ -303,7 +303,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], // calculate how much the perspective view squishes or stretches the extrude const float extrude_length_without_perspective = length(dist); - const float extrude_length_with_perspective = length(projected_extrude.xy / position.w * dynamic.units_to_pixels); + const float extrude_length_with_perspective = length(projected_extrude.xy / position.w * paintParams.units_to_pixels); return { .position = position, @@ -442,7 +442,7 @@ struct alignas(16) LinePatternTilePropertiesUBO { }; FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], - device const LineDynamicUBO& dynamic [[buffer(0)]], + device const GlobalPaintParamsUBO& paintParams [[buffer(0)]], device const LinePatternDrawableUBO& drawable [[buffer(1)]], device const LinePatternInterpolationUBO& interp [[buffer(2)]], device const LinePatternTilePropertiesUBO& tileProps [[buffer(3)]], @@ -500,7 +500,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], // calculate how much the perspective view squishes or stretches the extrude const float extrude_length_without_perspective = length(dist); - const float extrude_length_with_perspective = length(projected_extrude.xy / position.w * dynamic.units_to_pixels); + const float extrude_length_with_perspective = length(projected_extrude.xy / position.w * paintParams.units_to_pixels); return { .position = position, @@ -685,7 +685,7 @@ struct alignas(16) LineSDFInterpolationUBO { }; FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], - device const LineDynamicUBO& dynamic [[buffer(0)]], + device const GlobalPaintParamsUBO& paintParams [[buffer(0)]], device const LineSDFDrawableUBO& drawable [[buffer(1)]], device const LineSDFInterpolationUBO& interp [[buffer(2)]], device const LineEvaluatedPropsUBO& props [[buffer(4)]]) { @@ -747,7 +747,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], // calculate how much the perspective view squishes or stretches the extrude const float extrude_length_without_perspective = length(dist); - const float extrude_length_with_perspective = length(projected_extrude.xy / position.w * dynamic.units_to_pixels); + const float extrude_length_with_perspective = length(projected_extrude.xy / position.w * paintParams.units_to_pixels); return { .position = position, diff --git a/include/mbgl/shaders/mtl/raster.hpp b/include/mbgl/shaders/mtl/raster.hpp index 47d6a24b5..a6a489f46 100644 --- a/include/mbgl/shaders/mtl/raster.hpp +++ b/include/mbgl/shaders/mtl/raster.hpp @@ -22,8 +22,8 @@ struct ShaderSource { static constexpr auto source = R"( struct VertexStage { - short2 pos [[attribute(2)]]; - short2 texture_pos [[attribute(3)]]; + short2 pos [[attribute(3)]]; + short2 texture_pos [[attribute(4)]]; }; struct FragmentStage { @@ -37,7 +37,7 @@ struct alignas(16) RasterDrawableUBO { }; struct alignas(16) RasterEvaluatedPropsUBO { - float3 spin_weights; + float4 spin_weights; float2 tl_parent; float scale_parent; float buffer_scale; @@ -47,14 +47,12 @@ struct alignas(16) RasterEvaluatedPropsUBO { float brightness_high; float saturation_factor; float contrast_factor; - bool overdrawInspector; - uint8_t pad1, pad2, pad3; - float pad4; + float pad1, pad2; }; FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], - device const RasterDrawableUBO& drawable [[buffer(0)]], - device const RasterEvaluatedPropsUBO& props [[buffer(1)]]) { + device const RasterDrawableUBO& drawable [[buffer(1)]], + device const RasterEvaluatedPropsUBO& props [[buffer(2)]]) { const float4 position = drawable.matrix * float4(float2(vertx.pos), 0, 1); @@ -74,7 +72,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], } half4 fragment fragmentMain(FragmentStage in [[stage_in]], - device const RasterEvaluatedPropsUBO& props [[buffer(1)]], + device const RasterEvaluatedPropsUBO& props [[buffer(2)]], texture2d image0 [[texture(0)]], texture2d image1 [[texture(1)]], sampler image0_sampler [[sampler(0)]], diff --git a/include/mbgl/shaders/mtl/symbol_icon.hpp b/include/mbgl/shaders/mtl/symbol_icon.hpp index 3df3edc7d..9898812ab 100644 --- a/include/mbgl/shaders/mtl/symbol_icon.hpp +++ b/include/mbgl/shaders/mtl/symbol_icon.hpp @@ -46,7 +46,7 @@ struct FragmentStage { }; FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], - device const SymbolDynamicUBO& dynamic [[buffer(0)]], + device const GlobalPaintParamsUBO& paintParams [[buffer(0)]], device const SymbolDrawableUBO& drawable [[buffer(1)]], device const SymbolTilePropsUBO& tileprops [[buffer(2)]], device const SymbolInterpolateUBO& interp [[buffer(3)]], @@ -77,8 +77,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 = tileprops.pitch_with_map ? - camera_to_anchor_distance / dynamic.camera_to_center_distance : - dynamic.camera_to_center_distance / camera_to_anchor_distance; + camera_to_anchor_distance / paintParams.camera_to_center_distance : + paintParams.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 @@ -95,7 +95,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) / dynamic.aspect_ratio, b.x - a.x); + symbol_rotation = atan2((b.y - a.y) / paintParams.aspect_ratio, b.x - a.x); } const float angle_sin = sin(segment_angle + symbol_rotation); @@ -108,7 +108,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 raw_fade_opacity = unpack_opacity(vertx.fade_opacity); - const float fade_change = raw_fade_opacity[1] > 0.5 ? dynamic.fade_change : -dynamic.fade_change; + const float fade_change = raw_fade_opacity[1] > 0.5 ? paintParams.symbol_fade_change : -paintParams.symbol_fade_change; const float fade_opacity = max(0.0, min(1.0, raw_fade_opacity[0] + fade_change)); return { @@ -123,7 +123,6 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], } half4 fragment fragmentMain(FragmentStage in [[stage_in]], - device const SymbolDynamicUBO& dynamic [[buffer(0)]], device const SymbolDrawableUBO& drawable [[buffer(1)]], device const SymbolTilePropsUBO& tileprops [[buffer(2)]], device const SymbolEvaluatedPropsUBO& props [[buffer(4)]], diff --git a/include/mbgl/shaders/mtl/symbol_sdf.hpp b/include/mbgl/shaders/mtl/symbol_sdf.hpp index 8bd224085..6d793dae7 100644 --- a/include/mbgl/shaders/mtl/symbol_sdf.hpp +++ b/include/mbgl/shaders/mtl/symbol_sdf.hpp @@ -71,7 +71,7 @@ struct FragmentStage { }; FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], - device const SymbolDynamicUBO& dynamic [[buffer(0)]], + device const GlobalPaintParamsUBO& paintParams [[buffer(0)]], device const SymbolDrawableUBO& drawable [[buffer(1)]], device const SymbolTilePropsUBO& tileprops [[buffer(2)]], device const SymbolInterpolateUBO& interp [[buffer(3)]], @@ -106,8 +106,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 = tileprops.pitch_with_map ? - camera_to_anchor_distance / dynamic.camera_to_center_distance : - dynamic.camera_to_center_distance / camera_to_anchor_distance; + camera_to_anchor_distance / paintParams.camera_to_center_distance : + paintParams.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 @@ -127,7 +127,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) / dynamic.aspect_ratio, b.x - a.x); + symbol_rotation = atan2((b.y - a.y) / paintParams.aspect_ratio, b.x - a.x); } const float angle_sin = sin(segment_angle + symbol_rotation); @@ -138,7 +138,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], const float2 pos0 = projected_pos.xy / projected_pos.w + rotation_matrix * pos_rot; const float4 position = drawable.coord_matrix * float4(pos0, 0.0, 1.0); const float2 fade_opacity = unpack_opacity(vertx.fade_opacity); - const float fade_change = (fade_opacity[1] > 0.5) ? dynamic.fade_change : -dynamic.fade_change; + const float fade_change = (fade_opacity[1] > 0.5) ? paintParams.symbol_fade_change : -paintParams.symbol_fade_change; return { .position = position, @@ -165,7 +165,6 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], } half4 fragment fragmentMain(FragmentStage in [[stage_in]], - device const SymbolDynamicUBO& dynamic [[buffer(0)]], device const SymbolDrawableUBO& drawable [[buffer(1)]], device const SymbolTilePropsUBO& tileprops [[buffer(2)]], device const SymbolEvaluatedPropsUBO& props [[buffer(4)]], diff --git a/include/mbgl/shaders/mtl/symbol_text_and_icon.hpp b/include/mbgl/shaders/mtl/symbol_text_and_icon.hpp index 3daff244c..df00b2cb7 100644 --- a/include/mbgl/shaders/mtl/symbol_text_and_icon.hpp +++ b/include/mbgl/shaders/mtl/symbol_text_and_icon.hpp @@ -75,7 +75,7 @@ struct FragmentStage { }; FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], - device const SymbolDynamicUBO& dynamic [[buffer(0)]], + device const GlobalPaintParamsUBO& paintParams [[buffer(0)]], device const SymbolDrawableUBO& drawable [[buffer(1)]], device const SymbolTilePropsUBO& tileprops [[buffer(2)]], device const SymbolInterpolateUBO& interp [[buffer(3)]], @@ -110,8 +110,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 = tileprops.pitch_with_map ? - camera_to_anchor_distance / dynamic.camera_to_center_distance : - dynamic.camera_to_center_distance / camera_to_anchor_distance; + camera_to_anchor_distance / paintParams.camera_to_center_distance : + paintParams.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 @@ -131,7 +131,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) / dynamic.aspect_ratio, b.x - a.x); + symbol_rotation = atan2((b.y - a.y) / paintParams.aspect_ratio, b.x - a.x); } const float angle_sin = sin(segment_angle + symbol_rotation); @@ -145,7 +145,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) ? dynamic.fade_change : -dynamic.fade_change; + const float fade_change = (fade_opacity[1] > 0.5) ? paintParams.symbol_fade_change : -paintParams.symbol_fade_change; const bool is_icon = (is_sdf == ICON); return { @@ -175,7 +175,6 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], } half4 fragment fragmentMain(FragmentStage in [[stage_in]], - device const SymbolDynamicUBO& dynamic [[buffer(0)]], device const SymbolDrawableUBO& drawable [[buffer(1)]], device const SymbolTilePropsUBO& tileprops [[buffer(2)]], device const SymbolEvaluatedPropsUBO& props [[buffer(4)]], diff --git a/include/mbgl/shaders/mtl/widevector.hpp b/include/mbgl/shaders/mtl/widevector.hpp index d20d55657..2a49d68f5 100644 --- a/include/mbgl/shaders/mtl/widevector.hpp +++ b/include/mbgl/shaders/mtl/widevector.hpp @@ -23,10 +23,10 @@ struct ShaderSource { AttributeInfo{wideVectorUBOCount + 1, gfx::AttributeDataType::Float4, idWideVectorColor}, AttributeInfo{wideVectorUBOCount + 2, gfx::AttributeDataType::Int, idWideVectorIndex}}; static constexpr std::array instanceAttributes{ - AttributeInfo{5, gfx::AttributeDataType::Float3, idWideVectorInstanceCenter}, - AttributeInfo{5, gfx::AttributeDataType::Float4, idWideVectorInstanceColor}, - AttributeInfo{5, gfx::AttributeDataType::Int, idWideVectorInstancePrevious}, - AttributeInfo{5, gfx::AttributeDataType::Int, idWideVectorInstanceNext}}; + AttributeInfo{wideVectorUBOCount + 3, gfx::AttributeDataType::Float3, idWideVectorInstanceCenter}, + AttributeInfo{wideVectorUBOCount + 3, gfx::AttributeDataType::Float4, idWideVectorInstanceColor}, + AttributeInfo{wideVectorUBOCount + 3, gfx::AttributeDataType::Int, idWideVectorInstancePrevious}, + AttributeInfo{wideVectorUBOCount + 3, gfx::AttributeDataType::Int, idWideVectorInstanceNext}}; static constexpr std::array textures{}; static constexpr auto source = R"( @@ -112,9 +112,9 @@ typedef struct struct VertexTriWideVecB { // x, y offset around the center - float3 screenPos [[attribute(2)]]; - float4 color [[attribute(3)]]; - int index [[attribute(4)]]; + float3 screenPos [[attribute(3)]]; + float4 color [[attribute(4)]]; + int index [[attribute(5)]]; }; // Wide vector vertex passed to fragment shader (new version) @@ -221,10 +221,10 @@ constant constexpr float4 discardPt(0,0,-1e6,NAN); // Performance version of wide vector shader vertex ProjVertexTriWideVecPerf vertexTri_wideVecPerf( thread const VertexTriWideVecB vert [[ stage_in ]], - constant Uniforms &uniforms [[ buffer(0) ]], - constant UniformWideVec &wideVec [[ buffer(1) ]], + constant Uniforms &uniforms [[ buffer(1) ]], + constant UniformWideVec &wideVec [[ buffer(2) ]], uint instanceID [[ instance_id ]], - constant VertexTriWideVecInstance *wideVecInsts [[ buffer(5) ]]) + constant VertexTriWideVecInstance *wideVecInsts [[ buffer(6) ]]) { ProjVertexTriWideVecPerf outVert = { .position = discardPt, @@ -563,7 +563,7 @@ vertex ProjVertexTriWideVecPerf vertexTri_wideVecPerf( // Fragment shader that takes the back of the globe into account fragment float4 fragmentTri_wideVecPerf( ProjVertexTriWideVecPerf vert [[stage_in]], - constant Uniforms &uniforms [[ buffer(0) ]]) + constant Uniforms &uniforms [[ buffer(1) ]]) { float patternAlpha = 1.0; diff --git a/include/mbgl/shaders/raster_layer_ubo.hpp b/include/mbgl/shaders/raster_layer_ubo.hpp index 7f978193e..789cb597b 100644 --- a/include/mbgl/shaders/raster_layer_ubo.hpp +++ b/include/mbgl/shaders/raster_layer_ubo.hpp @@ -26,7 +26,7 @@ struct alignas(16) RasterEvaluatedPropsUBO { static_assert(sizeof(RasterEvaluatedPropsUBO) == 64); enum { - idRasterDrawableUBO, + idRasterDrawableUBO = globalUBOCount, idRasterEvaluatedPropsUBO, rasterUBOCount }; diff --git a/include/mbgl/shaders/shader_defines.hpp b/include/mbgl/shaders/shader_defines.hpp index f393fb379..937d6d499 100644 --- a/include/mbgl/shaders/shader_defines.hpp +++ b/include/mbgl/shaders/shader_defines.hpp @@ -23,7 +23,7 @@ namespace shaders { // UBO defines enum { - idClippingMaskUBO, + idClippingMaskUBO = globalUBOCount, clippingMaskUBOCount }; diff --git a/include/mbgl/shaders/symbol_layer_ubo.hpp b/include/mbgl/shaders/symbol_layer_ubo.hpp index 5c15e64c9..baf9b6928 100644 --- a/include/mbgl/shaders/symbol_layer_ubo.hpp +++ b/include/mbgl/shaders/symbol_layer_ubo.hpp @@ -5,16 +5,6 @@ namespace mbgl { namespace shaders { -/// Dynamic UBO -struct alignas(16) SymbolDynamicUBO { - /* 0 */ float fade_change; - /* 4 */ float camera_to_center_distance; - /* 8 */ float aspect_ratio; - /* 12 */ float pad; - /* 16 */ -}; -static_assert(sizeof(SymbolDynamicUBO) == 16); - struct alignas(16) SymbolDrawableUBO { /* 0 */ std::array matrix; /* 64 */ std::array label_plane_matrix; @@ -76,8 +66,7 @@ struct alignas(16) SymbolEvaluatedPropsUBO { static_assert(sizeof(SymbolEvaluatedPropsUBO) == 6 * 16); enum { - idSymbolDynamicUBO, - idSymbolDrawableUBO, + idSymbolDrawableUBO = globalUBOCount, idSymbolTilePropsUBO, idSymbolInterpolateUBO, idSymbolEvaluatedPropsUBO, diff --git a/include/mbgl/shaders/widevector_ubo.hpp b/include/mbgl/shaders/widevector_ubo.hpp index 208ed42d9..92a38dd2f 100644 --- a/include/mbgl/shaders/widevector_ubo.hpp +++ b/include/mbgl/shaders/widevector_ubo.hpp @@ -32,7 +32,7 @@ struct alignas(16) WideVectorUniformWideVecUBO { static_assert(sizeof(WideVectorUniformWideVecUBO) % 16 == 0); enum { - idWideVectorUniformsUBO, + idWideVectorUniformsUBO = globalUBOCount, idWideVectorUniformWideVecUBO, wideVectorUBOCount }; diff --git a/shaders/drawable.background_pattern.fragment.glsl b/shaders/drawable.background_pattern.fragment.glsl index 707f3cf06..f8ef5e7a5 100644 --- a/shaders/drawable.background_pattern.fragment.glsl +++ b/shaders/drawable.background_pattern.fragment.glsl @@ -1,16 +1,25 @@ +layout (std140) uniform GlobalPaintParamsUBO { + highp vec2 u_pattern_atlas_texsize; + highp vec2 u_units_to_pixels; + highp vec2 u_world_size; + highp float u_camera_to_center_distance; + highp float u_symbol_fade_change; + highp float u_aspect_ratio; + highp float u_pixel_ratio; + highp float global_pad1, global_pad2; +}; + layout (std140) uniform BackgroundPatternLayerUBO { highp vec2 u_pattern_tl_a; highp vec2 u_pattern_br_a; highp vec2 u_pattern_tl_b; highp vec2 u_pattern_br_b; - highp vec2 u_texsize; highp vec2 u_pattern_size_a; highp vec2 u_pattern_size_b; highp float u_scale_a; highp float u_scale_b; highp float u_mix; highp float u_opacity; - highp float layer_pad1, layer_pad2; }; uniform sampler2D u_image; @@ -20,11 +29,11 @@ in mediump vec2 v_pos_b; void main() { vec2 imagecoord = mod(v_pos_a, 1.0); - vec2 pos = mix(u_pattern_tl_a / u_texsize, u_pattern_br_a / u_texsize, imagecoord); + vec2 pos = mix(u_pattern_tl_a / u_pattern_atlas_texsize, u_pattern_br_a / u_pattern_atlas_texsize, imagecoord); vec4 color1 = texture(u_image, pos); vec2 imagecoord_b = mod(v_pos_b, 1.0); - vec2 pos2 = mix(u_pattern_tl_b / u_texsize, u_pattern_br_b / u_texsize, imagecoord_b); + vec2 pos2 = mix(u_pattern_tl_b / u_pattern_atlas_texsize, u_pattern_br_b / u_pattern_atlas_texsize, imagecoord_b); vec4 color2 = texture(u_image, pos2); fragColor = mix(color1, color2, u_mix) * u_opacity; diff --git a/shaders/drawable.background_pattern.vertex.glsl b/shaders/drawable.background_pattern.vertex.glsl index 982d370bd..5147bcbba 100644 --- a/shaders/drawable.background_pattern.vertex.glsl +++ b/shaders/drawable.background_pattern.vertex.glsl @@ -10,14 +10,12 @@ layout (std140) uniform BackgroundPatternLayerUBO { highp vec2 u_pattern_br_a; highp vec2 u_pattern_tl_b; highp vec2 u_pattern_br_b; - highp vec2 u_texsize; highp vec2 u_pattern_size_a; highp vec2 u_pattern_size_b; highp float u_scale_a; highp float u_scale_b; highp float u_mix; highp float u_opacity; - highp float layer_pad1, layer_pad2; }; layout (location = 0) in vec2 a_pos; diff --git a/shaders/drawable.circle.vertex.glsl b/shaders/drawable.circle.vertex.glsl index d86057e20..b3bcd07a1 100644 --- a/shaders/drawable.circle.vertex.glsl +++ b/shaders/drawable.circle.vertex.glsl @@ -1,18 +1,23 @@ layout (location = 0) in vec2 a_pos; out vec3 v_data; +layout (std140) uniform GlobalPaintParamsUBO { + highp vec2 u_pattern_atlas_texsize; + highp vec2 u_units_to_pixels; + highp vec2 u_world_size; + highp float u_camera_to_center_distance; + highp float u_symbol_fade_change; + highp float u_aspect_ratio; + highp float u_pixel_ratio; + highp float global_pad1, global_pad2; +}; + layout (std140) uniform CircleDrawableUBO { highp mat4 u_matrix; highp vec2 u_extrude_scale; lowp vec2 drawable_pad1; }; -layout (std140) uniform CirclePaintParamsUBO { - highp float u_camera_to_center_distance; - lowp float params_pad1; - lowp vec2 params_pad2; -}; - layout (std140) uniform CircleEvaluatedPropsUBO { highp vec4 u_color; highp vec4 u_stroke_color; diff --git a/shaders/drawable.collision_box.fragment.glsl b/shaders/drawable.collision_box.fragment.glsl index 6aad81ec5..81be488d0 100644 --- a/shaders/drawable.collision_box.fragment.glsl +++ b/shaders/drawable.collision_box.fragment.glsl @@ -1,7 +1,7 @@ -layout (std140) uniform CollisionBoxUBO { +layout (std140) uniform CollisionUBO { highp mat4 u_matrix; highp vec2 u_extrude_scale; - highp float u_camera_to_center_distance; + highp float u_overscale_factor; highp float pad1; }; diff --git a/shaders/drawable.collision_box.vertex.glsl b/shaders/drawable.collision_box.vertex.glsl index 8c2b28ee3..da1ddd393 100644 --- a/shaders/drawable.collision_box.vertex.glsl +++ b/shaders/drawable.collision_box.vertex.glsl @@ -4,10 +4,21 @@ layout (location = 2) in vec2 a_extrude; layout (location = 3) in vec2 a_placed; layout (location = 4) in vec2 a_shift; -layout (std140) uniform CollisionBoxUBO { +layout (std140) uniform GlobalPaintParamsUBO { + highp vec2 u_pattern_atlas_texsize; + highp vec2 u_units_to_pixels; + highp vec2 u_world_size; + highp float u_camera_to_center_distance; + highp float u_symbol_fade_change; + highp float u_aspect_ratio; + highp float u_pixel_ratio; + highp float global_pad1, global_pad2; +}; + +layout (std140) uniform CollisionUBO { highp mat4 u_matrix; highp vec2 u_extrude_scale; - highp float u_camera_to_center_distance; + highp float u_overscale_factor; highp float pad1; }; diff --git a/shaders/drawable.collision_circle.fragment.glsl b/shaders/drawable.collision_circle.fragment.glsl index 370020015..338070a2b 100644 --- a/shaders/drawable.collision_circle.fragment.glsl +++ b/shaders/drawable.collision_circle.fragment.glsl @@ -1,8 +1,19 @@ -layout (std140) uniform CollisionCircleUBO { +layout (std140) uniform GlobalPaintParamsUBO { + highp vec2 u_pattern_atlas_texsize; + highp vec2 u_units_to_pixels; + highp vec2 u_world_size; + highp float u_camera_to_center_distance; + highp float u_symbol_fade_change; + highp float u_aspect_ratio; + highp float u_pixel_ratio; + highp float global_pad1, global_pad2; +}; + +layout (std140) uniform CollisionUBO { highp mat4 u_matrix; highp vec2 u_extrude_scale; - highp float u_camera_to_center_distance; highp float u_overscale_factor; + highp float pad1; }; in float v_placed; diff --git a/shaders/drawable.collision_circle.vertex.glsl b/shaders/drawable.collision_circle.vertex.glsl index 1e19b93b5..92f325c8f 100644 --- a/shaders/drawable.collision_circle.vertex.glsl +++ b/shaders/drawable.collision_circle.vertex.glsl @@ -3,11 +3,22 @@ layout (location = 1) in vec2 a_anchor_pos; layout (location = 2) in vec2 a_extrude; layout (location = 3) in vec2 a_placed; -layout (std140) uniform CollisionCircleUBO { +layout (std140) uniform GlobalPaintParamsUBO { + highp vec2 u_pattern_atlas_texsize; + highp vec2 u_units_to_pixels; + highp vec2 u_world_size; + highp float u_camera_to_center_distance; + highp float u_symbol_fade_change; + highp float u_aspect_ratio; + highp float u_pixel_ratio; + highp float global_pad1, global_pad2; +}; + +layout (std140) uniform CollisionUBO { highp mat4 u_matrix; highp vec2 u_extrude_scale; - highp float u_camera_to_center_distance; highp float u_overscale_factor; + highp float pad1; }; out float v_placed; diff --git a/shaders/drawable.fill.fragment.glsl b/shaders/drawable.fill.fragment.glsl index 2acc814b8..0e0aed6c7 100644 --- a/shaders/drawable.fill.fragment.glsl +++ b/shaders/drawable.fill.fragment.glsl @@ -8,8 +8,8 @@ layout (std140) uniform FillEvaluatedPropsUBO { highp vec4 u_outline_color; highp float u_opacity; highp float u_fade; - highp float u_width; - highp float props_pad1; + highp float u_from_scale; + highp float u_to_scale; }; #pragma mapbox: define highp vec4 color diff --git a/shaders/drawable.fill.vertex.glsl b/shaders/drawable.fill.vertex.glsl index a47c00116..caffecd54 100644 --- a/shaders/drawable.fill.vertex.glsl +++ b/shaders/drawable.fill.vertex.glsl @@ -11,8 +11,8 @@ layout (std140) uniform FillEvaluatedPropsUBO { highp vec4 u_outline_color; highp float u_opacity; highp float u_fade; - highp float u_width; - highp float props_pad1; + highp float u_from_scale; + highp float u_to_scale; }; layout (location = 0) in vec2 a_pos; diff --git a/shaders/drawable.fill_extrusion.vertex.glsl b/shaders/drawable.fill_extrusion.vertex.glsl index 00e302f4a..79c7429bd 100644 --- a/shaders/drawable.fill_extrusion.vertex.glsl +++ b/shaders/drawable.fill_extrusion.vertex.glsl @@ -4,12 +4,11 @@ out vec4 v_color; layout (std140) uniform FillExtrusionDrawableUBO { highp mat4 u_matrix; - highp vec4 u_scale; highp vec2 u_texsize; highp vec2 u_pixel_coord_upper; highp vec2 u_pixel_coord_lower; highp float u_height_factor; - highp float drawable_pad1; + highp float u_tile_ratio; }; layout (std140) uniform FillExtrusionPropsUBO { highp vec4 u_color; @@ -22,7 +21,9 @@ layout (std140) uniform FillExtrusionPropsUBO { highp float u_vertical_gradient; highp float u_opacity; highp float u_fade; - highp float props_pad2, props_pad3, props_pad4; + highp float u_from_scale; + highp float u_to_scale; + highp float props_pad2; }; layout (std140) uniform FillExtrusionTilePropsUBO { highp vec4 u_pattern_from; diff --git a/shaders/drawable.fill_extrusion_pattern.fragment.glsl b/shaders/drawable.fill_extrusion_pattern.fragment.glsl index 110759f80..0f6d4b717 100644 --- a/shaders/drawable.fill_extrusion_pattern.fragment.glsl +++ b/shaders/drawable.fill_extrusion_pattern.fragment.glsl @@ -4,12 +4,11 @@ in vec4 v_lighting; layout (std140) uniform FillExtrusionDrawableUBO { highp mat4 u_matrix; - highp vec4 u_scale; highp vec2 u_texsize; highp vec2 u_pixel_coord_upper; highp vec2 u_pixel_coord_lower; highp float u_height_factor; - highp float drawable_pad1; + highp float u_tile_ratio; }; layout (std140) uniform FillExtrusionPropsUBO { highp vec4 u_color; @@ -22,7 +21,9 @@ layout (std140) uniform FillExtrusionPropsUBO { highp float u_vertical_gradient; highp float u_opacity; highp float u_fade; - highp float props_pad2, props_pad3, props_pad4; + highp float u_from_scale; + highp float u_to_scale; + highp float props_pad2; }; layout (std140) uniform FillExtrusionTilePropsUBO { highp vec4 u_pattern_from; diff --git a/shaders/drawable.fill_extrusion_pattern.vertex.glsl b/shaders/drawable.fill_extrusion_pattern.vertex.glsl index 767f779a4..bc0d9b09b 100644 --- a/shaders/drawable.fill_extrusion_pattern.vertex.glsl +++ b/shaders/drawable.fill_extrusion_pattern.vertex.glsl @@ -5,14 +5,24 @@ out vec2 v_pos_a; out vec2 v_pos_b; out vec4 v_lighting; +layout (std140) uniform GlobalPaintParamsUBO { + highp vec2 u_pattern_atlas_texsize; + highp vec2 u_units_to_pixels; + highp vec2 u_world_size; + highp float u_camera_to_center_distance; + highp float u_symbol_fade_change; + highp float u_aspect_ratio; + highp float u_pixel_ratio; + highp float global_pad1, global_pad2; +}; + layout (std140) uniform FillExtrusionDrawableUBO { highp mat4 u_matrix; - highp vec4 u_scale; highp vec2 u_texsize; highp vec2 u_pixel_coord_upper; highp vec2 u_pixel_coord_lower; highp float u_height_factor; - highp float drawable_pad1; + highp float u_tile_ratio; }; layout (std140) uniform FillExtrusionPropsUBO { highp vec4 u_color; @@ -25,7 +35,9 @@ layout (std140) uniform FillExtrusionPropsUBO { highp float u_vertical_gradient; highp float u_opacity; highp float u_fade; - highp float props_pad2, props_pad3, props_pad4; + highp float u_from_scale; + highp float u_to_scale; + highp float props_pad2; }; layout (std140) uniform FillExtrusionTilePropsUBO { highp vec4 u_pattern_from; @@ -56,10 +68,10 @@ void main() { vec2 pattern_tl_b = pattern_to.xy; vec2 pattern_br_b = pattern_to.zw; - float pixelRatio = u_scale.x; - float tileRatio = u_scale.y; - float fromScale = u_scale.z; - float toScale = u_scale.w; + float pixelRatio = u_pixel_ratio; + float tileRatio = u_tile_ratio; + float fromScale = u_from_scale; + float toScale = u_to_scale; vec3 normal = a_normal_ed.xyz; float edgedistance = a_normal_ed.w; diff --git a/shaders/drawable.fill_outline.fragment.glsl b/shaders/drawable.fill_outline.fragment.glsl index a9b53443e..2b795274a 100644 --- a/shaders/drawable.fill_outline.fragment.glsl +++ b/shaders/drawable.fill_outline.fragment.glsl @@ -9,8 +9,8 @@ layout (std140) uniform FillEvaluatedPropsUBO { highp vec4 u_outline_color; highp float u_opacity; highp float u_fade; - highp float u_width; - highp float props_pad1; + highp float u_from_scale; + highp float u_to_scale; }; in vec2 v_pos; diff --git a/shaders/drawable.fill_outline.vertex.glsl b/shaders/drawable.fill_outline.vertex.glsl index e3d484e55..9e255d162 100644 --- a/shaders/drawable.fill_outline.vertex.glsl +++ b/shaders/drawable.fill_outline.vertex.glsl @@ -1,7 +1,15 @@ +layout (std140) uniform GlobalPaintParamsUBO { + highp vec2 u_pattern_atlas_texsize; + highp vec2 u_units_to_pixels; + highp vec2 u_world_size; + highp float u_camera_to_center_distance; + highp float u_symbol_fade_change; + highp float u_aspect_ratio; + highp float u_pixel_ratio; + highp float global_pad1, global_pad2; +}; layout (std140) uniform FillOutlineDrawableUBO { highp mat4 u_matrix; - highp vec2 u_world; - highp vec2 drawable_pad1; }; layout (std140) uniform FillOutlineInterpolateUBO { highp float u_outline_color_t; @@ -14,8 +22,8 @@ layout (std140) uniform FillEvaluatedPropsUBO { highp vec4 u_outline_color; highp float u_opacity; highp float u_fade; - highp float u_width; - highp float props_pad1; + highp float u_from_scale; + highp float u_to_scale; }; layout (location = 0) in vec2 a_pos; @@ -30,5 +38,5 @@ void main() { #pragma mapbox: initialize lowp float opacity gl_Position = u_matrix * vec4(a_pos, 0, 1); - v_pos = (gl_Position.xy / gl_Position.w + 1.0) / 2.0 * u_world; + v_pos = (gl_Position.xy / gl_Position.w + 1.0) / 2.0 * u_world_size; } diff --git a/shaders/drawable.fill_outline_pattern.fragment.glsl b/shaders/drawable.fill_outline_pattern.fragment.glsl index fdb1009d0..21c8a683a 100644 --- a/shaders/drawable.fill_outline_pattern.fragment.glsl +++ b/shaders/drawable.fill_outline_pattern.fragment.glsl @@ -1,10 +1,10 @@ layout (std140) uniform FillOutlinePatternDrawableUBO { highp mat4 u_matrix; - highp vec4 u_scale; - highp vec2 u_world; highp vec2 u_pixel_coord_upper; highp vec2 u_pixel_coord_lower; highp vec2 u_texsize; + highp float u_tile_ratio; + highp float drawable_pad1; }; layout (std140) uniform FillOutlinePatternTilePropsUBO { highp vec4 u_pattern_from; @@ -21,8 +21,8 @@ layout (std140) uniform FillEvaluatedPropsUBO { highp vec4 u_outline_color; highp float u_opacity; highp float u_fade; - highp float u_width; - highp float props_pad1; + highp float u_from_scale; + highp float u_to_scale; }; uniform sampler2D u_image; diff --git a/shaders/drawable.fill_outline_pattern.vertex.glsl b/shaders/drawable.fill_outline_pattern.vertex.glsl index f11fe5fa2..d7be97bf8 100644 --- a/shaders/drawable.fill_outline_pattern.vertex.glsl +++ b/shaders/drawable.fill_outline_pattern.vertex.glsl @@ -1,10 +1,20 @@ +layout (std140) uniform GlobalPaintParamsUBO { + highp vec2 u_pattern_atlas_texsize; + highp vec2 u_units_to_pixels; + highp vec2 u_world_size; + highp float u_camera_to_center_distance; + highp float u_symbol_fade_change; + highp float u_aspect_ratio; + highp float u_pixel_ratio; + highp float global_pad1, global_pad2; +}; layout (std140) uniform FillOutlinePatternDrawableUBO { highp mat4 u_matrix; - highp vec4 u_scale; - highp vec2 u_world; highp vec2 u_pixel_coord_upper; highp vec2 u_pixel_coord_lower; highp vec2 u_texsize; + highp float u_tile_ratio; + highp float drawable_pad1; }; layout (std140) uniform FillOutlinePatternTilePropsUBO { highp vec4 u_pattern_from; @@ -21,8 +31,8 @@ layout (std140) uniform FillEvaluatedPropsUBO { highp vec4 u_outline_color; highp float u_opacity; highp float u_fade; - highp float u_width; - highp float props_pad1; + highp float u_from_scale; + highp float u_to_scale; }; layout (location = 0) in vec2 a_pos; @@ -45,10 +55,10 @@ void main() { vec2 pattern_tl_b = pattern_to.xy; vec2 pattern_br_b = pattern_to.zw; - float pixelRatio = u_scale.x; - float tileRatio = u_scale.y; - float fromScale = u_scale.z; - float toScale = u_scale.w; + float pixelRatio = u_pixel_ratio; + float tileRatio = u_tile_ratio; + float fromScale = u_from_scale; + float toScale = u_to_scale; gl_Position = u_matrix * vec4(a_pos, 0, 1); @@ -58,5 +68,5 @@ void main() { v_pos_a = get_pattern_pos(u_pixel_coord_upper, u_pixel_coord_lower, fromScale * display_size_a, tileRatio, a_pos); v_pos_b = get_pattern_pos(u_pixel_coord_upper, u_pixel_coord_lower, toScale * display_size_b, tileRatio, a_pos); - v_pos = (gl_Position.xy / gl_Position.w + 1.0) / 2.0 * u_world; + v_pos = (gl_Position.xy / gl_Position.w + 1.0) / 2.0 * u_world_size; } diff --git a/shaders/drawable.fill_outline_triangulated.fragment.glsl b/shaders/drawable.fill_outline_triangulated.fragment.glsl index 88ca6f1ac..cacaf1dc3 100644 --- a/shaders/drawable.fill_outline_triangulated.fragment.glsl +++ b/shaders/drawable.fill_outline_triangulated.fragment.glsl @@ -3,8 +3,8 @@ layout (std140) uniform FillEvaluatedPropsUBO { highp vec4 u_outline_color; highp float u_opacity; highp float u_fade; - highp float u_width; - highp float props_pad1; + highp float u_from_scale; + highp float u_to_scale; }; in float v_width; diff --git a/shaders/drawable.fill_outline_triangulated.vertex.glsl b/shaders/drawable.fill_outline_triangulated.vertex.glsl index db0c4d917..ed21764a6 100644 --- a/shaders/drawable.fill_outline_triangulated.vertex.glsl +++ b/shaders/drawable.fill_outline_triangulated.vertex.glsl @@ -9,19 +9,28 @@ layout (location = 0) in vec2 a_pos_normal; layout (location = 1) in vec4 a_data; +layout (std140) uniform GlobalPaintParamsUBO { + highp vec2 u_pattern_atlas_texsize; + highp vec2 u_units_to_pixels; + highp vec2 u_world_size; + highp float u_camera_to_center_distance; + highp float u_symbol_fade_change; + highp float u_aspect_ratio; + highp float u_pixel_ratio; + highp float global_pad1, global_pad2; +}; layout (std140) uniform FillOutlineTriangulatedDrawableUBO { highp mat4 u_matrix; - highp vec2 u_units_to_pixels; mediump float u_ratio; - lowp float drawable_pad1; + lowp float drawable_pad1, drawable_pad2, drawable_pad3; }; layout (std140) uniform FillEvaluatedPropsUBO { highp vec4 u_color; highp vec4 u_outline_color; highp float u_opacity; highp float u_fade; - highp float u_width; - highp float props_pad1; + highp float u_from_scale; + highp float u_to_scale; }; out vec2 v_normal; diff --git a/shaders/drawable.fill_pattern.fragment.glsl b/shaders/drawable.fill_pattern.fragment.glsl index 20be632b4..54b657cce 100644 --- a/shaders/drawable.fill_pattern.fragment.glsl +++ b/shaders/drawable.fill_pattern.fragment.glsl @@ -1,11 +1,10 @@ layout (std140) uniform FillPatternDrawableUBO { highp mat4 u_matrix; - highp vec4 u_scale; highp vec2 u_pixel_coord_upper; highp vec2 u_pixel_coord_lower; highp vec2 u_texsize; + highp float u_tile_ratio; highp float drawable_pad1; - highp float drawable_pad2; }; layout (std140) uniform FillPatternTilePropsUBO { highp vec4 u_pattern_from; @@ -22,8 +21,8 @@ layout (std140) uniform FillEvaluatedPropsUBO { highp vec4 u_outline_color; highp float u_opacity; highp float u_fade; - highp float u_width; - highp float props_pad1; + highp float u_from_scale; + highp float u_to_scale; }; uniform sampler2D u_image; diff --git a/shaders/drawable.fill_pattern.vertex.glsl b/shaders/drawable.fill_pattern.vertex.glsl index f44da587d..ba738168e 100644 --- a/shaders/drawable.fill_pattern.vertex.glsl +++ b/shaders/drawable.fill_pattern.vertex.glsl @@ -1,11 +1,20 @@ +layout (std140) uniform GlobalPaintParamsUBO { + highp vec2 u_pattern_atlas_texsize; + highp vec2 u_units_to_pixels; + highp vec2 u_world_size; + highp float u_camera_to_center_distance; + highp float u_symbol_fade_change; + highp float u_aspect_ratio; + highp float u_pixel_ratio; + highp float global_pad1, global_pad2; +}; layout (std140) uniform FillPatternDrawableUBO { highp mat4 u_matrix; - highp vec4 u_scale; highp vec2 u_pixel_coord_upper; highp vec2 u_pixel_coord_lower; highp vec2 u_texsize; + highp float u_tile_ratio; highp float drawable_pad1; - highp float drawable_pad2; }; layout (std140) uniform FillPatternTilePropsUBO { highp vec4 u_pattern_from; @@ -22,8 +31,8 @@ layout (std140) uniform FillEvaluatedPropsUBO { highp vec4 u_outline_color; highp float u_opacity; highp float u_fade; - highp float u_width; - highp float props_pad1; + highp float u_from_scale; + highp float u_to_scale; }; layout (location = 0) in vec2 a_pos; @@ -45,10 +54,10 @@ void main() { vec2 pattern_tl_b = pattern_to.xy; vec2 pattern_br_b = pattern_to.zw; - float pixelRatio = u_scale.x; - float tileZoomRatio = u_scale.y; - float fromScale = u_scale.z; - float toScale = u_scale.w; + float pixelRatio = u_pixel_ratio; + float tileZoomRatio = u_tile_ratio; + float fromScale = u_from_scale; + float toScale = u_to_scale; vec2 display_size_a = vec2((pattern_br_a.x - pattern_tl_a.x) / pixelRatio, (pattern_br_a.y - pattern_tl_a.y) / pixelRatio); vec2 display_size_b = vec2((pattern_br_b.x - pattern_tl_b.x) / pixelRatio, (pattern_br_b.y - pattern_tl_b.y) / pixelRatio); diff --git a/shaders/drawable.heatmap_texture.fragment.glsl b/shaders/drawable.heatmap_texture.fragment.glsl index 0edacf1af..0d08fa736 100644 --- a/shaders/drawable.heatmap_texture.fragment.glsl +++ b/shaders/drawable.heatmap_texture.fragment.glsl @@ -4,9 +4,8 @@ uniform sampler2D u_color_ramp; layout (std140) uniform HeatmapTexturePropsUBO { highp mat4 u_matrix; - highp vec2 u_world; highp float u_opacity; - lowp float props_pad1; + lowp float props_pad1, props_pad2, props_pad3; }; void main() { diff --git a/shaders/drawable.heatmap_texture.vertex.glsl b/shaders/drawable.heatmap_texture.vertex.glsl index 3b6e26d72..272f36924 100644 --- a/shaders/drawable.heatmap_texture.vertex.glsl +++ b/shaders/drawable.heatmap_texture.vertex.glsl @@ -1,15 +1,24 @@ layout (location = 0) in vec2 a_pos; out vec2 v_pos; +layout (std140) uniform GlobalPaintParamsUBO { + highp vec2 u_pattern_atlas_texsize; + highp vec2 u_units_to_pixels; + highp vec2 u_world_size; + highp float u_camera_to_center_distance; + highp float u_symbol_fade_change; + highp float u_aspect_ratio; + highp float u_pixel_ratio; + highp float global_pad1, global_pad2; +}; layout (std140) uniform HeatmapTexturePropsUBO { highp mat4 u_matrix; - highp vec2 u_world; highp float u_opacity; - lowp float props_pad1; + lowp float props_pad1, props_pad2, props_pad3; }; void main() { - gl_Position = u_matrix * vec4(a_pos * u_world, 0, 1); + gl_Position = u_matrix * vec4(a_pos * u_world_size, 0, 1); v_pos.x = a_pos.x; v_pos.y = 1.0 - a_pos.y; diff --git a/shaders/drawable.line.vertex.glsl b/shaders/drawable.line.vertex.glsl index 32d43d856..da69b172c 100644 --- a/shaders/drawable.line.vertex.glsl +++ b/shaders/drawable.line.vertex.glsl @@ -9,9 +9,15 @@ layout (location = 0) in vec2 a_pos_normal; layout (location = 1) in vec4 a_data; -layout (std140) uniform LineDynamicUBO { +layout (std140) uniform GlobalPaintParamsUBO { + highp vec2 u_pattern_atlas_texsize; highp vec2 u_units_to_pixels; - lowp float dynamic_pad1, dynamic_pad2; + highp vec2 u_world_size; + highp float u_camera_to_center_distance; + highp float u_symbol_fade_change; + highp float u_aspect_ratio; + highp float u_pixel_ratio; + highp float global_pad1, global_pad2; }; layout (std140) uniform LineDrawableUBO { diff --git a/shaders/drawable.line_gradient.vertex.glsl b/shaders/drawable.line_gradient.vertex.glsl index 38ae13910..41bff8228 100644 --- a/shaders/drawable.line_gradient.vertex.glsl +++ b/shaders/drawable.line_gradient.vertex.glsl @@ -13,9 +13,15 @@ layout (location = 0) in vec2 a_pos_normal; layout (location = 1) in vec4 a_data; -layout (std140) uniform LineDynamicUBO { +layout (std140) uniform GlobalPaintParamsUBO { + highp vec2 u_pattern_atlas_texsize; highp vec2 u_units_to_pixels; - lowp float dynamic_pad1, dynamic_pad2; + highp vec2 u_world_size; + highp float u_camera_to_center_distance; + highp float u_symbol_fade_change; + highp float u_aspect_ratio; + highp float u_pixel_ratio; + highp float global_pad1, global_pad2; }; layout (std140) uniform LineGradientDrawableUBO { diff --git a/shaders/drawable.line_pattern.vertex.glsl b/shaders/drawable.line_pattern.vertex.glsl index 714440ad7..e573d9a36 100644 --- a/shaders/drawable.line_pattern.vertex.glsl +++ b/shaders/drawable.line_pattern.vertex.glsl @@ -13,9 +13,15 @@ layout (location = 0) in vec2 a_pos_normal; layout (location = 1) in vec4 a_data; -layout (std140) uniform LineDynamicUBO { +layout (std140) uniform GlobalPaintParamsUBO { + highp vec2 u_pattern_atlas_texsize; highp vec2 u_units_to_pixels; - lowp float dynamic_pad1, dynamic_pad2; + highp vec2 u_world_size; + highp float u_camera_to_center_distance; + highp float u_symbol_fade_change; + highp float u_aspect_ratio; + highp float u_pixel_ratio; + highp float global_pad1, global_pad2; }; layout (std140) uniform LinePatternDrawableUBO { diff --git a/shaders/drawable.line_sdf.vertex.glsl b/shaders/drawable.line_sdf.vertex.glsl index 63cbd5127..98ce3b981 100644 --- a/shaders/drawable.line_sdf.vertex.glsl +++ b/shaders/drawable.line_sdf.vertex.glsl @@ -13,9 +13,15 @@ layout (location = 0) in vec2 a_pos_normal; layout (location = 1) in vec4 a_data; -layout (std140) uniform LineDynamicUBO { +layout (std140) uniform GlobalPaintParamsUBO { + highp vec2 u_pattern_atlas_texsize; highp vec2 u_units_to_pixels; - lowp float dynamic_pad1, dynamic_pad2; + highp vec2 u_world_size; + highp float u_camera_to_center_distance; + highp float u_symbol_fade_change; + highp float u_aspect_ratio; + highp float u_pixel_ratio; + highp float global_pad1, global_pad2; }; layout (std140) uniform LineSDFDrawableUBO { diff --git a/shaders/drawable.symbol_icon.vertex.glsl b/shaders/drawable.symbol_icon.vertex.glsl index 95bd7ea31..6bbd66d1e 100644 --- a/shaders/drawable.symbol_icon.vertex.glsl +++ b/shaders/drawable.symbol_icon.vertex.glsl @@ -4,11 +4,15 @@ layout (location = 2) in vec4 a_pixeloffset; layout (location = 3) in vec3 a_projected_pos; layout (location = 4) in float a_fade_opacity; -layout (std140) uniform SymbolDynamicUBO { - highp float u_fade_change; +layout (std140) uniform GlobalPaintParamsUBO { + highp vec2 u_pattern_atlas_texsize; + highp vec2 u_units_to_pixels; + highp vec2 u_world_size; highp float u_camera_to_center_distance; + highp float u_symbol_fade_change; highp float u_aspect_ratio; - highp float dynamic_pad1; + highp float u_pixel_ratio; + highp float global_pad1, global_pad2; }; layout (std140) uniform SymbolDrawableUBO { @@ -125,6 +129,6 @@ void main() { v_tex = a_tex / u_texsize; vec2 fade_opacity = unpack_opacity(a_fade_opacity); - float fade_change = fade_opacity[1] > 0.5 ? u_fade_change : -u_fade_change; + float fade_change = fade_opacity[1] > 0.5 ? u_symbol_fade_change : -u_symbol_fade_change; v_fade_opacity = max(0.0, min(1.0, fade_opacity[0] + fade_change)); } diff --git a/shaders/drawable.symbol_sdf.fragment.glsl b/shaders/drawable.symbol_sdf.fragment.glsl index 1ed1867ec..562401776 100644 --- a/shaders/drawable.symbol_sdf.fragment.glsl +++ b/shaders/drawable.symbol_sdf.fragment.glsl @@ -1,12 +1,5 @@ #define SDF_PX 8.0 -layout (std140) uniform SymbolDynamicUBO { - highp float u_fade_change; - highp float u_camera_to_center_distance; - highp float u_aspect_ratio; - highp float dynamic_pad1; -}; - layout (std140) uniform SymbolDrawableUBO { highp mat4 u_matrix; highp mat4 u_label_plane_matrix; diff --git a/shaders/drawable.symbol_sdf.vertex.glsl b/shaders/drawable.symbol_sdf.vertex.glsl index 948fe46ec..64ea45be7 100644 --- a/shaders/drawable.symbol_sdf.vertex.glsl +++ b/shaders/drawable.symbol_sdf.vertex.glsl @@ -12,11 +12,15 @@ layout (location = 4) in float a_fade_opacity; // [ text-size(lowerZoomStop, feature), // text-size(upperZoomStop, feature) ] -layout (std140) uniform SymbolDynamicUBO { - highp float u_fade_change; +layout (std140) uniform GlobalPaintParamsUBO { + highp vec2 u_pattern_atlas_texsize; + highp vec2 u_units_to_pixels; + highp vec2 u_world_size; highp float u_camera_to_center_distance; + highp float u_symbol_fade_change; highp float u_aspect_ratio; - highp float dynamic_pad1; + highp float u_pixel_ratio; + highp float global_pad1, global_pad2; }; layout (std140) uniform SymbolDrawableUBO { @@ -151,7 +155,7 @@ void main() { float gamma_scale = gl_Position.w; vec2 fade_opacity = unpack_opacity(a_fade_opacity); - float fade_change = fade_opacity[1] > 0.5 ? u_fade_change : -u_fade_change; + float fade_change = fade_opacity[1] > 0.5 ? u_symbol_fade_change : -u_symbol_fade_change; float interpolated_fade_opacity = max(0.0, min(1.0, fade_opacity[0] + fade_change)); v_data0 = a_tex / u_texsize; diff --git a/shaders/drawable.symbol_text_and_icon.fragment.glsl b/shaders/drawable.symbol_text_and_icon.fragment.glsl index fead23007..3438e655b 100644 --- a/shaders/drawable.symbol_text_and_icon.fragment.glsl +++ b/shaders/drawable.symbol_text_and_icon.fragment.glsl @@ -3,13 +3,6 @@ #define SDF 1.0 #define ICON 0.0 -layout (std140) uniform SymbolDynamicUBO { - highp float u_fade_change; - highp float u_camera_to_center_distance; - highp float u_aspect_ratio; - highp float dynamic_pad1; -}; - layout (std140) uniform SymbolDrawableUBO { highp mat4 u_matrix; highp mat4 u_label_plane_matrix; diff --git a/shaders/drawable.symbol_text_and_icon.vertex.glsl b/shaders/drawable.symbol_text_and_icon.vertex.glsl index 0eb5b70fd..d183ba432 100644 --- a/shaders/drawable.symbol_text_and_icon.vertex.glsl +++ b/shaders/drawable.symbol_text_and_icon.vertex.glsl @@ -11,11 +11,15 @@ layout (location = 3) in float a_fade_opacity; // [ text-size(lowerZoomStop, feature), // text-size(upperZoomStop, feature) ] -layout (std140) uniform SymbolDynamicUBO { - highp float u_fade_change; +layout (std140) uniform GlobalPaintParamsUBO { + highp vec2 u_pattern_atlas_texsize; + highp vec2 u_units_to_pixels; + highp vec2 u_world_size; highp float u_camera_to_center_distance; + highp float u_symbol_fade_change; highp float u_aspect_ratio; - highp float dynamic_pad1; + highp float u_pixel_ratio; + highp float global_pad1, global_pad2; }; layout (std140) uniform SymbolDrawableUBO { @@ -150,7 +154,7 @@ void main() { float gamma_scale = gl_Position.w; vec2 fade_opacity = unpack_opacity(a_fade_opacity); - float fade_change = fade_opacity[1] > 0.5 ? u_fade_change : -u_fade_change; + float fade_change = fade_opacity[1] > 0.5 ? u_symbol_fade_change : -u_symbol_fade_change; float interpolated_fade_opacity = max(0.0, min(1.0, fade_opacity[0] + fade_change)); v_data0.xy = a_tex / u_texsize; diff --git a/src/mbgl/gl/context.cpp b/src/mbgl/gl/context.cpp index 87d0dad5e..8632134d2 100644 --- a/src/mbgl/gl/context.cpp +++ b/src/mbgl/gl/context.cpp @@ -486,6 +486,29 @@ bool Context::emplaceOrUpdateUniformBuffer(gfx::UniformBufferPtr& buffer, return true; } } + +void Context::bindGlobalUniformBuffers(gfx::RenderPass&) const noexcept { + for (size_t id = 0; id < globalUniformBuffers.allocatedSize(); id++) { + const auto& globalUniformBuffer = globalUniformBuffers.get(id); + if (!globalUniformBuffer) continue; + GLint binding = static_cast(id); + const auto& uniformBufferGL = static_cast(*globalUniformBuffer); + MBGL_CHECK_ERROR(glBindBufferRange(GL_UNIFORM_BUFFER, + binding, + uniformBufferGL.getID(), + uniformBufferGL.getManagedBuffer().getBindingOffset(), + uniformBufferGL.getSize())); + } +} + +void Context::unbindGlobalUniformBuffers(gfx::RenderPass&) const noexcept { + for (size_t id = 0; id < globalUniformBuffers.allocatedSize(); id++) { + const auto& globalUniformBuffer = globalUniformBuffers.get(id); + if (!globalUniformBuffer) continue; + GLint binding = static_cast(id); + MBGL_CHECK_ERROR(glBindBufferBase(GL_UNIFORM_BUFFER, binding, 0)); + } +} #endif void Context::setDirtyState() { diff --git a/src/mbgl/gl/context.hpp b/src/mbgl/gl/context.hpp index a0d684da8..5e8a06968 100644 --- a/src/mbgl/gl/context.hpp +++ b/src/mbgl/gl/context.hpp @@ -19,6 +19,7 @@ #include #include #include +#include #endif #include @@ -134,6 +135,18 @@ public: const void* data, std::size_t size, bool persistent) override; + + /// Get the global uniform buffers + const gfx::UniformBufferArray& getGlobalUniformBuffers() const override { return globalUniformBuffers; }; + + /// Get the mutable global uniform buffer array + gfx::UniformBufferArray& mutableGlobalUniformBuffers() override { return globalUniformBuffers; }; + + /// Bind the global uniform buffers + void bindGlobalUniformBuffers(gfx::RenderPass&) const noexcept override; + + /// Unbind the global uniform buffers + void unbindGlobalUniformBuffers(gfx::RenderPass&) const noexcept override; #endif void setDirtyState() override; @@ -147,6 +160,7 @@ private: std::shared_ptr frameInFlightFence; std::unique_ptr uboAllocator; size_t frameNum = 0; + UniformBufferArrayGL globalUniformBuffers; #endif public: diff --git a/src/mbgl/mtl/context.cpp b/src/mbgl/mtl/context.cpp index 0d1e036de..84ab6ab75 100644 --- a/src/mbgl/mtl/context.cpp +++ b/src/mbgl/mtl/context.cpp @@ -55,6 +55,10 @@ Context::~Context() noexcept { clipMaskUniformsBuffer.reset(); stencilStateRenderable = nullptr; + for (size_t i = 0; i < globalUniformBuffers.allocatedSize(); i++) { + globalUniformBuffers.set(i, nullptr); + } + #if !defined(NDEBUG) Log::Debug(Event::General, "Rendering Stats:\n" + stats.toString("\n")); #endif @@ -607,5 +611,17 @@ MTLDepthStencilStatePtr Context::makeDepthStencilState(const gfx::DepthMode& dep return NS::TransferPtr(device->newDepthStencilState(depthStencilDescriptor.get())); } +void Context::bindGlobalUniformBuffers(gfx::RenderPass& renderPass) const noexcept { + for (size_t id = 0; id < globalUniformBuffers.allocatedSize(); id++) { + const auto& globalUniformBuffer = globalUniformBuffers.get(id); + if (!globalUniformBuffer) continue; + const auto& buffer = static_cast(*globalUniformBuffer.get()); + const auto& resource = buffer.getBufferResource(); + auto& mtlRenderPass = static_cast(renderPass); + mtlRenderPass.bindVertex(resource, 0, id); + mtlRenderPass.bindFragment(resource, 0, id); + } +} + } // namespace mtl } // namespace mbgl diff --git a/src/mbgl/renderer/layers/background_layer_tweaker.cpp b/src/mbgl/renderer/layers/background_layer_tweaker.cpp index d0c41d329..029ebec25 100644 --- a/src/mbgl/renderer/layers/background_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/background_layer_tweaker.cpp @@ -53,22 +53,16 @@ void BackgroundLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintPara auto& layerUniforms = layerGroup.mutableUniformBuffers(); if (hasPattern) { - const Size atlasSize = parameters.patternAtlas.getPixelSize(); - - const BackgroundPatternLayerUBO layerUBO = { - /* .pattern_tl_a = */ util::cast(imagePosA->tl()), - /* .pattern_br_a = */ util::cast(imagePosA->br()), - /* .pattern_tl_b = */ util::cast(imagePosB->tl()), - /* .pattern_br_b = */ util::cast(imagePosB->br()), - /* .texsize = */ {static_cast(atlasSize.width), static_cast(atlasSize.height)}, - /* .pattern_size_a = */ imagePosA->displaySize(), - /* .pattern_size_b = */ imagePosB->displaySize(), - /* .scale_a = */ crossfade.fromScale, - /* .scale_b = */ crossfade.toScale, - /* .mix = */ crossfade.t, - /* .opacity = */ evaluated.get(), - /* .pad1/2 = */ 0, - 0}; + const BackgroundPatternLayerUBO layerUBO = {/* .pattern_tl_a = */ util::cast(imagePosA->tl()), + /* .pattern_br_a = */ util::cast(imagePosA->br()), + /* .pattern_tl_b = */ util::cast(imagePosB->tl()), + /* .pattern_br_b = */ util::cast(imagePosB->br()), + /* .pattern_size_a = */ imagePosA->displaySize(), + /* .pattern_size_b = */ imagePosB->displaySize(), + /* .scale_a = */ crossfade.fromScale, + /* .scale_b = */ crossfade.toScale, + /* .mix = */ crossfade.t, + /* .opacity = */ evaluated.get()}; layerUniforms.createOrUpdate(idBackgroundLayerUBO, &layerUBO, context); } else { const BackgroundLayerUBO layerUBO = {/* .color = */ evaluated.get(), diff --git a/src/mbgl/renderer/layers/circle_layer_tweaker.cpp b/src/mbgl/renderer/layers/circle_layer_tweaker.cpp index 6c522ee9a..8d98756f0 100644 --- a/src/mbgl/renderer/layers/circle_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/circle_layer_tweaker.cpp @@ -34,16 +34,6 @@ void CircleLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParamete const auto debugGroup = parameters.encoder->createDebugGroup(label.c_str()); #endif - // Updated every frame, but shared across drawables - const CirclePaintParamsUBO paintParamsUBO = { - /* .camera_to_center_distance = */ parameters.state.getCameraToCenterDistance(), - /* .padding = */ 0, - 0, - 0}; - - auto& layerUniforms = layerGroup.mutableUniformBuffers(); - layerUniforms.createOrUpdate(idCirclePaintParamsUBO, &paintParamsUBO, context); - const auto zoom = parameters.state.getZoom(); const bool pitchWithMap = evaluated.get() == AlignmentType::Map; const bool scaleWithMap = evaluated.get() == CirclePitchScaleType::Map; @@ -64,6 +54,7 @@ void CircleLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParamete context.emplaceOrUpdateUniformBuffer(evaluatedPropsUniformBuffer, &evaluatedPropsUBO); propertiesUpdated = false; } + auto& layerUniforms = layerGroup.mutableUniformBuffers(); layerUniforms.set(idCircleEvaluatedPropsUBO, evaluatedPropsUniformBuffer); visitLayerGroupDrawables(layerGroup, [&](gfx::Drawable& drawable) { diff --git a/src/mbgl/renderer/layers/collision_layer_tweaker.cpp b/src/mbgl/renderer/layers/collision_layer_tweaker.cpp index d358c86e9..0f3eb8086 100644 --- a/src/mbgl/renderer/layers/collision_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/collision_layer_tweaker.cpp @@ -61,8 +61,8 @@ void CollisionLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParam const CollisionUBO drawableUBO = { /*.matrix=*/util::cast(matrix), /*.extrude_scale*/ extrudeScale, - /*.camera_to_center_distance*/ parameters.state.getCameraToCenterDistance(), - /*.overscale_factor*/ static_cast(drawable.getTileID()->overscaleFactor())}; + /*.overscale_factor*/ static_cast(drawable.getTileID()->overscaleFactor()), + /*.pad*/ 0}; auto& drawableUniforms = drawable.mutableUniformBuffers(); drawableUniforms.createOrUpdate(idCollisionUBO, &drawableUBO, context); diff --git a/src/mbgl/renderer/layers/fill_extrusion_layer_tweaker.cpp b/src/mbgl/renderer/layers/fill_extrusion_layer_tweaker.cpp index ebee5a80f..0067b46d1 100644 --- a/src/mbgl/renderer/layers/fill_extrusion_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/fill_extrusion_layer_tweaker.cpp @@ -54,9 +54,9 @@ void FillExtrusionLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintP /* .vertical_gradient = */ evaluated.get() ? 1.0f : 0.0f, /* .opacity = */ evaluated.get(), /* .fade = */ crossfade.t, - /* .pad = */ 0, - 0, - 0}; + /* .from_scale = */ crossfade.fromScale, + /* .to_scale = */ crossfade.toScale, + /* .pad = */ 0}; auto& layerUniforms = layerGroup.mutableUniformBuffers(); layerUniforms.createOrUpdate(idFillExtrusionPropsUBO, &propsUBO, context); @@ -82,7 +82,6 @@ void FillExtrusionLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintP const auto pixelX = static_cast(tileSizeAtNearestZoom * (tileID.canonical.x + tileID.wrap * zoomScale)); const auto pixelY = static_cast(tileSizeAtNearestZoom * tileID.canonical.y); - const auto pixelRatio = parameters.pixelRatio; const auto numTiles = std::pow(2, tileID.canonical.z); const auto heightFactor = static_cast(-numTiles / util::tileSize_D / 8.0); @@ -93,12 +92,11 @@ void FillExtrusionLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintP const FillExtrusionDrawableUBO drawableUBO = { /* .matrix = */ util::cast(matrix), - /* .scale = */ {pixelRatio, tileRatio, crossfade.fromScale, crossfade.toScale}, /* .texsize = */ {static_cast(textureSize.width), static_cast(textureSize.height)}, /* .pixel_coord_upper = */ {static_cast(pixelX >> 16), static_cast(pixelY >> 16)}, /* .pixel_coord_lower = */ {static_cast(pixelX & 0xFFFF), static_cast(pixelY & 0xFFFF)}, /* .height_factor = */ heightFactor, - /* .pad = */ 0}; + /* .tile_ratio = */ tileRatio}; auto& drawableUniforms = drawable.mutableUniformBuffers(); drawableUniforms.createOrUpdate(idFillExtrusionDrawableUBO, &drawableUBO, context); diff --git a/src/mbgl/renderer/layers/fill_layer_tweaker.cpp b/src/mbgl/renderer/layers/fill_layer_tweaker.cpp index 9763a274c..3bc95059f 100644 --- a/src/mbgl/renderer/layers/fill_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/fill_layer_tweaker.cpp @@ -46,8 +46,8 @@ void FillLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters /* .outline_color = */ evaluated.get().constantOr(FillOutlineColor::defaultValue()), /* .opacity = */ evaluated.get().constantOr(FillOpacity::defaultValue()), /* .fade = */ crossfade.t, - /* .width = */ 1.f, - 0, + /* .from_scale = */ crossfade.fromScale, + /* .to_scale = */ crossfade.toScale, }; context.emplaceOrUpdateUniformBuffer(evaluatedPropsUniformBuffer, &propsUBO); propertiesUpdated = false; @@ -57,10 +57,7 @@ void FillLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters const auto& translation = evaluated.get(); const auto anchor = evaluated.get(); - - const auto renderableSize = parameters.backend.getDefaultRenderable().getSize(); const auto intZoom = parameters.state.getIntegerZoom(); - const auto pixelRatio = parameters.pixelRatio; visitLayerGroupDrawables(layerGroup, [&](gfx::Drawable& drawable) { if (!drawable.getTileID() || !checkTweakDrawable(drawable)) { @@ -97,22 +94,17 @@ void FillLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters break; } case RenderFillLayer::FillVariant::FillOutline: { - const FillOutlineDrawableUBO drawableUBO = { - /*.matrix=*/util::cast(matrix), - /*.world=*/{(float)renderableSize.width, (float)renderableSize.height}, - /* pad1 */ 0, - /* pad2 */ 0}; + const FillOutlineDrawableUBO drawableUBO = {/*.matrix=*/util::cast(matrix)}; drawableUniforms.createOrUpdate(idFillDrawableUBO, &drawableUBO, context); break; } case RenderFillLayer::FillVariant::FillPattern: { const FillPatternDrawableUBO drawableUBO = { /*.matrix=*/util::cast(matrix), - /*.scale=*/{pixelRatio, tileRatio, crossfade.fromScale, crossfade.toScale}, /*.pixel_coord_upper=*/{static_cast(pixelX >> 16), static_cast(pixelY >> 16)}, /*.pixel_coord_lower=*/{static_cast(pixelX & 0xFFFF), static_cast(pixelY & 0xFFFF)}, /*.texsize=*/{static_cast(textureSize.width), static_cast(textureSize.height)}, - 0, + /*.tile_ratio = */ tileRatio, 0, }; drawableUniforms.createOrUpdate(idFillDrawableUBO, &drawableUBO, context); @@ -121,20 +113,20 @@ void FillLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters case RenderFillLayer::FillVariant::FillOutlinePattern: { const FillOutlinePatternDrawableUBO drawableUBO = { /*.matrix=*/util::cast(matrix), - /*.scale=*/{pixelRatio, tileRatio, crossfade.fromScale, crossfade.toScale}, - /*.world=*/{(float)renderableSize.width, (float)renderableSize.height}, /*.pixel_coord_upper=*/{static_cast(pixelX >> 16), static_cast(pixelY >> 16)}, /*.pixel_coord_lower=*/{static_cast(pixelX & 0xFFFF), static_cast(pixelY & 0xFFFF)}, /*.texsize=*/{static_cast(textureSize.width), static_cast(textureSize.height)}, - }; + /*.tile_ratio = */ tileRatio, + 0}; drawableUniforms.createOrUpdate(idFillDrawableUBO, &drawableUBO, context); break; } case RenderFillLayer::FillVariant::FillOutlineTriangulated: { const FillOutlineTriangulatedDrawableUBO drawableUBO = { /*.matrix=*/util::cast(matrix), - /*.units_to_pixels=*/{1.0f / parameters.pixelsToGLUnits[0], 1.0f / parameters.pixelsToGLUnits[1]}, /*.ratio=*/1.0f / tileID.pixelsToTileUnits(1.0f, parameters.state.getZoom()), + 0, + 0, 0}; drawableUniforms.createOrUpdate(idFillDrawableUBO, &drawableUBO, context); break; diff --git a/src/mbgl/renderer/layers/heatmap_texture_layer_tweaker.cpp b/src/mbgl/renderer/layers/heatmap_texture_layer_tweaker.cpp index 28cc38004..635103c17 100644 --- a/src/mbgl/renderer/layers/heatmap_texture_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/heatmap_texture_layer_tweaker.cpp @@ -29,15 +29,15 @@ void HeatmapTextureLayerTweaker::execute(LayerGroupBase& layerGroup, const Paint propertiesUpdated = false; + mat4 matrix; const auto& size = parameters.staticData.backendSize; - mat4 viewportMat; - matrix::ortho(viewportMat, 0, size.width, size.height, 0, -1, 1); - const HeatmapTexturePropsUBO propsUBO = { - /* .matrix = */ util::cast(viewportMat), - /* .world = */ {static_cast(size.width), static_cast(size.height)}, - /* .opacity = */ evaluated.get(), - /* .pad1 = */ 0, - }; + matrix::ortho(matrix, 0, size.width, size.height, 0, -1, 1); + + const HeatmapTexturePropsUBO propsUBO = {/* .matrix = */ util::cast(matrix), + /* .opacity = */ evaluated.get(), + /* .pad1,2,3 = */ 0, + 0, + 0}; auto& layerUniforms = layerGroup.mutableUniformBuffers(); layerUniforms.createOrUpdate(idHeatmapTexturePropsUBO, &propsUBO, parameters.context); } diff --git a/src/mbgl/renderer/layers/line_layer_tweaker.cpp b/src/mbgl/renderer/layers/line_layer_tweaker.cpp index 8ffd4c914..ea60805e1 100644 --- a/src/mbgl/renderer/layers/line_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/line_layer_tweaker.cpp @@ -44,12 +44,7 @@ void LineLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters context.emplaceOrUpdateUniformBuffer(evaluatedPropsUniformBuffer, &propsUBO); propertiesUpdated = false; } - - const LineDynamicUBO dynamicUBO = { - /*units_to_pixels = */ {1.0f / parameters.pixelsToGLUnits[0], 1.0f / parameters.pixelsToGLUnits[1]}, 0, 0}; - auto& layerUniforms = layerGroup.mutableUniformBuffers(); - layerUniforms.createOrUpdate(idLineDynamicUBO, &dynamicUBO, context); layerUniforms.set(idLineEvaluatedPropsUBO, evaluatedPropsUniformBuffer); visitLayerGroupDrawables(layerGroup, [&](gfx::Drawable& drawable) { diff --git a/src/mbgl/renderer/layers/symbol_layer_tweaker.cpp b/src/mbgl/renderer/layers/symbol_layer_tweaker.cpp index d3722851e..93173234b 100644 --- a/src/mbgl/renderer/layers/symbol_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/symbol_layer_tweaker.cpp @@ -72,18 +72,10 @@ void SymbolLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParamete context.emplaceOrUpdateUniformBuffer(evaluatedPropsUniformBuffer, &propsUBO); propertiesUpdated = false; } - - const auto camDist = state.getCameraToCenterDistance(); - - const SymbolDynamicUBO dynamicUBO = {/*.fade_change=*/parameters.symbolFadeChange, - /*.camera_to_center_distance=*/camDist, - /*.aspect_ratio=*/state.getSize().aspectRatio(), - 0}; - auto& layerUniforms = layerGroup.mutableUniformBuffers(); - layerUniforms.createOrUpdate(idSymbolDynamicUBO, &dynamicUBO, context); layerUniforms.set(idSymbolEvaluatedPropsUBO, evaluatedPropsUniformBuffer); + const auto camDist = state.getCameraToCenterDistance(); visitLayerGroupDrawables(layerGroup, [&](gfx::Drawable& drawable) { if (!drawable.getTileID() || !drawable.getData()) { return; diff --git a/src/mbgl/renderer/renderer_impl.cpp b/src/mbgl/renderer/renderer_impl.cpp index 72f16e364..4bbc4c390 100644 --- a/src/mbgl/renderer/renderer_impl.cpp +++ b/src/mbgl/renderer/renderer_impl.cpp @@ -247,6 +247,21 @@ void Renderer::Impl::render(const RenderTree& renderTree, // Upload the Debug layer group orchestrator.visitDebugLayerGroups([&](LayerGroupBase& layerGroup) { layerGroup.upload(*uploadPass); }); } + + const Size atlasSize = parameters.patternAtlas.getPixelSize(); + const auto& worldSize = parameters.staticData.backendSize; + const shaders::GlobalPaintParamsUBO globalPaintParamsUBO = { + /* .pattern_atlas_texsize = */ {static_cast(atlasSize.width), static_cast(atlasSize.height)}, + /* .units_to_pixels = */ {1.0f / parameters.pixelsToGLUnits[0], 1.0f / parameters.pixelsToGLUnits[1]}, + /* .world_size = */ {static_cast(worldSize.width), static_cast(worldSize.height)}, + /* .camera_to_center_distance = */ parameters.state.getCameraToCenterDistance(), + /* .symbol_fade_change = */ parameters.symbolFadeChange, + /* .aspect_ratio = */ parameters.state.getSize().aspectRatio(), + /* .pixel_ratio = */ parameters.pixelRatio, + /* .pad1/2 = */ 0, + 0}; + auto& globalUniforms = context.mutableGlobalUniformBuffers(); + globalUniforms.createOrUpdate(shaders::idGlobalPaintParamsUBO, &globalPaintParamsUBO, context); #endif // - 3D PASS @@ -446,6 +461,7 @@ void Renderer::Impl::render(const RenderTree& renderTree, } drawableTargetsPass(); commonClearPass(); + context.bindGlobalUniformBuffers(*parameters.renderPass); drawableOpaquePass(); drawableTranslucentPass(); drawableDebugOverlays(); @@ -465,6 +481,7 @@ void Renderer::Impl::render(const RenderTree& renderTree, #if MLN_DRAWABLE_RENDERER // Give the layers a chance to do cleanup orchestrator.visitLayerGroups([&](LayerGroupBase& layerGroup) { layerGroup.postRender(orchestrator, parameters); }); + context.unbindGlobalUniformBuffers(*parameters.renderPass); #endif // Ends the RenderPass diff --git a/src/mbgl/renderer/sources/render_tile_source.cpp b/src/mbgl/renderer/sources/render_tile_source.cpp index b46267c53..b1421ffa3 100644 --- a/src/mbgl/renderer/sources/render_tile_source.cpp +++ b/src/mbgl/renderer/sources/render_tile_source.cpp @@ -203,11 +203,6 @@ void TileSourceRenderItem::updateDebugDrawables(DebugLayerGroupMap& debugLayerGr const auto matrix = LayerTweaker::getTileMatrix( tileID, parameters, {{0, 0}}, style::TranslateAnchorType::Viewport, false, false, drawable, false); - const shaders::LineDynamicUBO dynamicUBO = { - /*units_to_pixels = */ {1.0f / parameters.pixelsToGLUnits[0], 1.0f / parameters.pixelsToGLUnits[1]}, - 0, - 0}; - const shaders::LineDrawableUBO drawableUBO = {/*matrix = */ util::cast(matrix), /*ratio = */ 1.0f / tileID.pixelsToTileUnits(1.0f, zoom), 0, @@ -222,7 +217,6 @@ void TileSourceRenderItem::updateDebugDrawables(DebugLayerGroupMap& debugLayerGr 0, 0}; auto& drawableUniforms = drawable.mutableUniformBuffers(); - drawableUniforms.createOrUpdate(idLineDynamicUBO, &dynamicUBO, parameters.context); drawableUniforms.createOrUpdate(idLineDrawableUBO, &drawableUBO, parameters.context); drawableUniforms.createOrUpdate(idLineInterpolationUBO, &lineInterpolationUBO, parameters.context); drawableUniforms.createOrUpdate(idLineEvaluatedPropsUBO, &linePropertiesUBO, parameters.context); diff --git a/src/mbgl/shaders/gl/shader_info.cpp b/src/mbgl/shaders/gl/shader_info.cpp index 6432342bd..86c1fbfa5 100644 --- a/src/mbgl/shaders/gl/shader_info.cpp +++ b/src/mbgl/shaders/gl/shader_info.cpp @@ -31,6 +31,7 @@ const std::vector ShaderInfo ShaderInfo::uniformBlocks = { + UniformBlockInfo{"GlobalPaintParamsUBO", idGlobalPaintParamsUBO}, UniformBlockInfo{"BackgroundPatternDrawableUBO", idBackgroundDrawableUBO}, UniformBlockInfo{"BackgroundPatternLayerUBO", idBackgroundLayerUBO}, }; @@ -44,8 +45,8 @@ const std::vector ShaderInfo ShaderInfo::uniformBlocks = { + UniformBlockInfo{"GlobalPaintParamsUBO", idGlobalPaintParamsUBO}, UniformBlockInfo{"CircleDrawableUBO", idCircleDrawableUBO}, - UniformBlockInfo{"CirclePaintParamsUBO", idCirclePaintParamsUBO}, UniformBlockInfo{"CircleEvaluatedPropsUBO", idCircleEvaluatedPropsUBO}, UniformBlockInfo{"CircleInterpolateUBO", idCircleInterpolateUBO}, }; @@ -64,7 +65,7 @@ const std::vector ShaderInfo ShaderInfo::uniformBlocks = { - UniformBlockInfo{"CollisionBoxUBO", idCollisionUBO}, + UniformBlockInfo{"CollisionUBO", idCollisionUBO}, }; const std::vector ShaderInfo::attributes = { AttributeInfo{"a_pos", idCollisionPosVertexAttribute}, @@ -78,7 +79,7 @@ const std::vector ShaderInfo ShaderInfo::uniformBlocks = { - UniformBlockInfo{"CollisionCircleUBO", idCollisionUBO}, + UniformBlockInfo{"CollisionUBO", idCollisionUBO}, }; const std::vector ShaderInfo::attributes = { AttributeInfo{"a_pos", idCollisionPosVertexAttribute}, @@ -129,6 +130,7 @@ const std::vector ShaderInfo ShaderInfo::uniformBlocks = { + UniformBlockInfo{"GlobalPaintParamsUBO", idGlobalPaintParamsUBO}, UniformBlockInfo{"FillOutlineDrawableUBO", idFillDrawableUBO}, UniformBlockInfo{"FillOutlineInterpolateUBO", idFillInterpolateUBO}, UniformBlockInfo{"FillEvaluatedPropsUBO", idFillEvaluatedPropsUBO}, @@ -143,6 +145,7 @@ const std::vector ShaderInfo ShaderInfo::uniformBlocks = { + UniformBlockInfo{"GlobalPaintParamsUBO", idGlobalPaintParamsUBO}, UniformBlockInfo{"FillPatternDrawableUBO", idFillDrawableUBO}, UniformBlockInfo{"FillPatternTilePropsUBO", idFillTilePropsUBO}, UniformBlockInfo{"FillPatternInterpolateUBO", idFillInterpolateUBO}, @@ -161,6 +164,7 @@ const std::vector ShaderInfo ShaderInfo::uniformBlocks = { + UniformBlockInfo{"GlobalPaintParamsUBO", idGlobalPaintParamsUBO}, UniformBlockInfo{"FillOutlinePatternDrawableUBO", idFillDrawableUBO}, UniformBlockInfo{"FillOutlinePatternTilePropsUBO", idFillTilePropsUBO}, UniformBlockInfo{"FillOutlinePatternInterpolateUBO", idFillInterpolateUBO}, @@ -180,6 +184,7 @@ const std::vector ShaderInfo ShaderInfo::uniformBlocks = { + UniformBlockInfo{"GlobalPaintParamsUBO", idGlobalPaintParamsUBO}, UniformBlockInfo{"FillOutlineTriangulatedDrawableUBO", idFillDrawableUBO}, UniformBlockInfo{"FillEvaluatedPropsUBO", idFillEvaluatedPropsUBO}, }; @@ -211,6 +216,7 @@ const std::vector ShaderInfo ShaderInfo::uniformBlocks = { + UniformBlockInfo{"GlobalPaintParamsUBO", idGlobalPaintParamsUBO}, UniformBlockInfo{"FillExtrusionDrawableUBO", idFillExtrusionDrawableUBO}, UniformBlockInfo{"FillExtrusionPropsUBO", idFillExtrusionPropsUBO}, UniformBlockInfo{"FillExtrusionTilePropsUBO", idFillExtrusionTilePropsUBO}, @@ -245,6 +251,7 @@ const std::vector ShaderInfo ShaderInfo::uniformBlocks = { + UniformBlockInfo{"GlobalPaintParamsUBO", idGlobalPaintParamsUBO}, UniformBlockInfo{"HeatmapTexturePropsUBO", idHeatmapTexturePropsUBO}, }; const std::vector ShaderInfo::attributes = { @@ -283,7 +290,7 @@ const std::vector ShaderInfo ShaderInfo::uniformBlocks = { - UniformBlockInfo{"LineDynamicUBO", idLineDynamicUBO}, + UniformBlockInfo{"GlobalPaintParamsUBO", idGlobalPaintParamsUBO}, UniformBlockInfo{"LineDrawableUBO", idLineDrawableUBO}, UniformBlockInfo{"LineInterpolationUBO", idLineInterpolationUBO}, UniformBlockInfo{"LineEvaluatedPropsUBO", idLineEvaluatedPropsUBO}, @@ -303,7 +310,7 @@ const std::vector ShaderInfo ShaderInfo::uniformBlocks = { - UniformBlockInfo{"LineDynamicUBO", idLineDynamicUBO}, + UniformBlockInfo{"GlobalPaintParamsUBO", idGlobalPaintParamsUBO}, UniformBlockInfo{"LineGradientDrawableUBO", idLineDrawableUBO}, UniformBlockInfo{"LineGradientInterpolationUBO", idLineInterpolationUBO}, UniformBlockInfo{"LineEvaluatedPropsUBO", idLineEvaluatedPropsUBO}, @@ -324,7 +331,7 @@ const std::vector ShaderInfo ShaderInfo::uniformBlocks = { - UniformBlockInfo{"LineDynamicUBO", idLineDynamicUBO}, + UniformBlockInfo{"GlobalPaintParamsUBO", idGlobalPaintParamsUBO}, UniformBlockInfo{"LinePatternDrawableUBO", idLineDrawableUBO}, UniformBlockInfo{"LinePatternInterpolationUBO", idLineInterpolationUBO}, UniformBlockInfo{"LinePatternTilePropertiesUBO", idLineTilePropertiesUBO}, @@ -347,7 +354,7 @@ const std::vector ShaderInfo ShaderInfo::uniformBlocks = { - UniformBlockInfo{"LineDynamicUBO", idLineDynamicUBO}, + UniformBlockInfo{"GlobalPaintParamsUBO", idGlobalPaintParamsUBO}, UniformBlockInfo{"LineSDFDrawableUBO", idLineDrawableUBO}, UniformBlockInfo{"LineSDFInterpolationUBO", idLineInterpolationUBO}, UniformBlockInfo{"LineEvaluatedPropsUBO", idLineEvaluatedPropsUBO}, @@ -383,7 +390,7 @@ const std::vector ShaderInfo ShaderInfo::uniformBlocks = { - UniformBlockInfo{"SymbolDynamicUBO", idSymbolDynamicUBO}, + UniformBlockInfo{"GlobalPaintParamsUBO", idGlobalPaintParamsUBO}, UniformBlockInfo{"SymbolDrawableUBO", idSymbolDrawableUBO}, UniformBlockInfo{"SymbolTilePropsUBO", idSymbolTilePropsUBO}, UniformBlockInfo{"SymbolInterpolateUBO", idSymbolInterpolateUBO}, @@ -404,7 +411,7 @@ const std::vector ShaderInfo ShaderInfo::uniformBlocks = { - UniformBlockInfo{"SymbolDynamicUBO", idSymbolDynamicUBO}, + UniformBlockInfo{"GlobalPaintParamsUBO", idGlobalPaintParamsUBO}, UniformBlockInfo{"SymbolDrawableUBO", idSymbolDrawableUBO}, UniformBlockInfo{"SymbolTilePropsUBO", idSymbolTilePropsUBO}, UniformBlockInfo{"SymbolInterpolateUBO", idSymbolInterpolateUBO}, @@ -429,7 +436,7 @@ const std::vector ShaderInfo ShaderInfo::uniformBlocks = { - UniformBlockInfo{"SymbolDynamicUBO", idSymbolDynamicUBO}, + UniformBlockInfo{"GlobalPaintParamsUBO", idGlobalPaintParamsUBO}, UniformBlockInfo{"SymbolDrawableUBO", idSymbolDrawableUBO}, UniformBlockInfo{"SymbolTilePropsUBO", idSymbolTilePropsUBO}, UniformBlockInfo{"SymbolInterpolateUBO", idSymbolInterpolateUBO}, diff --git a/src/mbgl/shaders/mtl/background_pattern.cpp b/src/mbgl/shaders/mtl/background_pattern.cpp index d7b761430..4346f7d7e 100644 --- a/src/mbgl/shaders/mtl/background_pattern.cpp +++ b/src/mbgl/shaders/mtl/background_pattern.cpp @@ -4,8 +4,9 @@ namespace mbgl { namespace shaders { -const std::array +const std::array ShaderSource::uniforms = { + UniformBlockInfo{false, true, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, UniformBlockInfo{true, false, sizeof(BackgroundPatternDrawableUBO), idBackgroundDrawableUBO}, UniformBlockInfo{true, true, sizeof(BackgroundPatternLayerUBO), idBackgroundLayerUBO}, }; diff --git a/src/mbgl/shaders/mtl/circle.cpp b/src/mbgl/shaders/mtl/circle.cpp index 4efc1329d..abbfbda3a 100644 --- a/src/mbgl/shaders/mtl/circle.cpp +++ b/src/mbgl/shaders/mtl/circle.cpp @@ -4,8 +4,8 @@ namespace mbgl { namespace shaders { const std::array ShaderSource::uniforms = { + UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, UniformBlockInfo{true, false, sizeof(CircleDrawableUBO), idCircleDrawableUBO}, - UniformBlockInfo{true, true, sizeof(CirclePaintParamsUBO), idCirclePaintParamsUBO}, UniformBlockInfo{true, true, sizeof(CircleEvaluatedPropsUBO), idCircleEvaluatedPropsUBO}, UniformBlockInfo{true, false, sizeof(CircleInterpolateUBO), idCircleInterpolateUBO}, }; diff --git a/src/mbgl/shaders/mtl/fill.cpp b/src/mbgl/shaders/mtl/fill.cpp index 0a49d9c88..6c881b368 100644 --- a/src/mbgl/shaders/mtl/fill.cpp +++ b/src/mbgl/shaders/mtl/fill.cpp @@ -15,7 +15,8 @@ const std::array ShaderSource ShaderSource::textures = {}; -const std::array ShaderSource::uniforms = { +const std::array ShaderSource::uniforms = { + UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, UniformBlockInfo{true, false, sizeof(FillOutlineDrawableUBO), idFillDrawableUBO}, UniformBlockInfo{true, false, sizeof(FillOutlineInterpolateUBO), idFillInterpolateUBO}, UniformBlockInfo{true, true, sizeof(FillEvaluatedPropsUBO), idFillEvaluatedPropsUBO}, @@ -27,7 +28,8 @@ const std::array ShaderSource ShaderSource::textures = {}; -const std::array ShaderSource::uniforms = { +const std::array ShaderSource::uniforms = { + UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, UniformBlockInfo{true, true, sizeof(FillPatternDrawableUBO), idFillDrawableUBO}, UniformBlockInfo{true, true, sizeof(FillPatternTilePropsUBO), idFillTilePropsUBO}, UniformBlockInfo{true, false, sizeof(FillPatternInterpolateUBO), idFillInterpolateUBO}, @@ -43,8 +45,9 @@ const std::array ShaderSource +const std::array ShaderSource::uniforms = { + UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, UniformBlockInfo{true, true, sizeof(FillOutlinePatternDrawableUBO), idFillDrawableUBO}, UniformBlockInfo{true, true, sizeof(FillOutlinePatternTilePropsUBO), idFillTilePropsUBO}, UniformBlockInfo{true, false, sizeof(FillOutlinePatternInterpolateUBO), idFillInterpolateUBO}, @@ -62,8 +65,9 @@ const std::array ShaderSource +const std::array ShaderSource::uniforms = { + UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, UniformBlockInfo{true, false, sizeof(FillOutlineTriangulatedDrawableUBO), idFillDrawableUBO}, UniformBlockInfo{true, true, sizeof(FillEvaluatedPropsUBO), idFillEvaluatedPropsUBO}, }; diff --git a/src/mbgl/shaders/mtl/fill_extrusion_pattern.cpp b/src/mbgl/shaders/mtl/fill_extrusion_pattern.cpp index 0a9d5cf57..415831ff9 100644 --- a/src/mbgl/shaders/mtl/fill_extrusion_pattern.cpp +++ b/src/mbgl/shaders/mtl/fill_extrusion_pattern.cpp @@ -4,8 +4,9 @@ namespace mbgl { namespace shaders { -const std::array +const std::array ShaderSource::uniforms = { + UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, UniformBlockInfo{true, true, sizeof(FillExtrusionDrawableUBO), idFillExtrusionDrawableUBO}, UniformBlockInfo{true, true, sizeof(FillExtrusionPropsUBO), idFillExtrusionPropsUBO}, UniformBlockInfo{true, true, sizeof(FillExtrusionTilePropsUBO), idFillExtrusionTilePropsUBO}, diff --git a/src/mbgl/shaders/mtl/heatmap_texture.cpp b/src/mbgl/shaders/mtl/heatmap_texture.cpp index c7843a03a..b87c7f011 100644 --- a/src/mbgl/shaders/mtl/heatmap_texture.cpp +++ b/src/mbgl/shaders/mtl/heatmap_texture.cpp @@ -3,8 +3,9 @@ namespace mbgl { namespace shaders { -const std::array ShaderSource::uniforms = +const std::array ShaderSource::uniforms = { + UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, UniformBlockInfo{true, true, sizeof(HeatmapTexturePropsUBO), idHeatmapTexturePropsUBO}, }; const std::array ShaderSource::attributes = diff --git a/src/mbgl/shaders/mtl/line.cpp b/src/mbgl/shaders/mtl/line.cpp index 0ce4a3dc3..51d85b460 100644 --- a/src/mbgl/shaders/mtl/line.cpp +++ b/src/mbgl/shaders/mtl/line.cpp @@ -4,7 +4,7 @@ namespace mbgl { namespace shaders { const std::array ShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(LineDynamicUBO), idLineDynamicUBO}, + UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, UniformBlockInfo{true, false, sizeof(idLineDrawableUBO), idLineDrawableUBO}, UniformBlockInfo{true, false, sizeof(LineInterpolationUBO), idLineInterpolationUBO}, UniformBlockInfo{true, true, sizeof(LineEvaluatedPropsUBO), idLineEvaluatedPropsUBO}, @@ -22,7 +22,7 @@ const std::array ShaderSource ShaderSource::textures = {}; const std::array ShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(LineDynamicUBO), idLineDynamicUBO}, + UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, UniformBlockInfo{true, false, sizeof(LineGradientDrawableUBO), idLineDrawableUBO}, UniformBlockInfo{true, false, sizeof(LineGradientInterpolationUBO), idLineInterpolationUBO}, UniformBlockInfo{true, true, sizeof(LineEvaluatedPropsUBO), idLineEvaluatedPropsUBO}, @@ -41,7 +41,7 @@ const std::array ShaderSource ShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(LineDynamicUBO), idLineDynamicUBO}, + UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, UniformBlockInfo{true, true, sizeof(LinePatternDrawableUBO), idLineDrawableUBO}, UniformBlockInfo{true, false, sizeof(LinePatternInterpolationUBO), idLineInterpolationUBO}, UniformBlockInfo{true, true, sizeof(LinePatternTilePropertiesUBO), idLineTilePropertiesUBO}, @@ -63,7 +63,7 @@ const std::array ShaderSource ShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(LineDynamicUBO), idLineDynamicUBO}, + UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, UniformBlockInfo{true, true, sizeof(LineSDFDrawableUBO), idLineDrawableUBO}, UniformBlockInfo{true, false, sizeof(LineSDFInterpolationUBO), idLineInterpolationUBO}, UniformBlockInfo{true, true, sizeof(LineEvaluatedPropsUBO), idLineEvaluatedPropsUBO}, diff --git a/src/mbgl/shaders/mtl/symbol_icon.cpp b/src/mbgl/shaders/mtl/symbol_icon.cpp index 8150f3952..c01f1d9f5 100644 --- a/src/mbgl/shaders/mtl/symbol_icon.cpp +++ b/src/mbgl/shaders/mtl/symbol_icon.cpp @@ -4,7 +4,7 @@ namespace mbgl { namespace shaders { const std::array ShaderSource::uniforms = { - UniformBlockInfo{true, true, sizeof(SymbolDynamicUBO), idSymbolDynamicUBO}, + UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, UniformBlockInfo{true, true, sizeof(SymbolDrawableUBO), idSymbolDrawableUBO}, UniformBlockInfo{true, true, sizeof(SymbolTilePropsUBO), idSymbolTilePropsUBO}, UniformBlockInfo{true, false, sizeof(SymbolInterpolateUBO), idSymbolInterpolateUBO}, diff --git a/src/mbgl/shaders/mtl/symbol_sdf.cpp b/src/mbgl/shaders/mtl/symbol_sdf.cpp index 0d4c42926..fc5a94c4b 100644 --- a/src/mbgl/shaders/mtl/symbol_sdf.cpp +++ b/src/mbgl/shaders/mtl/symbol_sdf.cpp @@ -5,7 +5,7 @@ namespace shaders { const std::array ShaderSource::uniforms = { - UniformBlockInfo{true, true, sizeof(SymbolDynamicUBO), idSymbolDynamicUBO}, + UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, UniformBlockInfo{true, true, sizeof(SymbolDrawableUBO), idSymbolDrawableUBO}, UniformBlockInfo{true, true, sizeof(SymbolTilePropsUBO), idSymbolTilePropsUBO}, UniformBlockInfo{true, false, sizeof(SymbolInterpolateUBO), idSymbolInterpolateUBO}, diff --git a/src/mbgl/shaders/mtl/symbol_text_and_icon.cpp b/src/mbgl/shaders/mtl/symbol_text_and_icon.cpp index b4f7d539c..26f7cc221 100644 --- a/src/mbgl/shaders/mtl/symbol_text_and_icon.cpp +++ b/src/mbgl/shaders/mtl/symbol_text_and_icon.cpp @@ -5,7 +5,7 @@ namespace shaders { const std::array ShaderSource::uniforms = { - UniformBlockInfo{true, true, sizeof(SymbolDynamicUBO), idSymbolDynamicUBO}, + UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, UniformBlockInfo{true, true, sizeof(SymbolDrawableUBO), idSymbolDrawableUBO}, UniformBlockInfo{true, true, sizeof(SymbolTilePropsUBO), idSymbolTilePropsUBO}, UniformBlockInfo{true, false, sizeof(SymbolInterpolateUBO), idSymbolInterpolateUBO}, diff --git a/src/mbgl/style/layers/custom_drawable_layer.cpp b/src/mbgl/style/layers/custom_drawable_layer.cpp index 5f3db032a..4afd3bcdb 100644 --- a/src/mbgl/style/layers/custom_drawable_layer.cpp +++ b/src/mbgl/style/layers/custom_drawable_layer.cpp @@ -107,9 +107,6 @@ public: const auto matrix = LayerTweaker::getTileMatrix( tileID, parameters, {{0, 0}}, style::TranslateAnchorType::Viewport, false, false, drawable, false); - const shaders::LineDynamicUBO dynamicUBO = { - /*units_to_pixels = */ {1.0f / parameters.pixelsToGLUnits[0], 1.0f / parameters.pixelsToGLUnits[1]}, 0, 0}; - const shaders::LineDrawableUBO drawableUBO = {/*matrix = */ util::cast(matrix), /*ratio = */ 1.0f / tileID.pixelsToTileUnits(1.0f, zoom), 0, @@ -124,7 +121,6 @@ public: 0, 0}; auto& drawableUniforms = drawable.mutableUniformBuffers(); - drawableUniforms.createOrUpdate(idLineDynamicUBO, &dynamicUBO, parameters.context); drawableUniforms.createOrUpdate(idLineDrawableUBO, &drawableUBO, parameters.context); drawableUniforms.createOrUpdate(idLineInterpolationUBO, &lineInterpolationUBO, parameters.context); drawableUniforms.createOrUpdate(idLineEvaluatedPropsUBO, &linePropertiesUBO, parameters.context); @@ -230,8 +226,8 @@ public: /* .outline_color = */ Color::white(), /* .opacity = */ opacity, /* .fade = */ 0.f, - /* .width = */ 0.f, - 0, + /* .from_scale = */ 0.f, + /* .to_scale = */ 0.f, }; auto& drawableUniforms = drawable.mutableUniformBuffers(); drawableUniforms.createOrUpdate(idFillDrawableUBO, &fillDrawableUBO, parameters.context);