Drawable Renderer (#1570), Remove layer index from drawables.

Add debug GL groups for uploads.
Enable GL debug groups only in debug builds.
This commit is contained in:
Tim Sylvester
2023-05-30 14:04:18 -07:00
committed by Bart Louwers
parent 8986bce151
commit c10616aec6
9 changed files with 26 additions and 70 deletions

View File

@@ -109,10 +109,6 @@ public:
DrawPriority getDrawPriority() const { return drawPriority; }
void setDrawPriority(DrawPriority value) { drawPriority = value; }
/// The layer index determines the drawing order
int32_t getLayerIndex() const { return layerIndex; }
void setLayerIndex(int32_t value) { layerIndex = value; }
/// Determines depth range within the layer
int32_t getSubLayerIndex() const { return subLayerIndex; }
void setSubLayerIndex(int32_t value) { subLayerIndex = value; }
@@ -162,7 +158,6 @@ protected:
std::optional<OverscaledTileID> tileID;
DrawPriority drawPriority = 0;
int32_t lineWidth = 1;
int32_t layerIndex = -1;
int32_t subLayerIndex = 0;
DepthMaskType depthType; // = DepthMaskType::ReadOnly;
@@ -176,24 +171,23 @@ protected:
using DrawablePtr = std::shared_ptr<Drawable>;
using UniqueDrawable = std::unique_ptr<Drawable>;
/// Comparator for sorting drawable pointers primarily by layer index
struct DrawablePtrLessByLayer {
DrawablePtrLessByLayer(bool descending)
/// Comparator for sorting drawable pointers primarily by draw priority
struct DrawableLessByPriority {
DrawableLessByPriority(bool descending)
: desc(descending) {}
bool operator()(const Drawable& left, const Drawable& right) const {
const auto& a = desc ? right : left;
const auto& b = desc ? left : right;
if (a.getDrawPriority() != b.getDrawPriority()) {
return a.getDrawPriority() < b.getDrawPriority();
}
return a.getId() < b.getId();
}
bool operator()(const DrawablePtr& left, const DrawablePtr& right) const {
const auto& a = desc ? right : left;
const auto& b = desc ? left : right;
if (!a || !b) {
// nulls are less than non-nulls
return (!a && b);
}
if (a->getLayerIndex() != b->getLayerIndex()) {
return a->getLayerIndex() < b->getLayerIndex();
}
if (a->getDrawPriority() != b->getDrawPriority()) {
return a->getDrawPriority() < b->getDrawPriority();
}
return a->getId() < b->getId();
// nulls are less than non-nulls
return (a && b) ? operator()(*a, *b) : (!a && b);
}
private:

View File

@@ -59,10 +59,6 @@ public:
DrawPriority getDrawPriority() const;
void setDrawPriority(DrawPriority);
/// The layer index assigned to generated drawables
int32_t getLayerIndex() const { return layerIndex; }
void setLayerIndex(int32_t value) { layerIndex = value; }
/// The layer index assigned to generated drawables
int32_t getSubLayerIndex() const { return subLayerIndex; }
void setSubLayerIndex(int32_t value) { subLayerIndex = value; }
@@ -162,7 +158,6 @@ protected:
mbgl::RenderPass renderPass;
float lineWidth = 1.0f;
DrawPriority drawPriority = 0;
int32_t layerIndex = -1;
int32_t subLayerIndex = 0;
DepthMaskType depthType = DepthMaskType::ReadOnly;
gfx::ShaderProgramBasePtr shader;

View File

@@ -44,7 +44,6 @@ void DrawableBuilder::flush() {
draw->setLineWidth(static_cast<int32_t>(lineWidth));
draw->setRenderPass(renderPass);
draw->setDrawPriority(drawPriority);
draw->setLayerIndex(layerIndex);
draw->setSubLayerIndex(subLayerIndex);
draw->setDepthType(depthType);
draw->setCullFaceMode(impl->cullFaceMode);

View File

@@ -3,6 +3,7 @@
#include <mbgl/gfx/render_pass.hpp>
#include <mbgl/gfx/renderable.hpp>
#include <mbgl/gfx/renderer_backend.hpp>
#include <mbgl/gfx/upload_pass.hpp>
#include <mbgl/gl/drawable_gl.hpp>
#include <mbgl/renderer/paint_parameters.hpp>
#include <mbgl/shaders/gl/shader_program_gl.hpp>
@@ -17,6 +18,16 @@ TileLayerGroupGL::TileLayerGroupGL(int32_t layerIndex_, std::size_t initialCapac
void TileLayerGroupGL::upload(gfx::Context& context, gfx::UploadPass& uploadPass) {
observeDrawables([&](gfx::Drawable& drawable) {
auto& drawableGL = static_cast<gl::DrawableGL&>(drawable);
#if !defined(NDEBUG)
std::string label;
if (const auto& tileID = drawable.getTileID()) {
label = drawable.getName() + "/" + util::toString(*tileID);
}
const auto labelPtr = (label.empty() ? drawable.getName() : label).c_str();
const auto debugGroup = uploadPass.createDebugGroup(labelPtr);
#endif
drawableGL.upload(context, uploadPass);
});
}
@@ -35,12 +46,14 @@ void TileLayerGroupGL::render(RenderOrchestrator&, PaintParameters& parameters)
return;
}
#if !defined(NDEBUG)
std::string label;
if (const auto& tileID = drawable.getTileID()) {
label = drawable.getName() + "/" + util::toString(*tileID);
}
const auto labelPtr = (label.empty() ? drawable.getName() : label).c_str();
const auto debugGroup = parameters.encoder->createDebugGroup(labelPtr);
#endif
drawable.draw(parameters);
});

View File

@@ -40,9 +40,6 @@ TileLayerGroup::~TileLayerGroup() {}
void TileLayerGroup::updateLayerIndex(int32_t newLayerIndex) {
layerIndex = newLayerIndex;
for (auto& it : impl->tileDrawables) {
it.second->setLayerIndex(newLayerIndex);
}
}
std::size_t TileLayerGroup::getDrawableCount() const {

View File

@@ -309,7 +309,6 @@ void RenderBackgroundLayer::update(gfx::ShaderRegistry& shaders,
builder->setShader(shader);
builder->setColorAttrMode(gfx::DrawableBuilder::ColorAttrMode::PerDrawable);
builder->setDepthType(gfx::DepthMaskType::ReadWrite);
builder->setLayerIndex(layerIndex);
}
// Tile coordinates are fixed...

View File

@@ -426,7 +426,6 @@ void RenderCircleLayer::update(gfx::ShaderRegistry& shaders,
circleBuilder->setDepthType((renderPass == RenderPass::Opaque) ? gfx::DepthMaskType::ReadWrite
: gfx::DepthMaskType::ReadOnly);
circleBuilder->setCullFaceMode(gfx::CullFaceMode::disabled());
circleBuilder->setLayerIndex(layerIndex);
circleBuilder->setRenderPass(renderPass);
circleBuilder->setVertexAttributes(circleVertexAttrs);

View File

@@ -460,8 +460,6 @@ void RenderFillLayer::update(gfx::ShaderRegistry& shaders,
fillBuilder->setDepthType((renderPass == RenderPass::Opaque) ? gfx::DepthMaskType::ReadWrite
: gfx::DepthMaskType::ReadOnly);
fillBuilder->setCullFaceMode(gfx::CullFaceMode::disabled());
fillBuilder->setDepthType(gfx::DepthMaskType::ReadWrite);
fillBuilder->setLayerIndex(layerIndex);
}
if (doOutline && !outlineBuilder && outlineShader) {
outlineBuilder = context.createDrawableBuilder("fill-outline");
@@ -470,28 +468,9 @@ void RenderFillLayer::update(gfx::ShaderRegistry& shaders,
outlineBuilder->setLineWidth(2.0f);
outlineBuilder->setDepthType(gfx::DepthMaskType::ReadOnly);
outlineBuilder->setCullFaceMode(gfx::CullFaceMode::disabled());
outlineBuilder->setLayerIndex(layerIndex);
outlineBuilder->setSubLayerIndex(unevaluated.get<FillOutlineColor>().isUndefined() ? 2 : 0);
}
// evaluated.get<FillTranslate>(),
// evaluated.get<FillTranslateAnchor>(),
// parameters.stencilModeForClipping(tile.id),
// parameters.colorModeForRenderPass(),
// gfx::CullFaceMode::disabled(),
//
// if (evaluated.get<FillAntialias>() && parameters.pass == RenderPass::Translucent) {
// draw(*fillOutlineProgram,
// gfx::Lines{2.0f},
// parameters.depthModeForSublayer(unevaluated.get<FillOutlineColor>().isUndefined()
// ? 2 : 0,
// gfx::DepthMaskType::ReadOnly),
// *bucket.lineIndexBuffer,
// bucket.lineSegments,
// FillOutlineProgram::TextureBindings{});
// }
if (fillBuilder) {
fillBuilder->setRenderPass(renderPass);
fillBuilder->setVertexAttributes(fillVertexAttrs);
@@ -539,7 +518,6 @@ void RenderFillLayer::update(gfx::ShaderRegistry& shaders,
patternBuilder->setColorAttrMode(gfx::DrawableBuilder::ColorAttrMode::None);
patternBuilder->setDepthType(gfx::DepthMaskType::ReadWrite);
patternBuilder->setCullFaceMode(gfx::CullFaceMode::disabled());
patternBuilder->setLayerIndex(layerIndex);
patternBuilder->setSubLayerIndex(1);
}
if (doOutline && !outlinePatternBuilder && outlinePatternShader) {
@@ -549,7 +527,6 @@ void RenderFillLayer::update(gfx::ShaderRegistry& shaders,
outlinePatternBuilder->setLineWidth(2.0f);
outlinePatternBuilder->setDepthType(gfx::DepthMaskType::ReadOnly);
outlinePatternBuilder->setCullFaceMode(gfx::CullFaceMode::disabled());
outlinePatternBuilder->setLayerIndex(layerIndex);
outlinePatternBuilder->setSubLayerIndex(2);
}

View File

@@ -103,20 +103,6 @@ void Renderer::Impl::render(const RenderTree& renderTree) {
// Run changes
orchestrator.processChanges();
// Collect drawables
std::vector<gfx::DrawablePtr> drawables(orchestrator.getDrawables().size());
std::transform(orchestrator.getDrawables().begin(),
orchestrator.getDrawables().end(),
drawables.begin(),
std::bind(&RenderOrchestrator::DrawableMap::value_type::second, std::placeholders::_1));
// Run tweakers to update any dynamic elements
for (auto& drawable : drawables) {
for (auto& tweaker : drawable->getTweakers()) {
tweaker->execute(*drawable, parameters);
}
}
// Run layer tweakers to update any dynamic elements
orchestrator.observeLayerGroups([&](LayerGroup& layerGroup) {
if (layerGroup.getLayerTweaker()) {
@@ -127,9 +113,6 @@ void Renderer::Impl::render(const RenderTree& renderTree) {
// Give the layers a chance to do setup
orchestrator.observeLayerGroups([&](LayerGroup& layerGroup) { layerGroup.preRender(orchestrator, parameters); });
// Sort the drawables
std::sort(drawables.begin(), drawables.end(), gfx::DrawablePtrLessByLayer(/*descending=*/true));
// - UPLOAD PASS -------------------------------------------------------------------------------
// Uploads all required buffers and images before we do any actual rendering.
{