Disable stencil instancing (#1778)

This commit is contained in:
Tim Sylvester
2023-10-18 17:22:14 -07:00
committed by GitHub
parent 7f785ae660
commit d43c52b9d8
2 changed files with 27 additions and 15 deletions

View File

@@ -330,6 +330,13 @@ bool Context::renderTileClippingMasks(gfx::RenderPass& renderPass,
encoder->setCullMode(MTL::CullModeNone);
encoder->setVertexBuffer(vertexRes.getMetalBuffer().get(), /*offset=*/0, ShaderClass::attributes[0].index);
// Instancing is disabled for now because the `[[stencil]]` attribute in the fragment shader output
// that we need to apply a different stencil value for each tile causes a problem on some older (A8-A11)
// devices, specifically `XPC_ERROR_CONNECTION_INTERRUPTED` when creating a render pipeline state.
// Adding a `[[depth(...)]]` output to the shader prevents this error, but the stencil value is
// still not written to the stencil attachment on those same devices.
#if STENCIL_INSTANCING
encoder->setVertexBuffer(uboBuffer.getMetalBuffer().get(), /*offset=*/0, ShaderClass::uniforms[0].index);
encoder->drawIndexedPrimitives(MTL::PrimitiveType::PrimitiveTypeTriangle,
indexCount,
@@ -339,6 +346,21 @@ bool Context::renderTileClippingMasks(gfx::RenderPass& renderPass,
/*instanceCount=*/static_cast<NS::UInteger>(tileUBOs.size()),
/*baseVertex=*/0,
/*baseInstance=*/0);
#else
for (std::size_t ii = 0; ii < tileUBOs.size(); ++ii) {
encoder->setStencilReferenceValue(tileUBOs[ii].stencil_ref);
encoder->setVertexBuffer(
uboBuffer.getMetalBuffer().get(), /*offset=*/ii * uboSize, ShaderClass::uniforms[0].index);
encoder->drawIndexedPrimitives(MTL::PrimitiveType::PrimitiveTypeTriangle,
indexCount,
MTL::IndexType::IndexTypeUInt16,
indexRes->getMetalBuffer().get(),
/*indexOffset=*/0,
/*instanceCount=*/1,
/*baseVertex=*/0,
/*baseInstance=*/0);
}
#endif
return true;
}