From 0a814689396f1ad3d6cf5964ff93c63dd153dc91 Mon Sep 17 00:00:00 2001 From: Bart Louwers Date: Wed, 4 Oct 2023 12:47:17 +0000 Subject: [PATCH] Make StringIndexer not a singleton --- include/mbgl/gfx/vertex_attribute.hpp | 2 +- include/mbgl/util/string_indexer.hpp | 36 ++++++-------- src/mbgl/gfx/drawable_builder.cpp | 2 +- src/mbgl/gl/drawable_gl.cpp | 2 +- src/mbgl/gl/drawable_gl_impl.hpp | 2 +- src/mbgl/gl/upload_pass.cpp | 2 +- src/mbgl/mtl/drawable.cpp | 4 +- src/mbgl/mtl/drawable_impl.hpp | 2 +- .../layers/background_layer_tweaker.cpp | 6 +-- .../renderer/layers/circle_layer_tweaker.cpp | 10 ++-- .../layers/collision_layer_tweaker.cpp | 4 +- .../layers/fill_extrusion_layer_tweaker.cpp | 14 +++--- .../renderer/layers/fill_layer_tweaker.cpp | 47 +++++++++--------- .../renderer/layers/heatmap_layer_tweaker.cpp | 8 ++-- .../layers/heatmap_texture_layer_tweaker.cpp | 2 +- .../layers/hillshade_layer_tweaker.cpp | 4 +- .../hillshade_prepare_layer_tweaker.cpp | 2 +- .../renderer/layers/line_layer_tweaker.cpp | 22 ++++----- .../renderer/layers/raster_layer_tweaker.cpp | 2 +- .../renderer/layers/render_circle_layer.cpp | 4 +- .../layers/render_fill_extrusion_layer.cpp | 6 +-- .../renderer/layers/render_fill_layer.cpp | 14 +++--- .../renderer/layers/render_heatmap_layer.cpp | 8 ++-- .../layers/render_hillshade_layer.cpp | 6 +-- .../renderer/layers/render_line_layer.cpp | 16 +++---- .../renderer/layers/render_raster_layer.cpp | 8 ++-- .../renderer/layers/render_symbol_layer.cpp | 30 ++++++------ .../renderer/layers/symbol_layer_tweaker.cpp | 18 +++---- .../renderer/sources/render_tile_source.cpp | 6 +-- src/mbgl/shaders/gl/shader_program_gl.cpp | 6 +-- src/mbgl/shaders/mtl/shader_program.cpp | 6 +-- src/mbgl/util/string_indexer.cpp | 33 ++++++------- test/util/string_indexer.test.cpp | 48 +++++++++---------- 33 files changed, 186 insertions(+), 196 deletions(-) diff --git a/include/mbgl/gfx/vertex_attribute.hpp b/include/mbgl/gfx/vertex_attribute.hpp index df7b9f334..df19b976f 100644 --- a/include/mbgl/gfx/vertex_attribute.hpp +++ b/include/mbgl/gfx/vertex_attribute.hpp @@ -384,7 +384,7 @@ public: auto& attributeNameID = DataDrivenPaintProperty::AttributeNameIDs[attrIndex]; if (!attributeNameID) { static const std::string attributePrefix = "a_"; - attributeNameID = StringIndexer::get(attributePrefix + attributeName.data()); + attributeNameID = stringIndexer().get(attributePrefix + attributeName.data()); } if (auto& attr = getOrAdd(*attributeNameID)) { diff --git a/include/mbgl/util/string_indexer.hpp b/include/mbgl/util/string_indexer.hpp index 8cd5afbd3..1067a32b0 100644 --- a/include/mbgl/util/string_indexer.hpp +++ b/include/mbgl/util/string_indexer.hpp @@ -15,36 +15,30 @@ using StringIdentity = size_t; class StringIndexer { public: + StringIndexer(); + StringIndexer(StringIndexer const&) = delete; StringIndexer(StringIndexer&&) = delete; void operator=(StringIndexer const&) = delete; - - static StringIdentity get(std::string_view); - - static std::string get(const StringIdentity id); - - static void clear(); - - static size_t size(); - -protected: - StringIndexer(); ~StringIndexer() = default; - using MapType = std::unordered_map; - using VectorType = std::vector; - using BufferType = std::vector; + StringIdentity get(std::string_view); - static StringIndexer& instance() { - static StringIndexer inst; - return inst; - } + std::string get(const StringIdentity id); - MapType stringToIdentity; - VectorType identityToString; - BufferType buffer; + void clear(); + + size_t size(); + +protected: + std::unordered_map stringToIdentity; + std::vector identityToString; + std::vector buffer; std::shared_mutex sharedMutex; }; +/// StringIndexer singleton +StringIndexer& stringIndexer(); + } // namespace mbgl diff --git a/src/mbgl/gfx/drawable_builder.cpp b/src/mbgl/gfx/drawable_builder.cpp index 22d34acb5..08a1c7c78 100644 --- a/src/mbgl/gfx/drawable_builder.cpp +++ b/src/mbgl/gfx/drawable_builder.cpp @@ -12,7 +12,7 @@ namespace gfx { DrawableBuilder::DrawableBuilder(std::string name_) : name(std::move(name_)), - vertexAttrNameId(StringIndexer::get("a_pos")), + vertexAttrNameId(stringIndexer().get("a_pos")), renderPass(mbgl::RenderPass::Opaque), impl(std::make_unique()) {} diff --git a/src/mbgl/gl/drawable_gl.cpp b/src/mbgl/gl/drawable_gl.cpp index f994f599b..e93dc3eb5 100644 --- a/src/mbgl/gl/drawable_gl.cpp +++ b/src/mbgl/gl/drawable_gl.cpp @@ -124,7 +124,7 @@ void DrawableGL::bindUniformBuffers() const { using namespace std::string_literals; const auto currTileID = getTileID() ? util::toString(*getTileID()) : ""; Log::Error(Event::General, - "bindUniformBuffers: UBO "s + std::string(StringIndexer::get(element.first)) + + "bindUniformBuffers: UBO "s + std::string(stringIndexer().get(element.first)) + " not found for " + util::toString(getID()) + " / " + getName() + " / " + currTileID + ". skipping."); assert(false); diff --git a/src/mbgl/gl/drawable_gl_impl.hpp b/src/mbgl/gl/drawable_gl_impl.hpp index 7cab156fc..5d4c4e21d 100644 --- a/src/mbgl/gl/drawable_gl_impl.hpp +++ b/src/mbgl/gl/drawable_gl_impl.hpp @@ -51,7 +51,7 @@ public: gfx::CullFaceMode cullFaceMode; GLfloat pointSize = 0.0f; - StringIdentity idVertexAttrName = StringIndexer::get("a_pos"); + StringIdentity idVertexAttrName = stringIndexer().get("a_pos"); }; struct DrawableGL::DrawSegmentGL final : public gfx::Drawable::DrawSegment { diff --git a/src/mbgl/gl/upload_pass.cpp b/src/mbgl/gl/upload_pass.cpp index ce08a36b2..2d1c1ba90 100644 --- a/src/mbgl/gl/upload_pass.cpp +++ b/src/mbgl/gl/upload_pass.cpp @@ -260,7 +260,7 @@ gfx::AttributeBindingArray UploadPass::buildAttributeBindings( // something else, the binding is invalid // TODO: throw? Log::Warning(Event::General, - "Got " + util::toString(rawData.size()) + " bytes for attribute '" + StringIndexer::get(id) + + "Got " + util::toString(rawData.size()) + " bytes for attribute '" + stringIndexer().get(id) + "' (" + util::toString(defaultGL.getIndex()) + "), expected " + util::toString(stride) + " or " + util::toString(stride * vertexCount)); return; diff --git a/src/mbgl/mtl/drawable.cpp b/src/mbgl/mtl/drawable.cpp index 89e36092b..e4d5aaf67 100644 --- a/src/mbgl/mtl/drawable.cpp +++ b/src/mbgl/mtl/drawable.cpp @@ -311,7 +311,7 @@ void Drawable::setVertices(std::vector&& data, std::size_t count, gfx:: using namespace std::string_literals; Log::Warning( Event::General, - "Vertex attribute type mismatch: "s + name + " / " + StringIndexer::get(impl->idVertexAttrName)); + "Vertex attribute type mismatch: "s + name + " / " + stringIndexer().get(impl->idVertexAttrName)); assert(false); } } @@ -380,7 +380,7 @@ void Drawable::bindUniformBuffers(const RenderPass& renderPass) const { const auto tileID = getTileID() ? util::toString(*getTileID()) : ""; const auto tileLabel = util::toString(getID()) + "/" + getName() + "/" + tileID; Log::Error(Event::General, - "bindUniformBuffers: UBO "s + StringIndexer::get(element.first) + " not found on " + + "bindUniformBuffers: UBO "s + stringIndexer().get(element.first) + " not found on " + tileLabel + ". skipping."); assert(false); continue; diff --git a/src/mbgl/mtl/drawable_impl.hpp b/src/mbgl/mtl/drawable_impl.hpp index ef386fe44..b54d990d2 100644 --- a/src/mbgl/mtl/drawable_impl.hpp +++ b/src/mbgl/mtl/drawable_impl.hpp @@ -52,7 +52,7 @@ public: gfx::StencilMode stencilMode; gfx::CullFaceMode cullFaceMode; // GLfloat pointSize = 0.0f; - StringIdentity idVertexAttrName = StringIndexer::get("a_pos"); + StringIdentity idVertexAttrName = stringIndexer().get("a_pos"); gfx::UniqueVertexBufferResource noBindingBuffer; }; diff --git a/src/mbgl/renderer/layers/background_layer_tweaker.cpp b/src/mbgl/renderer/layers/background_layer_tweaker.cpp index d4ee0b033..5b063d8e7 100644 --- a/src/mbgl/renderer/layers/background_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/background_layer_tweaker.cpp @@ -19,9 +19,9 @@ 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"); +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 RenderTree&, const PaintParameters& parameters) { const auto& state = parameters.state; diff --git a/src/mbgl/renderer/layers/circle_layer_tweaker.cpp b/src/mbgl/renderer/layers/circle_layer_tweaker.cpp index f328743b5..2f6a0a2b8 100644 --- a/src/mbgl/renderer/layers/circle_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/circle_layer_tweaker.cpp @@ -22,12 +22,12 @@ 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"); +static const StringIdentity idCircleDrawableUBOName = stringIndexer().get("CircleDrawableUBO"); +static const StringIdentity idCirclePaintParamsUBOName = stringIndexer().get("CirclePaintParamsUBO"); +static const StringIdentity idCircleEvaluatedPropsUBOName = stringIndexer().get("CircleEvaluatedPropsUBO"); -static const StringIdentity idExpressionInputsUBOName = StringIndexer::get("ExpressionInputsUBO"); -static const StringIdentity idCirclePermutationUBOName = StringIndexer::get("CirclePermutationUBO"); +static const StringIdentity idExpressionInputsUBOName = stringIndexer().get("ExpressionInputsUBO"); +static const StringIdentity idCirclePermutationUBOName = stringIndexer().get("CirclePermutationUBO"); void CircleLayerTweaker::execute(LayerGroupBase& layerGroup, const RenderTree& renderTree, diff --git a/src/mbgl/renderer/layers/collision_layer_tweaker.cpp b/src/mbgl/renderer/layers/collision_layer_tweaker.cpp index 508f16888..006424ead 100644 --- a/src/mbgl/renderer/layers/collision_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/collision_layer_tweaker.cpp @@ -31,8 +31,8 @@ static_assert(sizeof(CollisionUBO) == 20 * 4); } // namespace -const StringIdentity CollisionLayerTweaker::idCollisionCircleUBOName = StringIndexer::get(CollisionCircleUBOName); -const StringIdentity CollisionLayerTweaker::idCollisionBoxUBOName = StringIndexer::get(CollisionBoxUBOName); +const StringIdentity CollisionLayerTweaker::idCollisionCircleUBOName = stringIndexer().get(CollisionCircleUBOName); +const StringIdentity CollisionLayerTweaker::idCollisionBoxUBOName = stringIndexer().get(CollisionBoxUBOName); void CollisionLayerTweaker::execute(LayerGroupBase& layerGroup, const RenderTree& renderTree, diff --git a/src/mbgl/renderer/layers/fill_extrusion_layer_tweaker.cpp b/src/mbgl/renderer/layers/fill_extrusion_layer_tweaker.cpp index f5add4533..6678b784d 100644 --- a/src/mbgl/renderer/layers/fill_extrusion_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/fill_extrusion_layer_tweaker.cpp @@ -22,17 +22,17 @@ using namespace shaders; using namespace style; namespace { -const StringIdentity idFillExtrusionDrawableUBOName = StringIndexer::get("FillExtrusionDrawableUBO"); -const StringIdentity idFillExtrusionDrawablePropsUBOName = StringIndexer::get("FillExtrusionDrawablePropsUBO"); -const StringIdentity idExpressionInputsUBOName = StringIndexer::get("ExpressionInputsUBO"); -const StringIdentity idFillExtrusionPermutationUBOName = StringIndexer::get("FillExtrusionPermutationUBO"); -const StringIdentity idTexImageName = StringIndexer::get("u_image"); +const StringIdentity idFillExtrusionDrawableUBOName = stringIndexer().get("FillExtrusionDrawableUBO"); +const StringIdentity idFillExtrusionDrawablePropsUBOName = stringIndexer().get("FillExtrusionDrawablePropsUBO"); +const StringIdentity idExpressionInputsUBOName = stringIndexer().get("ExpressionInputsUBO"); +const StringIdentity idFillExtrusionPermutationUBOName = stringIndexer().get("FillExtrusionPermutationUBO"); +const StringIdentity idTexImageName = stringIndexer().get("u_image"); } // namespace -const StringIdentity FillExtrusionLayerTweaker::idFillExtrusionTilePropsUBOName = StringIndexer::get( +const StringIdentity FillExtrusionLayerTweaker::idFillExtrusionTilePropsUBOName = stringIndexer().get( "FillExtrusionDrawableTilePropsUBO"); -const StringIdentity FillExtrusionLayerTweaker::idFillExtrusionInterpolateUBOName = StringIndexer::get( +const StringIdentity FillExtrusionLayerTweaker::idFillExtrusionInterpolateUBOName = stringIndexer().get( "FillExtrusionInterpolateUBO"); void FillExtrusionLayerTweaker::execute(LayerGroupBase& layerGroup, diff --git a/src/mbgl/renderer/layers/fill_layer_tweaker.cpp b/src/mbgl/renderer/layers/fill_layer_tweaker.cpp index f7ed4cd0a..fe35add32 100644 --- a/src/mbgl/renderer/layers/fill_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/fill_layer_tweaker.cpp @@ -24,40 +24,41 @@ 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"); -static const StringIdentity idFillPermutationUBOName = StringIndexer::get("FillPermutationUBO"); +static const StringIdentity idFillDrawableUBOName = stringIndexer().get("FillDrawableUBO"); +static const StringIdentity idFillDrawablePropsUBOName = stringIndexer().get("FillDrawablePropsUBO"); +static const StringIdentity idFillEvaluatedPropsUBOName = stringIndexer().get("FillEvaluatedPropsUBO"); +static const StringIdentity idFillPermutationUBOName = stringIndexer().get("FillPermutationUBO"); -const StringIdentity FillLayerTweaker::idFillTilePropsUBOName = StringIndexer::get("FillDrawableTilePropsUBO"); -const StringIdentity FillLayerTweaker::idFillInterpolateUBOName = StringIndexer::get("FillInterpolateUBO"); -const StringIdentity FillLayerTweaker::idFillOutlineInterpolateUBOName = StringIndexer::get( +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 idFillOutlinePermutationUBOName = StringIndexer::get("FillOutlinePermutationUBO"); +static const StringIdentity idFillOutlineDrawableUBOName = stringIndexer().get("FillOutlineDrawableUBO"); +static const StringIdentity idFillOutlineEvaluatedPropsUBOName = stringIndexer().get("FillOutlineEvaluatedPropsUBO"); +static const StringIdentity idFillOutlinePermutationUBOName = stringIndexer().get("FillOutlinePermutationUBO"); -static const StringIdentity idFillOutlineInterpolateUBOName = StringIndexer::get("FillOutlineInterpolateUBO"); +static const StringIdentity idFillOutlineInterpolateUBOName = stringIndexer().get("FillOutlineInterpolateUBO"); -static const StringIdentity idFillPatternDrawableUBOName = StringIndexer::get("FillPatternDrawableUBO"); -static const StringIdentity idFillPatternPermutationUBOName = StringIndexer::get("FillPatternPermutationUBO"); -static const StringIdentity idFillPatternInterpolateUBOName = StringIndexer::get("FillPatternInterpolateUBO"); -static const StringIdentity idFillPatternEvaluatedPropsUBOName = StringIndexer::get("FillPatternEvaluatedPropsUBO"); -static const StringIdentity idFillPatternTilePropsUBOName = StringIndexer::get("FillPatternTilePropsUBO"); +static const StringIdentity idFillPatternDrawableUBOName = stringIndexer().get("FillPatternDrawableUBO"); +static const StringIdentity idFillPatternPermutationUBOName = stringIndexer().get("FillPatternPermutationUBO"); +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 idFillOutlinePatternPermutationUBOName = StringIndexer::get( +static const StringIdentity idFillOutlinePatternDrawableUBOName = stringIndexer().get("FillOutlinePatternDrawableUBO"); +static const StringIdentity idFillOutlinePatternPermutationUBOName = stringIndexer().get( "FillOutlinePatternPermutationUBO"); -static const StringIdentity idFillOutlinePatternInterpolateUBOName = StringIndexer::get( +static const StringIdentity idFillOutlinePatternInterpolateUBOName = stringIndexer().get( "FillOutlinePatternInterpolateUBO"); -static const StringIdentity idFillOutlinePatternEvaluatedPropsUBOName = StringIndexer::get( +static const StringIdentity idFillOutlinePatternEvaluatedPropsUBOName = stringIndexer().get( "FillOutlinePatternEvaluatedPropsUBO"); -static const StringIdentity idFillOutlinePatternTilePropsUBOName = StringIndexer::get("FillOutlinePatternTilePropsUBO"); +static const StringIdentity idFillOutlinePatternTilePropsUBOName = stringIndexer().get( + "FillOutlinePatternTilePropsUBO"); -static const StringIdentity idExpressionInputsUBOName = StringIndexer::get("ExpressionInputsUBO"); +static const StringIdentity idExpressionInputsUBOName = stringIndexer().get("ExpressionInputsUBO"); -static const StringIdentity idTexImageName = StringIndexer::get("u_image"); +static const StringIdentity idTexImageName = stringIndexer().get("u_image"); using namespace shaders; void FillLayerTweaker::execute(LayerGroupBase& layerGroup, diff --git a/src/mbgl/renderer/layers/heatmap_layer_tweaker.cpp b/src/mbgl/renderer/layers/heatmap_layer_tweaker.cpp index f4b44c468..e3c390ba4 100644 --- a/src/mbgl/renderer/layers/heatmap_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/heatmap_layer_tweaker.cpp @@ -20,10 +20,10 @@ namespace mbgl { using namespace style; using namespace shaders; -static const StringIdentity idHeatmapDrawableUBOName = StringIndexer::get("HeatmapDrawableUBO"); -static const StringIdentity idHeatmapEvaluatedPropsUBOName = StringIndexer::get("HeatmapEvaluatedPropsUBO"); -static const StringIdentity idHeatmapPermutationUBOName = StringIndexer::get("HeatmapPermutationUBO"); -static const StringIdentity idExpressionInputsUBOName = StringIndexer::get("ExpressionInputsUBO"); +static const StringIdentity idHeatmapDrawableUBOName = stringIndexer().get("HeatmapDrawableUBO"); +static const StringIdentity idHeatmapEvaluatedPropsUBOName = stringIndexer().get("HeatmapEvaluatedPropsUBO"); +static const StringIdentity idHeatmapPermutationUBOName = stringIndexer().get("HeatmapPermutationUBO"); +static const StringIdentity idExpressionInputsUBOName = stringIndexer().get("ExpressionInputsUBO"); void HeatmapLayerTweaker::execute(LayerGroupBase& layerGroup, const RenderTree& renderTree, diff --git a/src/mbgl/renderer/layers/heatmap_texture_layer_tweaker.cpp b/src/mbgl/renderer/layers/heatmap_texture_layer_tweaker.cpp index d7542bbbd..8efc1645d 100644 --- a/src/mbgl/renderer/layers/heatmap_texture_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/heatmap_texture_layer_tweaker.cpp @@ -16,7 +16,7 @@ namespace mbgl { using namespace style; using namespace shaders; -static const StringIdentity idHeatmapTextureDrawableUBOName = StringIndexer::get("HeatmapTextureDrawableUBO"); +static const StringIdentity idHeatmapTextureDrawableUBOName = stringIndexer().get("HeatmapTextureDrawableUBO"); void HeatmapTextureLayerTweaker::execute(LayerGroupBase& layerGroup, [[maybe_unused]] const RenderTree& renderTree, diff --git a/src/mbgl/renderer/layers/hillshade_layer_tweaker.cpp b/src/mbgl/renderer/layers/hillshade_layer_tweaker.cpp index 7e030ba36..786858516 100644 --- a/src/mbgl/renderer/layers/hillshade_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/hillshade_layer_tweaker.cpp @@ -15,8 +15,8 @@ namespace mbgl { using namespace style; using namespace shaders; -static const StringIdentity idHillshadeDrawableUBOName = StringIndexer::get("HillshadeDrawableUBO"); -static const StringIdentity idHillshadeEvaluatedPropsUBOName = StringIndexer::get("HillshadeEvaluatedPropsUBO"); +static const StringIdentity idHillshadeDrawableUBOName = stringIndexer().get("HillshadeDrawableUBO"); +static const StringIdentity idHillshadeEvaluatedPropsUBOName = stringIndexer().get("HillshadeEvaluatedPropsUBO"); std::array getLatRange(const UnwrappedTileID& id) { const LatLng latlng0 = LatLng(id); diff --git a/src/mbgl/renderer/layers/hillshade_prepare_layer_tweaker.cpp b/src/mbgl/renderer/layers/hillshade_prepare_layer_tweaker.cpp index d8971b00a..d445c192b 100644 --- a/src/mbgl/renderer/layers/hillshade_prepare_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/hillshade_prepare_layer_tweaker.cpp @@ -16,7 +16,7 @@ namespace mbgl { using namespace style; using namespace shaders; -static const StringIdentity idHillshadePrepareDrawableUBOName = StringIndexer::get("HillshadePrepareDrawableUBO"); +static const StringIdentity idHillshadePrepareDrawableUBOName = stringIndexer().get("HillshadePrepareDrawableUBO"); const std::array& getUnpackVector(Tileset::DEMEncoding encoding) { // https://www.mapbox.com/help/access-elevation-data/#mapbox-terrain-rgb diff --git a/src/mbgl/renderer/layers/line_layer_tweaker.cpp b/src/mbgl/renderer/layers/line_layer_tweaker.cpp index 9bd15fac5..918087231 100644 --- a/src/mbgl/renderer/layers/line_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/line_layer_tweaker.cpp @@ -24,18 +24,18 @@ 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 idTexImageName = StringIndexer::get("u_image"); +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 idTexImageName = stringIndexer().get("u_image"); -static const StringIdentity idExpressionInputsUBOName = StringIndexer::get("ExpressionInputsUBO"); -static const StringIdentity idLinePermutationUBOName = StringIndexer::get("LinePermutationUBO"); +static const StringIdentity idExpressionInputsUBOName = stringIndexer().get("ExpressionInputsUBO"); +static const StringIdentity idLinePermutationUBOName = stringIndexer().get("LinePermutationUBO"); void LineLayerTweaker::execute(LayerGroupBase& layerGroup, const RenderTree& renderTree, diff --git a/src/mbgl/renderer/layers/raster_layer_tweaker.cpp b/src/mbgl/renderer/layers/raster_layer_tweaker.cpp index 2854f82dd..6d4a38ed8 100644 --- a/src/mbgl/renderer/layers/raster_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/raster_layer_tweaker.cpp @@ -17,7 +17,7 @@ namespace mbgl { using namespace style; using namespace shaders; -static const StringIdentity idRasterDrawableUBOName = StringIndexer::get("RasterDrawableUBO"); +static const StringIdentity idRasterDrawableUBOName = stringIndexer().get("RasterDrawableUBO"); void RasterLayerTweaker::execute([[maybe_unused]] LayerGroupBase& layerGroup, [[maybe_unused]] const RenderTree& renderTree, diff --git a/src/mbgl/renderer/layers/render_circle_layer.cpp b/src/mbgl/renderer/layers/render_circle_layer.cpp index 57ace7043..6123bdcd1 100644 --- a/src/mbgl/renderer/layers/render_circle_layer.cpp +++ b/src/mbgl/renderer/layers/render_circle_layer.cpp @@ -271,8 +271,8 @@ bool RenderCircleLayer::queryIntersectsFeature(const GeometryCoordinates& queryG namespace { constexpr auto CircleShaderGroupName = "CircleShader"; -const StringIdentity idCircleInterpolateUBOName = StringIndexer::get("CircleInterpolateUBO"); -const StringIdentity idVertexAttribName = StringIndexer::get("a_pos"); +const StringIdentity idCircleInterpolateUBOName = stringIndexer().get("CircleInterpolateUBO"); +const StringIdentity idVertexAttribName = stringIndexer().get("a_pos"); } // namespace diff --git a/src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp b/src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp index ba6c69b01..5e481b159 100644 --- a/src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp +++ b/src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp @@ -39,10 +39,10 @@ using namespace shaders; namespace { #if MLN_DRAWABLE_RENDERER -const StringIdentity idPosAttribName = StringIndexer::get("a_pos"); -const StringIdentity idNormAttribName = StringIndexer::get("a_normal_ed"); +const StringIdentity idPosAttribName = stringIndexer().get("a_pos"); +const StringIdentity idNormAttribName = stringIndexer().get("a_normal_ed"); -const StringIdentity idIconTextureName = StringIndexer::get("u_image"); +const StringIdentity idIconTextureName = stringIndexer().get("u_image"); #endif // MLN_DRAWABLE_RENDERER diff --git a/src/mbgl/renderer/layers/render_fill_layer.cpp b/src/mbgl/renderer/layers/render_fill_layer.cpp index 4e585aa36..42892093c 100644 --- a/src/mbgl/renderer/layers/render_fill_layer.cpp +++ b/src/mbgl/renderer/layers/render_fill_layer.cpp @@ -46,14 +46,14 @@ 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 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"); +const StringIdentity idPosAttribName = stringIndexer().get("a_pos"); +const StringIdentity idIconTextureName = stringIndexer().get("u_image"); #endif // MLN_DRAWABLE_RENDERER inline const FillLayer::Impl& impl_cast(const Immutable& impl) { diff --git a/src/mbgl/renderer/layers/render_heatmap_layer.cpp b/src/mbgl/renderer/layers/render_heatmap_layer.cpp index 6264c29f2..f6e258372 100644 --- a/src/mbgl/renderer/layers/render_heatmap_layer.cpp +++ b/src/mbgl/renderer/layers/render_heatmap_layer.cpp @@ -280,10 +280,10 @@ 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"); +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"); } // namespace diff --git a/src/mbgl/renderer/layers/render_hillshade_layer.cpp b/src/mbgl/renderer/layers/render_hillshade_layer.cpp index dc2eab0b0..e5df0649c 100644 --- a/src/mbgl/renderer/layers/render_hillshade_layer.cpp +++ b/src/mbgl/renderer/layers/render_hillshade_layer.cpp @@ -299,9 +299,9 @@ void RenderHillshadeLayer::removeRenderTargets(UniqueChangeRequestVec& changes) static const std::string HillshadePrepareShaderGroupName = "HillshadePrepareShader"; static const std::string HillshadeShaderGroupName = "HillshadeShader"; -static const StringIdentity idPosAttribName = StringIndexer::get("a_pos"); -static const StringIdentity idTexturePosAttribName = StringIndexer::get("a_texture_pos"); -static const StringIdentity idTexImageName = StringIndexer::get("u_image"); +static const StringIdentity idPosAttribName = stringIndexer().get("a_pos"); +static const StringIdentity idTexturePosAttribName = stringIndexer().get("a_texture_pos"); +static const StringIdentity idTexImageName = stringIndexer().get("u_image"); void RenderHillshadeLayer::update(gfx::ShaderRegistry& shaders, gfx::Context& context, diff --git a/src/mbgl/renderer/layers/render_line_layer.cpp b/src/mbgl/renderer/layers/render_line_layer.cpp index 35dd69c66..8cea128c0 100644 --- a/src/mbgl/renderer/layers/render_line_layer.cpp +++ b/src/mbgl/renderer/layers/render_line_layer.cpp @@ -47,8 +47,8 @@ inline const LineLayer::Impl& impl_cast(const Immutable& imp #if MLN_DRAWABLE_RENDERER -const StringIdentity idVertexAttribName = StringIndexer::get("a_pos_normal"); -const StringIdentity idDataAttribName = StringIndexer::get("a_data"); +const StringIdentity idVertexAttribName = stringIndexer().get("a_pos_normal"); +const StringIdentity idDataAttribName = stringIndexer().get("a_data"); #endif // MLN_DRAWABLE_RENDERER @@ -351,15 +351,15 @@ 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"); +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 idLinePatternTilePropertiesUBOName = stringIndexer().get("LinePatternTilePropertiesUBO"); -static const StringIdentity idLineImageUniformName = StringIndexer::get("u_image"); +static const StringIdentity idLineImageUniformName = stringIndexer().get("u_image"); void RenderLineLayer::update(gfx::ShaderRegistry& shaders, gfx::Context& context, diff --git a/src/mbgl/renderer/layers/render_raster_layer.cpp b/src/mbgl/renderer/layers/render_raster_layer.cpp index c28ff1e25..70abfbc71 100644 --- a/src/mbgl/renderer/layers/render_raster_layer.cpp +++ b/src/mbgl/renderer/layers/render_raster_layer.cpp @@ -246,10 +246,10 @@ void RenderRasterLayer::layerIndexChanged(int32_t newLayerIndex, UniqueChangeReq changeLayerIndex(imageLayerGroup, newLayerIndex, changes); } -static const StringIdentity idPosAttribName = StringIndexer::get("a_pos"); -static const StringIdentity idTexturePosAttribName = StringIndexer::get("a_texture_pos"); -static const StringIdentity idTexImage0Name = StringIndexer::get("u_image0"); -static const StringIdentity idTexImage1Name = StringIndexer::get("u_image1"); +static const StringIdentity idPosAttribName = stringIndexer().get("a_pos"); +static const StringIdentity idTexturePosAttribName = stringIndexer().get("a_texture_pos"); +static const StringIdentity idTexImage0Name = stringIndexer().get("u_image0"); +static const StringIdentity idTexImage1Name = stringIndexer().get("u_image1"); void RenderRasterLayer::update(gfx::ShaderRegistry& shaders, gfx::Context& context, diff --git a/src/mbgl/renderer/layers/render_symbol_layer.cpp b/src/mbgl/renderer/layers/render_symbol_layer.cpp index df043b819..ea2d69e91 100644 --- a/src/mbgl/renderer/layers/render_symbol_layer.cpp +++ b/src/mbgl/renderer/layers/render_symbol_layer.cpp @@ -748,13 +748,13 @@ SymbolDrawableTilePropsUBO buildTileUBO(const SymbolBucket& bucket, }; } -const StringIdentity idDataAttibName = StringIndexer::get("a_data"); -const StringIdentity idPosOffsetAttribName = StringIndexer::get("a_pos_offset"); -const StringIdentity idPixOffsetAttribName = StringIndexer::get("a_pixeloffset"); -const StringIdentity idProjPosAttribName = StringIndexer::get("a_projected_pos"); -const StringIdentity idFadeOpacityAttribName = StringIndexer::get("a_fade_opacity"); -const StringIdentity idTexUniformName = StringIndexer::get("u_texture"); -const StringIdentity idTexIconUniformName = StringIndexer::get("u_texture_icon"); +const StringIdentity idDataAttibName = stringIndexer().get("a_data"); +const StringIdentity idPosOffsetAttribName = stringIndexer().get("a_pos_offset"); +const StringIdentity idPixOffsetAttribName = stringIndexer().get("a_pixeloffset"); +const StringIdentity idProjPosAttribName = stringIndexer().get("a_projected_pos"); +const StringIdentity idFadeOpacityAttribName = stringIndexer().get("a_fade_opacity"); +const StringIdentity idTexUniformName = stringIndexer().get("u_texture"); +const StringIdentity idTexIconUniformName = stringIndexer().get("u_texture_icon"); std::vector updateTileAttributes(const SymbolBucket::Buffer& buffer, const bool isText, @@ -862,11 +862,11 @@ void updateTileDrawable(gfx::Drawable& drawable, drawable.setVertexAttributes(std::move(attribs)); } -const StringIdentity idCollisionPosAttribName = StringIndexer::get("a_pos"); -const StringIdentity idCollisionAnchorPosAttribName = StringIndexer::get("a_anchor_pos"); -const StringIdentity idCollisionExtrudeAttribName = StringIndexer::get("a_extrude"); -const StringIdentity idCollisionPlacedAttribName = StringIndexer::get("a_placed"); -const StringIdentity idCollisionShiftAttribName = StringIndexer::get("a_shift"); +const StringIdentity idCollisionPosAttribName = stringIndexer().get("a_pos"); +const StringIdentity idCollisionAnchorPosAttribName = stringIndexer().get("a_anchor_pos"); +const StringIdentity idCollisionExtrudeAttribName = stringIndexer().get("a_extrude"); +const StringIdentity idCollisionPlacedAttribName = stringIndexer().get("a_placed"); +const StringIdentity idCollisionShiftAttribName = stringIndexer().get("a_shift"); gfx::VertexAttributeArray getCollisionVertexAttributes(const SymbolBucket::CollisionBuffer& buffer, bool staticCopy) { gfx::VertexAttributeArray vertexAttrs; @@ -1139,7 +1139,7 @@ void RenderSymbolLayer::update(gfx::ShaderRegistry& shaders, const auto& collisionBox = isText ? bucket.textCollisionBox : bucket.iconCollisionBox; if (const auto shader = std::static_pointer_cast( collisionBoxGroup->getOrCreateShader( - context, {}, StringIndexer::get(idCollisionPosAttribName)))) { + context, {}, stringIndexer().get(idCollisionPosAttribName)))) { collisionBuilder->setDrawableName(layerCollisionPrefix + suffix + "box"); collisionBuilder->setShader(shader); addVertices(collisionBox->vertices().vector(), staticVertexAndAttributes); @@ -1157,7 +1157,7 @@ void RenderSymbolLayer::update(gfx::ShaderRegistry& shaders, const auto& collisionCircle = isText ? bucket.textCollisionCircle : bucket.iconCollisionCircle; if (const auto shader = std::static_pointer_cast( collisionCircleGroup->getOrCreateShader( - context, {}, StringIndexer::get(idCollisionPosAttribName)))) { + context, {}, stringIndexer().get(idCollisionPosAttribName)))) { collisionBuilder->setDrawableName(layerCollisionPrefix + suffix + "circle"); collisionBuilder->setShader(shader); addVertices(collisionCircle->vertices().vector(), staticVertexAndAttributes); @@ -1355,7 +1355,7 @@ void RenderSymbolLayer::update(gfx::ShaderRegistry& shaders, return; } const auto shader = std::static_pointer_cast(shaderGroup->getOrCreateShader( - context, propertiesAsUniforms, StringIndexer::get(idPosOffsetAttribName))); + context, propertiesAsUniforms, stringIndexer().get(idPosOffsetAttribName))); if (!shader) { return; } diff --git a/src/mbgl/renderer/layers/symbol_layer_tweaker.cpp b/src/mbgl/renderer/layers/symbol_layer_tweaker.cpp index 21ad4983b..770145741 100644 --- a/src/mbgl/renderer/layers/symbol_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/symbol_layer_tweaker.cpp @@ -43,10 +43,10 @@ std::array toArray(const Size& s) { return util::cast(std::array{s.width, s.height}); } -const StringIdentity idTexUniformName = StringIndexer::get("u_texture"); -const StringIdentity idTexIconUniformName = StringIndexer::get("u_texture_icon"); -const StringIdentity idExpressionInputsUBOName = StringIndexer::get("ExpressionInputsUBO"); -const StringIdentity idSymbolPermutationUBOName = StringIndexer::get("SymbolPermutationUBO"); +const StringIdentity idTexUniformName = stringIndexer().get("u_texture"); +const StringIdentity idTexIconUniformName = stringIndexer().get("u_texture_icon"); +const StringIdentity idExpressionInputsUBOName = stringIndexer().get("ExpressionInputsUBO"); +const StringIdentity idSymbolPermutationUBOName = stringIndexer().get("SymbolPermutationUBO"); SymbolDrawablePaintUBO buildPaintUBO(bool isText, const SymbolPaintProperties::PossiblyEvaluated& evaluated) { return { @@ -63,12 +63,12 @@ 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( +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( +const StringIdentity SymbolLayerTweaker::idSymbolDrawableInterpolateUBOName = stringIndexer().get( "SymbolDrawableInterpolateUBO"); void SymbolLayerTweaker::execute(LayerGroupBase& layerGroup, diff --git a/src/mbgl/renderer/sources/render_tile_source.cpp b/src/mbgl/renderer/sources/render_tile_source.cpp index fe81eec85..c6904a4d4 100644 --- a/src/mbgl/renderer/sources/render_tile_source.cpp +++ b/src/mbgl/renderer/sources/render_tile_source.cpp @@ -67,8 +67,8 @@ void TileSourceRenderItem::updateDebugDrawables(DebugLayerGroupMap& debugLayerGr } // create a builder - static const StringIdentity idVertexAttribName = StringIndexer::get("a_pos"); - static const StringIdentity idDebugUBOName = StringIndexer::get("DebugUBO"); + static const StringIdentity idVertexAttribName = stringIndexer().get("a_pos"); + static const StringIdentity idDebugUBOName = stringIndexer().get("DebugUBO"); std::unique_ptr builder = context.createDrawableBuilder("debug-builder"); builder->setShader(debugShader); builder->setRenderPass(renderPass); @@ -109,7 +109,7 @@ void TileSourceRenderItem::updateDebugDrawables(DebugLayerGroupMap& debugLayerGr texture->setImage(emptyImage); texture->setSamplerConfiguration( {gfx::TextureFilterType::Linear, gfx::TextureWrapType::Clamp, gfx::TextureWrapType::Clamp}); - static const StringIdentity idDebugOverlayUniformName = StringIndexer::get("u_overlay"); + static const StringIdentity idDebugOverlayUniformName = stringIndexer().get("u_overlay"); samplerLocation = debugShader->getSamplerLocation(idDebugOverlayUniformName); } assert(samplerLocation.has_value()); diff --git a/src/mbgl/shaders/gl/shader_program_gl.cpp b/src/mbgl/shaders/gl/shader_program_gl.cpp index 364dd16f9..9688f1eee 100644 --- a/src/mbgl/shaders/gl/shader_program_gl.cpp +++ b/src/mbgl/shaders/gl/shader_program_gl.cpp @@ -158,7 +158,7 @@ std::shared_ptr ShaderProgramGL::create(Context& context, MBGL_CHECK_ERROR(glGetActiveUniformBlockiv(program, index, GL_UNIFORM_BLOCK_DATA_SIZE, &size)); assert(length > 0 && size > 0); MBGL_CHECK_ERROR(glUniformBlockBinding(program, index, binding)); - uniformBlocks.add(StringIndexer::get(name.data()), index, size); + uniformBlocks.add(stringIndexer().get(name.data()), index, size); } SamplerLocationMap samplerLocations; @@ -178,7 +178,7 @@ std::shared_ptr ShaderProgramGL::create(Context& context, GLint location = MBGL_CHECK_ERROR(glGetUniformLocation(program, name.data())); assert(location != -1); if (location != -1) { - samplerLocations[StringIndexer::get(name.data())] = location; + samplerLocations[stringIndexer().get(name.data())] = location; } } } @@ -198,7 +198,7 @@ std::shared_ptr ShaderProgramGL::create(Context& context, continue; } const GLint location = MBGL_CHECK_ERROR(glGetAttribLocation(program, name.data())); - addAttr(attrs, StringIndexer::get(name.data()), location, length, size, glType); + addAttr(attrs, stringIndexer().get(name.data()), location, length, size, glType); } return std::make_shared( diff --git a/src/mbgl/shaders/mtl/shader_program.cpp b/src/mbgl/shaders/mtl/shader_program.cpp index bb07378ae..830a4d7d0 100644 --- a/src/mbgl/shaders/mtl/shader_program.cpp +++ b/src/mbgl/shaders/mtl/shader_program.cpp @@ -182,7 +182,7 @@ void ShaderProgram::initAttribute(const shaders::AttributeInfo& info) { [&](auto, const gfx::VertexAttribute& attrib) { assert(attrib.getIndex() != index); }); uniformBlocks.visit([&](auto, const gfx::UniformBlock& block) { assert(block.getIndex() != index); }); #endif - vertexAttributes.add(StringIndexer::get(info.name), index, info.dataType, info.count); + vertexAttributes.add(stringIndexer().get(info.name), index, info.dataType, info.count); } void ShaderProgram::initUniformBlock(const shaders::UniformBlockInfo& info) { @@ -193,7 +193,7 @@ void ShaderProgram::initUniformBlock(const shaders::UniformBlockInfo& info) { [&](auto, const gfx::VertexAttribute& attrib) { assert(attrib.getIndex() != index); }); uniformBlocks.visit([&](auto, 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.add(stringIndexer().get(info.name), index, info.size)) { auto& block = static_cast(*block_); block.setBindVertex(info.vertex); block.setBindFragment(info.fragment); @@ -201,7 +201,7 @@ void ShaderProgram::initUniformBlock(const shaders::UniformBlockInfo& info) { } void ShaderProgram::initTexture(const shaders::TextureInfo& info) { - textureBindings[StringIndexer::get(info.name.data())] = info.index; + textureBindings[stringIndexer().get(info.name.data())] = info.index; } } // namespace mtl diff --git a/src/mbgl/util/string_indexer.cpp b/src/mbgl/util/string_indexer.cpp index d5e8ea112..19ffde6a2 100644 --- a/src/mbgl/util/string_indexer.cpp +++ b/src/mbgl/util/string_indexer.cpp @@ -19,10 +19,7 @@ StringIndexer::StringIndexer() { StringIdentity StringIndexer::get(std::string_view string) { { - std::shared_lock readerLock(instance().sharedMutex); - - const auto& stringToIdentity = instance().stringToIdentity; - [[maybe_unused]] const auto& identityToString = instance().identityToString; + std::shared_lock readerLock(sharedMutex); assert(stringToIdentity.size() == identityToString.size()); if (const auto it = stringToIdentity.find(string); it != stringToIdentity.end()) { @@ -31,15 +28,11 @@ StringIdentity StringIndexer::get(std::string_view string) { } { - std::unique_lock writerLock(instance().sharedMutex); - - auto& stringToIdentity = instance().stringToIdentity; - auto& identityToString = instance().identityToString; + std::unique_lock writerLock(sharedMutex); assert(stringToIdentity.size() == identityToString.size()); if (const auto it = stringToIdentity.find(string); it == stringToIdentity.end()) { // this writer to insert - auto& buffer = instance().buffer; const auto previousCapacity = buffer.capacity(); const StringIdentity id = identityToString.size(); @@ -67,30 +60,32 @@ StringIdentity StringIndexer::get(std::string_view string) { } std::string StringIndexer::get(const StringIdentity id) { - std::shared_lock readerLock(instance().sharedMutex); + std::shared_lock readerLock(sharedMutex); - const auto& identityToString = instance().identityToString; assert(id < identityToString.size()); - return id < identityToString.size() ? (instance().buffer.data() + identityToString[id]) : empty; + return id < identityToString.size() ? (buffer.data() + identityToString[id]) : empty; } void StringIndexer::clear() { - std::unique_lock writerLock(instance().sharedMutex); + std::unique_lock writerLock(sharedMutex); - instance().stringToIdentity.clear(); - instance().identityToString.clear(); - instance().buffer.clear(); + stringToIdentity.clear(); + identityToString.clear(); + buffer.clear(); } size_t StringIndexer::size() { - std::shared_lock readerLock(instance().sharedMutex); + std::shared_lock readerLock(sharedMutex); - [[maybe_unused]] auto& stringToIdentity = instance().stringToIdentity; - auto& identityToString = instance().identityToString; assert(stringToIdentity.size() == identityToString.size()); return identityToString.size(); } +StringIndexer& stringIndexer() { + static StringIndexer inst; + return inst; +} + } // namespace mbgl diff --git a/test/util/string_indexer.test.cpp b/test/util/string_indexer.test.cpp index f852992dd..9155f44b8 100644 --- a/test/util/string_indexer.test.cpp +++ b/test/util/string_indexer.test.cpp @@ -7,46 +7,46 @@ using namespace mbgl; TEST(StringIndexer, AddStrings) { - StringIndexer::clear(); - EXPECT_EQ(StringIndexer::size(), 0); + StringIndexer strIndexer; + EXPECT_EQ(strIndexer.size(), 0); - const auto id1 = StringIndexer::get("test string1"); + const auto id1 = strIndexer.get("test string1"); EXPECT_EQ(id1, 0); - EXPECT_EQ(StringIndexer::size(), 1); + EXPECT_EQ(strIndexer.size(), 1); const std::string_view s2 = "test string2"; - const auto id2 = StringIndexer::get(s2); + const auto id2 = strIndexer.get(s2); EXPECT_EQ(id2, 1); - EXPECT_EQ(StringIndexer::size(), 2); + EXPECT_EQ(strIndexer.size(), 2); } TEST(StringIndexer, GetString) { - StringIndexer::clear(); - EXPECT_EQ(StringIndexer::size(), 0); + StringIndexer strIndexer; + EXPECT_EQ(strIndexer.size(), 0); constexpr auto str = "test string1"; - const auto id1 = StringIndexer::get(str); + const auto id1 = strIndexer.get(str); EXPECT_EQ(id1, 0); - EXPECT_EQ(StringIndexer::size(), 1); + EXPECT_EQ(strIndexer.size(), 1); - const auto str1 = StringIndexer::get(id1); + const auto str1 = strIndexer.get(id1); EXPECT_EQ(str, str1); const auto str2 = str; - const auto id2 = StringIndexer::get(str2); + const auto id2 = strIndexer.get(str2); EXPECT_EQ(id1, id2); } TEST(StringIndexer, Reallocate) { - StringIndexer::clear(); - EXPECT_EQ(StringIndexer::size(), 0); + StringIndexer strIndexer; + EXPECT_EQ(strIndexer.size(), 0); constexpr auto str = "reallocate test string1"; - const auto id1 = StringIndexer::get(str); + const auto id1 = strIndexer.get(str); EXPECT_EQ(id1, 0); - EXPECT_EQ(StringIndexer::size(), 1); + EXPECT_EQ(strIndexer.size(), 1); // force reallocation. assume capacity: 100 strings, 100 * 32 bytes buffer space constexpr auto N = 1000; @@ -55,31 +55,31 @@ TEST(StringIndexer, Reallocate) { return "1234567890"s + "1234567890"s + "1234567890"s + "---" + std::to_string(i); }; for (auto i = 1; i < N; ++i) { - StringIndexer::get(string_for_i(i)); + strIndexer.get(string_for_i(i)); } - EXPECT_EQ(StringIndexer::size(), N); + EXPECT_EQ(strIndexer.size(), N); - const auto str1 = StringIndexer::get(id1); + const auto str1 = strIndexer.get(id1); EXPECT_EQ(str, str1); for (auto i = 1; i < N; ++i) { - const auto strN1 = StringIndexer::get(i); + const auto strN1 = strIndexer.get(i); EXPECT_EQ(strN1, string_for_i(i)); } } TEST(StringIndexer, GetOOBIdentity) { - StringIndexer::clear(); - EXPECT_EQ(StringIndexer::size(), 0); + StringIndexer strIndexer; + EXPECT_EQ(strIndexer.size(), 0); std::string str; #ifndef NDEBUG - EXPECT_DEATH_IF_SUPPORTED(str = StringIndexer::get(42), "id < identityToString.size()"); + EXPECT_DEATH_IF_SUPPORTED(str = strIndexer.get(42), "id < identityToString.size()"); #endif EXPECT_TRUE(str.empty()); #ifndef NDEBUG - EXPECT_DEATH_IF_SUPPORTED(str = StringIndexer::get(-1), "id < identityToString.size()"); + EXPECT_DEATH_IF_SUPPORTED(str = strIndexer.get(-1), "id < identityToString.size()"); #endif EXPECT_TRUE(str.empty()); }