Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Group descriptor sets by binding frequency #2892

Merged
merged 17 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1299,6 +1299,7 @@ if(MLN_WITH_VULKAN)
${PROJECT_SOURCE_DIR}/include/mbgl/vulkan/command_encoder.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/vulkan/context.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/vulkan/drawable.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/vulkan/descriptor_set.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/vulkan/drawable_builder.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/vulkan/index_buffer_resource.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/vulkan/layer_group.hpp
Expand Down Expand Up @@ -1334,6 +1335,7 @@ if(MLN_WITH_VULKAN)
${PROJECT_SOURCE_DIR}/src/mbgl/vulkan/buffer_resource.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/vulkan/command_encoder.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/vulkan/context.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/vulkan/descriptor_set.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/vulkan/drawable.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/vulkan/drawable_builder.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/vulkan/drawable_impl.hpp
Expand Down
1 change: 1 addition & 0 deletions include/mbgl/gfx/drawable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <mbgl/util/identity.hpp>
#include <mbgl/util/monotonic_timer.hpp>
#include <mbgl/util/traits.hpp>
#include <mbgl/util/immutable.hpp>

#include <cstdint>
#include <cstddef>
Expand Down
2 changes: 2 additions & 0 deletions include/mbgl/gfx/uniform_block.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#pragma once

#include <mbgl/shaders/shader_defines.hpp>
#include <memory>
#include <array>

namespace mbgl {
namespace gfx {
Expand Down
9 changes: 7 additions & 2 deletions include/mbgl/gfx/uniform_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

#include <mbgl/shaders/shader_defines.hpp>

#include <memory>
#include <vector>
#include <array>

namespace mbgl {
namespace gfx {

Expand Down Expand Up @@ -58,11 +62,12 @@ class UniformBufferArray {
const std::shared_ptr<UniformBuffer>& get(const size_t id) const;

/// Set a new uniform buffer element or replace the existing one.
const std::shared_ptr<UniformBuffer>& set(const size_t id, std::shared_ptr<UniformBuffer> uniformBuffer);
virtual const std::shared_ptr<UniformBuffer>& set(const size_t id, std::shared_ptr<UniformBuffer> uniformBuffer);

/// Create and add a new buffer or update an existing one
void createOrUpdate(const size_t id, const std::vector<uint8_t>& data, gfx::Context&, bool persistent = false);
void createOrUpdate(const size_t id, const void* data, std::size_t size, gfx::Context&, bool persistent = false);
virtual void createOrUpdate(
const size_t id, const void* data, std::size_t size, gfx::Context&, bool persistent = false);
template <typename T>
void createOrUpdate(const size_t id, const T* data, gfx::Context& context, bool persistent = false)
requires(!std::is_pointer_v<T>)
Expand Down
6 changes: 0 additions & 6 deletions include/mbgl/shaders/background_layer_ubo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,5 @@ struct alignas(16) BackgroundPatternLayerUBO {
};
static_assert(sizeof(BackgroundPatternLayerUBO) == 64);

enum {
idBackgroundDrawableUBO = globalUBOCount,
idBackgroundLayerUBO,
backgroundUBOCount
};

} // namespace shaders
} // namespace mbgl
7 changes: 0 additions & 7 deletions include/mbgl/shaders/circle_layer_ubo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,5 @@ struct alignas(16) CircleInterpolateUBO {
};
static_assert(sizeof(CircleInterpolateUBO) % 16 == 0);

enum {
idCircleDrawableUBO = globalUBOCount,
idCircleEvaluatedPropsUBO,
idCircleInterpolateUBO,
circleUBOCount
};

} // namespace shaders
} // namespace mbgl
5 changes: 0 additions & 5 deletions include/mbgl/shaders/collision_layer_ubo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,5 @@ struct alignas(16) CollisionUBO {
static_assert(sizeof(CollisionUBO) % 16 == 0);
static_assert(sizeof(CollisionUBO) == 80);

enum {
idCollisionUBO = globalUBOCount,
collisionUBOCount
};

} // namespace shaders
} // namespace mbgl
5 changes: 0 additions & 5 deletions include/mbgl/shaders/common_ubo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,5 @@ struct alignas(16) CommonUBO {
};
static_assert(sizeof(CommonUBO) % 16 == 0);

enum {
idCommonUBO = globalUBOCount,
commonUBOCount
};

} // namespace shaders
} // namespace mbgl
6 changes: 0 additions & 6 deletions include/mbgl/shaders/custom_drawable_layer_ubo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,5 @@ struct alignas(16) CustomSymbolIconParametersUBO {
};
static_assert(sizeof(CustomSymbolIconParametersUBO) == 3 * 16);

enum {
idCustomSymbolDrawableUBO = globalUBOCount,
idCustomSymbolParametersUBO,
customSymbolUBOCount
};

} // namespace shaders
} // namespace mbgl
5 changes: 0 additions & 5 deletions include/mbgl/shaders/debug_layer_ubo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,5 @@ struct alignas(16) DebugUBO {
};
static_assert(sizeof(DebugUBO) % 16 == 0);

enum {
idDebugUBO = globalUBOCount,
debugUBOCount
};

} // namespace shaders
} // namespace mbgl
8 changes: 0 additions & 8 deletions include/mbgl/shaders/fill_extrusion_layer_ubo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,5 @@ struct alignas(16) FillExtrusionInterpolateUBO {
};
static_assert(sizeof(FillExtrusionInterpolateUBO) == 2 * 16);

enum {
idFillExtrusionDrawableUBO = globalUBOCount,
idFillExtrusionPropsUBO,
idFillExtrusionTilePropsUBO,
idFillExtrusionInterpolateUBO,
fillExtrusionUBOCount
};

} // namespace shaders
} // namespace mbgl
8 changes: 0 additions & 8 deletions include/mbgl/shaders/fill_layer_ubo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,5 @@ struct alignas(16) FillEvaluatedPropsUBO {
};
static_assert(sizeof(FillEvaluatedPropsUBO) == 3 * 16);

enum {
idFillDrawableUBO = globalUBOCount,
idFillTilePropsUBO,
idFillInterpolateUBO,
idFillEvaluatedPropsUBO,
fillUBOCount
};

} // namespace shaders
} // namespace mbgl
7 changes: 0 additions & 7 deletions include/mbgl/shaders/heatmap_layer_ubo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,5 @@ struct alignas(16) HeatmapInterpolateUBO {
};
static_assert(sizeof(HeatmapInterpolateUBO) % 16 == 0);

enum {
idHeatmapDrawableUBO = globalUBOCount,
idHeatmapEvaluatedPropsUBO,
idHeatmapInterpolateUBO,
heatmapUBOCount
};

} // namespace shaders
} // namespace mbgl
5 changes: 0 additions & 5 deletions include/mbgl/shaders/heatmap_texture_layer_ubo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,5 @@ struct alignas(16) HeatmapTexturePropsUBO {
};
static_assert(sizeof(HeatmapTexturePropsUBO) % 16 == 0);

enum {
idHeatmapTexturePropsUBO = globalUBOCount,
heatmapTextureUBOCount
};

} // namespace shaders
} // namespace mbgl
6 changes: 0 additions & 6 deletions include/mbgl/shaders/hillshade_layer_ubo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,5 @@ struct alignas(16) HillshadeEvaluatedPropsUBO {
};
static_assert(sizeof(HillshadeEvaluatedPropsUBO) % 16 == 0);

enum {
idHillshadeDrawableUBO = globalUBOCount,
idHillshadeEvaluatedPropsUBO,
hillshadeUBOCount
};

} // namespace shaders
} // namespace mbgl
5 changes: 0 additions & 5 deletions include/mbgl/shaders/hillshade_prepare_layer_ubo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,5 @@ struct alignas(16) HillshadePrepareDrawableUBO {
};
static_assert(sizeof(HillshadePrepareDrawableUBO) % 16 == 0);

enum {
idHillshadePrepareDrawableUBO = globalUBOCount,
hillshadePrepareUBOCount
};

} // namespace shaders
} // namespace mbgl
9 changes: 0 additions & 9 deletions include/mbgl/shaders/line_layer_ubo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,5 @@ struct alignas(16) LineEvaluatedPropsUBO {
};
static_assert(sizeof(LineEvaluatedPropsUBO) % 16 == 0);

enum {
idLineDrawableUBO = globalUBOCount,
idLineInterpolationUBO,
idLineTilePropertiesUBO,
idLineEvaluatedPropsUBO,
idLineExpressionUBO,
lineUBOCount
};

} // namespace shaders
} // namespace mbgl
6 changes: 3 additions & 3 deletions include/mbgl/shaders/mtl/circle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ struct alignas(16) CircleInterpolateUBO {
FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
device const GlobalPaintParamsUBO& paintParams [[buffer(0)]],
device const CircleDrawableUBO& drawable [[buffer(1)]],
device const CircleEvaluatedPropsUBO& props [[buffer(2)]],
device const CircleInterpolateUBO& interp [[buffer(3)]]) {
device const CircleInterpolateUBO& interp [[buffer(2)]],
device const CircleEvaluatedPropsUBO& props [[buffer(3)]]) {
#if defined(HAS_UNIFORM_u_radius)
const auto radius = props.radius;
Expand Down Expand Up @@ -189,7 +189,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
}
half4 fragment fragmentMain(FragmentStage in [[stage_in]],
device const CircleEvaluatedPropsUBO& props [[buffer(2)]]) {
device const CircleEvaluatedPropsUBO& props [[buffer(3)]]) {
#if defined(OVERDRAW_INSPECTOR)
return half4(1.0);
#endif
Expand Down
4 changes: 2 additions & 2 deletions include/mbgl/shaders/mtl/fill_extrusion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ struct FragmentOutput {
FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
device const FillExtrusionDrawableUBO& drawable [[buffer(1)]],
device const FillExtrusionPropsUBO& props [[buffer(2)]],
device const FillExtrusionInterpolateUBO& interp [[buffer(4)]]) {
device const FillExtrusionInterpolateUBO& interp [[buffer(3)]],
device const FillExtrusionPropsUBO& props [[buffer(4)]]) {
#if defined(HAS_UNIFORM_u_base)
const auto base = props.light_position_base.w;
Expand Down
10 changes: 5 additions & 5 deletions include/mbgl/shaders/mtl/fill_extrusion_pattern.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ struct FragmentOutput {
FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
device const GlobalPaintParamsUBO& paintParams [[buffer(0)]],
device const FillExtrusionDrawableUBO& drawable [[buffer(1)]],
device const FillExtrusionPropsUBO& props [[buffer(2)]],
device const FillExtrusionTilePropsUBO& tileProps [[buffer(3)]],
device const FillExtrusionInterpolateUBO& interp [[buffer(4)]]) {
device const FillExtrusionTilePropsUBO& tileProps [[buffer(2)]],
device const FillExtrusionInterpolateUBO& interp [[buffer(3)]],
device const FillExtrusionPropsUBO& props [[buffer(4)]]) {
#if defined(HAS_UNIFORM_u_base)
const auto base = props.light_position_base.w;
Expand Down Expand Up @@ -151,8 +151,8 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
fragment FragmentOutput fragmentMain(FragmentStage in [[stage_in]],
device const FillExtrusionDrawableUBO& drawable [[buffer(1)]],
device const FillExtrusionPropsUBO& props [[buffer(2)]],
device const FillExtrusionTilePropsUBO& tileProps [[buffer(3)]],
device const FillExtrusionTilePropsUBO& tileProps [[buffer(2)]],
device const FillExtrusionPropsUBO& props [[buffer(4)]],
texture2d<float, access::sample> image0 [[texture(0)]],
sampler image0_sampler [[sampler(0)]]) {
#if defined(OVERDRAW_INSPECTOR)
Expand Down
6 changes: 3 additions & 3 deletions include/mbgl/shaders/mtl/heatmap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ constant const float ZERO = 1.0 / 255.0 / 16.0;
FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
device const HeatmapDrawableUBO& drawable [[buffer(1)]],
device const HeatmapEvaluatedPropsUBO& props [[buffer(2)]],
device const HeatmapInterpolateUBO& interp [[buffer(3)]]) {
device const HeatmapInterpolateUBO& interp [[buffer(2)]],
device const HeatmapEvaluatedPropsUBO& props [[buffer(3)]]) {
#if defined(HAS_UNIFORM_u_weight)
const auto weight = props.weight;
Expand Down Expand Up @@ -117,7 +117,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
}
half4 fragment fragmentMain(FragmentStage in [[stage_in]],
device const HeatmapEvaluatedPropsUBO& props [[buffer(2)]]) {
device const HeatmapEvaluatedPropsUBO& props [[buffer(3)]]) {
#if defined(OVERDRAW_INSPECTOR)
return half4(1.0);
#endif
Expand Down
15 changes: 8 additions & 7 deletions include/mbgl/shaders/mtl/widevector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <mbgl/shaders/mtl/common.hpp>
#include <mbgl/shaders/mtl/shader_program.hpp>
#include <mbgl/shaders/widevector_ubo.hpp>
#include <mbgl/shaders/shader_defines.hpp>

namespace mbgl {
namespace shaders {
Expand All @@ -19,14 +20,14 @@ struct ShaderSource<BuiltIn::WideVectorShader, gfx::Backend::Type::Metal> {
UniformBlockInfo{true, false, sizeof(WideVectorUniformWideVecUBO), idWideVectorUniformWideVecUBO},
};
static constexpr std::array<AttributeInfo, 3> attributes{
AttributeInfo{wideVectorUBOCount + 0, gfx::AttributeDataType::Float3, idWideVectorScreenPos},
AttributeInfo{wideVectorUBOCount + 1, gfx::AttributeDataType::Float4, idWideVectorColor},
AttributeInfo{wideVectorUBOCount + 2, gfx::AttributeDataType::Int, idWideVectorIndex}};
AttributeInfo{wideVectorDrawableUBOCount + 0, gfx::AttributeDataType::Float3, idWideVectorScreenPos},
AttributeInfo{wideVectorDrawableUBOCount + 1, gfx::AttributeDataType::Float4, idWideVectorColor},
AttributeInfo{wideVectorDrawableUBOCount + 2, gfx::AttributeDataType::Int, idWideVectorIndex}};
static constexpr std::array<AttributeInfo, 4> instanceAttributes{
AttributeInfo{wideVectorUBOCount + 3, gfx::AttributeDataType::Float3, idWideVectorInstanceCenter},
AttributeInfo{wideVectorUBOCount + 3, gfx::AttributeDataType::Float4, idWideVectorInstanceColor},
AttributeInfo{wideVectorUBOCount + 3, gfx::AttributeDataType::Int, idWideVectorInstancePrevious},
AttributeInfo{wideVectorUBOCount + 3, gfx::AttributeDataType::Int, idWideVectorInstanceNext}};
AttributeInfo{wideVectorDrawableUBOCount + 3, gfx::AttributeDataType::Float3, idWideVectorInstanceCenter},
AttributeInfo{wideVectorDrawableUBOCount + 3, gfx::AttributeDataType::Float4, idWideVectorInstanceColor},
AttributeInfo{wideVectorDrawableUBOCount + 3, gfx::AttributeDataType::Int, idWideVectorInstancePrevious},
AttributeInfo{wideVectorDrawableUBOCount + 3, gfx::AttributeDataType::Int, idWideVectorInstanceNext}};
static constexpr std::array<TextureInfo, 0> textures{};

static constexpr auto source = R"(
Expand Down
6 changes: 0 additions & 6 deletions include/mbgl/shaders/raster_layer_ubo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,5 @@ struct alignas(16) RasterEvaluatedPropsUBO {
};
static_assert(sizeof(RasterEvaluatedPropsUBO) == 64);

enum {
idRasterDrawableUBO = globalUBOCount,
idRasterEvaluatedPropsUBO,
rasterUBOCount
};

} // namespace shaders
} // namespace mbgl
Loading
Loading