Skip to content

Commit

Permalink
Vulkan.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcristici committed Dec 15, 2024
1 parent 94bfe6c commit 0fe9fee
Show file tree
Hide file tree
Showing 42 changed files with 636 additions and 260 deletions.
2 changes: 1 addition & 1 deletion include/mbgl/gfx/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class Context {
/// @param data The data to copy, may be `nullptr`
/// @param size The size of the buffer
/// @param persistent Performance hint, optimize for few or many uses
virtual UniformBufferPtr createUniformBuffer(const void* data, std::size_t size, bool persistent = false) = 0;
virtual UniformBufferPtr createUniformBuffer(const void* data, std::size_t size, bool persistent = false, bool ssbo = false) = 0;

/// Get the generic shader with the specified name
virtual gfx::ShaderProgramBasePtr getGenericShader(gfx::ShaderRegistry&, const std::string& name) = 0;
Expand Down
2 changes: 1 addition & 1 deletion include/mbgl/mtl/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class Context final : public gfx::Context {
void reduceMemoryUsage() override {}

gfx::UniqueDrawableBuilder createDrawableBuilder(std::string name) override;
gfx::UniformBufferPtr createUniformBuffer(const void* data, std::size_t size, bool persisten) override;
gfx::UniformBufferPtr createUniformBuffer(const void* data, std::size_t size, bool persistent = false, bool ssbo = false) override;

gfx::ShaderProgramBasePtr getGenericShader(gfx::ShaderRegistry&, const std::string& name) override;

Expand Down
2 changes: 1 addition & 1 deletion include/mbgl/shaders/layer_ubo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ enum {
drawableReservedUBOCount
};

#define MLN_UBO_CONSOLIDATION MLN_RENDER_BACKEND_METAL
#define MLN_UBO_CONSOLIDATION (MLN_RENDER_BACKEND_METAL || MLN_RENDER_BACKEND_VULKAN)

} // namespace shaders
} // namespace mbgl
2 changes: 1 addition & 1 deletion include/mbgl/shaders/mtl/custom_symbol_icon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct alignas(16) CustomSymbolIconDrawableUBO {
/* 108 */ float pad3;
/* 112 */
};
static_assert(sizeof(CustomSymbolIconParametersUBO) == 7 * 16, "wrong size");
static_assert(sizeof(CustomSymbolIconDrawableUBO) == 7 * 16, "wrong size");
)"

Expand Down
2 changes: 2 additions & 0 deletions include/mbgl/shaders/shader_defines.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ enum {
wideVectorDrawableUBOCount
};

static constexpr auto layerSSBOStartId = globalUBOCount;
static constexpr auto layerUBOStartId = std::max({static_cast<size_t>(backgroundDrawableUBOCount),
static_cast<size_t>(circleDrawableUBOCount),
static_cast<size_t>(clippingMaskDrawableUBOCount),
Expand Down Expand Up @@ -228,6 +229,7 @@ static constexpr auto maxUBOCountPerShader = std::max({static_cast<size_t>(backg
static_cast<size_t>(symbolUBOCount),
static_cast<size_t>(wideVectorUBOCount)});

static constexpr auto maxSSBOCountPerLayer = maxUBOCountPerDrawable;
static constexpr auto maxUBOCountPerLayer = maxUBOCountPerShader - layerUBOStartId;

// Texture defines
Expand Down
29 changes: 25 additions & 4 deletions include/mbgl/shaders/vulkan/background.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,23 @@ struct ShaderSource<BuiltIn::BackgroundShader, gfx::Backend::Type::Vulkan> {
layout(location = 0) in ivec2 in_position;
layout(set = DRAWABLE_UBO_SET_INDEX, binding = idBackgroundDrawableUBO) uniform BackgroundDrawableUBO {
layout(push_constant) uniform Constants {
int ubo_index;
} constant;
struct BackgroundDrawableUBO {
mat4 matrix;
} drawable;
vec4 pad1;
vec4 pad2;
};
layout(std140, set = LAYER_SET_INDEX, binding = idBackgroundDrawableUBO) readonly buffer BackgroundDrawableUBOVector {
BackgroundDrawableUBO drawable_ubo[];
} drawableVector;
void main() {
const BackgroundDrawableUBO drawable = drawableVector.drawable_ubo[constant.ubo_index];
gl_Position = drawable.matrix * vec4(in_position, 0.0, 1.0);
applySurfaceTransform();
}
Expand Down Expand Up @@ -70,15 +82,23 @@ struct ShaderSource<BuiltIn::BackgroundPatternShader, gfx::Backend::Type::Vulkan
static constexpr auto vertex = BACKGROUND_SHADER_COMMON R"(
layout(location = 0) in ivec2 in_position;
layout(set = DRAWABLE_UBO_SET_INDEX, binding = idBackgroundDrawableUBO) uniform BackgroundPatternDrawableUBO {
layout(push_constant) uniform Constants {
int ubo_index;
} constant;
struct BackgroundPatternDrawableUBO {
mat4 matrix;
vec2 pixel_coord_upper;
vec2 pixel_coord_lower;
float tile_units_to_pixels;
float pad1;
float pad2;
float pad3;
} drawable;
};
layout(std140, set = LAYER_SET_INDEX, binding = idBackgroundDrawableUBO) readonly buffer BackgroundPatternDrawableUBOVector {
BackgroundPatternDrawableUBO drawable_ubo[];
} drawableVector;
layout(set = LAYER_SET_INDEX, binding = idBackgroundPropsUBO) uniform BackgroundPatternPropsUBO {
vec2 pattern_tl_a;
Expand All @@ -97,6 +117,7 @@ layout(location = 0) out vec2 frag_pos_a;
layout(location = 1) out vec2 frag_pos_b;
void main() {
const BackgroundPatternDrawableUBO drawable = drawableVector.drawable_ubo[constant.ubo_index];
frag_pos_a = get_pattern_pos(drawable.pixel_coord_upper,
drawable.pixel_coord_lower,
Expand Down
13 changes: 11 additions & 2 deletions include/mbgl/shaders/vulkan/circle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ layout(location = 6) in vec2 in_stroke_width;
layout(location = 7) in vec2 in_stroke_opacity;
#endif
layout(set = DRAWABLE_UBO_SET_INDEX, binding = idCircleDrawableUBO) uniform CircleDrawableUBO {
layout(push_constant) uniform Constants {
int ubo_index;
} constant;
struct CircleDrawableUBO {
mat4 matrix;
vec2 extrude_scale;
// Interpolations
Expand All @@ -68,7 +72,11 @@ layout(set = DRAWABLE_UBO_SET_INDEX, binding = idCircleDrawableUBO) uniform Circ
float pad1;
float pad2;
float pad3;
} drawable;
};
layout(std140, set = LAYER_SET_INDEX, binding = idCircleDrawableUBO) readonly buffer CircleDrawableUBOVector {
CircleDrawableUBO drawable_ubo[];
} drawableVector;
layout(set = LAYER_SET_INDEX, binding = idCircleEvaluatedPropsUBO) uniform CircleEvaluatedPropsUBO {
vec4 color;
Expand Down Expand Up @@ -115,6 +123,7 @@ layout(location = 8) out lowp float frag_stroke_opacity;
#endif
void main() {
const CircleDrawableUBO drawable = drawableVector.drawable_ubo[constant.ubo_index];
#if defined(HAS_UNIFORM_u_radius)
const float radius = props.radius;
Expand Down
4 changes: 2 additions & 2 deletions include/mbgl/shaders/vulkan/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ vec2 get_pattern_pos(const vec2 pixel_coord_upper, const vec2 pixel_coord_lower,
#define idDrawableReservedVertexOnlyUBO 0
#define idDrawableReservedFragmentOnlyUBO 1
#define drawableReservedUBOCount 2
#define layerUBOStartId 0
#define layerUBOStartId 3
layout(set = GLOBAL_SET_INDEX, binding = 0) uniform GlobalPaintParamsUBO {
vec2 pattern_atlas_texsize;
Expand Down Expand Up @@ -118,7 +118,7 @@ void applySurfaceTransform() {
#define idDrawableReservedVertexOnlyUBO 0
#define idDrawableReservedFragmentOnlyUBO 1
#define drawableReservedUBOCount 2
#define layerUBOStartId 0
#define layerUBOStartId 3
layout(set = GLOBAL_SET_INDEX, binding = 0) uniform GlobalPaintParamsUBO {
vec2 pattern_atlas_texsize;
Expand Down
Loading

0 comments on commit 0fe9fee

Please sign in to comment.