Pack all draw state into a struct to avoid std::function allocations

This commit is contained in:
Billy Laws 2022-10-09 14:06:21 +01:00
parent b5d0060c3f
commit 36fd885b49

View File

@ -261,7 +261,11 @@ namespace skyline::gpu::interconnect::maxwell3d {
auto stateUpdater{builder.Build()}; auto stateUpdater{builder.Build()};
/**
* @brief Struct that can be linearly allocated, holding all state for the draw to avoid a dynamic allocation with lambda captures
*/
struct DrawParams { struct DrawParams {
StateUpdater stateUpdater;
u32 count; u32 count;
u32 first; u32 first;
u32 instanceCount; u32 instanceCount;
@ -269,7 +273,8 @@ namespace skyline::gpu::interconnect::maxwell3d {
u32 firstInstance; u32 firstInstance;
bool indexed; bool indexed;
}; };
auto *drawParams{ctx.executor.allocator->EmplaceUntracked<DrawParams>(DrawParams{count, first, instanceCount, vertexOffset, firstInstance, indexed})}; auto *drawParams{ctx.executor.allocator->EmplaceUntracked<DrawParams>(DrawParams{stateUpdater,
count, first, instanceCount, vertexOffset, firstInstance, indexed})};
const auto &surfaceClip{clearEngineRegisters.surfaceClip}; const auto &surfaceClip{clearEngineRegisters.surfaceClip};
vk::Rect2D scissor{ vk::Rect2D scissor{
@ -277,12 +282,14 @@ namespace skyline::gpu::interconnect::maxwell3d {
{surfaceClip.horizontal.width, surfaceClip.vertical.height} {surfaceClip.horizontal.width, surfaceClip.vertical.height}
}; };
ctx.executor.AddSubpass([stateUpdater, drawParams](vk::raii::CommandBuffer &commandBuffer, const std::shared_ptr<FenceCycle> &, GPU &gpu, vk::RenderPass, u32) { ctx.executor.AddSubpass([drawParams](vk::raii::CommandBuffer &commandBuffer, const std::shared_ptr<FenceCycle> &, GPU &gpu, vk::RenderPass, u32) {
stateUpdater.RecordAll(gpu, commandBuffer); drawParams->stateUpdater.RecordAll(gpu, commandBuffer);
if (drawParams->indexed) if (drawParams->indexed)
commandBuffer.drawIndexed(drawParams->count, drawParams->instanceCount, drawParams->first, static_cast<i32>(drawParams->vertexOffset), drawParams->firstInstance); commandBuffer.drawIndexed(drawParams->count, drawParams->instanceCount, drawParams->first, static_cast<i32>(drawParams->vertexOffset), drawParams->firstInstance);
else else
commandBuffer.draw(drawParams->count, drawParams->instanceCount, drawParams->first, drawParams->firstInstance); commandBuffer.draw(drawParams->count, drawParams->instanceCount, drawParams->first, drawParams->firstInstance);
}, scissor, {}, activeState.GetColorAttachments(), activeState.GetDepthAttachment(), !ctx.gpu.traits.quirks.relaxedRenderPassCompatibility); }, scissor, {}, activeState.GetColorAttachments(), activeState.GetDepthAttachment(), !ctx.gpu.traits.quirks.relaxedRenderPassCompatibility);
constantBuffers.ResetQuickBind(); constantBuffers.ResetQuickBind();