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

Metal base vertex instance drawing disabled on GPUFamilyApple2 devices #2470

Merged
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
Loading