1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2024-12-11 10:24:10 +01:00

[dxvk] Use DxvkPhysicalBufferSlice for buffer memory barriers

This commit is contained in:
Philip Rebohle 2018-01-18 17:32:34 +01:00
parent a87ae8aba4
commit f41a7c7c87
No known key found for this signature in database
GPG Key ID: C8CC613427A31C99
6 changed files with 68 additions and 29 deletions

View File

@ -6,9 +6,7 @@ namespace dxvk {
DxvkBarrierSet::~DxvkBarrierSet() { }
void DxvkBarrierSet::accessBuffer(
const Rc<DxvkBuffer>& 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);
}
}

View File

@ -21,9 +21,7 @@ namespace dxvk {
~DxvkBarrierSet();
void accessBuffer(
const Rc<DxvkBuffer>& buffer,
VkDeviceSize offset,
VkDeviceSize size,
const DxvkPhysicalBufferSlice& bufSlice,
VkPipelineStageFlags srcStages,
VkAccessFlags srcAccess,
VkPipelineStageFlags dstStages,

View File

@ -15,14 +15,13 @@ namespace dxvk {
}
void DxvkBuffer::renameResource(
const Rc<DxvkPhysicalBuffer>& resource) {
void DxvkBuffer::renameResource(const DxvkPhysicalBufferSlice& resource) {
m_resource = resource;
}
Rc<DxvkPhysicalBuffer> DxvkBuffer::allocateResource() {
return m_device->allocBufferResource(m_info, m_memFlags);
DxvkPhysicalBufferSlice DxvkBuffer::allocateResource() {
return m_device->allocBufferResource(m_info, m_memFlags)->slice(0);
}

View File

@ -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<DxvkResource> 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<DxvkPhysicalBuffer>& resource);
const DxvkPhysicalBufferSlice& resource);
/**
* \brief Allocates new backing resource
* \returns The new buffer
*/
Rc<DxvkPhysicalBuffer> 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<DxvkPhysicalBuffer> 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<vk::DeviceFn> 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);
}

View File

@ -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
*

View File

@ -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,