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

[d3d9] Don't set storage buffer usage unless necessary

This actually matters now to some degree.
This commit is contained in:
Philip Rebohle 2023-01-13 03:44:21 +01:00 committed by Philip Rebohle
parent d35bf455d9
commit 459758c6ff
3 changed files with 35 additions and 5 deletions

View File

@ -13,7 +13,7 @@ namespace dxvk {
DxsoProgramType ShaderStage, DxsoProgramType ShaderStage,
DxsoConstantBuffers BufferType, DxsoConstantBuffers BufferType,
VkDeviceSize Size) VkDeviceSize Size)
: D3D9ConstantBuffer(pDevice, GetShaderStage(ShaderStage), : D3D9ConstantBuffer(pDevice, getBufferUsage(pDevice, ShaderStage, BufferType), GetShaderStage(ShaderStage),
computeResourceSlotId(ShaderStage, DxsoBindingType::ConstantBuffer, BufferType), computeResourceSlotId(ShaderStage, DxsoBindingType::ConstantBuffer, BufferType),
Size) { Size) {
@ -22,11 +22,13 @@ namespace dxvk {
D3D9ConstantBuffer::D3D9ConstantBuffer( D3D9ConstantBuffer::D3D9ConstantBuffer(
D3D9DeviceEx* pDevice, D3D9DeviceEx* pDevice,
VkBufferUsageFlags Usage,
VkShaderStageFlags Stages, VkShaderStageFlags Stages,
uint32_t ResourceSlot, uint32_t ResourceSlot,
VkDeviceSize Size) VkDeviceSize Size)
: m_device (pDevice) : m_device (pDevice)
, m_binding (ResourceSlot) , m_binding (ResourceSlot)
, m_usage (Usage)
, m_stages (Stages) , m_stages (Stages)
, m_size (Size) , m_size (Size)
, m_align (getAlignment(pDevice->GetDXVKDevice())) { , m_align (getAlignment(pDevice->GetDXVKDevice())) {
@ -98,12 +100,15 @@ namespace dxvk {
// in the backend, so set both STORAGE and UNIFORM usage/access. // in the backend, so set both STORAGE and UNIFORM usage/access.
DxvkBufferCreateInfo bufferInfo; DxvkBufferCreateInfo bufferInfo;
bufferInfo.size = align(m_size, m_align); bufferInfo.size = align(m_size, m_align);
bufferInfo.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT bufferInfo.usage = m_usage;
| VK_BUFFER_USAGE_STORAGE_BUFFER_BIT; bufferInfo.access = 0;
bufferInfo.access = VK_ACCESS_UNIFORM_READ_BIT
| VK_ACCESS_SHADER_READ_BIT;
bufferInfo.stages = util::pipelineStages(m_stages); bufferInfo.stages = util::pipelineStages(m_stages);
if (m_usage & VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)
bufferInfo.access |= VK_ACCESS_UNIFORM_READ_BIT;
if (m_usage & VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)
bufferInfo.access |= VK_ACCESS_SHADER_READ_BIT;
VkMemoryPropertyFlags memoryFlags VkMemoryPropertyFlags memoryFlags
= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
| VK_MEMORY_PROPERTY_HOST_COHERENT_BIT; | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
@ -130,4 +135,21 @@ namespace dxvk {
device->properties().extRobustness2.robustUniformBufferAccessSizeAlignment); device->properties().extRobustness2.robustUniformBufferAccessSizeAlignment);
} }
VkBufferUsageFlags D3D9ConstantBuffer::getBufferUsage(
D3D9DeviceEx* pDevice,
DxsoProgramType ShaderStage,
DxsoConstantBuffers BufferType) {
VkBufferUsageFlags result = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
// We won't always need this, but the only buffer that
// this applies to is so large that it will not matter.
if (pDevice->CanSWVP()
&& ShaderStage == DxsoProgramType::VertexShader
&& BufferType == DxsoConstantBuffers::VSConstantBuffer)
result |= VK_BUFFER_USAGE_STORAGE_BUFFER_BIT;
return result;
}
} }

View File

@ -29,6 +29,7 @@ namespace dxvk {
D3D9ConstantBuffer( D3D9ConstantBuffer(
D3D9DeviceEx* pDevice, D3D9DeviceEx* pDevice,
VkBufferUsageFlags Usage,
VkShaderStageFlags Stages, VkShaderStageFlags Stages,
uint32_t ResourceSlot, uint32_t ResourceSlot,
VkDeviceSize Size); VkDeviceSize Size);
@ -66,6 +67,7 @@ namespace dxvk {
D3D9DeviceEx* m_device = nullptr; D3D9DeviceEx* m_device = nullptr;
uint32_t m_binding = 0u; uint32_t m_binding = 0u;
VkBufferUsageFlags m_usage = 0u;
VkShaderStageFlags m_stages = 0u; VkShaderStageFlags m_stages = 0u;
VkDeviceSize m_size = 0ull; VkDeviceSize m_size = 0ull;
VkDeviceSize m_align = 0ull; VkDeviceSize m_align = 0ull;
@ -78,6 +80,11 @@ namespace dxvk {
VkDeviceSize getAlignment(const Rc<DxvkDevice>& device) const; VkDeviceSize getAlignment(const Rc<DxvkDevice>& device) const;
static VkBufferUsageFlags getBufferUsage(
D3D9DeviceEx* pDevice,
DxsoProgramType ShaderStage,
DxsoConstantBuffers BufferType);
}; };
} }

View File

@ -5021,6 +5021,7 @@ namespace dxvk {
if (m_usingGraphicsPipelines) { if (m_usingGraphicsPipelines) {
m_specBuffer = D3D9ConstantBuffer(this, m_specBuffer = D3D9ConstantBuffer(this,
VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT,
getSpecConstantBufferSlot(), getSpecConstantBufferSlot(),
sizeof(D3D9SpecializationInfo)); sizeof(D3D9SpecializationInfo));