Skip to content

Commit

Permalink
Replace macro with run-time string concatenation (#3124)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcristici authored Jan 10, 2025
1 parent 57f42d9 commit 9f02e29
Show file tree
Hide file tree
Showing 17 changed files with 106 additions and 85 deletions.
15 changes: 6 additions & 9 deletions include/mbgl/shaders/mtl/background.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
namespace mbgl {
namespace shaders {

#define BACKGROUND_SHADER_COMMON \
R"(
constexpr auto backgroundShaderPrelude = R"(
enum {
idBackgroundDrawableUBO = idDrawableReservedVertexOnlyUBO,
Expand Down Expand Up @@ -72,7 +71,7 @@ union BackgroundDrawableUnionUBO {
BackgroundPatternDrawableUBO backgroundPatternDrawableUBO;
};
)"
)";

template <>
struct ShaderSource<BuiltIn::BackgroundShader, gfx::Backend::Type::Metal> {
Expand All @@ -84,9 +83,8 @@ struct ShaderSource<BuiltIn::BackgroundShader, gfx::Backend::Type::Metal> {
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
static const std::array<TextureInfo, 0> textures;

static constexpr auto source = BACKGROUND_SHADER_COMMON R"(
#include <metal_stdlib>
using namespace metal;
static constexpr auto prelude = backgroundShaderPrelude;
static constexpr auto source = R"(
struct VertexStage {
short2 position [[attribute(backgroundUBOCount + 0)]];
Expand Down Expand Up @@ -128,9 +126,8 @@ struct ShaderSource<BuiltIn::BackgroundPatternShader, gfx::Backend::Type::Metal>
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
static const std::array<TextureInfo, 1> textures;

static constexpr auto source = BACKGROUND_SHADER_COMMON R"(
#include <metal_stdlib>
using namespace metal;
static constexpr auto prelude = backgroundShaderPrelude;
static constexpr auto source = R"(
struct VertexStage {
short2 position [[attribute(backgroundUBOCount + 0)]];
Expand Down
9 changes: 5 additions & 4 deletions include/mbgl/shaders/mtl/circle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
namespace mbgl {
namespace shaders {

#define CIRCLE_SHADER_PRELUDE \
R"(
constexpr auto circleShaderPrelude = R"(
enum {
idCircleDrawableUBO = idDrawableReservedVertexOnlyUBO,
Expand Down Expand Up @@ -51,7 +50,7 @@ struct alignas(16) CircleEvaluatedPropsUBO {
};
static_assert(sizeof(CircleEvaluatedPropsUBO) == 4 * 16, "wrong size");
)"
)";

template <>
struct ShaderSource<BuiltIn::CircleShader, gfx::Backend::Type::Metal> {
Expand All @@ -63,7 +62,9 @@ struct ShaderSource<BuiltIn::CircleShader, gfx::Backend::Type::Metal> {
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
static const std::array<TextureInfo, 0> textures;

static constexpr auto source = CIRCLE_SHADER_PRELUDE R"(
static constexpr auto prelude = circleShaderPrelude;
static constexpr auto source = R"(
struct VertexStage {
short2 position [[attribute(circleUBOCount + 0)]];
Expand Down
12 changes: 5 additions & 7 deletions include/mbgl/shaders/mtl/clipping_mask.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ struct alignas(16) ClipUBO {
};
static_assert(sizeof(ClipUBO) == 5 * 16);

#define CLIPPING_MASK_SHADER_PRELUDE \
R"(
#include <metal_stdlib>
using namespace metal;
constexpr auto clippingMaskShaderPrelude = R"(
enum {
idClippingMaskUBO = idDrawableReservedVertexOnlyUBO,
Expand All @@ -37,7 +33,7 @@ struct alignas(16) ClipUBO {
};
static_assert(sizeof(ClipUBO) == 5 * 16, "wrong size");
)"
)";

template <>
struct ShaderSource<BuiltIn::ClippingMaskProgram, gfx::Backend::Type::Metal> {
Expand All @@ -49,7 +45,9 @@ struct ShaderSource<BuiltIn::ClippingMaskProgram, gfx::Backend::Type::Metal> {
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
static const std::array<TextureInfo, 0> textures;

static constexpr auto source = CLIPPING_MASK_SHADER_PRELUDE R"(
static constexpr auto prelude = clippingMaskShaderPrelude;
static constexpr auto source = R"(
struct VertexStage {
short2 position [[attribute(clippingMaskUBOCount + 0)]];
};
Expand Down
11 changes: 6 additions & 5 deletions include/mbgl/shaders/mtl/collision.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
namespace mbgl {
namespace shaders {

#define COLLISION_SHADER_COMMON \
R"(
constexpr auto collisionShaderPrelude = R"(
enum {
idCollisionDrawableUBO = idDrawableReservedVertexOnlyUBO,
Expand All @@ -30,7 +29,7 @@ struct alignas(16) CollisionTilePropsUBO {
};
static_assert(sizeof(CollisionTilePropsUBO) == 16, "wrong size");
)"
)";

template <>
struct ShaderSource<BuiltIn::CollisionBoxShader, gfx::Backend::Type::Metal> {
Expand All @@ -42,7 +41,8 @@ struct ShaderSource<BuiltIn::CollisionBoxShader, gfx::Backend::Type::Metal> {
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
static const std::array<TextureInfo, 0> textures;

static constexpr auto source = COLLISION_SHADER_COMMON R"(
static constexpr auto prelude = collisionShaderPrelude;
static constexpr auto source = R"(
struct VertexStage {
short2 pos [[attribute(collisionUBOCount + 0)]];
Expand Down Expand Up @@ -115,7 +115,8 @@ struct ShaderSource<BuiltIn::CollisionCircleShader, gfx::Backend::Type::Metal> {
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
static const std::array<TextureInfo, 0> textures;

static constexpr auto source = COLLISION_SHADER_COMMON R"(
static constexpr auto prelude = collisionShaderPrelude;
static constexpr auto source = R"(
struct VertexStage {
short2 pos [[attribute(collisionUBOCount + 0)]];
Expand Down
9 changes: 5 additions & 4 deletions include/mbgl/shaders/mtl/custom_symbol_icon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
namespace mbgl {
namespace shaders {

#define CUSTOM_SYMBOL_ICON_SHADER_PRELUDE \
R"(
constexpr auto customSymbolIconShaderPrelude = R"(
enum {
idCustomSymbolDrawableUBO = idDrawableReservedVertexOnlyUBO,
Expand All @@ -31,7 +30,7 @@ struct alignas(16) CustomSymbolIconDrawableUBO {
};
static_assert(sizeof(CustomSymbolIconDrawableUBO) == 7 * 16, "wrong size");
)"
)";

template <>
struct ShaderSource<BuiltIn::CustomSymbolIconShader, gfx::Backend::Type::Metal> {
Expand All @@ -43,7 +42,9 @@ struct ShaderSource<BuiltIn::CustomSymbolIconShader, gfx::Backend::Type::Metal>
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
static const std::array<TextureInfo, 1> textures;

static constexpr auto source = CUSTOM_SYMBOL_ICON_SHADER_PRELUDE R"(
static constexpr auto prelude = customSymbolIconShaderPrelude;
static constexpr auto source = R"(
struct VertexStage {
float2 a_pos [[attribute(customSymbolUBOCount + 0)]];
float2 a_tex [[attribute(customSymbolUBOCount + 1)]];
Expand Down
8 changes: 4 additions & 4 deletions include/mbgl/shaders/mtl/debug.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
namespace mbgl {
namespace shaders {

#define DEBUG_SHADER_PRELUDE \
R"(
constexpr auto debugShaderPrelude = R"(
enum {
idDebugUBO = drawableReservedUBOCount,
Expand All @@ -26,7 +25,7 @@ struct alignas(16) DebugUBO {
};
static_assert(sizeof(DebugUBO) == 6 * 16, "wrong size");
)"
)";

template <>
struct ShaderSource<BuiltIn::DebugShader, gfx::Backend::Type::Metal> {
Expand All @@ -38,7 +37,8 @@ struct ShaderSource<BuiltIn::DebugShader, gfx::Backend::Type::Metal> {
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
static const std::array<TextureInfo, 1> textures;

static constexpr auto source = DEBUG_SHADER_PRELUDE R"(
static constexpr auto prelude = debugShaderPrelude;
static constexpr auto source = R"(
struct VertexStage {
short2 pos [[attribute(debugUBOCount + 0)]];
Expand Down
23 changes: 15 additions & 8 deletions include/mbgl/shaders/mtl/fill.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
namespace mbgl {
namespace shaders {

#define FILL_SHADER_COMMON \
R"(
constexpr auto fillShaderPrelude = R"(
enum {
idFillDrawableUBO = idDrawableReservedVertexOnlyUBO,
Expand Down Expand Up @@ -139,7 +138,7 @@ union FillTilePropsUnionUBO {
FillOutlinePatternTilePropsUBO fillOutlinePatternTilePropsUBO;
};
)"
)";

template <>
struct ShaderSource<BuiltIn::FillShader, gfx::Backend::Type::Metal> {
Expand All @@ -151,7 +150,8 @@ struct ShaderSource<BuiltIn::FillShader, gfx::Backend::Type::Metal> {
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
static const std::array<TextureInfo, 0> textures;

static constexpr auto source = FILL_SHADER_COMMON R"(
static constexpr auto prelude = fillShaderPrelude;
static constexpr auto source = R"(
struct VertexStage {
short2 position [[attribute(fillUBOCount + 0)]];
Expand Down Expand Up @@ -225,7 +225,9 @@ struct ShaderSource<BuiltIn::FillOutlineShader, gfx::Backend::Type::Metal> {
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
static const std::array<TextureInfo, 0> textures;

static constexpr auto source = FILL_SHADER_COMMON R"(
static constexpr auto prelude = fillShaderPrelude;
static constexpr auto source = R"(
struct VertexStage {
short2 position [[attribute(fillUBOCount + 0)]];
float4 outline_color [[attribute(fillUBOCount + 1)]];
Expand Down Expand Up @@ -302,7 +304,9 @@ struct ShaderSource<BuiltIn::FillPatternShader, gfx::Backend::Type::Metal> {
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
static const std::array<TextureInfo, 1> textures;

static constexpr auto source = FILL_SHADER_COMMON R"(
static constexpr auto prelude = fillShaderPrelude;
static constexpr auto source = R"(
struct VertexStage {
short2 position [[attribute(fillUBOCount + 0)]];
Expand Down Expand Up @@ -443,7 +447,8 @@ struct ShaderSource<BuiltIn::FillOutlinePatternShader, gfx::Backend::Type::Metal
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
static const std::array<TextureInfo, 1> textures;

static constexpr auto source = FILL_SHADER_COMMON R"(
static constexpr auto prelude = fillShaderPrelude;
static constexpr auto source = R"(
struct VertexStage {
short2 position [[attribute(fillUBOCount + 0)]];
Expand Down Expand Up @@ -597,7 +602,9 @@ struct ShaderSource<BuiltIn::FillOutlineTriangulatedShader, gfx::Backend::Type::
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
static const std::array<TextureInfo, 0> textures;

static constexpr auto source = FILL_SHADER_COMMON R"(
static constexpr auto prelude = fillShaderPrelude;
static constexpr auto source = R"(
struct VertexStage {
short2 pos_normal [[attribute(fillUBOCount + 0)]];
uchar4 data [[attribute(fillUBOCount + 1)]];
Expand Down
13 changes: 8 additions & 5 deletions include/mbgl/shaders/mtl/fill_extrusion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
namespace mbgl {
namespace shaders {

#define FILL_EXTRUSION_SHADER_COMMON \
R"(
constexpr auto fillExtrusionShaderPrelude = R"(
enum {
idFillExtrusionDrawableUBO = idDrawableReservedVertexOnlyUBO,
Expand Down Expand Up @@ -62,7 +61,7 @@ struct alignas(16) FillExtrusionPropsUBO {
};
static_assert(sizeof(FillExtrusionPropsUBO) == 5 * 16, "wrong size");
)"
)";

template <>
struct ShaderSource<BuiltIn::FillExtrusionShader, gfx::Backend::Type::Metal> {
Expand All @@ -74,7 +73,9 @@ struct ShaderSource<BuiltIn::FillExtrusionShader, gfx::Backend::Type::Metal> {
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
static const std::array<TextureInfo, 0> textures;

static constexpr auto source = FILL_EXTRUSION_SHADER_COMMON R"(
static constexpr auto prelude = fillExtrusionShaderPrelude;
static constexpr auto source = R"(
struct VertexStage {
short2 pos [[attribute(fillExtrusionUBOCount + 0)]];
short4 normal_ed [[attribute(fillExtrusionUBOCount + 1)]];
Expand Down Expand Up @@ -193,7 +194,9 @@ struct ShaderSource<BuiltIn::FillExtrusionPatternShader, gfx::Backend::Type::Met
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
static const std::array<TextureInfo, 1> textures;

static constexpr auto source = FILL_EXTRUSION_SHADER_COMMON R"(
static constexpr auto prelude = fillExtrusionShaderPrelude;
static constexpr auto source = R"(
struct VertexStage {
short2 pos [[attribute(fillExtrusionUBOCount + 0)]];
short4 normal_ed [[attribute(fillExtrusionUBOCount + 1)]];
Expand Down
8 changes: 4 additions & 4 deletions include/mbgl/shaders/mtl/heatmap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
namespace mbgl {
namespace shaders {

#define HEATMAP_SHADER_PRELUDE \
R"(
constexpr auto heatmapShaderPrelude = R"(
enum {
idHeatmapDrawableUBO = idDrawableReservedVertexOnlyUBO,
Expand Down Expand Up @@ -38,7 +37,7 @@ struct alignas(16) HeatmapEvaluatedPropsUBO {
};
static_assert(sizeof(HeatmapEvaluatedPropsUBO) == 16, "wrong size");
)"
)";

template <>
struct ShaderSource<BuiltIn::HeatmapShader, gfx::Backend::Type::Metal> {
Expand All @@ -50,7 +49,8 @@ struct ShaderSource<BuiltIn::HeatmapShader, gfx::Backend::Type::Metal> {
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
static const std::array<TextureInfo, 0> textures;

static constexpr auto source = HEATMAP_SHADER_PRELUDE R"(
static constexpr auto prelude = heatmapShaderPrelude;
static constexpr auto source = R"(
struct VertexStage {
short2 pos [[attribute(heatmapUBOCount + 0)]];
Expand Down
8 changes: 4 additions & 4 deletions include/mbgl/shaders/mtl/heatmap_texture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
namespace mbgl {
namespace shaders {

#define HEATMAP_TEXTURE_SHADER_PRELUDE \
R"(
constexpr auto heatmapTextureShaderPrelude = R"(
enum {
idHeatmapTexturePropsUBO = drawableReservedUBOCount,
Expand All @@ -25,7 +24,7 @@ struct alignas(16) HeatmapTexturePropsUBO {
};
static_assert(sizeof(HeatmapTexturePropsUBO) == 5 * 16, "wrong size");
)"
)";

template <>
struct ShaderSource<BuiltIn::HeatmapTextureShader, gfx::Backend::Type::Metal> {
Expand All @@ -37,7 +36,8 @@ struct ShaderSource<BuiltIn::HeatmapTextureShader, gfx::Backend::Type::Metal> {
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
static const std::array<TextureInfo, 2> textures;

static constexpr auto source = HEATMAP_TEXTURE_SHADER_PRELUDE R"(
static constexpr auto prelude = heatmapTextureShaderPrelude;
static constexpr auto source = R"(
struct VertexStage {
short2 pos [[attribute(heatmapTextureUBOCount + 0)]];
Expand Down
Loading

0 comments on commit 9f02e29

Please sign in to comment.