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

[dxvk] Add usage property to buffer views

And pass it to the Vulkan driver depending on maintenance5 support.
This commit is contained in:
Philip Rebohle 2024-09-13 14:16:27 +02:00
parent ab557a2eed
commit ddb59ae394
9 changed files with 33 additions and 8 deletions

View File

@ -532,6 +532,7 @@ namespace dxvk {
bufferViewInfo.format = rawFormat; bufferViewInfo.format = rawFormat;
bufferViewInfo.rangeOffset = 0; bufferViewInfo.rangeOffset = 0;
bufferViewInfo.rangeLength = bufferInfo.size; bufferViewInfo.rangeLength = bufferInfo.size;
bufferViewInfo.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
Rc<DxvkBufferView> bufferView = m_device->createBufferView(buffer, Rc<DxvkBufferView> bufferView = m_device->createBufferView(buffer,
bufferViewInfo); bufferViewInfo);

View File

@ -43,6 +43,7 @@ namespace dxvk {
// Fill in buffer view info // Fill in buffer view info
DxvkBufferViewCreateInfo viewInfo; DxvkBufferViewCreateInfo viewInfo;
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

View File

@ -26,6 +26,7 @@ namespace dxvk {
auto buffer = static_cast<D3D11Buffer*>(pResource); auto buffer = static_cast<D3D11Buffer*>(pResource);
DxvkBufferViewCreateInfo viewInfo; DxvkBufferViewCreateInfo viewInfo;
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;
@ -454,6 +455,7 @@ namespace dxvk {
viewInfo.format = VK_FORMAT_UNDEFINED; viewInfo.format = VK_FORMAT_UNDEFINED;
viewInfo.rangeOffset = 0; viewInfo.rangeOffset = 0;
viewInfo.rangeLength = sizeof(uint32_t); viewInfo.rangeLength = sizeof(uint32_t);
viewInfo.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
return device->createBufferView(buffer, viewInfo); return device->createBufferView(buffer, viewInfo);
} }

View File

@ -96,6 +96,7 @@ namespace dxvk {
bufferViewInfo.format = bufferFormat; bufferViewInfo.format = bufferFormat;
bufferViewInfo.rangeOffset = srcSlice.offset(); bufferViewInfo.rangeOffset = srcSlice.offset();
bufferViewInfo.rangeLength = srcSlice.length(); bufferViewInfo.rangeLength = srcSlice.length();
bufferViewInfo.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
auto tmpBufferView = m_device->createBufferView(srcSlice.buffer(), bufferViewInfo); auto tmpBufferView = m_device->createBufferView(srcSlice.buffer(), bufferViewInfo);
m_context->setSpecConstant(VK_PIPELINE_BIND_POINT_COMPUTE, 0, specConstantValue); m_context->setSpecConstant(VK_PIPELINE_BIND_POINT_COMPUTE, 0, specConstantValue);

View File

@ -240,14 +240,18 @@ namespace dxvk {
DxvkBufferView::DxvkBufferView( DxvkBufferView::DxvkBufferView(
const Rc<vk::DeviceFn>& vkd, DxvkDevice* device,
const Rc<DxvkBuffer>& buffer, const Rc<DxvkBuffer>& buffer,
const DxvkBufferViewCreateInfo& info) const DxvkBufferViewCreateInfo& info)
: m_vkd(vkd), m_info(info), m_buffer(buffer), : m_vkd(device->vkd()), m_info(info), m_buffer(buffer),
m_usage (info.usage),
m_bufferSlice (getSliceHandle()), m_bufferSlice (getSliceHandle()),
m_bufferView (VK_NULL_HANDLE) { m_bufferView (VK_NULL_HANDLE) {
if (m_info.format != VK_FORMAT_UNDEFINED) if (m_info.format != VK_FORMAT_UNDEFINED)
m_bufferView = createBufferView(m_bufferSlice); m_bufferView = createBufferView(m_bufferSlice);
if (!device->features().khrMaintenance5.maintenance5)
m_usage = 0;
} }
@ -266,12 +270,18 @@ namespace dxvk {
VkBufferView DxvkBufferView::createBufferView( VkBufferView DxvkBufferView::createBufferView(
const DxvkBufferSliceHandle& slice) { const DxvkBufferSliceHandle& slice) {
VkBufferUsageFlags2CreateInfoKHR viewFlags = { VK_STRUCTURE_TYPE_BUFFER_USAGE_FLAGS_2_CREATE_INFO_KHR };
viewFlags.usage = m_usage;
VkBufferViewCreateInfo viewInfo = { VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO }; VkBufferViewCreateInfo viewInfo = { VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO };
viewInfo.buffer = slice.handle; viewInfo.buffer = slice.handle;
viewInfo.format = m_info.format; viewInfo.format = m_info.format;
viewInfo.offset = slice.offset; viewInfo.offset = slice.offset;
viewInfo.range = slice.length; viewInfo.range = slice.length;
if (!m_usage)
viewInfo.pNext = &viewFlags;
VkBufferView result = VK_NULL_HANDLE; VkBufferView result = VK_NULL_HANDLE;
if (m_vkd->vkCreateBufferView(m_vkd->device(), if (m_vkd->vkCreateBufferView(m_vkd->device(),

View File

@ -52,6 +52,9 @@ namespace dxvk {
/// Size of the buffer region to include in the view /// Size of the buffer region to include in the view
VkDeviceSize rangeLength; VkDeviceSize rangeLength;
/// Buffer view usage flags
VkBufferUsageFlags usage;
}; };
@ -577,7 +580,7 @@ namespace dxvk {
public: public:
DxvkBufferView( DxvkBufferView(
const Rc<vk::DeviceFn>& vkd, DxvkDevice* device,
const Rc<DxvkBuffer>& buffer, const Rc<DxvkBuffer>& buffer,
const DxvkBufferViewCreateInfo& info); const DxvkBufferViewCreateInfo& info);
@ -676,6 +679,7 @@ namespace dxvk {
Rc<vk::DeviceFn> m_vkd; Rc<vk::DeviceFn> m_vkd;
DxvkBufferViewCreateInfo m_info; DxvkBufferViewCreateInfo m_info;
Rc<DxvkBuffer> m_buffer; Rc<DxvkBuffer> m_buffer;
VkBufferUsageFlags m_usage;
DxvkBufferSliceHandle m_bufferSlice; DxvkBufferSliceHandle m_bufferSlice;
VkBufferView m_bufferView; VkBufferView m_bufferView;

View File

@ -873,10 +873,12 @@ namespace dxvk {
viewInfo.format = format; viewInfo.format = format;
viewInfo.rangeOffset = dstBufferOffset; viewInfo.rangeOffset = dstBufferOffset;
viewInfo.rangeLength = dstBufferSlice.length; viewInfo.rangeLength = dstBufferSlice.length;
viewInfo.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
Rc<DxvkBufferView> dstView = m_device->createBufferView(dstBuffer, viewInfo); Rc<DxvkBufferView> dstView = m_device->createBufferView(dstBuffer, viewInfo);
viewInfo.rangeOffset = srcBufferOffset; viewInfo.rangeOffset = srcBufferOffset;
viewInfo.rangeLength = srcBufferSlice.length; viewInfo.rangeLength = srcBufferSlice.length;
viewInfo.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Rc<DxvkBufferView> srcView; Rc<DxvkBufferView> srcView;
if (srcBuffer == dstBuffer if (srcBuffer == dstBuffer
@ -1066,11 +1068,13 @@ namespace dxvk {
tmpViewInfoD.format = dataFormatD; tmpViewInfoD.format = dataFormatD;
tmpViewInfoD.rangeOffset = 0; tmpViewInfoD.rangeOffset = 0;
tmpViewInfoD.rangeLength = dataSizeD; tmpViewInfoD.rangeLength = dataSizeD;
tmpViewInfoD.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
DxvkBufferViewCreateInfo tmpViewInfoS; DxvkBufferViewCreateInfo tmpViewInfoS;
tmpViewInfoS.format = dataFormatS; tmpViewInfoS.format = dataFormatS;
tmpViewInfoS.rangeOffset = dataSizeD; tmpViewInfoS.rangeOffset = dataSizeD;
tmpViewInfoS.rangeLength = dataSizeS; tmpViewInfoS.rangeLength = dataSizeS;
tmpViewInfoS.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
auto tmpBufferViewD = m_device->createBufferView(tmpBuffer, tmpViewInfoD); auto tmpBufferViewD = m_device->createBufferView(tmpBuffer, tmpViewInfoD);
auto tmpBufferViewS = m_device->createBufferView(tmpBuffer, tmpViewInfoS); auto tmpBufferViewS = m_device->createBufferView(tmpBuffer, tmpViewInfoS);

View File

@ -167,7 +167,7 @@ namespace dxvk {
Rc<DxvkBufferView> DxvkDevice::createBufferView( Rc<DxvkBufferView> DxvkDevice::createBufferView(
const Rc<DxvkBuffer>& buffer, const Rc<DxvkBuffer>& buffer,
const DxvkBufferViewCreateInfo& createInfo) { const DxvkBufferViewCreateInfo& createInfo) {
return new DxvkBufferView(m_vkd, buffer, createInfo); return new DxvkBufferView(this, buffer, createInfo);
} }

View File

@ -254,6 +254,7 @@ namespace dxvk::hud {
info.format = VK_FORMAT_R8_UINT; info.format = VK_FORMAT_R8_UINT;
info.rangeOffset = 0; info.rangeOffset = 0;
info.rangeLength = m_dataBuffer->info().size; info.rangeLength = m_dataBuffer->info().size;
info.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
return m_device->createBufferView(m_dataBuffer, info); return m_device->createBufferView(m_dataBuffer, info);
} }
@ -278,6 +279,7 @@ namespace dxvk::hud {
info.format = VK_FORMAT_UNDEFINED; info.format = VK_FORMAT_UNDEFINED;
info.rangeOffset = 0; info.rangeOffset = 0;
info.rangeLength = m_fontBuffer->info().size; info.rangeLength = m_fontBuffer->info().size;
info.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
return m_device->createBufferView(m_fontBuffer, info); return m_device->createBufferView(m_fontBuffer, info);
} }