From 36fd885b494f3bef515778eff9e0b41a64c075e3 Mon Sep 17 00:00:00 2001 From: Billy Laws Date: Sun, 9 Oct 2022 14:06:21 +0100 Subject: [PATCH] Pack all draw state into a struct to avoid std::function allocations --- .../gpu/interconnect/maxwell_3d/maxwell_3d.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/app/src/main/cpp/skyline/gpu/interconnect/maxwell_3d/maxwell_3d.cpp b/app/src/main/cpp/skyline/gpu/interconnect/maxwell_3d/maxwell_3d.cpp index 1d48905b..67555fd3 100644 --- a/app/src/main/cpp/skyline/gpu/interconnect/maxwell_3d/maxwell_3d.cpp +++ b/app/src/main/cpp/skyline/gpu/interconnect/maxwell_3d/maxwell_3d.cpp @@ -261,7 +261,11 @@ namespace skyline::gpu::interconnect::maxwell3d { 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 { + StateUpdater stateUpdater; u32 count; u32 first; u32 instanceCount; @@ -269,7 +273,8 @@ namespace skyline::gpu::interconnect::maxwell3d { u32 firstInstance; bool indexed; }; - auto *drawParams{ctx.executor.allocator->EmplaceUntracked(DrawParams{count, first, instanceCount, vertexOffset, firstInstance, indexed})}; + auto *drawParams{ctx.executor.allocator->EmplaceUntracked(DrawParams{stateUpdater, + count, first, instanceCount, vertexOffset, firstInstance, indexed})}; const auto &surfaceClip{clearEngineRegisters.surfaceClip}; vk::Rect2D scissor{ @@ -277,12 +282,14 @@ namespace skyline::gpu::interconnect::maxwell3d { {surfaceClip.horizontal.width, surfaceClip.vertical.height} }; - ctx.executor.AddSubpass([stateUpdater, drawParams](vk::raii::CommandBuffer &commandBuffer, const std::shared_ptr &, GPU &gpu, vk::RenderPass, u32) { - stateUpdater.RecordAll(gpu, commandBuffer); + ctx.executor.AddSubpass([drawParams](vk::raii::CommandBuffer &commandBuffer, const std::shared_ptr &, GPU &gpu, vk::RenderPass, u32) { + drawParams->stateUpdater.RecordAll(gpu, commandBuffer); + if (drawParams->indexed) commandBuffer.drawIndexed(drawParams->count, drawParams->instanceCount, drawParams->first, static_cast(drawParams->vertexOffset), drawParams->firstInstance); else commandBuffer.draw(drawParams->count, drawParams->instanceCount, drawParams->first, drawParams->firstInstance); + }, scissor, {}, activeState.GetColorAttachments(), activeState.GetDepthAttachment(), !ctx.gpu.traits.quirks.relaxedRenderPassCompatibility); constantBuffers.ResetQuickBind();