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

[dxvk] Remove DxvkBufferViewCreateInfo

Use the new key struct directly to avoid unnecessary struct conversion.
This commit is contained in:
Philip Rebohle 2024-09-28 01:20:26 +02:00
parent b0d0959329
commit 8195bea63e
9 changed files with 71 additions and 103 deletions

View File

@ -484,7 +484,7 @@ namespace dxvk {
} else { } else {
// Create a view with an integer format if necessary // Create a view with an integer format if necessary
if (uavFormat != rawFormat) { if (uavFormat != rawFormat) {
DxvkBufferViewCreateInfo info = bufferView->info(); DxvkBufferViewKey info = bufferView->info();
info.format = rawFormat; info.format = rawFormat;
bufferView = bufferView->buffer()->createView(info); bufferView = bufferView->buffer()->createView(info);
@ -554,11 +554,11 @@ namespace dxvk {
Rc<DxvkBuffer> buffer = m_device->createBuffer(bufferInfo, Rc<DxvkBuffer> buffer = m_device->createBuffer(bufferInfo,
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT); VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
DxvkBufferViewCreateInfo bufferViewInfo; DxvkBufferViewKey bufferViewInfo;
bufferViewInfo.format = rawFormat; bufferViewInfo.format = rawFormat;
bufferViewInfo.rangeOffset = 0; bufferViewInfo.offset = 0;
bufferViewInfo.rangeLength = bufferInfo.size; bufferViewInfo.size = bufferInfo.size;
bufferViewInfo.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT; bufferViewInfo.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
Rc<DxvkBufferView> bufferView = buffer->createView(bufferViewInfo); Rc<DxvkBufferView> bufferView = buffer->createView(bufferViewInfo);
@ -754,7 +754,7 @@ namespace dxvk {
if (bufView != nullptr) { if (bufView != nullptr) {
VkDeviceSize offset = 0; VkDeviceSize offset = 0;
VkDeviceSize length = bufView->info().rangeLength / formatInfo->elementSize; VkDeviceSize length = bufView->info().size / formatInfo->elementSize;
if (pRect) { if (pRect) {
offset = pRect[i].left; offset = pRect[i].left;

View File

@ -42,31 +42,31 @@ namespace dxvk {
} }
// Fill in buffer view info // Fill in buffer view info
DxvkBufferViewCreateInfo viewInfo; DxvkBufferViewKey viewInfo;
viewInfo.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT; viewInfo.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
if (bufInfo.Flags & D3D11_BUFFEREX_SRV_FLAG_RAW) { if (bufInfo.Flags & D3D11_BUFFEREX_SRV_FLAG_RAW) {
// Raw buffer view. We'll represent this as a // Raw buffer view. We'll represent this as a
// uniform texel buffer with UINT32 elements. // uniform texel buffer with UINT32 elements.
viewInfo.format = VK_FORMAT_R32_UINT; viewInfo.format = VK_FORMAT_R32_UINT;
viewInfo.rangeOffset = sizeof(uint32_t) * bufInfo.FirstElement; viewInfo.offset = sizeof(uint32_t) * bufInfo.FirstElement;
viewInfo.rangeLength = sizeof(uint32_t) * bufInfo.NumElements; viewInfo.size = sizeof(uint32_t) * bufInfo.NumElements;
} else if (pDesc->Format == DXGI_FORMAT_UNKNOWN) { } else if (pDesc->Format == DXGI_FORMAT_UNKNOWN) {
// Structured buffer view // Structured buffer view
viewInfo.format = VK_FORMAT_R32_UINT; viewInfo.format = VK_FORMAT_R32_UINT;
viewInfo.rangeOffset = buffer->Desc()->StructureByteStride * bufInfo.FirstElement; viewInfo.offset = buffer->Desc()->StructureByteStride * bufInfo.FirstElement;
viewInfo.rangeLength = buffer->Desc()->StructureByteStride * bufInfo.NumElements; viewInfo.size = buffer->Desc()->StructureByteStride * bufInfo.NumElements;
} else { } else {
viewInfo.format = pDevice->LookupFormat(pDesc->Format, DXGI_VK_FORMAT_MODE_COLOR).Format; viewInfo.format = pDevice->LookupFormat(pDesc->Format, DXGI_VK_FORMAT_MODE_COLOR).Format;
const DxvkFormatInfo* formatInfo = lookupFormatInfo(viewInfo.format); const DxvkFormatInfo* formatInfo = lookupFormatInfo(viewInfo.format);
viewInfo.rangeOffset = formatInfo->elementSize * bufInfo.FirstElement; viewInfo.offset = formatInfo->elementSize * bufInfo.FirstElement;
viewInfo.rangeLength = formatInfo->elementSize * bufInfo.NumElements; viewInfo.size = formatInfo->elementSize * bufInfo.NumElements;
} }
// Populate view info struct // Populate view info struct
m_info.Buffer.Offset = viewInfo.rangeOffset; m_info.Buffer.Offset = viewInfo.offset;
m_info.Buffer.Length = viewInfo.rangeLength; m_info.Buffer.Length = viewInfo.size;
// Create underlying buffer view object // Create underlying buffer view object
m_bufferView = buffer->GetBuffer()->createView(viewInfo); m_bufferView = buffer->GetBuffer()->createView(viewInfo);

View File

@ -25,31 +25,31 @@ namespace dxvk {
if (resourceDesc.Dim == D3D11_RESOURCE_DIMENSION_BUFFER) { if (resourceDesc.Dim == D3D11_RESOURCE_DIMENSION_BUFFER) {
auto buffer = static_cast<D3D11Buffer*>(pResource); auto buffer = static_cast<D3D11Buffer*>(pResource);
DxvkBufferViewCreateInfo viewInfo; DxvkBufferViewKey viewInfo;
viewInfo.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT; viewInfo.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
if (pDesc->Buffer.Flags & D3D11_BUFFEREX_SRV_FLAG_RAW) { if (pDesc->Buffer.Flags & D3D11_BUFFEREX_SRV_FLAG_RAW) {
viewInfo.format = VK_FORMAT_R32_UINT; viewInfo.format = VK_FORMAT_R32_UINT;
viewInfo.rangeOffset = sizeof(uint32_t) * pDesc->Buffer.FirstElement; viewInfo.offset = sizeof(uint32_t) * pDesc->Buffer.FirstElement;
viewInfo.rangeLength = sizeof(uint32_t) * pDesc->Buffer.NumElements; viewInfo.size = sizeof(uint32_t) * pDesc->Buffer.NumElements;
} else if (pDesc->Format == DXGI_FORMAT_UNKNOWN) { } else if (pDesc->Format == DXGI_FORMAT_UNKNOWN) {
viewInfo.format = VK_FORMAT_R32_UINT; viewInfo.format = VK_FORMAT_R32_UINT;
viewInfo.rangeOffset = buffer->Desc()->StructureByteStride * pDesc->Buffer.FirstElement; viewInfo.offset = buffer->Desc()->StructureByteStride * pDesc->Buffer.FirstElement;
viewInfo.rangeLength = buffer->Desc()->StructureByteStride * pDesc->Buffer.NumElements; viewInfo.size = buffer->Desc()->StructureByteStride * pDesc->Buffer.NumElements;
} else { } else {
viewInfo.format = pDevice->LookupFormat(pDesc->Format, DXGI_VK_FORMAT_MODE_COLOR).Format; viewInfo.format = pDevice->LookupFormat(pDesc->Format, DXGI_VK_FORMAT_MODE_COLOR).Format;
const DxvkFormatInfo* formatInfo = lookupFormatInfo(viewInfo.format); const DxvkFormatInfo* formatInfo = lookupFormatInfo(viewInfo.format);
viewInfo.rangeOffset = formatInfo->elementSize * pDesc->Buffer.FirstElement; viewInfo.offset = formatInfo->elementSize * pDesc->Buffer.FirstElement;
viewInfo.rangeLength = formatInfo->elementSize * pDesc->Buffer.NumElements; viewInfo.size = formatInfo->elementSize * pDesc->Buffer.NumElements;
} }
if (pDesc->Buffer.Flags & (D3D11_BUFFER_UAV_FLAG_APPEND | D3D11_BUFFER_UAV_FLAG_COUNTER)) if (pDesc->Buffer.Flags & (D3D11_BUFFER_UAV_FLAG_APPEND | D3D11_BUFFER_UAV_FLAG_COUNTER))
m_counterView = CreateCounterBufferView(); m_counterView = CreateCounterBufferView();
// Populate view info struct // Populate view info struct
m_info.Buffer.Offset = viewInfo.rangeOffset; m_info.Buffer.Offset = viewInfo.offset;
m_info.Buffer.Length = viewInfo.rangeLength; m_info.Buffer.Length = viewInfo.size;
m_bufferView = buffer->GetBuffer()->createView(viewInfo); m_bufferView = buffer->GetBuffer()->createView(viewInfo);
} else { } else {
@ -449,10 +449,10 @@ namespace dxvk {
Rc<DxvkBuffer> buffer = device->createBuffer(info, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT); Rc<DxvkBuffer> buffer = device->createBuffer(info, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
DxvkBufferViewCreateInfo viewInfo; DxvkBufferViewKey viewInfo;
viewInfo.format = VK_FORMAT_UNDEFINED; viewInfo.format = VK_FORMAT_UNDEFINED;
viewInfo.rangeOffset = 0; viewInfo.offset = 0;
viewInfo.rangeLength = sizeof(uint32_t); viewInfo.size = sizeof(uint32_t);
viewInfo.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT; viewInfo.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
return buffer->createView(viewInfo); return buffer->createView(viewInfo);

View File

@ -92,10 +92,10 @@ namespace dxvk {
imageExtent.height / macroPixelRun.height, imageExtent.height / macroPixelRun.height,
1 }; 1 };
DxvkBufferViewCreateInfo bufferViewInfo; DxvkBufferViewKey bufferViewInfo;
bufferViewInfo.format = bufferFormat; bufferViewInfo.format = bufferFormat;
bufferViewInfo.rangeOffset = srcSlice.offset(); bufferViewInfo.offset = srcSlice.offset();
bufferViewInfo.rangeLength = srcSlice.length(); bufferViewInfo.size = srcSlice.length();
bufferViewInfo.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT; bufferViewInfo.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
auto tmpBufferView = srcSlice.buffer()->createView(bufferViewInfo); auto tmpBufferView = srcSlice.buffer()->createView(bufferViewInfo);

View File

@ -49,17 +49,11 @@ namespace dxvk {
Rc<DxvkBufferView> DxvkBuffer::createView( Rc<DxvkBufferView> DxvkBuffer::createView(
const DxvkBufferViewCreateInfo& info) { const DxvkBufferViewKey& info) {
DxvkBufferViewKey key = { };
key.format = info.format;
key.offset = info.rangeOffset;
key.size = info.rangeLength;
key.usage = info.usage;
std::unique_lock lock(m_viewMutex); std::unique_lock lock(m_viewMutex);
auto entry = m_views.emplace(std::piecewise_construct, auto entry = m_views.emplace(std::piecewise_construct,
std::make_tuple(key), std::make_tuple(this, key)); std::make_tuple(info), std::make_tuple(this, info));
return &entry.first->second; return &entry.first->second;
} }

View File

@ -37,29 +37,8 @@ namespace dxvk {
/// Allowed access patterns /// Allowed access patterns
VkAccessFlags access; VkAccessFlags access;
}; };
/**
* \brief Buffer view create info
*
* The properties of a buffer view that
* are to \ref DxvkDevice::createBufferView
*/
struct DxvkBufferViewCreateInfo {
/// Buffer data format, like image data
VkFormat format = VK_FORMAT_UNDEFINED;
/// Offset of the buffer region to include in the view
VkDeviceSize rangeOffset = 0u;
/// Size of the buffer region to include in the view
VkDeviceSize rangeLength = 0u;
/// Buffer view usage flags
VkBufferUsageFlags usage = 0u;
};
/** /**
* \brief Buffer slice info * \brief Buffer slice info
* *
@ -134,13 +113,8 @@ namespace dxvk {
* \brief Buffer view properties * \brief Buffer view properties
* \returns Buffer view properties * \returns Buffer view properties
*/ */
DxvkBufferViewCreateInfo info() const { DxvkBufferViewKey info() const {
DxvkBufferViewCreateInfo info = { }; return m_key;
info.format = m_key.format;
info.rangeOffset = m_key.offset;
info.rangeLength = m_key.size;
info.usage = m_key.usage;
return info;
} }
/** /**
@ -382,7 +356,7 @@ namespace dxvk {
* \returns Newly created buffer view * \returns Newly created buffer view
*/ */
Rc<DxvkBufferView> createView( Rc<DxvkBufferView> createView(
const DxvkBufferViewCreateInfo& info); const DxvkBufferViewKey& info);
/** /**
* \brief Retrieves sparse binding table * \brief Retrieves sparse binding table
@ -438,7 +412,7 @@ namespace dxvk {
: DxvkBufferSlice(std::move(buffer), 0, buffer->info().size) { } : DxvkBufferSlice(std::move(buffer), 0, buffer->info().size) { }
explicit DxvkBufferSlice(const Rc<DxvkBufferView>& view) explicit DxvkBufferSlice(const Rc<DxvkBufferView>& view)
: DxvkBufferSlice(view->buffer(), view->info().rangeOffset, view->info().rangeLength) { } : DxvkBufferSlice(view->buffer(), view->info().offset, view->info().size) { }
DxvkBufferSlice(const DxvkBufferSlice& ) = default; DxvkBufferSlice(const DxvkBufferSlice& ) = default;
DxvkBufferSlice( DxvkBufferSlice&&) = default; DxvkBufferSlice( DxvkBufferSlice&&) = default;

View File

@ -861,15 +861,15 @@ namespace dxvk {
return; return;
} }
DxvkBufferViewCreateInfo viewInfo; DxvkBufferViewKey viewInfo;
viewInfo.format = format; viewInfo.format = format;
viewInfo.rangeOffset = dstBufferOffset; viewInfo.offset = dstBufferOffset;
viewInfo.rangeLength = dstBufferSlice.length; viewInfo.size = dstBufferSlice.length;
viewInfo.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT; viewInfo.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
Rc<DxvkBufferView> dstView = dstBuffer->createView(viewInfo); Rc<DxvkBufferView> dstView = dstBuffer->createView(viewInfo);
viewInfo.rangeOffset = srcBufferOffset; viewInfo.offset = srcBufferOffset;
viewInfo.rangeLength = srcBufferSlice.length; viewInfo.size = srcBufferSlice.length;
viewInfo.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT; viewInfo.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Rc<DxvkBufferView> srcView; Rc<DxvkBufferView> srcView;
@ -908,7 +908,7 @@ namespace dxvk {
VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
VK_ACCESS_SHADER_READ_BIT); VK_ACCESS_SHADER_READ_BIT);
viewInfo.rangeOffset = 0; viewInfo.offset = 0;
srcView = tmpBuffer->createView(viewInfo); srcView = tmpBuffer->createView(viewInfo);
m_cmd->trackResource<DxvkAccess::Write>(tmpBuffer); m_cmd->trackResource<DxvkAccess::Write>(tmpBuffer);
@ -1053,17 +1053,17 @@ namespace dxvk {
auto tmpBuffer = m_device->createBuffer(tmpBufferInfo, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT); auto tmpBuffer = m_device->createBuffer(tmpBufferInfo, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
// Create formatted buffer views // Create formatted buffer views
DxvkBufferViewCreateInfo tmpViewInfoD; DxvkBufferViewKey tmpViewInfoD;
tmpViewInfoD.format = dataFormatD; tmpViewInfoD.format = dataFormatD;
tmpViewInfoD.rangeOffset = 0; tmpViewInfoD.offset = 0;
tmpViewInfoD.rangeLength = dataSizeD; tmpViewInfoD.size = dataSizeD;
tmpViewInfoD.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT; tmpViewInfoD.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
DxvkBufferViewCreateInfo tmpViewInfoS; DxvkBufferViewKey tmpViewInfoS;
tmpViewInfoS.format = dataFormatS; tmpViewInfoS.format = dataFormatS;
tmpViewInfoS.rangeOffset = dataSizeD; tmpViewInfoS.offset = dataSizeD;
tmpViewInfoS.rangeLength = dataSizeS; tmpViewInfoS.size = dataSizeS;
tmpViewInfoS.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT; tmpViewInfoS.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
auto tmpBufferViewD = tmpBuffer->createView(tmpViewInfoD); auto tmpBufferViewD = tmpBuffer->createView(tmpViewInfoD);
auto tmpBufferViewS = tmpBuffer->createView(tmpViewInfoS); auto tmpBufferViewS = tmpBuffer->createView(tmpViewInfoS);
@ -1146,13 +1146,13 @@ namespace dxvk {
std::array<VkBufferImageCopy2, 2> copyRegions; std::array<VkBufferImageCopy2, 2> copyRegions;
copyRegions[0] = { VK_STRUCTURE_TYPE_BUFFER_IMAGE_COPY_2 }; copyRegions[0] = { VK_STRUCTURE_TYPE_BUFFER_IMAGE_COPY_2 };
copyRegions[0].bufferOffset = tmpBufferViewD->info().rangeOffset; copyRegions[0].bufferOffset = tmpBufferViewD->info().offset;
copyRegions[0].imageSubresource = dstSubresourceD; copyRegions[0].imageSubresource = dstSubresourceD;
copyRegions[0].imageOffset = dstOffset3D; copyRegions[0].imageOffset = dstOffset3D;
copyRegions[0].imageExtent = dstExtent3D; copyRegions[0].imageExtent = dstExtent3D;
copyRegions[1] = { VK_STRUCTURE_TYPE_BUFFER_IMAGE_COPY_2 }; copyRegions[1] = { VK_STRUCTURE_TYPE_BUFFER_IMAGE_COPY_2 };
copyRegions[1].bufferOffset = tmpBufferViewS->info().rangeOffset; copyRegions[1].bufferOffset = tmpBufferViewS->info().offset;
copyRegions[1].imageSubresource = dstSubresourceS; copyRegions[1].imageSubresource = dstSubresourceS;
copyRegions[1].imageOffset = dstOffset3D; copyRegions[1].imageOffset = dstOffset3D;
copyRegions[1].imageExtent = dstExtent3D; copyRegions[1].imageExtent = dstExtent3D;

View File

@ -791,10 +791,10 @@ namespace dxvk::hud {
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
VK_MEMORY_PROPERTY_HOST_COHERENT_BIT); VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
DxvkBufferViewCreateInfo viewInfo = { }; DxvkBufferViewKey viewInfo = { };
viewInfo.format = VK_FORMAT_UNDEFINED; viewInfo.format = VK_FORMAT_UNDEFINED;
viewInfo.rangeOffset = 0; viewInfo.offset = 0;
viewInfo.rangeLength = info.size; viewInfo.size = info.size;
viewInfo.usage = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT; viewInfo.usage = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT;
m_pageMaskView = m_pageMaskBuffer->createView(viewInfo); m_pageMaskView = m_pageMaskBuffer->createView(viewInfo);

View File

@ -248,11 +248,11 @@ namespace dxvk::hud {
Rc<DxvkBufferView> HudRenderer::createDataView() { Rc<DxvkBufferView> HudRenderer::createDataView() {
DxvkBufferViewCreateInfo info; DxvkBufferViewKey info;
info.format = VK_FORMAT_R8_UINT; info.format = VK_FORMAT_R8_UINT;
info.rangeOffset = 0; info.offset = 0;
info.rangeLength = m_dataBuffer->info().size; info.size = m_dataBuffer->info().size;
info.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT; info.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
return m_dataBuffer->createView(info); return m_dataBuffer->createView(info);
} }
@ -273,11 +273,11 @@ namespace dxvk::hud {
Rc<DxvkBufferView> HudRenderer::createFontBufferView() { Rc<DxvkBufferView> HudRenderer::createFontBufferView() {
DxvkBufferViewCreateInfo info; DxvkBufferViewKey info;
info.format = VK_FORMAT_UNDEFINED; info.format = VK_FORMAT_UNDEFINED;
info.rangeOffset = 0; info.offset = 0;
info.rangeLength = m_fontBuffer->info().size; info.size = m_fontBuffer->info().size;
info.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT; info.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
return m_fontBuffer->createView(info); return m_fontBuffer->createView(info);
} }