From 0315997fcd31f1d6de68514d6c7a5bb0a07b35bd Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Wed, 3 Aug 2022 16:14:57 +0200 Subject: [PATCH] [d3d9] Use mutable lambdas to avoid some redundant ref counting --- src/d3d9/d3d9_constant_buffer.cpp | 4 ++-- src/d3d9/d3d9_device.cpp | 33 ++++++++++++++++--------------- src/d3d9/d3d9_format_helpers.cpp | 6 +++--- 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/d3d9/d3d9_constant_buffer.cpp b/src/d3d9/d3d9_constant_buffer.cpp index a20502bb7..a88935b01 100644 --- a/src/d3d9/d3d9_constant_buffer.cpp +++ b/src/d3d9/d3d9_constant_buffer.cpp @@ -117,8 +117,8 @@ namespace dxvk { cStages = m_stages, cBinding = m_binding, cSlice = DxvkBufferSlice(m_buffer) - ] (DxvkContext* ctx) { - ctx->bindResourceBuffer(cStages, cBinding, cSlice); + ] (DxvkContext* ctx) mutable { + ctx->bindResourceBuffer(cStages, cBinding, std::move(cSlice)); }); } diff --git a/src/d3d9/d3d9_device.cpp b/src/d3d9/d3d9_device.cpp index 78a02707d..716100c39 100644 --- a/src/d3d9/d3d9_device.cpp +++ b/src/d3d9/d3d9_device.cpp @@ -2503,12 +2503,12 @@ namespace dxvk { cPrimCount = PrimitiveCount, cInstanceCount = GetInstanceCount(), cStride = VertexStreamZeroStride - ](DxvkContext* ctx) { + ](DxvkContext* ctx) mutable { auto drawInfo = GenerateDrawInfo(cPrimType, cPrimCount, cInstanceCount); ApplyPrimitiveType(ctx, cPrimType); - ctx->bindVertexBuffer(0, cBufferSlice, cStride); + ctx->bindVertexBuffer(0, std::move(cBufferSlice), cStride); ctx->draw( drawInfo.vertexCount, drawInfo.instanceCount, 0, 0); @@ -2645,7 +2645,7 @@ namespace dxvk { cInstanceCount = GetInstanceCount(), cBufferSlice = slice, cIndexed = m_state.indices != nullptr - ](DxvkContext* ctx) { + ](DxvkContext* ctx) mutable { Rc shader = m_swvpEmulator.GetShaderModule(this, cDecl); auto drawInfo = GenerateDrawInfo(D3DPT_POINTLIST, cVertexCount, cInstanceCount); @@ -2662,8 +2662,8 @@ namespace dxvk { // to avoid val errors / UB. ctx->bindShader(VK_SHADER_STAGE_FRAGMENT_BIT, nullptr); - ctx->bindShader(VK_SHADER_STAGE_GEOMETRY_BIT, shader); - ctx->bindResourceBuffer(VK_SHADER_STAGE_GEOMETRY_BIT, getSWVPBufferSlot(), cBufferSlice); + ctx->bindShader(VK_SHADER_STAGE_GEOMETRY_BIT, std::move(shader)); + ctx->bindResourceBuffer(VK_SHADER_STAGE_GEOMETRY_BIT, getSWVPBufferSlot(), std::move(cBufferSlice)); ctx->draw( drawInfo.vertexCount, drawInfo.instanceCount, cStartIndex, 0); @@ -5476,8 +5476,8 @@ namespace dxvk { // Create and bind the framebuffer object to the context EmitCs([ cAttachments = std::move(attachments) - ] (DxvkContext* ctx) { - ctx->bindRenderTargets(cAttachments); + ] (DxvkContext* ctx) mutable { + ctx->bindRenderTargets(std::move(cAttachments)); }); } @@ -5813,7 +5813,8 @@ namespace dxvk { auto pair = m_samplers.find(cKey); if (pair != m_samplers.end()) { - ctx->bindResourceSampler(stage, cSlot, pair->second); + ctx->bindResourceSampler(stage, cSlot, + Rc(pair->second)); return; } @@ -5880,9 +5881,9 @@ namespace dxvk { EmitCs([ cSlot = slot, cImageView = commonTex->GetSampleView(srgb) - ](DxvkContext* ctx) { + ](DxvkContext* ctx) mutable { VkShaderStageFlags stage = VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT; - ctx->bindResourceView(stage, cSlot, cImageView, nullptr); + ctx->bindResourceView(stage, cSlot, std::move(cImageView), nullptr); }); } @@ -6129,8 +6130,8 @@ namespace dxvk { D3D9ShaderPermutation Permutation) { EmitCs([ cShader = pShaderModule->GetShader(Permutation) - ] (DxvkContext* ctx) { - ctx->bindShader(GetShaderStage(ShaderStage), cShader); + ] (DxvkContext* ctx) mutable { + ctx->bindShader(GetShaderStage(ShaderStage), std::move(cShader)); }); } @@ -6259,8 +6260,8 @@ namespace dxvk { pBuffer->GetCommonBuffer()->GetBufferSlice(Offset) : DxvkBufferSlice(), cStride = pBuffer != nullptr ? Stride : 0 - ] (DxvkContext* ctx) { - ctx->bindVertexBuffer(cSlotId, cBufferSlice, cStride); + ] (DxvkContext* ctx) mutable { + ctx->bindVertexBuffer(cSlotId, std::move(cBufferSlice), cStride); }); } @@ -6276,8 +6277,8 @@ namespace dxvk { EmitCs([ cBufferSlice = buffer != nullptr ? buffer->GetBufferSlice() : DxvkBufferSlice(), cIndexType = indexType - ](DxvkContext* ctx) { - ctx->bindIndexBuffer(cBufferSlice, cIndexType); + ](DxvkContext* ctx) mutable { + ctx->bindIndexBuffer(std::move(cBufferSlice), cIndexType); }); } diff --git a/src/d3d9/d3d9_format_helpers.cpp b/src/d3d9/d3d9_format_helpers.cpp index 2c369d21b..59dc3868f 100644 --- a/src/d3d9/d3d9_format_helpers.cpp +++ b/src/d3d9/d3d9_format_helpers.cpp @@ -94,9 +94,9 @@ namespace dxvk { auto tmpBufferView = m_device->createBufferView(srcSlice.buffer(), bufferViewInfo); m_context->setSpecConstant(VK_PIPELINE_BIND_POINT_COMPUTE, 0, specConstantValue); - m_context->bindResourceView(VK_SHADER_STAGE_COMPUTE_BIT, BindingIds::Image, tmpImageView, nullptr); - m_context->bindResourceView(VK_SHADER_STAGE_COMPUTE_BIT, BindingIds::Buffer, nullptr, tmpBufferView); - m_context->bindShader(VK_SHADER_STAGE_COMPUTE_BIT, m_shaders[videoFormat.FormatType]); + m_context->bindResourceView(VK_SHADER_STAGE_COMPUTE_BIT, BindingIds::Image, std::move(tmpImageView), nullptr); + m_context->bindResourceView(VK_SHADER_STAGE_COMPUTE_BIT, BindingIds::Buffer, nullptr, std::move(tmpBufferView)); + m_context->bindShader(VK_SHADER_STAGE_COMPUTE_BIT, Rc(m_shaders[videoFormat.FormatType])); m_context->pushConstants(0, sizeof(VkExtent2D), &imageExtent); m_context->dispatch( (imageExtent.width / 8) + (imageExtent.width % 8),