diff --git a/src/dxvk/dxvk_barrier.cpp b/src/dxvk/dxvk_barrier.cpp index c218212d..626be9ca 100644 --- a/src/dxvk/dxvk_barrier.cpp +++ b/src/dxvk/dxvk_barrier.cpp @@ -6,9 +6,7 @@ namespace dxvk { DxvkBarrierSet::~DxvkBarrierSet() { } void DxvkBarrierSet::accessBuffer( - const Rc& buffer, - VkDeviceSize offset, - VkDeviceSize size, + const DxvkPhysicalBufferSlice& bufSlice, VkPipelineStageFlags srcStages, VkAccessFlags srcAccess, VkPipelineStageFlags dstStages, @@ -27,9 +25,9 @@ namespace dxvk { barrier.dstAccessMask = dstAccess; barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; - barrier.buffer = buffer->handle(); - barrier.offset = offset; - barrier.size = size; + barrier.buffer = bufSlice.handle(); + barrier.offset = bufSlice.offset(); + barrier.size = bufSlice.length(); m_bufBarriers.push_back(barrier); } } diff --git a/src/dxvk/dxvk_barrier.h b/src/dxvk/dxvk_barrier.h index 8ed23e64..87687e68 100644 --- a/src/dxvk/dxvk_barrier.h +++ b/src/dxvk/dxvk_barrier.h @@ -21,9 +21,7 @@ namespace dxvk { ~DxvkBarrierSet(); void accessBuffer( - const Rc& buffer, - VkDeviceSize offset, - VkDeviceSize size, + const DxvkPhysicalBufferSlice& bufSlice, VkPipelineStageFlags srcStages, VkAccessFlags srcAccess, VkPipelineStageFlags dstStages, diff --git a/src/dxvk/dxvk_buffer.cpp b/src/dxvk/dxvk_buffer.cpp index 86cbffe5..58d9112e 100644 --- a/src/dxvk/dxvk_buffer.cpp +++ b/src/dxvk/dxvk_buffer.cpp @@ -15,14 +15,13 @@ namespace dxvk { } - void DxvkBuffer::renameResource( - const Rc& resource) { + void DxvkBuffer::renameResource(const DxvkPhysicalBufferSlice& resource) { m_resource = resource; } - Rc DxvkBuffer::allocateResource() { - return m_device->allocBufferResource(m_info, m_memFlags); + DxvkPhysicalBufferSlice DxvkBuffer::allocateResource() { + return m_device->allocBufferResource(m_info, m_memFlags)->slice(0); } diff --git a/src/dxvk/dxvk_buffer.h b/src/dxvk/dxvk_buffer.h index 5d73c252..d07efc5d 100644 --- a/src/dxvk/dxvk_buffer.h +++ b/src/dxvk/dxvk_buffer.h @@ -44,7 +44,7 @@ namespace dxvk { * \returns Buffer handle */ VkBuffer handle() const { - return m_resource->handle();; + return m_resource.handle(); } /** @@ -57,7 +57,7 @@ namespace dxvk { * \returns Pointer to mapped memory region */ void* mapPtr(VkDeviceSize offset) const { - return m_resource->mapPtr(offset); + return m_resource.mapPtr(offset); } /** @@ -70,7 +70,7 @@ namespace dxvk { * \returns \c true if the buffer is in use */ bool isInUse() const { - return m_resource->isInUse(); + return m_resource.resource()->isInUse(); } /** @@ -80,7 +80,7 @@ namespace dxvk { * \returns The resource object */ Rc resource() const { - return m_resource; + return m_resource.resource(); } /** @@ -93,13 +93,36 @@ namespace dxvk { * \param [in] resource The new backing resource */ void renameResource( - const Rc& resource); + const DxvkPhysicalBufferSlice& resource); /** * \brief Allocates new backing resource * \returns The new buffer */ - Rc allocateResource(); + DxvkPhysicalBufferSlice allocateResource(); + + /** + * \brief Physical buffer slice + * + * Retrieves a slice into the physical + * buffer which backs this buffer. + * \returns The backing slice + */ + DxvkPhysicalBufferSlice slice() const { + return m_resource; + } + + /** + * \brief Physical buffer sub slice + * + * Retrieves a sub slice into the backing buffer. + * \param [in] offset Offset into the buffer + * \param [in] length Length of the slice + * \returns The sub slice + */ + DxvkPhysicalBufferSlice subSlice(VkDeviceSize offset, VkDeviceSize length) const { + return m_resource.subSlice(offset, length); + } private: @@ -107,7 +130,7 @@ namespace dxvk { DxvkBufferCreateInfo m_info; VkMemoryPropertyFlags m_memFlags; - Rc m_resource; + DxvkPhysicalBufferSlice m_resource; }; @@ -154,6 +177,16 @@ namespace dxvk { return m_buffer; } + /** + * \brief Underlying buffer slice + * \returns Slice backing the view + */ + DxvkPhysicalBufferSlice slice() const { + return m_buffer->subSlice( + m_info.rangeOffset, + m_info.rangeLength); + } + private: Rc m_vkd; @@ -217,6 +250,10 @@ namespace dxvk { return m_length; } + DxvkPhysicalBufferSlice physicalSlice() const { + return m_buffer->subSlice(m_offset, m_length); + } + void* mapPtr(VkDeviceSize offset) const { return m_buffer->mapPtr(m_offset + offset); } diff --git a/src/dxvk/dxvk_buffer_res.h b/src/dxvk/dxvk_buffer_res.h index 36947c62..a4b50509 100644 --- a/src/dxvk/dxvk_buffer_res.h +++ b/src/dxvk/dxvk_buffer_res.h @@ -162,6 +162,17 @@ namespace dxvk { return m_length; } + /** + * \brief Sub slice into the physical buffer + * + * \param [in] offset Offset, relative to this slice + * \param [in] length Number of bytes of the sub slice + * \returns The sub slice + */ + DxvkPhysicalBufferSlice subSlice(VkDeviceSize offset, VkDeviceSize length) const { + return DxvkPhysicalBufferSlice(m_buffer, m_offset + offset, length); + } + /** * \brief Map pointer * diff --git a/src/dxvk/dxvk_context.cpp b/src/dxvk/dxvk_context.cpp index 40281aff..028a0764 100644 --- a/src/dxvk/dxvk_context.cpp +++ b/src/dxvk/dxvk_context.cpp @@ -273,14 +273,14 @@ namespace dxvk { 1, &bufferRegion); m_barriers.accessBuffer( - srcBuffer, srcOffset, numBytes, + srcBuffer->subSlice(srcOffset, numBytes), VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_TRANSFER_READ_BIT, srcBuffer->info().stages, srcBuffer->info().access); m_barriers.accessBuffer( - dstBuffer, dstOffset, numBytes, + dstBuffer->subSlice(dstOffset, numBytes), VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_TRANSFER_WRITE_BIT, dstBuffer->info().stages, @@ -652,7 +652,7 @@ namespace dxvk { } m_barriers.accessBuffer( - buffer, offset, size, + buffer->subSlice(offset, size), VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_TRANSFER_WRITE_BIT, buffer->info().stages, @@ -1274,9 +1274,7 @@ namespace dxvk { if (binding.type == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER) { m_barriers.accessBuffer( - slot.bufferSlice.buffer(), - slot.bufferSlice.offset(), - slot.bufferSlice.length(), + slot.bufferSlice.physicalSlice(), VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT, @@ -1284,9 +1282,7 @@ namespace dxvk { slot.bufferSlice.buffer()->info().access); } else if (binding.type == VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER) { m_barriers.accessBuffer( - slot.bufferView->buffer(), - slot.bufferView->info().rangeOffset, - slot.bufferView->info().rangeLength, + slot.bufferView->slice(), VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT,