Implement Maxwell 3D instanced draw support

In the Maxwell 3D engine, instanced draws are implemented by repeating the exact same draw in sequence with special flag set in vertexBeginGl. This flag allows either incrementing the instance counter or resetting it, since we need to supply an instance count to the host API we defer all draws until state changes occur. If there are no state changes between draws we can skip them and count the occurences to get the number of instances to draw.
This commit is contained in:
Billy Laws
2022-05-07 13:55:17 +01:00
parent 03594a081c
commit 4149ab1067
4 changed files with 106 additions and 17 deletions

View File

@ -2787,7 +2787,7 @@ namespace skyline::gpu::interconnect {
/* Draws */
public:
template<bool IsIndexed>
void Draw(u32 count, u32 first, i32 vertexOffset = 0) {
void Draw(u32 count, u32 first, u32 instanceCount = 1, i32 vertexOffset = 0) {
ValidatePrimitiveRestartState();
// Index Buffer Setup
@ -2982,21 +2982,24 @@ namespace skyline::gpu::interconnect {
if constexpr (IsIndexed) {
commandBuffer.bindIndexBuffer(boundIndexBuffer->handle, boundIndexBuffer->offset, boundIndexBuffer->type);
commandBuffer.drawIndexed(count, 1, first, vertexOffset, 0);
commandBuffer.drawIndexed(count, instanceCount, first, vertexOffset, 0);
} else {
commandBuffer.draw(count, 1, first, 0);
commandBuffer.draw(count, instanceCount, first, 0);
}
}, vk::Rect2D{
.extent = activeColorRenderTargets.empty() ? depthRenderTarget.guest.dimensions : activeColorRenderTargets.front()->texture->dimensions,
}, {}, activeColorRenderTargets, depthRenderTargetView, !gpu.traits.quirks.relaxedRenderPassCompatibility);
}
void DrawVertex(u32 vertexCount, u32 firstVertex) {
Draw<false>(vertexCount, firstVertex);
void Draw(u32 vertexCount, u32 firstVertex, u32 instanceCount) {
if (needsQuadConversion)
Draw<true>(vertexCount, firstVertex, instanceCount);
else
Draw<false>(vertexCount, firstVertex, instanceCount);
}
void DrawIndexed(u32 indexCount, u32 firstIndex, i32 vertexOffset) {
Draw<true>(indexCount, firstIndex, vertexOffset);
void DrawIndexed(u32 indexCount, u32 firstIndex, u32 instanceCount, i32 vertexOffset) {
Draw<true>(indexCount, firstIndex, instanceCount, vertexOffset);
}
};
}