From 86eff40b65e3b6064e3bee3fc5452d78686d9bcd Mon Sep 17 00:00:00 2001 From: Alex Cristici Date: Tue, 28 Apr 2026 19:00:37 +0300 Subject: [PATCH] Add attribute buffer index to support multiple attributes interleaved in single buffer bind [Core optimization] (#4241) Co-authored-by: Adrian Cojocaru --- include/mbgl/mtl/vertex_attribute.hpp | 17 ++++- include/mbgl/shaders/mtl/background.hpp | 4 +- include/mbgl/shaders/mtl/circle.hpp | 16 ++-- include/mbgl/shaders/mtl/clipping_mask.hpp | 2 +- include/mbgl/shaders/mtl/collision.hpp | 18 ++--- include/mbgl/shaders/mtl/color_relief.hpp | 4 +- include/mbgl/shaders/mtl/custom_geometry.hpp | 4 +- .../mbgl/shaders/mtl/custom_symbol_icon.hpp | 4 +- include/mbgl/shaders/mtl/debug.hpp | 2 +- include/mbgl/shaders/mtl/fill.hpp | 32 ++++---- include/mbgl/shaders/mtl/fill_extrusion.hpp | 22 +++--- include/mbgl/shaders/mtl/heatmap.hpp | 6 +- include/mbgl/shaders/mtl/heatmap_texture.hpp | 2 +- include/mbgl/shaders/mtl/hillshade.hpp | 4 +- .../mbgl/shaders/mtl/hillshade_prepare.hpp | 4 +- include/mbgl/shaders/mtl/line.hpp | 66 ++++++++--------- .../mbgl/shaders/mtl/location_indicator.hpp | 6 +- include/mbgl/shaders/mtl/raster.hpp | 4 +- include/mbgl/shaders/mtl/shader_program.hpp | 23 +++--- include/mbgl/shaders/mtl/symbol.hpp | 50 ++++++------- include/mbgl/shaders/mtl/widevector.hpp | 8 +- src/mbgl/gfx/attribute.hpp | 5 +- src/mbgl/gl/upload_pass.cpp | 3 + src/mbgl/mtl/context.cpp | 13 ++-- src/mbgl/mtl/drawable.cpp | 32 ++++---- src/mbgl/mtl/upload_pass.cpp | 4 + src/mbgl/mtl/vertex_attribute.cpp | 11 +++ src/mbgl/shaders/mtl/background.cpp | 4 +- src/mbgl/shaders/mtl/circle.cpp | 18 +++-- src/mbgl/shaders/mtl/clipping_mask.cpp | 2 +- src/mbgl/shaders/mtl/collision.cpp | 22 +++--- src/mbgl/shaders/mtl/color_relief.cpp | 4 +- src/mbgl/shaders/mtl/custom_geometry.cpp | 4 +- src/mbgl/shaders/mtl/custom_symbol_icon.cpp | 4 +- src/mbgl/shaders/mtl/debug.cpp | 2 +- src/mbgl/shaders/mtl/fill.cpp | 40 ++++++---- src/mbgl/shaders/mtl/fill_extrusion.cpp | 27 ++++--- src/mbgl/shaders/mtl/heatmap.cpp | 8 +- src/mbgl/shaders/mtl/heatmap_texture.cpp | 2 +- src/mbgl/shaders/mtl/hillshade.cpp | 4 +- src/mbgl/shaders/mtl/hillshade_prepare.cpp | 5 +- src/mbgl/shaders/mtl/line.cpp | 74 ++++++++++--------- src/mbgl/shaders/mtl/location_indicator.cpp | 8 +- src/mbgl/shaders/mtl/raster.cpp | 4 +- src/mbgl/shaders/mtl/shader_program.cpp | 6 +- src/mbgl/shaders/mtl/symbol.cpp | 71 ++++++++++-------- src/mbgl/shaders/mtl/widevector.cpp | 14 ++-- src/mbgl/vulkan/upload_pass.cpp | 3 + src/mbgl/webgpu/context.cpp | 3 +- src/mbgl/webgpu/upload_pass.cpp | 3 + 50 files changed, 388 insertions(+), 310 deletions(-) diff --git a/include/mbgl/mtl/vertex_attribute.hpp b/include/mbgl/mtl/vertex_attribute.hpp index 49c0c65fc..680b9c7fb 100644 --- a/include/mbgl/mtl/vertex_attribute.hpp +++ b/include/mbgl/mtl/vertex_attribute.hpp @@ -17,13 +17,23 @@ public: : gfx::VertexAttribute(index_, dataType_, count_) {} VertexAttribute(const VertexAttribute& other) = delete; VertexAttribute(VertexAttribute&& other) - : gfx::VertexAttribute(std::move(other)) {} + : gfx::VertexAttribute(std::move(other)), + bufferIndex(other.bufferIndex) {} ~VertexAttribute() override = default; + /// @brief Get the bufer index of the vertex attribute + int getBufferIndex() const { return bufferIndex; } + + /// @brief Set the buffer index of the vertex attribute + void setBufferIndex(int value) { bufferIndex = value; } + static const gfx::UniqueVertexBufferResource& getBuffer(gfx::VertexAttribute&, UploadPass&, const gfx::BufferUsageType, bool forceUpdate); + +protected: + int bufferIndex = 0; }; /// Stores a collection of vertex attributes by name @@ -39,6 +49,11 @@ public: } VertexAttributeArray& operator=(const VertexAttributeArray& other) = delete; + const std::unique_ptr& set(const size_t id, + int index, + gfx::AttributeDataType type, + int bufferIndex); + /// Indicates whether any values have changed bool isModifiedAfter(std::chrono::duration time) const; diff --git a/include/mbgl/shaders/mtl/background.hpp b/include/mbgl/shaders/mtl/background.hpp index ad414accc..175eebe4a 100644 --- a/include/mbgl/shaders/mtl/background.hpp +++ b/include/mbgl/shaders/mtl/background.hpp @@ -87,7 +87,7 @@ struct ShaderSource { static constexpr auto source = R"( struct VertexStage { - short2 position [[attribute(backgroundUBOCount + 0)]]; + short2 position [[attribute(0)]]; }; struct FragmentStage { @@ -130,7 +130,7 @@ struct ShaderSource static constexpr auto source = R"( struct VertexStage { - short2 position [[attribute(backgroundUBOCount + 0)]]; + short2 position [[attribute(0)]]; }; struct FragmentStage { diff --git a/include/mbgl/shaders/mtl/circle.hpp b/include/mbgl/shaders/mtl/circle.hpp index 7575f39bd..6ad808366 100644 --- a/include/mbgl/shaders/mtl/circle.hpp +++ b/include/mbgl/shaders/mtl/circle.hpp @@ -66,28 +66,28 @@ struct ShaderSource { static constexpr auto source = R"( struct VertexStage { - short2 position [[attribute(circleUBOCount + 0)]]; + short2 position [[attribute(0)]]; #if !defined(HAS_UNIFORM_u_color) - float4 color [[attribute(circleUBOCount + 1)]]; + float4 color [[attribute(1)]]; #endif #if !defined(HAS_UNIFORM_u_radius) - float2 radius [[attribute(circleUBOCount + 2)]]; + float2 radius [[attribute(2)]]; #endif #if !defined(HAS_UNIFORM_u_blur) - float2 blur [[attribute(circleUBOCount + 3)]]; + float2 blur [[attribute(3)]]; #endif #if !defined(HAS_UNIFORM_u_opacity) - float2 opacity [[attribute(circleUBOCount + 4)]]; + float2 opacity [[attribute(4)]]; #endif #if !defined(HAS_UNIFORM_u_stroke_color) - float4 stroke_color [[attribute(circleUBOCount + 5)]]; + float4 stroke_color [[attribute(5)]]; #endif #if !defined(HAS_UNIFORM_u_stroke_width) - float2 stroke_width [[attribute(circleUBOCount + 6)]]; + float2 stroke_width [[attribute(6)]]; #endif #if !defined(HAS_UNIFORM_u_stroke_opacity) - float2 stroke_opacity [[attribute(circleUBOCount + 7)]]; + float2 stroke_opacity [[attribute(7)]]; #endif }; diff --git a/include/mbgl/shaders/mtl/clipping_mask.hpp b/include/mbgl/shaders/mtl/clipping_mask.hpp index e0f5d8b61..d97f45a6e 100644 --- a/include/mbgl/shaders/mtl/clipping_mask.hpp +++ b/include/mbgl/shaders/mtl/clipping_mask.hpp @@ -49,7 +49,7 @@ struct ShaderSource { static constexpr auto source = R"( struct VertexStage { - short2 position [[attribute(clippingMaskUBOCount + 0)]]; + short2 position [[attribute(0)]]; }; struct FragmentStage { diff --git a/include/mbgl/shaders/mtl/collision.hpp b/include/mbgl/shaders/mtl/collision.hpp index 79a21da87..00e8dfba2 100644 --- a/include/mbgl/shaders/mtl/collision.hpp +++ b/include/mbgl/shaders/mtl/collision.hpp @@ -45,11 +45,11 @@ struct ShaderSource { static constexpr auto source = R"( struct VertexStage { - short2 pos [[attribute(collisionUBOCount + 0)]]; - short2 anchor_pos [[attribute(collisionUBOCount + 1)]]; - short2 extrude [[attribute(collisionUBOCount + 2)]]; - ushort2 placed [[attribute(collisionUBOCount + 3)]]; - float2 shift [[attribute(collisionUBOCount + 4)]]; + short2 pos [[attribute(0)]]; + short2 anchor_pos [[attribute(1)]]; + short2 extrude [[attribute(2)]]; + ushort2 placed [[attribute(3)]]; + float2 shift [[attribute(4)]]; }; struct FragmentStage { @@ -119,10 +119,10 @@ struct ShaderSource { static constexpr auto source = R"( struct VertexStage { - short2 pos [[attribute(collisionUBOCount + 0)]]; - short2 anchor_pos [[attribute(collisionUBOCount + 1)]]; - short2 extrude [[attribute(collisionUBOCount + 2)]]; - ushort2 placed [[attribute(collisionUBOCount + 3)]]; + short2 pos [[attribute(0)]]; + short2 anchor_pos [[attribute(1)]]; + short2 extrude [[attribute(2)]]; + ushort2 placed [[attribute(3)]]; }; struct FragmentStage { diff --git a/include/mbgl/shaders/mtl/color_relief.hpp b/include/mbgl/shaders/mtl/color_relief.hpp index ad2628cc8..8be00e069 100644 --- a/include/mbgl/shaders/mtl/color_relief.hpp +++ b/include/mbgl/shaders/mtl/color_relief.hpp @@ -56,8 +56,8 @@ struct ShaderSource { static constexpr auto source = R"( struct VertexStage { - short2 pos [[attribute(colorReliefUBOCount + 0)]]; - short2 texture_pos [[attribute(colorReliefUBOCount + 1)]]; + short2 pos [[attribute(0)]]; + short2 texture_pos [[attribute(1)]]; }; struct FragmentStage { diff --git a/include/mbgl/shaders/mtl/custom_geometry.hpp b/include/mbgl/shaders/mtl/custom_geometry.hpp index c19473597..b4bc2666c 100644 --- a/include/mbgl/shaders/mtl/custom_geometry.hpp +++ b/include/mbgl/shaders/mtl/custom_geometry.hpp @@ -37,8 +37,8 @@ struct ShaderSource { static constexpr auto source = R"( struct VertexStage { - float3 position [[attribute(customGeometryUBOCount + 0)]]; - float2 uv [[attribute(customGeometryUBOCount + 1)]]; + float3 position [[attribute(0)]]; + float2 uv [[attribute(1)]]; }; struct FragmentStage { diff --git a/include/mbgl/shaders/mtl/custom_symbol_icon.hpp b/include/mbgl/shaders/mtl/custom_symbol_icon.hpp index a497f9fda..57535e0d4 100644 --- a/include/mbgl/shaders/mtl/custom_symbol_icon.hpp +++ b/include/mbgl/shaders/mtl/custom_symbol_icon.hpp @@ -46,8 +46,8 @@ struct ShaderSource static constexpr auto source = R"( struct VertexStage { - float2 a_pos [[attribute(customSymbolUBOCount + 0)]]; - float2 a_tex [[attribute(customSymbolUBOCount + 1)]]; + float2 a_pos [[attribute(0)]]; + float2 a_tex [[attribute(1)]]; }; struct FragmentStage { diff --git a/include/mbgl/shaders/mtl/debug.hpp b/include/mbgl/shaders/mtl/debug.hpp index e252f3863..649ccf758 100644 --- a/include/mbgl/shaders/mtl/debug.hpp +++ b/include/mbgl/shaders/mtl/debug.hpp @@ -41,7 +41,7 @@ struct ShaderSource { static constexpr auto source = R"( struct VertexStage { - short2 pos [[attribute(debugUBOCount + 0)]]; + short2 pos [[attribute(0)]]; }; struct FragmentStage { diff --git a/include/mbgl/shaders/mtl/fill.hpp b/include/mbgl/shaders/mtl/fill.hpp index 43da9b16d..5b872dd66 100644 --- a/include/mbgl/shaders/mtl/fill.hpp +++ b/include/mbgl/shaders/mtl/fill.hpp @@ -154,13 +154,13 @@ struct ShaderSource { static constexpr auto source = R"( struct VertexStage { - short2 position [[attribute(fillUBOCount + 0)]]; + short2 position [[attribute(0)]]; #if !defined(HAS_UNIFORM_u_color) - float4 color [[attribute(fillUBOCount + 1)]]; + float4 color [[attribute(1)]]; #endif #if !defined(HAS_UNIFORM_u_opacity) - float2 opacity [[attribute(fillUBOCount + 2)]]; + float2 opacity [[attribute(2)]]; #endif }; @@ -229,9 +229,9 @@ struct ShaderSource { static constexpr auto source = R"( struct VertexStage { - short2 position [[attribute(fillUBOCount + 0)]]; - float4 outline_color [[attribute(fillUBOCount + 1)]]; - float2 opacity [[attribute(fillUBOCount + 2)]]; + short2 position [[attribute(0)]]; + float4 outline_color [[attribute(1)]]; + float2 opacity [[attribute(2)]]; }; struct FragmentStage { @@ -308,16 +308,16 @@ struct ShaderSource { static constexpr auto source = R"( struct VertexStage { - short2 position [[attribute(fillUBOCount + 0)]]; + short2 position [[attribute(0)]]; #if !defined(HAS_UNIFORM_u_pattern_from) - ushort4 pattern_from [[attribute(fillUBOCount + 1)]]; + ushort4 pattern_from [[attribute(1)]]; #endif #if !defined(HAS_UNIFORM_u_pattern_to) - ushort4 pattern_to [[attribute(fillUBOCount + 2)]]; + ushort4 pattern_to [[attribute(2)]]; #endif #if !defined(HAS_UNIFORM_u_opacity) - float2 opacity [[attribute(fillUBOCount + 3)]]; + float2 opacity [[attribute(3)]]; #endif }; @@ -451,16 +451,16 @@ struct ShaderSource { static constexpr auto source = R"( struct VertexStage { - short2 pos [[attribute(fillExtrusionUBOCount + 0)]]; - short4 normal_ed [[attribute(fillExtrusionUBOCount + 1)]]; + short2 pos [[attribute(0)]]; + short4 normal_ed [[attribute(1)]]; #if !defined(HAS_UNIFORM_u_color) - float4 color [[attribute(fillExtrusionUBOCount + 2)]]; + float4 color [[attribute(2)]]; #endif #if !defined(HAS_UNIFORM_u_base) - float base [[attribute(fillExtrusionUBOCount + 3)]]; + float base [[attribute(3)]]; #endif #if !defined(HAS_UNIFORM_u_height) - float height [[attribute(fillExtrusionUBOCount + 4)]]; + float height [[attribute(4)]]; #endif }; @@ -198,20 +198,20 @@ struct ShaderSource { static constexpr auto source = R"( struct VertexStage { - short2 pos [[attribute(heatmapUBOCount + 0)]]; + short2 pos [[attribute(0)]]; #if !defined(HAS_UNIFORM_u_weight) - float2 weight [[attribute(heatmapUBOCount + 1)]]; + float2 weight [[attribute(1)]]; #endif #if !defined(HAS_UNIFORM_u_radius) - float2 radius [[attribute(heatmapUBOCount + 2)]]; + float2 radius [[attribute(2)]]; #endif }; diff --git a/include/mbgl/shaders/mtl/heatmap_texture.hpp b/include/mbgl/shaders/mtl/heatmap_texture.hpp index 767b77847..02ab127a0 100644 --- a/include/mbgl/shaders/mtl/heatmap_texture.hpp +++ b/include/mbgl/shaders/mtl/heatmap_texture.hpp @@ -40,7 +40,7 @@ struct ShaderSource { static constexpr auto source = R"( struct VertexStage { - short2 pos [[attribute(heatmapTextureUBOCount + 0)]]; + short2 pos [[attribute(0)]]; }; struct FragmentStage { diff --git a/include/mbgl/shaders/mtl/hillshade.hpp b/include/mbgl/shaders/mtl/hillshade.hpp index dc8d25000..a908d73e1 100644 --- a/include/mbgl/shaders/mtl/hillshade.hpp +++ b/include/mbgl/shaders/mtl/hillshade.hpp @@ -68,8 +68,8 @@ struct ShaderSource { #define BASIC 4 struct VertexStage { - short2 pos [[attribute(hillshadeUBOCount + 0)]]; - short2 texture_pos [[attribute(hillshadeUBOCount + 1)]]; + short2 pos [[attribute(0)]]; + short2 texture_pos [[attribute(1)]]; }; struct FragmentStage { diff --git a/include/mbgl/shaders/mtl/hillshade_prepare.hpp b/include/mbgl/shaders/mtl/hillshade_prepare.hpp index fe16327e8..48fee0f93 100644 --- a/include/mbgl/shaders/mtl/hillshade_prepare.hpp +++ b/include/mbgl/shaders/mtl/hillshade_prepare.hpp @@ -46,8 +46,8 @@ struct ShaderSource static constexpr auto source = R"( struct VertexStage { - short2 pos [[attribute(hillshadePrepareUBOCount + 0)]]; - short2 texture_pos [[attribute(hillshadePrepareUBOCount + 1)]]; + short2 pos [[attribute(0)]]; + short2 texture_pos [[attribute(1)]]; }; struct FragmentStage { diff --git a/include/mbgl/shaders/mtl/line.hpp b/include/mbgl/shaders/mtl/line.hpp index 0aea59741..8ef79abb1 100644 --- a/include/mbgl/shaders/mtl/line.hpp +++ b/include/mbgl/shaders/mtl/line.hpp @@ -186,26 +186,26 @@ struct ShaderSource { static constexpr auto source = R"( struct VertexStage { - short2 pos_normal [[attribute(lineUBOCount + 0)]]; - uchar4 data [[attribute(lineUBOCount + 1)]]; + short2 pos_normal [[attribute(0)]]; + uchar4 data [[attribute(1)]]; #if !defined(HAS_UNIFORM_u_color) - float4 color [[attribute(lineUBOCount + 2)]]; + float4 color [[attribute(2)]]; #endif #if !defined(HAS_UNIFORM_u_blur) - float2 blur [[attribute(lineUBOCount + 3)]]; + float2 blur [[attribute(3)]]; #endif #if !defined(HAS_UNIFORM_u_opacity) - float2 opacity [[attribute(lineUBOCount + 4)]]; + float2 opacity [[attribute(4)]]; #endif #if !defined(HAS_UNIFORM_u_gapwidth) - float2 gapwidth [[attribute(lineUBOCount + 5)]]; + float2 gapwidth [[attribute(5)]]; #endif #if !defined(HAS_UNIFORM_u_offset) - float2 offset [[attribute(lineUBOCount + 6)]]; + float2 offset [[attribute(6)]]; #endif #if !defined(HAS_UNIFORM_u_width) - float2 width [[attribute(lineUBOCount + 7)]]; + float2 width [[attribute(7)]]; #endif }; @@ -366,22 +366,22 @@ struct ShaderSource { static constexpr auto source = R"( struct VertexStage { - short2 pos_normal [[attribute(lineUBOCount + 0)]]; - uchar4 data [[attribute(lineUBOCount + 1)]]; + short2 pos_normal [[attribute(0)]]; + uchar4 data [[attribute(1)]]; #if !defined(HAS_UNIFORM_u_blur) - float2 blur [[attribute(lineUBOCount + 2)]]; + float2 blur [[attribute(2)]]; #endif #if !defined(HAS_UNIFORM_u_opacity) - float2 opacity [[attribute(lineUBOCount + 3)]]; + float2 opacity [[attribute(3)]]; #endif #if !defined(HAS_UNIFORM_u_gapwidth) - float2 gapwidth [[attribute(lineUBOCount + 4)]]; + float2 gapwidth [[attribute(4)]]; #endif #if !defined(HAS_UNIFORM_u_offset) - float2 offset [[attribute(lineUBOCount + 5)]]; + float2 offset [[attribute(5)]]; #endif #if !defined(HAS_UNIFORM_u_width) - float2 width [[attribute(lineUBOCount + 6)]]; + float2 width [[attribute(6)]]; #endif }; @@ -533,29 +533,29 @@ struct ShaderSource { static constexpr auto source = R"( struct VertexStage { - short2 pos_normal [[attribute(lineUBOCount + 0)]]; - uchar4 data [[attribute(lineUBOCount + 1)]]; + short2 pos_normal [[attribute(0)]]; + uchar4 data [[attribute(1)]]; #if !defined(HAS_UNIFORM_u_blur) - float2 blur [[attribute(lineUBOCount + 2)]]; + float2 blur [[attribute(2)]]; #endif #if !defined(HAS_UNIFORM_u_opacity) - float2 opacity [[attribute(lineUBOCount + 3)]]; + float2 opacity [[attribute(3)]]; #endif #if !defined(HAS_UNIFORM_u_gapwidth) - float2 gapwidth [[attribute(lineUBOCount + 4)]]; + float2 gapwidth [[attribute(4)]]; #endif #if !defined(HAS_UNIFORM_u_offset) - float2 offset [[attribute(lineUBOCount + 5)]]; + float2 offset [[attribute(5)]]; #endif #if !defined(HAS_UNIFORM_u_width) - float2 width [[attribute(lineUBOCount + 6)]]; + float2 width [[attribute(6)]]; #endif #if !defined(HAS_UNIFORM_u_pattern_from) - ushort4 pattern_from [[attribute(lineUBOCount + 7)]]; + ushort4 pattern_from [[attribute(7)]]; #endif #if !defined(HAS_UNIFORM_u_pattern_to) - ushort4 pattern_to [[attribute(lineUBOCount + 8)]]; + ushort4 pattern_to [[attribute(8)]]; #endif }; @@ -770,29 +770,29 @@ struct ShaderSource { static constexpr auto source = R"( struct VertexStage { - short2 pos_normal [[attribute(lineUBOCount + 0)]]; - uchar4 data [[attribute(lineUBOCount + 1)]]; + short2 pos_normal [[attribute(0)]]; + uchar4 data [[attribute(1)]]; #if !defined(HAS_UNIFORM_u_color) - float4 color [[attribute(lineUBOCount + 2)]]; + float4 color [[attribute(2)]]; #endif #if !defined(HAS_UNIFORM_u_blur) - float2 blur [[attribute(lineUBOCount + 3)]]; + float2 blur [[attribute(3)]]; #endif #if !defined(HAS_UNIFORM_u_opacity) - float2 opacity [[attribute(lineUBOCount + 4)]]; + float2 opacity [[attribute(4)]]; #endif #if !defined(HAS_UNIFORM_u_gapwidth) - float2 gapwidth [[attribute(lineUBOCount + 5)]]; + float2 gapwidth [[attribute(5)]]; #endif #if !defined(HAS_UNIFORM_u_offset) - float2 offset [[attribute(lineUBOCount + 6)]]; + float2 offset [[attribute(6)]]; #endif #if !defined(HAS_UNIFORM_u_width) - float2 width [[attribute(lineUBOCount + 7)]]; + float2 width [[attribute(7)]]; #endif #if !defined(HAS_UNIFORM_u_floorwidth) - float2 floorwidth [[attribute(lineUBOCount + 8)]]; + float2 floorwidth [[attribute(8)]]; #endif }; diff --git a/include/mbgl/shaders/mtl/location_indicator.hpp b/include/mbgl/shaders/mtl/location_indicator.hpp index 93d8d5ff8..2564dc93a 100644 --- a/include/mbgl/shaders/mtl/location_indicator.hpp +++ b/include/mbgl/shaders/mtl/location_indicator.hpp @@ -37,7 +37,7 @@ struct ShaderSource static constexpr auto source = R"( struct VertexStage { - float2 position [[attribute(locationIndicatorUBOCount + 0)]]; + float2 position [[attribute(0)]]; }; struct FragmentStage { @@ -73,8 +73,8 @@ struct ShaderSource { static constexpr auto source = R"( struct VertexStage { - short2 pos [[attribute(rasterUBOCount + 0)]]; - short2 texture_pos [[attribute(rasterUBOCount + 1)]]; + short2 pos [[attribute(0)]]; + short2 texture_pos [[attribute(1)]]; }; struct FragmentStage { diff --git a/include/mbgl/shaders/mtl/shader_program.hpp b/include/mbgl/shaders/mtl/shader_program.hpp index 95d92b1f4..f534bc4e9 100644 --- a/include/mbgl/shaders/mtl/shader_program.hpp +++ b/include/mbgl/shaders/mtl/shader_program.hpp @@ -12,28 +12,22 @@ namespace mbgl { namespace shaders { -struct UniformBlockInfo { - constexpr UniformBlockInfo(bool vertex_, bool fragment_, std::size_t size_, std::size_t id_) - : index(id_), - vertex(vertex_), - fragment(fragment_), - size(size_), - id(id_) {} - std::size_t index; - bool vertex; - bool fragment; - std::size_t size; - std::size_t id; -}; + struct AttributeInfo { - constexpr AttributeInfo(std::size_t index_, gfx::AttributeDataType dataType_, std::size_t id_) + constexpr AttributeInfo(std::size_t index_, + gfx::AttributeDataType dataType_, + std::size_t bufferIndex_, + std::size_t id_) : index(index_), dataType(dataType_), + bufferIndex(bufferIndex_), id(id_) {} std::size_t index; gfx::AttributeDataType dataType; + std::size_t bufferIndex; std::size_t id; }; + struct TextureInfo { constexpr TextureInfo(std::size_t index_, std::size_t id_) : index(index_), @@ -41,6 +35,7 @@ struct TextureInfo { std::size_t index; std::size_t id; }; + } // namespace shaders namespace mtl { class RenderableResource; diff --git a/include/mbgl/shaders/mtl/symbol.hpp b/include/mbgl/shaders/mtl/symbol.hpp index d04194b5e..e3eb31385 100644 --- a/include/mbgl/shaders/mtl/symbol.hpp +++ b/include/mbgl/shaders/mtl/symbol.hpp @@ -89,14 +89,14 @@ struct ShaderSource { static constexpr auto source = R"( struct VertexStage { - float4 pos_offset [[attribute(symbolUBOCount + 0)]]; - float4 data [[attribute(symbolUBOCount + 1)]]; - float4 pixeloffset [[attribute(symbolUBOCount + 2)]]; - float3 projected_pos [[attribute(symbolUBOCount + 3)]]; - float fade_opacity [[attribute(symbolUBOCount + 4)]]; + float4 pos_offset [[attribute(0)]]; + float4 data [[attribute(1)]]; + float4 pixeloffset [[attribute(2)]]; + float3 projected_pos [[attribute(3)]]; + float fade_opacity [[attribute(4)]]; #if !defined(HAS_UNIFORM_u_opacity) - float opacity [[attribute(symbolUBOCount + 5)]]; + float opacity [[attribute(5)]]; #endif }; @@ -245,26 +245,26 @@ struct ShaderSource { static constexpr auto source = R"( struct VertexStage { - float4 pos_offset [[attribute(symbolUBOCount + 0)]]; - float4 data [[attribute(symbolUBOCount + 1)]]; - float4 pixeloffset [[attribute(symbolUBOCount + 2)]]; - float3 projected_pos [[attribute(symbolUBOCount + 3)]]; - float fade_opacity [[attribute(symbolUBOCount + 4)]]; + float4 pos_offset [[attribute(0)]]; + float4 data [[attribute(1)]]; + float4 pixeloffset [[attribute(2)]]; + float3 projected_pos [[attribute(3)]]; + float fade_opacity [[attribute(4)]]; #if !defined(HAS_UNIFORM_u_fill_color) - float4 fill_color [[attribute(symbolUBOCount + 5)]]; + float4 fill_color [[attribute(5)]]; #endif #if !defined(HAS_UNIFORM_u_halo_color) - float4 halo_color [[attribute(symbolUBOCount + 6)]]; + float4 halo_color [[attribute(6)]]; #endif #if !defined(HAS_UNIFORM_u_opacity) - float opacity [[attribute(symbolUBOCount + 7)]]; + float opacity [[attribute(7)]]; #endif #if !defined(HAS_UNIFORM_u_halo_width) - float halo_width [[attribute(symbolUBOCount + 8)]]; + float halo_width [[attribute(8)]]; #endif #if !defined(HAS_UNIFORM_u_halo_blur) - float halo_blur [[attribute(symbolUBOCount + 9)]]; + float halo_blur [[attribute(9)]]; #endif }; @@ -481,25 +481,25 @@ struct ShaderSource #define ICON 0.0 struct VertexStage { - float4 pos_offset [[attribute(symbolUBOCount + 0)]]; - float4 data [[attribute(symbolUBOCount + 1)]]; - float3 projected_pos [[attribute(symbolUBOCount + 2)]]; - float fade_opacity [[attribute(symbolUBOCount + 3)]]; + float4 pos_offset [[attribute(0)]]; + float4 data [[attribute(1)]]; + float3 projected_pos [[attribute(2)]]; + float fade_opacity [[attribute(3)]]; #if !defined(HAS_UNIFORM_u_fill_color) - float4 fill_color [[attribute(symbolUBOCount + 4)]]; + float4 fill_color [[attribute(4)]]; #endif #if !defined(HAS_UNIFORM_u_halo_color) - float4 halo_color [[attribute(symbolUBOCount + 5)]]; + float4 halo_color [[attribute(5)]]; #endif #if !defined(HAS_UNIFORM_u_opacity) - float opacity [[attribute(symbolUBOCount + 6)]]; + float opacity [[attribute(6)]]; #endif #if !defined(HAS_UNIFORM_u_halo_width) - float halo_width [[attribute(symbolUBOCount + 7)]]; + float halo_width [[attribute(7)]]; #endif #if !defined(HAS_UNIFORM_u_halo_blur) - float halo_blur [[attribute(symbolUBOCount + 8)]]; + float halo_blur [[attribute(8)]]; #endif }; diff --git a/include/mbgl/shaders/mtl/widevector.hpp b/include/mbgl/shaders/mtl/widevector.hpp index eb065f9ba..99420868c 100644 --- a/include/mbgl/shaders/mtl/widevector.hpp +++ b/include/mbgl/shaders/mtl/widevector.hpp @@ -110,9 +110,9 @@ typedef struct struct VertexTriWideVecB { // x, y offset around the center - float3 screenPos [[attribute(wideVectorUBOCount + 0)]]; - float4 color [[attribute(wideVectorUBOCount + 1)]]; - int index [[attribute(wideVectorUBOCount + 2)]]; + float3 screenPos [[attribute(0)]]; + float4 color [[attribute(1)]]; + int index [[attribute(2)]]; }; // Wide vector vertex passed to fragment shader (new version) @@ -222,7 +222,7 @@ vertex ProjVertexTriWideVecPerf vertexTri_wideVecPerf( constant Uniforms &uniforms [[ buffer(idWideVectorUniformsUBO) ]], constant UniformWideVec &wideVec [[ buffer(idWideVectorUniformWideVecUBO) ]], uint instanceID [[ instance_id ]], - constant VertexTriWideVecInstance *wideVecInsts [[ buffer(wideVectorUBOCount + 3) ]]) + constant VertexTriWideVecInstance *wideVecInsts [[ buffer(wideVectorUBOCount + 1) ]]) { ProjVertexTriWideVecPerf outVert = { .position = discardPt, diff --git a/src/mbgl/gfx/attribute.hpp b/src/mbgl/gfx/attribute.hpp index 2ff1ef573..11c6e0048 100644 --- a/src/mbgl/gfx/attribute.hpp +++ b/src/mbgl/gfx/attribute.hpp @@ -119,10 +119,12 @@ public: uint32_t vertexStride; const VertexBufferResource* vertexBufferResource; uint32_t vertexOffset; + uint32_t bufferIndex; friend bool operator==(const AttributeBinding& lhs, const AttributeBinding& rhs) { return lhs.attribute == rhs.attribute && lhs.vertexStride == rhs.vertexStride && - lhs.vertexBufferResource == rhs.vertexBufferResource && lhs.vertexOffset == rhs.vertexOffset; + lhs.vertexBufferResource == rhs.vertexBufferResource && lhs.vertexOffset == rhs.vertexOffset && + lhs.bufferIndex == rhs.bufferIndex; } bool operator!=(const AttributeBinding& rhs) const { return !(*this == rhs); } @@ -293,6 +295,7 @@ AttributeBinding attributeBinding(const VertexBuffer>& Descriptor::data.stride, &buffer.getResource(), 0, + 0, }; } diff --git a/src/mbgl/gl/upload_pass.cpp b/src/mbgl/gl/upload_pass.cpp index 9c2dbcb56..ac456e11f 100644 --- a/src/mbgl/gl/upload_pass.cpp +++ b/src/mbgl/gl/upload_pass.cpp @@ -167,6 +167,7 @@ gfx::AttributeBindingArray UploadPass::buildAttributeBindings( /* vertexStride = */ vertexStride, /* vertexBufferResource = */ nullptr, // buffer details established later /* vertexOffset = */ 0, + /*.bufferIndex = */ 0, }; } @@ -187,6 +188,7 @@ gfx::AttributeBindingArray UploadPass::buildAttributeBindings( /*.vertexStride = */ effectiveAttr.getSharedStride(), /*.vertexBufferResource = */ buffer.get(), /*.vertexOffset = */ effectiveAttr.getSharedVertexOffset(), + /*.bufferIndex = */ 0, }; return; } @@ -230,6 +232,7 @@ gfx::AttributeBindingArray UploadPass::buildAttributeBindings( /* vertexStride = */ static_cast(stride), /* vertexBufferResource = */ nullptr, // buffer details established later /* vertexOffset = */ 0, + /*.bufferIndex = */ 0, }; pad(allData, align, padding); diff --git a/src/mbgl/mtl/context.cpp b/src/mbgl/mtl/context.cpp index 9a82d411c..00ec7b825 100644 --- a/src/mbgl/mtl/context.cpp +++ b/src/mbgl/mtl/context.cpp @@ -366,20 +366,19 @@ bool Context::renderTileClippingMasks(gfx::RenderPass& renderPass, if (!clipMaskPipelineState) { // A vertex descriptor tells Metal what's in the vertex buffer auto vertDesc = NS::RetainPtr(MTL::VertexDescriptor::vertexDescriptor()); - auto attribDesc = NS::TransferPtr(MTL::VertexAttributeDescriptor::alloc()->init()); - auto layoutDesc = NS::TransferPtr(MTL::VertexBufferLayoutDescriptor::alloc()->init()); - if (!vertDesc || !attribDesc || !layoutDesc) { + if (!vertDesc) { return false; } - attribDesc->setBufferIndex(ShaderClass::attributes[0].index); + const auto& attribDesc = vertDesc->attributes()->object(ShaderClass::attributes[0].index); + attribDesc->setBufferIndex(ShaderClass::attributes[0].bufferIndex); attribDesc->setOffset(0); attribDesc->setFormat(MTL::VertexFormatShort2); + + const auto& layoutDesc = vertDesc->layouts()->object(ShaderClass::attributes[0].bufferIndex); layoutDesc->setStride(static_cast(vertexSize)); layoutDesc->setStepFunction(MTL::VertexStepFunctionPerVertex); layoutDesc->setStepRate(1); - vertDesc->attributes()->setObject(attribDesc.get(), ShaderClass::attributes[0].index); - vertDesc->layouts()->setObject(layoutDesc.get(), ShaderClass::attributes[0].index); // Create a render pipeline state, telling Metal how to render the primitives const std::size_t hash = mbgl::util::hash(ShaderClass::attributes[0].index, @@ -422,7 +421,7 @@ bool Context::renderTileClippingMasks(gfx::RenderPass& renderPass, mtlRenderPass.setCullMode(MTL::CullModeNone); - mtlRenderPass.bindVertex(vertexRes, /*offset=*/0, ShaderClass::attributes[0].index); + mtlRenderPass.bindVertex(vertexRes, /*offset=*/0, ShaderClass::attributes[0].bufferIndex); // Instancing is disabled for now because the `[[stencil]]` attribute in the fragment shader output // that we need to apply a different stencil value for each tile causes a problem on some older (A8-A11) diff --git a/src/mbgl/mtl/drawable.cpp b/src/mbgl/mtl/drawable.cpp index 8219aeda9..9969807de 100644 --- a/src/mbgl/mtl/drawable.cpp +++ b/src/mbgl/mtl/drawable.cpp @@ -398,28 +398,24 @@ void Drawable::setVertexAttrId(const size_t id) { } void Drawable::bindAttributes(RenderPass& renderPass) const { - NS::UInteger attributeIndex = 0; for (const auto& binding : impl->attributeBindings) { const auto* buffer = static_cast(binding ? binding->vertexBufferResource : nullptr); if (buffer && buffer->get()) { assert(binding->vertexStride * impl->vertexCount <= getBufferSize(binding->vertexBufferResource)); - renderPass.bindVertex(buffer->get(), /*offset=*/0, attributeIndex); + renderPass.bindVertex(buffer->get(), /*offset=*/0, binding->bufferIndex); } - attributeIndex += 1; } } void Drawable::bindInstanceAttributes(RenderPass& renderPass) const { - NS::UInteger attributeIndex = 0; for (const auto& binding : impl->instanceBindings) { if (binding.has_value()) { const auto* buffer = static_cast(binding->vertexBufferResource); if (buffer && buffer->get()) { - renderPass.bindVertex(buffer->get(), /*offset=*/0, attributeIndex); + renderPass.bindVertex(buffer->get(), /*offset=*/0, binding->bufferIndex); } } - attributeIndex += 1; } } @@ -602,20 +598,22 @@ void Drawable::upload(gfx::UploadPass& uploadPass_) { } } - auto attribDesc = NS::TransferPtr(MTL::VertexAttributeDescriptor::alloc()->init()); - attribDesc->setBufferIndex(index); + const auto& attribDesc = vertDesc->attributes()->object(index); + attribDesc->setBufferIndex(binding->bufferIndex); attribDesc->setOffset(static_cast(binding->attribute.offset)); attribDesc->setFormat(mtlVertexTypeOf(binding->attribute.dataType)); - assert(binding->vertexStride > 0); - auto layoutDesc = NS::TransferPtr(MTL::VertexBufferLayoutDescriptor::alloc()->init()); - layoutDesc->setStride(static_cast(binding->vertexStride)); - layoutDesc->setStepFunction(binding->vertexBufferResource ? MTL::VertexStepFunctionPerVertex - : MTL::VertexStepFunctionConstant); - layoutDesc->setStepRate(binding->vertexBufferResource ? 1 : 0); - - vertDesc->attributes()->setObject(attribDesc.get(), index); - vertDesc->layouts()->setObject(layoutDesc.get(), index); + const auto& layoutDesc = vertDesc->layouts()->object(binding->bufferIndex); + if (!layoutDesc->stride()) { + assert(binding->vertexStride > 0); + layoutDesc->setStride(static_cast(binding->vertexStride)); + layoutDesc->setStepFunction(binding->vertexBufferResource ? MTL::VertexStepFunctionPerVertex + : MTL::VertexStepFunctionConstant); + layoutDesc->setStepRate(binding->vertexBufferResource ? 1 : 0); + } else { + assert(layoutDesc->stride() == static_cast(binding->vertexStride)); + assert(layoutDesc->stepRate() == (binding->vertexBufferResource ? 1 : 0)); + } mbgl::util::hash_combine(hash, mbgl::util::hash(index, diff --git a/src/mbgl/mtl/upload_pass.cpp b/src/mbgl/mtl/upload_pass.cpp index 4327773fe..2001cc319 100644 --- a/src/mbgl/mtl/upload_pass.cpp +++ b/src/mbgl/mtl/upload_pass.cpp @@ -142,6 +142,7 @@ gfx::AttributeBindingArray UploadPass::buildAttributeBindings( auto& effectiveAttr = override_ ? *override_ : default_; const auto& defaultAttr = static_cast(default_); const auto index = static_cast(defaultAttr.getIndex()); + const auto bufferIndex = static_cast(defaultAttr.getBufferIndex()); bindings.resize(std::max(bindings.size(), index + 1)); @@ -154,6 +155,7 @@ gfx::AttributeBindingArray UploadPass::buildAttributeBindings( .vertexStride = static_cast(VertexAttribute::getStrideOf(defaultAttr.getDataType())), .vertexBufferResource = nullptr, .vertexOffset = 0, + .bufferIndex = bufferIndex, }; return; } @@ -168,6 +170,7 @@ gfx::AttributeBindingArray UploadPass::buildAttributeBindings( /*.vertexStride = */ effectiveAttr.getSharedStride(), /*.vertexBufferResource = */ buffer_.get(), /*.vertexOffset = */ effectiveAttr.getSharedVertexOffset(), + /*.bufferIndex = */ bufferIndex, }; return; } @@ -182,6 +185,7 @@ gfx::AttributeBindingArray UploadPass::buildAttributeBindings( /*.vertexStride = */ static_cast(effectiveAttr.getStride()), /*.vertexBufferResource = */ buffer_.get(), /*.vertexOffset = */ 0, + /*.bufferIndex = */ bufferIndex, }; return; } diff --git a/src/mbgl/mtl/vertex_attribute.cpp b/src/mbgl/mtl/vertex_attribute.cpp index bdd5ea435..f93d3bbeb 100644 --- a/src/mbgl/mtl/vertex_attribute.cpp +++ b/src/mbgl/mtl/vertex_attribute.cpp @@ -35,5 +35,16 @@ const gfx::UniqueVertexBufferResource& VertexAttribute::getBuffer(gfx::VertexAtt return attrib_.getBuffer(); } +const std::unique_ptr& VertexAttributeArray::set(const size_t id, + int index, + gfx::AttributeDataType dataType, + int bufferIndex) { + auto& attrib = gfx::VertexAttributeArray::set(id, index, dataType, 1); + if (attrib) { + static_cast(attrib.get())->setBufferIndex(bufferIndex); + } + return attrib; +} + } // namespace mtl } // namespace mbgl diff --git a/src/mbgl/shaders/mtl/background.cpp b/src/mbgl/shaders/mtl/background.cpp index 2b9e8ab91..e0e5a333e 100644 --- a/src/mbgl/shaders/mtl/background.cpp +++ b/src/mbgl/shaders/mtl/background.cpp @@ -10,7 +10,7 @@ namespace shaders { using BackgroundShaderSource = ShaderSource; const std::array BackgroundShaderSource::attributes = { - AttributeInfo{backgroundUBOCount + 0, gfx::AttributeDataType::Float3, idBackgroundPosVertexAttribute}, + AttributeInfo{0, gfx::AttributeDataType::Float3, backgroundUBOCount + 0, idBackgroundPosVertexAttribute}, }; const std::array BackgroundShaderSource::textures = {}; @@ -20,7 +20,7 @@ const std::array BackgroundShaderSource::textures = {}; using BackgroundPatternShaderSource = ShaderSource; const std::array BackgroundPatternShaderSource::attributes = { - AttributeInfo{backgroundUBOCount + 0, gfx::AttributeDataType::Float3, idBackgroundPosVertexAttribute}, + AttributeInfo{0, gfx::AttributeDataType::Float3, backgroundUBOCount + 0, idBackgroundPosVertexAttribute}, }; const std::array BackgroundPatternShaderSource::textures = {TextureInfo{0, idBackgroundImageTexture}}; diff --git a/src/mbgl/shaders/mtl/circle.cpp b/src/mbgl/shaders/mtl/circle.cpp index 121d4a6ba..a9d6fa9b5 100644 --- a/src/mbgl/shaders/mtl/circle.cpp +++ b/src/mbgl/shaders/mtl/circle.cpp @@ -7,14 +7,16 @@ namespace shaders { using CircleShaderSource = ShaderSource; const std::array CircleShaderSource::attributes = { - AttributeInfo{circleUBOCount + 0, gfx::AttributeDataType::Short2, idCirclePosVertexAttribute}, - AttributeInfo{circleUBOCount + 1, gfx::AttributeDataType::Float4, idCircleColorVertexAttribute}, - AttributeInfo{circleUBOCount + 2, gfx::AttributeDataType::Float2, idCircleRadiusVertexAttribute}, - AttributeInfo{circleUBOCount + 3, gfx::AttributeDataType::Float2, idCircleBlurVertexAttribute}, - AttributeInfo{circleUBOCount + 4, gfx::AttributeDataType::Float2, idCircleOpacityVertexAttribute}, - AttributeInfo{circleUBOCount + 5, gfx::AttributeDataType::Float4, idCircleStrokeColorVertexAttribute}, - AttributeInfo{circleUBOCount + 6, gfx::AttributeDataType::Float2, idCircleStrokeWidthVertexAttribute}, - AttributeInfo{circleUBOCount + 7, gfx::AttributeDataType::Float2, idCircleStrokeOpacityVertexAttribute}, + AttributeInfo{0, gfx::AttributeDataType::Short2, circleUBOCount + 0, idCirclePosVertexAttribute}, + + // Data driven + AttributeInfo{1, gfx::AttributeDataType::Float4, circleUBOCount + 1, idCircleColorVertexAttribute}, + AttributeInfo{2, gfx::AttributeDataType::Float2, circleUBOCount + 1, idCircleRadiusVertexAttribute}, + AttributeInfo{3, gfx::AttributeDataType::Float2, circleUBOCount + 1, idCircleBlurVertexAttribute}, + AttributeInfo{4, gfx::AttributeDataType::Float2, circleUBOCount + 1, idCircleOpacityVertexAttribute}, + AttributeInfo{5, gfx::AttributeDataType::Float4, circleUBOCount + 1, idCircleStrokeColorVertexAttribute}, + AttributeInfo{6, gfx::AttributeDataType::Float2, circleUBOCount + 1, idCircleStrokeWidthVertexAttribute}, + AttributeInfo{7, gfx::AttributeDataType::Float2, circleUBOCount + 1, idCircleStrokeOpacityVertexAttribute}, }; const std::array CircleShaderSource::textures = {}; diff --git a/src/mbgl/shaders/mtl/clipping_mask.cpp b/src/mbgl/shaders/mtl/clipping_mask.cpp index be572874a..e76cfee90 100644 --- a/src/mbgl/shaders/mtl/clipping_mask.cpp +++ b/src/mbgl/shaders/mtl/clipping_mask.cpp @@ -6,7 +6,7 @@ namespace shaders { using ClippingMaskShaderSource = ShaderSource; const std::array ClippingMaskShaderSource::attributes = { - AttributeInfo{clippingMaskUBOCount + 0, gfx::AttributeDataType::Float3, idClippingMaskPosVertexAttribute}, + AttributeInfo{0, gfx::AttributeDataType::Float3, clippingMaskUBOCount + 0, idClippingMaskPosVertexAttribute}, }; const std::array ClippingMaskShaderSource::textures = {}; diff --git a/src/mbgl/shaders/mtl/collision.cpp b/src/mbgl/shaders/mtl/collision.cpp index 35e4792e6..f7b9cbb25 100644 --- a/src/mbgl/shaders/mtl/collision.cpp +++ b/src/mbgl/shaders/mtl/collision.cpp @@ -10,11 +10,13 @@ namespace shaders { using CollisionBoxShaderSource = ShaderSource; const std::array CollisionBoxShaderSource::attributes = { - AttributeInfo{collisionUBOCount + 0, gfx::AttributeDataType::Short2, idCollisionPosVertexAttribute}, - AttributeInfo{collisionUBOCount + 1, gfx::AttributeDataType::Short2, idCollisionAnchorPosVertexAttribute}, - AttributeInfo{collisionUBOCount + 2, gfx::AttributeDataType::Short2, idCollisionExtrudeVertexAttribute}, - AttributeInfo{collisionUBOCount + 3, gfx::AttributeDataType::UShort2, idCollisionPlacedVertexAttribute}, - AttributeInfo{collisionUBOCount + 4, gfx::AttributeDataType::Float2, idCollisionShiftVertexAttribute}, + AttributeInfo{0, gfx::AttributeDataType::Short2, collisionUBOCount + 0, idCollisionPosVertexAttribute}, + AttributeInfo{1, gfx::AttributeDataType::Short2, collisionUBOCount + 0, idCollisionAnchorPosVertexAttribute}, + AttributeInfo{2, gfx::AttributeDataType::Short2, collisionUBOCount + 0, idCollisionExtrudeVertexAttribute}, + + // Dynamic + AttributeInfo{3, gfx::AttributeDataType::UShort2, collisionUBOCount + 1, idCollisionPlacedVertexAttribute}, + AttributeInfo{4, gfx::AttributeDataType::Float2, collisionUBOCount + 1, idCollisionShiftVertexAttribute}, }; const std::array CollisionBoxShaderSource::textures = {}; @@ -24,10 +26,12 @@ const std::array CollisionBoxShaderSource::textures = {}; using CollisionCircleShaderSource = ShaderSource; const std::array CollisionCircleShaderSource::attributes = { - AttributeInfo{collisionUBOCount + 0, gfx::AttributeDataType::Short2, idCollisionPosVertexAttribute}, - AttributeInfo{collisionUBOCount + 1, gfx::AttributeDataType::Short2, idCollisionAnchorPosVertexAttribute}, - AttributeInfo{collisionUBOCount + 2, gfx::AttributeDataType::Short2, idCollisionExtrudeVertexAttribute}, - AttributeInfo{collisionUBOCount + 3, gfx::AttributeDataType::UShort2, idCollisionPlacedVertexAttribute}, + AttributeInfo{0, gfx::AttributeDataType::Short2, collisionUBOCount + 0, idCollisionPosVertexAttribute}, + AttributeInfo{1, gfx::AttributeDataType::Short2, collisionUBOCount + 0, idCollisionAnchorPosVertexAttribute}, + AttributeInfo{2, gfx::AttributeDataType::Short2, collisionUBOCount + 0, idCollisionExtrudeVertexAttribute}, + + // Dynamic + AttributeInfo{3, gfx::AttributeDataType::UShort2, collisionUBOCount + 1, idCollisionPlacedVertexAttribute}, }; const std::array CollisionCircleShaderSource::textures = {}; diff --git a/src/mbgl/shaders/mtl/color_relief.cpp b/src/mbgl/shaders/mtl/color_relief.cpp index 14f8bf692..967edeb55 100644 --- a/src/mbgl/shaders/mtl/color_relief.cpp +++ b/src/mbgl/shaders/mtl/color_relief.cpp @@ -8,8 +8,8 @@ namespace shaders { using ColorReliefShaderSource = ShaderSource; const std::array ColorReliefShaderSource::attributes = { - AttributeInfo{colorReliefUBOCount + 0, gfx::AttributeDataType::Short2, idColorReliefPosVertexAttribute}, - AttributeInfo{colorReliefUBOCount + 1, gfx::AttributeDataType::Short2, idColorReliefTexturePosVertexAttribute}, + AttributeInfo{0, gfx::AttributeDataType::Short2, colorReliefUBOCount + 0, idColorReliefPosVertexAttribute}, + AttributeInfo{1, gfx::AttributeDataType::Short2, colorReliefUBOCount + 0, idColorReliefTexturePosVertexAttribute}, }; const std::array ColorReliefShaderSource::textures = { TextureInfo{0, idColorReliefImageTexture}, diff --git a/src/mbgl/shaders/mtl/custom_geometry.cpp b/src/mbgl/shaders/mtl/custom_geometry.cpp index 45cfe5b07..57f5593ef 100644 --- a/src/mbgl/shaders/mtl/custom_geometry.cpp +++ b/src/mbgl/shaders/mtl/custom_geometry.cpp @@ -7,8 +7,8 @@ namespace shaders { using CustomGeometryShaderSource = ShaderSource; const std::array CustomGeometryShaderSource::attributes = { - AttributeInfo{customGeometryUBOCount + 0, gfx::AttributeDataType::Float3, idCustomGeometryPosVertexAttribute}, - AttributeInfo{customGeometryUBOCount + 1, gfx::AttributeDataType::Float2, idCustomGeometryTexVertexAttribute}, + AttributeInfo{0, gfx::AttributeDataType::Float3, customGeometryUBOCount + 0, idCustomGeometryPosVertexAttribute}, + AttributeInfo{1, gfx::AttributeDataType::Float2, customGeometryUBOCount + 0, idCustomGeometryTexVertexAttribute}, }; const std::array CustomGeometryShaderSource::textures = {TextureInfo{0, idCustomGeometryTexture}}; diff --git a/src/mbgl/shaders/mtl/custom_symbol_icon.cpp b/src/mbgl/shaders/mtl/custom_symbol_icon.cpp index 849d86844..35e47da65 100644 --- a/src/mbgl/shaders/mtl/custom_symbol_icon.cpp +++ b/src/mbgl/shaders/mtl/custom_symbol_icon.cpp @@ -7,8 +7,8 @@ namespace shaders { using CustomSymbolIconShaderSource = ShaderSource; const std::array CustomSymbolIconShaderSource::attributes = { - AttributeInfo{customSymbolUBOCount + 0, gfx::AttributeDataType::Float2, idCustomSymbolPosVertexAttribute}, - AttributeInfo{customSymbolUBOCount + 1, gfx::AttributeDataType::Float2, idCustomSymbolTexVertexAttribute}, + AttributeInfo{0, gfx::AttributeDataType::Float2, customSymbolUBOCount + 0, idCustomSymbolPosVertexAttribute}, + AttributeInfo{1, gfx::AttributeDataType::Float2, customSymbolUBOCount + 0, idCustomSymbolTexVertexAttribute}, }; const std::array CustomSymbolIconShaderSource::textures = { TextureInfo{0, idCustomSymbolImageTexture}, diff --git a/src/mbgl/shaders/mtl/debug.cpp b/src/mbgl/shaders/mtl/debug.cpp index ffebb0d20..260083201 100644 --- a/src/mbgl/shaders/mtl/debug.cpp +++ b/src/mbgl/shaders/mtl/debug.cpp @@ -7,7 +7,7 @@ namespace shaders { using DebugShaderSource = ShaderSource; const std::array DebugShaderSource::attributes = { - AttributeInfo{debugUBOCount + 0, gfx::AttributeDataType::Short2, idDebugPosVertexAttribute}, + AttributeInfo{0, gfx::AttributeDataType::Short2, debugUBOCount + 0, idDebugPosVertexAttribute}, }; const std::array DebugShaderSource::textures = { TextureInfo{0, idDebugOverlayTexture}, diff --git a/src/mbgl/shaders/mtl/fill.cpp b/src/mbgl/shaders/mtl/fill.cpp index 20fce1316..2430411fb 100644 --- a/src/mbgl/shaders/mtl/fill.cpp +++ b/src/mbgl/shaders/mtl/fill.cpp @@ -10,9 +10,11 @@ namespace shaders { using FillShaderSource = ShaderSource; const std::array FillShaderSource::attributes = { - AttributeInfo{fillUBOCount + 0, gfx::AttributeDataType::Short2, idFillPosVertexAttribute}, - AttributeInfo{fillUBOCount + 1, gfx::AttributeDataType::Float4, idFillColorVertexAttribute}, - AttributeInfo{fillUBOCount + 2, gfx::AttributeDataType::Float2, idFillOpacityVertexAttribute}, + AttributeInfo{0, gfx::AttributeDataType::Short2, fillUBOCount + 0, idFillPosVertexAttribute}, + + // Data driven + AttributeInfo{1, gfx::AttributeDataType::Float4, fillUBOCount + 1, idFillColorVertexAttribute}, + AttributeInfo{2, gfx::AttributeDataType::Float2, fillUBOCount + 1, idFillOpacityVertexAttribute}, }; const std::array FillShaderSource::textures = {}; @@ -22,9 +24,11 @@ const std::array FillShaderSource::textures = {}; using FillOutlineShaderSource = ShaderSource; const std::array FillOutlineShaderSource::attributes = { - AttributeInfo{fillUBOCount + 0, gfx::AttributeDataType::Short2, idFillPosVertexAttribute}, - AttributeInfo{fillUBOCount + 1, gfx::AttributeDataType::Float4, idFillOutlineColorVertexAttribute}, - AttributeInfo{fillUBOCount + 2, gfx::AttributeDataType::Float2, idFillOpacityVertexAttribute}, + AttributeInfo{0, gfx::AttributeDataType::Short2, fillUBOCount + 0, idFillPosVertexAttribute}, + + // Data driven + AttributeInfo{1, gfx::AttributeDataType::Float4, fillUBOCount + 1, idFillOutlineColorVertexAttribute}, + AttributeInfo{2, gfx::AttributeDataType::Float2, fillUBOCount + 1, idFillOpacityVertexAttribute}, }; const std::array FillOutlineShaderSource::textures = {}; @@ -34,10 +38,12 @@ const std::array FillOutlineShaderSource::textures = {}; using FillPatternShaderSource = ShaderSource; const std::array FillPatternShaderSource::attributes = { - AttributeInfo{fillUBOCount + 0, gfx::AttributeDataType::Short2, idFillPosVertexAttribute}, - AttributeInfo{fillUBOCount + 1, gfx::AttributeDataType::UShort4, idFillPatternFromVertexAttribute}, - AttributeInfo{fillUBOCount + 2, gfx::AttributeDataType::UShort4, idFillPatternToVertexAttribute}, - AttributeInfo{fillUBOCount + 3, gfx::AttributeDataType::Float2, idFillOpacityVertexAttribute}, + AttributeInfo{0, gfx::AttributeDataType::Short2, fillUBOCount + 0, idFillPosVertexAttribute}, + + // Data driven + AttributeInfo{1, gfx::AttributeDataType::UShort4, fillUBOCount + 1, idFillPatternFromVertexAttribute}, + AttributeInfo{2, gfx::AttributeDataType::UShort4, fillUBOCount + 1, idFillPatternToVertexAttribute}, + AttributeInfo{3, gfx::AttributeDataType::Float2, fillUBOCount + 1, idFillOpacityVertexAttribute}, }; const std::array FillPatternShaderSource::textures = { TextureInfo{0, idFillImageTexture}, @@ -49,10 +55,12 @@ const std::array FillPatternShaderSource::textures = { using FillOutlinePatternShaderSource = ShaderSource; const std::array FillOutlinePatternShaderSource::attributes = { - AttributeInfo{fillUBOCount + 0, gfx::AttributeDataType::Short2, idFillPosVertexAttribute}, - AttributeInfo{fillUBOCount + 1, gfx::AttributeDataType::UShort4, idFillPatternFromVertexAttribute}, - AttributeInfo{fillUBOCount + 2, gfx::AttributeDataType::UShort4, idFillPatternToVertexAttribute}, - AttributeInfo{fillUBOCount + 3, gfx::AttributeDataType::Float2, idFillOpacityVertexAttribute}, + AttributeInfo{0, gfx::AttributeDataType::Short2, fillUBOCount + 0, idFillPosVertexAttribute}, + + // Data driven + AttributeInfo{1, gfx::AttributeDataType::UShort4, fillUBOCount + 1, idFillPatternFromVertexAttribute}, + AttributeInfo{2, gfx::AttributeDataType::UShort4, fillUBOCount + 1, idFillPatternToVertexAttribute}, + AttributeInfo{3, gfx::AttributeDataType::Float2, fillUBOCount + 1, idFillOpacityVertexAttribute}, }; const std::array FillOutlinePatternShaderSource::textures = { TextureInfo{0, idFillImageTexture}, @@ -65,8 +73,8 @@ using FillOutlineTriangulatedShaderSource = ShaderSource; const std::array FillOutlineTriangulatedShaderSource::attributes = { - AttributeInfo{fillUBOCount + 0, gfx::AttributeDataType::Short2, idLinePosNormalVertexAttribute}, - AttributeInfo{fillUBOCount + 1, gfx::AttributeDataType::UByte4, idLineDataVertexAttribute}, + AttributeInfo{0, gfx::AttributeDataType::Short2, fillUBOCount + 0, idLinePosNormalVertexAttribute}, + AttributeInfo{1, gfx::AttributeDataType::UByte4, fillUBOCount + 0, idLineDataVertexAttribute}, }; const std::array FillOutlineTriangulatedShaderSource::textures = {}; diff --git a/src/mbgl/shaders/mtl/fill_extrusion.cpp b/src/mbgl/shaders/mtl/fill_extrusion.cpp index c39a9620a..a4186077e 100644 --- a/src/mbgl/shaders/mtl/fill_extrusion.cpp +++ b/src/mbgl/shaders/mtl/fill_extrusion.cpp @@ -10,11 +10,13 @@ namespace shaders { using FillExtrusionShaderSource = ShaderSource; const std::array FillExtrusionShaderSource::attributes = { - AttributeInfo{fillExtrusionUBOCount + 0, gfx::AttributeDataType::Short2, idFillExtrusionPosVertexAttribute}, - AttributeInfo{fillExtrusionUBOCount + 1, gfx::AttributeDataType::Short4, idFillExtrusionNormalEdVertexAttribute}, - AttributeInfo{fillExtrusionUBOCount + 2, gfx::AttributeDataType::Float4, idFillExtrusionColorVertexAttribute}, - AttributeInfo{fillExtrusionUBOCount + 3, gfx::AttributeDataType::Float, idFillExtrusionBaseVertexAttribute}, - AttributeInfo{fillExtrusionUBOCount + 4, gfx::AttributeDataType::Float, idFillExtrusionHeightVertexAttribute}, + AttributeInfo{0, gfx::AttributeDataType::Short2, fillExtrusionUBOCount + 0, idFillExtrusionPosVertexAttribute}, + AttributeInfo{1, gfx::AttributeDataType::Short4, fillExtrusionUBOCount + 0, idFillExtrusionNormalEdVertexAttribute}, + + // Data driven + AttributeInfo{2, gfx::AttributeDataType::Float4, fillExtrusionUBOCount + 1, idFillExtrusionColorVertexAttribute}, + AttributeInfo{3, gfx::AttributeDataType::Float, fillExtrusionUBOCount + 1, idFillExtrusionBaseVertexAttribute}, + AttributeInfo{4, gfx::AttributeDataType::Float, fillExtrusionUBOCount + 1, idFillExtrusionHeightVertexAttribute}, }; const std::array FillExtrusionShaderSource::textures = {}; @@ -24,13 +26,16 @@ const std::array FillExtrusionShaderSource::textures = {}; using FillExtrusionPatternShaderSource = ShaderSource; const std::array FillExtrusionPatternShaderSource::attributes = { - AttributeInfo{fillExtrusionUBOCount + 0, gfx::AttributeDataType::Short2, idFillExtrusionPosVertexAttribute}, - AttributeInfo{fillExtrusionUBOCount + 1, gfx::AttributeDataType::Short4, idFillExtrusionNormalEdVertexAttribute}, - AttributeInfo{fillExtrusionUBOCount + 2, gfx::AttributeDataType::Float, idFillExtrusionBaseVertexAttribute}, - AttributeInfo{fillExtrusionUBOCount + 3, gfx::AttributeDataType::Float, idFillExtrusionHeightVertexAttribute}, + AttributeInfo{0, gfx::AttributeDataType::Short2, fillExtrusionUBOCount + 0, idFillExtrusionPosVertexAttribute}, + AttributeInfo{1, gfx::AttributeDataType::Short4, fillExtrusionUBOCount + 0, idFillExtrusionNormalEdVertexAttribute}, + + // Data driven + AttributeInfo{2, gfx::AttributeDataType::Float, fillExtrusionUBOCount + 1, idFillExtrusionBaseVertexAttribute}, + AttributeInfo{3, gfx::AttributeDataType::Float, fillExtrusionUBOCount + 1, idFillExtrusionHeightVertexAttribute}, AttributeInfo{ - fillExtrusionUBOCount + 4, gfx::AttributeDataType::UShort4, idFillExtrusionPatternFromVertexAttribute}, - AttributeInfo{fillExtrusionUBOCount + 5, gfx::AttributeDataType::UShort4, idFillExtrusionPatternToVertexAttribute}, + 4, gfx::AttributeDataType::UShort4, fillExtrusionUBOCount + 1, idFillExtrusionPatternFromVertexAttribute}, + AttributeInfo{ + 5, gfx::AttributeDataType::UShort4, fillExtrusionUBOCount + 1, idFillExtrusionPatternToVertexAttribute}, }; const std::array FillExtrusionPatternShaderSource::textures = { TextureInfo{0, idFillExtrusionImageTexture}, diff --git a/src/mbgl/shaders/mtl/heatmap.cpp b/src/mbgl/shaders/mtl/heatmap.cpp index 45351bb32..4cb0767d1 100644 --- a/src/mbgl/shaders/mtl/heatmap.cpp +++ b/src/mbgl/shaders/mtl/heatmap.cpp @@ -7,9 +7,11 @@ namespace shaders { using HeatmapShaderSource = ShaderSource; const std::array HeatmapShaderSource::attributes = { - AttributeInfo{heatmapUBOCount + 0, gfx::AttributeDataType::Short2, idHeatmapPosVertexAttribute}, - AttributeInfo{heatmapUBOCount + 1, gfx::AttributeDataType::Float2, idHeatmapWeightVertexAttribute}, - AttributeInfo{heatmapUBOCount + 2, gfx::AttributeDataType::Float2, idHeatmapRadiusVertexAttribute}, + AttributeInfo{0, gfx::AttributeDataType::Short2, heatmapUBOCount + 0, idHeatmapPosVertexAttribute}, + + // Data driven + AttributeInfo{1, gfx::AttributeDataType::Float2, heatmapUBOCount + 1, idHeatmapWeightVertexAttribute}, + AttributeInfo{2, gfx::AttributeDataType::Float2, heatmapUBOCount + 1, idHeatmapRadiusVertexAttribute}, }; const std::array HeatmapShaderSource::textures = {}; diff --git a/src/mbgl/shaders/mtl/heatmap_texture.cpp b/src/mbgl/shaders/mtl/heatmap_texture.cpp index 28fb4e54a..0512d488a 100644 --- a/src/mbgl/shaders/mtl/heatmap_texture.cpp +++ b/src/mbgl/shaders/mtl/heatmap_texture.cpp @@ -7,7 +7,7 @@ namespace shaders { using HeatmapTextureShaderSource = ShaderSource; const std::array HeatmapTextureShaderSource::attributes = { - AttributeInfo{heatmapTextureUBOCount + 0, gfx::AttributeDataType::Short2, idHeatmapPosVertexAttribute}, + AttributeInfo{0, gfx::AttributeDataType::Short2, heatmapTextureUBOCount + 0, idHeatmapPosVertexAttribute}, }; const std::array HeatmapTextureShaderSource::textures = { TextureInfo{0, idHeatmapImageTexture}, diff --git a/src/mbgl/shaders/mtl/hillshade.cpp b/src/mbgl/shaders/mtl/hillshade.cpp index d06950228..68e0f6c9b 100644 --- a/src/mbgl/shaders/mtl/hillshade.cpp +++ b/src/mbgl/shaders/mtl/hillshade.cpp @@ -7,8 +7,8 @@ namespace shaders { using HillshadeShaderSource = ShaderSource; const std::array HillshadeShaderSource::attributes = { - AttributeInfo{hillshadeUBOCount + 0, gfx::AttributeDataType::Short2, idHillshadePosVertexAttribute}, - AttributeInfo{hillshadeUBOCount + 1, gfx::AttributeDataType::Short2, idHillshadeTexturePosVertexAttribute}, + AttributeInfo{0, gfx::AttributeDataType::Short2, hillshadeUBOCount + 0, idHillshadePosVertexAttribute}, + AttributeInfo{1, gfx::AttributeDataType::Short2, hillshadeUBOCount + 0, idHillshadeTexturePosVertexAttribute}, }; const std::array HillshadeShaderSource::textures = { TextureInfo{0, idHillshadeImageTexture}, diff --git a/src/mbgl/shaders/mtl/hillshade_prepare.cpp b/src/mbgl/shaders/mtl/hillshade_prepare.cpp index 3cd1571de..524352209 100644 --- a/src/mbgl/shaders/mtl/hillshade_prepare.cpp +++ b/src/mbgl/shaders/mtl/hillshade_prepare.cpp @@ -7,8 +7,9 @@ namespace shaders { using HillshadePrepareShaderSource = ShaderSource; const std::array HillshadePrepareShaderSource::attributes = { - AttributeInfo{hillshadePrepareUBOCount + 0, gfx::AttributeDataType::Short2, idHillshadePosVertexAttribute}, - AttributeInfo{hillshadePrepareUBOCount + 1, gfx::AttributeDataType::Short2, idHillshadeTexturePosVertexAttribute}, + AttributeInfo{0, gfx::AttributeDataType::Short2, hillshadePrepareUBOCount + 0, idHillshadePosVertexAttribute}, + AttributeInfo{ + 1, gfx::AttributeDataType::Short2, hillshadePrepareUBOCount + 0, idHillshadeTexturePosVertexAttribute}, }; const std::array HillshadePrepareShaderSource::textures = { TextureInfo{0, idHillshadeImageTexture}, diff --git a/src/mbgl/shaders/mtl/line.cpp b/src/mbgl/shaders/mtl/line.cpp index 028085a5f..b6aebec5c 100644 --- a/src/mbgl/shaders/mtl/line.cpp +++ b/src/mbgl/shaders/mtl/line.cpp @@ -10,14 +10,16 @@ namespace shaders { using LineShaderSource = ShaderSource; const std::array LineShaderSource::attributes = { - AttributeInfo{lineUBOCount + 0, gfx::AttributeDataType::Short2, idLinePosNormalVertexAttribute}, - AttributeInfo{lineUBOCount + 1, gfx::AttributeDataType::UByte4, idLineDataVertexAttribute}, - AttributeInfo{lineUBOCount + 2, gfx::AttributeDataType::Float4, idLineColorVertexAttribute}, - AttributeInfo{lineUBOCount + 3, gfx::AttributeDataType::Float2, idLineBlurVertexAttribute}, - AttributeInfo{lineUBOCount + 4, gfx::AttributeDataType::Float2, idLineOpacityVertexAttribute}, - AttributeInfo{lineUBOCount + 5, gfx::AttributeDataType::Float2, idLineGapWidthVertexAttribute}, - AttributeInfo{lineUBOCount + 6, gfx::AttributeDataType::Float2, idLineOffsetVertexAttribute}, - AttributeInfo{lineUBOCount + 7, gfx::AttributeDataType::Float2, idLineWidthVertexAttribute}, + AttributeInfo{0, gfx::AttributeDataType::Short2, lineUBOCount + 0, idLinePosNormalVertexAttribute}, + AttributeInfo{1, gfx::AttributeDataType::UByte4, lineUBOCount + 0, idLineDataVertexAttribute}, + + // Data driven + AttributeInfo{2, gfx::AttributeDataType::Float4, lineUBOCount + 1, idLineColorVertexAttribute}, + AttributeInfo{3, gfx::AttributeDataType::Float2, lineUBOCount + 1, idLineBlurVertexAttribute}, + AttributeInfo{4, gfx::AttributeDataType::Float2, lineUBOCount + 1, idLineOpacityVertexAttribute}, + AttributeInfo{5, gfx::AttributeDataType::Float2, lineUBOCount + 1, idLineGapWidthVertexAttribute}, + AttributeInfo{6, gfx::AttributeDataType::Float2, lineUBOCount + 1, idLineOffsetVertexAttribute}, + AttributeInfo{7, gfx::AttributeDataType::Float2, lineUBOCount + 1, idLineWidthVertexAttribute}, }; const std::array LineShaderSource::textures = {}; @@ -27,13 +29,15 @@ const std::array LineShaderSource::textures = {}; using LineGradientShaderSource = ShaderSource; const std::array LineGradientShaderSource::attributes = { - AttributeInfo{lineUBOCount + 0, gfx::AttributeDataType::Short2, idLinePosNormalVertexAttribute}, - AttributeInfo{lineUBOCount + 1, gfx::AttributeDataType::UByte4, idLineDataVertexAttribute}, - AttributeInfo{lineUBOCount + 2, gfx::AttributeDataType::Float2, idLineBlurVertexAttribute}, - AttributeInfo{lineUBOCount + 3, gfx::AttributeDataType::Float2, idLineOpacityVertexAttribute}, - AttributeInfo{lineUBOCount + 4, gfx::AttributeDataType::Float2, idLineGapWidthVertexAttribute}, - AttributeInfo{lineUBOCount + 5, gfx::AttributeDataType::Float2, idLineOffsetVertexAttribute}, - AttributeInfo{lineUBOCount + 6, gfx::AttributeDataType::Float2, idLineWidthVertexAttribute}, + AttributeInfo{0, gfx::AttributeDataType::Short2, lineUBOCount + 0, idLinePosNormalVertexAttribute}, + AttributeInfo{1, gfx::AttributeDataType::UByte4, lineUBOCount + 0, idLineDataVertexAttribute}, + + // Data driven + AttributeInfo{2, gfx::AttributeDataType::Float2, lineUBOCount + 1, idLineBlurVertexAttribute}, + AttributeInfo{3, gfx::AttributeDataType::Float2, lineUBOCount + 1, idLineOpacityVertexAttribute}, + AttributeInfo{4, gfx::AttributeDataType::Float2, lineUBOCount + 1, idLineGapWidthVertexAttribute}, + AttributeInfo{5, gfx::AttributeDataType::Float2, lineUBOCount + 1, idLineOffsetVertexAttribute}, + AttributeInfo{6, gfx::AttributeDataType::Float2, lineUBOCount + 1, idLineWidthVertexAttribute}, }; const std::array LineGradientShaderSource::textures = { TextureInfo{0, idLineImageTexture}, @@ -45,15 +49,17 @@ const std::array LineGradientShaderSource::textures = { using LinePatternShaderSource = ShaderSource; const std::array LinePatternShaderSource::attributes = { - AttributeInfo{lineUBOCount + 0, gfx::AttributeDataType::Short2, idLinePosNormalVertexAttribute}, - AttributeInfo{lineUBOCount + 1, gfx::AttributeDataType::UByte4, idLineDataVertexAttribute}, - AttributeInfo{lineUBOCount + 2, gfx::AttributeDataType::Float2, idLineBlurVertexAttribute}, - AttributeInfo{lineUBOCount + 3, gfx::AttributeDataType::Float2, idLineOpacityVertexAttribute}, - AttributeInfo{lineUBOCount + 4, gfx::AttributeDataType::Float2, idLineGapWidthVertexAttribute}, - AttributeInfo{lineUBOCount + 5, gfx::AttributeDataType::Float2, idLineOffsetVertexAttribute}, - AttributeInfo{lineUBOCount + 6, gfx::AttributeDataType::Float2, idLineWidthVertexAttribute}, - AttributeInfo{lineUBOCount + 7, gfx::AttributeDataType::UShort4, idLinePatternFromVertexAttribute}, - AttributeInfo{lineUBOCount + 8, gfx::AttributeDataType::UShort4, idLinePatternToVertexAttribute}, + AttributeInfo{0, gfx::AttributeDataType::Short2, lineUBOCount + 0, idLinePosNormalVertexAttribute}, + AttributeInfo{1, gfx::AttributeDataType::UByte4, lineUBOCount + 0, idLineDataVertexAttribute}, + + // Data driven + AttributeInfo{2, gfx::AttributeDataType::Float2, lineUBOCount + 1, idLineBlurVertexAttribute}, + AttributeInfo{3, gfx::AttributeDataType::Float2, lineUBOCount + 1, idLineOpacityVertexAttribute}, + AttributeInfo{4, gfx::AttributeDataType::Float2, lineUBOCount + 1, idLineGapWidthVertexAttribute}, + AttributeInfo{5, gfx::AttributeDataType::Float2, lineUBOCount + 1, idLineOffsetVertexAttribute}, + AttributeInfo{6, gfx::AttributeDataType::Float2, lineUBOCount + 1, idLineWidthVertexAttribute}, + AttributeInfo{7, gfx::AttributeDataType::UShort4, lineUBOCount + 1, idLinePatternFromVertexAttribute}, + AttributeInfo{8, gfx::AttributeDataType::UShort4, lineUBOCount + 1, idLinePatternToVertexAttribute}, }; const std::array LinePatternShaderSource::textures = { TextureInfo{0, idLineImageTexture}, @@ -65,15 +71,17 @@ const std::array LinePatternShaderSource::textures = { using LineSDFShaderSource = ShaderSource; const std::array LineSDFShaderSource::attributes = { - AttributeInfo{lineUBOCount + 0, gfx::AttributeDataType::Short2, idLinePosNormalVertexAttribute}, - AttributeInfo{lineUBOCount + 1, gfx::AttributeDataType::UByte4, idLineDataVertexAttribute}, - AttributeInfo{lineUBOCount + 2, gfx::AttributeDataType::Float4, idLineColorVertexAttribute}, - AttributeInfo{lineUBOCount + 3, gfx::AttributeDataType::Float2, idLineBlurVertexAttribute}, - AttributeInfo{lineUBOCount + 4, gfx::AttributeDataType::Float2, idLineOpacityVertexAttribute}, - AttributeInfo{lineUBOCount + 5, gfx::AttributeDataType::Float2, idLineGapWidthVertexAttribute}, - AttributeInfo{lineUBOCount + 6, gfx::AttributeDataType::Float2, idLineOffsetVertexAttribute}, - AttributeInfo{lineUBOCount + 7, gfx::AttributeDataType::Float2, idLineWidthVertexAttribute}, - AttributeInfo{lineUBOCount + 8, gfx::AttributeDataType::Float2, idLineFloorWidthVertexAttribute}, + AttributeInfo{0, gfx::AttributeDataType::Short2, lineUBOCount + 0, idLinePosNormalVertexAttribute}, + AttributeInfo{1, gfx::AttributeDataType::UByte4, lineUBOCount + 0, idLineDataVertexAttribute}, + + // Data driven + AttributeInfo{2, gfx::AttributeDataType::Float4, lineUBOCount + 1, idLineColorVertexAttribute}, + AttributeInfo{3, gfx::AttributeDataType::Float2, lineUBOCount + 1, idLineBlurVertexAttribute}, + AttributeInfo{4, gfx::AttributeDataType::Float2, lineUBOCount + 1, idLineOpacityVertexAttribute}, + AttributeInfo{5, gfx::AttributeDataType::Float2, lineUBOCount + 1, idLineGapWidthVertexAttribute}, + AttributeInfo{6, gfx::AttributeDataType::Float2, lineUBOCount + 1, idLineOffsetVertexAttribute}, + AttributeInfo{7, gfx::AttributeDataType::Float2, lineUBOCount + 1, idLineWidthVertexAttribute}, + AttributeInfo{8, gfx::AttributeDataType::Float2, lineUBOCount + 1, idLineFloorWidthVertexAttribute}, }; const std::array LineSDFShaderSource::textures = { TextureInfo{0, idLineImageTexture}, diff --git a/src/mbgl/shaders/mtl/location_indicator.cpp b/src/mbgl/shaders/mtl/location_indicator.cpp index fcdd06d4e..0604357f8 100644 --- a/src/mbgl/shaders/mtl/location_indicator.cpp +++ b/src/mbgl/shaders/mtl/location_indicator.cpp @@ -7,14 +7,16 @@ namespace shaders { using LocationIndicatorShaderSource = ShaderSource; const std::array LocationIndicatorShaderSource::attributes = {AttributeInfo{ - locationIndicatorUBOCount + 0, gfx::AttributeDataType::Float2, idLocationIndicatorPosVertexAttribute}}; + 0, gfx::AttributeDataType::Float2, locationIndicatorUBOCount + 0, idLocationIndicatorPosVertexAttribute}}; using LocationIndicatorTexturedShaderSource = ShaderSource; const std::array LocationIndicatorTexturedShaderSource::attributes = { - AttributeInfo{locationIndicatorUBOCount + 0, gfx::AttributeDataType::Float2, idLocationIndicatorPosVertexAttribute}, - AttributeInfo{locationIndicatorUBOCount + 1, gfx::AttributeDataType::Float2, idLocationIndicatorTexVertexAttribute}, + AttributeInfo{ + 0, gfx::AttributeDataType::Float2, locationIndicatorUBOCount + 0, idLocationIndicatorPosVertexAttribute}, + AttributeInfo{ + 1, gfx::AttributeDataType::Float2, locationIndicatorUBOCount + 1, idLocationIndicatorTexVertexAttribute}, }; const std::array LocationIndicatorTexturedShaderSource::textures = { diff --git a/src/mbgl/shaders/mtl/raster.cpp b/src/mbgl/shaders/mtl/raster.cpp index a3b5e1cb1..c0fd31e0a 100644 --- a/src/mbgl/shaders/mtl/raster.cpp +++ b/src/mbgl/shaders/mtl/raster.cpp @@ -7,8 +7,8 @@ namespace shaders { using RasterShaderSource = ShaderSource; const std::array RasterShaderSource::attributes = { - AttributeInfo{rasterUBOCount + 0, gfx::AttributeDataType::Short2, idRasterPosVertexAttribute}, - AttributeInfo{rasterUBOCount + 1, gfx::AttributeDataType::Short2, idRasterTexturePosVertexAttribute}, + AttributeInfo{0, gfx::AttributeDataType::Short2, rasterUBOCount + 0, idRasterPosVertexAttribute}, + AttributeInfo{1, gfx::AttributeDataType::Short2, rasterUBOCount + 0, idRasterTexturePosVertexAttribute}, }; const std::array RasterShaderSource::textures = { TextureInfo{0, idRasterImage0Texture}, diff --git a/src/mbgl/shaders/mtl/shader_program.cpp b/src/mbgl/shaders/mtl/shader_program.cpp index c75fe60ed..d6015f77a 100644 --- a/src/mbgl/shaders/mtl/shader_program.cpp +++ b/src/mbgl/shaders/mtl/shader_program.cpp @@ -185,23 +185,25 @@ std::optional ShaderProgram::getSamplerLocation(const size_t id) const { void ShaderProgram::initAttribute(const shaders::AttributeInfo& info) { const auto index = static_cast(info.index); + const auto bufferIndex = static_cast(info.bufferIndex); #if !defined(NDEBUG) // Indexes must be unique, if there's a conflict check the `attributes` array in the shader vertexAttributes.visitAttributes([&](const gfx::VertexAttribute& attrib) { assert(attrib.getIndex() != index); }); instanceAttributes.visitAttributes([&](const gfx::VertexAttribute& attrib) { assert(attrib.getIndex() != index); }); #endif - vertexAttributes.set(info.id, index, info.dataType, 1); + vertexAttributes.set(info.id, index, info.dataType, bufferIndex); } void ShaderProgram::initInstanceAttribute(const shaders::AttributeInfo& info) { // Index is the block index of the instance attribute const auto index = static_cast(info.index); + const auto bufferIndex = static_cast(info.bufferIndex); #if !defined(NDEBUG) // Indexes must not be reused by regular attributes or uniform blocks // More than one instance attribute can have the same index, if they share the block vertexAttributes.visitAttributes([&](const gfx::VertexAttribute& attrib) { assert(attrib.getIndex() != index); }); #endif - instanceAttributes.set(info.id, index, info.dataType, 1); + instanceAttributes.set(info.id, index, info.dataType, bufferIndex); } void ShaderProgram::initTexture(const shaders::TextureInfo& info) { diff --git a/src/mbgl/shaders/mtl/symbol.cpp b/src/mbgl/shaders/mtl/symbol.cpp index 67d1a2be6..7daef0cf3 100644 --- a/src/mbgl/shaders/mtl/symbol.cpp +++ b/src/mbgl/shaders/mtl/symbol.cpp @@ -10,15 +10,18 @@ namespace shaders { using SymbolIconShaderSource = ShaderSource; const std::array SymbolIconShaderSource::attributes = { - // always attributes - AttributeInfo{symbolUBOCount + 0, gfx::AttributeDataType::Short4, idSymbolPosOffsetVertexAttribute}, - AttributeInfo{symbolUBOCount + 1, gfx::AttributeDataType::UShort4, idSymbolDataVertexAttribute}, - AttributeInfo{symbolUBOCount + 2, gfx::AttributeDataType::Short4, idSymbolPixelOffsetVertexAttribute}, - AttributeInfo{symbolUBOCount + 3, gfx::AttributeDataType::Float3, idSymbolProjectedPosVertexAttribute}, - AttributeInfo{symbolUBOCount + 4, gfx::AttributeDataType::Float, idSymbolFadeOpacityVertexAttribute}, + AttributeInfo{0, gfx::AttributeDataType::Short4, symbolUBOCount + 0, idSymbolPosOffsetVertexAttribute}, + AttributeInfo{1, gfx::AttributeDataType::UShort4, symbolUBOCount + 0, idSymbolDataVertexAttribute}, + AttributeInfo{2, gfx::AttributeDataType::Short4, symbolUBOCount + 0, idSymbolPixelOffsetVertexAttribute}, - // sometimes uniforms - AttributeInfo{symbolUBOCount + 5, gfx::AttributeDataType::Float, idSymbolOpacityVertexAttribute}, + // Dynamic + AttributeInfo{3, gfx::AttributeDataType::Float3, symbolUBOCount + 1, idSymbolProjectedPosVertexAttribute}, + + // Opacity + AttributeInfo{4, gfx::AttributeDataType::Float, symbolUBOCount + 2, idSymbolFadeOpacityVertexAttribute}, + + // Data driven + AttributeInfo{5, gfx::AttributeDataType::Float, symbolUBOCount + 3, idSymbolOpacityVertexAttribute}, }; const std::array SymbolIconShaderSource::textures = { TextureInfo{0, idSymbolImageTexture}, @@ -30,19 +33,22 @@ const std::array SymbolIconShaderSource::textures = { using SymbolSDFShaderSource = ShaderSource; const std::array SymbolSDFShaderSource::attributes = { - // always attributes - AttributeInfo{symbolUBOCount + 0, gfx::AttributeDataType::Short4, idSymbolPosOffsetVertexAttribute}, - AttributeInfo{symbolUBOCount + 1, gfx::AttributeDataType::UShort4, idSymbolDataVertexAttribute}, - AttributeInfo{symbolUBOCount + 2, gfx::AttributeDataType::Short4, idSymbolPixelOffsetVertexAttribute}, - AttributeInfo{symbolUBOCount + 3, gfx::AttributeDataType::Float3, idSymbolProjectedPosVertexAttribute}, - AttributeInfo{symbolUBOCount + 4, gfx::AttributeDataType::Float, idSymbolFadeOpacityVertexAttribute}, + AttributeInfo{0, gfx::AttributeDataType::Short4, symbolUBOCount + 0, idSymbolPosOffsetVertexAttribute}, + AttributeInfo{1, gfx::AttributeDataType::UShort4, symbolUBOCount + 0, idSymbolDataVertexAttribute}, + AttributeInfo{2, gfx::AttributeDataType::Short4, symbolUBOCount + 0, idSymbolPixelOffsetVertexAttribute}, - // sometimes uniforms - AttributeInfo{symbolUBOCount + 5, gfx::AttributeDataType::Float4, idSymbolColorVertexAttribute}, - AttributeInfo{symbolUBOCount + 6, gfx::AttributeDataType::Float4, idSymbolHaloColorVertexAttribute}, - AttributeInfo{symbolUBOCount + 7, gfx::AttributeDataType::Float, idSymbolOpacityVertexAttribute}, - AttributeInfo{symbolUBOCount + 8, gfx::AttributeDataType::Float, idSymbolHaloWidthVertexAttribute}, - AttributeInfo{symbolUBOCount + 9, gfx::AttributeDataType::Float, idSymbolHaloBlurVertexAttribute}, + // Dynamic + AttributeInfo{3, gfx::AttributeDataType::Float3, symbolUBOCount + 1, idSymbolProjectedPosVertexAttribute}, + + // Opacity + AttributeInfo{4, gfx::AttributeDataType::Float, symbolUBOCount + 2, idSymbolFadeOpacityVertexAttribute}, + + // Data driven + AttributeInfo{5, gfx::AttributeDataType::Float4, symbolUBOCount + 3, idSymbolColorVertexAttribute}, + AttributeInfo{6, gfx::AttributeDataType::Float4, symbolUBOCount + 3, idSymbolHaloColorVertexAttribute}, + AttributeInfo{7, gfx::AttributeDataType::Float, symbolUBOCount + 3, idSymbolOpacityVertexAttribute}, + AttributeInfo{8, gfx::AttributeDataType::Float, symbolUBOCount + 3, idSymbolHaloWidthVertexAttribute}, + AttributeInfo{9, gfx::AttributeDataType::Float, symbolUBOCount + 3, idSymbolHaloBlurVertexAttribute}, }; const std::array SymbolSDFShaderSource::textures = { TextureInfo{0, idSymbolImageTexture}, @@ -54,18 +60,21 @@ const std::array SymbolSDFShaderSource::textures = { using SymbolTextAndIconShaderSource = ShaderSource; const std::array SymbolTextAndIconShaderSource::attributes = { - // always attributes - AttributeInfo{symbolUBOCount + 0, gfx::AttributeDataType::Short4, idSymbolPosOffsetVertexAttribute}, - AttributeInfo{symbolUBOCount + 1, gfx::AttributeDataType::UShort4, idSymbolDataVertexAttribute}, - AttributeInfo{symbolUBOCount + 2, gfx::AttributeDataType::Float3, idSymbolProjectedPosVertexAttribute}, - AttributeInfo{symbolUBOCount + 3, gfx::AttributeDataType::Float, idSymbolFadeOpacityVertexAttribute}, + AttributeInfo{0, gfx::AttributeDataType::Short4, symbolUBOCount + 0, idSymbolPosOffsetVertexAttribute}, + AttributeInfo{1, gfx::AttributeDataType::UShort4, symbolUBOCount + 0, idSymbolDataVertexAttribute}, - // sometimes uniforms - AttributeInfo{symbolUBOCount + 4, gfx::AttributeDataType::Float4, idSymbolColorVertexAttribute}, - AttributeInfo{symbolUBOCount + 5, gfx::AttributeDataType::Float4, idSymbolHaloColorVertexAttribute}, - AttributeInfo{symbolUBOCount + 6, gfx::AttributeDataType::Float, idSymbolOpacityVertexAttribute}, - AttributeInfo{symbolUBOCount + 7, gfx::AttributeDataType::Float, idSymbolHaloWidthVertexAttribute}, - AttributeInfo{symbolUBOCount + 8, gfx::AttributeDataType::Float, idSymbolHaloBlurVertexAttribute}, + // Dynamic + AttributeInfo{2, gfx::AttributeDataType::Float3, symbolUBOCount + 1, idSymbolProjectedPosVertexAttribute}, + + // Opacity + AttributeInfo{3, gfx::AttributeDataType::Float, symbolUBOCount + 2, idSymbolFadeOpacityVertexAttribute}, + + // Data driven + AttributeInfo{4, gfx::AttributeDataType::Float4, symbolUBOCount + 3, idSymbolColorVertexAttribute}, + AttributeInfo{5, gfx::AttributeDataType::Float4, symbolUBOCount + 3, idSymbolHaloColorVertexAttribute}, + AttributeInfo{6, gfx::AttributeDataType::Float, symbolUBOCount + 3, idSymbolOpacityVertexAttribute}, + AttributeInfo{7, gfx::AttributeDataType::Float, symbolUBOCount + 3, idSymbolHaloWidthVertexAttribute}, + AttributeInfo{8, gfx::AttributeDataType::Float, symbolUBOCount + 3, idSymbolHaloBlurVertexAttribute}, }; const std::array SymbolTextAndIconShaderSource::textures = { TextureInfo{0, idSymbolImageTexture}, diff --git a/src/mbgl/shaders/mtl/widevector.cpp b/src/mbgl/shaders/mtl/widevector.cpp index fec44118d..c86153593 100644 --- a/src/mbgl/shaders/mtl/widevector.cpp +++ b/src/mbgl/shaders/mtl/widevector.cpp @@ -7,15 +7,15 @@ namespace shaders { using WideVectorShaderSource = ShaderSource; const std::array WideVectorShaderSource::attributes = { - AttributeInfo{wideVectorUBOCount + 0, gfx::AttributeDataType::Float3, idWideVectorScreenPos}, - AttributeInfo{wideVectorUBOCount + 1, gfx::AttributeDataType::Float4, idWideVectorColor}, - AttributeInfo{wideVectorUBOCount + 2, gfx::AttributeDataType::Int, idWideVectorIndex}, + AttributeInfo{0, gfx::AttributeDataType::Float3, wideVectorUBOCount + 0, idWideVectorScreenPos}, + AttributeInfo{1, gfx::AttributeDataType::Float4, wideVectorUBOCount + 0, idWideVectorColor}, + AttributeInfo{2, gfx::AttributeDataType::Int, wideVectorUBOCount + 0, idWideVectorIndex}, }; const std::array WideVectorShaderSource::instanceAttributes = { - 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}, + AttributeInfo{3, gfx::AttributeDataType::Float3, wideVectorUBOCount + 1, idWideVectorInstanceCenter}, + AttributeInfo{4, gfx::AttributeDataType::Float4, wideVectorUBOCount + 1, idWideVectorInstanceColor}, + AttributeInfo{5, gfx::AttributeDataType::Int, wideVectorUBOCount + 1, idWideVectorInstancePrevious}, + AttributeInfo{6, gfx::AttributeDataType::Int, wideVectorUBOCount + 1, idWideVectorInstanceNext}, }; const std::array WideVectorShaderSource::textures = {}; diff --git a/src/mbgl/vulkan/upload_pass.cpp b/src/mbgl/vulkan/upload_pass.cpp index 448737301..b91194b2d 100644 --- a/src/mbgl/vulkan/upload_pass.cpp +++ b/src/mbgl/vulkan/upload_pass.cpp @@ -122,6 +122,7 @@ gfx::AttributeBindingArray UploadPass::buildAttributeBindings( /*.vertexStride = */ static_cast(VertexAttribute::getStrideOf(defaultAttr.getDataType())), /*.vertexBufferResource = */ nullptr, /*.vertexOffset = */ 0, + /*.bufferIndex = */ 0, }; return; } @@ -136,6 +137,7 @@ gfx::AttributeBindingArray UploadPass::buildAttributeBindings( /*.vertexStride = */ effectiveAttr.getSharedStride(), /*.vertexBufferResource = */ buffer.get(), /*.vertexOffset = */ effectiveAttr.getSharedVertexOffset(), + /*.bufferIndex = */ 0, }; return; } @@ -150,6 +152,7 @@ gfx::AttributeBindingArray UploadPass::buildAttributeBindings( /*.vertexStride = */ static_cast(effectiveAttr.getStride()), /*.vertexBufferResource = */ buffer.get(), /*.vertexOffset = */ 0, + /*.bufferIndex = */ 0, }; return; } diff --git a/src/mbgl/webgpu/context.cpp b/src/mbgl/webgpu/context.cpp index 4ef4ce9a4..545789497 100644 --- a/src/mbgl/webgpu/context.cpp +++ b/src/mbgl/webgpu/context.cpp @@ -460,7 +460,8 @@ gfx::AttributeBindingArray Context::getOrCreateVertexBindings(gfx::Context&, result[index] = {/*.attribute = */ {attr.getDataType(), /*offset=*/0}, /*.vertexStride = */ static_cast(attr.getStride()), /*.vertexBufferResource = */ bufferResource.get(), - /*.vertexOffset = */ 0}; + /*.vertexOffset = */ 0, + /*.bufferIndex = */ 0}; } } }); diff --git a/src/mbgl/webgpu/upload_pass.cpp b/src/mbgl/webgpu/upload_pass.cpp index e611bcbb2..5e2bc54f1 100644 --- a/src/mbgl/webgpu/upload_pass.cpp +++ b/src/mbgl/webgpu/upload_pass.cpp @@ -187,6 +187,7 @@ gfx::AttributeBindingArray UploadPass::buildAttributeBindings( /*.vertexStride = */ static_cast(stride), /*.vertexBufferResource = */ dummyBuffer.get(), /*.vertexOffset = */ 0, + /*.bufferIndex = */ 0, }; // Store the buffer so it doesn't get destroyed @@ -205,6 +206,7 @@ gfx::AttributeBindingArray UploadPass::buildAttributeBindings( /*.vertexStride = */ effectiveAttr.getSharedStride(), /*.vertexBufferResource = */ buffer_.get(), /*.vertexOffset = */ effectiveAttr.getSharedVertexOffset(), + /*.bufferIndex = */ 0, }; return; } @@ -219,6 +221,7 @@ gfx::AttributeBindingArray UploadPass::buildAttributeBindings( /*.vertexStride = */ static_cast(effectiveAttr.getStride()), /*.vertexBufferResource = */ buffer_.get(), /*.vertexOffset = */ 0, + /*.bufferIndex = */ 0, }; return; }