From 2109ba6caadf7b97fa4c629dde04ec712c441c01 Mon Sep 17 00:00:00 2001 From: Alex Cristici Date: Wed, 8 Jan 2025 18:38:23 +0200 Subject: [PATCH 1/7] Initial version from Bart. --- include/mbgl/shaders/mtl/collision.hpp | 48 +++++++++------- include/mbgl/shaders/mtl/shader_group.hpp | 3 +- include/mbgl/util/string.hpp | 68 +++++++++++++++++++++++ 3 files changed, 97 insertions(+), 22 deletions(-) diff --git a/include/mbgl/shaders/mtl/collision.hpp b/include/mbgl/shaders/mtl/collision.hpp index ad62b6638af..4cc599af816 100644 --- a/include/mbgl/shaders/mtl/collision.hpp +++ b/include/mbgl/shaders/mtl/collision.hpp @@ -3,12 +3,14 @@ #include #include #include +#include namespace mbgl { namespace shaders { -#define COLLISION_SHADER_COMMON \ - R"( +using mbgl::util::operator""_cts; + +constexpr auto collisionShaderCommon = R"( enum { idCollisionDrawableUBO = idDrawableReservedVertexOnlyUBO, @@ -30,19 +32,9 @@ struct alignas(16) CollisionTilePropsUBO { }; static_assert(sizeof(CollisionTilePropsUBO) == 16, "wrong size"); -)" - -template <> -struct ShaderSource { - static constexpr auto name = "CollisionBoxShader"; - static constexpr auto vertexMainFunction = "vertexMain"; - static constexpr auto fragmentMainFunction = "fragmentMain"; - - static const std::array attributes; - static constexpr std::array instanceAttributes{}; - static const std::array textures; +)"_cts; - static constexpr auto source = COLLISION_SHADER_COMMON R"( +constexpr auto collisionBoxShaderSource = collisionShaderCommon + R"( struct VertexStage { short2 pos [[attribute(collisionUBOCount + 0)]]; @@ -102,20 +94,22 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]]) { return half4(color); } -)"; -}; +)"_cts; template <> -struct ShaderSource { - static constexpr auto name = "CollisionCircleShader"; +struct ShaderSource { + static constexpr auto name = "CollisionBoxShader"; static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; - static const std::array attributes; + static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; - static constexpr auto source = COLLISION_SHADER_COMMON R"( + static constexpr auto source = collisionBoxShaderSource.as_string_view(); +}; + +constexpr auto collisionCircleShaderSource = collisionShaderCommon + R"( struct VertexStage { short2 pos [[attribute(collisionUBOCount + 0)]]; @@ -195,7 +189,19 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], return half4(opacity_t * color); } -)"; +)"_cts; + +template <> +struct ShaderSource { + static constexpr auto name = "CollisionCircleShader"; + static constexpr auto vertexMainFunction = "vertexMain"; + static constexpr auto fragmentMainFunction = "fragmentMain"; + + static const std::array attributes; + static constexpr std::array instanceAttributes{}; + static const std::array textures; + + static constexpr auto source = collisionCircleShaderSource.as_string_view(); }; } // namespace shaders diff --git a/include/mbgl/shaders/mtl/shader_group.hpp b/include/mbgl/shaders/mtl/shader_group.hpp index 111332a0ca3..8492c362a0e 100644 --- a/include/mbgl/shaders/mtl/shader_group.hpp +++ b/include/mbgl/shaders/mtl/shader_group.hpp @@ -63,7 +63,8 @@ class ShaderGroup final : public ShaderGroupBase { addAdditionalDefines(propertiesAsUniforms, additionalDefines); auto& context = static_cast(gfxContext); - const auto shaderSource = std::string(shaders::prelude) + source; + // C++26 will allow operator+ with std::string and std::string_view + const auto shaderSource = std::string(shaders::prelude) + std::string(source); shader = context.createProgram( ShaderID, shaderName, shaderSource, vertMain, fragMain, programParameters, additionalDefines); assert(shader); diff --git a/include/mbgl/util/string.hpp b/include/mbgl/util/string.hpp index ded4df9d081..aadd1dcc76d 100644 --- a/include/mbgl/util/string.hpp +++ b/include/mbgl/util/string.hpp @@ -96,6 +96,74 @@ inline float stof(const std::string &str) { return std::stof(str); } +// https://gist.github.com/Baduit/63c4ea0f248451f7047c1b003c8335d5 +// Note: asked author to clarify license + +template +struct CompileTimeString +{ + constexpr CompileTimeString() noexcept = default; + + constexpr CompileTimeString(const char(&literal)[ArraySize]) noexcept + { + std::ranges::copy(literal, data); + } + + template + constexpr auto operator+(const CompileTimeString& other) const noexcept + { + CompileTimeString result; + std::ranges::copy(data, result.data); + std::ranges::copy(other.data, result.data + ArraySize - 1); + return result; + } + + // Don't count the \0 at the end + constexpr std::size_t size() const { return ArraySize - 1; } + + constexpr auto begin() noexcept { return std::begin(data); } + constexpr auto end() noexcept { return std::end(data); } + constexpr auto cbegin() const noexcept { return std::cbegin(data); } + constexpr auto cend() const noexcept { return std::cend(data); } + constexpr auto rbegin() noexcept { return std::rbegin(data); } + constexpr auto rend() noexcept { return std::rend(data); } + constexpr auto crbegin() const noexcept { return std::crbegin(data); } + constexpr auto crend() const noexcept { return std::crend(data); } + + template + constexpr bool operator==(const CompileTimeString& other) const + { + return as_string_view() == other.as_string_view(); + } + + + constexpr bool starts_with(std::string_view sv) const noexcept { return as_string_view().starts_with(sv); } + constexpr bool starts_with(char ch) const noexcept { return as_string_view().starts_with(ch); } + constexpr bool starts_with(const char* s) const { return as_string_view().starts_with(s); } + + template + constexpr bool starts_with(const CompileTimeString& other) const + { + return starts_with(other.as_string_view()); + } + + // https://en.cppreference.com/w/cpp/language/reference + // https://en.cppreference.com/w/cpp/language/member_functions#Member_functions_with_ref-qualifier + constexpr operator std::string_view() const & { return as_string_view(); } + constexpr operator std::string_view() const && = delete; + + constexpr std::string_view as_string_view() const & { return std::string_view(data, ArraySize - 1); } + constexpr std::string_view as_string_view() const && = delete; + + char data[ArraySize]; +}; + +template +constexpr auto operator""_cts() +{ + return Str; +} + } // namespace util } // namespace mbgl From f45e9ba23410d67e5d82276fb19f7f049f0d9244 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 8 Jan 2025 16:39:50 +0000 Subject: [PATCH 2/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- include/mbgl/util/string.hpp | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/include/mbgl/util/string.hpp b/include/mbgl/util/string.hpp index aadd1dcc76d..92773850958 100644 --- a/include/mbgl/util/string.hpp +++ b/include/mbgl/util/string.hpp @@ -100,18 +100,13 @@ inline float stof(const std::string &str) { // Note: asked author to clarify license template -struct CompileTimeString -{ +struct CompileTimeString { constexpr CompileTimeString() noexcept = default; - constexpr CompileTimeString(const char(&literal)[ArraySize]) noexcept - { - std::ranges::copy(literal, data); - } + constexpr CompileTimeString(const char (&literal)[ArraySize]) noexcept { std::ranges::copy(literal, data); } template - constexpr auto operator+(const CompileTimeString& other) const noexcept - { + constexpr auto operator+(const CompileTimeString &other) const noexcept { CompileTimeString result; std::ranges::copy(data, result.data); std::ranges::copy(other.data, result.data + ArraySize - 1); @@ -131,19 +126,16 @@ struct CompileTimeString constexpr auto crend() const noexcept { return std::crend(data); } template - constexpr bool operator==(const CompileTimeString& other) const - { + constexpr bool operator==(const CompileTimeString &other) const { return as_string_view() == other.as_string_view(); } - constexpr bool starts_with(std::string_view sv) const noexcept { return as_string_view().starts_with(sv); } constexpr bool starts_with(char ch) const noexcept { return as_string_view().starts_with(ch); } - constexpr bool starts_with(const char* s) const { return as_string_view().starts_with(s); } + constexpr bool starts_with(const char *s) const { return as_string_view().starts_with(s); } template - constexpr bool starts_with(const CompileTimeString& other) const - { + constexpr bool starts_with(const CompileTimeString &other) const { return starts_with(other.as_string_view()); } @@ -158,9 +150,8 @@ struct CompileTimeString char data[ArraySize]; }; -template -constexpr auto operator""_cts() -{ +template +constexpr auto operator""_cts() { return Str; } From 3717ffacff1bf60c3ba4f328609a0323ecc658b1 Mon Sep 17 00:00:00 2001 From: Alex Cristici Date: Wed, 8 Jan 2025 19:42:06 +0200 Subject: [PATCH 3/7] Fix CI. --- include/mbgl/util/string.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/include/mbgl/util/string.hpp b/include/mbgl/util/string.hpp index 92773850958..a17bfe5c37b 100644 --- a/include/mbgl/util/string.hpp +++ b/include/mbgl/util/string.hpp @@ -7,6 +7,7 @@ #include #include #include +#include // Polyfill needed by Qt when building for Android with GCC #if defined(__ANDROID__) && defined(__GLIBCXX__) From c17ee7928f26b8b1cd253622a8aaec560b25b193 Mon Sep 17 00:00:00 2001 From: Alex Cristici Date: Wed, 8 Jan 2025 23:08:39 +0200 Subject: [PATCH 4/7] Replace macro with compile-time string for all metal shaders. --- include/mbgl/shaders/mtl/background.hpp | 48 ++++++---- include/mbgl/shaders/mtl/circle.hpp | 33 ++++--- include/mbgl/shaders/mtl/clipping_mask.hpp | 33 ++++--- .../mbgl/shaders/mtl/custom_symbol_icon.hpp | 33 ++++--- include/mbgl/shaders/mtl/debug.hpp | 34 ++++--- include/mbgl/shaders/mtl/fill.hpp | 93 +++++++++++-------- include/mbgl/shaders/mtl/fill_extrusion.hpp | 50 +++++----- include/mbgl/shaders/mtl/heatmap.hpp | 34 ++++--- include/mbgl/shaders/mtl/heatmap_texture.hpp | 34 ++++--- include/mbgl/shaders/mtl/hillshade.hpp | 34 ++++--- .../mbgl/shaders/mtl/hillshade_prepare.hpp | 33 ++++--- include/mbgl/shaders/mtl/line.hpp | 78 +++++++++------- include/mbgl/shaders/mtl/raster.hpp | 34 ++++--- include/mbgl/shaders/mtl/symbol.hpp | 65 +++++++------ include/mbgl/shaders/mtl/widevector.hpp | 33 ++++--- 15 files changed, 385 insertions(+), 284 deletions(-) diff --git a/include/mbgl/shaders/mtl/background.hpp b/include/mbgl/shaders/mtl/background.hpp index cb683aefde7..4f189312306 100644 --- a/include/mbgl/shaders/mtl/background.hpp +++ b/include/mbgl/shaders/mtl/background.hpp @@ -3,12 +3,14 @@ #include #include #include +#include namespace mbgl { namespace shaders { -#define BACKGROUND_SHADER_COMMON \ - R"( +using mbgl::util::operator""_cts; + +constexpr auto backgroundShaderCommon = R"( enum { idBackgroundDrawableUBO = idDrawableReservedVertexOnlyUBO, @@ -72,19 +74,10 @@ union BackgroundDrawableUnionUBO { BackgroundPatternDrawableUBO backgroundPatternDrawableUBO; }; -)" - -template <> -struct ShaderSource { - static constexpr auto name = "BackgroundShader"; - static constexpr auto vertexMainFunction = "vertexMain"; - static constexpr auto fragmentMainFunction = "fragmentMain"; +)"_cts; - static const std::array attributes; - static constexpr std::array instanceAttributes{}; - static const std::array textures; +constexpr auto backgroundShaderSource = backgroundShaderCommon + R"( - static constexpr auto source = BACKGROUND_SHADER_COMMON R"( #include using namespace metal; @@ -115,20 +108,23 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], return half4(props.color * props.opacity); } -)"; -}; +)"_cts; template <> -struct ShaderSource { - static constexpr auto name = "BackgroundPatternShader"; +struct ShaderSource { + static constexpr auto name = "BackgroundShader"; static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; static const std::array attributes; static constexpr std::array instanceAttributes{}; - static const std::array textures; + static const std::array textures; + + static constexpr auto source = backgroundShaderSource.as_string_view(); +}; + +constexpr auto backgroundPatternShaderSource = backgroundShaderCommon + R"( - static constexpr auto source = BACKGROUND_SHADER_COMMON R"( #include using namespace metal; @@ -186,7 +182,19 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], return half4(mix(color1, color2, props.mix) * props.opacity); } -)"; +)"_cts; + +template <> +struct ShaderSource { + static constexpr auto name = "BackgroundPatternShader"; + static constexpr auto vertexMainFunction = "vertexMain"; + static constexpr auto fragmentMainFunction = "fragmentMain"; + + static const std::array attributes; + static constexpr std::array instanceAttributes{}; + static const std::array textures; + + static constexpr auto source = backgroundPatternShaderSource.as_string_view(); }; } // namespace shaders diff --git a/include/mbgl/shaders/mtl/circle.hpp b/include/mbgl/shaders/mtl/circle.hpp index 2a95a763fe1..44c89e56df4 100644 --- a/include/mbgl/shaders/mtl/circle.hpp +++ b/include/mbgl/shaders/mtl/circle.hpp @@ -3,12 +3,14 @@ #include #include #include +#include namespace mbgl { namespace shaders { -#define CIRCLE_SHADER_PRELUDE \ - R"( +using mbgl::util::operator""_cts; + +constexpr auto circleShaderPrelude = R"( enum { idCircleDrawableUBO = idDrawableReservedVertexOnlyUBO, @@ -51,19 +53,10 @@ struct alignas(16) CircleEvaluatedPropsUBO { }; static_assert(sizeof(CircleEvaluatedPropsUBO) == 4 * 16, "wrong size"); -)" +)"_cts; -template <> -struct ShaderSource { - static constexpr auto name = "CircleShader"; - static constexpr auto vertexMainFunction = "vertexMain"; - static constexpr auto fragmentMainFunction = "fragmentMain"; +constexpr auto circleShaderSource = circleShaderPrelude + R"( - static const std::array attributes; - static constexpr std::array instanceAttributes{}; - static const std::array textures; - - static constexpr auto source = CIRCLE_SHADER_PRELUDE R"( struct VertexStage { short2 position [[attribute(circleUBOCount + 0)]]; @@ -251,7 +244,19 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], return half4(opacity_t * mix(color * opacity, stroke_color * stroke_opacity, color_t)); } -)"; +)"_cts; + +template <> +struct ShaderSource { + static constexpr auto name = "CircleShader"; + static constexpr auto vertexMainFunction = "vertexMain"; + static constexpr auto fragmentMainFunction = "fragmentMain"; + + static const std::array attributes; + static constexpr std::array instanceAttributes{}; + static const std::array textures; + + static constexpr auto source = circleShaderSource.as_string_view(); }; } // namespace shaders diff --git a/include/mbgl/shaders/mtl/clipping_mask.hpp b/include/mbgl/shaders/mtl/clipping_mask.hpp index 580c1ad9efd..69c7b432829 100644 --- a/include/mbgl/shaders/mtl/clipping_mask.hpp +++ b/include/mbgl/shaders/mtl/clipping_mask.hpp @@ -2,10 +2,13 @@ #include #include +#include namespace mbgl { namespace shaders { +using mbgl::util::operator""_cts; + struct alignas(16) ClipUBO { /* 0 */ std::array matrix; /* 64 */ std::uint32_t stencil_ref; @@ -16,8 +19,7 @@ struct alignas(16) ClipUBO { }; static_assert(sizeof(ClipUBO) == 5 * 16); -#define CLIPPING_MASK_SHADER_PRELUDE \ - R"( +constexpr auto clippingMaskShaderPrelude = R"( #include using namespace metal; @@ -37,19 +39,10 @@ struct alignas(16) ClipUBO { }; static_assert(sizeof(ClipUBO) == 5 * 16, "wrong size"); -)" +)"_cts; -template <> -struct ShaderSource { - static constexpr auto name = "ClippingMaskProgram"; - static constexpr auto vertexMainFunction = "vertexMain"; - static constexpr auto fragmentMainFunction = "fragmentMain"; +constexpr auto clippingMaskShaderSource = clippingMaskShaderPrelude + R"( - static const std::array attributes; - static constexpr std::array instanceAttributes{}; - static const std::array textures; - - static constexpr auto source = CLIPPING_MASK_SHADER_PRELUDE R"( struct VertexStage { short2 position [[attribute(clippingMaskUBOCount + 0)]]; }; @@ -71,7 +64,19 @@ FragmentStage vertex vertexMain(VertexStage in [[stage_in]], half4 fragment fragmentMain(FragmentStage in [[stage_in]]) { return half4(1.0); } -)"; +)"_cts; + +template <> +struct ShaderSource { + static constexpr auto name = "ClippingMaskProgram"; + static constexpr auto vertexMainFunction = "vertexMain"; + static constexpr auto fragmentMainFunction = "fragmentMain"; + + static const std::array attributes; + static constexpr std::array instanceAttributes{}; + static const std::array textures; + + static constexpr auto source = clippingMaskShaderSource.as_string_view(); }; } // namespace shaders diff --git a/include/mbgl/shaders/mtl/custom_symbol_icon.hpp b/include/mbgl/shaders/mtl/custom_symbol_icon.hpp index 82581e74d37..8e8e037d70d 100644 --- a/include/mbgl/shaders/mtl/custom_symbol_icon.hpp +++ b/include/mbgl/shaders/mtl/custom_symbol_icon.hpp @@ -3,12 +3,14 @@ #include #include #include +#include namespace mbgl { namespace shaders { -#define CUSTOM_SYMBOL_ICON_SHADER_PRELUDE \ - R"( +using mbgl::util::operator""_cts; + +constexpr auto customSymbolIconShaderPrelude = R"( enum { idCustomSymbolDrawableUBO = idDrawableReservedVertexOnlyUBO, @@ -31,19 +33,10 @@ struct alignas(16) CustomSymbolIconDrawableUBO { }; static_assert(sizeof(CustomSymbolIconDrawableUBO) == 7 * 16, "wrong size"); -)" +)"_cts; -template <> -struct ShaderSource { - static constexpr auto name = "CustomSymbolIconShader"; - static constexpr auto vertexMainFunction = "vertexMain"; - static constexpr auto fragmentMainFunction = "fragmentMain"; +constexpr auto customSymbolIconShaderSource = customSymbolIconShaderPrelude + R"( - static const std::array attributes; - static constexpr std::array instanceAttributes{}; - static const std::array textures; - - static constexpr auto source = CUSTOM_SYMBOL_ICON_SHADER_PRELUDE R"( struct VertexStage { float2 a_pos [[attribute(customSymbolUBOCount + 0)]]; float2 a_tex [[attribute(customSymbolUBOCount + 1)]]; @@ -107,7 +100,19 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], return half4(image.sample(image_sampler, float2(in.tex))); } -)"; +)"_cts; + +template <> +struct ShaderSource { + static constexpr auto name = "CustomSymbolIconShader"; + static constexpr auto vertexMainFunction = "vertexMain"; + static constexpr auto fragmentMainFunction = "fragmentMain"; + + static const std::array attributes; + static constexpr std::array instanceAttributes{}; + static const std::array textures; + + static constexpr auto source = customSymbolIconShaderSource.as_string_view(); }; } // namespace shaders diff --git a/include/mbgl/shaders/mtl/debug.hpp b/include/mbgl/shaders/mtl/debug.hpp index 633c6a0a985..7d9352c2f22 100644 --- a/include/mbgl/shaders/mtl/debug.hpp +++ b/include/mbgl/shaders/mtl/debug.hpp @@ -3,12 +3,14 @@ #include #include #include +#include namespace mbgl { namespace shaders { -#define DEBUG_SHADER_PRELUDE \ - R"( +using mbgl::util::operator""_cts; + +constexpr auto debugShaderPrelude = R"( enum { idDebugUBO = drawableReservedUBOCount, @@ -26,19 +28,9 @@ struct alignas(16) DebugUBO { }; static_assert(sizeof(DebugUBO) == 6 * 16, "wrong size"); -)" - -template <> -struct ShaderSource { - static constexpr auto name = "DebugShader"; - static constexpr auto vertexMainFunction = "vertexMain"; - static constexpr auto fragmentMainFunction = "fragmentMain"; - - static const std::array attributes; - static constexpr std::array instanceAttributes{}; - static const std::array textures; +)"_cts; - static constexpr auto source = DEBUG_SHADER_PRELUDE R"( +constexpr auto debugShaderSource = debugShaderPrelude + R"( struct VertexStage { short2 pos [[attribute(debugUBOCount + 0)]]; @@ -73,7 +65,19 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], float4 color = mix(debug.color, overlay_color, overlay_color.a); return half4(color); } -)"; +)"_cts; + +template <> +struct ShaderSource { + static constexpr auto name = "DebugShader"; + static constexpr auto vertexMainFunction = "vertexMain"; + static constexpr auto fragmentMainFunction = "fragmentMain"; + + static const std::array attributes; + static constexpr std::array instanceAttributes{}; + static const std::array textures; + + static constexpr auto source = debugShaderSource.as_string_view(); }; } // namespace shaders diff --git a/include/mbgl/shaders/mtl/fill.hpp b/include/mbgl/shaders/mtl/fill.hpp index b589a8dca4d..b7cb6c9d70b 100644 --- a/include/mbgl/shaders/mtl/fill.hpp +++ b/include/mbgl/shaders/mtl/fill.hpp @@ -3,12 +3,14 @@ #include #include #include +#include namespace mbgl { namespace shaders { -#define FILL_SHADER_COMMON \ - R"( +using mbgl::util::operator""_cts; + +constexpr auto fillShaderCommon = R"( enum { idFillDrawableUBO = idDrawableReservedVertexOnlyUBO, @@ -139,19 +141,9 @@ union FillTilePropsUnionUBO { FillOutlinePatternTilePropsUBO fillOutlinePatternTilePropsUBO; }; -)" - -template <> -struct ShaderSource { - static constexpr auto name = "FillShader"; - static constexpr auto vertexMainFunction = "vertexMain"; - static constexpr auto fragmentMainFunction = "fragmentMain"; - - static const std::array attributes; - static constexpr std::array instanceAttributes{}; - static const std::array textures; +)"_cts; - static constexpr auto source = FILL_SHADER_COMMON R"( +constexpr auto fillShaderSource = fillShaderCommon + R"( struct VertexStage { short2 position [[attribute(fillUBOCount + 0)]]; @@ -212,12 +204,11 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], return half4(color * opacity); } -)"; -}; +)"_cts; template <> -struct ShaderSource { - static constexpr auto name = "FillOutlineShader"; +struct ShaderSource { + static constexpr auto name = "FillShader"; static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; @@ -225,7 +216,11 @@ struct ShaderSource { static constexpr std::array instanceAttributes{}; static const std::array textures; - static constexpr auto source = FILL_SHADER_COMMON R"( + static constexpr auto source = fillShaderSource.as_string_view(); +}; + +constexpr auto fillOutlineShaderSource = fillShaderCommon + R"( + struct VertexStage { short2 position [[attribute(fillUBOCount + 0)]]; float4 outline_color [[attribute(fillUBOCount + 1)]]; @@ -289,20 +284,23 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], return half4(color * opacity); } -)"; -}; +)"_cts; template <> -struct ShaderSource { - static constexpr auto name = "FillPatternShader"; +struct ShaderSource { + static constexpr auto name = "FillOutlineShader"; static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; - static const std::array attributes; + static const std::array attributes; static constexpr std::array instanceAttributes{}; - static const std::array textures; + static const std::array textures; + + static constexpr auto source = fillOutlineShaderSource.as_string_view(); +}; + +constexpr auto fillPatternShaderSource = fillShaderCommon + R"( - static constexpr auto source = FILL_SHADER_COMMON R"( struct VertexStage { short2 position [[attribute(fillUBOCount + 0)]]; @@ -430,12 +428,11 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], return half4(mix(color1, color2, props.fade) * opacity); } -)"; -}; +)"_cts; template <> -struct ShaderSource { - static constexpr auto name = "FillOutlinePatternShader"; +struct ShaderSource { + static constexpr auto name = "FillPatternShader"; static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; @@ -443,7 +440,10 @@ struct ShaderSource instanceAttributes{}; static const std::array textures; - static constexpr auto source = FILL_SHADER_COMMON R"( + static constexpr auto source = fillPatternShaderSource.as_string_view(); +}; + +constexpr auto fillOutlinePatternShaderSource = fillShaderCommon + R"( struct VertexStage { short2 position [[attribute(fillUBOCount + 0)]]; @@ -584,20 +584,23 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], return half4(mix(color1, color2, props.fade) * opacity); } -)"; -}; +)"_cts; template <> -struct ShaderSource { - static constexpr auto name = "FillOutlineTriangulatedShader"; +struct ShaderSource { + static constexpr auto name = "FillOutlinePatternShader"; static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; - static const std::array attributes; + static const std::array attributes; static constexpr std::array instanceAttributes{}; - static const std::array textures; + static const std::array textures; + + static constexpr auto source = fillOutlinePatternShaderSource.as_string_view(); +}; + +constexpr auto fillOutlineTriangulatedShaderSource = fillShaderCommon + R"( - static constexpr auto source = FILL_SHADER_COMMON R"( struct VertexStage { short2 pos_normal [[attribute(fillUBOCount + 0)]]; uchar4 data [[attribute(fillUBOCount + 1)]]; @@ -665,7 +668,19 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], return half4(props.outline_color * (alpha * props.opacity)); } -)"; +)"_cts; + +template <> +struct ShaderSource { + static constexpr auto name = "FillOutlineTriangulatedShader"; + static constexpr auto vertexMainFunction = "vertexMain"; + static constexpr auto fragmentMainFunction = "fragmentMain"; + + static const std::array attributes; + static constexpr std::array instanceAttributes{}; + static const std::array textures; + + static constexpr auto source = fillOutlineTriangulatedShaderSource.as_string_view(); }; } // namespace shaders diff --git a/include/mbgl/shaders/mtl/fill_extrusion.hpp b/include/mbgl/shaders/mtl/fill_extrusion.hpp index 4a5e05663f3..940f1c100b8 100644 --- a/include/mbgl/shaders/mtl/fill_extrusion.hpp +++ b/include/mbgl/shaders/mtl/fill_extrusion.hpp @@ -3,12 +3,14 @@ #include #include #include +#include namespace mbgl { namespace shaders { -#define FILL_EXTRUSION_SHADER_COMMON \ - R"( +using mbgl::util::operator""_cts; + +constexpr auto fillExtrusionShaderCommon = R"( enum { idFillExtrusionDrawableUBO = idDrawableReservedVertexOnlyUBO, @@ -62,19 +64,10 @@ struct alignas(16) FillExtrusionPropsUBO { }; static_assert(sizeof(FillExtrusionPropsUBO) == 5 * 16, "wrong size"); -)" +)"_cts; -template <> -struct ShaderSource { - static constexpr auto name = "FillExtrusionShader"; - static constexpr auto vertexMainFunction = "vertexMain"; - static constexpr auto fragmentMainFunction = "fragmentMain"; +constexpr auto fillExtrusionShaderSource = fillExtrusionShaderCommon + R"( - static const std::array attributes; - static constexpr std::array instanceAttributes{}; - static const std::array textures; - - static constexpr auto source = FILL_EXTRUSION_SHADER_COMMON R"( struct VertexStage { short2 pos [[attribute(fillExtrusionUBOCount + 0)]]; short4 normal_ed [[attribute(fillExtrusionUBOCount + 1)]]; @@ -180,20 +173,23 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], fragment FragmentOutput fragmentMain(FragmentStage in [[stage_in]]) { return { in.color/*, in.position.z*/ }; } -)"; -}; +)"_cts; template <> -struct ShaderSource { - static constexpr auto name = "FillExtrusionPatternShader"; +struct ShaderSource { + static constexpr auto name = "FillExtrusionShader"; static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; - static const std::array attributes; + static const std::array attributes; static constexpr std::array instanceAttributes{}; - static const std::array textures; + static const std::array textures; + + static constexpr auto source = fillExtrusionShaderSource.as_string_view(); +}; + +constexpr auto fillExtrusionPatternShaderSource = fillExtrusionShaderCommon + R"( - static constexpr auto source = FILL_EXTRUSION_SHADER_COMMON R"( struct VertexStage { short2 pos [[attribute(fillExtrusionUBOCount + 0)]]; short4 normal_ed [[attribute(fillExtrusionUBOCount + 1)]]; @@ -364,7 +360,19 @@ fragment FragmentOutput fragmentMain(FragmentStage in [[stage_in]], return {half4(mix(color1, color2, props.fade) * in.lighting)/*, in.position.z*/}; } -)"; +)"_cts; + +template <> +struct ShaderSource { + static constexpr auto name = "FillExtrusionPatternShader"; + static constexpr auto vertexMainFunction = "vertexMain"; + static constexpr auto fragmentMainFunction = "fragmentMain"; + + static const std::array attributes; + static constexpr std::array instanceAttributes{}; + static const std::array textures; + + static constexpr auto source = fillExtrusionPatternShaderSource.as_string_view(); }; } // namespace shaders diff --git a/include/mbgl/shaders/mtl/heatmap.hpp b/include/mbgl/shaders/mtl/heatmap.hpp index 81e4c25e4ba..e791eef91a0 100644 --- a/include/mbgl/shaders/mtl/heatmap.hpp +++ b/include/mbgl/shaders/mtl/heatmap.hpp @@ -3,12 +3,14 @@ #include #include #include +#include namespace mbgl { namespace shaders { -#define HEATMAP_SHADER_PRELUDE \ - R"( +using mbgl::util::operator""_cts; + +constexpr auto heatmapShaderPrelude = R"( enum { idHeatmapDrawableUBO = idDrawableReservedVertexOnlyUBO, @@ -38,19 +40,9 @@ struct alignas(16) HeatmapEvaluatedPropsUBO { }; static_assert(sizeof(HeatmapEvaluatedPropsUBO) == 16, "wrong size"); -)" - -template <> -struct ShaderSource { - static constexpr auto name = "HeatmapShader"; - static constexpr auto vertexMainFunction = "vertexMain"; - static constexpr auto fragmentMainFunction = "fragmentMain"; - - static const std::array attributes; - static constexpr std::array instanceAttributes{}; - static const std::array textures; +)"_cts; - static constexpr auto source = HEATMAP_SHADER_PRELUDE R"( +constexpr auto heatmapShaderSource = heatmapShaderPrelude + R"( struct VertexStage { short2 pos [[attribute(heatmapUBOCount + 0)]]; @@ -141,7 +133,19 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], return half4(val, 1.0, 1.0, 1.0); } -)"; +)"_cts; + +template <> +struct ShaderSource { + static constexpr auto name = "HeatmapShader"; + static constexpr auto vertexMainFunction = "vertexMain"; + static constexpr auto fragmentMainFunction = "fragmentMain"; + + static const std::array attributes; + static constexpr std::array instanceAttributes{}; + static const std::array textures; + + static constexpr auto source = heatmapShaderSource.as_string_view(); }; } // namespace shaders diff --git a/include/mbgl/shaders/mtl/heatmap_texture.hpp b/include/mbgl/shaders/mtl/heatmap_texture.hpp index e32b2fdb53d..f614b54517d 100644 --- a/include/mbgl/shaders/mtl/heatmap_texture.hpp +++ b/include/mbgl/shaders/mtl/heatmap_texture.hpp @@ -3,12 +3,14 @@ #include #include #include +#include namespace mbgl { namespace shaders { -#define HEATMAP_TEXTURE_SHADER_PRELUDE \ - R"( +using mbgl::util::operator""_cts; + +constexpr auto heatmapTextureShaderPrelude = R"( enum { idHeatmapTexturePropsUBO = drawableReservedUBOCount, @@ -25,19 +27,9 @@ struct alignas(16) HeatmapTexturePropsUBO { }; static_assert(sizeof(HeatmapTexturePropsUBO) == 5 * 16, "wrong size"); -)" - -template <> -struct ShaderSource { - static constexpr auto name = "HeatmapTextureShader"; - static constexpr auto vertexMainFunction = "vertexMain"; - static constexpr auto fragmentMainFunction = "fragmentMain"; - - static const std::array attributes; - static constexpr std::array instanceAttributes{}; - static const std::array textures; +)"_cts; - static constexpr auto source = HEATMAP_TEXTURE_SHADER_PRELUDE R"( +constexpr auto heatmapTextureShaderSource = heatmapTextureShaderPrelude + R"( struct VertexStage { short2 pos [[attribute(heatmapTextureUBOCount + 0)]]; @@ -76,7 +68,19 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], float4 color = color_ramp.sample(color_ramp_sampler, float2(t, 0.5)); return half4(color * props.opacity); } -)"; +)"_cts; + +template <> +struct ShaderSource { + static constexpr auto name = "HeatmapTextureShader"; + static constexpr auto vertexMainFunction = "vertexMain"; + static constexpr auto fragmentMainFunction = "fragmentMain"; + + static const std::array attributes; + static constexpr std::array instanceAttributes{}; + static const std::array textures; + + static constexpr auto source = heatmapTextureShaderSource.as_string_view(); }; } // namespace shaders diff --git a/include/mbgl/shaders/mtl/hillshade.hpp b/include/mbgl/shaders/mtl/hillshade.hpp index 39e5c74135e..57984d1f033 100644 --- a/include/mbgl/shaders/mtl/hillshade.hpp +++ b/include/mbgl/shaders/mtl/hillshade.hpp @@ -3,12 +3,14 @@ #include #include #include +#include namespace mbgl { namespace shaders { -#define HILLSHADE_SHADER_PRELUDE \ - R"( +using mbgl::util::operator""_cts; + +constexpr auto hillshadeShaderPrelude = R"( enum { idHillshadeDrawableUBO = idDrawableReservedVertexOnlyUBO, @@ -39,19 +41,9 @@ struct alignas(16) HillshadeEvaluatedPropsUBO { }; static_assert(sizeof(HillshadeEvaluatedPropsUBO) == 3 * 16, "wrong size"); -)" - -template <> -struct ShaderSource { - static constexpr auto name = "HillshadeShader"; - static constexpr auto vertexMainFunction = "vertexMain"; - static constexpr auto fragmentMainFunction = "fragmentMain"; - - static const std::array attributes; - static constexpr std::array instanceAttributes{}; - static const std::array textures; +)"_cts; - static constexpr auto source = HILLSHADE_SHADER_PRELUDE R"( +constexpr auto hillshadeShaderSource = hillshadeShaderPrelude + R"( struct VertexStage { short2 pos [[attribute(hillshadeUBOCount + 0)]]; @@ -129,7 +121,19 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], return half4(color); } -)"; +)"_cts; + +template <> +struct ShaderSource { + static constexpr auto name = "HillshadeShader"; + static constexpr auto vertexMainFunction = "vertexMain"; + static constexpr auto fragmentMainFunction = "fragmentMain"; + + static const std::array attributes; + static constexpr std::array instanceAttributes{}; + static const std::array textures; + + static constexpr auto source = hillshadeShaderSource.as_string_view(); }; } // namespace shaders diff --git a/include/mbgl/shaders/mtl/hillshade_prepare.hpp b/include/mbgl/shaders/mtl/hillshade_prepare.hpp index 8b3770b4d61..1f736503fad 100644 --- a/include/mbgl/shaders/mtl/hillshade_prepare.hpp +++ b/include/mbgl/shaders/mtl/hillshade_prepare.hpp @@ -3,12 +3,14 @@ #include #include #include +#include namespace mbgl { namespace shaders { -#define HILLSHADE_PREPARE_SHADER_PRELUDE \ - R"( +using mbgl::util::operator""_cts; + +constexpr auto hillshadePrepareShaderPrelude = R"( enum { idHillshadePrepareDrawableUBO = idDrawableReservedVertexOnlyUBO, @@ -31,19 +33,10 @@ struct alignas(16) HillshadePrepareTilePropsUBO { }; static_assert(sizeof(HillshadePrepareTilePropsUBO) == 2 * 16, "wrong size"); -)" +)"_cts; -template <> -struct ShaderSource { - static constexpr auto name = "HillshadePrepareShader"; - static constexpr auto vertexMainFunction = "vertexMain"; - static constexpr auto fragmentMainFunction = "fragmentMain"; +constexpr auto hillshadePrepareShaderSource = hillshadePrepareShaderPrelude + R"( - static const std::array attributes; - static constexpr std::array instanceAttributes{}; - static const std::array textures; - - static constexpr auto source = HILLSHADE_PREPARE_SHADER_PRELUDE R"( struct VertexStage { short2 pos [[attribute(hillshadePrepareUBOCount + 0)]]; short2 texture_pos [[attribute(hillshadePrepareUBOCount + 1)]]; @@ -138,7 +131,19 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], return half4(color); } -)"; +)"_cts; + +template <> +struct ShaderSource { + static constexpr auto name = "HillshadePrepareShader"; + static constexpr auto vertexMainFunction = "vertexMain"; + static constexpr auto fragmentMainFunction = "fragmentMain"; + + static const std::array attributes; + static constexpr std::array instanceAttributes{}; + static const std::array textures; + + static constexpr auto source = hillshadePrepareShaderSource.as_string_view(); }; } // namespace shaders diff --git a/include/mbgl/shaders/mtl/line.hpp b/include/mbgl/shaders/mtl/line.hpp index b95c3d0c666..1f1991a3561 100644 --- a/include/mbgl/shaders/mtl/line.hpp +++ b/include/mbgl/shaders/mtl/line.hpp @@ -3,12 +3,14 @@ #include #include #include +#include namespace mbgl { namespace shaders { -#define LINE_SHADER_COMMON \ - R"( +using mbgl::util::operator""_cts; + +constexpr auto lineShaderCommon = R"( enum { idLineDrawableUBO = idDrawableReservedVertexOnlyUBO, @@ -171,19 +173,10 @@ union LineTilePropsUnionUBO { LineSDFTilePropsUBO lineSDFTilePropsUBO; }; -)" +)"_cts; -template <> -struct ShaderSource { - static constexpr auto name = "LineShader"; - static constexpr auto vertexMainFunction = "vertexMain"; - static constexpr auto fragmentMainFunction = "fragmentMain"; +constexpr auto lineShaderSource = lineShaderCommon + R"( - static const std::array attributes; - static constexpr std::array instanceAttributes{}; - static const std::array textures; - - static constexpr auto source = LINE_SHADER_COMMON R"( struct VertexStage { short2 pos_normal [[attribute(lineUBOCount + 0)]]; uchar4 data [[attribute(lineUBOCount + 1)]]; @@ -348,20 +341,23 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], return half4(color * (alpha * opacity)); } -)"; -}; +)"_cts; template <> -struct ShaderSource { - static constexpr auto name = "LineGradientShader"; +struct ShaderSource { + static constexpr auto name = "LineShader"; static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; - static const std::array attributes; + static const std::array attributes; static constexpr std::array instanceAttributes{}; - static const std::array textures; + static const std::array textures; + + static constexpr auto source = lineShaderSource.as_string_view(); +}; + +constexpr auto lineGradientShaderSource = lineShaderCommon + R"( - static constexpr auto source = LINE_SHADER_COMMON R"( struct VertexStage { short2 pos_normal [[attribute(lineUBOCount + 0)]]; uchar4 data [[attribute(lineUBOCount + 1)]]; @@ -513,20 +509,23 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], return half4(color * (alpha * opacity)); } -)"; -}; +)"_cts; template <> -struct ShaderSource { - static constexpr auto name = "LinePatternShader"; +struct ShaderSource { + static constexpr auto name = "LineGradientShader"; static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; - static const std::array attributes; + static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; - static constexpr auto source = LINE_SHADER_COMMON R"( + static constexpr auto source = lineGradientShaderSource.as_string_view(); +}; + +constexpr auto linePatternShaderSource = lineShaderCommon + R"( + struct VertexStage { short2 pos_normal [[attribute(lineUBOCount + 0)]]; uchar4 data [[attribute(lineUBOCount + 1)]]; @@ -748,12 +747,11 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], return half4(color * alpha * opacity); } -)"; -}; +)"_cts; template <> -struct ShaderSource { - static constexpr auto name = "LineSDFShader"; +struct ShaderSource { + static constexpr auto name = "LinePatternShader"; static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; @@ -761,7 +759,11 @@ struct ShaderSource { static constexpr std::array instanceAttributes{}; static const std::array textures; - static constexpr auto source = LINE_SHADER_COMMON R"( + static constexpr auto source = linePatternShaderSource.as_string_view(); +}; + +constexpr auto lineSDFShaderSource = lineShaderCommon + R"( + struct VertexStage { short2 pos_normal [[attribute(lineUBOCount + 0)]]; uchar4 data [[attribute(lineUBOCount + 1)]]; @@ -967,7 +969,19 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], return half4(color * (alpha * opacity)); } -)"; +)"_cts; + +template <> +struct ShaderSource { + static constexpr auto name = "LineSDFShader"; + static constexpr auto vertexMainFunction = "vertexMain"; + static constexpr auto fragmentMainFunction = "fragmentMain"; + + static const std::array attributes; + static constexpr std::array instanceAttributes{}; + static const std::array textures; + + static constexpr auto source = lineSDFShaderSource.as_string_view(); }; } // namespace shaders diff --git a/include/mbgl/shaders/mtl/raster.hpp b/include/mbgl/shaders/mtl/raster.hpp index 22b1e995512..74167e8997f 100644 --- a/include/mbgl/shaders/mtl/raster.hpp +++ b/include/mbgl/shaders/mtl/raster.hpp @@ -3,12 +3,14 @@ #include #include #include +#include namespace mbgl { namespace shaders { -#define RASTER_SHADER_PRELUDE \ - R"( +using mbgl::util::operator""_cts; + +constexpr auto rasterShaderPrelude = R"( enum { idRasterDrawableUBO = idDrawableReservedVertexOnlyUBO, @@ -40,19 +42,9 @@ struct alignas(16) RasterEvaluatedPropsUBO { }; static_assert(sizeof(RasterEvaluatedPropsUBO) == 4 * 16, "wrong size"); -)" - -template <> -struct ShaderSource { - static constexpr auto name = "RasterShader"; - static constexpr auto vertexMainFunction = "vertexMain"; - static constexpr auto fragmentMainFunction = "fragmentMain"; - - static const std::array attributes; - static constexpr std::array instanceAttributes{}; - static const std::array textures; +)"_cts; - static constexpr auto source = RASTER_SHADER_PRELUDE R"( +constexpr auto rasterShaderSource = rasterShaderPrelude + R"( struct VertexStage { short2 pos [[attribute(rasterUBOCount + 0)]]; @@ -131,7 +123,19 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], return half4(half3(mix(high_vec, low_vec, rgb) * color.a), color.a); } -)"; +)"_cts; + +template <> +struct ShaderSource { + static constexpr auto name = "RasterShader"; + static constexpr auto vertexMainFunction = "vertexMain"; + static constexpr auto fragmentMainFunction = "fragmentMain"; + + static const std::array attributes; + static constexpr std::array instanceAttributes{}; + static const std::array textures; + + static constexpr auto source = rasterShaderSource.as_string_view(); }; } // namespace shaders diff --git a/include/mbgl/shaders/mtl/symbol.hpp b/include/mbgl/shaders/mtl/symbol.hpp index e3e9bcf9158..6f1a0c41794 100644 --- a/include/mbgl/shaders/mtl/symbol.hpp +++ b/include/mbgl/shaders/mtl/symbol.hpp @@ -3,12 +3,14 @@ #include #include #include +#include namespace mbgl { namespace shaders { -#define SYMBOL_SHADER_COMMON \ - R"( +using mbgl::util::operator""_cts; + +constexpr auto symbolShaderCommon = R"( enum { idSymbolDrawableUBO = idDrawableReservedVertexOnlyUBO, @@ -71,19 +73,10 @@ struct alignas(16) SymbolEvaluatedPropsUBO { }; static_assert(sizeof(SymbolEvaluatedPropsUBO) == 6 * 16, "wrong size"); -)" +)"_cts; -template <> -struct ShaderSource { - static constexpr auto name = "SymbolIconShader"; - static constexpr auto vertexMainFunction = "vertexMain"; - static constexpr auto fragmentMainFunction = "fragmentMain"; +constexpr auto symbolIconShaderSource = symbolShaderCommon + R"( - static const std::array attributes; - static constexpr std::array instanceAttributes{}; - static const std::array textures; - - static constexpr auto source = SYMBOL_SHADER_COMMON R"( struct VertexStage { float4 pos_offset [[attribute(symbolUBOCount + 0)]]; float4 data [[attribute(symbolUBOCount + 1)]]; @@ -206,20 +199,23 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], return half4(image.sample(image_sampler, float2(in.tex)) * opacity); } -)"; -}; +)"_cts; template <> -struct ShaderSource { - static constexpr auto name = "SymbolSDFIconShader"; +struct ShaderSource { + static constexpr auto name = "SymbolIconShader"; static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; - static const std::array attributes; + static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; - static constexpr auto source = SYMBOL_SHADER_COMMON R"( + static constexpr auto source = symbolIconShaderSource.as_string_view(); +}; + +constexpr auto symbolSDFIconShaderSource = symbolShaderCommon + R"( + struct VertexStage { float4 pos_offset [[attribute(symbolUBOCount + 0)]]; float4 data [[attribute(symbolUBOCount + 1)]]; @@ -413,20 +409,23 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], return half4(color * (alpha * opacity * in.fade_opacity)); } -)"; -}; +)"_cts; template <> -struct ShaderSource { - static constexpr auto name = "SymbolTextAndIconShader"; +struct ShaderSource { + static constexpr auto name = "SymbolSDFIconShader"; static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; - static const std::array attributes; + static const std::array attributes; static constexpr std::array instanceAttributes{}; - static const std::array textures; + static const std::array textures; + + static constexpr auto source = symbolSDFIconShaderSource.as_string_view(); +}; + +constexpr auto symbolTextAndIconShaderSource = symbolShaderCommon + R"( - static constexpr auto source = SYMBOL_SHADER_COMMON R"( #define SDF 1.0 #define ICON 0.0 @@ -637,7 +636,19 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], return half4(color * (alpha * opacity * in.fade_opacity)); } -)"; +)"_cts; + +template <> +struct ShaderSource { + static constexpr auto name = "SymbolTextAndIconShader"; + static constexpr auto vertexMainFunction = "vertexMain"; + static constexpr auto fragmentMainFunction = "fragmentMain"; + + static const std::array attributes; + static constexpr std::array instanceAttributes{}; + static const std::array textures; + + static constexpr auto source = symbolTextAndIconShaderSource.as_string_view(); }; } // namespace shaders diff --git a/include/mbgl/shaders/mtl/widevector.hpp b/include/mbgl/shaders/mtl/widevector.hpp index ba18276c5c6..7b1612834d5 100644 --- a/include/mbgl/shaders/mtl/widevector.hpp +++ b/include/mbgl/shaders/mtl/widevector.hpp @@ -3,12 +3,14 @@ #include #include #include +#include namespace mbgl { namespace shaders { -#define WIDEVECTOR_SHADER_PRELUDE \ - R"( +using mbgl::util::operator""_cts; + +constexpr auto wideVectorShaderPrelude = R"( enum { idWideVectorUniformsUBO = idDrawableReservedVertexOnlyUBO, @@ -16,19 +18,10 @@ enum { wideVectorUBOCount }; -)" +)"_cts; -template <> -struct ShaderSource { - static constexpr auto name = "WideVectorShader"; - static constexpr auto vertexMainFunction = "vertexTri_wideVecPerf"; - static constexpr auto fragmentMainFunction = "fragmentTri_wideVecPerf"; +constexpr auto wideVectorShaderSource = wideVectorShaderPrelude + R"( - static const std::array attributes; - static const std::array instanceAttributes; - static const std::array textures; - - static constexpr auto source = WIDEVECTOR_SHADER_PRELUDE R"( #include namespace WhirlyKitShader @@ -579,7 +572,19 @@ fragment float4 fragmentTri_wideVecPerf( return vert.color * float4(1,1,1,edgeAlpha * patternAlpha * roundAlpha); } -)"; +)"_cts; + +template <> +struct ShaderSource { + static constexpr auto name = "WideVectorShader"; + static constexpr auto vertexMainFunction = "vertexTri_wideVecPerf"; + static constexpr auto fragmentMainFunction = "fragmentTri_wideVecPerf"; + + static const std::array attributes; + static const std::array instanceAttributes; + static const std::array textures; + + static constexpr auto source = wideVectorShaderSource.as_string_view(); }; } // namespace shaders From b13614779b0fe5e8636a523533ef0912006356a6 Mon Sep 17 00:00:00 2001 From: Alex Cristici Date: Thu, 9 Jan 2025 17:31:11 +0200 Subject: [PATCH 5/7] Removed compile-time string and split shader code in prelude and source. --- include/mbgl/shaders/mtl/background.hpp | 54 +++++------ include/mbgl/shaders/mtl/circle.hpp | 32 +++---- include/mbgl/shaders/mtl/clipping_mask.hpp | 35 +++---- include/mbgl/shaders/mtl/collision.hpp | 49 +++++----- .../mbgl/shaders/mtl/custom_symbol_icon.hpp | 32 +++---- include/mbgl/shaders/mtl/debug.hpp | 32 +++---- include/mbgl/shaders/mtl/fill.hpp | 95 +++++++++---------- include/mbgl/shaders/mtl/fill_extrusion.hpp | 51 +++++----- include/mbgl/shaders/mtl/heatmap.hpp | 32 +++---- include/mbgl/shaders/mtl/heatmap_texture.hpp | 32 +++---- include/mbgl/shaders/mtl/hillshade.hpp | 32 +++---- .../mbgl/shaders/mtl/hillshade_prepare.hpp | 32 +++---- include/mbgl/shaders/mtl/line.hpp | 80 ++++++++-------- include/mbgl/shaders/mtl/raster.hpp | 32 +++---- include/mbgl/shaders/mtl/shader_group.hpp | 3 +- include/mbgl/shaders/mtl/symbol.hpp | 66 ++++++------- include/mbgl/shaders/mtl/widevector.hpp | 32 +++---- include/mbgl/util/string.hpp | 60 ------------ 18 files changed, 319 insertions(+), 462 deletions(-) diff --git a/include/mbgl/shaders/mtl/background.hpp b/include/mbgl/shaders/mtl/background.hpp index 4f189312306..2457d740aea 100644 --- a/include/mbgl/shaders/mtl/background.hpp +++ b/include/mbgl/shaders/mtl/background.hpp @@ -3,14 +3,11 @@ #include #include #include -#include namespace mbgl { namespace shaders { -using mbgl::util::operator""_cts; - -constexpr auto backgroundShaderCommon = R"( +constexpr auto backgroundShaderPrelude = R"( enum { idBackgroundDrawableUBO = idDrawableReservedVertexOnlyUBO, @@ -74,12 +71,20 @@ union BackgroundDrawableUnionUBO { BackgroundPatternDrawableUBO backgroundPatternDrawableUBO; }; -)"_cts; +)"; + +template <> +struct ShaderSource { + static constexpr auto name = "BackgroundShader"; + static constexpr auto vertexMainFunction = "vertexMain"; + static constexpr auto fragmentMainFunction = "fragmentMain"; -constexpr auto backgroundShaderSource = backgroundShaderCommon + R"( + static const std::array attributes; + static constexpr std::array instanceAttributes{}; + static const std::array textures; -#include -using namespace metal; + static constexpr auto prelude = backgroundShaderPrelude; + static constexpr auto source = R"( struct VertexStage { short2 position [[attribute(backgroundUBOCount + 0)]]; @@ -108,25 +113,22 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], return half4(props.color * props.opacity); } -)"_cts; +)"; +}; + template <> -struct ShaderSource { - static constexpr auto name = "BackgroundShader"; +struct ShaderSource { + static constexpr auto name = "BackgroundPatternShader"; static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; static const std::array attributes; static constexpr std::array instanceAttributes{}; - static const std::array textures; - - static constexpr auto source = backgroundShaderSource.as_string_view(); -}; - -constexpr auto backgroundPatternShaderSource = backgroundShaderCommon + R"( + static const std::array textures; -#include -using namespace metal; + static constexpr auto prelude = backgroundShaderPrelude; + static constexpr auto source = R"( struct VertexStage { short2 position [[attribute(backgroundUBOCount + 0)]]; @@ -182,19 +184,7 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], return half4(mix(color1, color2, props.mix) * props.opacity); } -)"_cts; - -template <> -struct ShaderSource { - static constexpr auto name = "BackgroundPatternShader"; - static constexpr auto vertexMainFunction = "vertexMain"; - static constexpr auto fragmentMainFunction = "fragmentMain"; - - static const std::array attributes; - static constexpr std::array instanceAttributes{}; - static const std::array textures; - - static constexpr auto source = backgroundPatternShaderSource.as_string_view(); +)"; }; } // namespace shaders diff --git a/include/mbgl/shaders/mtl/circle.hpp b/include/mbgl/shaders/mtl/circle.hpp index 44c89e56df4..7575f39bd83 100644 --- a/include/mbgl/shaders/mtl/circle.hpp +++ b/include/mbgl/shaders/mtl/circle.hpp @@ -3,13 +3,10 @@ #include #include #include -#include namespace mbgl { namespace shaders { -using mbgl::util::operator""_cts; - constexpr auto circleShaderPrelude = R"( enum { @@ -53,9 +50,20 @@ struct alignas(16) CircleEvaluatedPropsUBO { }; static_assert(sizeof(CircleEvaluatedPropsUBO) == 4 * 16, "wrong size"); -)"_cts; +)"; + +template <> +struct ShaderSource { + static constexpr auto name = "CircleShader"; + static constexpr auto vertexMainFunction = "vertexMain"; + static constexpr auto fragmentMainFunction = "fragmentMain"; + + static const std::array attributes; + static constexpr std::array instanceAttributes{}; + static const std::array textures; -constexpr auto circleShaderSource = circleShaderPrelude + R"( + static constexpr auto prelude = circleShaderPrelude; + static constexpr auto source = R"( struct VertexStage { short2 position [[attribute(circleUBOCount + 0)]]; @@ -244,19 +252,7 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], return half4(opacity_t * mix(color * opacity, stroke_color * stroke_opacity, color_t)); } -)"_cts; - -template <> -struct ShaderSource { - static constexpr auto name = "CircleShader"; - static constexpr auto vertexMainFunction = "vertexMain"; - static constexpr auto fragmentMainFunction = "fragmentMain"; - - static const std::array attributes; - static constexpr std::array instanceAttributes{}; - static const std::array textures; - - static constexpr auto source = circleShaderSource.as_string_view(); +)"; }; } // namespace shaders diff --git a/include/mbgl/shaders/mtl/clipping_mask.hpp b/include/mbgl/shaders/mtl/clipping_mask.hpp index 69c7b432829..e0f5d8b6173 100644 --- a/include/mbgl/shaders/mtl/clipping_mask.hpp +++ b/include/mbgl/shaders/mtl/clipping_mask.hpp @@ -2,13 +2,10 @@ #include #include -#include namespace mbgl { namespace shaders { -using mbgl::util::operator""_cts; - struct alignas(16) ClipUBO { /* 0 */ std::array matrix; /* 64 */ std::uint32_t stencil_ref; @@ -21,9 +18,6 @@ static_assert(sizeof(ClipUBO) == 5 * 16); constexpr auto clippingMaskShaderPrelude = R"( -#include -using namespace metal; - enum { idClippingMaskUBO = idDrawableReservedVertexOnlyUBO, clippingMaskUBOCount = drawableReservedUBOCount @@ -39,9 +33,20 @@ struct alignas(16) ClipUBO { }; static_assert(sizeof(ClipUBO) == 5 * 16, "wrong size"); -)"_cts; +)"; + +template <> +struct ShaderSource { + static constexpr auto name = "ClippingMaskProgram"; + static constexpr auto vertexMainFunction = "vertexMain"; + static constexpr auto fragmentMainFunction = "fragmentMain"; + + static const std::array attributes; + static constexpr std::array instanceAttributes{}; + static const std::array textures; -constexpr auto clippingMaskShaderSource = clippingMaskShaderPrelude + R"( + static constexpr auto prelude = clippingMaskShaderPrelude; + static constexpr auto source = R"( struct VertexStage { short2 position [[attribute(clippingMaskUBOCount + 0)]]; @@ -64,19 +69,7 @@ FragmentStage vertex vertexMain(VertexStage in [[stage_in]], half4 fragment fragmentMain(FragmentStage in [[stage_in]]) { return half4(1.0); } -)"_cts; - -template <> -struct ShaderSource { - static constexpr auto name = "ClippingMaskProgram"; - static constexpr auto vertexMainFunction = "vertexMain"; - static constexpr auto fragmentMainFunction = "fragmentMain"; - - static const std::array attributes; - static constexpr std::array instanceAttributes{}; - static const std::array textures; - - static constexpr auto source = clippingMaskShaderSource.as_string_view(); +)"; }; } // namespace shaders diff --git a/include/mbgl/shaders/mtl/collision.hpp b/include/mbgl/shaders/mtl/collision.hpp index 4cc599af816..79a21da87db 100644 --- a/include/mbgl/shaders/mtl/collision.hpp +++ b/include/mbgl/shaders/mtl/collision.hpp @@ -3,14 +3,11 @@ #include #include #include -#include namespace mbgl { namespace shaders { -using mbgl::util::operator""_cts; - -constexpr auto collisionShaderCommon = R"( +constexpr auto collisionShaderPrelude = R"( enum { idCollisionDrawableUBO = idDrawableReservedVertexOnlyUBO, @@ -32,9 +29,20 @@ struct alignas(16) CollisionTilePropsUBO { }; static_assert(sizeof(CollisionTilePropsUBO) == 16, "wrong size"); -)"_cts; +)"; + +template <> +struct ShaderSource { + static constexpr auto name = "CollisionBoxShader"; + static constexpr auto vertexMainFunction = "vertexMain"; + static constexpr auto fragmentMainFunction = "fragmentMain"; + + static const std::array attributes; + static constexpr std::array instanceAttributes{}; + static const std::array textures; -constexpr auto collisionBoxShaderSource = collisionShaderCommon + R"( + static constexpr auto prelude = collisionShaderPrelude; + static constexpr auto source = R"( struct VertexStage { short2 pos [[attribute(collisionUBOCount + 0)]]; @@ -94,22 +102,21 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]]) { return half4(color); } -)"_cts; +)"; +}; template <> -struct ShaderSource { - static constexpr auto name = "CollisionBoxShader"; +struct ShaderSource { + static constexpr auto name = "CollisionCircleShader"; static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; - static const std::array attributes; + static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; - static constexpr auto source = collisionBoxShaderSource.as_string_view(); -}; - -constexpr auto collisionCircleShaderSource = collisionShaderCommon + R"( + static constexpr auto prelude = collisionShaderPrelude; + static constexpr auto source = R"( struct VertexStage { short2 pos [[attribute(collisionUBOCount + 0)]]; @@ -189,19 +196,7 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], return half4(opacity_t * color); } -)"_cts; - -template <> -struct ShaderSource { - static constexpr auto name = "CollisionCircleShader"; - static constexpr auto vertexMainFunction = "vertexMain"; - static constexpr auto fragmentMainFunction = "fragmentMain"; - - static const std::array attributes; - static constexpr std::array instanceAttributes{}; - static const std::array textures; - - static constexpr auto source = collisionCircleShaderSource.as_string_view(); +)"; }; } // namespace shaders diff --git a/include/mbgl/shaders/mtl/custom_symbol_icon.hpp b/include/mbgl/shaders/mtl/custom_symbol_icon.hpp index 8e8e037d70d..a497f9fdaa2 100644 --- a/include/mbgl/shaders/mtl/custom_symbol_icon.hpp +++ b/include/mbgl/shaders/mtl/custom_symbol_icon.hpp @@ -3,13 +3,10 @@ #include #include #include -#include namespace mbgl { namespace shaders { -using mbgl::util::operator""_cts; - constexpr auto customSymbolIconShaderPrelude = R"( enum { @@ -33,9 +30,20 @@ struct alignas(16) CustomSymbolIconDrawableUBO { }; static_assert(sizeof(CustomSymbolIconDrawableUBO) == 7 * 16, "wrong size"); -)"_cts; +)"; + +template <> +struct ShaderSource { + static constexpr auto name = "CustomSymbolIconShader"; + static constexpr auto vertexMainFunction = "vertexMain"; + static constexpr auto fragmentMainFunction = "fragmentMain"; + + static const std::array attributes; + static constexpr std::array instanceAttributes{}; + static const std::array textures; -constexpr auto customSymbolIconShaderSource = customSymbolIconShaderPrelude + R"( + static constexpr auto prelude = customSymbolIconShaderPrelude; + static constexpr auto source = R"( struct VertexStage { float2 a_pos [[attribute(customSymbolUBOCount + 0)]]; @@ -100,19 +108,7 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], return half4(image.sample(image_sampler, float2(in.tex))); } -)"_cts; - -template <> -struct ShaderSource { - static constexpr auto name = "CustomSymbolIconShader"; - static constexpr auto vertexMainFunction = "vertexMain"; - static constexpr auto fragmentMainFunction = "fragmentMain"; - - static const std::array attributes; - static constexpr std::array instanceAttributes{}; - static const std::array textures; - - static constexpr auto source = customSymbolIconShaderSource.as_string_view(); +)"; }; } // namespace shaders diff --git a/include/mbgl/shaders/mtl/debug.hpp b/include/mbgl/shaders/mtl/debug.hpp index 7d9352c2f22..e252f38636a 100644 --- a/include/mbgl/shaders/mtl/debug.hpp +++ b/include/mbgl/shaders/mtl/debug.hpp @@ -3,13 +3,10 @@ #include #include #include -#include namespace mbgl { namespace shaders { -using mbgl::util::operator""_cts; - constexpr auto debugShaderPrelude = R"( enum { @@ -28,9 +25,20 @@ struct alignas(16) DebugUBO { }; static_assert(sizeof(DebugUBO) == 6 * 16, "wrong size"); -)"_cts; +)"; + +template <> +struct ShaderSource { + static constexpr auto name = "DebugShader"; + static constexpr auto vertexMainFunction = "vertexMain"; + static constexpr auto fragmentMainFunction = "fragmentMain"; + + static const std::array attributes; + static constexpr std::array instanceAttributes{}; + static const std::array textures; -constexpr auto debugShaderSource = debugShaderPrelude + R"( + static constexpr auto prelude = debugShaderPrelude; + static constexpr auto source = R"( struct VertexStage { short2 pos [[attribute(debugUBOCount + 0)]]; @@ -65,19 +73,7 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], float4 color = mix(debug.color, overlay_color, overlay_color.a); return half4(color); } -)"_cts; - -template <> -struct ShaderSource { - static constexpr auto name = "DebugShader"; - static constexpr auto vertexMainFunction = "vertexMain"; - static constexpr auto fragmentMainFunction = "fragmentMain"; - - static const std::array attributes; - static constexpr std::array instanceAttributes{}; - static const std::array textures; - - static constexpr auto source = debugShaderSource.as_string_view(); +)"; }; } // namespace shaders diff --git a/include/mbgl/shaders/mtl/fill.hpp b/include/mbgl/shaders/mtl/fill.hpp index b7cb6c9d70b..b507c380a3e 100644 --- a/include/mbgl/shaders/mtl/fill.hpp +++ b/include/mbgl/shaders/mtl/fill.hpp @@ -3,14 +3,11 @@ #include #include #include -#include namespace mbgl { namespace shaders { -using mbgl::util::operator""_cts; - -constexpr auto fillShaderCommon = R"( +constexpr auto fillShaderPrelude = R"( enum { idFillDrawableUBO = idDrawableReservedVertexOnlyUBO, @@ -141,9 +138,20 @@ union FillTilePropsUnionUBO { FillOutlinePatternTilePropsUBO fillOutlinePatternTilePropsUBO; }; -)"_cts; +)"; -constexpr auto fillShaderSource = fillShaderCommon + R"( +template <> +struct ShaderSource { + static constexpr auto name = "FillShader"; + static constexpr auto vertexMainFunction = "vertexMain"; + static constexpr auto fragmentMainFunction = "fragmentMain"; + + static const std::array attributes; + static constexpr std::array instanceAttributes{}; + static const std::array textures; + + static constexpr auto prelude = fillShaderPrelude; + static constexpr auto source = R"( struct VertexStage { short2 position [[attribute(fillUBOCount + 0)]]; @@ -204,11 +212,12 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], return half4(color * opacity); } -)"_cts; +)"; +}; template <> -struct ShaderSource { - static constexpr auto name = "FillShader"; +struct ShaderSource { + static constexpr auto name = "FillOutlineShader"; static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; @@ -216,10 +225,8 @@ struct ShaderSource { static constexpr std::array instanceAttributes{}; static const std::array textures; - static constexpr auto source = fillShaderSource.as_string_view(); -}; - -constexpr auto fillOutlineShaderSource = fillShaderCommon + R"( + static constexpr auto prelude = fillShaderPrelude; + static constexpr auto source = R"( struct VertexStage { short2 position [[attribute(fillUBOCount + 0)]]; @@ -284,22 +291,22 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], return half4(color * opacity); } -)"_cts; +)"; +}; + template <> -struct ShaderSource { - static constexpr auto name = "FillOutlineShader"; +struct ShaderSource { + static constexpr auto name = "FillPatternShader"; static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; - static const std::array attributes; + static const std::array attributes; static constexpr std::array instanceAttributes{}; - static const std::array textures; - - static constexpr auto source = fillOutlineShaderSource.as_string_view(); -}; + static const std::array textures; -constexpr auto fillPatternShaderSource = fillShaderCommon + R"( + static constexpr auto prelude = fillShaderPrelude; + static constexpr auto source = R"( struct VertexStage { short2 position [[attribute(fillUBOCount + 0)]]; @@ -428,11 +435,12 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], return half4(mix(color1, color2, props.fade) * opacity); } -)"_cts; +)"; +}; template <> -struct ShaderSource { - static constexpr auto name = "FillPatternShader"; +struct ShaderSource { + static constexpr auto name = "FillOutlinePatternShader"; static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; @@ -440,10 +448,8 @@ struct ShaderSource { static constexpr std::array instanceAttributes{}; static const std::array textures; - static constexpr auto source = fillPatternShaderSource.as_string_view(); -}; - -constexpr auto fillOutlinePatternShaderSource = fillShaderCommon + R"( + static constexpr auto prelude = fillShaderPrelude; + static constexpr auto source = R"( struct VertexStage { short2 position [[attribute(fillUBOCount + 0)]]; @@ -584,22 +590,21 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], return half4(mix(color1, color2, props.fade) * opacity); } -)"_cts; +)"; +}; template <> -struct ShaderSource { - static constexpr auto name = "FillOutlinePatternShader"; +struct ShaderSource { + static constexpr auto name = "FillOutlineTriangulatedShader"; static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; - static const std::array attributes; + static const std::array attributes; static constexpr std::array instanceAttributes{}; - static const std::array textures; - - static constexpr auto source = fillOutlinePatternShaderSource.as_string_view(); -}; + static const std::array textures; -constexpr auto fillOutlineTriangulatedShaderSource = fillShaderCommon + R"( + static constexpr auto prelude = fillShaderPrelude; + static constexpr auto source = R"( struct VertexStage { short2 pos_normal [[attribute(fillUBOCount + 0)]]; @@ -668,19 +673,7 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], return half4(props.outline_color * (alpha * props.opacity)); } -)"_cts; - -template <> -struct ShaderSource { - static constexpr auto name = "FillOutlineTriangulatedShader"; - static constexpr auto vertexMainFunction = "vertexMain"; - static constexpr auto fragmentMainFunction = "fragmentMain"; - - static const std::array attributes; - static constexpr std::array instanceAttributes{}; - static const std::array textures; - - static constexpr auto source = fillOutlineTriangulatedShaderSource.as_string_view(); +)"; }; } // namespace shaders diff --git a/include/mbgl/shaders/mtl/fill_extrusion.hpp b/include/mbgl/shaders/mtl/fill_extrusion.hpp index 940f1c100b8..0ac9350ebd4 100644 --- a/include/mbgl/shaders/mtl/fill_extrusion.hpp +++ b/include/mbgl/shaders/mtl/fill_extrusion.hpp @@ -3,14 +3,11 @@ #include #include #include -#include namespace mbgl { namespace shaders { -using mbgl::util::operator""_cts; - -constexpr auto fillExtrusionShaderCommon = R"( +constexpr auto fillExtrusionShaderPrelude = R"( enum { idFillExtrusionDrawableUBO = idDrawableReservedVertexOnlyUBO, @@ -64,9 +61,20 @@ struct alignas(16) FillExtrusionPropsUBO { }; static_assert(sizeof(FillExtrusionPropsUBO) == 5 * 16, "wrong size"); -)"_cts; +)"; -constexpr auto fillExtrusionShaderSource = fillExtrusionShaderCommon + R"( +template <> +struct ShaderSource { + static constexpr auto name = "FillExtrusionShader"; + static constexpr auto vertexMainFunction = "vertexMain"; + static constexpr auto fragmentMainFunction = "fragmentMain"; + + static const std::array attributes; + static constexpr std::array instanceAttributes{}; + static const std::array textures; + + static constexpr auto prelude = fillExtrusionShaderPrelude; + static constexpr auto source = R"( struct VertexStage { short2 pos [[attribute(fillExtrusionUBOCount + 0)]]; @@ -173,22 +181,21 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], fragment FragmentOutput fragmentMain(FragmentStage in [[stage_in]]) { return { in.color/*, in.position.z*/ }; } -)"_cts; +)"; +}; template <> -struct ShaderSource { - static constexpr auto name = "FillExtrusionShader"; +struct ShaderSource { + static constexpr auto name = "FillExtrusionPatternShader"; static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; - static const std::array attributes; + static const std::array attributes; static constexpr std::array instanceAttributes{}; - static const std::array textures; - - static constexpr auto source = fillExtrusionShaderSource.as_string_view(); -}; + static const std::array textures; -constexpr auto fillExtrusionPatternShaderSource = fillExtrusionShaderCommon + R"( + static constexpr auto prelude = fillExtrusionShaderPrelude; + static constexpr auto source = R"( struct VertexStage { short2 pos [[attribute(fillExtrusionUBOCount + 0)]]; @@ -360,19 +367,7 @@ fragment FragmentOutput fragmentMain(FragmentStage in [[stage_in]], return {half4(mix(color1, color2, props.fade) * in.lighting)/*, in.position.z*/}; } -)"_cts; - -template <> -struct ShaderSource { - static constexpr auto name = "FillExtrusionPatternShader"; - static constexpr auto vertexMainFunction = "vertexMain"; - static constexpr auto fragmentMainFunction = "fragmentMain"; - - static const std::array attributes; - static constexpr std::array instanceAttributes{}; - static const std::array textures; - - static constexpr auto source = fillExtrusionPatternShaderSource.as_string_view(); +)"; }; } // namespace shaders diff --git a/include/mbgl/shaders/mtl/heatmap.hpp b/include/mbgl/shaders/mtl/heatmap.hpp index e791eef91a0..ead80d8ab33 100644 --- a/include/mbgl/shaders/mtl/heatmap.hpp +++ b/include/mbgl/shaders/mtl/heatmap.hpp @@ -3,13 +3,10 @@ #include #include #include -#include namespace mbgl { namespace shaders { -using mbgl::util::operator""_cts; - constexpr auto heatmapShaderPrelude = R"( enum { @@ -40,9 +37,20 @@ struct alignas(16) HeatmapEvaluatedPropsUBO { }; static_assert(sizeof(HeatmapEvaluatedPropsUBO) == 16, "wrong size"); -)"_cts; +)"; + +template <> +struct ShaderSource { + static constexpr auto name = "HeatmapShader"; + static constexpr auto vertexMainFunction = "vertexMain"; + static constexpr auto fragmentMainFunction = "fragmentMain"; + + static const std::array attributes; + static constexpr std::array instanceAttributes{}; + static const std::array textures; -constexpr auto heatmapShaderSource = heatmapShaderPrelude + R"( + static constexpr auto prelude = heatmapShaderPrelude; + static constexpr auto source = R"( struct VertexStage { short2 pos [[attribute(heatmapUBOCount + 0)]]; @@ -133,19 +141,7 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], return half4(val, 1.0, 1.0, 1.0); } -)"_cts; - -template <> -struct ShaderSource { - static constexpr auto name = "HeatmapShader"; - static constexpr auto vertexMainFunction = "vertexMain"; - static constexpr auto fragmentMainFunction = "fragmentMain"; - - static const std::array attributes; - static constexpr std::array instanceAttributes{}; - static const std::array textures; - - static constexpr auto source = heatmapShaderSource.as_string_view(); +)"; }; } // namespace shaders diff --git a/include/mbgl/shaders/mtl/heatmap_texture.hpp b/include/mbgl/shaders/mtl/heatmap_texture.hpp index f614b54517d..767b77847ed 100644 --- a/include/mbgl/shaders/mtl/heatmap_texture.hpp +++ b/include/mbgl/shaders/mtl/heatmap_texture.hpp @@ -3,13 +3,10 @@ #include #include #include -#include namespace mbgl { namespace shaders { -using mbgl::util::operator""_cts; - constexpr auto heatmapTextureShaderPrelude = R"( enum { @@ -27,9 +24,20 @@ struct alignas(16) HeatmapTexturePropsUBO { }; static_assert(sizeof(HeatmapTexturePropsUBO) == 5 * 16, "wrong size"); -)"_cts; +)"; + +template <> +struct ShaderSource { + static constexpr auto name = "HeatmapTextureShader"; + static constexpr auto vertexMainFunction = "vertexMain"; + static constexpr auto fragmentMainFunction = "fragmentMain"; + + static const std::array attributes; + static constexpr std::array instanceAttributes{}; + static const std::array textures; -constexpr auto heatmapTextureShaderSource = heatmapTextureShaderPrelude + R"( + static constexpr auto prelude = heatmapTextureShaderPrelude; + static constexpr auto source = R"( struct VertexStage { short2 pos [[attribute(heatmapTextureUBOCount + 0)]]; @@ -68,19 +76,7 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], float4 color = color_ramp.sample(color_ramp_sampler, float2(t, 0.5)); return half4(color * props.opacity); } -)"_cts; - -template <> -struct ShaderSource { - static constexpr auto name = "HeatmapTextureShader"; - static constexpr auto vertexMainFunction = "vertexMain"; - static constexpr auto fragmentMainFunction = "fragmentMain"; - - static const std::array attributes; - static constexpr std::array instanceAttributes{}; - static const std::array textures; - - static constexpr auto source = heatmapTextureShaderSource.as_string_view(); +)"; }; } // namespace shaders diff --git a/include/mbgl/shaders/mtl/hillshade.hpp b/include/mbgl/shaders/mtl/hillshade.hpp index 57984d1f033..f51f4b7a7ad 100644 --- a/include/mbgl/shaders/mtl/hillshade.hpp +++ b/include/mbgl/shaders/mtl/hillshade.hpp @@ -3,13 +3,10 @@ #include #include #include -#include namespace mbgl { namespace shaders { -using mbgl::util::operator""_cts; - constexpr auto hillshadeShaderPrelude = R"( enum { @@ -41,9 +38,20 @@ struct alignas(16) HillshadeEvaluatedPropsUBO { }; static_assert(sizeof(HillshadeEvaluatedPropsUBO) == 3 * 16, "wrong size"); -)"_cts; +)"; + +template <> +struct ShaderSource { + static constexpr auto name = "HillshadeShader"; + static constexpr auto vertexMainFunction = "vertexMain"; + static constexpr auto fragmentMainFunction = "fragmentMain"; + + static const std::array attributes; + static constexpr std::array instanceAttributes{}; + static const std::array textures; -constexpr auto hillshadeShaderSource = hillshadeShaderPrelude + R"( + static constexpr auto prelude = hillshadeShaderPrelude; + static constexpr auto source = R"( struct VertexStage { short2 pos [[attribute(hillshadeUBOCount + 0)]]; @@ -121,19 +129,7 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], return half4(color); } -)"_cts; - -template <> -struct ShaderSource { - static constexpr auto name = "HillshadeShader"; - static constexpr auto vertexMainFunction = "vertexMain"; - static constexpr auto fragmentMainFunction = "fragmentMain"; - - static const std::array attributes; - static constexpr std::array instanceAttributes{}; - static const std::array textures; - - static constexpr auto source = hillshadeShaderSource.as_string_view(); +)"; }; } // namespace shaders diff --git a/include/mbgl/shaders/mtl/hillshade_prepare.hpp b/include/mbgl/shaders/mtl/hillshade_prepare.hpp index 1f736503fad..6d7ddcf01a7 100644 --- a/include/mbgl/shaders/mtl/hillshade_prepare.hpp +++ b/include/mbgl/shaders/mtl/hillshade_prepare.hpp @@ -3,13 +3,10 @@ #include #include #include -#include namespace mbgl { namespace shaders { -using mbgl::util::operator""_cts; - constexpr auto hillshadePrepareShaderPrelude = R"( enum { @@ -33,9 +30,20 @@ struct alignas(16) HillshadePrepareTilePropsUBO { }; static_assert(sizeof(HillshadePrepareTilePropsUBO) == 2 * 16, "wrong size"); -)"_cts; +)"; + +template <> +struct ShaderSource { + static constexpr auto name = "HillshadePrepareShader"; + static constexpr auto vertexMainFunction = "vertexMain"; + static constexpr auto fragmentMainFunction = "fragmentMain"; + + static const std::array attributes; + static constexpr std::array instanceAttributes{}; + static const std::array textures; -constexpr auto hillshadePrepareShaderSource = hillshadePrepareShaderPrelude + R"( + static constexpr auto prelude = hillshadePrepareShaderPrelude; + static constexpr auto source = R"( struct VertexStage { short2 pos [[attribute(hillshadePrepareUBOCount + 0)]]; @@ -131,19 +139,7 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], return half4(color); } -)"_cts; - -template <> -struct ShaderSource { - static constexpr auto name = "HillshadePrepareShader"; - static constexpr auto vertexMainFunction = "vertexMain"; - static constexpr auto fragmentMainFunction = "fragmentMain"; - - static const std::array attributes; - static constexpr std::array instanceAttributes{}; - static const std::array textures; - - static constexpr auto source = hillshadePrepareShaderSource.as_string_view(); +)"; }; } // namespace shaders diff --git a/include/mbgl/shaders/mtl/line.hpp b/include/mbgl/shaders/mtl/line.hpp index 1f1991a3561..1cbb845903e 100644 --- a/include/mbgl/shaders/mtl/line.hpp +++ b/include/mbgl/shaders/mtl/line.hpp @@ -3,14 +3,11 @@ #include #include #include -#include namespace mbgl { namespace shaders { -using mbgl::util::operator""_cts; - -constexpr auto lineShaderCommon = R"( +constexpr auto lineShadePrelude = R"( enum { idLineDrawableUBO = idDrawableReservedVertexOnlyUBO, @@ -173,9 +170,20 @@ union LineTilePropsUnionUBO { LineSDFTilePropsUBO lineSDFTilePropsUBO; }; -)"_cts; +)"; -constexpr auto lineShaderSource = lineShaderCommon + R"( +template <> +struct ShaderSource { + static constexpr auto name = "LineShader"; + static constexpr auto vertexMainFunction = "vertexMain"; + static constexpr auto fragmentMainFunction = "fragmentMain"; + + static const std::array attributes; + static constexpr std::array instanceAttributes{}; + static const std::array textures; + + static constexpr auto prelude = lineShadePrelude; + static constexpr auto source = R"( struct VertexStage { short2 pos_normal [[attribute(lineUBOCount + 0)]]; @@ -341,22 +349,22 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], return half4(color * (alpha * opacity)); } -)"_cts; +)"; +}; + template <> -struct ShaderSource { - static constexpr auto name = "LineShader"; +struct ShaderSource { + static constexpr auto name = "LineGradientShader"; static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; - static const std::array attributes; + static const std::array attributes; static constexpr std::array instanceAttributes{}; - static const std::array textures; - - static constexpr auto source = lineShaderSource.as_string_view(); -}; + static const std::array textures; -constexpr auto lineGradientShaderSource = lineShaderCommon + R"( + static constexpr auto prelude = lineShadePrelude; + static constexpr auto source = R"( struct VertexStage { short2 pos_normal [[attribute(lineUBOCount + 0)]]; @@ -509,22 +517,21 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], return half4(color * (alpha * opacity)); } -)"_cts; +)"; +}; template <> -struct ShaderSource { - static constexpr auto name = "LineGradientShader"; +struct ShaderSource { + static constexpr auto name = "LinePatternShader"; static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; - static const std::array attributes; + static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; - static constexpr auto source = lineGradientShaderSource.as_string_view(); -}; - -constexpr auto linePatternShaderSource = lineShaderCommon + R"( + static constexpr auto prelude = lineShadePrelude; + static constexpr auto source = R"( struct VertexStage { short2 pos_normal [[attribute(lineUBOCount + 0)]]; @@ -747,11 +754,12 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], return half4(color * alpha * opacity); } -)"_cts; +)"; +}; template <> -struct ShaderSource { - static constexpr auto name = "LinePatternShader"; +struct ShaderSource { + static constexpr auto name = "LineSDFShader"; static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; @@ -759,10 +767,8 @@ struct ShaderSource { static constexpr std::array instanceAttributes{}; static const std::array textures; - static constexpr auto source = linePatternShaderSource.as_string_view(); -}; - -constexpr auto lineSDFShaderSource = lineShaderCommon + R"( + static constexpr auto prelude = lineShadePrelude; + static constexpr auto source = R"( struct VertexStage { short2 pos_normal [[attribute(lineUBOCount + 0)]]; @@ -969,19 +975,7 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], return half4(color * (alpha * opacity)); } -)"_cts; - -template <> -struct ShaderSource { - static constexpr auto name = "LineSDFShader"; - static constexpr auto vertexMainFunction = "vertexMain"; - static constexpr auto fragmentMainFunction = "fragmentMain"; - - static const std::array attributes; - static constexpr std::array instanceAttributes{}; - static const std::array textures; - - static constexpr auto source = lineSDFShaderSource.as_string_view(); +)"; }; } // namespace shaders diff --git a/include/mbgl/shaders/mtl/raster.hpp b/include/mbgl/shaders/mtl/raster.hpp index 74167e8997f..399d0ca0b46 100644 --- a/include/mbgl/shaders/mtl/raster.hpp +++ b/include/mbgl/shaders/mtl/raster.hpp @@ -3,13 +3,10 @@ #include #include #include -#include namespace mbgl { namespace shaders { -using mbgl::util::operator""_cts; - constexpr auto rasterShaderPrelude = R"( enum { @@ -42,9 +39,20 @@ struct alignas(16) RasterEvaluatedPropsUBO { }; static_assert(sizeof(RasterEvaluatedPropsUBO) == 4 * 16, "wrong size"); -)"_cts; +)"; + +template <> +struct ShaderSource { + static constexpr auto name = "RasterShader"; + static constexpr auto vertexMainFunction = "vertexMain"; + static constexpr auto fragmentMainFunction = "fragmentMain"; + + static const std::array attributes; + static constexpr std::array instanceAttributes{}; + static const std::array textures; -constexpr auto rasterShaderSource = rasterShaderPrelude + R"( + static constexpr auto prelude = rasterShaderPrelude; + static constexpr auto source = R"( struct VertexStage { short2 pos [[attribute(rasterUBOCount + 0)]]; @@ -123,19 +131,7 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], return half4(half3(mix(high_vec, low_vec, rgb) * color.a), color.a); } -)"_cts; - -template <> -struct ShaderSource { - static constexpr auto name = "RasterShader"; - static constexpr auto vertexMainFunction = "vertexMain"; - static constexpr auto fragmentMainFunction = "fragmentMain"; - - static const std::array attributes; - static constexpr std::array instanceAttributes{}; - static const std::array textures; - - static constexpr auto source = rasterShaderSource.as_string_view(); +)"; }; } // namespace shaders diff --git a/include/mbgl/shaders/mtl/shader_group.hpp b/include/mbgl/shaders/mtl/shader_group.hpp index 8492c362a0e..4688592070f 100644 --- a/include/mbgl/shaders/mtl/shader_group.hpp +++ b/include/mbgl/shaders/mtl/shader_group.hpp @@ -48,6 +48,7 @@ class ShaderGroup final : public ShaderGroupBase { std::string_view /*firstAttribName*/) override { using ShaderSource = shaders::ShaderSource; constexpr auto& name = ShaderSource::name; + constexpr auto& prelude = ShaderSource::prelude; constexpr auto& source = ShaderSource::source; constexpr auto& vertMain = ShaderSource::vertexMainFunction; constexpr auto& fragMain = ShaderSource::fragmentMainFunction; @@ -64,7 +65,7 @@ class ShaderGroup final : public ShaderGroupBase { auto& context = static_cast(gfxContext); // C++26 will allow operator+ with std::string and std::string_view - const auto shaderSource = std::string(shaders::prelude) + std::string(source); + const auto shaderSource = std::string(shaders::prelude) + std::string(prelude) + std::string(source); shader = context.createProgram( ShaderID, shaderName, shaderSource, vertMain, fragMain, programParameters, additionalDefines); assert(shader); diff --git a/include/mbgl/shaders/mtl/symbol.hpp b/include/mbgl/shaders/mtl/symbol.hpp index 6f1a0c41794..df3e754dc65 100644 --- a/include/mbgl/shaders/mtl/symbol.hpp +++ b/include/mbgl/shaders/mtl/symbol.hpp @@ -3,14 +3,11 @@ #include #include #include -#include namespace mbgl { namespace shaders { -using mbgl::util::operator""_cts; - -constexpr auto symbolShaderCommon = R"( +constexpr auto symbolShaderPrelude = R"( enum { idSymbolDrawableUBO = idDrawableReservedVertexOnlyUBO, @@ -73,9 +70,20 @@ struct alignas(16) SymbolEvaluatedPropsUBO { }; static_assert(sizeof(SymbolEvaluatedPropsUBO) == 6 * 16, "wrong size"); -)"_cts; +)"; + +template <> +struct ShaderSource { + static constexpr auto name = "SymbolIconShader"; + static constexpr auto vertexMainFunction = "vertexMain"; + static constexpr auto fragmentMainFunction = "fragmentMain"; + + static const std::array attributes; + static constexpr std::array instanceAttributes{}; + static const std::array textures; -constexpr auto symbolIconShaderSource = symbolShaderCommon + R"( + static constexpr auto prelude = symbolShaderPrelude; + static constexpr auto source = R"( struct VertexStage { float4 pos_offset [[attribute(symbolUBOCount + 0)]]; @@ -199,22 +207,21 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], return half4(image.sample(image_sampler, float2(in.tex)) * opacity); } -)"_cts; +)"; +}; template <> -struct ShaderSource { - static constexpr auto name = "SymbolIconShader"; +struct ShaderSource { + static constexpr auto name = "SymbolSDFIconShader"; static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; - static const std::array attributes; + static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; - static constexpr auto source = symbolIconShaderSource.as_string_view(); -}; - -constexpr auto symbolSDFIconShaderSource = symbolShaderCommon + R"( + static constexpr auto prelude = symbolShaderPrelude; + static constexpr auto source = R"( struct VertexStage { float4 pos_offset [[attribute(symbolUBOCount + 0)]]; @@ -409,22 +416,21 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], return half4(color * (alpha * opacity * in.fade_opacity)); } -)"_cts; +)"; +}; template <> -struct ShaderSource { - static constexpr auto name = "SymbolSDFIconShader"; +struct ShaderSource { + static constexpr auto name = "SymbolTextAndIconShader"; static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; - static const std::array attributes; + static const std::array attributes; static constexpr std::array instanceAttributes{}; - static const std::array textures; - - static constexpr auto source = symbolSDFIconShaderSource.as_string_view(); -}; + static const std::array textures; -constexpr auto symbolTextAndIconShaderSource = symbolShaderCommon + R"( + static constexpr auto prelude = symbolShaderPrelude; + static constexpr auto source = R"( #define SDF 1.0 #define ICON 0.0 @@ -636,19 +642,7 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], return half4(color * (alpha * opacity * in.fade_opacity)); } -)"_cts; - -template <> -struct ShaderSource { - static constexpr auto name = "SymbolTextAndIconShader"; - static constexpr auto vertexMainFunction = "vertexMain"; - static constexpr auto fragmentMainFunction = "fragmentMain"; - - static const std::array attributes; - static constexpr std::array instanceAttributes{}; - static const std::array textures; - - static constexpr auto source = symbolTextAndIconShaderSource.as_string_view(); +)"; }; } // namespace shaders diff --git a/include/mbgl/shaders/mtl/widevector.hpp b/include/mbgl/shaders/mtl/widevector.hpp index 7b1612834d5..f312d2dc602 100644 --- a/include/mbgl/shaders/mtl/widevector.hpp +++ b/include/mbgl/shaders/mtl/widevector.hpp @@ -3,13 +3,10 @@ #include #include #include -#include namespace mbgl { namespace shaders { -using mbgl::util::operator""_cts; - constexpr auto wideVectorShaderPrelude = R"( enum { @@ -18,11 +15,20 @@ enum { wideVectorUBOCount }; -)"_cts; +)"; -constexpr auto wideVectorShaderSource = wideVectorShaderPrelude + R"( +template <> +struct ShaderSource { + static constexpr auto name = "WideVectorShader"; + static constexpr auto vertexMainFunction = "vertexTri_wideVecPerf"; + static constexpr auto fragmentMainFunction = "fragmentTri_wideVecPerf"; -#include + static const std::array attributes; + static const std::array instanceAttributes; + static const std::array textures; + + static constexpr auto prelude = wideVectorShaderPrelude; + static constexpr auto source = R"( namespace WhirlyKitShader { @@ -572,19 +578,7 @@ fragment float4 fragmentTri_wideVecPerf( return vert.color * float4(1,1,1,edgeAlpha * patternAlpha * roundAlpha); } -)"_cts; - -template <> -struct ShaderSource { - static constexpr auto name = "WideVectorShader"; - static constexpr auto vertexMainFunction = "vertexTri_wideVecPerf"; - static constexpr auto fragmentMainFunction = "fragmentTri_wideVecPerf"; - - static const std::array attributes; - static const std::array instanceAttributes; - static const std::array textures; - - static constexpr auto source = wideVectorShaderSource.as_string_view(); +)"; }; } // namespace shaders diff --git a/include/mbgl/util/string.hpp b/include/mbgl/util/string.hpp index a17bfe5c37b..ded4df9d081 100644 --- a/include/mbgl/util/string.hpp +++ b/include/mbgl/util/string.hpp @@ -7,7 +7,6 @@ #include #include #include -#include // Polyfill needed by Qt when building for Android with GCC #if defined(__ANDROID__) && defined(__GLIBCXX__) @@ -97,65 +96,6 @@ inline float stof(const std::string &str) { return std::stof(str); } -// https://gist.github.com/Baduit/63c4ea0f248451f7047c1b003c8335d5 -// Note: asked author to clarify license - -template -struct CompileTimeString { - constexpr CompileTimeString() noexcept = default; - - constexpr CompileTimeString(const char (&literal)[ArraySize]) noexcept { std::ranges::copy(literal, data); } - - template - constexpr auto operator+(const CompileTimeString &other) const noexcept { - CompileTimeString result; - std::ranges::copy(data, result.data); - std::ranges::copy(other.data, result.data + ArraySize - 1); - return result; - } - - // Don't count the \0 at the end - constexpr std::size_t size() const { return ArraySize - 1; } - - constexpr auto begin() noexcept { return std::begin(data); } - constexpr auto end() noexcept { return std::end(data); } - constexpr auto cbegin() const noexcept { return std::cbegin(data); } - constexpr auto cend() const noexcept { return std::cend(data); } - constexpr auto rbegin() noexcept { return std::rbegin(data); } - constexpr auto rend() noexcept { return std::rend(data); } - constexpr auto crbegin() const noexcept { return std::crbegin(data); } - constexpr auto crend() const noexcept { return std::crend(data); } - - template - constexpr bool operator==(const CompileTimeString &other) const { - return as_string_view() == other.as_string_view(); - } - - constexpr bool starts_with(std::string_view sv) const noexcept { return as_string_view().starts_with(sv); } - constexpr bool starts_with(char ch) const noexcept { return as_string_view().starts_with(ch); } - constexpr bool starts_with(const char *s) const { return as_string_view().starts_with(s); } - - template - constexpr bool starts_with(const CompileTimeString &other) const { - return starts_with(other.as_string_view()); - } - - // https://en.cppreference.com/w/cpp/language/reference - // https://en.cppreference.com/w/cpp/language/member_functions#Member_functions_with_ref-qualifier - constexpr operator std::string_view() const & { return as_string_view(); } - constexpr operator std::string_view() const && = delete; - - constexpr std::string_view as_string_view() const & { return std::string_view(data, ArraySize - 1); } - constexpr std::string_view as_string_view() const && = delete; - - char data[ArraySize]; -}; - -template -constexpr auto operator""_cts() { - return Str; -} - } // namespace util } // namespace mbgl From 8c9afcbd458c9f31003a47965ea498c6cc640b96 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 9 Jan 2025 15:31:54 +0000 Subject: [PATCH 6/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- include/mbgl/shaders/mtl/background.hpp | 1 - include/mbgl/shaders/mtl/fill.hpp | 1 - include/mbgl/shaders/mtl/line.hpp | 1 - 3 files changed, 3 deletions(-) diff --git a/include/mbgl/shaders/mtl/background.hpp b/include/mbgl/shaders/mtl/background.hpp index 2457d740aea..ad414accc28 100644 --- a/include/mbgl/shaders/mtl/background.hpp +++ b/include/mbgl/shaders/mtl/background.hpp @@ -116,7 +116,6 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], )"; }; - template <> struct ShaderSource { static constexpr auto name = "BackgroundPatternShader"; diff --git a/include/mbgl/shaders/mtl/fill.hpp b/include/mbgl/shaders/mtl/fill.hpp index b507c380a3e..cc908d3d8bd 100644 --- a/include/mbgl/shaders/mtl/fill.hpp +++ b/include/mbgl/shaders/mtl/fill.hpp @@ -294,7 +294,6 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], )"; }; - template <> struct ShaderSource { static constexpr auto name = "FillPatternShader"; diff --git a/include/mbgl/shaders/mtl/line.hpp b/include/mbgl/shaders/mtl/line.hpp index 1cbb845903e..5ca7dcb78dc 100644 --- a/include/mbgl/shaders/mtl/line.hpp +++ b/include/mbgl/shaders/mtl/line.hpp @@ -352,7 +352,6 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], )"; }; - template <> struct ShaderSource { static constexpr auto name = "LineGradientShader"; From fd4b3ee42b87b2d18e578c8a40c12e80fc0a84e2 Mon Sep 17 00:00:00 2001 From: Alex Cristici Date: Fri, 10 Jan 2025 14:55:21 +0200 Subject: [PATCH 7/7] Comment removed. --- include/mbgl/shaders/mtl/shader_group.hpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/mbgl/shaders/mtl/shader_group.hpp b/include/mbgl/shaders/mtl/shader_group.hpp index 4688592070f..8a5d507270b 100644 --- a/include/mbgl/shaders/mtl/shader_group.hpp +++ b/include/mbgl/shaders/mtl/shader_group.hpp @@ -64,8 +64,7 @@ class ShaderGroup final : public ShaderGroupBase { addAdditionalDefines(propertiesAsUniforms, additionalDefines); auto& context = static_cast(gfxContext); - // C++26 will allow operator+ with std::string and std::string_view - const auto shaderSource = std::string(shaders::prelude) + std::string(prelude) + std::string(source); + const auto shaderSource = std::string(shaders::prelude) + prelude + source; shader = context.createProgram( ShaderID, shaderName, shaderSource, vertMain, fragMain, programParameters, additionalDefines); assert(shader);