From 8195bea63e0762ac302cd5568761cb1d7b9c0700 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Sat, 28 Sep 2024 01:20:26 +0200 Subject: [PATCH] [dxvk] Remove DxvkBufferViewCreateInfo Use the new key struct directly to avoid unnecessary struct conversion. --- src/d3d11/d3d11_context.cpp | 14 ++++++------ src/d3d11/d3d11_view_srv.cpp | 18 +++++++-------- src/d3d11/d3d11_view_uav.cpp | 28 +++++++++++------------ src/d3d9/d3d9_format_helpers.cpp | 8 +++---- src/dxvk/dxvk_buffer.cpp | 10 ++------- src/dxvk/dxvk_buffer.h | 34 ++++------------------------ src/dxvk/dxvk_context.cpp | 36 +++++++++++++++--------------- src/dxvk/hud/dxvk_hud_item.cpp | 6 ++--- src/dxvk/hud/dxvk_hud_renderer.cpp | 20 ++++++++--------- 9 files changed, 71 insertions(+), 103 deletions(-) diff --git a/src/d3d11/d3d11_context.cpp b/src/d3d11/d3d11_context.cpp index 3f6a3d5c..1b41dd28 100644 --- a/src/d3d11/d3d11_context.cpp +++ b/src/d3d11/d3d11_context.cpp @@ -484,7 +484,7 @@ namespace dxvk { } else { // Create a view with an integer format if necessary if (uavFormat != rawFormat) { - DxvkBufferViewCreateInfo info = bufferView->info(); + DxvkBufferViewKey info = bufferView->info(); info.format = rawFormat; bufferView = bufferView->buffer()->createView(info); @@ -554,11 +554,11 @@ namespace dxvk { Rc buffer = m_device->createBuffer(bufferInfo, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT); - DxvkBufferViewCreateInfo bufferViewInfo; - bufferViewInfo.format = rawFormat; - bufferViewInfo.rangeOffset = 0; - bufferViewInfo.rangeLength = bufferInfo.size; - bufferViewInfo.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT; + DxvkBufferViewKey bufferViewInfo; + bufferViewInfo.format = rawFormat; + bufferViewInfo.offset = 0; + bufferViewInfo.size = bufferInfo.size; + bufferViewInfo.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT; Rc bufferView = buffer->createView(bufferViewInfo); @@ -754,7 +754,7 @@ namespace dxvk { if (bufView != nullptr) { VkDeviceSize offset = 0; - VkDeviceSize length = bufView->info().rangeLength / formatInfo->elementSize; + VkDeviceSize length = bufView->info().size / formatInfo->elementSize; if (pRect) { offset = pRect[i].left; diff --git a/src/d3d11/d3d11_view_srv.cpp b/src/d3d11/d3d11_view_srv.cpp index 117cb368..2023de30 100644 --- a/src/d3d11/d3d11_view_srv.cpp +++ b/src/d3d11/d3d11_view_srv.cpp @@ -42,31 +42,31 @@ namespace dxvk { } // Fill in buffer view info - DxvkBufferViewCreateInfo viewInfo; + DxvkBufferViewKey viewInfo; viewInfo.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT; if (bufInfo.Flags & D3D11_BUFFEREX_SRV_FLAG_RAW) { // Raw buffer view. We'll represent this as a // uniform texel buffer with UINT32 elements. viewInfo.format = VK_FORMAT_R32_UINT; - viewInfo.rangeOffset = sizeof(uint32_t) * bufInfo.FirstElement; - viewInfo.rangeLength = sizeof(uint32_t) * bufInfo.NumElements; + viewInfo.offset = sizeof(uint32_t) * bufInfo.FirstElement; + viewInfo.size = sizeof(uint32_t) * bufInfo.NumElements; } else if (pDesc->Format == DXGI_FORMAT_UNKNOWN) { // Structured buffer view viewInfo.format = VK_FORMAT_R32_UINT; - viewInfo.rangeOffset = buffer->Desc()->StructureByteStride * bufInfo.FirstElement; - viewInfo.rangeLength = buffer->Desc()->StructureByteStride * bufInfo.NumElements; + viewInfo.offset = buffer->Desc()->StructureByteStride * bufInfo.FirstElement; + viewInfo.size = buffer->Desc()->StructureByteStride * bufInfo.NumElements; } else { viewInfo.format = pDevice->LookupFormat(pDesc->Format, DXGI_VK_FORMAT_MODE_COLOR).Format; const DxvkFormatInfo* formatInfo = lookupFormatInfo(viewInfo.format); - viewInfo.rangeOffset = formatInfo->elementSize * bufInfo.FirstElement; - viewInfo.rangeLength = formatInfo->elementSize * bufInfo.NumElements; + viewInfo.offset = formatInfo->elementSize * bufInfo.FirstElement; + viewInfo.size = formatInfo->elementSize * bufInfo.NumElements; } // Populate view info struct - m_info.Buffer.Offset = viewInfo.rangeOffset; - m_info.Buffer.Length = viewInfo.rangeLength; + m_info.Buffer.Offset = viewInfo.offset; + m_info.Buffer.Length = viewInfo.size; // Create underlying buffer view object m_bufferView = buffer->GetBuffer()->createView(viewInfo); diff --git a/src/d3d11/d3d11_view_uav.cpp b/src/d3d11/d3d11_view_uav.cpp index 3464859b..96d2578c 100644 --- a/src/d3d11/d3d11_view_uav.cpp +++ b/src/d3d11/d3d11_view_uav.cpp @@ -25,31 +25,31 @@ namespace dxvk { if (resourceDesc.Dim == D3D11_RESOURCE_DIMENSION_BUFFER) { auto buffer = static_cast(pResource); - DxvkBufferViewCreateInfo viewInfo; + DxvkBufferViewKey viewInfo; viewInfo.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT; if (pDesc->Buffer.Flags & D3D11_BUFFEREX_SRV_FLAG_RAW) { - viewInfo.format = VK_FORMAT_R32_UINT; - viewInfo.rangeOffset = sizeof(uint32_t) * pDesc->Buffer.FirstElement; - viewInfo.rangeLength = sizeof(uint32_t) * pDesc->Buffer.NumElements; + viewInfo.format = VK_FORMAT_R32_UINT; + viewInfo.offset = sizeof(uint32_t) * pDesc->Buffer.FirstElement; + viewInfo.size = sizeof(uint32_t) * pDesc->Buffer.NumElements; } else if (pDesc->Format == DXGI_FORMAT_UNKNOWN) { - viewInfo.format = VK_FORMAT_R32_UINT; - viewInfo.rangeOffset = buffer->Desc()->StructureByteStride * pDesc->Buffer.FirstElement; - viewInfo.rangeLength = buffer->Desc()->StructureByteStride * pDesc->Buffer.NumElements; + viewInfo.format = VK_FORMAT_R32_UINT; + viewInfo.offset = buffer->Desc()->StructureByteStride * pDesc->Buffer.FirstElement; + viewInfo.size = buffer->Desc()->StructureByteStride * pDesc->Buffer.NumElements; } else { viewInfo.format = pDevice->LookupFormat(pDesc->Format, DXGI_VK_FORMAT_MODE_COLOR).Format; const DxvkFormatInfo* formatInfo = lookupFormatInfo(viewInfo.format); - viewInfo.rangeOffset = formatInfo->elementSize * pDesc->Buffer.FirstElement; - viewInfo.rangeLength = formatInfo->elementSize * pDesc->Buffer.NumElements; + viewInfo.offset = formatInfo->elementSize * pDesc->Buffer.FirstElement; + viewInfo.size = formatInfo->elementSize * pDesc->Buffer.NumElements; } if (pDesc->Buffer.Flags & (D3D11_BUFFER_UAV_FLAG_APPEND | D3D11_BUFFER_UAV_FLAG_COUNTER)) m_counterView = CreateCounterBufferView(); // Populate view info struct - m_info.Buffer.Offset = viewInfo.rangeOffset; - m_info.Buffer.Length = viewInfo.rangeLength; + m_info.Buffer.Offset = viewInfo.offset; + m_info.Buffer.Length = viewInfo.size; m_bufferView = buffer->GetBuffer()->createView(viewInfo); } else { @@ -449,10 +449,10 @@ namespace dxvk { Rc buffer = device->createBuffer(info, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT); - DxvkBufferViewCreateInfo viewInfo; + DxvkBufferViewKey viewInfo; viewInfo.format = VK_FORMAT_UNDEFINED; - viewInfo.rangeOffset = 0; - viewInfo.rangeLength = sizeof(uint32_t); + viewInfo.offset = 0; + viewInfo.size = sizeof(uint32_t); viewInfo.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT; return buffer->createView(viewInfo); diff --git a/src/d3d9/d3d9_format_helpers.cpp b/src/d3d9/d3d9_format_helpers.cpp index 4bd645cc..534bd7c6 100644 --- a/src/d3d9/d3d9_format_helpers.cpp +++ b/src/d3d9/d3d9_format_helpers.cpp @@ -92,10 +92,10 @@ namespace dxvk { imageExtent.height / macroPixelRun.height, 1 }; - DxvkBufferViewCreateInfo bufferViewInfo; - bufferViewInfo.format = bufferFormat; - bufferViewInfo.rangeOffset = srcSlice.offset(); - bufferViewInfo.rangeLength = srcSlice.length(); + DxvkBufferViewKey bufferViewInfo; + bufferViewInfo.format = bufferFormat; + bufferViewInfo.offset = srcSlice.offset(); + bufferViewInfo.size = srcSlice.length(); bufferViewInfo.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT; auto tmpBufferView = srcSlice.buffer()->createView(bufferViewInfo); diff --git a/src/dxvk/dxvk_buffer.cpp b/src/dxvk/dxvk_buffer.cpp index e4a34c0e..13d0c578 100644 --- a/src/dxvk/dxvk_buffer.cpp +++ b/src/dxvk/dxvk_buffer.cpp @@ -49,17 +49,11 @@ namespace dxvk { Rc DxvkBuffer::createView( - const DxvkBufferViewCreateInfo& info) { - DxvkBufferViewKey key = { }; - key.format = info.format; - key.offset = info.rangeOffset; - key.size = info.rangeLength; - key.usage = info.usage; - + const DxvkBufferViewKey& info) { std::unique_lock lock(m_viewMutex); 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; } diff --git a/src/dxvk/dxvk_buffer.h b/src/dxvk/dxvk_buffer.h index 682a7fbf..446aa109 100644 --- a/src/dxvk/dxvk_buffer.h +++ b/src/dxvk/dxvk_buffer.h @@ -37,29 +37,8 @@ namespace dxvk { /// Allowed access patterns 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 * @@ -134,13 +113,8 @@ namespace dxvk { * \brief Buffer view properties * \returns Buffer view properties */ - DxvkBufferViewCreateInfo info() const { - DxvkBufferViewCreateInfo info = { }; - info.format = m_key.format; - info.rangeOffset = m_key.offset; - info.rangeLength = m_key.size; - info.usage = m_key.usage; - return info; + DxvkBufferViewKey info() const { + return m_key; } /** @@ -382,7 +356,7 @@ namespace dxvk { * \returns Newly created buffer view */ Rc createView( - const DxvkBufferViewCreateInfo& info); + const DxvkBufferViewKey& info); /** * \brief Retrieves sparse binding table @@ -438,7 +412,7 @@ namespace dxvk { : DxvkBufferSlice(std::move(buffer), 0, buffer->info().size) { } explicit DxvkBufferSlice(const Rc& view) - : DxvkBufferSlice(view->buffer(), view->info().rangeOffset, view->info().rangeLength) { } + : DxvkBufferSlice(view->buffer(), view->info().offset, view->info().size) { } DxvkBufferSlice(const DxvkBufferSlice& ) = default; DxvkBufferSlice( DxvkBufferSlice&&) = default; diff --git a/src/dxvk/dxvk_context.cpp b/src/dxvk/dxvk_context.cpp index 44bee866..cf0b311f 100644 --- a/src/dxvk/dxvk_context.cpp +++ b/src/dxvk/dxvk_context.cpp @@ -861,15 +861,15 @@ namespace dxvk { return; } - DxvkBufferViewCreateInfo viewInfo; + DxvkBufferViewKey viewInfo; viewInfo.format = format; - viewInfo.rangeOffset = dstBufferOffset; - viewInfo.rangeLength = dstBufferSlice.length; + viewInfo.offset = dstBufferOffset; + viewInfo.size = dstBufferSlice.length; viewInfo.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT; Rc dstView = dstBuffer->createView(viewInfo); - viewInfo.rangeOffset = srcBufferOffset; - viewInfo.rangeLength = srcBufferSlice.length; + viewInfo.offset = srcBufferOffset; + viewInfo.size = srcBufferSlice.length; viewInfo.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT; Rc srcView; @@ -908,7 +908,7 @@ namespace dxvk { VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_ACCESS_SHADER_READ_BIT); - viewInfo.rangeOffset = 0; + viewInfo.offset = 0; srcView = tmpBuffer->createView(viewInfo); m_cmd->trackResource(tmpBuffer); @@ -1053,17 +1053,17 @@ namespace dxvk { auto tmpBuffer = m_device->createBuffer(tmpBufferInfo, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT); // Create formatted buffer views - DxvkBufferViewCreateInfo tmpViewInfoD; - tmpViewInfoD.format = dataFormatD; - tmpViewInfoD.rangeOffset = 0; - tmpViewInfoD.rangeLength = dataSizeD; - tmpViewInfoD.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT; + DxvkBufferViewKey tmpViewInfoD; + tmpViewInfoD.format = dataFormatD; + tmpViewInfoD.offset = 0; + tmpViewInfoD.size = dataSizeD; + tmpViewInfoD.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT; - DxvkBufferViewCreateInfo tmpViewInfoS; - tmpViewInfoS.format = dataFormatS; - tmpViewInfoS.rangeOffset = dataSizeD; - tmpViewInfoS.rangeLength = dataSizeS; - tmpViewInfoS.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT; + DxvkBufferViewKey tmpViewInfoS; + tmpViewInfoS.format = dataFormatS; + tmpViewInfoS.offset = dataSizeD; + tmpViewInfoS.size = dataSizeS; + tmpViewInfoS.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT; auto tmpBufferViewD = tmpBuffer->createView(tmpViewInfoD); auto tmpBufferViewS = tmpBuffer->createView(tmpViewInfoS); @@ -1146,13 +1146,13 @@ namespace dxvk { std::array copyRegions; 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].imageOffset = dstOffset3D; copyRegions[0].imageExtent = dstExtent3D; 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].imageOffset = dstOffset3D; copyRegions[1].imageExtent = dstExtent3D; diff --git a/src/dxvk/hud/dxvk_hud_item.cpp b/src/dxvk/hud/dxvk_hud_item.cpp index 2032cf18..4e71219a 100644 --- a/src/dxvk/hud/dxvk_hud_item.cpp +++ b/src/dxvk/hud/dxvk_hud_item.cpp @@ -791,10 +791,10 @@ namespace dxvk::hud { VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT); - DxvkBufferViewCreateInfo viewInfo = { }; + DxvkBufferViewKey viewInfo = { }; viewInfo.format = VK_FORMAT_UNDEFINED; - viewInfo.rangeOffset = 0; - viewInfo.rangeLength = info.size; + viewInfo.offset = 0; + viewInfo.size = info.size; viewInfo.usage = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT; m_pageMaskView = m_pageMaskBuffer->createView(viewInfo); diff --git a/src/dxvk/hud/dxvk_hud_renderer.cpp b/src/dxvk/hud/dxvk_hud_renderer.cpp index d9c9a936..f57d39d5 100644 --- a/src/dxvk/hud/dxvk_hud_renderer.cpp +++ b/src/dxvk/hud/dxvk_hud_renderer.cpp @@ -248,11 +248,11 @@ namespace dxvk::hud { Rc HudRenderer::createDataView() { - DxvkBufferViewCreateInfo info; - info.format = VK_FORMAT_R8_UINT; - info.rangeOffset = 0; - info.rangeLength = m_dataBuffer->info().size; - info.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT; + DxvkBufferViewKey info; + info.format = VK_FORMAT_R8_UINT; + info.offset = 0; + info.size = m_dataBuffer->info().size; + info.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT; return m_dataBuffer->createView(info); } @@ -273,11 +273,11 @@ namespace dxvk::hud { Rc HudRenderer::createFontBufferView() { - DxvkBufferViewCreateInfo info; - info.format = VK_FORMAT_UNDEFINED; - info.rangeOffset = 0; - info.rangeLength = m_fontBuffer->info().size; - info.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT; + DxvkBufferViewKey info; + info.format = VK_FORMAT_UNDEFINED; + info.offset = 0; + info.size = m_fontBuffer->info().size; + info.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT; return m_fontBuffer->createView(info); }