From 61a6b66435f54316a66dcd07c5a4959c803db9c1 Mon Sep 17 00:00:00 2001 From: Alex Cristici Date: Wed, 31 Jan 2024 22:02:05 +0200 Subject: [PATCH] UBO by index instead of map (#1980) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- CMakeLists.txt | 4 + bazel/core.bzl | 3 + include/mbgl/gfx/uniform_block.hpp | 51 ++--- include/mbgl/gfx/uniform_buffer.hpp | 37 ++-- include/mbgl/shaders/background_layer_ubo.hpp | 6 + include/mbgl/shaders/circle_layer_ubo.hpp | 8 + include/mbgl/shaders/collision_layer_ubo.hpp | 5 + include/mbgl/shaders/debug_layer_ubo.hpp | 5 + .../mbgl/shaders/fill_extrusion_layer_ubo.hpp | 48 +++-- include/mbgl/shaders/fill_layer_ubo.hpp | 30 +++ include/mbgl/shaders/gl/shader_group_gl.hpp | 10 +- include/mbgl/shaders/gl/shader_info.hpp | 147 +++++++++++++++ include/mbgl/shaders/gl/shader_program_gl.hpp | 4 +- include/mbgl/shaders/heatmap_layer_ubo.hpp | 7 + .../shaders/heatmap_texture_layer_ubo.hpp | 5 + include/mbgl/shaders/hillshade_layer_ubo.hpp | 6 + .../shaders/hillshade_prepare_layer_ubo.hpp | 5 + include/mbgl/shaders/line_layer_ubo.hpp | 158 ++++++++++------ include/mbgl/shaders/mtl/shader_program.hpp | 5 +- include/mbgl/shaders/mtl/symbol_icon.hpp | 14 +- include/mbgl/shaders/raster_layer_ubo.hpp | 5 + include/mbgl/shaders/symbol_layer_ubo.hpp | 9 + include/mbgl/shaders/ubo_max_count.hpp | 44 +++++ src/mbgl/gfx/uniform_block.cpp | 26 ++- src/mbgl/gfx/uniform_buffer.cpp | 45 ++--- src/mbgl/gl/drawable_gl.cpp | 25 ++- src/mbgl/mtl/drawable.cpp | 19 +- .../layers/background_layer_tweaker.cpp | 9 +- .../renderer/layers/circle_layer_tweaker.cpp | 10 +- .../layers/collision_layer_tweaker.cpp | 16 +- .../layers/collision_layer_tweaker.hpp | 5 - .../layers/fill_extrusion_layer_tweaker.cpp | 11 +- .../layers/fill_extrusion_layer_tweaker.hpp | 3 - .../renderer/layers/fill_layer_tweaker.cpp | 121 ++++++------ .../renderer/layers/fill_layer_tweaker.hpp | 4 - .../renderer/layers/heatmap_layer_tweaker.cpp | 7 +- .../layers/heatmap_texture_layer_tweaker.cpp | 4 +- .../layers/hillshade_layer_tweaker.cpp | 7 +- .../hillshade_prepare_layer_tweaker.cpp | 4 +- .../renderer/layers/line_layer_tweaker.cpp | 39 ++-- .../renderer/layers/raster_layer_tweaker.cpp | 4 +- .../renderer/layers/render_circle_layer.cpp | 5 +- .../layers/render_fill_extrusion_layer.cpp | 10 +- .../renderer/layers/render_fill_layer.cpp | 56 +++--- .../renderer/layers/render_heatmap_layer.cpp | 6 +- .../renderer/layers/render_line_layer.cpp | 71 ++++--- .../renderer/layers/render_symbol_layer.cpp | 12 +- .../renderer/layers/symbol_layer_tweaker.cpp | 14 +- .../renderer/layers/symbol_layer_tweaker.hpp | 6 - .../renderer/sources/render_tile_source.cpp | 18 +- src/mbgl/shaders/gl/shader_info.cpp | 178 ++++++++++++++++++ src/mbgl/shaders/gl/shader_program_gl.cpp | 30 +-- src/mbgl/shaders/mtl/background.cpp | 4 +- src/mbgl/shaders/mtl/background_pattern.cpp | 4 +- src/mbgl/shaders/mtl/circle.cpp | 8 +- src/mbgl/shaders/mtl/clipping_mask.cpp | 2 +- src/mbgl/shaders/mtl/collision_box.cpp | 2 +- src/mbgl/shaders/mtl/collision_circle.cpp | 2 +- src/mbgl/shaders/mtl/debug.cpp | 2 +- src/mbgl/shaders/mtl/fill.cpp | 28 +-- src/mbgl/shaders/mtl/fill_extrusion.cpp | 6 +- .../shaders/mtl/fill_extrusion_pattern.cpp | 8 +- src/mbgl/shaders/mtl/heatmap.cpp | 6 +- src/mbgl/shaders/mtl/heatmap_texture.cpp | 2 +- src/mbgl/shaders/mtl/hillshade.cpp | 4 +- src/mbgl/shaders/mtl/hillshade_prepare.cpp | 2 +- src/mbgl/shaders/mtl/line.cpp | 30 +-- src/mbgl/shaders/mtl/line_gradient.cpp | 8 +- src/mbgl/shaders/mtl/raster.cpp | 2 +- src/mbgl/shaders/mtl/shader_program.cpp | 11 +- src/mbgl/shaders/mtl/symbol_icon.cpp | 10 +- src/mbgl/shaders/mtl/symbol_sdf.cpp | 10 +- src/mbgl/shaders/mtl/symbol_text_and_icon.cpp | 10 +- .../style/layers/custom_drawable_layer.cpp | 24 +-- 74 files changed, 977 insertions(+), 589 deletions(-) create mode 100644 include/mbgl/shaders/gl/shader_info.hpp create mode 100644 include/mbgl/shaders/ubo_max_count.hpp create mode 100644 src/mbgl/shaders/gl/shader_info.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index b8df248e3..f99fb436d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -159,6 +159,7 @@ if(MLN_DRAWABLE_RENDERER) ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/shader_program_base.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/util/identity.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/util/suppress_copies.hpp + ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/gl/shader_info.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/gl/shader_program_gl.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/gl/buffer_allocator.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/gl/drawable_gl.hpp @@ -1139,6 +1140,8 @@ if(MLN_WITH_OPENGL) ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/layer_ubo.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/line_layer_ubo.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/raster_layer_ubo.hpp + ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/symbol_layer_ubo.hpp + ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/ubo_max_count.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/gl/shader_program_gl.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/gl/drawable_gl.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/gl/drawable_gl_builder.hpp @@ -1149,6 +1152,7 @@ if(MLN_WITH_OPENGL) ${PROJECT_SOURCE_DIR}/include/mbgl/gl/texture2d.hpp ) list(APPEND SRC_FILES + ${PROJECT_SOURCE_DIR}/src/mbgl/shaders/gl/shader_info.cpp ${PROJECT_SOURCE_DIR}/src/mbgl/shaders/gl/shader_program_gl.cpp ${PROJECT_SOURCE_DIR}/src/mbgl/gl/drawable_gl.cpp ${PROJECT_SOURCE_DIR}/src/mbgl/gl/drawable_gl_builder.cpp diff --git a/bazel/core.bzl b/bazel/core.bzl index 21341a2da..34e514003 100644 --- a/bazel/core.bzl +++ b/bazel/core.bzl @@ -990,6 +990,7 @@ MLN_DRAWABLES_HEADERS = [ "include/mbgl/shaders/raster_layer_ubo.hpp", "include/mbgl/shaders/shader_program_base.hpp", "include/mbgl/shaders/symbol_layer_ubo.hpp", + "include/mbgl/shaders/ubo_max_count.hpp", "include/mbgl/util/identity.hpp", "include/mbgl/util/suppress_copies.hpp", "include/mbgl/style/layers/custom_drawable_layer.hpp", @@ -1006,6 +1007,7 @@ MLN_DRAWABLES_GL_SOURCE = [ "src/mbgl/gl/uniform_block_gl.cpp", "src/mbgl/gl/uniform_buffer_gl.cpp", "src/mbgl/gl/vertex_attribute_gl.cpp", + "src/mbgl/shaders/gl/shader_info.cpp", "src/mbgl/shaders/gl/shader_program_gl.cpp", ] @@ -1018,6 +1020,7 @@ MLN_DRAWABLES_GL_HEADERS = [ "include/mbgl/gl/uniform_buffer_gl.hpp", "include/mbgl/gl/vertex_attribute_gl.hpp", "include/mbgl/gl/texture2d.hpp", + "include/mbgl/shaders/gl/shader_info.hpp", "include/mbgl/shaders/gl/shader_program_gl.hpp", "include/mbgl/shaders/gl/shader_group_gl.hpp", ] diff --git a/include/mbgl/gfx/uniform_block.hpp b/include/mbgl/gfx/uniform_block.hpp index e64a62133..d93d49acf 100644 --- a/include/mbgl/gfx/uniform_block.hpp +++ b/include/mbgl/gfx/uniform_block.hpp @@ -1,18 +1,14 @@ #pragma once -#include -#include - -#include -#include -#include -#include -#include +#include namespace mbgl { namespace gfx { class UniformBuffer; +class UniformBlock; + +using UniqueUniformBlock = std::unique_ptr; /// @brief This class represents an uniform block class UniformBlock { @@ -60,11 +56,9 @@ protected: std::size_t size; }; -/// Stores a collection of uniform blocks by name +/// Stores a collection of uniform blocks by id class UniformBlockArray { public: - using UniformBlockMap = mbgl::unordered_map>; - /// @brief Constructor UniformBlockArray() = default; @@ -77,22 +71,19 @@ public: /// @brief Destructor virtual ~UniformBlockArray() = default; - /// @brief Get map of elements. - const UniformBlockMap& getMap() const { return uniformBlockMap; } - - /// @brief Number of elements - std::size_t size() const { return uniformBlockMap.size(); } + /// @brief Number of maximum allocated elements + std::size_t allocatedSize() const { return uniformBlockVector.size(); } /// @brief Get an uniform block element. /// @return Pointer to the element on success, or null if the uniform block doesn't exists. - const std::unique_ptr& get(const StringIdentity id) const; + const std::unique_ptr& get(const size_t id) const; - /// @brief Add a new uniform block element. - /// @param name + /// @brief Set a new uniform block element. + /// @param id /// @param index /// @param size /// @return Pointer to the new element on success, or null if the uniform block already exists. - const std::unique_ptr& add(const StringIdentity id, int index, std::size_t size); + const std::unique_ptr& set(const size_t id, const size_t index, std::size_t size); /// @brief Move assignment operator UniformBlockArray& operator=(UniformBlockArray&&); @@ -101,31 +92,21 @@ public: UniformBlockArray& operator=(const UniformBlockArray&); /// Do something with each block - template + template void visit(Func f) { - std::for_each(uniformBlockMap.begin(), uniformBlockMap.end(), [&](const auto& kv) { - if (kv.second) { - f(kv.first, *kv.second); + std::for_each(uniformBlockVector.begin(), uniformBlockVector.end(), [&](const auto& block) { + if (block) { + f(*block); } }); } protected: - const std::unique_ptr& add(const StringIdentity id, std::unique_ptr&& uniformBlock) { - const auto result = uniformBlockMap.insert(std::make_pair(id, std::unique_ptr())); - if (result.second) { - result.first->second = std::move(uniformBlock); - return result.first->second; - } else { - return nullref; - } - } - virtual std::unique_ptr create(int index, std::size_t size) = 0; virtual std::unique_ptr copy(const UniformBlock& uniformBlock) = 0; protected: - UniformBlockMap uniformBlockMap; + std::array uniformBlockVector; static std::unique_ptr nullref; }; diff --git a/include/mbgl/gfx/uniform_buffer.hpp b/include/mbgl/gfx/uniform_buffer.hpp index 46aeddad8..8b21ee69e 100644 --- a/include/mbgl/gfx/uniform_buffer.hpp +++ b/include/mbgl/gfx/uniform_buffer.hpp @@ -1,12 +1,7 @@ #pragma once +#include #include -#include - -#include -#include -#include -#include namespace mbgl { namespace gfx { @@ -15,6 +10,7 @@ class Context; class UniformBuffer; class UniformBufferArray; +using UniformBufferPtr = std::shared_ptr; using UniqueUniformBuffer = std::unique_ptr; using UniqueUniformBufferArray = std::unique_ptr; @@ -46,37 +42,30 @@ protected: std::size_t size; }; -/// Stores a collection of uniform buffers by name +/// Stores a collection of uniform buffers by id class UniformBufferArray { public: - using UniformBufferMap = mbgl::unordered_map>; - UniformBufferArray() = default; UniformBufferArray(UniformBufferArray&&); // Would need to use the virtual assignment operator UniformBufferArray(const UniformBufferArray&) = delete; virtual ~UniformBufferArray() = default; - /// Number of elements - std::size_t size() const { return uniformBufferMap.size(); } + /// Number of maximum allocated elements + std::size_t allocatedSize() const { return uniformBufferVector.size(); } /// Get an uniform buffer element. /// Returns a pointer to the element on success, or null if the uniform buffer doesn't exists. - const std::shared_ptr& get(const StringIdentity id) const; + const std::shared_ptr& get(const size_t id) const; - /// Add a new uniform buffer element or replace the existing one. - const std::shared_ptr& addOrReplace(const StringIdentity id, - std::shared_ptr uniformBuffer); + /// Set a new uniform buffer element or replace the existing one. + const std::shared_ptr& set(const size_t id, std::shared_ptr uniformBuffer); /// Create and add a new buffer or update an existing one - void createOrUpdate(const StringIdentity id, - const std::vector& data, - gfx::Context&, - bool persistent = false); - void createOrUpdate( - const StringIdentity id, const void* data, std::size_t size, gfx::Context&, bool persistent = false); + void createOrUpdate(const size_t id, const std::vector& data, gfx::Context&, bool persistent = false); + void createOrUpdate(const size_t id, const void* data, std::size_t size, gfx::Context&, bool persistent = false); template - std::enable_if_t> createOrUpdate(const StringIdentity id, + std::enable_if_t> createOrUpdate(const size_t id, const T* data, gfx::Context& context, bool persistent = false) { @@ -87,12 +76,10 @@ public: UniformBufferArray& operator=(const UniformBufferArray&); protected: - const std::shared_ptr& add(const StringIdentity id, std::shared_ptr&&); - virtual std::unique_ptr copy(const UniformBuffer&) = 0; protected: - UniformBufferMap uniformBufferMap; + std::array uniformBufferVector; static std::shared_ptr nullref; }; diff --git a/include/mbgl/shaders/background_layer_ubo.hpp b/include/mbgl/shaders/background_layer_ubo.hpp index a7a5c6203..167d6eee4 100644 --- a/include/mbgl/shaders/background_layer_ubo.hpp +++ b/include/mbgl/shaders/background_layer_ubo.hpp @@ -40,5 +40,11 @@ struct alignas(16) BackgroundPatternLayerUBO { }; static_assert(sizeof(BackgroundPatternLayerUBO) == 96); +enum { + idBackgroundDrawableUBO, + idBackgroundLayerUBO, + backgroundUBOCount +}; + } // namespace shaders } // namespace mbgl diff --git a/include/mbgl/shaders/circle_layer_ubo.hpp b/include/mbgl/shaders/circle_layer_ubo.hpp index 9c347b807..7b52c4c5c 100644 --- a/include/mbgl/shaders/circle_layer_ubo.hpp +++ b/include/mbgl/shaders/circle_layer_ubo.hpp @@ -46,5 +46,13 @@ struct alignas(16) CircleInterpolateUBO { }; static_assert(sizeof(CircleInterpolateUBO) % 16 == 0); +enum { + idCircleDrawableUBO, + idCirclePaintParamsUBO, + idCircleEvaluatedPropsUBO, + idCircleInterpolateUBO, + circleUBOCount +}; + } // namespace shaders } // namespace mbgl diff --git a/include/mbgl/shaders/collision_layer_ubo.hpp b/include/mbgl/shaders/collision_layer_ubo.hpp index ac7d762d0..ea1c9d790 100644 --- a/include/mbgl/shaders/collision_layer_ubo.hpp +++ b/include/mbgl/shaders/collision_layer_ubo.hpp @@ -14,5 +14,10 @@ struct alignas(16) CollisionUBO { static_assert(sizeof(CollisionUBO) % 16 == 0); static_assert(sizeof(CollisionUBO) == 80); +enum { + idCollisionUBO, + collisionUBOCount +}; + } // namespace shaders } // namespace mbgl diff --git a/include/mbgl/shaders/debug_layer_ubo.hpp b/include/mbgl/shaders/debug_layer_ubo.hpp index d0f6adffa..11ef0edf9 100644 --- a/include/mbgl/shaders/debug_layer_ubo.hpp +++ b/include/mbgl/shaders/debug_layer_ubo.hpp @@ -13,5 +13,10 @@ struct alignas(16) DebugUBO { }; static_assert(sizeof(DebugUBO) % 16 == 0); +enum { + idDebugUBO, + debugUBOCount +}; + } // namespace shaders } // namespace mbgl diff --git a/include/mbgl/shaders/fill_extrusion_layer_ubo.hpp b/include/mbgl/shaders/fill_extrusion_layer_ubo.hpp index 7861a3bcc..10dcb6543 100644 --- a/include/mbgl/shaders/fill_extrusion_layer_ubo.hpp +++ b/include/mbgl/shaders/fill_extrusion_layer_ubo.hpp @@ -7,26 +7,6 @@ namespace mbgl { namespace shaders { -/// Evaluated properties that depend on the tile -struct alignas(16) FillExtrusionDrawableTilePropsUBO { - /* 0 */ std::array pattern_from; - /* 16 */ std::array pattern_to; - /* 32 */ -}; -static_assert(sizeof(FillExtrusionDrawableTilePropsUBO) == 2 * 16); - -/// Attribute interpolations -struct alignas(16) FillExtrusionInterpolateUBO { - /* 0 */ float base_t; - /* 4 */ float height_t; - /* 8 */ float color_t; - /* 12 */ float pattern_from_t; - /* 16 */ float pattern_to_t; - /* 20 */ float pad1, pad2, pad3; - /* 32 */ -}; -static_assert(sizeof(FillExtrusionInterpolateUBO) == 2 * 16); - struct alignas(16) FillExtrusionDrawableUBO { /* 0 */ std::array matrix; /* 64 */ std::array scale; @@ -56,5 +36,33 @@ struct alignas(16) FillExtrusionDrawablePropsUBO { }; static_assert(sizeof(FillExtrusionDrawablePropsUBO) == 5 * 16); +/// Evaluated properties that depend on the tile +struct alignas(16) FillExtrusionDrawableTilePropsUBO { + /* 0 */ std::array pattern_from; + /* 16 */ std::array pattern_to; + /* 32 */ +}; +static_assert(sizeof(FillExtrusionDrawableTilePropsUBO) == 2 * 16); + +/// Attribute interpolations +struct alignas(16) FillExtrusionInterpolateUBO { + /* 0 */ float base_t; + /* 4 */ float height_t; + /* 8 */ float color_t; + /* 12 */ float pattern_from_t; + /* 16 */ float pattern_to_t; + /* 20 */ float pad1, pad2, pad3; + /* 32 */ +}; +static_assert(sizeof(FillExtrusionInterpolateUBO) == 2 * 16); + +enum { + idFillExtrusionDrawableUBO, + idFillExtrusionDrawablePropsUBO, + idFillExtrusionDrawableTilePropsUBO, + idFillExtrusionInterpolateUBO, + fillExtrusionUBOCount +}; + } // namespace shaders } // namespace mbgl diff --git a/include/mbgl/shaders/fill_layer_ubo.hpp b/include/mbgl/shaders/fill_layer_ubo.hpp index 789d1fa68..1959a401b 100644 --- a/include/mbgl/shaders/fill_layer_ubo.hpp +++ b/include/mbgl/shaders/fill_layer_ubo.hpp @@ -27,6 +27,13 @@ struct alignas(16) FillInterpolateUBO { }; static_assert(sizeof(FillInterpolateUBO) % 16 == 0); +enum { + idFillDrawableUBO, + idFillEvaluatedPropsUBO, + idFillInterpolateUBO, + fillUBOCount +}; + // // Fill outline @@ -52,6 +59,13 @@ struct alignas(16) FillOutlineInterpolateUBO { }; static_assert(sizeof(FillOutlineInterpolateUBO) == 1 * 16); +enum { + idFillOutlineDrawableUBO, + idFillOutlineEvaluatedPropsUBO, + idFillOutlineInterpolateUBO, + fillOutlineUBOCount +}; + // // Fill Pattern @@ -87,6 +101,14 @@ struct alignas(16) FillPatternInterpolateUBO { }; static_assert(sizeof(FillPatternInterpolateUBO) == 1 * 16); +enum { + idFillPatternDrawableUBO, + idFillPatternTilePropsUBO, + idFillPatternEvaluatedPropsUBO, + idFillPatternInterpolateUBO, + fillPatternUBOCount +}; + // // Fill pattern outline @@ -121,5 +143,13 @@ struct alignas(16) FillOutlinePatternInterpolateUBO { }; static_assert(sizeof(FillOutlinePatternInterpolateUBO) == 1 * 16); +enum { + idFillOutlinePatternDrawableUBO, + idFillOutlinePatternTilePropsUBO, + idFillOutlinePatternEvaluatedPropsUBO, + idFillOutlinePatternInterpolateUBO, + fillOutlinePatternUBOCount +}; + } // namespace shaders } // namespace mbgl diff --git a/include/mbgl/shaders/gl/shader_group_gl.hpp b/include/mbgl/shaders/gl/shader_group_gl.hpp index 8a517470d..1c64db0c3 100644 --- a/include/mbgl/shaders/gl/shader_group_gl.hpp +++ b/include/mbgl/shaders/gl/shader_group_gl.hpp @@ -53,8 +53,14 @@ public: } auto& glContext = static_cast(context); - shader = ShaderProgramGL::create( - glContext, programParameters, shaderName, firstAttribName, vert, frag, additionalDefines); + shader = ShaderProgramGL::create(glContext, + programParameters, + shaderName, + firstAttribName, + shaders::ShaderInfo::uniformBlocks, + vert, + frag, + additionalDefines); if (!shader || !registerShader(shader, shaderName)) { throw std::runtime_error("Failed to register " + shaderName + " with shader group!"); } diff --git a/include/mbgl/shaders/gl/shader_info.hpp b/include/mbgl/shaders/gl/shader_info.hpp new file mode 100644 index 000000000..980e4faa1 --- /dev/null +++ b/include/mbgl/shaders/gl/shader_info.hpp @@ -0,0 +1,147 @@ +#pragma once + +#include + +#include +#include + +namespace mbgl { +namespace shaders { + +struct UniformBlockInfo { + UniformBlockInfo(std::string_view name, std::size_t id); + std::string_view name; + std::size_t id; + std::size_t binding; +}; + +template +struct ShaderInfo; + +template <> +struct ShaderInfo { + static const std::vector uniformBlocks; +}; + +template <> +struct ShaderInfo { + static const std::vector uniformBlocks; +}; + +template <> +struct ShaderInfo { + static const std::vector uniformBlocks; +}; + +template <> +struct ShaderInfo { + static const std::vector uniformBlocks; +}; + +template <> +struct ShaderInfo { + static const std::vector uniformBlocks; +}; + +template <> +struct ShaderInfo { + static const std::vector uniformBlocks; +}; + +template <> +struct ShaderInfo { + static const std::vector uniformBlocks; +}; + +template <> +struct ShaderInfo { + static const std::vector uniformBlocks; +}; + +template <> +struct ShaderInfo { + static const std::vector uniformBlocks; +}; + +template <> +struct ShaderInfo { + static const std::vector uniformBlocks; +}; + +template <> +struct ShaderInfo { + static const std::vector uniformBlocks; +}; + +template <> +struct ShaderInfo { + static const std::vector uniformBlocks; +}; + +template <> +struct ShaderInfo { + static const std::vector uniformBlocks; +}; + +template <> +struct ShaderInfo { + static const std::vector uniformBlocks; +}; + +template <> +struct ShaderInfo { + static const std::vector uniformBlocks; +}; + +template <> +struct ShaderInfo { + static const std::vector uniformBlocks; +}; + +template <> +struct ShaderInfo { + static const std::vector uniformBlocks; +}; + +template <> +struct ShaderInfo { + static const std::vector uniformBlocks; +}; + +template <> +struct ShaderInfo { + static const std::vector uniformBlocks; +}; + +template <> +struct ShaderInfo { + static const std::vector uniformBlocks; +}; + +template <> +struct ShaderInfo { + static const std::vector uniformBlocks; +}; + +template <> +struct ShaderInfo { + static const std::vector uniformBlocks; +}; + +template <> +struct ShaderInfo { + static const std::vector uniformBlocks; +}; + +template <> +struct ShaderInfo { + static const std::vector uniformBlocks; +}; + +template <> +struct ShaderInfo { + static const std::vector uniformBlocks; +}; + +} // namespace shaders +} // namespace mbgl diff --git a/include/mbgl/shaders/gl/shader_program_gl.hpp b/include/mbgl/shaders/gl/shader_program_gl.hpp index 9b6dc6bd6..4836a730e 100644 --- a/include/mbgl/shaders/gl/shader_program_gl.hpp +++ b/include/mbgl/shaders/gl/shader_program_gl.hpp @@ -3,8 +3,9 @@ #include #include #include +#include #include -#include +#include #include @@ -33,6 +34,7 @@ public: const ProgramParameters& programParameters, const std::string& name, const std::string_view firstAttribName, + const std::vector& uniformBlocksInfo, const std::string& vertexSource, const std::string& fragmentSource, const std::string& additionalDefines = "") noexcept(false); diff --git a/include/mbgl/shaders/heatmap_layer_ubo.hpp b/include/mbgl/shaders/heatmap_layer_ubo.hpp index 68ac43ea8..5b6bce58d 100644 --- a/include/mbgl/shaders/heatmap_layer_ubo.hpp +++ b/include/mbgl/shaders/heatmap_layer_ubo.hpp @@ -27,5 +27,12 @@ struct alignas(16) HeatmapInterpolateUBO { }; static_assert(sizeof(HeatmapInterpolateUBO) % 16 == 0); +enum { + idHeatmapDrawableUBO, + idHeatmapEvaluatedPropsUBO, + idHeatmapInterpolateUBO, + heatmapUBOCount +}; + } // namespace shaders } // namespace mbgl diff --git a/include/mbgl/shaders/heatmap_texture_layer_ubo.hpp b/include/mbgl/shaders/heatmap_texture_layer_ubo.hpp index 73d4f89bc..f11a550da 100644 --- a/include/mbgl/shaders/heatmap_texture_layer_ubo.hpp +++ b/include/mbgl/shaders/heatmap_texture_layer_ubo.hpp @@ -13,5 +13,10 @@ struct alignas(16) HeatmapTextureDrawableUBO { }; static_assert(sizeof(HeatmapTextureDrawableUBO) % 16 == 0); +enum { + idHeatmapTextureDrawableUBO, + heatmapTextureUBOCount +}; + } // namespace shaders } // namespace mbgl diff --git a/include/mbgl/shaders/hillshade_layer_ubo.hpp b/include/mbgl/shaders/hillshade_layer_ubo.hpp index 77fd1a993..89d3f118c 100644 --- a/include/mbgl/shaders/hillshade_layer_ubo.hpp +++ b/include/mbgl/shaders/hillshade_layer_ubo.hpp @@ -19,5 +19,11 @@ struct alignas(16) HillshadeEvaluatedPropsUBO { }; static_assert(sizeof(HillshadeEvaluatedPropsUBO) % 16 == 0); +enum { + idHillshadeDrawableUBO, + idHillshadeEvaluatedPropsUBO, + hillshadeUBOCount +}; + } // namespace shaders } // namespace mbgl diff --git a/include/mbgl/shaders/hillshade_prepare_layer_ubo.hpp b/include/mbgl/shaders/hillshade_prepare_layer_ubo.hpp index 57ac65f3e..7daa8338f 100644 --- a/include/mbgl/shaders/hillshade_prepare_layer_ubo.hpp +++ b/include/mbgl/shaders/hillshade_prepare_layer_ubo.hpp @@ -14,5 +14,10 @@ struct alignas(16) HillshadePrepareDrawableUBO { }; static_assert(sizeof(HillshadePrepareDrawableUBO) % 16 == 0); +enum { + idHillshadePrepareDrawableUBO, + hillshadePrepareUBOCount +}; + } // namespace shaders } // namespace mbgl diff --git a/include/mbgl/shaders/line_layer_ubo.hpp b/include/mbgl/shaders/line_layer_ubo.hpp index 0b20b6d6e..152daa5a5 100644 --- a/include/mbgl/shaders/line_layer_ubo.hpp +++ b/include/mbgl/shaders/line_layer_ubo.hpp @@ -5,6 +5,9 @@ namespace mbgl { namespace shaders { +// +// Line + struct alignas(16) LineDynamicUBO { /* 0 */ std::array units_to_pixels; /* 8 */ float pad1, pad2; @@ -19,8 +22,6 @@ struct alignas(16) LineUBO { }; static_assert(sizeof(LineUBO) % 16 == 0); -using LineGradientUBO = LineUBO; - struct alignas(16) LinePropertiesUBO { Color color; float blur; @@ -32,6 +33,30 @@ struct alignas(16) LinePropertiesUBO { }; static_assert(sizeof(LinePropertiesUBO) % 16 == 0); +struct alignas(16) LineInterpolationUBO { + float color_t; + float blur_t; + float opacity_t; + float gapwidth_t; + float offset_t; + float width_t; + float pad1, pad2; +}; +static_assert(sizeof(LineInterpolationUBO) % 16 == 0); + +enum { + idLineDynamicUBO, + idLineUBO, + idLinePropertiesUBO, + idLineInterpolationUBO, + lineUBOCount +}; + +// +// Line gradient + +using LineGradientUBO = LineUBO; + struct alignas(16) LineGradientPropertiesUBO { float blur; float opacity; @@ -42,6 +67,27 @@ struct alignas(16) LineGradientPropertiesUBO { }; static_assert(sizeof(LineGradientPropertiesUBO) % 16 == 0); +struct alignas(16) LineGradientInterpolationUBO { + float blur_t; + float opacity_t; + float gapwidth_t; + float offset_t; + float width_t; + float pad1, pad2, pad3; +}; +static_assert(sizeof(LineGradientInterpolationUBO) % 16 == 0); + +enum { + idLineGradientDynamicUBO, + idLineGradientUBO, + idLineGradientPropertiesUBO, + idLineGradientInterpolationUBO, + lineGradientUBOCount +}; + +// +// Line pattern + struct alignas(16) LinePatternUBO { std::array matrix; std::array scale; @@ -61,6 +107,36 @@ struct alignas(16) LinePatternPropertiesUBO { }; static_assert(sizeof(LinePatternPropertiesUBO) % 16 == 0); +struct alignas(16) LinePatternInterpolationUBO { + float blur_t; + float opacity_t; + float offset_t; + float gapwidth_t; + float width_t; + float pattern_from_t; + float pattern_to_t; + float pad1; +}; +static_assert(sizeof(LinePatternInterpolationUBO) % 16 == 0); + +struct alignas(16) LinePatternTilePropertiesUBO { + std::array pattern_from; + std::array pattern_to; +}; +static_assert(sizeof(LinePatternTilePropertiesUBO) % 16 == 0); + +enum { + idLinePatternDynamicUBO, + idLinePatternUBO, + idLinePatternPropertiesUBO, + idLinePatternInterpolationUBO, + idLinePatternTilePropertiesUBO, + linePatternUBOCount +}; + +// +// Line SDF + struct alignas(16) LineSDFUBO { std::array matrix; std::array patternscale_a; @@ -86,6 +162,29 @@ struct alignas(16) LineSDFPropertiesUBO { }; static_assert(sizeof(LineSDFPropertiesUBO) % 16 == 0); +struct alignas(16) LineSDFInterpolationUBO { + float color_t; + float blur_t; + float opacity_t; + float gapwidth_t; + float offset_t; + float width_t; + float floorwidth_t; + float pad1; +}; +static_assert(sizeof(LineSDFInterpolationUBO) % 16 == 0); + +enum { + idLineSDFDynamicUBO, + idLineSDFUBO, + idLineSDFPropertiesUBO, + idLineSDFInterpolationUBO, + lineSDFUBOCount +}; + +// +// Line basic + struct alignas(16) LineBasicUBO { std::array matrix; std::array units_to_pixels; @@ -102,58 +201,11 @@ struct alignas(16) LineBasicPropertiesUBO { }; static_assert(sizeof(LineBasicPropertiesUBO) % 16 == 0); -/// Property interpolation UBOs -struct alignas(16) LineInterpolationUBO { - float color_t; - float blur_t; - float opacity_t; - float gapwidth_t; - float offset_t; - float width_t; - float pad1, pad2; +enum { + idLineBasicUBO, + idLineBasicPropertiesUBO, + lineBasicUBOCount }; -static_assert(sizeof(LineInterpolationUBO) % 16 == 0); - -struct alignas(16) LineGradientInterpolationUBO { - float blur_t; - float opacity_t; - float gapwidth_t; - float offset_t; - float width_t; - float pad1, pad2, pad3; -}; -static_assert(sizeof(LineGradientInterpolationUBO) % 16 == 0); - -struct alignas(16) LinePatternInterpolationUBO { - float blur_t; - float opacity_t; - float offset_t; - float gapwidth_t; - float width_t; - float pattern_from_t; - float pattern_to_t; - float pad1; -}; -static_assert(sizeof(LinePatternInterpolationUBO) % 16 == 0); - -struct alignas(16) LineSDFInterpolationUBO { - float color_t; - float blur_t; - float opacity_t; - float gapwidth_t; - float offset_t; - float width_t; - float floorwidth_t; - float pad1; -}; -static_assert(sizeof(LineSDFInterpolationUBO) % 16 == 0); - -/// Evaluated properties that depend on the tile -struct alignas(16) LinePatternTilePropertiesUBO { - std::array pattern_from; - std::array pattern_to; -}; -static_assert(sizeof(LinePatternTilePropertiesUBO) % 16 == 0); } // namespace shaders } // namespace mbgl diff --git a/include/mbgl/shaders/mtl/shader_program.hpp b/include/mbgl/shaders/mtl/shader_program.hpp index 7a63be323..bea1380c9 100644 --- a/include/mbgl/shaders/mtl/shader_program.hpp +++ b/include/mbgl/shaders/mtl/shader_program.hpp @@ -21,13 +21,12 @@ struct AttributeInfo { StringIdentity nameID; }; struct UniformBlockInfo { - UniformBlockInfo(std::size_t index, bool vertex, bool fragment, std::size_t size, std::string_view name); + UniformBlockInfo(std::size_t index, bool vertex, bool fragment, std::size_t size, std::size_t id); std::size_t index; bool vertex; bool fragment; std::size_t size; - std::string_view name; - StringIdentity nameID; + std::size_t id; }; struct TextureInfo { TextureInfo(std::size_t index, std::string_view name); diff --git a/include/mbgl/shaders/mtl/symbol_icon.hpp b/include/mbgl/shaders/mtl/symbol_icon.hpp index 896cc55b5..9c658ae12 100644 --- a/include/mbgl/shaders/mtl/symbol_icon.hpp +++ b/include/mbgl/shaders/mtl/symbol_icon.hpp @@ -45,11 +45,11 @@ struct FragmentStage { }; FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], - device const SymbolDrawableUBO& drawable [[buffer(8)]], - device const SymbolDynamicUBO& dynamic [[buffer(9)]], - device const SymbolDrawablePaintUBO& paint [[buffer(10)]], - device const SymbolDrawableTilePropsUBO& props [[buffer(11)]], - device const SymbolDrawableInterpolateUBO& interp [[buffer(12)]]) { + device const SymbolDrawableUBO& drawable [[buffer(6)]], + device const SymbolDynamicUBO& dynamic [[buffer(7)]], + device const SymbolDrawablePaintUBO& paint [[buffer(8)]], + device const SymbolDrawableTilePropsUBO& props [[buffer(9)]], + device const SymbolDrawableInterpolateUBO& interp [[buffer(10)]]) { const float2 a_pos = vertx.pos_offset.xy; const float2 a_offset = vertx.pos_offset.zw; @@ -122,8 +122,8 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], } half4 fragment fragmentMain(FragmentStage in [[stage_in]], - device const SymbolDrawableUBO& drawable [[buffer(8)]], - device const SymbolDrawablePaintUBO& paint [[buffer(10)]], + device const SymbolDrawableUBO& drawable [[buffer(6)]], + device const SymbolDrawablePaintUBO& paint [[buffer(8)]], texture2d image [[texture(0)]], sampler image_sampler [[sampler(0)]]) { #if defined(OVERDRAW_INSPECTOR) diff --git a/include/mbgl/shaders/raster_layer_ubo.hpp b/include/mbgl/shaders/raster_layer_ubo.hpp index f289db53d..4a8f20d26 100644 --- a/include/mbgl/shaders/raster_layer_ubo.hpp +++ b/include/mbgl/shaders/raster_layer_ubo.hpp @@ -22,5 +22,10 @@ struct alignas(16) RasterDrawableUBO { static_assert(sizeof(RasterDrawableUBO) == 128); static_assert(sizeof(RasterDrawableUBO) % 16 == 0); +enum { + idRasterDrawableUBO, + rasterUBOCount +}; + } // namespace shaders } // namespace mbgl diff --git a/include/mbgl/shaders/symbol_layer_ubo.hpp b/include/mbgl/shaders/symbol_layer_ubo.hpp index 7c93fb567..82376a5c6 100644 --- a/include/mbgl/shaders/symbol_layer_ubo.hpp +++ b/include/mbgl/shaders/symbol_layer_ubo.hpp @@ -69,5 +69,14 @@ struct alignas(16) SymbolDrawablePaintUBO { }; static_assert(sizeof(SymbolDrawablePaintUBO) == 3 * 16); +enum { + idSymbolDrawableUBO, + idSymbolDynamicUBO, + idSymbolDrawablePaintUBO, + idSymbolDrawableTilePropsUBO, + idSymbolDrawableInterpolateUBO, + symbolUBOCount +}; + } // namespace shaders } // namespace mbgl diff --git a/include/mbgl/shaders/ubo_max_count.hpp b/include/mbgl/shaders/ubo_max_count.hpp new file mode 100644 index 000000000..32f262097 --- /dev/null +++ b/include/mbgl/shaders/ubo_max_count.hpp @@ -0,0 +1,44 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +namespace mbgl { +namespace shaders { + +static constexpr auto maxUBOCountPerShader = std::max({static_cast(backgroundUBOCount), + static_cast(circleUBOCount), + static_cast(collisionUBOCount), + static_cast(debugUBOCount), + static_cast(fillUBOCount), + static_cast(fillOutlineUBOCount), + static_cast(fillPatternUBOCount), + static_cast(fillOutlinePatternUBOCount), + static_cast(fillExtrusionUBOCount), + static_cast(heatmapUBOCount), + static_cast(heatmapTextureUBOCount), + static_cast(hillshadeUBOCount), + static_cast(hillshadePrepareUBOCount), + static_cast(lineUBOCount), + static_cast(lineGradientUBOCount), + static_cast(linePatternUBOCount), + static_cast(lineSDFUBOCount), + static_cast(lineBasicUBOCount), + static_cast(rasterUBOCount), + static_cast(symbolUBOCount)}); + +} // namespace shaders +} // namespace mbgl diff --git a/src/mbgl/gfx/uniform_block.cpp b/src/mbgl/gfx/uniform_block.cpp index 5710c8e91..c80230711 100644 --- a/src/mbgl/gfx/uniform_block.cpp +++ b/src/mbgl/gfx/uniform_block.cpp @@ -6,34 +6,32 @@ namespace gfx { std::unique_ptr UniformBlockArray::nullref = nullptr; UniformBlockArray::UniformBlockArray(UniformBlockArray&& other) - : uniformBlockMap(std::move(other.uniformBlockMap)) {} + : uniformBlockVector(std::move(other.uniformBlockVector)) {} UniformBlockArray& UniformBlockArray::operator=(UniformBlockArray&& other) { - uniformBlockMap = std::move(other.uniformBlockMap); + uniformBlockVector = std::move(other.uniformBlockVector); return *this; } UniformBlockArray& UniformBlockArray::operator=(const UniformBlockArray& other) { - uniformBlockMap.clear(); - for (const auto& kv : other.uniformBlockMap) { - add(kv.first, copy(*kv.second)); + for (size_t id = 0; id < other.uniformBlockVector.size(); id++) { + uniformBlockVector[id] = copy(*other.uniformBlockVector[id]); } return *this; } -const std::unique_ptr& UniformBlockArray::get(const StringIdentity id) const { - const auto result = uniformBlockMap.find(id); - return (result != uniformBlockMap.end()) ? result->second : nullref; +const std::unique_ptr& UniformBlockArray::get(const size_t id) const { + const auto& result = (id < uniformBlockVector.size()) ? uniformBlockVector[id] : nullref; + return (result != nullptr) ? result : nullref; } -const std::unique_ptr& UniformBlockArray::add(const StringIdentity id, int index, std::size_t size) { - const auto result = uniformBlockMap.insert(std::make_pair(id, std::unique_ptr())); - if (result.second) { - result.first->second = create(index, size); - return result.first->second; - } else { +const std::unique_ptr& UniformBlockArray::set(const size_t id, const size_t index, std::size_t size) { + assert(id < uniformBlockVector.size()); + if (id >= uniformBlockVector.size()) { return nullref; } + uniformBlockVector[id] = create(static_cast(index), size); + return uniformBlockVector[id]; } } // namespace gfx diff --git a/src/mbgl/gfx/uniform_buffer.cpp b/src/mbgl/gfx/uniform_buffer.cpp index b38b70b87..8370eee4c 100644 --- a/src/mbgl/gfx/uniform_buffer.cpp +++ b/src/mbgl/gfx/uniform_buffer.cpp @@ -8,34 +8,36 @@ namespace gfx { std::shared_ptr UniformBufferArray::nullref = nullptr; UniformBufferArray::UniformBufferArray(UniformBufferArray&& other) - : uniformBufferMap(std::move(other.uniformBufferMap)) {} + : uniformBufferVector(std::move(other.uniformBufferVector)) {} UniformBufferArray& UniformBufferArray::operator=(UniformBufferArray&& other) { - uniformBufferMap = std::move(other.uniformBufferMap); + uniformBufferVector = std::move(other.uniformBufferVector); return *this; } UniformBufferArray& UniformBufferArray::operator=(const UniformBufferArray& other) { - uniformBufferMap.clear(); - for (const auto& kv : other.uniformBufferMap) { - add(kv.first, copy(*kv.second)); + for (size_t id = 0; id < other.uniformBufferVector.size(); id++) { + uniformBufferVector[id] = other.uniformBufferVector[id]; } return *this; } -const std::shared_ptr& UniformBufferArray::get(const StringIdentity id) const { - const auto result = uniformBufferMap.find(id); - return (result != uniformBufferMap.end()) ? result->second : nullref; +const std::shared_ptr& UniformBufferArray::get(const size_t id) const { + const auto& result = (id < uniformBufferVector.size()) ? uniformBufferVector[id] : nullref; + return (result != nullptr) ? result : nullref; } -const std::shared_ptr& UniformBufferArray::addOrReplace(const StringIdentity id, - std::shared_ptr uniformBuffer) { - const auto result = uniformBufferMap.insert(std::make_pair(id, std::shared_ptr())); - result.first->second = std::move(uniformBuffer); - return result.first->second; +const std::shared_ptr& UniformBufferArray::set(const size_t id, + std::shared_ptr uniformBuffer) { + assert(id < uniformBufferVector.size()); + if (id >= uniformBufferVector.size()) { + return nullref; + } + uniformBufferVector[id] = std::move(uniformBuffer); + return uniformBufferVector[id]; } -void UniformBufferArray::createOrUpdate(const StringIdentity id, +void UniformBufferArray::createOrUpdate(const size_t id, const std::vector& data, gfx::Context& context, bool persistent) { @@ -43,22 +45,11 @@ void UniformBufferArray::createOrUpdate(const StringIdentity id, } void UniformBufferArray::createOrUpdate( - const StringIdentity id, const void* data, const std::size_t size, gfx::Context& context, bool persistent) { + const size_t id, const void* data, const std::size_t size, gfx::Context& context, bool persistent) { if (auto& ubo = get(id); ubo && ubo->getSize() == size) { ubo->update(data, size); } else { - add(id, context.createUniformBuffer(data, size, persistent)); - } -} - -const std::shared_ptr& UniformBufferArray::add(const StringIdentity id, - std::shared_ptr&& uniformBuffer) { - const auto result = uniformBufferMap.insert(std::make_pair(id, std::shared_ptr())); - if (result.second) { - result.first->second = std::move(uniformBuffer); - return result.first->second; - } else { - return nullref; + uniformBufferVector[id] = context.createUniformBuffer(data, size, persistent); } } diff --git a/src/mbgl/gl/drawable_gl.cpp b/src/mbgl/gl/drawable_gl.cpp index f9b2728d3..4560f4665 100644 --- a/src/mbgl/gl/drawable_gl.cpp +++ b/src/mbgl/gl/drawable_gl.cpp @@ -104,29 +104,34 @@ void DrawableGL::setVertexAttrNameId(const StringIdentity id) { void DrawableGL::bindUniformBuffers() const { if (shader) { - const auto& shaderGL = static_cast(*shader); - for (const auto& element : shaderGL.getUniformBlocks().getMap()) { - const auto& uniformBuffer = getUniformBuffers().get(element.first); + const auto& uniformBlocks = shader->getUniformBlocks(); + for (size_t id = 0; id < uniformBlocks.allocatedSize(); id++) { + const auto& block = uniformBlocks.get(id); + if (!block) continue; + const auto& uniformBuffer = getUniformBuffers().get(id); + assert(uniformBuffer && "UBO missing, drawable skipped"); if (!uniformBuffer) { using namespace std::string_literals; const auto tileIDStr = getTileID() ? util::toString(*getTileID()) : ""; Log::Error(Event::General, - "bindUniformBuffers: UBO "s + std::string(stringIndexer().get(element.first)) + - " not found for " + util::toString(getID()) + " / " + getName() + " / " + tileIDStr + - ". skipping."); + "bindUniformBuffers: UBO "s + util::toString(block->getIndex()) + " not found for " + + util::toString(getID()) + " / " + getName() + " / " + tileIDStr + ". skipping."); assert(false); continue; } - element.second->bindBuffer(*uniformBuffer); + block->bindBuffer(*uniformBuffer); } } } void DrawableGL::unbindUniformBuffers() const { if (shader) { - const auto& shaderGL = static_cast(*shader); - for (const auto& element : shaderGL.getUniformBlocks().getMap()) { - element.second->unbindBuffer(); + const auto& uniformBlocks = shader->getUniformBlocks(); + for (size_t id = 0; id < uniformBlocks.allocatedSize(); id++) { + const auto& block = uniformBlocks.get(id); + if (block) { + block->unbindBuffer(); + } } } } diff --git a/src/mbgl/mtl/drawable.cpp b/src/mbgl/mtl/drawable.cpp index c8f948a4f..79a5caed8 100644 --- a/src/mbgl/mtl/drawable.cpp +++ b/src/mbgl/mtl/drawable.cpp @@ -361,21 +361,22 @@ void Drawable::bindAttributes(RenderPass& renderPass) const noexcept { void Drawable::bindUniformBuffers(RenderPass& renderPass) const noexcept { if (shader) { - const auto& shaderMTL = static_cast(*shader); - for (const auto& element : shaderMTL.getUniformBlocks().getMap()) { - const auto& uniformBuffer = getUniformBuffers().get(element.first); + const auto& uniformBlocks = shader->getUniformBlocks(); + for (size_t id = 0; id < uniformBlocks.allocatedSize(); id++) { + const auto& block = uniformBlocks.get(id); + if (!block) continue; + const auto& uniformBuffer = getUniformBuffers().get(id); assert(uniformBuffer && "UBO missing, drawable skipped"); if (uniformBuffer) { const auto& buffer = static_cast(*uniformBuffer.get()); const auto& resource = buffer.getBufferResource(); - const auto& block = static_cast(*element.second); - const auto index = block.getIndex(); + const auto& mtlBlock = static_cast(*block); - if (block.getBindVertex()) { - renderPass.bindVertex(resource, /*offset=*/0, index); + if (mtlBlock.getBindVertex()) { + renderPass.bindVertex(resource, /*offset=*/0, block->getIndex()); } - if (block.getBindFragment()) { - renderPass.bindFragment(resource, /*offset=*/0, index); + if (mtlBlock.getBindFragment()) { + renderPass.bindFragment(resource, /*offset=*/0, block->getIndex()); } } } diff --git a/src/mbgl/renderer/layers/background_layer_tweaker.cpp b/src/mbgl/renderer/layers/background_layer_tweaker.cpp index faffc5249..1fb49074f 100644 --- a/src/mbgl/renderer/layers/background_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/background_layer_tweaker.cpp @@ -19,8 +19,7 @@ using namespace shaders; #if !defined(NDEBUG) constexpr auto BackgroundPatternShaderName = "BackgroundPatternShader"; #endif -static const StringIdentity idBackgroundDrawableUBOName = stringIndexer().get("BackgroundDrawableUBO"); -static const StringIdentity idBackgroundLayerUBOName = stringIndexer().get("BackgroundLayerUBO"); + static const StringIdentity idTexUniformName = stringIndexer().get("u_image"); void BackgroundLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters& parameters) { @@ -73,7 +72,7 @@ void BackgroundLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintPara const BackgroundDrawableUBO drawableUBO = {/* .matrix = */ util::cast(matrix)}; auto& uniforms = drawable.mutableUniformBuffers(); - uniforms.createOrUpdate(idBackgroundDrawableUBOName, &drawableUBO, context); + uniforms.createOrUpdate(idBackgroundDrawableUBO, &drawableUBO, context); if (hasPattern) { if (!samplerLocation.has_value()) { @@ -115,7 +114,7 @@ void BackgroundLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintPara /* .opacity = */ evaluated.get(), /* .pad1 = */ 0, }; - uniforms.createOrUpdate(idBackgroundLayerUBOName, &layerUBO, context); + uniforms.createOrUpdate(idBackgroundLayerUBO, &layerUBO, context); } else { // UBOs can be shared if (!backgroundLayerBuffer) { @@ -126,7 +125,7 @@ void BackgroundLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintPara 0}; backgroundLayerBuffer = context.createUniformBuffer(&layerUBO, sizeof(layerUBO)); } - uniforms.addOrReplace(idBackgroundLayerUBOName, backgroundLayerBuffer); + uniforms.set(idBackgroundLayerUBO, backgroundLayerBuffer); } }); } diff --git a/src/mbgl/renderer/layers/circle_layer_tweaker.cpp b/src/mbgl/renderer/layers/circle_layer_tweaker.cpp index 91a1ef0e9..0af7eefd8 100644 --- a/src/mbgl/renderer/layers/circle_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/circle_layer_tweaker.cpp @@ -22,10 +22,6 @@ namespace mbgl { using namespace style; using namespace shaders; -static const StringIdentity idCircleDrawableUBOName = stringIndexer().get("CircleDrawableUBO"); -static const StringIdentity idCirclePaintParamsUBOName = stringIndexer().get("CirclePaintParamsUBO"); -static const StringIdentity idCircleEvaluatedPropsUBOName = stringIndexer().get("CircleEvaluatedPropsUBO"); - void CircleLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters& parameters) { auto& context = parameters.context; const auto& evaluated = static_cast(*evaluatedProperties).evaluated; @@ -76,8 +72,8 @@ void CircleLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParamete const UnwrappedTileID tileID = drawable.getTileID()->toUnwrapped(); auto& uniforms = drawable.mutableUniformBuffers(); - uniforms.addOrReplace(idCirclePaintParamsUBOName, paintParamsUniformBuffer); - uniforms.addOrReplace(idCircleEvaluatedPropsUBOName, evaluatedPropsUniformBuffer); + uniforms.set(idCirclePaintParamsUBO, paintParamsUniformBuffer); + uniforms.set(idCircleEvaluatedPropsUBO, evaluatedPropsUniformBuffer); const auto& translation = evaluated.get(); const auto anchor = evaluated.get(); @@ -95,7 +91,7 @@ void CircleLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParamete /* .extrude_scale = */ extrudeScale, /* .padding = */ 0}; - uniforms.createOrUpdate(idCircleDrawableUBOName, &drawableUBO, context); + uniforms.createOrUpdate(idCircleDrawableUBO, &drawableUBO, context); }); } diff --git a/src/mbgl/renderer/layers/collision_layer_tweaker.cpp b/src/mbgl/renderer/layers/collision_layer_tweaker.cpp index 5e5f97006..53aed5a54 100644 --- a/src/mbgl/renderer/layers/collision_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/collision_layer_tweaker.cpp @@ -21,9 +21,6 @@ namespace mbgl { using namespace style; using namespace shaders; -const StringIdentity CollisionLayerTweaker::idCollisionCircleUBOName = stringIndexer().get(CollisionCircleUBOName); -const StringIdentity CollisionLayerTweaker::idCollisionBoxUBOName = stringIndexer().get(CollisionBoxUBOName); - void CollisionLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters& parameters) { if (layerGroup.empty()) { return; @@ -65,19 +62,8 @@ void CollisionLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParam /*.camera_to_center_distance*/ parameters.state.getCameraToCenterDistance(), /*.overscale_factor*/ static_cast(drawable.getTileID()->overscaleFactor())}; - const auto shader = drawable.getShader(); - const auto& shaderUniforms = shader->getUniformBlocks(); auto& uniforms = drawable.mutableUniformBuffers(); - - if (shaderUniforms.get(idCollisionBoxUBOName)) { - // collision box - uniforms.createOrUpdate(idCollisionBoxUBOName, &drawableUBO, context); - } else if (shaderUniforms.get(idCollisionCircleUBOName)) { - // collision circle - uniforms.createOrUpdate(idCollisionCircleUBOName, &drawableUBO, context); - } else { - Log::Error(Event::General, "Collision shader uniform name unknown."); - } + uniforms.createOrUpdate(idCollisionUBO, &drawableUBO, context); }); } diff --git a/src/mbgl/renderer/layers/collision_layer_tweaker.hpp b/src/mbgl/renderer/layers/collision_layer_tweaker.hpp index 42c26c9c6..34ade8bf9 100644 --- a/src/mbgl/renderer/layers/collision_layer_tweaker.hpp +++ b/src/mbgl/renderer/layers/collision_layer_tweaker.hpp @@ -19,11 +19,6 @@ public: ~CollisionLayerTweaker() override = default; void execute(LayerGroupBase&, const PaintParameters&) override; - - static constexpr auto CollisionCircleUBOName = "CollisionCircleUBO"; - static const StringIdentity idCollisionCircleUBOName; - static constexpr auto CollisionBoxUBOName = "CollisionBoxUBO"; - static const StringIdentity idCollisionBoxUBOName; }; } // namespace mbgl diff --git a/src/mbgl/renderer/layers/fill_extrusion_layer_tweaker.cpp b/src/mbgl/renderer/layers/fill_extrusion_layer_tweaker.cpp index 4b1e97510..b65cb9072 100644 --- a/src/mbgl/renderer/layers/fill_extrusion_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/fill_extrusion_layer_tweaker.cpp @@ -27,17 +27,10 @@ using namespace shaders; using namespace style; namespace { -const StringIdentity idFillExtrusionDrawableUBOName = stringIndexer().get("FillExtrusionDrawableUBO"); -const StringIdentity idFillExtrusionDrawablePropsUBOName = stringIndexer().get("FillExtrusionDrawablePropsUBO"); const StringIdentity idTexImageName = stringIndexer().get("u_image"); } // namespace -const StringIdentity FillExtrusionLayerTweaker::idFillExtrusionTilePropsUBOName = stringIndexer().get( - "FillExtrusionDrawableTilePropsUBO"); -const StringIdentity FillExtrusionLayerTweaker::idFillExtrusionInterpolateUBOName = stringIndexer().get( - "FillExtrusionInterpolateUBO"); - void FillExtrusionLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters& parameters) { auto& context = parameters.context; const auto& props = static_cast(*evaluatedProperties); @@ -81,7 +74,7 @@ void FillExtrusionLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintP const UnwrappedTileID tileID = drawable.getTileID()->toUnwrapped(); auto& uniforms = drawable.mutableUniformBuffers(); - uniforms.addOrReplace(idFillExtrusionDrawablePropsUBOName, propsBuffer); + uniforms.set(idFillExtrusionDrawablePropsUBO, propsBuffer); const auto& translation = evaluated.get(); const auto anchor = evaluated.get(); @@ -119,7 +112,7 @@ void FillExtrusionLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintP /* .height_factor = */ heightFactor, /* .pad = */ 0}; - uniforms.createOrUpdate(idFillExtrusionDrawableUBOName, &drawableUBO, context); + uniforms.createOrUpdate(idFillExtrusionDrawableUBO, &drawableUBO, context); }); } diff --git a/src/mbgl/renderer/layers/fill_extrusion_layer_tweaker.hpp b/src/mbgl/renderer/layers/fill_extrusion_layer_tweaker.hpp index 853040359..d6fffe219 100644 --- a/src/mbgl/renderer/layers/fill_extrusion_layer_tweaker.hpp +++ b/src/mbgl/renderer/layers/fill_extrusion_layer_tweaker.hpp @@ -20,9 +20,6 @@ public: void execute(LayerGroupBase&, const PaintParameters&) override; - static const StringIdentity idFillExtrusionTilePropsUBOName; - static const StringIdentity idFillExtrusionInterpolateUBOName; - private: gfx::UniformBufferPtr propsBuffer; diff --git a/src/mbgl/renderer/layers/fill_layer_tweaker.cpp b/src/mbgl/renderer/layers/fill_layer_tweaker.cpp index bbd34ca10..63565a87d 100644 --- a/src/mbgl/renderer/layers/fill_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/fill_layer_tweaker.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -24,33 +25,6 @@ namespace mbgl { using namespace style; -static const StringIdentity idFillDrawableUBOName = stringIndexer().get("FillDrawableUBO"); -static const StringIdentity idFillDrawablePropsUBOName = stringIndexer().get("FillDrawablePropsUBO"); -static const StringIdentity idFillEvaluatedPropsUBOName = stringIndexer().get("FillEvaluatedPropsUBO"); - -const StringIdentity FillLayerTweaker::idFillTilePropsUBOName = stringIndexer().get("FillDrawableTilePropsUBO"); -const StringIdentity FillLayerTweaker::idFillInterpolateUBOName = stringIndexer().get("FillInterpolateUBO"); -const StringIdentity FillLayerTweaker::idFillOutlineInterpolateUBOName = stringIndexer().get( - "FillOutlineInterpolateUBO"); - -static const StringIdentity idFillOutlineDrawableUBOName = stringIndexer().get("FillOutlineDrawableUBO"); -static const StringIdentity idFillOutlineEvaluatedPropsUBOName = stringIndexer().get("FillOutlineEvaluatedPropsUBO"); - -static const StringIdentity idFillOutlineInterpolateUBOName = stringIndexer().get("FillOutlineInterpolateUBO"); - -static const StringIdentity idFillPatternDrawableUBOName = stringIndexer().get("FillPatternDrawableUBO"); -static const StringIdentity idFillPatternInterpolateUBOName = stringIndexer().get("FillPatternInterpolateUBO"); -static const StringIdentity idFillPatternEvaluatedPropsUBOName = stringIndexer().get("FillPatternEvaluatedPropsUBO"); -static const StringIdentity idFillPatternTilePropsUBOName = stringIndexer().get("FillPatternTilePropsUBO"); - -static const StringIdentity idFillOutlinePatternDrawableUBOName = stringIndexer().get("FillOutlinePatternDrawableUBO"); -static const StringIdentity idFillOutlinePatternInterpolateUBOName = stringIndexer().get( - "FillOutlinePatternInterpolateUBO"); -static const StringIdentity idFillOutlinePatternEvaluatedPropsUBOName = stringIndexer().get( - "FillOutlinePatternEvaluatedPropsUBO"); -static const StringIdentity idFillOutlinePatternTilePropsUBOName = stringIndexer().get( - "FillOutlinePatternTilePropsUBO"); - static const StringIdentity idTexImageName = stringIndexer().get("u_image"); using namespace shaders; @@ -176,53 +150,68 @@ void FillLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters } auto& uniforms = drawable.mutableUniformBuffers(); - if (uniforms.get(idFillInterpolateUBOName)) { - UpdateFillUniformBuffers(); + switch (static_cast(drawable.getType())) { + case RenderFillLayer::FillVariant::Fill: { + UpdateFillUniformBuffers(); - uniforms.addOrReplace(idFillEvaluatedPropsUBOName, fillPropsUniformBuffer); + uniforms.set(idFillEvaluatedPropsUBO, fillPropsUniformBuffer); - const FillDrawableUBO drawableUBO = {/*.matrix=*/util::cast(matrix)}; - uniforms.createOrUpdate(idFillDrawableUBOName, &drawableUBO, context); - } else if (uniforms.get(idFillOutlineInterpolateUBOName)) { - UpdateFillOutlineUniformBuffers(); + const FillDrawableUBO drawableUBO = {/*.matrix=*/util::cast(matrix)}; + uniforms.createOrUpdate(idFillDrawableUBO, &drawableUBO, context); + break; + } + case RenderFillLayer::FillVariant::FillOutline: { + UpdateFillOutlineUniformBuffers(); - uniforms.addOrReplace(idFillOutlineEvaluatedPropsUBOName, fillOutlinePropsUniformBuffer); + uniforms.set(idFillOutlineEvaluatedPropsUBO, fillOutlinePropsUniformBuffer); - const FillOutlineDrawableUBO drawableUBO = { - /*.matrix=*/util::cast(matrix), - /*.world=*/{(float)renderableSize.width, (float)renderableSize.height}, - /* pad1 */ 0, - /* pad2 */ 0}; - uniforms.createOrUpdate(idFillOutlineDrawableUBOName, &drawableUBO, context); - } else if (uniforms.get(idFillPatternInterpolateUBOName)) { - UpdateFillPatternUniformBuffers(); + const FillOutlineDrawableUBO drawableUBO = { + /*.matrix=*/util::cast(matrix), + /*.world=*/{(float)renderableSize.width, (float)renderableSize.height}, + /* pad1 */ 0, + /* pad2 */ 0}; + uniforms.createOrUpdate(idFillOutlineDrawableUBO, &drawableUBO, context); + break; + } + case RenderFillLayer::FillVariant::FillPattern: { + UpdateFillPatternUniformBuffers(); - uniforms.addOrReplace(idFillPatternEvaluatedPropsUBOName, fillPatternPropsUniformBuffer); + uniforms.set(idFillPatternEvaluatedPropsUBO, fillPatternPropsUniformBuffer); - 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, - 0, - }; - uniforms.createOrUpdate(idFillPatternDrawableUBOName, &drawableUBO, context); - } else if (uniforms.get(idFillOutlinePatternInterpolateUBOName)) { - UpdateFillOutlinePatternUniformBuffers(); + 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, + 0, + }; + uniforms.createOrUpdate(idFillPatternDrawableUBO, &drawableUBO, context); + break; + } + case RenderFillLayer::FillVariant::FillOutlinePattern: { + UpdateFillOutlinePatternUniformBuffers(); - uniforms.addOrReplace(idFillOutlinePatternEvaluatedPropsUBOName, fillOutlinePatternPropsUniformBuffer); + uniforms.set(idFillOutlinePatternEvaluatedPropsUBO, fillOutlinePatternPropsUniformBuffer); - 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)}, - }; - uniforms.createOrUpdate(idFillOutlinePatternDrawableUBOName, &drawableUBO, context); + 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)}, + }; + uniforms.createOrUpdate(idFillOutlinePatternDrawableUBO, &drawableUBO, context); + break; + } + default: { +#ifndef NDEBUG + mbgl::Log::Error(mbgl::Event::Render, "Invalid fill variant type supplied during drawable update!"); +#endif + break; + } } }); diff --git a/src/mbgl/renderer/layers/fill_layer_tweaker.hpp b/src/mbgl/renderer/layers/fill_layer_tweaker.hpp index f2fb7583f..92d983404 100644 --- a/src/mbgl/renderer/layers/fill_layer_tweaker.hpp +++ b/src/mbgl/renderer/layers/fill_layer_tweaker.hpp @@ -20,10 +20,6 @@ public: void execute(LayerGroupBase&, const PaintParameters&) override; - static const StringIdentity idFillTilePropsUBOName; - static const StringIdentity idFillInterpolateUBOName; - static const StringIdentity idFillOutlineInterpolateUBOName; - private: gfx::UniformBufferPtr fillPropsUniformBuffer; gfx::UniformBufferPtr fillOutlinePropsUniformBuffer; diff --git a/src/mbgl/renderer/layers/heatmap_layer_tweaker.cpp b/src/mbgl/renderer/layers/heatmap_layer_tweaker.cpp index ed9ced5f4..a699bed7e 100644 --- a/src/mbgl/renderer/layers/heatmap_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/heatmap_layer_tweaker.cpp @@ -20,9 +20,6 @@ namespace mbgl { using namespace style; using namespace shaders; -static const StringIdentity idHeatmapDrawableUBOName = stringIndexer().get("HeatmapDrawableUBO"); -static const StringIdentity idHeatmapEvaluatedPropsUBOName = stringIndexer().get("HeatmapEvaluatedPropsUBO"); - void HeatmapLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters& parameters) { auto& context = parameters.context; const auto zoom = parameters.state.getZoom(); @@ -57,7 +54,7 @@ void HeatmapLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParamet const UnwrappedTileID tileID = drawable.getTileID()->toUnwrapped(); auto& uniforms = drawable.mutableUniformBuffers(); - uniforms.addOrReplace(idHeatmapEvaluatedPropsUBOName, getPropsBuffer()); + uniforms.set(idHeatmapEvaluatedPropsUBO, getPropsBuffer()); constexpr bool nearClipped = false; constexpr bool inViewportPixelUnits = false; @@ -68,7 +65,7 @@ void HeatmapLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParamet /* .extrude_scale = */ tileID.pixelsToTileUnits(1.0f, static_cast(zoom)), /* .padding = */ {0}}; - uniforms.createOrUpdate(idHeatmapDrawableUBOName, &drawableUBO, context); + uniforms.createOrUpdate(idHeatmapDrawableUBO, &drawableUBO, context); }); propertiesUpdated = false; diff --git a/src/mbgl/renderer/layers/heatmap_texture_layer_tweaker.cpp b/src/mbgl/renderer/layers/heatmap_texture_layer_tweaker.cpp index d964bbddd..436e871be 100644 --- a/src/mbgl/renderer/layers/heatmap_texture_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/heatmap_texture_layer_tweaker.cpp @@ -16,8 +16,6 @@ namespace mbgl { using namespace style; using namespace shaders; -static const StringIdentity idHeatmapTextureDrawableUBOName = stringIndexer().get("HeatmapTextureDrawableUBO"); - void HeatmapTextureLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters& parameters) { const auto& evaluated = static_cast(*evaluatedProperties).evaluated; @@ -50,7 +48,7 @@ void HeatmapTextureLayerTweaker::execute(LayerGroupBase& layerGroup, const Paint if (!checkTweakDrawable(drawable)) { return; } - drawable.mutableUniformBuffers().addOrReplace(idHeatmapTextureDrawableUBOName, getDrawableUBO()); + drawable.mutableUniformBuffers().set(idHeatmapTextureDrawableUBO, getDrawableUBO()); }); } diff --git a/src/mbgl/renderer/layers/hillshade_layer_tweaker.cpp b/src/mbgl/renderer/layers/hillshade_layer_tweaker.cpp index 28d2d0c35..5a38e2aae 100644 --- a/src/mbgl/renderer/layers/hillshade_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/hillshade_layer_tweaker.cpp @@ -16,9 +16,6 @@ using namespace style; using namespace shaders; namespace { -const StringIdentity idHillshadeDrawableUBOName = stringIndexer().get("HillshadeDrawableUBO"); -const StringIdentity idHillshadeEvaluatedPropsUBOName = stringIndexer().get("HillshadeEvaluatedPropsUBO"); - std::array getLatRange(const UnwrappedTileID& id) { const LatLng latlng0 = LatLng(id); const LatLng latlng1 = LatLng(UnwrappedTileID(id.canonical.z, id.canonical.x, id.canonical.y + 1)); @@ -66,14 +63,14 @@ void HillshadeLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParam const UnwrappedTileID tileID = drawable.getTileID()->toUnwrapped(); auto& uniforms = drawable.mutableUniformBuffers(); - uniforms.addOrReplace(idHillshadeEvaluatedPropsUBOName, getPropsBuffer()); + uniforms.set(idHillshadeEvaluatedPropsUBO, getPropsBuffer()); const auto matrix = getTileMatrix( tileID, parameters, {0.f, 0.f}, TranslateAnchorType::Viewport, false, false, drawable, true); HillshadeDrawableUBO drawableUBO = {/* .matrix = */ util::cast(matrix), /* .latrange = */ getLatRange(tileID), /* .light = */ getLight(parameters, evaluated)}; - uniforms.createOrUpdate(idHillshadeDrawableUBOName, &drawableUBO, parameters.context); + uniforms.createOrUpdate(idHillshadeDrawableUBO, &drawableUBO, parameters.context); }); propertiesUpdated = false; diff --git a/src/mbgl/renderer/layers/hillshade_prepare_layer_tweaker.cpp b/src/mbgl/renderer/layers/hillshade_prepare_layer_tweaker.cpp index 4823460a5..6ba4d4664 100644 --- a/src/mbgl/renderer/layers/hillshade_prepare_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/hillshade_prepare_layer_tweaker.cpp @@ -17,8 +17,6 @@ using namespace style; using namespace shaders; namespace { -const StringIdentity idHillshadePrepareDrawableUBOName = stringIndexer().get("HillshadePrepareDrawableUBO"); - // https://www.mapbox.com/help/access-elevation-data/#mapbox-terrain-rgb constexpr std::array unpackMapbox = {{6553.6f, 25.6f, 0.1f, 10000.0f}}; @@ -59,7 +57,7 @@ void HillshadePrepareLayerTweaker::execute(LayerGroupBase& layerGroup, const Pai /* .maxzoom = */ static_cast(drawableData.maxzoom)}; drawable.mutableUniformBuffers().createOrUpdate( - idHillshadePrepareDrawableUBOName, &drawableUBO, parameters.context); + idHillshadePrepareDrawableUBO, &drawableUBO, parameters.context); }); } diff --git a/src/mbgl/renderer/layers/line_layer_tweaker.cpp b/src/mbgl/renderer/layers/line_layer_tweaker.cpp index f24ceccf1..d3256c706 100644 --- a/src/mbgl/renderer/layers/line_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/line_layer_tweaker.cpp @@ -25,15 +25,6 @@ namespace mbgl { using namespace style; using namespace shaders; -static const StringIdentity idLineUBOName = stringIndexer().get("LineUBO"); -static const StringIdentity idLinePropertiesUBOName = stringIndexer().get("LinePropertiesUBO"); -static const StringIdentity idLineGradientUBOName = stringIndexer().get("LineGradientUBO"); -static const StringIdentity idLineGradientPropertiesUBOName = stringIndexer().get("LineGradientPropertiesUBO"); -static const StringIdentity idLinePatternUBOName = stringIndexer().get("LinePatternUBO"); -static const StringIdentity idLinePatternPropertiesUBOName = stringIndexer().get("LinePatternPropertiesUBO"); -static const StringIdentity idLineSDFUBOName = stringIndexer().get("LineSDFUBO"); -static const StringIdentity idLineSDFPropertiesUBOName = stringIndexer().get("LineSDFPropertiesUBO"); -static const StringIdentity idLineDynamicUBOName = stringIndexer().get("LineDynamicUBO"); static const StringIdentity idTexImageName = stringIndexer().get("u_image"); void LineLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters& parameters) { @@ -136,8 +127,6 @@ void LineLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters const auto matrix = getTileMatrix( tileID, parameters, translation, anchor, nearClipped, inViewportPixelUnits, drawable); - uniforms.addOrReplace(idLineDynamicUBOName, dynamicBuffer); - const LineType type = static_cast(drawable.getType()); switch (type) { case LineType::Simple: { @@ -146,10 +135,13 @@ void LineLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters 0, 0, 0}; - uniforms.createOrUpdate(idLineUBOName, &lineUBO, context); + uniforms.createOrUpdate(idLineUBO, &lineUBO, context); // properties UBO - uniforms.addOrReplace(idLinePropertiesUBOName, getLinePropsBuffer()); + uniforms.set(idLinePropertiesUBO, getLinePropsBuffer()); + + // dynamic UBO + uniforms.set(idLineDynamicUBO, dynamicBuffer); } break; case LineType::Gradient: { @@ -159,10 +151,13 @@ void LineLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters 0, 0, 0}; - uniforms.createOrUpdate(idLineGradientUBOName, &lineGradientUBO, context); + uniforms.createOrUpdate(idLineGradientUBO, &lineGradientUBO, context); // properties UBO - uniforms.addOrReplace(idLineGradientPropertiesUBOName, getLineGradientPropsBuffer()); + uniforms.set(idLineGradientPropertiesUBO, getLineGradientPropsBuffer()); + + // dynamic UBO + uniforms.set(idLineGradientDynamicUBO, dynamicBuffer); } break; case LineType::Pattern: { @@ -182,10 +177,13 @@ void LineLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters /*texsize =*/{static_cast(textureSize.width), static_cast(textureSize.height)}, /*ratio =*/1.0f / tileID.pixelsToTileUnits(1.0f, static_cast(zoom)), /*fade =*/crossfade.t}; - uniforms.createOrUpdate(idLinePatternUBOName, &linePatternUBO, context); + uniforms.createOrUpdate(idLinePatternUBO, &linePatternUBO, context); // properties UBO - uniforms.addOrReplace(idLinePatternPropertiesUBOName, getLinePatternPropsBuffer()); + uniforms.set(idLinePatternPropertiesUBO, getLinePatternPropsBuffer()); + + // dynamic UBO + uniforms.set(idLinePatternDynamicUBO, dynamicBuffer); } break; @@ -229,10 +227,13 @@ void LineLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters 0, 0, 0}; - uniforms.createOrUpdate(idLineSDFUBOName, &lineSDFUBO, context); + uniforms.createOrUpdate(idLineSDFUBO, &lineSDFUBO, context); // properties UBO - uniforms.addOrReplace(idLineSDFPropertiesUBOName, getLineSDFPropsBuffer()); + uniforms.set(idLineSDFPropertiesUBO, getLineSDFPropsBuffer()); + + // dynamic UBO + uniforms.set(idLineSDFDynamicUBO, dynamicBuffer); } } break; diff --git a/src/mbgl/renderer/layers/raster_layer_tweaker.cpp b/src/mbgl/renderer/layers/raster_layer_tweaker.cpp index 665562d1e..de19f3914 100644 --- a/src/mbgl/renderer/layers/raster_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/raster_layer_tweaker.cpp @@ -17,8 +17,6 @@ namespace mbgl { using namespace style; using namespace shaders; -static const StringIdentity idRasterDrawableUBOName = stringIndexer().get("RasterDrawableUBO"); - void RasterLayerTweaker::execute([[maybe_unused]] LayerGroupBase& layerGroup, [[maybe_unused]] const PaintParameters& parameters) { const auto& evaluated = static_cast(*evaluatedProperties).evaluated; @@ -92,7 +90,7 @@ void RasterLayerTweaker::execute([[maybe_unused]] LayerGroupBase& layerGroup, 0, 0}; auto& uniforms = drawable.mutableUniformBuffers(); - uniforms.createOrUpdate(idRasterDrawableUBOName, &drawableUBO, parameters.context); + uniforms.createOrUpdate(idRasterDrawableUBO, &drawableUBO, parameters.context); }); } diff --git a/src/mbgl/renderer/layers/render_circle_layer.cpp b/src/mbgl/renderer/layers/render_circle_layer.cpp index a1343eeec..9a11ca919 100644 --- a/src/mbgl/renderer/layers/render_circle_layer.cpp +++ b/src/mbgl/renderer/layers/render_circle_layer.cpp @@ -264,7 +264,6 @@ bool RenderCircleLayer::queryIntersectsFeature(const GeometryCoordinates& queryG namespace { constexpr auto CircleShaderGroupName = "CircleShader"; -const StringIdentity idCircleInterpolateUBOName = stringIndexer().get("CircleInterpolateUBO"); const StringIdentity idVertexAttribName = stringIndexer().get("a_pos"); } // namespace @@ -361,7 +360,7 @@ void RenderCircleLayer::update(gfx::ShaderRegistry& shaders, } auto& uniforms = drawable.mutableUniformBuffers(); - uniforms.createOrUpdate(idCircleInterpolateUBOName, &interpolateUBO, context); + uniforms.createOrUpdate(idCircleInterpolateUBO, &interpolateUBO, context); return true; }; if (updateTile(renderPass, tileID, std::move(updateExisting))) { @@ -417,7 +416,7 @@ void RenderCircleLayer::update(gfx::ShaderRegistry& shaders, drawable->setLayerTweaker(layerTweaker); auto& uniforms = drawable->mutableUniformBuffers(); - uniforms.addOrReplace(idCircleInterpolateUBOName, interpBuffer); + uniforms.set(idCircleInterpolateUBO, interpBuffer); tileLayerGroup->addDrawable(renderPass, tileID, std::move(drawable)); ++stats.drawablesAdded; diff --git a/src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp b/src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp index 296e73d51..f6bf877ce 100644 --- a/src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp +++ b/src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp @@ -402,8 +402,8 @@ void RenderFillExtrusionLayer::update(gfx::ShaderRegistry& shaders, } auto& uniforms = drawable.mutableUniformBuffers(); - uniforms.createOrUpdate(FillExtrusionLayerTweaker::idFillExtrusionTilePropsUBOName, &tilePropsUBO, context); - uniforms.createOrUpdate(FillExtrusionLayerTweaker::idFillExtrusionInterpolateUBOName, &interpUBO, context); + uniforms.createOrUpdate(idFillExtrusionDrawableTilePropsUBO, &tilePropsUBO, context); + uniforms.createOrUpdate(idFillExtrusionInterpolateUBO, &interpUBO, context); return true; }; if (updateTile(drawPass, tileID, std::move(updateExisting))) { @@ -515,10 +515,8 @@ void RenderFillExtrusionLayer::update(gfx::ShaderRegistry& shaders, drawable->setLayerTweaker(layerTweaker); auto& uniforms = drawable->mutableUniformBuffers(); - uniforms.createOrUpdate( - FillExtrusionLayerTweaker::idFillExtrusionTilePropsUBOName, &tilePropsUBO, context); - uniforms.createOrUpdate( - FillExtrusionLayerTweaker::idFillExtrusionInterpolateUBOName, &interpUBO, context); + uniforms.createOrUpdate(idFillExtrusionDrawableTilePropsUBO, &tilePropsUBO, context); + uniforms.createOrUpdate(idFillExtrusionInterpolateUBO, &interpUBO, context); tileLayerGroup->addDrawable(drawPass, tileID, std::move(drawable)); ++stats.drawablesAdded; diff --git a/src/mbgl/renderer/layers/render_fill_layer.cpp b/src/mbgl/renderer/layers/render_fill_layer.cpp index dd1436651..7ade9731d 100644 --- a/src/mbgl/renderer/layers/render_fill_layer.cpp +++ b/src/mbgl/renderer/layers/render_fill_layer.cpp @@ -50,12 +50,6 @@ constexpr auto FillOutlineShaderName = "FillOutlineShader"; constexpr auto FillPatternShaderName = "FillPatternShader"; constexpr auto FillOutlinePatternShaderName = "FillOutlinePatternShader"; -const StringIdentity idFillOutlineInterpolateUBOName = stringIndexer().get("FillOutlineInterpolateUBO"); -const StringIdentity idFillPatternInterpolateUBOName = stringIndexer().get("FillPatternInterpolateUBO"); -const StringIdentity idFillPatternTilePropsUBOName = stringIndexer().get("FillPatternTilePropsUBO"); -const StringIdentity idFillOutlinePatternInterpolateUBOName = stringIndexer().get("FillOutlinePatternInterpolateUBO"); -const StringIdentity idFillOutlinePatternTilePropsUBOName = stringIndexer().get("FillOutlinePatternTilePropsUBO"); - const StringIdentity idPosAttribName = stringIndexer().get("a_pos"); const StringIdentity idIconTextureName = stringIndexer().get("u_image"); #endif // MLN_DRAWABLE_RENDERER @@ -365,21 +359,19 @@ public: const auto zoom = parameters.state.getZoom(); auto& uniforms = drawable.mutableUniformBuffers(); - static const StringIdentity idLineUBOName = stringIndexer().get("LineBasicUBO"); { const auto matrix = LayerTweaker::getTileMatrix( tileID, parameters, {{0, 0}}, style::TranslateAnchorType::Viewport, false, false, drawable, false); - const shaders::LineBasicUBO lineUBO{ + const shaders::LineBasicUBO lineBasicUBO{ /*matrix = */ util::cast(matrix), /*units_to_pixels = */ {1.0f / parameters.pixelsToGLUnits[0], 1.0f / parameters.pixelsToGLUnits[1]}, /*ratio = */ 1.0f / tileID.pixelsToTileUnits(1.0f, zoom), 0}; - parameters.context.emplaceOrUpdateUniformBuffer(lineUniformBuffer, &lineUBO); + parameters.context.emplaceOrUpdateUniformBuffer(lineUniformBuffer, &lineBasicUBO); } - uniforms.addOrReplace(idLineUBOName, lineUniformBuffer); + uniforms.set(idLineBasicUBO, lineUniformBuffer); - static const StringIdentity idLinePropertiesUBOName = stringIndexer().get("LineBasicPropertiesUBO"); if (!linePropertiesUniformBuffer) { const shaders::LineBasicPropertiesUBO linePropertiesUBO{/*color =*/color, /*opacity =*/opacity, @@ -388,8 +380,8 @@ public: 0}; parameters.context.emplaceOrUpdateUniformBuffer(linePropertiesUniformBuffer, &linePropertiesUBO); } - if (!uniforms.get(idLinePropertiesUBOName)) { - uniforms.addOrReplace(idLinePropertiesUBOName, linePropertiesUniformBuffer); + if (!uniforms.get(idLineBasicPropertiesUBO)) { + uniforms.set(idLineBasicPropertiesUBO, linePropertiesUniformBuffer); } }; @@ -640,24 +632,23 @@ void RenderFillLayer::update(gfx::ShaderRegistry& shaders, auto& uniforms = drawable.mutableUniformBuffers(); switch (static_cast(drawable.getType())) { case FillVariant::Fill: { - uniforms.createOrUpdate( - FillLayerTweaker::idFillInterpolateUBOName, &getFillInterpolateUBO(), context); + uniforms.createOrUpdate(idFillInterpolateUBO, &getFillInterpolateUBO(), context); break; } case FillVariant::FillOutline: { - uniforms.createOrUpdate(idFillOutlineInterpolateUBOName, &getFillOutlineInterpolateUBO(), context); + uniforms.createOrUpdate(idFillOutlineInterpolateUBO, &getFillOutlineInterpolateUBO(), context); break; } case FillVariant::FillPattern: { - uniforms.createOrUpdate(idFillPatternInterpolateUBOName, &getFillPatternInterpolateUBO(), context); - uniforms.createOrUpdate(idFillPatternTilePropsUBOName, &getFillPatternTilePropsUBO(), context); + uniforms.createOrUpdate(idFillPatternInterpolateUBO, &getFillPatternInterpolateUBO(), context); + uniforms.createOrUpdate(idFillPatternTilePropsUBO, &getFillPatternTilePropsUBO(), context); break; } case FillVariant::FillOutlinePattern: { uniforms.createOrUpdate( - idFillOutlinePatternInterpolateUBOName, &getFillOutlinePatternInterpolateUBO(), context); + idFillOutlinePatternInterpolateUBO, &getFillOutlinePatternInterpolateUBO(), context); uniforms.createOrUpdate( - idFillOutlinePatternTilePropsUBOName, &getFillOutlinePatternTilePropsUBO(), context); + idFillOutlinePatternTilePropsUBO, &getFillOutlinePatternTilePropsUBO(), context); break; } default: { @@ -779,7 +770,7 @@ void RenderFillLayer::update(gfx::ShaderRegistry& shaders, } const auto finish = [&](gfx::DrawableBuilder& builder, - const StringIdentity interpolateUBONameId, + const size_t interpolateUBOId, const auto& interpolateUBO, FillVariant type) { builder.setVertexAttrNameId(idPosAttribName); @@ -791,7 +782,7 @@ void RenderFillLayer::update(gfx::ShaderRegistry& shaders, drawable->setType(static_cast(type)); auto& uniforms = drawable->mutableUniformBuffers(); - uniforms.createOrUpdate(interpolateUBONameId, &interpolateUBO, context); + uniforms.createOrUpdate(interpolateUBOId, &interpolateUBO, context); fillTileLayerGroup->addDrawable(renderPass, tileID, std::move(drawable)); ++stats.drawablesAdded; } @@ -819,10 +810,7 @@ void RenderFillLayer::update(gfx::ShaderRegistry& shaders, bucket.sharedTriangles, bucket.triangleSegments.data(), bucket.triangleSegments.size()); - finish(*fillBuilder, - FillLayerTweaker::idFillInterpolateUBOName, - getFillInterpolateUBO(), - FillVariant::Fill); + finish(*fillBuilder, idFillInterpolateUBO, getFillInterpolateUBO(), FillVariant::Fill); } #if MLN_TRIANGULATE_FILL_OUTLINES @@ -841,7 +829,7 @@ void RenderFillLayer::update(gfx::ShaderRegistry& shaders, bucket.basicLineSegments.data(), bucket.basicLineSegments.size()); finish(*outlineBuilder, - FillLayerTweaker::idFillOutlineInterpolateUBOName, + idFillOutlineInterpolateUBO, getFillOutlineInterpolateUBO(), FillVariant::FillOutline); } @@ -856,7 +844,7 @@ void RenderFillLayer::update(gfx::ShaderRegistry& shaders, bucket.basicLineSegments.data(), bucket.basicLineSegments.size()); finish(*outlineBuilder, - FillLayerTweaker::idFillOutlineInterpolateUBOName, + idFillOutlineInterpolateUBO, getFillOutlineInterpolateUBO(), FillVariant::FillOutline); } @@ -914,7 +902,7 @@ void RenderFillLayer::update(gfx::ShaderRegistry& shaders, const auto finish = [&](gfx::DrawableBuilder& builder, const StringIdentity interpolateNameId, const auto& interpolateUBO, - const StringIdentity tileUBONameId, + const size_t tileUBOId, const auto& tileUBO, FillVariant type) { builder.flush(context); @@ -926,7 +914,7 @@ void RenderFillLayer::update(gfx::ShaderRegistry& shaders, auto& uniforms = drawable->mutableUniformBuffers(); uniforms.createOrUpdate(interpolateNameId, &interpolateUBO, context); - uniforms.createOrUpdate(tileUBONameId, &tileUBO, context); + uniforms.createOrUpdate(tileUBOId, &tileUBO, context); fillTileLayerGroup->addDrawable(renderPass, tileID, std::move(drawable)); ++stats.drawablesAdded; } @@ -948,9 +936,9 @@ void RenderFillLayer::update(gfx::ShaderRegistry& shaders, bucket.triangleSegments.size()); finish(*patternBuilder, - idFillPatternInterpolateUBOName, + idFillPatternInterpolateUBO, getFillPatternInterpolateUBO(), - idFillPatternTilePropsUBOName, + idFillPatternTilePropsUBO, getFillPatternTilePropsUBO(), FillVariant::FillPattern); } @@ -965,9 +953,9 @@ void RenderFillLayer::update(gfx::ShaderRegistry& shaders, bucket.basicLineSegments.size()); finish(*outlinePatternBuilder, - idFillOutlinePatternInterpolateUBOName, + idFillOutlinePatternInterpolateUBO, getFillOutlinePatternInterpolateUBO(), - idFillOutlinePatternTilePropsUBOName, + idFillOutlinePatternTilePropsUBO, getFillOutlinePatternTilePropsUBO(), FillVariant::FillOutlinePattern); } diff --git a/src/mbgl/renderer/layers/render_heatmap_layer.cpp b/src/mbgl/renderer/layers/render_heatmap_layer.cpp index c5af6665e..20413c708 100644 --- a/src/mbgl/renderer/layers/render_heatmap_layer.cpp +++ b/src/mbgl/renderer/layers/render_heatmap_layer.cpp @@ -277,7 +277,7 @@ namespace { constexpr auto HeatmapShaderGroupName = "HeatmapShader"; constexpr auto HeatmapTextureShaderGroupName = "HeatmapTextureShader"; -const StringIdentity idHeatmapInterpolateUBOName = stringIndexer().get("HeatmapInterpolateUBO"); + const StringIdentity idVertexAttribName = stringIndexer().get("a_pos"); const StringIdentity idTexImageName = stringIndexer().get("u_image"); const StringIdentity idTexColorRampName = stringIndexer().get("u_color_ramp"); @@ -402,7 +402,7 @@ void RenderHeatmapLayer::update(gfx::ShaderRegistry& shaders, auto& uniforms = drawable.mutableUniformBuffers(); if (auto buffer = getInterpolateBuffer()) { - uniforms.addOrReplace(idHeatmapInterpolateUBOName, std::move(buffer)); + uniforms.set(idHeatmapInterpolateUBO, std::move(buffer)); } }); @@ -467,7 +467,7 @@ void RenderHeatmapLayer::update(gfx::ShaderRegistry& shaders, auto& uniforms = drawable->mutableUniformBuffers(); if (auto buffer = getInterpolateBuffer()) { - uniforms.addOrReplace(idHeatmapInterpolateUBOName, std::move(buffer)); + uniforms.set(idHeatmapInterpolateUBO, std::move(buffer)); } tileLayerGroup->addDrawable(renderPass, tileID, std::move(drawable)); diff --git a/src/mbgl/renderer/layers/render_line_layer.cpp b/src/mbgl/renderer/layers/render_line_layer.cpp index c3a69b9eb..a6c90f2e9 100644 --- a/src/mbgl/renderer/layers/render_line_layer.cpp +++ b/src/mbgl/renderer/layers/render_line_layer.cpp @@ -345,15 +345,6 @@ float RenderLineLayer::getLineWidth(const GeometryTileFeature& feature, } #if MLN_DRAWABLE_RENDERER -/// Property interpolation UBOs -static const StringIdentity idLineInterpolationUBOName = stringIndexer().get("LineInterpolationUBO"); -static const StringIdentity idLineGradientInterpolationUBOName = stringIndexer().get("LineGradientInterpolationUBO"); -static const StringIdentity idLinePatternInterpolationUBOName = stringIndexer().get("LinePatternInterpolationUBO"); -static const StringIdentity idLineSDFInterpolationUBOName = stringIndexer().get("LineSDFInterpolationUBO"); - -/// Evaluated properties that depend on the tile -static const StringIdentity idLinePatternTilePropertiesUBOName = stringIndexer().get("LinePatternTilePropertiesUBO"); - static const StringIdentity idLineImageUniformName = stringIndexer().get("u_image"); void RenderLineLayer::update(gfx::ShaderRegistry& shaders, @@ -577,34 +568,36 @@ void RenderLineLayer::update(gfx::ShaderRegistry& shaders, return false; } - const auto& shader = drawable.getShader(); - const auto& shaderUniforms = shader->getUniformBlocks(); auto& drawableUniforms = drawable.mutableUniformBuffers(); + const LineLayerTweaker::LineType type = static_cast(drawable.getType()); + switch (type) { + case LineLayerTweaker::LineType::Simple: { + drawableUniforms.createOrUpdate(idLineInterpolationUBO, &getLineInterpolationUBO(), context); + } break; - // simple line interpolation UBO - if (shaderUniforms.get(idLineInterpolationUBOName)) { - drawableUniforms.createOrUpdate(idLineInterpolationUBOName, &getLineInterpolationUBO(), context); - } - // gradient line interpolation UBO - else if (shaderUniforms.get(idLineGradientInterpolationUBOName)) { - drawableUniforms.createOrUpdate( - idLineGradientInterpolationUBOName, &getLineGradientInterpolationUBO(), context); - } - // pattern line interpolation UBO - else if (shaderUniforms.get(idLinePatternInterpolationUBOName)) { - // interpolation - drawableUniforms.createOrUpdate( - idLinePatternInterpolationUBOName, &getLinePatternInterpolationUBO(), context); - // tile properties - drawableUniforms.createOrUpdate( - idLinePatternTilePropertiesUBOName, &getLinePatternTilePropertiesUBO(), context); - } - // SDF line interpolation UBO - else if (shaderUniforms.get(idLineSDFInterpolationUBOName)) { - drawableUniforms.createOrUpdate(idLineSDFInterpolationUBOName, &getLineSDFInterpolationUBO(), context); - } + case LineLayerTweaker::LineType::Gradient: { + drawableUniforms.createOrUpdate( + idLineGradientInterpolationUBO, &getLineGradientInterpolationUBO(), context); + } break; - // TODO: vertex attributes or `propertiesAsUniforms` updated, is that needed? + case LineLayerTweaker::LineType::Pattern: { + drawableUniforms.createOrUpdate( + idLinePatternInterpolationUBO, &getLinePatternInterpolationUBO(), context); + + drawableUniforms.createOrUpdate( + idLinePatternTilePropertiesUBO, &getLinePatternTilePropertiesUBO(), context); + } break; + + case LineLayerTweaker::LineType::SDF: { + drawableUniforms.createOrUpdate(idLineSDFInterpolationUBO, &getLineSDFInterpolationUBO(), context); + } break; + + default: { + using namespace std::string_literals; + Log::Error(Event::General, + "RenderLineLayer: unknown line type: "s + std::to_string(mbgl::underlying_type(type))); + } break; + } return true; }; if (updateTile(renderPass, tileID, std::move(updateExisting))) { @@ -649,7 +642,7 @@ void RenderLineLayer::update(gfx::ShaderRegistry& shaders, drawable->setLayerTweaker(layerTweaker); drawable->setData(std::make_unique(cap)); drawable->mutableUniformBuffers().createOrUpdate( - idLineSDFInterpolationUBOName, &getLineSDFInterpolationUBO(), context); + idLineSDFInterpolationUBO, &getLineSDFInterpolationUBO(), context); tileLayerGroup->addDrawable(renderPass, tileID, std::move(drawable)); ++stats.drawablesAdded; @@ -706,9 +699,9 @@ void RenderLineLayer::update(gfx::ShaderRegistry& shaders, drawable->setTileID(tileID); drawable->setLayerTweaker(layerTweaker); drawable->mutableUniformBuffers().createOrUpdate( - idLinePatternInterpolationUBOName, &getLinePatternInterpolationUBO(), context); + idLinePatternInterpolationUBO, &getLinePatternInterpolationUBO(), context); drawable->mutableUniformBuffers().createOrUpdate( - idLinePatternTilePropertiesUBOName, &getLinePatternTilePropertiesUBO(), context); + idLinePatternTilePropertiesUBO, &getLinePatternTilePropertiesUBO(), context); tileLayerGroup->addDrawable(renderPass, tileID, std::move(drawable)); ++stats.drawablesAdded; @@ -758,7 +751,7 @@ void RenderLineLayer::update(gfx::ShaderRegistry& shaders, drawable->setTileID(tileID); drawable->setLayerTweaker(layerTweaker); drawable->mutableUniformBuffers().createOrUpdate( - idLineGradientInterpolationUBOName, &getLineGradientInterpolationUBO(), context); + idLineGradientInterpolationUBO, &getLineGradientInterpolationUBO(), context); tileLayerGroup->addDrawable(renderPass, tileID, std::move(drawable)); ++stats.drawablesAdded; @@ -795,7 +788,7 @@ void RenderLineLayer::update(gfx::ShaderRegistry& shaders, drawable->setTileID(tileID); drawable->setLayerTweaker(layerTweaker); drawable->mutableUniformBuffers().createOrUpdate( - idLineInterpolationUBOName, &getLineInterpolationUBO(), context); + idLineInterpolationUBO, &getLineInterpolationUBO(), context); tileLayerGroup->addDrawable(renderPass, tileID, std::move(drawable)); ++stats.drawablesAdded; diff --git a/src/mbgl/renderer/layers/render_symbol_layer.cpp b/src/mbgl/renderer/layers/render_symbol_layer.cpp index a59e00820..f35b745d0 100644 --- a/src/mbgl/renderer/layers/render_symbol_layer.cpp +++ b/src/mbgl/renderer/layers/render_symbol_layer.cpp @@ -848,20 +848,20 @@ void updateTileDrawable(gfx::Drawable& drawable, // Create or update the shared interpolation UBO gfx::UniformBufferPtr& interpUBO = isText ? textInterpUBO : iconInterpUBO; if (interpUBO) { - uniforms.addOrReplace(SymbolLayerTweaker::idSymbolDrawableInterpolateUBOName, interpUBO); + uniforms.set(idSymbolDrawableInterpolateUBO, interpUBO); } else { const auto ubo = buildInterpUBO(paintProps, isText, currentZoom); - interpUBO = uniforms.get(SymbolLayerTweaker::idSymbolDrawableInterpolateUBOName); + interpUBO = uniforms.get(idSymbolDrawableInterpolateUBO); if (interpUBO) { interpUBO->update(&ubo, sizeof(ubo)); } else { interpUBO = context.createUniformBuffer(&ubo, sizeof(ubo)); - uniforms.addOrReplace(SymbolLayerTweaker::idSymbolDrawableInterpolateUBOName, interpUBO); + uniforms.set(idSymbolDrawableInterpolateUBO, interpUBO); } } const auto tileUBO = buildTileUBO(bucket, drawData, currentZoom); - uniforms.createOrUpdate(SymbolLayerTweaker::idSymbolDrawableTilePropsUBOName, &tileUBO, context); + uniforms.createOrUpdate(idSymbolDrawableTilePropsUBO, &tileUBO, context); const auto& buffer = isText ? bucket.text : (sdfIcons ? bucket.sdfIcon : bucket.icon); const auto vertexCount = buffer.vertices().elements(); @@ -1367,8 +1367,8 @@ void RenderSymbolLayer::update(gfx::ShaderRegistry& shaders, drawable->setData(std::move(drawData)); auto& uniforms = drawable->mutableUniformBuffers(); - uniforms.createOrUpdate(SymbolLayerTweaker::idSymbolDrawableTilePropsUBOName, &tileUBO, context); - uniforms.addOrReplace(SymbolLayerTweaker::idSymbolDrawableInterpolateUBOName, interpUBO); + uniforms.createOrUpdate(idSymbolDrawableTilePropsUBO, &tileUBO, context); + uniforms.set(idSymbolDrawableInterpolateUBO, interpUBO); tileLayerGroup->addDrawable(passes, tileID, std::move(drawable)); ++stats.drawablesAdded; diff --git a/src/mbgl/renderer/layers/symbol_layer_tweaker.cpp b/src/mbgl/renderer/layers/symbol_layer_tweaker.cpp index aa7378110..120e9c20b 100644 --- a/src/mbgl/renderer/layers/symbol_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/symbol_layer_tweaker.cpp @@ -62,14 +62,6 @@ SymbolDrawablePaintUBO buildPaintUBO(bool isText, const SymbolPaintProperties::P } // namespace -const StringIdentity SymbolLayerTweaker::idSymbolDrawableUBOName = stringIndexer().get("SymbolDrawableUBO"); -const StringIdentity SymbolLayerTweaker::idSymbolDynamicUBOName = stringIndexer().get("SymbolDynamicUBO"); -const StringIdentity SymbolLayerTweaker::idSymbolDrawablePaintUBOName = stringIndexer().get("SymbolDrawablePaintUBO"); -const StringIdentity SymbolLayerTweaker::idSymbolDrawableTilePropsUBOName = stringIndexer().get( - "SymbolDrawableTilePropsUBO"); -const StringIdentity SymbolLayerTweaker::idSymbolDrawableInterpolateUBOName = stringIndexer().get( - "SymbolDrawableInterpolateUBO"); - void SymbolLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters& parameters) { auto& context = parameters.context; const auto& state = parameters.state; @@ -169,10 +161,10 @@ void SymbolLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParamete }; auto& uniforms = drawable.mutableUniformBuffers(); - uniforms.createOrUpdate(idSymbolDrawableUBOName, &drawableUBO, context); + uniforms.createOrUpdate(idSymbolDrawableUBO, &drawableUBO, context); - uniforms.addOrReplace(idSymbolDynamicUBOName, dynamicBuffer); - uniforms.addOrReplace(idSymbolDrawablePaintUBOName, isText ? textPaintBuffer : iconPaintBuffer); + uniforms.set(idSymbolDynamicUBO, dynamicBuffer); + uniforms.set(idSymbolDrawablePaintUBO, isText ? textPaintBuffer : iconPaintBuffer); }); } diff --git a/src/mbgl/renderer/layers/symbol_layer_tweaker.hpp b/src/mbgl/renderer/layers/symbol_layer_tweaker.hpp index 2b57d7be7..341d627ef 100644 --- a/src/mbgl/renderer/layers/symbol_layer_tweaker.hpp +++ b/src/mbgl/renderer/layers/symbol_layer_tweaker.hpp @@ -20,12 +20,6 @@ public: void execute(LayerGroupBase&, const PaintParameters&) override; - static const StringIdentity idSymbolDrawableUBOName; - static const StringIdentity idSymbolDynamicUBOName; - static const StringIdentity idSymbolDrawablePaintUBOName; - static const StringIdentity idSymbolDrawableTilePropsUBOName; - static const StringIdentity idSymbolDrawableInterpolateUBOName; - private: gfx::UniformBufferPtr textPaintBuffer; gfx::UniformBufferPtr iconPaintBuffer; diff --git a/src/mbgl/renderer/sources/render_tile_source.cpp b/src/mbgl/renderer/sources/render_tile_source.cpp index 442038384..959dbff43 100644 --- a/src/mbgl/renderer/sources/render_tile_source.cpp +++ b/src/mbgl/renderer/sources/render_tile_source.cpp @@ -66,7 +66,6 @@ void TileSourceRenderItem::updateDebugDrawables(DebugLayerGroupMap& debugLayerGr return; } static const StringIdentity idVertexAttribName = stringIndexer().get("a_pos"); - static const StringIdentity idDebugUBOName = stringIndexer().get("DebugUBO"); std::unique_ptr debugBuilder = [&]() -> std::unique_ptr { auto builder = context.createDrawableBuilder("debug-builder"); builder->setShader(debugShader); @@ -151,7 +150,7 @@ void TileSourceRenderItem::updateDebugDrawables(DebugLayerGroupMap& debugLayerGr auto updatedCount = tileLayerGroup->visitDrawables(renderPass, tileID, [&](gfx::Drawable& drawable) { // update existing drawable auto& uniforms = drawable.mutableUniformBuffers(); - uniforms.createOrUpdate(idDebugUBOName, &debugUBO, context); + uniforms.createOrUpdate(idDebugUBO, &debugUBO, context); }); return updatedCount; }; @@ -180,7 +179,7 @@ void TileSourceRenderItem::updateDebugDrawables(DebugLayerGroupMap& debugLayerGr for (auto& drawable : debugBuilder->clearDrawables()) { drawable->setTileID(tileID); auto& uniforms = drawable->mutableUniformBuffers(); - uniforms.createOrUpdate(idDebugUBOName, &debugUBO, context); + uniforms.createOrUpdate(idDebugUBO, &debugUBO, context); tileLayerGroup->addDrawable(renderPass, tileID, std::move(drawable)); } @@ -210,22 +209,17 @@ void TileSourceRenderItem::updateDebugDrawables(DebugLayerGroupMap& debugLayerGr const auto matrix = LayerTweaker::getTileMatrix( tileID, parameters, {{0, 0}}, style::TranslateAnchorType::Viewport, false, false, drawable, false); - static const StringIdentity idLineDynamicUBOName = stringIndexer().get("LineDynamicUBO"); const shaders::LineDynamicUBO dynamicUBO = { /*units_to_pixels = */ {1.0f / parameters.pixelsToGLUnits[0], 1.0f / parameters.pixelsToGLUnits[1]}, 0, 0}; - static const StringIdentity idLineUBOName = stringIndexer().get("LineUBO"); const shaders::LineUBO lineUBO{/*matrix = */ util::cast(matrix), /*ratio = */ 1.0f / tileID.pixelsToTileUnits(1.0f, zoom), 0, 0, 0}; - static const StringIdentity idLinePropertiesUBOName = stringIndexer().get("LinePropertiesUBO"); - - static const StringIdentity idLineInterpolationUBOName = stringIndexer().get("LineInterpolationUBO"); const shaders::LineInterpolationUBO lineInterpolationUBO{/*color_t =*/0.f, /*blur_t =*/0.f, /*opacity_t =*/0.f, @@ -235,10 +229,10 @@ void TileSourceRenderItem::updateDebugDrawables(DebugLayerGroupMap& debugLayerGr 0, 0}; auto& uniforms = drawable.mutableUniformBuffers(); - uniforms.createOrUpdate(idLineDynamicUBOName, &dynamicUBO, parameters.context); - uniforms.createOrUpdate(idLineUBOName, &lineUBO, parameters.context); - uniforms.createOrUpdate(idLinePropertiesUBOName, &linePropertiesUBO, parameters.context); - uniforms.createOrUpdate(idLineInterpolationUBOName, &lineInterpolationUBO, parameters.context); + uniforms.createOrUpdate(idLineDynamicUBO, &dynamicUBO, parameters.context); + uniforms.createOrUpdate(idLineUBO, &lineUBO, parameters.context); + uniforms.createOrUpdate(idLinePropertiesUBO, &linePropertiesUBO, parameters.context); + uniforms.createOrUpdate(idLineInterpolationUBO, &lineInterpolationUBO, parameters.context); }; private: diff --git a/src/mbgl/shaders/gl/shader_info.cpp b/src/mbgl/shaders/gl/shader_info.cpp new file mode 100644 index 000000000..5d90eb2fc --- /dev/null +++ b/src/mbgl/shaders/gl/shader_info.cpp @@ -0,0 +1,178 @@ +#include + +#include + +namespace mbgl { +namespace shaders { + +UniformBlockInfo::UniformBlockInfo(std::string_view name_, std::size_t id_) + : name(name_), + id(id_), + binding(id_) {} + +const std::vector ShaderInfo::uniformBlocks = { + UniformBlockInfo{"BackgroundDrawableUBO", idBackgroundDrawableUBO}, + UniformBlockInfo{"BackgroundLayerUBO", idBackgroundLayerUBO}, +}; + +const std::vector + ShaderInfo::uniformBlocks = { + UniformBlockInfo{"BackgroundDrawableUBO", idBackgroundDrawableUBO}, + UniformBlockInfo{"BackgroundLayerUBO", idBackgroundLayerUBO}, +}; + +const std::vector ShaderInfo::uniformBlocks = { + UniformBlockInfo{"CircleDrawableUBO", idCircleDrawableUBO}, + UniformBlockInfo{"CirclePaintParamsUBO", idCirclePaintParamsUBO}, + UniformBlockInfo{"CircleEvaluatedPropsUBO", idCircleEvaluatedPropsUBO}, + UniformBlockInfo{"CircleInterpolateUBO", idCircleInterpolateUBO}, +}; + +const std::vector ShaderInfo::uniformBlocks = + { + UniformBlockInfo{"CollisionBoxUBO", idCollisionUBO}, +}; + +const std::vector + ShaderInfo::uniformBlocks = { + UniformBlockInfo{"CollisionCircleUBO", idCollisionUBO}, +}; + +const std::vector ShaderInfo::uniformBlocks = { + UniformBlockInfo{"DebugUBO", idDebugUBO}, +}; + +const std::vector ShaderInfo::uniformBlocks = { + UniformBlockInfo{"FillDrawableUBO", idFillDrawableUBO}, + UniformBlockInfo{"FillEvaluatedPropsUBO", idFillEvaluatedPropsUBO}, + UniformBlockInfo{"FillInterpolateUBO", idFillInterpolateUBO}, +}; + +const std::vector ShaderInfo::uniformBlocks = + { + UniformBlockInfo{"FillOutlineDrawableUBO", idFillOutlineDrawableUBO}, + UniformBlockInfo{"FillOutlineEvaluatedPropsUBO", idFillOutlineEvaluatedPropsUBO}, + UniformBlockInfo{"FillOutlineInterpolateUBO", idFillOutlineInterpolateUBO}, +}; + +const std::vector ShaderInfo::uniformBlocks = + { + UniformBlockInfo{"FillPatternDrawableUBO", idFillPatternDrawableUBO}, + UniformBlockInfo{"FillPatternTilePropsUBO", idFillPatternTilePropsUBO}, + UniformBlockInfo{"FillPatternEvaluatedPropsUBO", idFillPatternEvaluatedPropsUBO}, + UniformBlockInfo{"FillPatternInterpolateUBO", idFillPatternInterpolateUBO}, +}; + +const std::vector + ShaderInfo::uniformBlocks = { + UniformBlockInfo{"FillOutlinePatternDrawableUBO", idFillOutlinePatternDrawableUBO}, + UniformBlockInfo{"FillOutlinePatternTilePropsUBO", idFillOutlinePatternTilePropsUBO}, + UniformBlockInfo{"FillOutlinePatternEvaluatedPropsUBO", idFillOutlinePatternEvaluatedPropsUBO}, + UniformBlockInfo{"FillOutlinePatternInterpolateUBO", idFillOutlinePatternInterpolateUBO}, +}; + +const std::vector + ShaderInfo::uniformBlocks = { + UniformBlockInfo{"FillExtrusionDrawableUBO", idFillExtrusionDrawableUBO}, + UniformBlockInfo{"FillExtrusionDrawablePropsUBO", idFillExtrusionDrawablePropsUBO}, + UniformBlockInfo{"FillExtrusionDrawableTilePropsUBO", idFillExtrusionDrawableTilePropsUBO}, + UniformBlockInfo{"FillExtrusionInterpolateUBO", idFillExtrusionInterpolateUBO}, +}; + +const std::vector + ShaderInfo::uniformBlocks = { + UniformBlockInfo{"FillExtrusionDrawableUBO", idFillExtrusionDrawableUBO}, + UniformBlockInfo{"FillExtrusionDrawablePropsUBO", idFillExtrusionDrawablePropsUBO}, + UniformBlockInfo{"FillExtrusionDrawableTilePropsUBO", idFillExtrusionDrawableTilePropsUBO}, + UniformBlockInfo{"FillExtrusionInterpolateUBO", idFillExtrusionInterpolateUBO}, +}; + +const std::vector ShaderInfo::uniformBlocks = { + UniformBlockInfo{"HeatmapDrawableUBO", idHeatmapDrawableUBO}, + UniformBlockInfo{"HeatmapEvaluatedPropsUBO", idHeatmapEvaluatedPropsUBO}, + UniformBlockInfo{"HeatmapInterpolateUBO", idHeatmapInterpolateUBO}, +}; + +const std::vector + ShaderInfo::uniformBlocks = { + UniformBlockInfo{"HeatmapTextureDrawableUBO", idHeatmapTextureDrawableUBO}, +}; + +const std::vector + ShaderInfo::uniformBlocks = { + UniformBlockInfo{"HillshadePrepareDrawableUBO", idHillshadePrepareDrawableUBO}, +}; + +const std::vector ShaderInfo::uniformBlocks = { + UniformBlockInfo{"HillshadeDrawableUBO", idHillshadeDrawableUBO}, + UniformBlockInfo{"HillshadeEvaluatedPropsUBO", idHillshadeEvaluatedPropsUBO}, +}; + +const std::vector ShaderInfo::uniformBlocks = + { + UniformBlockInfo{"LineDynamicUBO", idLineDynamicUBO}, + UniformBlockInfo{"LineGradientUBO", idLineGradientUBO}, + UniformBlockInfo{"LineGradientPropertiesUBO", idLineGradientPropertiesUBO}, + UniformBlockInfo{"LineGradientInterpolationUBO", idLineGradientInterpolationUBO}, +}; + +const std::vector ShaderInfo::uniformBlocks = + { + UniformBlockInfo{"LineDynamicUBO", idLineDynamicUBO}, + UniformBlockInfo{"LinePatternUBO", idLinePatternUBO}, + UniformBlockInfo{"LinePatternPropertiesUBO", idLinePatternPropertiesUBO}, + UniformBlockInfo{"LinePatternInterpolationUBO", idLinePatternInterpolationUBO}, + UniformBlockInfo{"LinePatternTilePropertiesUBO", idLinePatternTilePropertiesUBO}, +}; + +const std::vector ShaderInfo::uniformBlocks = { + UniformBlockInfo{"LineDynamicUBO", idLineDynamicUBO}, + UniformBlockInfo{"LineSDFUBO", idLineSDFUBO}, + UniformBlockInfo{"LineSDFPropertiesUBO", idLineSDFPropertiesUBO}, + UniformBlockInfo{"LineSDFInterpolationUBO", idLineSDFInterpolationUBO}, +}; + +const std::vector ShaderInfo::uniformBlocks = { + UniformBlockInfo{"LineDynamicUBO", idLineDynamicUBO}, + UniformBlockInfo{"LineUBO", idLineUBO}, + UniformBlockInfo{"LinePropertiesUBO", idLinePropertiesUBO}, + UniformBlockInfo{"LineInterpolationUBO", idLineInterpolationUBO}, +}; + +const std::vector ShaderInfo::uniformBlocks = { + UniformBlockInfo{"LineBasicUBO", idLineBasicUBO}, + UniformBlockInfo{"LineBasicPropertiesUBO", idLineBasicPropertiesUBO}, +}; + +const std::vector ShaderInfo::uniformBlocks = { + UniformBlockInfo{"RasterDrawableUBO", idRasterDrawableUBO}, +}; + +const std::vector ShaderInfo::uniformBlocks = { + UniformBlockInfo{"SymbolDrawableUBO", idSymbolDrawableUBO}, + UniformBlockInfo{"SymbolDynamicUBO", idSymbolDynamicUBO}, + UniformBlockInfo{"SymbolDrawablePaintUBO", idSymbolDrawablePaintUBO}, + UniformBlockInfo{"SymbolDrawableTilePropsUBO", idSymbolDrawableTilePropsUBO}, + UniformBlockInfo{"SymbolDrawableInterpolateUBO", idSymbolDrawableInterpolateUBO}, +}; + +const std::vector + ShaderInfo::uniformBlocks = { + UniformBlockInfo{"SymbolDrawableUBO", idSymbolDrawableUBO}, + UniformBlockInfo{"SymbolDynamicUBO", idSymbolDynamicUBO}, + UniformBlockInfo{"SymbolDrawablePaintUBO", idSymbolDrawablePaintUBO}, + UniformBlockInfo{"SymbolDrawableTilePropsUBO", idSymbolDrawableTilePropsUBO}, + UniformBlockInfo{"SymbolDrawableInterpolateUBO", idSymbolDrawableInterpolateUBO}, +}; + +const std::vector + ShaderInfo::uniformBlocks = { + UniformBlockInfo{"SymbolDrawableUBO", idSymbolDrawableUBO}, + UniformBlockInfo{"SymbolDynamicUBO", idSymbolDynamicUBO}, + UniformBlockInfo{"SymbolDrawablePaintUBO", idSymbolDrawablePaintUBO}, + UniformBlockInfo{"SymbolDrawableTilePropsUBO", idSymbolDrawableTilePropsUBO}, + UniformBlockInfo{"SymbolDrawableInterpolateUBO", idSymbolDrawableInterpolateUBO}, +}; + +} // namespace shaders +} // namespace mbgl diff --git a/src/mbgl/shaders/gl/shader_program_gl.cpp b/src/mbgl/shaders/gl/shader_program_gl.cpp index 9688f1eee..0e3ce2f41 100644 --- a/src/mbgl/shaders/gl/shader_program_gl.cpp +++ b/src/mbgl/shaders/gl/shader_program_gl.cpp @@ -113,13 +113,15 @@ std::optional ShaderProgramGL::getSamplerLocation(const StringIdentity return result; } -std::shared_ptr ShaderProgramGL::create(Context& context, - const ProgramParameters& programParameters, - const std::string& /*name*/, - const std::string_view firstAttribName, - const std::string& vertexSource, - const std::string& fragmentSource, - const std::string& additionalDefines) noexcept(false) { +std::shared_ptr ShaderProgramGL::create( + Context& context, + const ProgramParameters& programParameters, + const std::string& /*name*/, + const std::string_view firstAttribName, + const std::vector& uniformBlocksInfo, + const std::string& vertexSource, + const std::string& fragmentSource, + const std::string& additionalDefines) noexcept(false) { // throws on compile error auto vertProg = context.createShader( ShaderType::Vertex, @@ -149,23 +151,21 @@ std::shared_ptr ShaderProgramGL::create(Context& context, MBGL_CHECK_ERROR(glGetProgramiv(program, GL_ACTIVE_UNIFORM_BLOCKS, &count)); MBGL_CHECK_ERROR(glGetProgramiv(program, GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH, &maxLength)); - auto name = std::vector(maxLength); - for (GLint index = 0; index < count; ++index) { - GLsizei length = 0; + for (const auto& blockInfo : uniformBlocksInfo) { + GLint index = MBGL_CHECK_ERROR(glGetUniformBlockIndex(program, blockInfo.name.data())); GLint size = 0; - GLint binding = index; - MBGL_CHECK_ERROR(glGetActiveUniformBlockName(program, index, maxLength, &length, name.data())); MBGL_CHECK_ERROR(glGetActiveUniformBlockiv(program, index, GL_UNIFORM_BLOCK_DATA_SIZE, &size)); - assert(length > 0 && size > 0); + assert(size > 0); + GLint binding = static_cast(blockInfo.binding); MBGL_CHECK_ERROR(glUniformBlockBinding(program, index, binding)); - uniformBlocks.add(stringIndexer().get(name.data()), index, size); + uniformBlocks.set(blockInfo.id, binding, size); } SamplerLocationMap samplerLocations; GLint numActiveUniforms = 0; MBGL_CHECK_ERROR(glGetProgramiv(program, GL_ACTIVE_UNIFORMS, &numActiveUniforms)); MBGL_CHECK_ERROR(glGetProgramiv(program, GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxLength)); - name.resize(maxLength); + auto name = std::vector(maxLength); for (GLint index = 0; index < numActiveUniforms; ++index) { GLsizei actualLength = 0; GLint size = 0; diff --git a/src/mbgl/shaders/mtl/background.cpp b/src/mbgl/shaders/mtl/background.cpp index a542af6af..e6a9d6e28 100644 --- a/src/mbgl/shaders/mtl/background.cpp +++ b/src/mbgl/shaders/mtl/background.cpp @@ -8,8 +8,8 @@ const std::array ShaderSource ShaderSource::uniforms = { - UniformBlockInfo{1, true, false, sizeof(BackgroundDrawableUBO), "BackgroundDrawableUBO"}, - UniformBlockInfo{2, false, true, sizeof(BackgroundLayerUBO), "BackgroundLayerUBO"}, + UniformBlockInfo{1, true, false, sizeof(BackgroundDrawableUBO), idBackgroundDrawableUBO}, + UniformBlockInfo{2, false, true, sizeof(BackgroundLayerUBO), idBackgroundLayerUBO}, }; const std::array ShaderSource::textures = {}; diff --git a/src/mbgl/shaders/mtl/background_pattern.cpp b/src/mbgl/shaders/mtl/background_pattern.cpp index 44ebf54b7..1cdb89b0d 100644 --- a/src/mbgl/shaders/mtl/background_pattern.cpp +++ b/src/mbgl/shaders/mtl/background_pattern.cpp @@ -10,8 +10,8 @@ const std::array }; const std::array ShaderSource::uniforms = { - UniformBlockInfo{1, true, false, sizeof(BackgroundDrawableUBO), "BackgroundDrawableUBO"}, - UniformBlockInfo{2, true, true, sizeof(BackgroundPatternLayerUBO), "BackgroundLayerUBO"}, + UniformBlockInfo{1, true, false, sizeof(BackgroundDrawableUBO), idBackgroundDrawableUBO}, + UniformBlockInfo{2, true, true, sizeof(BackgroundPatternLayerUBO), idBackgroundLayerUBO}, }; const std::array ShaderSource::textures = { TextureInfo{0, "u_image"}}; diff --git a/src/mbgl/shaders/mtl/circle.cpp b/src/mbgl/shaders/mtl/circle.cpp index 949a05c7b..426447ad5 100644 --- a/src/mbgl/shaders/mtl/circle.cpp +++ b/src/mbgl/shaders/mtl/circle.cpp @@ -14,10 +14,10 @@ const std::array ShaderSource ShaderSource::uniforms = { - UniformBlockInfo{8, true, false, sizeof(CircleDrawableUBO), "CircleDrawableUBO"}, - UniformBlockInfo{9, true, true, sizeof(CirclePaintParamsUBO), "CirclePaintParamsUBO"}, - UniformBlockInfo{10, true, true, sizeof(CircleEvaluatedPropsUBO), "CircleEvaluatedPropsUBO"}, - UniformBlockInfo{11, true, false, sizeof(CircleInterpolateUBO), "CircleInterpolateUBO"}, + UniformBlockInfo{8, true, false, sizeof(CircleDrawableUBO), idCircleDrawableUBO}, + UniformBlockInfo{9, true, true, sizeof(CirclePaintParamsUBO), idCirclePaintParamsUBO}, + UniformBlockInfo{10, true, true, sizeof(CircleEvaluatedPropsUBO), idCircleEvaluatedPropsUBO}, + UniformBlockInfo{11, true, false, sizeof(CircleInterpolateUBO), idCircleInterpolateUBO}, }; const std::array ShaderSource::textures = {}; diff --git a/src/mbgl/shaders/mtl/clipping_mask.cpp b/src/mbgl/shaders/mtl/clipping_mask.cpp index 28585accc..bd2ba6237 100644 --- a/src/mbgl/shaders/mtl/clipping_mask.cpp +++ b/src/mbgl/shaders/mtl/clipping_mask.cpp @@ -9,7 +9,7 @@ const std::array ShaderType::attributes = { AttributeInfo{0, gfx::AttributeDataType::Float3, "a_pos"}, }; const std::array ShaderType::uniforms = { - UniformBlockInfo{1, true, false, sizeof(ClipUBO), "ClipUBO"}, + UniformBlockInfo{1, true, false, sizeof(ClipUBO), 0}, }; const std::array ShaderType::textures = {}; diff --git a/src/mbgl/shaders/mtl/collision_box.cpp b/src/mbgl/shaders/mtl/collision_box.cpp index 205f7fe6e..c712f76b8 100644 --- a/src/mbgl/shaders/mtl/collision_box.cpp +++ b/src/mbgl/shaders/mtl/collision_box.cpp @@ -11,7 +11,7 @@ const std::array ShaderSource ShaderSource::uniforms = { - UniformBlockInfo{5, true, true, sizeof(CollisionUBO), "CollisionBoxUBO"}, + UniformBlockInfo{5, true, true, sizeof(CollisionUBO), idCollisionUBO}, }; const std::array ShaderSource::textures = {}; diff --git a/src/mbgl/shaders/mtl/collision_circle.cpp b/src/mbgl/shaders/mtl/collision_circle.cpp index b0c36b075..2979256b5 100644 --- a/src/mbgl/shaders/mtl/collision_circle.cpp +++ b/src/mbgl/shaders/mtl/collision_circle.cpp @@ -12,7 +12,7 @@ const std::array ShaderSource ShaderSource::uniforms = { - UniformBlockInfo{4, true, true, sizeof(CollisionUBO), "CollisionCircleUBO"}, + UniformBlockInfo{4, true, true, sizeof(CollisionUBO), idCollisionUBO}, }; const std::array ShaderSource::textures = {}; diff --git a/src/mbgl/shaders/mtl/debug.cpp b/src/mbgl/shaders/mtl/debug.cpp index f47f5ff1a..8694c6a21 100644 --- a/src/mbgl/shaders/mtl/debug.cpp +++ b/src/mbgl/shaders/mtl/debug.cpp @@ -7,7 +7,7 @@ const std::array ShaderSource ShaderSource::uniforms = { - UniformBlockInfo{1, true, true, sizeof(DebugUBO), "DebugUBO"}, + UniformBlockInfo{1, true, true, sizeof(DebugUBO), idDebugUBO}, }; const std::array ShaderSource::textures = { TextureInfo{0, "u_overlay"}, diff --git a/src/mbgl/shaders/mtl/fill.cpp b/src/mbgl/shaders/mtl/fill.cpp index 5fcee8114..3b124bbaa 100644 --- a/src/mbgl/shaders/mtl/fill.cpp +++ b/src/mbgl/shaders/mtl/fill.cpp @@ -9,9 +9,9 @@ const std::array ShaderSource ShaderSource::uniforms = { - UniformBlockInfo{3, true, false, sizeof(FillDrawableUBO), "FillDrawableUBO"}, - UniformBlockInfo{4, true, true, sizeof(FillEvaluatedPropsUBO), "FillEvaluatedPropsUBO"}, - UniformBlockInfo{5, true, false, sizeof(FillInterpolateUBO), "FillInterpolateUBO"}, + UniformBlockInfo{3, true, false, sizeof(FillDrawableUBO), idFillDrawableUBO}, + UniformBlockInfo{4, true, true, sizeof(FillEvaluatedPropsUBO), idFillEvaluatedPropsUBO}, + UniformBlockInfo{5, true, false, sizeof(FillInterpolateUBO), idFillInterpolateUBO}, }; const std::array ShaderSource::textures = {}; @@ -21,9 +21,9 @@ const std::array ShaderSource ShaderSource::uniforms = { - UniformBlockInfo{3, true, false, sizeof(FillOutlineDrawableUBO), "FillOutlineDrawableUBO"}, - UniformBlockInfo{4, true, true, sizeof(FillOutlineEvaluatedPropsUBO), "FillOutlineEvaluatedPropsUBO"}, - UniformBlockInfo{5, true, false, sizeof(FillOutlineInterpolateUBO), "FillOutlineInterpolateUBO"}, + UniformBlockInfo{3, true, false, sizeof(FillOutlineDrawableUBO), idFillOutlineDrawableUBO}, + UniformBlockInfo{4, true, true, sizeof(FillOutlineEvaluatedPropsUBO), idFillOutlineEvaluatedPropsUBO}, + UniformBlockInfo{5, true, false, sizeof(FillOutlineInterpolateUBO), idFillOutlineInterpolateUBO}, }; const std::array ShaderSource::textures = {}; @@ -34,10 +34,10 @@ const std::array ShaderSource ShaderSource::uniforms = { - UniformBlockInfo{4, true, true, sizeof(FillPatternDrawableUBO), "FillPatternDrawableUBO"}, - UniformBlockInfo{5, true, true, sizeof(FillPatternTilePropsUBO), "FillPatternTilePropsUBO"}, - UniformBlockInfo{6, true, true, sizeof(FillPatternEvaluatedPropsUBO), "FillPatternEvaluatedPropsUBO"}, - UniformBlockInfo{7, true, false, sizeof(FillPatternInterpolateUBO), "FillPatternInterpolateUBO"}, + UniformBlockInfo{4, true, true, sizeof(FillPatternDrawableUBO), idFillPatternDrawableUBO}, + UniformBlockInfo{5, true, true, sizeof(FillPatternTilePropsUBO), idFillPatternTilePropsUBO}, + UniformBlockInfo{6, true, true, sizeof(FillPatternEvaluatedPropsUBO), idFillPatternEvaluatedPropsUBO}, + UniformBlockInfo{7, true, false, sizeof(FillPatternInterpolateUBO), idFillPatternInterpolateUBO}, }; const std::array ShaderSource::textures = { TextureInfo{0, "u_image"}, @@ -52,10 +52,10 @@ const std::array }; const std::array ShaderSource::uniforms = { - UniformBlockInfo{4, true, true, sizeof(FillOutlinePatternDrawableUBO), "FillOutlinePatternDrawableUBO"}, - UniformBlockInfo{5, true, true, sizeof(FillOutlinePatternTilePropsUBO), "FillOutlinePatternTilePropsUBO"}, - UniformBlockInfo{6, true, true, sizeof(FillOutlinePatternEvaluatedPropsUBO), "FillOutlinePatternEvaluatedPropsUBO"}, - UniformBlockInfo{7, true, false, sizeof(FillOutlinePatternInterpolateUBO), "FillOutlinePatternInterpolateUBO"}, + UniformBlockInfo{4, true, true, sizeof(FillOutlinePatternDrawableUBO), idFillOutlinePatternDrawableUBO}, + UniformBlockInfo{5, true, true, sizeof(FillOutlinePatternTilePropsUBO), idFillOutlinePatternTilePropsUBO}, + UniformBlockInfo{6, true, true, sizeof(FillOutlinePatternEvaluatedPropsUBO), idFillOutlinePatternEvaluatedPropsUBO}, + UniformBlockInfo{7, true, false, sizeof(FillOutlinePatternInterpolateUBO), idFillOutlinePatternInterpolateUBO}, }; const std::array ShaderSource::textures = { diff --git a/src/mbgl/shaders/mtl/fill_extrusion.cpp b/src/mbgl/shaders/mtl/fill_extrusion.cpp index 3b80c261a..b3dc1472e 100644 --- a/src/mbgl/shaders/mtl/fill_extrusion.cpp +++ b/src/mbgl/shaders/mtl/fill_extrusion.cpp @@ -12,9 +12,9 @@ const std::array ShaderSource ShaderSource::uniforms = { - UniformBlockInfo{5, true, false, sizeof(FillExtrusionDrawableUBO), "FillExtrusionDrawableUBO"}, - UniformBlockInfo{6, true, false, sizeof(FillExtrusionDrawablePropsUBO), "FillExtrusionDrawablePropsUBO"}, - UniformBlockInfo{7, true, false, sizeof(FillExtrusionInterpolateUBO), "FillExtrusionInterpolateUBO"}, + UniformBlockInfo{5, true, false, sizeof(FillExtrusionDrawableUBO), idFillExtrusionDrawableUBO}, + UniformBlockInfo{6, true, false, sizeof(FillExtrusionDrawablePropsUBO), idFillExtrusionDrawablePropsUBO}, + UniformBlockInfo{7, true, false, sizeof(FillExtrusionInterpolateUBO), idFillExtrusionInterpolateUBO}, }; const std::array ShaderSource::textures = {}; diff --git a/src/mbgl/shaders/mtl/fill_extrusion_pattern.cpp b/src/mbgl/shaders/mtl/fill_extrusion_pattern.cpp index 6e5a78e28..7f4b301f4 100644 --- a/src/mbgl/shaders/mtl/fill_extrusion_pattern.cpp +++ b/src/mbgl/shaders/mtl/fill_extrusion_pattern.cpp @@ -15,10 +15,10 @@ const std::array }; const std::array ShaderSource::uniforms = { - UniformBlockInfo{6, true, true, sizeof(FillExtrusionDrawableUBO), "FillExtrusionDrawableUBO"}, - UniformBlockInfo{7, true, true, sizeof(FillExtrusionDrawablePropsUBO), "FillExtrusionDrawablePropsUBO"}, - UniformBlockInfo{8, true, true, sizeof(FillExtrusionDrawableTilePropsUBO), "FillExtrusionDrawableTilePropsUBO"}, - UniformBlockInfo{9, true, false, sizeof(FillExtrusionInterpolateUBO), "FillExtrusionInterpolateUBO"}, + UniformBlockInfo{6, true, true, sizeof(FillExtrusionDrawableUBO), idFillExtrusionDrawableUBO}, + UniformBlockInfo{7, true, true, sizeof(FillExtrusionDrawablePropsUBO), idFillExtrusionDrawablePropsUBO}, + UniformBlockInfo{8, true, true, sizeof(FillExtrusionDrawableTilePropsUBO), idFillExtrusionDrawableTilePropsUBO}, + UniformBlockInfo{9, true, false, sizeof(FillExtrusionInterpolateUBO), idFillExtrusionInterpolateUBO}, }; const std::array ShaderSource::textures = { diff --git a/src/mbgl/shaders/mtl/heatmap.cpp b/src/mbgl/shaders/mtl/heatmap.cpp index 23f179b5c..9f3d05853 100644 --- a/src/mbgl/shaders/mtl/heatmap.cpp +++ b/src/mbgl/shaders/mtl/heatmap.cpp @@ -9,9 +9,9 @@ const std::array ShaderSource ShaderSource::uniforms = { - UniformBlockInfo{3, true, false, sizeof(HeatmapDrawableUBO), "HeatmapDrawableUBO"}, - UniformBlockInfo{4, true, true, sizeof(HeatmapEvaluatedPropsUBO), "HeatmapEvaluatedPropsUBO"}, - UniformBlockInfo{5, true, false, sizeof(HeatmapInterpolateUBO), "HeatmapInterpolateUBO"}, + UniformBlockInfo{3, true, false, sizeof(HeatmapDrawableUBO), idHeatmapDrawableUBO}, + UniformBlockInfo{4, true, true, sizeof(HeatmapEvaluatedPropsUBO), idHeatmapEvaluatedPropsUBO}, + UniformBlockInfo{5, true, false, sizeof(HeatmapInterpolateUBO), idHeatmapInterpolateUBO}, }; const std::array ShaderSource::textures = {}; diff --git a/src/mbgl/shaders/mtl/heatmap_texture.cpp b/src/mbgl/shaders/mtl/heatmap_texture.cpp index 689ba08fe..40a8e99cb 100644 --- a/src/mbgl/shaders/mtl/heatmap_texture.cpp +++ b/src/mbgl/shaders/mtl/heatmap_texture.cpp @@ -9,7 +9,7 @@ const std::array ShaderSource ShaderSource::uniforms = { - UniformBlockInfo{1, true, true, sizeof(HeatmapTextureDrawableUBO), "HeatmapTextureDrawableUBO"}, + UniformBlockInfo{1, true, true, sizeof(HeatmapTextureDrawableUBO), idHeatmapTextureDrawableUBO}, }; const std::array ShaderSource::textures = { TextureInfo{0, "u_image"}, diff --git a/src/mbgl/shaders/mtl/hillshade.cpp b/src/mbgl/shaders/mtl/hillshade.cpp index 88713ea10..c4d9b1c7a 100644 --- a/src/mbgl/shaders/mtl/hillshade.cpp +++ b/src/mbgl/shaders/mtl/hillshade.cpp @@ -8,8 +8,8 @@ const std::array ShaderSource ShaderSource::uniforms = { - UniformBlockInfo{2, true, true, sizeof(HillshadeDrawableUBO), "HillshadeDrawableUBO"}, - UniformBlockInfo{3, false, true, sizeof(HillshadeEvaluatedPropsUBO), "HillshadeEvaluatedPropsUBO"}, + UniformBlockInfo{2, true, true, sizeof(HillshadeDrawableUBO), idHillshadeDrawableUBO}, + UniformBlockInfo{3, false, true, sizeof(HillshadeEvaluatedPropsUBO), idHillshadeEvaluatedPropsUBO}, }; const std::array ShaderSource::textures = { TextureInfo{0, "u_image"}, diff --git a/src/mbgl/shaders/mtl/hillshade_prepare.cpp b/src/mbgl/shaders/mtl/hillshade_prepare.cpp index d4b6cb301..717552aa2 100644 --- a/src/mbgl/shaders/mtl/hillshade_prepare.cpp +++ b/src/mbgl/shaders/mtl/hillshade_prepare.cpp @@ -10,7 +10,7 @@ const std::array }; const std::array ShaderSource::uniforms = { - UniformBlockInfo{2, true, true, sizeof(HillshadePrepareDrawableUBO), "HillshadePrepareDrawableUBO"}, + UniformBlockInfo{2, true, true, sizeof(HillshadePrepareDrawableUBO), idHillshadePrepareDrawableUBO}, }; const std::array ShaderSource::textures = { TextureInfo{0, "u_image"}, diff --git a/src/mbgl/shaders/mtl/line.cpp b/src/mbgl/shaders/mtl/line.cpp index f99d466fc..805007aee 100644 --- a/src/mbgl/shaders/mtl/line.cpp +++ b/src/mbgl/shaders/mtl/line.cpp @@ -14,10 +14,10 @@ const std::array ShaderSource ShaderSource::uniforms = { - UniformBlockInfo{8, true, false, sizeof(LineDynamicUBO), "LineDynamicUBO"}, - UniformBlockInfo{9, true, true, sizeof(LineUBO), "LineUBO"}, - UniformBlockInfo{10, true, true, sizeof(LinePropertiesUBO), "LinePropertiesUBO"}, - UniformBlockInfo{11, true, false, sizeof(LineInterpolationUBO), "LineInterpolationUBO"}, + UniformBlockInfo{8, true, false, sizeof(LineDynamicUBO), idLineDynamicUBO}, + UniformBlockInfo{9, true, true, sizeof(LineUBO), idLineUBO}, + UniformBlockInfo{10, true, true, sizeof(LinePropertiesUBO), idLinePropertiesUBO}, + UniformBlockInfo{11, true, false, sizeof(LineInterpolationUBO), idLineInterpolationUBO}, }; const std::array ShaderSource::textures = {}; @@ -33,11 +33,11 @@ const std::array ShaderSource ShaderSource::uniforms = { - UniformBlockInfo{9, true, false, sizeof(LineDynamicUBO), "LineDynamicUBO"}, - UniformBlockInfo{10, true, true, sizeof(LinePatternUBO), "LinePatternUBO"}, - UniformBlockInfo{11, true, true, sizeof(LinePatternPropertiesUBO), "LinePatternPropertiesUBO"}, - UniformBlockInfo{12, true, false, sizeof(LinePatternInterpolationUBO), "LinePatternInterpolationUBO"}, - UniformBlockInfo{13, true, true, sizeof(LinePatternTilePropertiesUBO), "LinePatternTilePropertiesUBO"}, + UniformBlockInfo{9, true, false, sizeof(LineDynamicUBO), idLinePatternDynamicUBO}, + UniformBlockInfo{10, true, true, sizeof(LinePatternUBO), idLinePatternUBO}, + UniformBlockInfo{11, true, true, sizeof(LinePatternPropertiesUBO), idLinePatternPropertiesUBO}, + UniformBlockInfo{12, true, false, sizeof(LinePatternInterpolationUBO), idLinePatternInterpolationUBO}, + UniformBlockInfo{13, true, true, sizeof(LinePatternTilePropertiesUBO), idLinePatternTilePropertiesUBO}, }; const std::array ShaderSource::textures = { TextureInfo{0, "u_image"}, @@ -55,10 +55,10 @@ const std::array ShaderSource ShaderSource::uniforms = { - UniformBlockInfo{9, true, false, sizeof(LineDynamicUBO), "LineDynamicUBO"}, - UniformBlockInfo{10, true, true, sizeof(LineSDFUBO), "LineSDFUBO"}, - UniformBlockInfo{11, true, true, sizeof(LineSDFPropertiesUBO), "LineSDFPropertiesUBO"}, - UniformBlockInfo{12, true, false, sizeof(LineSDFInterpolationUBO), "LineSDFInterpolationUBO"}, + UniformBlockInfo{9, true, false, sizeof(LineDynamicUBO), idLineSDFDynamicUBO}, + UniformBlockInfo{10, true, true, sizeof(LineSDFUBO), idLineSDFUBO}, + UniformBlockInfo{11, true, true, sizeof(LineSDFPropertiesUBO), idLineSDFPropertiesUBO}, + UniformBlockInfo{12, true, false, sizeof(LineSDFInterpolationUBO), idLineSDFInterpolationUBO}, }; const std::array ShaderSource::textures = { TextureInfo{0, "u_image"}, @@ -69,8 +69,8 @@ const std::array ShaderSource ShaderSource::uniforms = { - UniformBlockInfo{2, true, true, sizeof(LineBasicUBO), "LineBasicUBO"}, - UniformBlockInfo{3, true, true, sizeof(LineBasicPropertiesUBO), "LineBasicPropertiesUBO"}, + UniformBlockInfo{2, true, true, sizeof(LineBasicUBO), idLineBasicUBO}, + UniformBlockInfo{3, true, true, sizeof(LineBasicPropertiesUBO), idLineBasicPropertiesUBO}, }; const std::array ShaderSource::textures = {}; diff --git a/src/mbgl/shaders/mtl/line_gradient.cpp b/src/mbgl/shaders/mtl/line_gradient.cpp index e981fe157..131a6a1a5 100644 --- a/src/mbgl/shaders/mtl/line_gradient.cpp +++ b/src/mbgl/shaders/mtl/line_gradient.cpp @@ -13,10 +13,10 @@ const std::array ShaderSource ShaderSource::uniforms = { - UniformBlockInfo{7, true, false, sizeof(LineDynamicUBO), "LineDynamicUBO"}, - UniformBlockInfo{8, true, true, sizeof(LineGradientUBO), "LineGradientUBO"}, - UniformBlockInfo{9, true, true, sizeof(LineGradientPropertiesUBO), "LineGradientPropertiesUBO"}, - UniformBlockInfo{10, true, false, sizeof(LineGradientInterpolationUBO), "LineGradientInterpolationUBO"}, + UniformBlockInfo{7, true, false, sizeof(LineDynamicUBO), idLineGradientDynamicUBO}, + UniformBlockInfo{8, true, true, sizeof(LineGradientUBO), idLineGradientUBO}, + UniformBlockInfo{9, true, true, sizeof(LineGradientPropertiesUBO), idLineGradientPropertiesUBO}, + UniformBlockInfo{10, true, false, sizeof(LineGradientInterpolationUBO), idLineGradientInterpolationUBO}, }; const std::array ShaderSource::textures = { TextureInfo{0, "u_image"}, diff --git a/src/mbgl/shaders/mtl/raster.cpp b/src/mbgl/shaders/mtl/raster.cpp index 0b74b2195..cd0a21dd2 100644 --- a/src/mbgl/shaders/mtl/raster.cpp +++ b/src/mbgl/shaders/mtl/raster.cpp @@ -8,7 +8,7 @@ const std::array ShaderSource ShaderSource::uniforms = { - UniformBlockInfo{2, true, true, sizeof(RasterDrawableUBO), "RasterDrawableUBO"}, + UniformBlockInfo{2, true, true, sizeof(RasterDrawableUBO), idRasterDrawableUBO}, }; const std::array ShaderSource::textures = { TextureInfo{0, "u_image0"}, diff --git a/src/mbgl/shaders/mtl/shader_program.cpp b/src/mbgl/shaders/mtl/shader_program.cpp index bcb7df204..c75ef817e 100644 --- a/src/mbgl/shaders/mtl/shader_program.cpp +++ b/src/mbgl/shaders/mtl/shader_program.cpp @@ -31,13 +31,12 @@ shaders::AttributeInfo::AttributeInfo(std::size_t index_, gfx::AttributeDataType nameID(stringIndexer().get(name_)) {} shaders::UniformBlockInfo::UniformBlockInfo( - std::size_t index_, bool vertex_, bool fragment_, std::size_t size_, std::string_view name_) + std::size_t index_, bool vertex_, bool fragment_, std::size_t size_, std::size_t id_) : index(index_), vertex(vertex_), fragment(fragment_), size(size_), - name(name_), - nameID(stringIndexer().get(name_)) {} + id(id_) {} shaders::TextureInfo::TextureInfo(std::size_t index_, std::string_view name_) : index(index_), @@ -202,7 +201,7 @@ void ShaderProgram::initAttribute(const shaders::AttributeInfo& info) { // Indexes must be unique, if there's a conflict check the `attributes` array in the shader vertexAttributes.visitAttributes( [&](auto, const gfx::VertexAttribute& attrib) { assert(attrib.getIndex() != index); }); - uniformBlocks.visit([&](auto, const gfx::UniformBlock& block) { assert(block.getIndex() != index); }); + uniformBlocks.visit([&](const gfx::UniformBlock& block) { assert(block.getIndex() != index); }); #endif vertexAttributes.add(stringIndexer().get(info.name), index, info.dataType, 1); } @@ -213,9 +212,9 @@ void ShaderProgram::initUniformBlock(const shaders::UniformBlockInfo& info) { // Indexes must be unique, if there's a conflict check the `attributes` array in the shader vertexAttributes.visitAttributes( [&](auto, const gfx::VertexAttribute& attrib) { assert(attrib.getIndex() != index); }); - uniformBlocks.visit([&](auto, const gfx::UniformBlock& block) { assert(block.getIndex() != index); }); + uniformBlocks.visit([&](const gfx::UniformBlock& block) { assert(block.getIndex() != index); }); #endif - if (const auto& block_ = uniformBlocks.add(stringIndexer().get(info.name), index, info.size)) { + if (const auto& block_ = uniformBlocks.set(info.id, index, info.size)) { auto& block = static_cast(*block_); block.setBindVertex(info.vertex); block.setBindFragment(info.fragment); diff --git a/src/mbgl/shaders/mtl/symbol_icon.cpp b/src/mbgl/shaders/mtl/symbol_icon.cpp index e1b776556..cfb82bb83 100644 --- a/src/mbgl/shaders/mtl/symbol_icon.cpp +++ b/src/mbgl/shaders/mtl/symbol_icon.cpp @@ -15,11 +15,11 @@ const std::array ShaderSource ShaderSource::uniforms = { - UniformBlockInfo{8, true, true, sizeof(SymbolDrawableUBO), "SymbolDrawableUBO"}, - UniformBlockInfo{9, true, false, sizeof(SymbolDynamicUBO), "SymbolDynamicUBO"}, - UniformBlockInfo{10, true, true, sizeof(SymbolDrawablePaintUBO), "SymbolDrawablePaintUBO"}, - UniformBlockInfo{11, true, false, sizeof(SymbolDrawableTilePropsUBO), "SymbolDrawableTilePropsUBO"}, - UniformBlockInfo{12, true, false, sizeof(SymbolDrawableInterpolateUBO), "SymbolDrawableInterpolateUBO"}, + UniformBlockInfo{6, true, true, sizeof(SymbolDrawableUBO), idSymbolDrawableUBO}, + UniformBlockInfo{7, true, false, sizeof(SymbolDynamicUBO), idSymbolDynamicUBO}, + UniformBlockInfo{8, true, true, sizeof(SymbolDrawablePaintUBO), idSymbolDrawablePaintUBO}, + UniformBlockInfo{9, true, false, sizeof(SymbolDrawableTilePropsUBO), idSymbolDrawableTilePropsUBO}, + UniformBlockInfo{10, true, false, sizeof(SymbolDrawableInterpolateUBO), idSymbolDrawableInterpolateUBO}, }; const std::array ShaderSource::textures = { TextureInfo{0, "u_texture"}, diff --git a/src/mbgl/shaders/mtl/symbol_sdf.cpp b/src/mbgl/shaders/mtl/symbol_sdf.cpp index 74998b262..074d706e4 100644 --- a/src/mbgl/shaders/mtl/symbol_sdf.cpp +++ b/src/mbgl/shaders/mtl/symbol_sdf.cpp @@ -21,11 +21,11 @@ const std::array ShaderSource ShaderSource::uniforms = { - UniformBlockInfo{10, true, true, sizeof(SymbolDrawableUBO), "SymbolDrawableUBO"}, - UniformBlockInfo{11, true, true, sizeof(SymbolDynamicUBO), "SymbolDynamicUBO"}, - UniformBlockInfo{12, true, true, sizeof(SymbolDrawablePaintUBO), "SymbolDrawablePaintUBO"}, - UniformBlockInfo{13, true, true, sizeof(SymbolDrawableTilePropsUBO), "SymbolDrawableTilePropsUBO"}, - UniformBlockInfo{14, true, false, sizeof(SymbolDrawableInterpolateUBO), "SymbolDrawableInterpolateUBO"}, + UniformBlockInfo{10, true, true, sizeof(SymbolDrawableUBO), idSymbolDrawableUBO}, + UniformBlockInfo{11, true, true, sizeof(SymbolDynamicUBO), idSymbolDynamicUBO}, + UniformBlockInfo{12, true, true, sizeof(SymbolDrawablePaintUBO), idSymbolDrawablePaintUBO}, + UniformBlockInfo{13, true, true, sizeof(SymbolDrawableTilePropsUBO), idSymbolDrawableTilePropsUBO}, + UniformBlockInfo{14, true, false, sizeof(SymbolDrawableInterpolateUBO), idSymbolDrawableInterpolateUBO}, }; const std::array ShaderSource::textures = { TextureInfo{0, "u_texture"}, diff --git a/src/mbgl/shaders/mtl/symbol_text_and_icon.cpp b/src/mbgl/shaders/mtl/symbol_text_and_icon.cpp index 9c6ebdeb2..afcd477ef 100644 --- a/src/mbgl/shaders/mtl/symbol_text_and_icon.cpp +++ b/src/mbgl/shaders/mtl/symbol_text_and_icon.cpp @@ -20,11 +20,11 @@ const std::array }; const std::array ShaderSource::uniforms = { - UniformBlockInfo{9, true, true, sizeof(SymbolDrawableUBO), "SymbolDrawableUBO"}, - UniformBlockInfo{10, true, true, sizeof(SymbolDynamicUBO), "SymbolDynamicUBO"}, - UniformBlockInfo{11, true, true, sizeof(SymbolDrawablePaintUBO), "SymbolDrawablePaintUBO"}, - UniformBlockInfo{12, true, true, sizeof(SymbolDrawableTilePropsUBO), "SymbolDrawableTilePropsUBO"}, - UniformBlockInfo{13, true, false, sizeof(SymbolDrawableInterpolateUBO), "SymbolDrawableInterpolateUBO"}, + UniformBlockInfo{9, true, true, sizeof(SymbolDrawableUBO), idSymbolDrawableUBO}, + UniformBlockInfo{10, true, true, sizeof(SymbolDynamicUBO), idSymbolDynamicUBO}, + UniformBlockInfo{11, true, true, sizeof(SymbolDrawablePaintUBO), idSymbolDrawablePaintUBO}, + UniformBlockInfo{12, true, true, sizeof(SymbolDrawableTilePropsUBO), idSymbolDrawableTilePropsUBO}, + UniformBlockInfo{13, true, false, sizeof(SymbolDrawableInterpolateUBO), idSymbolDrawableInterpolateUBO}, }; const std::array ShaderSource::textures = { TextureInfo{0, "u_texture"}, diff --git a/src/mbgl/style/layers/custom_drawable_layer.cpp b/src/mbgl/style/layers/custom_drawable_layer.cpp index 0b48648ba..d7ee3b3e2 100644 --- a/src/mbgl/style/layers/custom_drawable_layer.cpp +++ b/src/mbgl/style/layers/custom_drawable_layer.cpp @@ -27,6 +27,8 @@ namespace mbgl { namespace style { +using namespace shaders; + namespace { const LayerTypeInfo typeInfoCustomDrawable{"custom-drawable", LayerTypeInfo::Source::NotRequired, @@ -97,20 +99,15 @@ public: const auto matrix = LayerTweaker::getTileMatrix( tileID, parameters, {{0, 0}}, style::TranslateAnchorType::Viewport, false, false, drawable, false); - static const StringIdentity idLineDynamicUBOName = stringIndexer().get("LineDynamicUBO"); const shaders::LineDynamicUBO dynamicUBO = { /*units_to_pixels = */ {1.0f / parameters.pixelsToGLUnits[0], 1.0f / parameters.pixelsToGLUnits[1]}, 0, 0}; - static const StringIdentity idLineUBOName = stringIndexer().get("LineUBO"); const shaders::LineUBO lineUBO{/*matrix = */ util::cast(matrix), /*ratio = */ 1.0f / tileID.pixelsToTileUnits(1.0f, zoom), 0, 0, 0}; - static const StringIdentity idLinePropertiesUBOName = stringIndexer().get("LinePropertiesUBO"); - - static const StringIdentity idLineInterpolationUBOName = stringIndexer().get("LineInterpolationUBO"); const shaders::LineInterpolationUBO lineInterpolationUBO{/*color_t =*/0.f, /*blur_t =*/0.f, /*opacity_t =*/0.f, @@ -120,10 +117,10 @@ public: 0, 0}; auto& uniforms = drawable.mutableUniformBuffers(); - uniforms.createOrUpdate(idLineDynamicUBOName, &dynamicUBO, parameters.context); - uniforms.createOrUpdate(idLineUBOName, &lineUBO, parameters.context); - uniforms.createOrUpdate(idLinePropertiesUBOName, &linePropertiesUBO, parameters.context); - uniforms.createOrUpdate(idLineInterpolationUBOName, &lineInterpolationUBO, parameters.context); + uniforms.createOrUpdate(idLineDynamicUBO, &dynamicUBO, parameters.context); + uniforms.createOrUpdate(idLineUBO, &lineUBO, parameters.context); + uniforms.createOrUpdate(idLinePropertiesUBO, &linePropertiesUBO, parameters.context); + uniforms.createOrUpdate(idLineInterpolationUBO, &lineInterpolationUBO, parameters.context); }; private: @@ -151,10 +148,8 @@ public: const auto matrix = LayerTweaker::getTileMatrix( tileID, parameters, {{0, 0}}, style::TranslateAnchorType::Viewport, false, false, drawable, false); - static const StringIdentity idFillDrawableUBOName = stringIndexer().get("FillDrawableUBO"); const shaders::FillDrawableUBO fillUBO{/*matrix = */ util::cast(matrix)}; - static const StringIdentity idFillEvaluatedPropsUBOName = stringIndexer().get("FillEvaluatedPropsUBO"); const shaders::FillEvaluatedPropsUBO fillPropertiesUBO{ /* .color = */ color, /* .opacity = */ opacity, @@ -163,7 +158,6 @@ public: 0, }; - static const StringIdentity idFillInterpolateUBOName = stringIndexer().get("FillInterpolateUBO"); const shaders::FillInterpolateUBO fillInterpolateUBO{ /* .color_t = */ 0.f, /* .opacity_t = */ 0.f, @@ -171,9 +165,9 @@ public: 0, }; auto& uniforms = drawable.mutableUniformBuffers(); - uniforms.createOrUpdate(idFillDrawableUBOName, &fillUBO, parameters.context); - uniforms.createOrUpdate(idFillEvaluatedPropsUBOName, &fillPropertiesUBO, parameters.context); - uniforms.createOrUpdate(idFillInterpolateUBOName, &fillInterpolateUBO, parameters.context); + uniforms.createOrUpdate(idFillDrawableUBO, &fillUBO, parameters.context); + uniforms.createOrUpdate(idFillEvaluatedPropsUBO, &fillPropertiesUBO, parameters.context); + uniforms.createOrUpdate(idFillInterpolateUBO, &fillInterpolateUBO, parameters.context); }; private: