diff --git a/src/dxvk/dxvk_context.cpp b/src/dxvk/dxvk_context.cpp index 6462e4d2d..a51c9d1c4 100644 --- a/src/dxvk/dxvk_context.cpp +++ b/src/dxvk/dxvk_context.cpp @@ -329,23 +329,44 @@ namespace dxvk { VkDeviceSize offset, VkDeviceSize length, uint32_t value) { - this->spillRenderPass(true); - - length = align(length, sizeof(uint32_t)); - auto slice = buffer->getSliceHandle(offset, length); + bool replaceBuffer = this->tryInvalidateDeviceLocalBuffer(buffer, length); + auto bufferSlice = buffer->getSliceHandle(offset, align(length, sizeof(uint32_t))); - if (m_execBarriers.isBufferDirty(slice, DxvkAccess::Write)) - m_execBarriers.recordCommands(m_cmd); + if (!replaceBuffer) { + this->spillRenderPass(true); - m_cmd->cmdFillBuffer(DxvkCmdBuffer::ExecBuffer, - slice.handle, slice.offset, slice.length, value); - - m_execBarriers.accessBuffer(slice, + if (m_execBarriers.isBufferDirty(bufferSlice, DxvkAccess::Write)) + m_execBarriers.recordCommands(m_cmd); + } + + DxvkCmdBuffer cmdBuffer = replaceBuffer + ? DxvkCmdBuffer::InitBuffer + : DxvkCmdBuffer::ExecBuffer; + + if (length > sizeof(value)) { + m_cmd->cmdFillBuffer(cmdBuffer, + bufferSlice.handle, + bufferSlice.offset, + bufferSlice.length, + value); + } else { + m_cmd->cmdUpdateBuffer(cmdBuffer, + bufferSlice.handle, + bufferSlice.offset, + bufferSlice.length, + &value); + } + + auto& barriers = replaceBuffer + ? m_initBarriers + : m_execBarriers; + + barriers.accessBuffer(bufferSlice, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_TRANSFER_WRITE_BIT, buffer->info().stages, buffer->info().access); - + m_cmd->trackResource(buffer); }