Skip to content

Commit

Permalink
Metal base vertex instance drawing disabled on GPUFamilyApple2 devices (
Browse files Browse the repository at this point in the history
#2470)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
alexcristici and pre-commit-ci[bot] committed Jun 5, 2024
1 parent 2b18442 commit 410d706
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
2 changes: 2 additions & 0 deletions include/mbgl/mtl/renderer_backend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class RendererBackend : public gfx::RendererBackend {

const MTLDevicePtr& getDevice() const { return device; }
const MTLCommandQueuePtr& getCommandQueue() const { return commandQueue; }
const bool isBaseVertexInstanceDrawingSupported() const { return baseVertexInstanceDrawingSupported; }

protected:
std::unique_ptr<gfx::Context> createContext() override;
Expand Down Expand Up @@ -61,6 +62,7 @@ class RendererBackend : public gfx::RendererBackend {
protected:
MTLDevicePtr device;
MTLCommandQueuePtr commandQueue;
bool baseVertexInstanceDrawingSupported = false;
};

} // namespace mtl
Expand Down
8 changes: 2 additions & 6 deletions src/mbgl/mtl/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,9 +416,7 @@ bool Context::renderTileClippingMasks(gfx::RenderPass& renderPass,
MTL::IndexType::IndexTypeUInt16,
indexRes->getMetalBuffer().get(),
/*indexOffset=*/0,
/*instanceCount=*/static_cast<NS::UInteger>(tileUBOs.size()),
/*baseVertex=*/0,
/*baseInstance=*/0);
/*instanceCount=*/static_cast<NS::UInteger>(tileUBOs.size()));
#else
const auto uboIndex = ShaderClass::uniforms[0].index;
for (std::size_t ii = 0; ii < tileUBOs.size(); ++ii) {
Expand All @@ -429,9 +427,7 @@ bool Context::renderTileClippingMasks(gfx::RenderPass& renderPass,
MTL::IndexType::IndexTypeUInt16,
indexRes->getMetalBuffer().get(),
/*indexOffset=*/0,
/*instanceCount=*/1,
/*baseVertex=*/0,
/*baseInstance=*/0);
/*instanceCount=*/1);
}
#endif

Expand Down
22 changes: 14 additions & 8 deletions src/mbgl/mtl/drawable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,14 +292,20 @@ void Drawable::draw(PaintParameters& parameters) const {
assert(static_cast<std::size_t>(maxIndex) < mlSegment.vertexLength);
#endif

encoder->drawIndexedPrimitives(primitiveType,
mlSegment.indexLength,
indexType,
indexBuffer,
indexOffset,
instanceCount,
baseVertex,
baseInstance);
if (context.getBackend().isBaseVertexInstanceDrawingSupported()) {
encoder->drawIndexedPrimitives(primitiveType,
mlSegment.indexLength,
indexType,
indexBuffer,
indexOffset,
instanceCount,
baseVertex,
baseInstance);
} else {
encoder->drawIndexedPrimitives(
primitiveType, mlSegment.indexLength, indexType, indexBuffer, indexOffset, instanceCount);
}

context.renderingStats().numDrawCalls++;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/mbgl/mtl/renderer_backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ RendererBackend::RendererBackend(const gfx::ContextMode contextMode_)
commandQueue(NS::TransferPtr(device->newCommandQueue())) {
assert(device);
assert(commandQueue);
baseVertexInstanceDrawingSupported = device->supportsFamily(MTL::GPUFamilyApple3);
}

RendererBackend::~RendererBackend() = default;
Expand Down

0 comments on commit 410d706

Please sign in to comment.