Vulkan fill extrusion instancing [Core optimization] (#4310)
Co-authored-by: Alex Cristici <alex.cristici@gmail.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Bart Louwers <bart@emeel.net>
This commit is contained in:
@@ -71,14 +71,8 @@ enum {
|
||||
globalUBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
idDrawableReservedVertexOnlyUBO = globalUBOCount,
|
||||
idDrawableReservedFragmentOnlyUBO,
|
||||
drawableReservedUBOCount
|
||||
};
|
||||
|
||||
#define MLN_UBO_CONSOLIDATION (MLN_RENDER_BACKEND_METAL || MLN_RENDER_BACKEND_VULKAN || MLN_RENDER_BACKEND_WEBGPU)
|
||||
#define MLN_USE_FILL_EXTRUSION_INSTANCING (MLN_RENDER_BACKEND_METAL)
|
||||
#define MLN_USE_FILL_EXTRUSION_INSTANCING (MLN_RENDER_BACKEND_METAL || MLN_RENDER_BACKEND_VULKAN)
|
||||
|
||||
} // namespace shaders
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -7,253 +7,281 @@
|
||||
namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
// drawable UBOs
|
||||
|
||||
enum {
|
||||
idBackgroundDrawableUBO = idDrawableReservedVertexOnlyUBO,
|
||||
backgroundDrawableUBOCount = drawableReservedUBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
idCircleDrawableUBO = idDrawableReservedVertexOnlyUBO,
|
||||
circleDrawableUBOCount = drawableReservedUBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
idClippingMaskUBO = idDrawableReservedVertexOnlyUBO,
|
||||
clippingMaskDrawableUBOCount = drawableReservedUBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
idCollisionDrawableUBO = idDrawableReservedVertexOnlyUBO,
|
||||
idCollisionTilePropsUBO = drawableReservedUBOCount,
|
||||
collisionDrawableUBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
idCustomGeometryDrawableUBO = drawableReservedUBOCount,
|
||||
customGeometryDrawableUBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
idCustomSymbolDrawableUBO = idDrawableReservedVertexOnlyUBO,
|
||||
customSymbolDrawableUBOCount = drawableReservedUBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
idDebugUBO = drawableReservedUBOCount,
|
||||
debugDrawableUBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
idFillDrawableUBO = idDrawableReservedVertexOnlyUBO,
|
||||
idFillTilePropsUBO = drawableReservedUBOCount,
|
||||
fillDrawableUBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
idFillExtrusionDrawableUBO = idDrawableReservedVertexOnlyUBO,
|
||||
idFillExtrusionTilePropsUBO = drawableReservedUBOCount,
|
||||
fillExtrusionDrawableUBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
idHeatmapDrawableUBO = idDrawableReservedVertexOnlyUBO,
|
||||
heatmapDrawableUBOCount = drawableReservedUBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
heatmapTextureDrawableUBOCount = drawableReservedUBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
idHillshadeDrawableUBO = idDrawableReservedVertexOnlyUBO,
|
||||
idHillshadeTilePropsUBO = idDrawableReservedFragmentOnlyUBO,
|
||||
hillshadeDrawableUBOCount = drawableReservedUBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
idHillshadePrepareDrawableUBO = idDrawableReservedVertexOnlyUBO,
|
||||
idHillshadePrepareTilePropsUBO = drawableReservedUBOCount,
|
||||
hillshadePrepareDrawableUBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
idColorReliefDrawableUBO = idDrawableReservedVertexOnlyUBO,
|
||||
idColorReliefTilePropsUBO = drawableReservedUBOCount,
|
||||
colorReliefDrawableUBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
idLineDrawableUBO = idDrawableReservedVertexOnlyUBO,
|
||||
idLineTilePropsUBO = idDrawableReservedFragmentOnlyUBO,
|
||||
lineDrawableUBOCount = drawableReservedUBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
idLocationIndicatorDrawableUBO = drawableReservedUBOCount,
|
||||
locationIndicatorDrawableUBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
idRasterDrawableUBO = idDrawableReservedVertexOnlyUBO,
|
||||
rasterDrawableUBOCount = drawableReservedUBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
idSymbolDrawableUBO = idDrawableReservedVertexOnlyUBO,
|
||||
idSymbolTilePropsUBO = idDrawableReservedFragmentOnlyUBO,
|
||||
symbolDrawableUBOCount = drawableReservedUBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
idWideVectorUniformsUBO = idDrawableReservedVertexOnlyUBO,
|
||||
idWideVectorUniformWideVecUBO = drawableReservedUBOCount,
|
||||
wideVectorDrawableUBOCount
|
||||
};
|
||||
// layer SSBOs
|
||||
|
||||
static constexpr uint32_t layerSSBOStartId = globalUBOCount;
|
||||
static constexpr uint32_t layerUBOStartId = std::max({static_cast<uint32_t>(backgroundDrawableUBOCount),
|
||||
static_cast<uint32_t>(circleDrawableUBOCount),
|
||||
static_cast<uint32_t>(clippingMaskDrawableUBOCount),
|
||||
static_cast<uint32_t>(collisionDrawableUBOCount),
|
||||
static_cast<uint32_t>(customGeometryDrawableUBOCount),
|
||||
static_cast<uint32_t>(customSymbolDrawableUBOCount),
|
||||
static_cast<uint32_t>(debugDrawableUBOCount),
|
||||
static_cast<uint32_t>(fillDrawableUBOCount),
|
||||
static_cast<uint32_t>(fillExtrusionDrawableUBOCount),
|
||||
static_cast<uint32_t>(heatmapDrawableUBOCount),
|
||||
static_cast<uint32_t>(heatmapTextureDrawableUBOCount),
|
||||
static_cast<uint32_t>(hillshadeDrawableUBOCount),
|
||||
static_cast<uint32_t>(hillshadePrepareDrawableUBOCount),
|
||||
static_cast<uint32_t>(colorReliefDrawableUBOCount),
|
||||
static_cast<uint32_t>(lineDrawableUBOCount),
|
||||
static_cast<uint32_t>(locationIndicatorDrawableUBOCount),
|
||||
static_cast<uint32_t>(rasterDrawableUBOCount),
|
||||
static_cast<uint32_t>(symbolDrawableUBOCount),
|
||||
static_cast<uint32_t>(wideVectorDrawableUBOCount)});
|
||||
|
||||
static constexpr uint32_t maxUBOCountPerDrawable = layerUBOStartId - globalUBOCount;
|
||||
enum {
|
||||
idDrawableReservedVertexOnlyUBO = layerSSBOStartId,
|
||||
idDrawableReservedFragmentOnlyUBO,
|
||||
drawableReservedUBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
idBackgroundDrawableUBO = idDrawableReservedVertexOnlyUBO, // SSBO
|
||||
backgroundLayerSSBOCount = drawableReservedUBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
idCircleDrawableUBO = idDrawableReservedVertexOnlyUBO, // SSBO
|
||||
circleLayerSSBOCount = drawableReservedUBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
idColorReliefDrawableUBO = idDrawableReservedVertexOnlyUBO, // SSBO
|
||||
idColorReliefTilePropsUBO = drawableReservedUBOCount, // SSBO
|
||||
colorReliefLayerSSBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
idFillDrawableUBO = idDrawableReservedVertexOnlyUBO, // SSBO
|
||||
idFillTilePropsUBO = drawableReservedUBOCount, // SSBO
|
||||
fillLayerSSBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
idFillExtrusionDrawableUBO = idDrawableReservedVertexOnlyUBO, // SSBO
|
||||
idFillExtrusionTilePropsUBO = drawableReservedUBOCount, // both SSBO and UBO?
|
||||
fillExtrusionLayerSSBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
idHeatmapDrawableUBO = idDrawableReservedVertexOnlyUBO, // SSBO
|
||||
heatmapLayerSSBOCount = drawableReservedUBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
idHillshadeDrawableUBO = idDrawableReservedVertexOnlyUBO, // SSBO
|
||||
idHillshadeTilePropsUBO = idDrawableReservedFragmentOnlyUBO, // SSBO
|
||||
hillshadeLayerSSBOCount = drawableReservedUBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
idLineDrawableUBO = idDrawableReservedVertexOnlyUBO, // SSBO
|
||||
idLineTilePropsUBO = idDrawableReservedFragmentOnlyUBO, // SSBO
|
||||
lineLayerSSBOCount = drawableReservedUBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
idRasterDrawableUBO = idDrawableReservedVertexOnlyUBO, // SSBO
|
||||
rasterLayerSSBOCount = drawableReservedUBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
idSymbolDrawableUBO = idDrawableReservedVertexOnlyUBO, // SSBO
|
||||
idSymbolTilePropsUBO = idDrawableReservedFragmentOnlyUBO, // SSBO
|
||||
symbolLayerSSBOCount = drawableReservedUBOCount
|
||||
};
|
||||
|
||||
// layer UBOs
|
||||
static constexpr uint32_t layerUBOStartId = std::max({static_cast<uint32_t>(drawableReservedUBOCount),
|
||||
static_cast<uint32_t>(backgroundLayerSSBOCount),
|
||||
static_cast<uint32_t>(circleLayerSSBOCount),
|
||||
static_cast<uint32_t>(fillLayerSSBOCount),
|
||||
static_cast<uint32_t>(fillExtrusionLayerSSBOCount),
|
||||
static_cast<uint32_t>(heatmapLayerSSBOCount),
|
||||
static_cast<uint32_t>(hillshadeLayerSSBOCount),
|
||||
static_cast<uint32_t>(colorReliefLayerSSBOCount),
|
||||
static_cast<uint32_t>(lineLayerSSBOCount),
|
||||
static_cast<uint32_t>(rasterLayerSSBOCount),
|
||||
static_cast<uint32_t>(symbolLayerSSBOCount)});
|
||||
|
||||
#if MLN_RENDER_BACKEND_VULKAN
|
||||
#define getLayerStartValue(packedValue) layerUBOStartId
|
||||
#define getEnumValue(packed, unpacked) unpacked
|
||||
#else
|
||||
#define getLayerStartValue(packedValue) packedValue
|
||||
#define getEnumValue(packed, unpacked) packed
|
||||
#endif
|
||||
|
||||
enum {
|
||||
idBackgroundPropsUBO = getLayerStartValue(backgroundDrawableUBOCount),
|
||||
backgroundUBOCount
|
||||
idBackgroundPropsUBO = getEnumValue(backgroundLayerSSBOCount, layerUBOStartId),
|
||||
backgroundLayerUBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
idCircleEvaluatedPropsUBO = getLayerStartValue(circleDrawableUBOCount),
|
||||
circleUBOCount
|
||||
idCircleEvaluatedPropsUBO = getEnumValue(circleLayerSSBOCount, layerUBOStartId),
|
||||
circleLayerUBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
clippingMaskUBOCount = getLayerStartValue(clippingMaskDrawableUBOCount)
|
||||
idColorReliefEvaluatedPropsUBO = getEnumValue(colorReliefLayerSSBOCount, layerUBOStartId),
|
||||
colorReliefLayerUBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
collisionUBOCount = getLayerStartValue(collisionDrawableUBOCount)
|
||||
idFillEvaluatedPropsUBO = getEnumValue(fillLayerSSBOCount, layerUBOStartId),
|
||||
fillLayerUBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
customGeometryUBOCount = getLayerStartValue(customGeometryDrawableUBOCount)
|
||||
idFillExtrusionPropsUBO = getEnumValue(fillExtrusionLayerSSBOCount, layerUBOStartId),
|
||||
fillExtrusionLayerUBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
customSymbolUBOCount = getLayerStartValue(customSymbolDrawableUBOCount)
|
||||
idHeatmapEvaluatedPropsUBO = getEnumValue(heatmapLayerSSBOCount, layerUBOStartId),
|
||||
heatmapLayerUBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
debugUBOCount = getLayerStartValue(debugDrawableUBOCount)
|
||||
};
|
||||
|
||||
enum {
|
||||
idFillEvaluatedPropsUBO = getLayerStartValue(fillDrawableUBOCount),
|
||||
fillUBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
idFillExtrusionPropsUBO = getLayerStartValue(fillExtrusionDrawableUBOCount),
|
||||
fillExtrusionUBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
idHeatmapEvaluatedPropsUBO = getLayerStartValue(heatmapDrawableUBOCount),
|
||||
heatmapUBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
idHeatmapTexturePropsUBO = getLayerStartValue(heatmapTextureDrawableUBOCount),
|
||||
idHeatmapTexturePropsUBO = getEnumValue(drawableReservedUBOCount, layerUBOStartId),
|
||||
heatmapTextureUBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
idHillshadeEvaluatedPropsUBO = getLayerStartValue(hillshadeDrawableUBOCount),
|
||||
hillshadeUBOCount
|
||||
idHillshadeEvaluatedPropsUBO = getEnumValue(hillshadeLayerSSBOCount, layerUBOStartId),
|
||||
hillshadeLayerUBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
hillshadePrepareUBOCount = getLayerStartValue(hillshadePrepareDrawableUBOCount)
|
||||
};
|
||||
|
||||
enum {
|
||||
idColorReliefEvaluatedPropsUBO = getLayerStartValue(colorReliefDrawableUBOCount),
|
||||
colorReliefUBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
idLineEvaluatedPropsUBO = getLayerStartValue(lineDrawableUBOCount),
|
||||
idLineEvaluatedPropsUBO = getEnumValue(lineLayerSSBOCount, layerUBOStartId),
|
||||
idLineExpressionUBO,
|
||||
lineUBOCount
|
||||
lineLayerUBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
locationIndicatorUBOCount = getLayerStartValue(locationIndicatorDrawableUBOCount)
|
||||
idRasterEvaluatedPropsUBO = getEnumValue(rasterLayerSSBOCount, layerUBOStartId),
|
||||
rasterLayerUBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
idRasterEvaluatedPropsUBO = getLayerStartValue(rasterDrawableUBOCount),
|
||||
rasterUBOCount
|
||||
idSymbolEvaluatedPropsUBO = getEnumValue(symbolLayerSSBOCount, layerUBOStartId),
|
||||
symbolLayerUBOCount
|
||||
};
|
||||
|
||||
// drawable SSBOs
|
||||
|
||||
static constexpr uint32_t drawableSSBOStartId = std::max({static_cast<uint32_t>(backgroundLayerUBOCount),
|
||||
static_cast<uint32_t>(circleLayerUBOCount),
|
||||
static_cast<uint32_t>(colorReliefLayerUBOCount),
|
||||
static_cast<uint32_t>(fillLayerUBOCount),
|
||||
static_cast<uint32_t>(fillExtrusionLayerUBOCount),
|
||||
static_cast<uint32_t>(heatmapLayerUBOCount),
|
||||
static_cast<uint32_t>(hillshadeLayerUBOCount),
|
||||
static_cast<uint32_t>(lineLayerUBOCount),
|
||||
static_cast<uint32_t>(rasterLayerUBOCount),
|
||||
static_cast<uint32_t>(symbolLayerUBOCount)});
|
||||
|
||||
enum {
|
||||
#if MLN_USE_FILL_EXTRUSION_INSTANCING
|
||||
idFillExtrusionInstanced = getEnumValue(fillExtrusionLayerUBOCount, drawableSSBOStartId),
|
||||
#endif
|
||||
fillExtrusionDrawableSSBOCount
|
||||
};
|
||||
|
||||
// drawable UBOs
|
||||
|
||||
static constexpr uint32_t drawableUBOStartId = std::max(
|
||||
{static_cast<uint32_t>(drawableSSBOStartId), static_cast<uint32_t>(fillExtrusionDrawableSSBOCount)});
|
||||
|
||||
enum {
|
||||
backgroundUBOCount = getEnumValue(backgroundLayerUBOCount, drawableUBOStartId)
|
||||
};
|
||||
|
||||
enum {
|
||||
idSymbolEvaluatedPropsUBO = getLayerStartValue(symbolDrawableUBOCount),
|
||||
symbolUBOCount
|
||||
circleUBOCount = getEnumValue(circleLayerUBOCount, drawableUBOStartId)
|
||||
};
|
||||
|
||||
enum {
|
||||
wideVectorUBOCount = getLayerStartValue(wideVectorDrawableUBOCount)
|
||||
idCollisionDrawableUBO = getEnumValue(idDrawableReservedVertexOnlyUBO, drawableUBOStartId), // UBO
|
||||
idCollisionTilePropsUBO = getEnumValue(drawableReservedUBOCount, idCollisionDrawableUBO + 1),
|
||||
collisionUBOCount
|
||||
};
|
||||
|
||||
#undef getLayerStartValue
|
||||
enum {
|
||||
idClippingMaskUBO = getEnumValue(idDrawableReservedVertexOnlyUBO, drawableUBOStartId),
|
||||
clippingMaskUBOCount = getEnumValue(drawableReservedUBOCount, idClippingMaskUBO + 1)
|
||||
};
|
||||
|
||||
enum {
|
||||
colorReliefUBOCount = getEnumValue(colorReliefLayerUBOCount, drawableUBOStartId)
|
||||
};
|
||||
|
||||
enum {
|
||||
idCustomGeometryDrawableUBO = getEnumValue(drawableReservedUBOCount, drawableUBOStartId), // UBO
|
||||
customGeometryUBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
idCustomSymbolDrawableUBO = getEnumValue(idDrawableReservedVertexOnlyUBO, drawableUBOStartId), // UBO
|
||||
customSymbolUBOCount = getEnumValue(drawableReservedUBOCount, idCustomSymbolDrawableUBO + 1)
|
||||
};
|
||||
|
||||
enum {
|
||||
idDebugUBO = getEnumValue(drawableReservedUBOCount, drawableUBOStartId), // UBO
|
||||
debugUBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
fillUBOCount = getEnumValue(fillLayerUBOCount, drawableUBOStartId)
|
||||
};
|
||||
|
||||
enum {
|
||||
fillExtrusionUBOCount = getEnumValue(fillExtrusionLayerUBOCount, drawableUBOStartId)
|
||||
};
|
||||
|
||||
enum {
|
||||
heatmapUBOCount = getEnumValue(heatmapLayerUBOCount, drawableUBOStartId)
|
||||
};
|
||||
|
||||
enum {
|
||||
idHillshadePrepareDrawableUBO = getEnumValue(idDrawableReservedVertexOnlyUBO, drawableUBOStartId), // UBO
|
||||
idHillshadePrepareTilePropsUBO = getEnumValue(drawableReservedUBOCount, idHillshadePrepareDrawableUBO + 1), // UBO
|
||||
hillshadePrepareUBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
hillshadeUBOCount = getEnumValue(hillshadeLayerUBOCount, drawableUBOStartId)
|
||||
};
|
||||
|
||||
enum {
|
||||
lineUBOCount = getEnumValue(lineLayerUBOCount, drawableUBOStartId)
|
||||
};
|
||||
|
||||
enum {
|
||||
idLocationIndicatorDrawableUBO = getEnumValue(drawableReservedUBOCount, drawableUBOStartId), // UBO
|
||||
locationIndicatorUBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
rasterUBOCount = getEnumValue(rasterLayerUBOCount, drawableUBOStartId)
|
||||
};
|
||||
|
||||
enum {
|
||||
symbolUBOCount = getEnumValue(symbolLayerUBOCount, drawableUBOStartId)
|
||||
};
|
||||
|
||||
enum {
|
||||
idWideVectorUniformsUBO = getEnumValue(idDrawableReservedVertexOnlyUBO, drawableUBOStartId), // UBO
|
||||
idWideVectorUniformWideVecUBO = getEnumValue(drawableReservedUBOCount, idWideVectorUniformsUBO + 1), // UBO
|
||||
wideVectorUBOCount
|
||||
};
|
||||
|
||||
#undef getEnumValue
|
||||
|
||||
static constexpr uint32_t maxUBOCountPerShader = std::max({static_cast<uint32_t>(backgroundUBOCount),
|
||||
static_cast<uint32_t>(circleUBOCount),
|
||||
static_cast<uint32_t>(clippingMaskUBOCount),
|
||||
static_cast<uint32_t>(collisionUBOCount),
|
||||
static_cast<uint32_t>(customSymbolUBOCount),
|
||||
static_cast<uint32_t>(colorReliefUBOCount),
|
||||
static_cast<uint32_t>(customGeometryUBOCount),
|
||||
static_cast<uint32_t>(debugUBOCount),
|
||||
static_cast<uint32_t>(fillUBOCount),
|
||||
static_cast<uint32_t>(fillExtrusionUBOCount),
|
||||
static_cast<uint32_t>(heatmapUBOCount),
|
||||
static_cast<uint32_t>(heatmapTextureUBOCount),
|
||||
static_cast<uint32_t>(hillshadeUBOCount),
|
||||
static_cast<uint32_t>(heatmapUBOCount),
|
||||
static_cast<uint32_t>(hillshadePrepareUBOCount),
|
||||
static_cast<uint32_t>(colorReliefUBOCount),
|
||||
static_cast<uint32_t>(hillshadeUBOCount),
|
||||
static_cast<uint32_t>(lineUBOCount),
|
||||
static_cast<uint32_t>(locationIndicatorUBOCount),
|
||||
static_cast<uint32_t>(rasterUBOCount),
|
||||
static_cast<uint32_t>(symbolUBOCount),
|
||||
static_cast<uint32_t>(wideVectorUBOCount)});
|
||||
|
||||
static constexpr uint32_t maxSSBOCountPerLayer = maxUBOCountPerDrawable;
|
||||
static constexpr uint32_t maxUBOCountPerLayer = maxUBOCountPerShader - layerUBOStartId;
|
||||
static constexpr uint32_t maxSSBOCountPerLayer = layerUBOStartId - layerSSBOStartId;
|
||||
static constexpr uint32_t maxUBOCountPerLayer = drawableSSBOStartId - layerUBOStartId;
|
||||
|
||||
static constexpr uint32_t maxSSBOCountPerDrawable = drawableUBOStartId - drawableSSBOStartId;
|
||||
static constexpr uint32_t maxUBOCountPerDrawable = maxUBOCountPerShader - drawableUBOStartId;
|
||||
|
||||
// Texture defines
|
||||
enum {
|
||||
|
||||
@@ -8,8 +8,8 @@ namespace shaders {
|
||||
|
||||
constexpr auto collisionShaderPrelude = R"(
|
||||
|
||||
#define idCollisionDrawableUBO idDrawableReservedVertexOnlyUBO
|
||||
#define idCollisionTilePropsUBO drawableReservedUBOCount
|
||||
#define idCollisionDrawableUBO drawableUBOStartId
|
||||
#define idCollisionTilePropsUBO drawableUBOStartId + 1
|
||||
|
||||
)";
|
||||
|
||||
|
||||
@@ -67,15 +67,33 @@ vec2 get_pattern_pos(const vec2 pixel_coord_upper, const vec2 pixel_coord_lower,
|
||||
return (tile_units_to_pixels * pos + offset) / pattern_size;
|
||||
}
|
||||
|
||||
#define GLOBAL_SET_INDEX 0
|
||||
#define LAYER_SET_INDEX 1
|
||||
#define DRAWABLE_UBO_SET_INDEX 2
|
||||
#define DRAWABLE_IMAGE_SET_INDEX 3
|
||||
vec2 unpack_int(int value) {
|
||||
const int low = (value << 16) >> 16;
|
||||
const int high = value >> 16;
|
||||
|
||||
#define idDrawableReservedVertexOnlyUBO 0
|
||||
#define idDrawableReservedFragmentOnlyUBO 1
|
||||
#define drawableReservedUBOCount 2
|
||||
#define layerUBOStartId 3
|
||||
return vec2(low, high);
|
||||
}
|
||||
|
||||
vec2 unpack_uint(uint value) {
|
||||
const uint low = value & 0xFFFF;
|
||||
const uint high = (value >> 16) & 0xFFFF;
|
||||
|
||||
return vec2(low, high);
|
||||
}
|
||||
|
||||
#define GLOBAL_SET_INDEX 0
|
||||
#define LAYER_SET_INDEX 1
|
||||
#define DRAWABLE_UBO_SET_INDEX 2
|
||||
#define DRAWABLE_IMAGE_SET_INDEX 3
|
||||
|
||||
#define layerSSBOStartId 0
|
||||
#define layerUBOStartId 3
|
||||
#define drawableSSBOStartId 0
|
||||
#define drawableUBOStartId 1
|
||||
|
||||
#define idDrawableReservedVertexOnlyUBO layerSSBOStartId
|
||||
#define idDrawableReservedFragmentOnlyUBO idDrawableReservedVertexOnlyUBO + 1
|
||||
#define drawableReservedUBOCount idDrawableReservedFragmentOnlyUBO + 1
|
||||
|
||||
layout(set = GLOBAL_SET_INDEX, binding = 0) uniform GlobalPaintParamsUBO {
|
||||
vec2 pattern_atlas_texsize;
|
||||
@@ -110,15 +128,19 @@ void applySurfaceTransform() {
|
||||
#define M_PI 3.1415926535897932384626433832795
|
||||
#define SDF_PX 8.0
|
||||
|
||||
#define GLOBAL_SET_INDEX 0
|
||||
#define LAYER_SET_INDEX 1
|
||||
#define DRAWABLE_UBO_SET_INDEX 2
|
||||
#define DRAWABLE_IMAGE_SET_INDEX 3
|
||||
#define GLOBAL_SET_INDEX 0
|
||||
#define LAYER_SET_INDEX 1
|
||||
#define DRAWABLE_UBO_SET_INDEX 2
|
||||
#define DRAWABLE_IMAGE_SET_INDEX 3
|
||||
|
||||
#define idDrawableReservedVertexOnlyUBO 0
|
||||
#define idDrawableReservedFragmentOnlyUBO 1
|
||||
#define drawableReservedUBOCount 2
|
||||
#define layerUBOStartId 3
|
||||
#define layerSSBOStartId 0
|
||||
#define layerUBOStartId 3
|
||||
#define drawableSSBOStartId 0
|
||||
#define drawableUBOStartId 1
|
||||
|
||||
#define idDrawableReservedVertexOnlyUBO layerSSBOStartId
|
||||
#define idDrawableReservedFragmentOnlyUBO idDrawableReservedVertexOnlyUBO + 1
|
||||
#define drawableReservedUBOCount idDrawableReservedFragmentOnlyUBO + 1
|
||||
|
||||
layout(set = GLOBAL_SET_INDEX, binding = 0) uniform GlobalPaintParamsUBO {
|
||||
vec2 pattern_atlas_texsize;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
constexpr auto customGeometryShaderPrelude = R"(#define idCustomGeometryDrawableUBO drawableReservedUBOCount)";
|
||||
constexpr auto customGeometryShaderPrelude = R"(#define idCustomGeometryDrawableUBO drawableUBOStartId)";
|
||||
|
||||
template <>
|
||||
struct ShaderSource<BuiltIn::CustomGeometryShader, gfx::Backend::Type::Vulkan> {
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
constexpr auto customSymbolIconShaderPrelude = R"(#define idCustomSymbolDrawableUBO idDrawableReservedVertexOnlyUBO)";
|
||||
constexpr auto customSymbolIconShaderPrelude = R"(#define idCustomSymbolDrawableUBO drawableUBOStartId)";
|
||||
|
||||
template <>
|
||||
struct ShaderSource<BuiltIn::CustomSymbolIconShader, gfx::Backend::Type::Vulkan> {
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
constexpr auto debugShaderPrelude = R"(#define idDebugUBO drawableReservedUBOCount)";
|
||||
constexpr auto debugShaderPrelude = R"(#define idDebugUBO drawableUBOStartId)";
|
||||
|
||||
template <>
|
||||
struct ShaderSource<BuiltIn::DebugShader, gfx::Backend::Type::Vulkan> {
|
||||
|
||||
@@ -8,9 +8,10 @@ namespace shaders {
|
||||
|
||||
constexpr auto fillExtrusionShaderPrelude = R"(
|
||||
|
||||
#define idFillExtrusionDrawableUBO idDrawableReservedVertexOnlyUBO
|
||||
#define idFillExtrusionTilePropsUBO drawableReservedUBOCount
|
||||
#define idFillExtrusionPropsUBO layerUBOStartId
|
||||
#define idFillExtrusionDrawableUBO idDrawableReservedVertexOnlyUBO
|
||||
#define idFillExtrusionTilePropsUBO drawableReservedUBOCount
|
||||
#define idFillExtrusionPropsUBO layerUBOStartId
|
||||
#define idFillExtrusionInstancedDrawableUBO drawableSSBOStartId
|
||||
|
||||
)";
|
||||
|
||||
@@ -18,7 +19,7 @@ template <>
|
||||
struct ShaderSource<BuiltIn::FillExtrusionShader, gfx::Backend::Type::Vulkan> {
|
||||
static constexpr const char* name = "FillExtrusionShader";
|
||||
|
||||
static const std::array<AttributeInfo, 5> attributes;
|
||||
static const std::array<AttributeInfo, 4> attributes;
|
||||
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
|
||||
static const std::array<TextureInfo, 0> textures;
|
||||
|
||||
@@ -26,18 +27,17 @@ struct ShaderSource<BuiltIn::FillExtrusionShader, gfx::Backend::Type::Vulkan> {
|
||||
static constexpr auto vertex = R"(
|
||||
|
||||
layout(location = 0) in ivec2 in_position;
|
||||
layout(location = 1) in ivec4 in_normal_ed;
|
||||
|
||||
#if !defined(HAS_UNIFORM_u_color)
|
||||
layout(location = 2) in vec4 in_color;
|
||||
layout(location = 1) in vec4 in_color;
|
||||
#endif
|
||||
|
||||
#if !defined(HAS_UNIFORM_u_base)
|
||||
layout(location = 3) in vec2 in_base;
|
||||
layout(location = 2) in vec2 in_base;
|
||||
#endif
|
||||
|
||||
#if !defined(HAS_UNIFORM_u_height)
|
||||
layout(location = 4) in vec2 in_height;
|
||||
layout(location = 3) in vec2 in_height;
|
||||
#endif
|
||||
|
||||
layout(push_constant) uniform Constants {
|
||||
@@ -100,8 +100,8 @@ void main() {
|
||||
vec4 color = unpack_mix_color(in_color, drawable.color_t);
|
||||
#endif
|
||||
|
||||
const vec3 normal = in_normal_ed.xyz;
|
||||
const float t = mod(normal.x, 2.0);
|
||||
const vec3 normal = vec3(0.0, 0.0, 1.0);
|
||||
const float t = 1.0;
|
||||
const float z = t != 0.0 ? height : base;
|
||||
|
||||
gl_Position = drawable.matrix * vec4(in_position, z, 1.0);
|
||||
@@ -121,7 +121,177 @@ void main() {
|
||||
color += vec4(0.03, 0.03, 0.03, 1.0);
|
||||
|
||||
// Calculate cos(theta), where theta is the angle between surface normal and diffuse light ray
|
||||
const float directionalFraction = clamp(dot(normal / 16384.0, props.light_position_base.xyz), 0.0, 1.0);
|
||||
const float directionalFraction = clamp(dot(normal, props.light_position_base.xyz), 0.0, 1.0);
|
||||
|
||||
// Adjust directional so that the range of values for highlight/shading is
|
||||
// narrower with lower light intensity and with lighter/brighter surface colors
|
||||
const float minDirectional = 1.0 - props.light_intensity;
|
||||
const float maxDirectional = max(1.0 - luminance + props.light_intensity, 1.0);
|
||||
float directional = mix(minDirectional, maxDirectional, directionalFraction);
|
||||
|
||||
// Add gradient along z axis of side surfaces
|
||||
if (normal.y != 0.0) {
|
||||
// This avoids another branching statement, but multiplies by a constant of 0.84 if no
|
||||
// vertical gradient, and otherwise calculates the gradient based on base + height
|
||||
// TODO: If we're optimizing to the level of avoiding branches, we should pre-compute
|
||||
// the square root when height is a uniform.
|
||||
const float fMin = mix(0.7, 0.98, 1.0 - props.light_intensity);
|
||||
const float factor = clamp((t + base) * pow(height / 150.0, 0.5), fMin, 1.0);
|
||||
directional *= (1.0 - props.vertical_gradient) + (props.vertical_gradient * factor);
|
||||
}
|
||||
|
||||
// Assign final color based on surface + ambient light color, diffuse light directional,
|
||||
// and light color with lower bounds adjusted to hue of light so that shading is tinted
|
||||
// with the complementary (opposite) color to the light color
|
||||
const vec3 light_color = props.light_color_pad.rgb;
|
||||
const vec3 minLight = mix(vec3(0.0), vec3(0.3), 1.0 - light_color.rgb);
|
||||
vcolor += vec4(clamp(color.rgb * directional * light_color.rgb, minLight, vec3(1.0)), 0.0);
|
||||
|
||||
frag_color = vcolor * props.opacity;
|
||||
}
|
||||
)";
|
||||
static constexpr auto fragment = R"(
|
||||
|
||||
layout(location = 0) in vec4 frag_color;
|
||||
layout(location = 0) out vec4 out_color;
|
||||
|
||||
void main() {
|
||||
out_color = frag_color;
|
||||
}
|
||||
)";
|
||||
};
|
||||
|
||||
template <>
|
||||
struct ShaderSource<BuiltIn::FillExtrusionInstancedShader, gfx::Backend::Type::Vulkan> {
|
||||
static constexpr const char* name = "FillExtrusionInstancedShader";
|
||||
|
||||
static const std::array<AttributeInfo, 1> attributes;
|
||||
static const std::array<AttributeInfo, 5> instanceAttributes;
|
||||
static const std::array<TextureInfo, 0> textures;
|
||||
|
||||
static constexpr auto prelude = fillExtrusionShaderPrelude;
|
||||
|
||||
static constexpr auto vertex = R"(
|
||||
|
||||
layout(location = 0) in ivec2 in_position;
|
||||
|
||||
#if !defined(HAS_UNIFORM_u_color)
|
||||
layout(location = 3) in vec4 in_color;
|
||||
#endif
|
||||
|
||||
#if !defined(HAS_UNIFORM_u_base)
|
||||
layout(location = 4) in vec2 in_base;
|
||||
#endif
|
||||
|
||||
#if !defined(HAS_UNIFORM_u_height)
|
||||
layout(location = 5) in vec2 in_height;
|
||||
#endif
|
||||
|
||||
layout(push_constant) uniform Constants {
|
||||
int ubo_index;
|
||||
} constant;
|
||||
|
||||
struct FillExtrusionDrawableUBO {
|
||||
mat4 matrix;
|
||||
vec2 pixel_coord_upper;
|
||||
vec2 pixel_coord_lower;
|
||||
float height_factor;
|
||||
float tile_ratio;
|
||||
// Interpolations
|
||||
float base_t;
|
||||
float height_t;
|
||||
float color_t;
|
||||
float pattern_from_t;
|
||||
float pattern_to_t;
|
||||
float pad1;
|
||||
};
|
||||
|
||||
layout(std140, set = LAYER_SET_INDEX, binding = idFillExtrusionDrawableUBO) readonly buffer FillExtrusionDrawableUBOVector {
|
||||
FillExtrusionDrawableUBO drawable_ubo[];
|
||||
} drawableVector;
|
||||
|
||||
layout(set = LAYER_SET_INDEX, binding = idFillExtrusionPropsUBO) uniform FillExtrusionPropsUBO {
|
||||
vec4 color;
|
||||
vec4 light_color_pad;
|
||||
vec4 light_position_base;
|
||||
float height;
|
||||
float light_intensity;
|
||||
float vertical_gradient;
|
||||
float opacity;
|
||||
float fade;
|
||||
float from_scale;
|
||||
float to_scale;
|
||||
float pad2;
|
||||
} props;
|
||||
|
||||
struct OutlineInstance {
|
||||
int pos;
|
||||
uint ed_discard;
|
||||
};
|
||||
|
||||
layout(std430, set = DRAWABLE_UBO_SET_INDEX, binding = idFillExtrusionInstancedDrawableUBO) readonly buffer FillExtrusionInstanceVector {
|
||||
OutlineInstance instance[];
|
||||
} instanceVector;
|
||||
|
||||
layout(location = 0) out mediump vec4 frag_color;
|
||||
|
||||
void main() {
|
||||
|
||||
const vec2 instancePos = unpack_int(instanceVector.instance[gl_InstanceIndex].pos);
|
||||
const vec2 instanceEd = unpack_uint(instanceVector.instance[gl_InstanceIndex].ed_discard);
|
||||
|
||||
if (instanceEd.y > 0.0) {
|
||||
gl_Position = vec4(0.0);
|
||||
frag_color = vec4(0.0);
|
||||
return;
|
||||
}
|
||||
|
||||
const FillExtrusionDrawableUBO drawable = drawableVector.drawable_ubo[constant.ubo_index];
|
||||
|
||||
#if defined(HAS_UNIFORM_u_base)
|
||||
const float base = props.light_position_base.w;
|
||||
#else
|
||||
const float base = max(unpack_mix_float(in_base, drawable.base_t), 0.0);
|
||||
#endif
|
||||
|
||||
#if defined(HAS_UNIFORM_u_height)
|
||||
const float height = props.height;
|
||||
#else
|
||||
const float height = max(unpack_mix_float(in_height, drawable.height_t), 0.0);
|
||||
#endif
|
||||
|
||||
#if defined(HAS_UNIFORM_u_color)
|
||||
vec4 color = props.color;
|
||||
#else
|
||||
vec4 color = unpack_mix_color(in_color, drawable.color_t);
|
||||
#endif
|
||||
|
||||
const vec2 p1 = unpack_int(instanceVector.instance[gl_InstanceIndex + 1].pos);
|
||||
const vec2 p2 = unpack_int(instanceVector.instance[gl_InstanceIndex + 0].pos);
|
||||
const vec2 perp = normalize(p1 - p2);
|
||||
|
||||
const vec3 normal = vec3(-perp.y, perp.x, 0.0);
|
||||
const float t = float(in_position.y);
|
||||
const float z = t != 0.0 ? height : base;
|
||||
|
||||
gl_Position = drawable.matrix * vec4(unpack_int(instanceVector.instance[gl_InstanceIndex + in_position.x].pos), z, 1.0);
|
||||
applySurfaceTransform();
|
||||
|
||||
#if defined(OVERDRAW_INSPECTOR)
|
||||
frag_color = vec4(1.0);
|
||||
return;
|
||||
#endif
|
||||
|
||||
// Relative luminance (how dark/bright is the surface color?)
|
||||
const float luminance = color.r * 0.2126 + color.g * 0.7152 + color.b * 0.0722;
|
||||
|
||||
vec4 vcolor = vec4(0.0, 0.0, 0.0, 1.0);
|
||||
|
||||
// Add slight ambient lighting so no extrusions are totally black
|
||||
color += vec4(0.03, 0.03, 0.03, 1.0);
|
||||
|
||||
// Calculate cos(theta), where theta is the angle between surface normal and diffuse light ray
|
||||
const float directionalFraction = clamp(dot(normal, props.light_position_base.xyz), 0.0, 1.0);
|
||||
|
||||
// Adjust directional so that the range of values for highlight/shading is
|
||||
// narrower with lower light intensity and with lighter/brighter surface colors
|
||||
@@ -166,7 +336,7 @@ template <>
|
||||
struct ShaderSource<BuiltIn::FillExtrusionPatternShader, gfx::Backend::Type::Vulkan> {
|
||||
static constexpr const char* name = "FillExtrusionPatternShader";
|
||||
|
||||
static const std::array<AttributeInfo, 6> attributes;
|
||||
static const std::array<AttributeInfo, 5> attributes;
|
||||
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
|
||||
static const std::array<TextureInfo, 1> textures;
|
||||
|
||||
@@ -174,22 +344,21 @@ struct ShaderSource<BuiltIn::FillExtrusionPatternShader, gfx::Backend::Type::Vul
|
||||
static constexpr auto vertex = R"(
|
||||
|
||||
layout(location = 0) in ivec2 in_position;
|
||||
layout(location = 1) in ivec4 in_normal_ed;
|
||||
|
||||
#if !defined(HAS_UNIFORM_u_base)
|
||||
layout(location = 2) in vec2 in_base;
|
||||
layout(location = 1) in vec2 in_base;
|
||||
#endif
|
||||
|
||||
#if !defined(HAS_UNIFORM_u_height)
|
||||
layout(location = 3) in vec2 in_height;
|
||||
layout(location = 2) in vec2 in_height;
|
||||
#endif
|
||||
|
||||
#if !defined(HAS_UNIFORM_u_pattern_from)
|
||||
layout(location = 4) in uvec4 in_pattern_from;
|
||||
layout(location = 3) in uvec4 in_pattern_from;
|
||||
#endif
|
||||
|
||||
#if !defined(HAS_UNIFORM_u_pattern_to)
|
||||
layout(location = 5) in uvec4 in_pattern_to;
|
||||
layout(location = 4) in uvec4 in_pattern_to;
|
||||
#endif
|
||||
|
||||
layout(push_constant) uniform Constants {
|
||||
@@ -215,13 +384,17 @@ layout(std140, set = LAYER_SET_INDEX, binding = idFillExtrusionDrawableUBO) read
|
||||
FillExtrusionDrawableUBO drawable_ubo[];
|
||||
} drawableVector;
|
||||
|
||||
layout(set = DRAWABLE_UBO_SET_INDEX, binding = idFillExtrusionTilePropsUBO) uniform FillExtrusionTilePropsUBO {
|
||||
struct FillExtrusionTilePropsUBO {
|
||||
vec4 pattern_from;
|
||||
vec4 pattern_to;
|
||||
vec2 texsize;
|
||||
float pad1;
|
||||
float pad2;
|
||||
} tileProps;
|
||||
};
|
||||
|
||||
layout(std140, set = LAYER_SET_INDEX, binding = idFillExtrusionTilePropsUBO) readonly buffer FillExtrusionTilePropsUBOVector {
|
||||
FillExtrusionTilePropsUBO tile_props_ubo[];
|
||||
} tilePropsVector;
|
||||
|
||||
layout(set = LAYER_SET_INDEX, binding = idFillExtrusionPropsUBO) uniform FillExtrusionPropsUBO {
|
||||
vec4 color;
|
||||
@@ -251,6 +424,7 @@ layout(location = 4) out mediump vec4 frag_pattern_to;
|
||||
|
||||
void main() {
|
||||
const FillExtrusionDrawableUBO drawable = drawableVector.drawable_ubo[constant.ubo_index];
|
||||
const FillExtrusionTilePropsUBO tileProps = tilePropsVector.tile_props_ubo[constant.ubo_index];
|
||||
|
||||
#if defined(HAS_UNIFORM_u_base)
|
||||
const float base = props.light_position_base.w;
|
||||
@@ -264,16 +438,19 @@ void main() {
|
||||
const float height = max(unpack_mix_float(in_height, drawable.height_t), 0.0);
|
||||
#endif
|
||||
|
||||
const vec3 normal = in_normal_ed.xyz;
|
||||
const float edgedistance = in_normal_ed.w;
|
||||
const float t = mod(normal.x, 2.0);
|
||||
const vec3 normal = vec3(0.0, 0.0, 1.0);
|
||||
const float t = 1.0;
|
||||
const float z = t != 0.0 ? height : base;
|
||||
|
||||
gl_Position = drawable.matrix * vec4(in_position, z, 1.0);
|
||||
applySurfaceTransform();
|
||||
|
||||
#if defined(OVERDRAW_INSPECTOR)
|
||||
frag_color = vec4(1.0);
|
||||
frag_lighting = vec4(1.0);
|
||||
frag_pos_a = vec4(0.0);
|
||||
frag_pos_b = vec4(0.0);
|
||||
frag_pattern_from = vec4(0.0);
|
||||
frag_pattern_to = vec4(0.0);
|
||||
return;
|
||||
#endif
|
||||
|
||||
@@ -304,12 +481,298 @@ void main() {
|
||||
const vec2 display_size_a = vec2((pattern_br_a.x - pattern_tl_a.x) / pixelRatio, (pattern_br_a.y - pattern_tl_a.y) / pixelRatio);
|
||||
const vec2 display_size_b = vec2((pattern_br_b.x - pattern_tl_b.x) / pixelRatio, (pattern_br_b.y - pattern_tl_b.y) / pixelRatio);
|
||||
|
||||
const vec2 pos = normal.x == 1.0 && normal.y == 0.0 && normal.z == 16384.0
|
||||
? vec2(in_position) // extrusion top
|
||||
: vec2(edgedistance, z * drawable.height_factor); // extrusion side
|
||||
const vec2 pos = vec2(in_position); // extrusion side
|
||||
|
||||
vec4 lighting = vec4(0.0, 0.0, 0.0, 1.0);
|
||||
float directional = clamp(dot(normal / 16383.0, props.light_position_base.xyz), 0.0, 1.0);
|
||||
float directional = clamp(dot(normal, props.light_position_base.xyz), 0.0, 1.0);
|
||||
directional = mix((1.0 - props.light_intensity), max((0.5 + props.light_intensity), 1.0), directional);
|
||||
|
||||
if (normal.y != 0.0) {
|
||||
// This avoids another branching statement, but multiplies by a constant of 0.84 if no vertical gradient,
|
||||
// and otherwise calculates the gradient based on base + height
|
||||
directional *= (
|
||||
(1.0 - props.vertical_gradient) +
|
||||
(props.vertical_gradient * clamp((t + base) * pow(height / 150.0, 0.5), mix(0.7, 0.98, 1.0 - props.light_intensity), 1.0)));
|
||||
}
|
||||
|
||||
lighting.rgb += clamp(directional * props.light_color_pad.rgb, mix(vec3(0.0), vec3(0.3), 1.0 - props.light_color_pad.rgb), vec3(1.0));
|
||||
lighting *= props.opacity;
|
||||
|
||||
frag_lighting = lighting;
|
||||
frag_pos_a = get_pattern_pos(drawable.pixel_coord_upper, drawable.pixel_coord_lower, fromScale * display_size_a, tileZoomRatio, pos);
|
||||
frag_pos_b = get_pattern_pos(drawable.pixel_coord_upper, drawable.pixel_coord_lower, toScale * display_size_b, tileZoomRatio, pos);
|
||||
|
||||
#if !defined(HAS_UNIFORM_u_pattern_from)
|
||||
frag_pattern_from = in_pattern_from;
|
||||
#endif
|
||||
|
||||
#if !defined(HAS_UNIFORM_u_pattern_to)
|
||||
frag_pattern_to = in_pattern_to;
|
||||
#endif
|
||||
}
|
||||
)";
|
||||
|
||||
static constexpr auto fragment = R"(
|
||||
|
||||
layout(location = 0) in mediump vec4 frag_lighting;
|
||||
layout(location = 1) in mediump vec2 frag_pos_a;
|
||||
layout(location = 2) in mediump vec2 frag_pos_b;
|
||||
|
||||
#if !defined(HAS_UNIFORM_u_pattern_from)
|
||||
layout(location = 3) in mediump vec4 frag_pattern_from;
|
||||
#endif
|
||||
|
||||
#if !defined(HAS_UNIFORM_u_pattern_to)
|
||||
layout(location = 4) in mediump vec4 frag_pattern_to;
|
||||
#endif
|
||||
|
||||
layout(location = 0) out vec4 out_color;
|
||||
|
||||
layout(push_constant) uniform Constants {
|
||||
int ubo_index;
|
||||
} constant;
|
||||
|
||||
struct FillExtrusionTilePropsUBO {
|
||||
vec4 pattern_from;
|
||||
vec4 pattern_to;
|
||||
vec2 texsize;
|
||||
float pad1;
|
||||
float pad2;
|
||||
};
|
||||
|
||||
layout(std140, set = LAYER_SET_INDEX, binding = idFillExtrusionTilePropsUBO) readonly buffer FillExtrusionTilePropsUBOVector {
|
||||
FillExtrusionTilePropsUBO tile_props_ubo[];
|
||||
} tilePropsVector;
|
||||
|
||||
layout(set = LAYER_SET_INDEX, binding = idFillExtrusionPropsUBO) uniform FillExtrusionPropsUBO {
|
||||
vec4 color;
|
||||
vec4 light_color_pad;
|
||||
vec4 light_position_base;
|
||||
float height;
|
||||
float light_intensity;
|
||||
float vertical_gradient;
|
||||
float opacity;
|
||||
float fade;
|
||||
float from_scale;
|
||||
float to_scale;
|
||||
float pad2;
|
||||
} props;
|
||||
|
||||
layout(set = DRAWABLE_IMAGE_SET_INDEX, binding = 0) uniform sampler2D image0_sampler;
|
||||
|
||||
void main() {
|
||||
|
||||
#if defined(OVERDRAW_INSPECTOR)
|
||||
out_color = vec4(1.0);
|
||||
return;
|
||||
#endif
|
||||
|
||||
const FillExtrusionTilePropsUBO tileProps = tilePropsVector.tile_props_ubo[constant.ubo_index];
|
||||
|
||||
#if defined(HAS_UNIFORM_u_pattern_from)
|
||||
const vec4 pattern_from = tileProps.pattern_from;
|
||||
#else
|
||||
const vec4 pattern_from = frag_pattern_from;
|
||||
#endif
|
||||
#if defined(HAS_UNIFORM_u_pattern_to)
|
||||
const vec4 pattern_to = tileProps.pattern_to;
|
||||
#else
|
||||
const vec4 pattern_to = frag_pattern_to;
|
||||
#endif
|
||||
|
||||
const vec2 pattern_tl_a = pattern_from.xy;
|
||||
const vec2 pattern_br_a = pattern_from.zw;
|
||||
const vec2 pattern_tl_b = pattern_to.xy;
|
||||
const vec2 pattern_br_b = pattern_to.zw;
|
||||
|
||||
const vec2 imagecoord = mod(frag_pos_a, 1.0);
|
||||
const vec2 pos = mix(pattern_tl_a / tileProps.texsize, pattern_br_a / tileProps.texsize, imagecoord);
|
||||
const vec4 color1 = texture(image0_sampler, pos);
|
||||
|
||||
const vec2 imagecoord_b = mod(frag_pos_b, 1.0);
|
||||
const vec2 pos2 = mix(pattern_tl_b / tileProps.texsize, pattern_br_b / tileProps.texsize, imagecoord_b);
|
||||
const vec4 color2 = texture(image0_sampler, pos2);
|
||||
|
||||
out_color = mix(color1, color2, props.fade) * frag_lighting;
|
||||
}
|
||||
)";
|
||||
};
|
||||
|
||||
template <>
|
||||
struct ShaderSource<BuiltIn::FillExtrusionPatternInstancedShader, gfx::Backend::Type::Vulkan> {
|
||||
static constexpr const char* name = "FillExtrusionPatternInstancedShader";
|
||||
|
||||
static const std::array<AttributeInfo, 1> attributes;
|
||||
static const std::array<AttributeInfo, 6> instanceAttributes;
|
||||
static const std::array<TextureInfo, 1> textures;
|
||||
|
||||
static constexpr auto prelude = fillExtrusionShaderPrelude;
|
||||
static constexpr auto vertex = R"(
|
||||
|
||||
layout(location = 0) in ivec2 in_position;
|
||||
|
||||
#if !defined(HAS_UNIFORM_u_base)
|
||||
layout(location = 3) in vec2 in_base;
|
||||
#endif
|
||||
|
||||
#if !defined(HAS_UNIFORM_u_height)
|
||||
layout(location = 4) in vec2 in_height;
|
||||
#endif
|
||||
|
||||
#if !defined(HAS_UNIFORM_u_pattern_from)
|
||||
layout(location = 5) in uvec4 in_pattern_from;
|
||||
#endif
|
||||
|
||||
#if !defined(HAS_UNIFORM_u_pattern_to)
|
||||
layout(location = 6) in uvec4 in_pattern_to;
|
||||
#endif
|
||||
|
||||
layout(push_constant) uniform Constants {
|
||||
int ubo_index;
|
||||
} constant;
|
||||
|
||||
struct FillExtrusionDrawableUBO {
|
||||
mat4 matrix;
|
||||
vec2 pixel_coord_upper;
|
||||
vec2 pixel_coord_lower;
|
||||
float height_factor;
|
||||
float tile_ratio;
|
||||
// Interpolations
|
||||
float base_t;
|
||||
float height_t;
|
||||
float color_t;
|
||||
float pattern_from_t;
|
||||
float pattern_to_t;
|
||||
float pad1;
|
||||
};
|
||||
|
||||
layout(std140, set = LAYER_SET_INDEX, binding = idFillExtrusionDrawableUBO) readonly buffer FillExtrusionDrawableUBOVector {
|
||||
FillExtrusionDrawableUBO drawable_ubo[];
|
||||
} drawableVector;
|
||||
|
||||
struct OutlineInstance {
|
||||
int pos;
|
||||
uint ed_discard;
|
||||
};
|
||||
|
||||
layout(std430, set = DRAWABLE_UBO_SET_INDEX, binding = idFillExtrusionInstancedDrawableUBO) readonly buffer FillExtrusionInstanceVector {
|
||||
OutlineInstance instance[];
|
||||
} instanceVector;
|
||||
|
||||
struct FillExtrusionTilePropsUBO {
|
||||
vec4 pattern_from;
|
||||
vec4 pattern_to;
|
||||
vec2 texsize;
|
||||
float pad1;
|
||||
float pad2;
|
||||
};
|
||||
|
||||
layout(std140, set = LAYER_SET_INDEX, binding = idFillExtrusionTilePropsUBO) readonly buffer FillExtrusionTilePropsUBOVector {
|
||||
FillExtrusionTilePropsUBO tile_props_ubo[];
|
||||
} tilePropsVector;
|
||||
|
||||
layout(set = LAYER_SET_INDEX, binding = idFillExtrusionPropsUBO) uniform FillExtrusionPropsUBO {
|
||||
vec4 color;
|
||||
vec4 light_color_pad;
|
||||
vec4 light_position_base;
|
||||
float height;
|
||||
float light_intensity;
|
||||
float vertical_gradient;
|
||||
float opacity;
|
||||
float fade;
|
||||
float from_scale;
|
||||
float to_scale;
|
||||
float pad2;
|
||||
} props;
|
||||
|
||||
layout(location = 0) out mediump vec4 frag_lighting;
|
||||
layout(location = 1) out mediump vec2 frag_pos_a;
|
||||
layout(location = 2) out mediump vec2 frag_pos_b;
|
||||
|
||||
#if !defined(HAS_UNIFORM_u_pattern_from)
|
||||
layout(location = 3) out mediump vec4 frag_pattern_from;
|
||||
#endif
|
||||
|
||||
#if !defined(HAS_UNIFORM_u_pattern_to)
|
||||
layout(location = 4) out mediump vec4 frag_pattern_to;
|
||||
#endif
|
||||
|
||||
void main() {
|
||||
const vec2 instancePos = unpack_int(instanceVector.instance[gl_InstanceIndex].pos);
|
||||
const vec2 instanceEd = unpack_uint(instanceVector.instance[gl_InstanceIndex].ed_discard);
|
||||
|
||||
if (instanceEd.y > 0.0) {
|
||||
gl_Position = vec4(0.0);
|
||||
return;
|
||||
}
|
||||
|
||||
const FillExtrusionDrawableUBO drawable = drawableVector.drawable_ubo[constant.ubo_index];
|
||||
const FillExtrusionTilePropsUBO tileProps = tilePropsVector.tile_props_ubo[constant.ubo_index];
|
||||
|
||||
#if defined(HAS_UNIFORM_u_base)
|
||||
const float base = props.light_position_base.w;
|
||||
#else
|
||||
const float base = max(unpack_mix_float(in_base, drawable.base_t), 0.0);
|
||||
#endif
|
||||
|
||||
#if defined(HAS_UNIFORM_u_height)
|
||||
const float height = props.height;
|
||||
#else
|
||||
const float height = max(unpack_mix_float(in_height, drawable.height_t), 0.0);
|
||||
#endif
|
||||
|
||||
const vec2 p1 = unpack_int(instanceVector.instance[gl_InstanceIndex + 1].pos);
|
||||
const vec2 p2 = unpack_int(instanceVector.instance[gl_InstanceIndex + 0].pos);
|
||||
const vec2 perp = normalize(p1 - p2);
|
||||
|
||||
const vec3 normal = vec3(-perp.y, perp.x, 0.0);
|
||||
const float edgedistance = unpack_uint(instanceVector.instance[gl_InstanceIndex + 1 - in_position.x].ed_discard).x;
|
||||
const float t = float(in_position.y);
|
||||
const float z = t != 0.0 ? height : base;
|
||||
|
||||
gl_Position = drawable.matrix * vec4(unpack_int(instanceVector.instance[gl_InstanceIndex + in_position.x].pos), z, 1.0);
|
||||
applySurfaceTransform();
|
||||
|
||||
#if defined(OVERDRAW_INSPECTOR)
|
||||
frag_lighting = vec4(1.0);
|
||||
frag_pos_a = vec4(0.0);
|
||||
frag_pos_b = vec4(0.0);
|
||||
frag_pattern_from = vec4(0.0);
|
||||
frag_pattern_to = vec4(0.0);
|
||||
return;
|
||||
#endif
|
||||
|
||||
#if defined(HAS_UNIFORM_u_pattern_from)
|
||||
const mediump vec4 pattern_from = tileProps.pattern_from;
|
||||
#else
|
||||
const mediump vec4 pattern_from = in_pattern_from;
|
||||
frag_pattern_from = in_pattern_from;
|
||||
#endif
|
||||
|
||||
#if defined(HAS_UNIFORM_u_pattern_to)
|
||||
const mediump vec4 pattern_to = tileProps.pattern_to;
|
||||
#else
|
||||
const mediump vec4 pattern_to = in_pattern_to;
|
||||
frag_pattern_to = in_pattern_to;
|
||||
#endif
|
||||
|
||||
const vec2 pattern_tl_a = pattern_from.xy;
|
||||
const vec2 pattern_br_a = pattern_from.zw;
|
||||
const vec2 pattern_tl_b = pattern_to.xy;
|
||||
const vec2 pattern_br_b = pattern_to.zw;
|
||||
|
||||
const float pixelRatio = paintParams.pixel_ratio;
|
||||
const float tileZoomRatio = drawable.tile_ratio;
|
||||
const float fromScale = props.from_scale;
|
||||
const float toScale = props.to_scale;
|
||||
|
||||
const vec2 display_size_a = vec2((pattern_br_a.x - pattern_tl_a.x) / pixelRatio, (pattern_br_a.y - pattern_tl_a.y) / pixelRatio);
|
||||
const vec2 display_size_b = vec2((pattern_br_b.x - pattern_tl_b.x) / pixelRatio, (pattern_br_b.y - pattern_tl_b.y) / pixelRatio);
|
||||
|
||||
const vec2 pos = vec2(edgedistance, z * drawable.height_factor); // extrusion side
|
||||
|
||||
vec4 lighting = vec4(0.0, 0.0, 0.0, 1.0);
|
||||
float directional = clamp(dot(normal, props.light_position_base.xyz), 0.0, 1.0);
|
||||
directional = mix((1.0 - props.light_intensity), max((0.5 + props.light_intensity), 1.0), directional);
|
||||
|
||||
if (normal.y != 0.0) {
|
||||
|
||||
@@ -8,8 +8,8 @@ namespace shaders {
|
||||
|
||||
constexpr auto hillshadePrepareShaderPrelude = R"(
|
||||
|
||||
#define idHillshadePrepareDrawableUBO idDrawableReservedVertexOnlyUBO
|
||||
#define idHillshadePrepareTilePropsUBO drawableReservedUBOCount
|
||||
#define idHillshadePrepareDrawableUBO drawableUBOStartId
|
||||
#define idHillshadePrepareTilePropsUBO drawableUBOStartId + 1
|
||||
|
||||
)";
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
constexpr auto locationIndicatorShaderPrelude = R"(#define idLocationIndicatorDrawableUBO drawableReservedUBOCount)";
|
||||
constexpr auto locationIndicatorShaderPrelude = R"(#define idLocationIndicatorDrawableUBO drawableUBOStartId)";
|
||||
|
||||
template <>
|
||||
struct ShaderSource<BuiltIn::LocationIndicatorShader, gfx::Backend::Type::Vulkan> {
|
||||
|
||||
@@ -77,11 +77,13 @@ public:
|
||||
using ShaderClass = shaders::ShaderSource<ShaderID, gfx::Backend::Type::Vulkan>;
|
||||
for (const auto& attrib : ShaderClass::attributes) {
|
||||
if (!propertiesAsUniforms.second.contains(attrib.id)) {
|
||||
shader->initAttribute(attrib);
|
||||
shader->initVertexAttribute(attrib);
|
||||
}
|
||||
}
|
||||
for (const auto& attrib : ShaderClass::instanceAttributes) {
|
||||
shader->initInstanceAttribute(attrib);
|
||||
if (!propertiesAsUniforms.second.contains(attrib.id)) {
|
||||
shader->initInstanceAttribute(attrib);
|
||||
}
|
||||
}
|
||||
for (const auto& texture : ShaderClass::textures) {
|
||||
shader->initTexture(texture);
|
||||
|
||||
@@ -11,27 +11,17 @@
|
||||
|
||||
namespace mbgl {
|
||||
namespace shaders {
|
||||
struct UniformBlockInfo {
|
||||
constexpr UniformBlockInfo(bool vertex_, bool fragment_, std::size_t size_, std::size_t id_)
|
||||
: index(id_),
|
||||
vertex(vertex_),
|
||||
fragment(fragment_),
|
||||
size(size_),
|
||||
id(id_) {}
|
||||
std::size_t index;
|
||||
bool vertex;
|
||||
bool fragment;
|
||||
std::size_t size;
|
||||
std::size_t id;
|
||||
};
|
||||
|
||||
struct AttributeInfo {
|
||||
constexpr AttributeInfo(std::size_t index_, gfx::AttributeDataType dataType_, std::size_t id_)
|
||||
constexpr AttributeInfo(std::size_t index_, gfx::AttributeDataType dataType_, std::size_t id_, int ubo_ = -1)
|
||||
: index(index_),
|
||||
dataType(dataType_),
|
||||
id(id_) {}
|
||||
id(id_),
|
||||
ubo(ubo_) {}
|
||||
std::size_t index;
|
||||
gfx::AttributeDataType dataType;
|
||||
std::size_t id;
|
||||
int ubo;
|
||||
};
|
||||
struct TextureInfo {
|
||||
constexpr TextureInfo(std::size_t index_, std::size_t id_)
|
||||
@@ -72,7 +62,7 @@ public:
|
||||
|
||||
bool hasTextures() const;
|
||||
|
||||
void initAttribute(const shaders::AttributeInfo&);
|
||||
void initVertexAttribute(const shaders::AttributeInfo&);
|
||||
void initInstanceAttribute(const shaders::AttributeInfo&);
|
||||
void initTexture(const shaders::TextureInfo&);
|
||||
|
||||
|
||||
@@ -8,8 +8,8 @@ namespace shaders {
|
||||
|
||||
constexpr auto wideVectorShaderPrelude = R"(
|
||||
|
||||
#define idWideVectorUniformsUBO idDrawableReservedVertexOnlyUBO
|
||||
#define idWideVectorUniformWideVecUBO drawableReservedUBOCount
|
||||
#define idWideVectorUniformsUBO drawableUBOStartId
|
||||
#define idWideVectorUniformWideVecUBO drawableUBOStartId + 1
|
||||
|
||||
)";
|
||||
|
||||
|
||||
@@ -47,6 +47,7 @@ public:
|
||||
BufferResource& operator=(BufferResource&&) noexcept;
|
||||
|
||||
BufferResource clone() const;
|
||||
BufferResource shared() const;
|
||||
void destroy(bool deferred = true);
|
||||
|
||||
void update(const void* data, std::size_t size, std::size_t offset) noexcept;
|
||||
@@ -72,6 +73,9 @@ public:
|
||||
/// Used to detect whether buffer contents have changed
|
||||
VersionType getVersion() const noexcept { return version; }
|
||||
|
||||
protected:
|
||||
BufferResource(const BufferResource&) noexcept;
|
||||
|
||||
protected:
|
||||
Context& context;
|
||||
std::size_t size;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <mbgl/gfx/drawable.hpp>
|
||||
#include <mbgl/gfx/draw_mode.hpp>
|
||||
#include <mbgl/gfx/upload_pass.hpp>
|
||||
|
||||
#include <memory>
|
||||
|
||||
@@ -52,6 +53,7 @@ public:
|
||||
std::size_t segmentCount) override;
|
||||
|
||||
protected:
|
||||
void setSharedBuffers(const gfx::VertexAttributeArray&, const gfx::AttributeBindingArray&);
|
||||
void buildVulkanInputBindings();
|
||||
|
||||
bool bindAttributes(CommandEncoder&) const;
|
||||
|
||||
@@ -50,9 +50,9 @@ public:
|
||||
bool persistent) override;
|
||||
void updateIndexBufferResource(gfx::IndexBufferResource&, const void* data, std::size_t size) override;
|
||||
|
||||
const gfx::UniqueVertexBufferResource& getBuffer(const gfx::VertexVectorBasePtr&,
|
||||
gfx::BufferUsageType,
|
||||
bool forceUpdate);
|
||||
BufferResource createBufferResource(const void* data, std::size_t size, size_t usage, bool persistent);
|
||||
|
||||
const gfx::UniqueVertexBufferResource& getBuffer(const gfx::VertexVectorBasePtr&, size_t usage, bool forceUpdate);
|
||||
|
||||
gfx::AttributeBindingArray buildAttributeBindings(
|
||||
const std::size_t vertexCount,
|
||||
|
||||
@@ -21,10 +21,18 @@ public:
|
||||
VertexAttribute(const VertexAttribute& other) = delete;
|
||||
~VertexAttribute() override = default;
|
||||
|
||||
void setUBO(int value) { ubo = value; }
|
||||
int getUBO() const { return ubo; }
|
||||
|
||||
size_t getBufferUsage() const;
|
||||
|
||||
static const gfx::UniqueVertexBufferResource& getBuffer(gfx::VertexAttribute&,
|
||||
UploadPass&,
|
||||
const gfx::BufferUsageType,
|
||||
size_t,
|
||||
bool forceUpdate);
|
||||
|
||||
protected:
|
||||
int ubo = -1;
|
||||
};
|
||||
|
||||
/// Stores a collection of vertex attributes by name
|
||||
|
||||
@@ -5,36 +5,79 @@
|
||||
namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
// idFillExtrusionInstanced is shared between instanced and non-instanced drawables
|
||||
|
||||
//
|
||||
// Fill extrusion
|
||||
|
||||
using FillExtrusionShaderSource = ShaderSource<BuiltIn::FillExtrusionShader, gfx::Backend::Type::Vulkan>;
|
||||
|
||||
const std::array<AttributeInfo, 5> FillExtrusionShaderSource::attributes = {
|
||||
AttributeInfo{0, gfx::AttributeDataType::Short2, idFillExtrusionPosVertexAttribute},
|
||||
AttributeInfo{1, gfx::AttributeDataType::Short4, idFillExtrusionNormalEdVertexAttribute},
|
||||
AttributeInfo{2, gfx::AttributeDataType::Float4, idFillExtrusionColorVertexAttribute},
|
||||
AttributeInfo{3, gfx::AttributeDataType::Float, idFillExtrusionBaseVertexAttribute},
|
||||
AttributeInfo{4, gfx::AttributeDataType::Float, idFillExtrusionHeightVertexAttribute},
|
||||
const std::array<AttributeInfo, 4> FillExtrusionShaderSource::attributes = {
|
||||
AttributeInfo{0, gfx::AttributeDataType::Short2, idFillExtrusionPosVertexAttribute, idFillExtrusionInstanced},
|
||||
AttributeInfo{1, gfx::AttributeDataType::Float4, idFillExtrusionColorVertexAttribute},
|
||||
AttributeInfo{2, gfx::AttributeDataType::Float, idFillExtrusionBaseVertexAttribute},
|
||||
AttributeInfo{3, gfx::AttributeDataType::Float, idFillExtrusionHeightVertexAttribute},
|
||||
};
|
||||
const std::array<TextureInfo, 0> FillExtrusionShaderSource::textures = {};
|
||||
|
||||
//
|
||||
// Fill extrusion instanced
|
||||
|
||||
using FillExtrusionInstancedShaderSource =
|
||||
ShaderSource<BuiltIn::FillExtrusionInstancedShader, gfx::Backend::Type::Vulkan>;
|
||||
|
||||
const std::array<AttributeInfo, 1> FillExtrusionInstancedShaderSource::attributes = {
|
||||
AttributeInfo{0, gfx::AttributeDataType::Short2, idFillExtrusionPosVertexAttribute},
|
||||
};
|
||||
const std::array<AttributeInfo, 5> FillExtrusionInstancedShaderSource::instanceAttributes = {
|
||||
AttributeInfo{1, gfx::AttributeDataType::Short2, idFillExtrusionOutlinePosAttribute, idFillExtrusionInstanced},
|
||||
AttributeInfo{2, gfx::AttributeDataType::UShort2, idFillExtrusionEdDiscardAttribute, idFillExtrusionInstanced},
|
||||
|
||||
// Data driven
|
||||
AttributeInfo{3, gfx::AttributeDataType::Float4, idFillExtrusionColorVertexAttribute},
|
||||
AttributeInfo{4, gfx::AttributeDataType::Float, idFillExtrusionBaseVertexAttribute},
|
||||
AttributeInfo{5, gfx::AttributeDataType::Float, idFillExtrusionHeightVertexAttribute},
|
||||
};
|
||||
const std::array<TextureInfo, 0> FillExtrusionInstancedShaderSource::textures = {};
|
||||
|
||||
//
|
||||
// Fill extrusion pattern
|
||||
|
||||
using FillExtrusionPatternShaderSource = ShaderSource<BuiltIn::FillExtrusionPatternShader, gfx::Backend::Type::Vulkan>;
|
||||
|
||||
const std::array<AttributeInfo, 6> FillExtrusionPatternShaderSource::attributes = {
|
||||
AttributeInfo{0, gfx::AttributeDataType::Short2, idFillExtrusionPosVertexAttribute},
|
||||
AttributeInfo{1, gfx::AttributeDataType::Short4, idFillExtrusionNormalEdVertexAttribute},
|
||||
AttributeInfo{2, gfx::AttributeDataType::Float, idFillExtrusionBaseVertexAttribute},
|
||||
AttributeInfo{3, gfx::AttributeDataType::Float, idFillExtrusionHeightVertexAttribute},
|
||||
AttributeInfo{4, gfx::AttributeDataType::UShort4, idFillExtrusionPatternFromVertexAttribute},
|
||||
AttributeInfo{5, gfx::AttributeDataType::UShort4, idFillExtrusionPatternToVertexAttribute},
|
||||
const std::array<AttributeInfo, 5> FillExtrusionPatternShaderSource::attributes = {
|
||||
AttributeInfo{0, gfx::AttributeDataType::Short2, idFillExtrusionPosVertexAttribute, idFillExtrusionInstanced},
|
||||
AttributeInfo{1, gfx::AttributeDataType::Float, idFillExtrusionBaseVertexAttribute},
|
||||
AttributeInfo{2, gfx::AttributeDataType::Float, idFillExtrusionHeightVertexAttribute},
|
||||
AttributeInfo{3, gfx::AttributeDataType::UShort4, idFillExtrusionPatternFromVertexAttribute},
|
||||
AttributeInfo{4, gfx::AttributeDataType::UShort4, idFillExtrusionPatternToVertexAttribute},
|
||||
};
|
||||
const std::array<TextureInfo, 1> FillExtrusionPatternShaderSource::textures = {
|
||||
TextureInfo{0, idFillExtrusionImageTexture},
|
||||
};
|
||||
|
||||
//
|
||||
// Fill extrusion pattern instanced
|
||||
|
||||
using FillExtrusionPatternInstancedShaderSource =
|
||||
ShaderSource<BuiltIn::FillExtrusionPatternInstancedShader, gfx::Backend::Type::Vulkan>;
|
||||
|
||||
const std::array<AttributeInfo, 1> FillExtrusionPatternInstancedShaderSource::attributes = {
|
||||
AttributeInfo{0, gfx::AttributeDataType::Short2, idFillExtrusionPosVertexAttribute},
|
||||
};
|
||||
const std::array<AttributeInfo, 6> FillExtrusionPatternInstancedShaderSource::instanceAttributes = {
|
||||
AttributeInfo{1, gfx::AttributeDataType::Short2, idFillExtrusionOutlinePosAttribute, idFillExtrusionInstanced},
|
||||
AttributeInfo{2, gfx::AttributeDataType::UShort2, idFillExtrusionEdDiscardAttribute, idFillExtrusionInstanced},
|
||||
|
||||
// Data driven
|
||||
AttributeInfo{3, gfx::AttributeDataType::Float, idFillExtrusionBaseVertexAttribute},
|
||||
AttributeInfo{4, gfx::AttributeDataType::Float, idFillExtrusionHeightVertexAttribute},
|
||||
AttributeInfo{5, gfx::AttributeDataType::UShort4, idFillExtrusionPatternFromVertexAttribute},
|
||||
AttributeInfo{6, gfx::AttributeDataType::UShort4, idFillExtrusionPatternToVertexAttribute},
|
||||
};
|
||||
const std::array<TextureInfo, 1> FillExtrusionPatternInstancedShaderSource::textures = {
|
||||
TextureInfo{0, idFillExtrusionImageTexture},
|
||||
};
|
||||
|
||||
} // namespace shaders
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -244,14 +244,18 @@ bool ShaderProgram::hasTextures() const {
|
||||
textureBindings.begin(), textureBindings.end(), [](const auto& texture) { return texture.has_value(); });
|
||||
}
|
||||
|
||||
void ShaderProgram::initAttribute(const shaders::AttributeInfo& info) {
|
||||
void ShaderProgram::initVertexAttribute(const shaders::AttributeInfo& info) {
|
||||
const auto index = static_cast<int>(info.index);
|
||||
#if !defined(NDEBUG)
|
||||
// Indexes must be unique, if there's a conflict check the `attributes` array in the shader
|
||||
vertexAttributes.visitAttributes([&](const gfx::VertexAttribute& attrib) { assert(attrib.getIndex() != index); });
|
||||
instanceAttributes.visitAttributes([&](const gfx::VertexAttribute& attrib) { assert(attrib.getIndex() != index); });
|
||||
#endif
|
||||
vertexAttributes.set(info.id, index, info.dataType, 1);
|
||||
|
||||
if (info.ubo != -1) {
|
||||
auto& attrib = static_cast<VertexAttribute&>(*vertexAttributes.get(info.id));
|
||||
attrib.setUBO(info.ubo);
|
||||
}
|
||||
}
|
||||
|
||||
void ShaderProgram::initInstanceAttribute(const shaders::AttributeInfo& info) {
|
||||
@@ -260,9 +264,14 @@ void ShaderProgram::initInstanceAttribute(const shaders::AttributeInfo& info) {
|
||||
#if !defined(NDEBUG)
|
||||
// Indexes must not be reused by regular attributes or uniform blocks
|
||||
// More than one instance attribute can have the same index, if they share the block
|
||||
vertexAttributes.visitAttributes([&](const gfx::VertexAttribute& attrib) { assert(attrib.getIndex() != index); });
|
||||
instanceAttributes.visitAttributes([&](const gfx::VertexAttribute& attrib) { assert(attrib.getIndex() != index); });
|
||||
#endif
|
||||
instanceAttributes.set(info.id, index, info.dataType, 1);
|
||||
|
||||
if (info.ubo != -1) {
|
||||
auto& attrib = static_cast<VertexAttribute&>(*instanceAttributes.get(info.id));
|
||||
attrib.setUBO(info.ubo);
|
||||
}
|
||||
}
|
||||
|
||||
void ShaderProgram::initTexture(const shaders::TextureInfo& info) {
|
||||
|
||||
@@ -57,7 +57,8 @@ BufferResource::BufferResource(
|
||||
std::size_t totalSize = size;
|
||||
|
||||
// TODO -> check avg minUniformBufferOffsetAlignment vs individual buffers
|
||||
if (usage & VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT || usage & VK_BUFFER_USAGE_STORAGE_BUFFER_BIT) {
|
||||
if ((usage & VK_BUFFER_USAGE_VERTEX_BUFFER_BIT) == 0 &&
|
||||
(usage & VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT || usage & VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
|
||||
const auto& backend = context.getBackend();
|
||||
const auto& deviceProps = backend.getDeviceProperties();
|
||||
|
||||
@@ -127,30 +128,44 @@ BufferResource::BufferResource(BufferResource&& other) noexcept
|
||||
other.bufferAllocation = nullptr;
|
||||
}
|
||||
|
||||
BufferResource::BufferResource(const BufferResource& other) noexcept
|
||||
: context(other.context),
|
||||
size(other.size),
|
||||
usage(other.usage),
|
||||
version(other.version),
|
||||
persistent(other.persistent),
|
||||
bufferAllocation(other.bufferAllocation),
|
||||
bufferWindowSize(other.bufferWindowSize),
|
||||
bufferWindowVersions(other.bufferWindowVersions) {}
|
||||
|
||||
BufferResource::~BufferResource() noexcept {
|
||||
destroy(true);
|
||||
}
|
||||
|
||||
void BufferResource::destroy(bool deferred) {
|
||||
if (isValid()) {
|
||||
context.threadSafeAccessRenderingStats([&](gfx::RenderingStats& stats) {
|
||||
stats.numBuffers--;
|
||||
|
||||
if (bufferWindowSize > 0) {
|
||||
stats.memBuffers -= bufferWindowSize * context.getBackend().getMaxFrames();
|
||||
} else {
|
||||
stats.memBuffers -= size;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (!bufferAllocation) {
|
||||
return;
|
||||
}
|
||||
|
||||
const size_t size_ = bufferWindowSize > 0 ? bufferWindowSize * bufferWindowVersions.size() : size;
|
||||
|
||||
if (deferred) {
|
||||
context.enqueueDeletion([allocation = std::move(bufferAllocation)](auto&) mutable { allocation.reset(); });
|
||||
context.enqueueDeletion([size_, allocation = std::move(bufferAllocation)](auto& context_) mutable {
|
||||
if (allocation.use_count() == 1) {
|
||||
context_.threadSafeAccessRenderingStats([&](gfx::RenderingStats& stats) {
|
||||
stats.numBuffers--;
|
||||
stats.memBuffers -= size_;
|
||||
});
|
||||
}
|
||||
allocation.reset();
|
||||
});
|
||||
} else {
|
||||
if (bufferAllocation.use_count() == 1) {
|
||||
context.threadSafeAccessRenderingStats([&](gfx::RenderingStats& stats) {
|
||||
stats.numBuffers--;
|
||||
stats.memBuffers -= size_;
|
||||
});
|
||||
}
|
||||
bufferAllocation.reset();
|
||||
}
|
||||
}
|
||||
@@ -159,6 +174,10 @@ BufferResource BufferResource::clone() const {
|
||||
return {context, contents(), size, usage, persistent};
|
||||
}
|
||||
|
||||
BufferResource BufferResource::shared() const {
|
||||
return BufferResource(*this);
|
||||
}
|
||||
|
||||
BufferResource& BufferResource::operator=(BufferResource&& other) noexcept {
|
||||
assert(&context == &other.context);
|
||||
if (isValid()) {
|
||||
|
||||
@@ -99,7 +99,8 @@ void Context::initFrameResources() {
|
||||
|
||||
descriptorPoolMap.emplace(
|
||||
DescriptorSetType::DrawableUniform,
|
||||
DescriptorPoolGrowable(drawableUniformDescriptorPoolSize, 0, shaders::maxUBOCountPerDrawable, 0));
|
||||
DescriptorPoolGrowable(
|
||||
drawableUniformDescriptorPoolSize, shaders::maxSSBOCountPerDrawable, shaders::maxUBOCountPerDrawable, 0));
|
||||
|
||||
descriptorPoolMap.emplace(
|
||||
DescriptorSetType::DrawableImage,
|
||||
@@ -125,18 +126,18 @@ void Context::initFrameResources() {
|
||||
}
|
||||
|
||||
// force placeholder texture upload before any descriptor sets
|
||||
(void)getDummyTexture();
|
||||
static_cast<void>(getDummyTexture());
|
||||
|
||||
buildUniformDescriptorSetLayout(
|
||||
globalUniformDescriptorSetLayout, 0, 0, shaders::globalUBOCount, "GlobalUniformDescriptorSetLayout");
|
||||
buildUniformDescriptorSetLayout(layerUniformDescriptorSetLayout,
|
||||
shaders::globalUBOCount,
|
||||
shaders::layerSSBOStartId,
|
||||
shaders::maxSSBOCountPerLayer,
|
||||
shaders::maxUBOCountPerLayer,
|
||||
"LayerUniformDescriptorSetLayout");
|
||||
buildUniformDescriptorSetLayout(drawableUniformDescriptorSetLayout,
|
||||
shaders::globalUBOCount,
|
||||
0,
|
||||
shaders::drawableSSBOStartId,
|
||||
shaders::maxSSBOCountPerDrawable,
|
||||
shaders::maxUBOCountPerDrawable,
|
||||
"DrawableUniformDescriptorSetLayout");
|
||||
buildImageDescriptorSetLayout();
|
||||
@@ -663,7 +664,7 @@ const std::unique_ptr<Texture2D>& Context::getDummyTexture() {
|
||||
}
|
||||
|
||||
void Context::buildUniformDescriptorSetLayout(vk::UniqueDescriptorSetLayout& layout,
|
||||
size_t startId,
|
||||
[[maybe_unused]] size_t startId,
|
||||
size_t storageCount,
|
||||
size_t uniformCount,
|
||||
const std::string& name) {
|
||||
@@ -673,6 +674,7 @@ void Context::buildUniformDescriptorSetLayout(vk::UniqueDescriptorSetLayout& lay
|
||||
if (startId + i != shaders::idDrawableReservedFragmentOnlyUBO) {
|
||||
stageFlags |= vk::ShaderStageFlagBits::eVertex;
|
||||
}
|
||||
|
||||
if (startId + i != shaders::idDrawableReservedVertexOnlyUBO) {
|
||||
stageFlags |= vk::ShaderStageFlagBits::eFragment;
|
||||
}
|
||||
|
||||
@@ -194,6 +194,9 @@ void Drawable::upload(gfx::UploadPass& uploadPass_) {
|
||||
|
||||
if (impl->attributeBindings != attributeBindings_) {
|
||||
impl->attributeBindings = std::move(attributeBindings_);
|
||||
|
||||
const auto& shaderImpl = static_cast<const mbgl::vulkan::ShaderProgram&>(*shader);
|
||||
setSharedBuffers(shaderImpl.getVertexAttributes(), impl->attributeBindings);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -219,6 +222,9 @@ void Drawable::upload(gfx::UploadPass& uploadPass_) {
|
||||
|
||||
if (impl->instanceBindings != instanceBindings_) {
|
||||
impl->instanceBindings = std::move(instanceBindings_);
|
||||
|
||||
const auto& shaderImpl = static_cast<const mbgl::vulkan::ShaderProgram&>(*shader);
|
||||
setSharedBuffers(shaderImpl.getInstanceAttributes(), impl->instanceBindings);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -358,6 +364,26 @@ gfx::UniformBufferArray& Drawable::mutableUniformBuffers() {
|
||||
return impl->uniformBuffers;
|
||||
}
|
||||
|
||||
void Drawable::setSharedBuffers(const gfx::VertexAttributeArray& attribs, const gfx::AttributeBindingArray& bindings) {
|
||||
// set shared vertex/uniform buffers
|
||||
attribs.visitAttributes([&](const gfx::VertexAttribute& attrib) {
|
||||
const auto& vkAttrib = static_cast<const VertexAttribute&>(attrib);
|
||||
int ubo = vkAttrib.getUBO();
|
||||
|
||||
if (ubo == -1 || impl->uniformBuffers.get(ubo) != nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
const auto& binding = bindings[vkAttrib.getIndex()];
|
||||
if (!binding) {
|
||||
return;
|
||||
}
|
||||
|
||||
const auto buffer = static_cast<const VertexBufferResource*>(binding->vertexBufferResource);
|
||||
impl->uniformBuffers.set(ubo, std::make_shared<UniformBuffer>(buffer->get().shared()));
|
||||
});
|
||||
}
|
||||
|
||||
void Drawable::buildVulkanInputBindings() {
|
||||
MLN_TRACE_FUNC();
|
||||
|
||||
|
||||
@@ -24,8 +24,10 @@ using namespace platform;
|
||||
class Drawable::Impl final {
|
||||
public:
|
||||
Impl()
|
||||
: uniformBuffers(
|
||||
DescriptorSetType::DrawableUniform, shaders::globalUBOCount, 0, shaders::maxUBOCountPerDrawable) {}
|
||||
: uniformBuffers(DescriptorSetType::DrawableUniform,
|
||||
shaders::drawableSSBOStartId,
|
||||
shaders::maxSSBOCountPerDrawable,
|
||||
shaders::maxUBOCountPerDrawable) {}
|
||||
|
||||
~Impl() = default;
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace vulkan {
|
||||
LayerGroup::LayerGroup(int32_t layerIndex_, std::size_t initialCapacity, std::string name_)
|
||||
: mbgl::LayerGroup(layerIndex_, initialCapacity, std::move(name_)),
|
||||
uniformBuffers(DescriptorSetType::Layer,
|
||||
shaders::globalUBOCount,
|
||||
shaders::layerSSBOStartId,
|
||||
shaders::maxSSBOCountPerLayer,
|
||||
shaders::maxUBOCountPerLayer) {}
|
||||
|
||||
|
||||
@@ -690,7 +690,9 @@ void RendererBackend::initShaders(gfx::ShaderRegistry& shaders, const ProgramPar
|
||||
shaders::BuiltIn::FillOutlinePatternShader,
|
||||
shaders::BuiltIn::FillOutlineTriangulatedShader,
|
||||
shaders::BuiltIn::FillExtrusionShader,
|
||||
shaders::BuiltIn::FillExtrusionInstancedShader,
|
||||
shaders::BuiltIn::FillExtrusionPatternShader,
|
||||
shaders::BuiltIn::FillExtrusionPatternInstancedShader,
|
||||
shaders::BuiltIn::HeatmapShader,
|
||||
shaders::BuiltIn::HeatmapTextureShader,
|
||||
shaders::BuiltIn::HillshadeShader,
|
||||
|
||||
@@ -50,6 +50,10 @@ void UploadPass::updateIndexBufferResource(gfx::IndexBufferResource& resource, c
|
||||
static_cast<IndexBufferResource&>(resource).get().update(data, size, /*offset=*/0);
|
||||
}
|
||||
|
||||
BufferResource UploadPass::createBufferResource(const void* data, std::size_t size, size_t usage, bool persistent) {
|
||||
return commandEncoder.context.createBuffer(data, size, usage, persistent);
|
||||
}
|
||||
|
||||
struct VertexBuffer : public gfx::VertexBufferBase {
|
||||
~VertexBuffer() override = default;
|
||||
|
||||
@@ -59,7 +63,7 @@ struct VertexBuffer : public gfx::VertexBufferBase {
|
||||
static const std::unique_ptr<gfx::VertexBufferResource> noBuffer;
|
||||
|
||||
const gfx::UniqueVertexBufferResource& UploadPass::getBuffer(const gfx::VertexVectorBasePtr& vec,
|
||||
const gfx::BufferUsageType usage,
|
||||
size_t usage,
|
||||
[[maybe_unused]] bool forceUpdate) {
|
||||
if (vec) {
|
||||
const auto* rawBufPtr = vec->getRawData();
|
||||
@@ -81,7 +85,8 @@ const gfx::UniqueVertexBufferResource& UploadPass::getBuffer(const gfx::VertexVe
|
||||
// Otherwise, create a new one
|
||||
if (rawBufSize > 0) {
|
||||
auto buffer = std::make_unique<VertexBuffer>();
|
||||
buffer->resource = createVertexBufferResource(rawBufPtr, rawBufSize, usage, /*persistent=*/false);
|
||||
buffer->resource = std::make_unique<VertexBufferResource>(
|
||||
createBufferResource(rawBufPtr, rawBufSize, usage, false));
|
||||
vec->setBuffer(std::move(buffer));
|
||||
|
||||
auto* rawData = static_cast<VertexBuffer*>(vec->getBuffer());
|
||||
@@ -100,7 +105,7 @@ gfx::AttributeBindingArray UploadPass::buildAttributeBindings(
|
||||
const std::vector<std::uint8_t>&,
|
||||
const gfx::VertexAttributeArray& defaults,
|
||||
const gfx::VertexAttributeArray& overrides,
|
||||
const gfx::BufferUsageType usage,
|
||||
const gfx::BufferUsageType,
|
||||
const std::optional<std::chrono::duration<double>> lastUpdate,
|
||||
/*out*/ std::vector<std::unique_ptr<gfx::VertexBufferResource>>&) {
|
||||
gfx::AttributeBindingArray bindings;
|
||||
@@ -128,7 +133,8 @@ gfx::AttributeBindingArray UploadPass::buildAttributeBindings(
|
||||
}
|
||||
|
||||
// If the attribute references data shared with a bucket, get the corresponding buffer.
|
||||
if (const auto& buffer = getBuffer(effectiveAttr.getSharedRawData(), usage, !lastUpdate)) {
|
||||
if (const auto& buffer = getBuffer(
|
||||
effectiveAttr.getSharedRawData(), defaultAttr.getBufferUsage(), !lastUpdate)) {
|
||||
assert(effectiveAttr.getSharedStride() * effectiveAttr.getSharedVertexOffset() <
|
||||
effectiveAttr.getSharedRawData()->getRawSize() * effectiveAttr.getSharedRawData()->getRawCount());
|
||||
|
||||
@@ -146,7 +152,7 @@ gfx::AttributeBindingArray UploadPass::buildAttributeBindings(
|
||||
|
||||
// Otherwise, turn the data managed by the attribute into a buffer.
|
||||
if (const auto& buffer = VertexAttribute::getBuffer(
|
||||
effectiveAttr, *this, gfx::BufferUsageType::StaticDraw, !lastUpdate)) {
|
||||
effectiveAttr, *this, defaultAttr.getBufferUsage(), !lastUpdate)) {
|
||||
bindings[index] = {
|
||||
/*.attribute = */ {effectiveAttr.getDataType(), /*offset=*/0},
|
||||
/*.vertexStride = */ static_cast<uint32_t>(effectiveAttr.getStride()),
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <mbgl/gfx/vertex_vector.hpp>
|
||||
#include <mbgl/vulkan/buffer_resource.hpp>
|
||||
#include <mbgl/vulkan/vertex_buffer_resource.hpp>
|
||||
#include <mbgl/vulkan/upload_pass.hpp>
|
||||
#include <mbgl/util/logging.hpp>
|
||||
#include <mbgl/util/convert.hpp>
|
||||
@@ -12,9 +13,17 @@
|
||||
namespace mbgl {
|
||||
namespace vulkan {
|
||||
|
||||
size_t VertexAttribute::getBufferUsage() const {
|
||||
if (ubo == -1) {
|
||||
return VK_BUFFER_USAGE_VERTEX_BUFFER_BIT;
|
||||
}
|
||||
|
||||
return VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT;
|
||||
}
|
||||
|
||||
const gfx::UniqueVertexBufferResource& VertexAttribute::getBuffer(gfx::VertexAttribute& attrib_,
|
||||
UploadPass& uploadPass,
|
||||
const gfx::BufferUsageType usage,
|
||||
size_t usage,
|
||||
bool forceUpdate) {
|
||||
if (!attrib_.getBuffer()) {
|
||||
auto& attrib = static_cast<VertexAttribute&>(attrib_);
|
||||
@@ -22,8 +31,8 @@ const gfx::UniqueVertexBufferResource& VertexAttribute::getBuffer(gfx::VertexAtt
|
||||
return uploadPass.getBuffer(attrib.sharedRawData, usage, forceUpdate);
|
||||
} else {
|
||||
if (!attrib.rawData.empty()) {
|
||||
auto buffer = uploadPass.createVertexBufferResource(
|
||||
attrib.rawData.data(), attrib.rawData.size(), usage, false);
|
||||
auto buffer = std::make_unique<VertexBufferResource>(
|
||||
uploadPass.createBufferResource(attrib.rawData.data(), attrib.rawData.size(), usage, false));
|
||||
attrib.setBuffer(std::move(buffer));
|
||||
attrib.setRawData({});
|
||||
attrib_.setDirty(false);
|
||||
|
||||
Reference in New Issue
Block a user