From 9c0dec9f58bc21f120be9e6bd2e367e9a2581d80 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Sat, 1 Mar 2025 13:17:48 +0100 Subject: [PATCH] [dxvk] Move buffer initialization to transfer queue --- src/dxvk/dxvk_context.cpp | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/dxvk/dxvk_context.cpp b/src/dxvk/dxvk_context.cpp index d14edddc9..54bdb3e47 100644 --- a/src/dxvk/dxvk_context.cpp +++ b/src/dxvk/dxvk_context.cpp @@ -1008,45 +1008,49 @@ namespace dxvk { void DxvkContext::initBuffer( const Rc& buffer) { - auto slice = buffer->getSliceHandle(); + auto dstSlice = buffer->getSliceHandle(); // Buffer size may be misaligned, in which case we have // to use a plain buffer copy to fill the last few bytes. constexpr VkDeviceSize MinCopyAndFillSize = 1u << 20; - VkDeviceSize copySize = slice.length & 3u; - VkDeviceSize fillSize = slice.length - copySize; + VkDeviceSize copySize = dstSlice.length & 3u; + VkDeviceSize fillSize = dstSlice.length - copySize; // If the buffer is small, just dispatch one single copy - if (copySize && slice.length < MinCopyAndFillSize) { - copySize = slice.length; + if (copySize && dstSlice.length < MinCopyAndFillSize) { + copySize = dstSlice.length; fillSize = 0u; } if (fillSize) { - m_cmd->cmdFillBuffer(DxvkCmdBuffer::InitBuffer, - slice.handle, slice.offset, fillSize, 0u); + m_cmd->cmdFillBuffer(DxvkCmdBuffer::SdmaBuffer, + dstSlice.handle, dstSlice.offset, fillSize, 0u); } if (copySize) { - auto zero = createZeroBuffer(copySize)->getSliceHandle(); + auto srcSlice = createZeroBuffer(copySize)->getSliceHandle(); VkBufferCopy2 copyRegion = { VK_STRUCTURE_TYPE_BUFFER_COPY_2 }; - copyRegion.srcOffset = zero.offset; - copyRegion.dstOffset = slice.offset + fillSize; + copyRegion.srcOffset = srcSlice.offset; + copyRegion.dstOffset = dstSlice.offset + fillSize; copyRegion.size = copySize; VkCopyBufferInfo2 copyInfo = { VK_STRUCTURE_TYPE_COPY_BUFFER_INFO_2 }; - copyInfo.srcBuffer = zero.handle; - copyInfo.dstBuffer = slice.handle; + copyInfo.srcBuffer = srcSlice.handle; + copyInfo.dstBuffer = dstSlice.handle; copyInfo.regionCount = 1; copyInfo.pRegions = ©Region; - m_cmd->cmdCopyBuffer(DxvkCmdBuffer::InitBuffer, ©Info); + m_cmd->cmdCopyBuffer(DxvkCmdBuffer::SdmaBuffer, ©Info); } - accessMemory(DxvkCmdBuffer::InitBuffer, + accessMemory(DxvkCmdBuffer::SdmaBuffer, VK_PIPELINE_STAGE_2_TRANSFER_BIT, VK_ACCESS_2_TRANSFER_WRITE_BIT, + VK_PIPELINE_STAGE_2_TRANSFER_BIT, VK_ACCESS_2_NONE); + + accessMemory(DxvkCmdBuffer::InitBarriers, + VK_PIPELINE_STAGE_2_TRANSFER_BIT, VK_ACCESS_2_NONE, buffer->info().stages, buffer->info().access); m_cmd->track(buffer, DxvkAccess::Write);