1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2024-12-02 01: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 {
// 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<DxvkBuffer> 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<DxvkBufferView> 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;

View File

@ -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);

View File

@ -25,31 +25,31 @@ namespace dxvk {
if (resourceDesc.Dim == D3D11_RESOURCE_DIMENSION_BUFFER) {
auto buffer = static_cast<D3D11Buffer*>(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<DxvkBuffer> 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);

View File

@ -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);

View File

@ -49,17 +49,11 @@ namespace dxvk {
Rc<DxvkBufferView> 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;
}

View File

@ -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<DxvkBufferView> 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<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( DxvkBufferSlice&&) = default;

View File

@ -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<DxvkBufferView> 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<DxvkBufferView> 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<DxvkAccess::Write>(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<VkBufferImageCopy2, 2> 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;

View File

@ -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);

View File

@ -248,11 +248,11 @@ namespace dxvk::hud {
Rc<DxvkBufferView> 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<DxvkBufferView> 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);
}