From 0f7c23c02286412eb5c229d8331e881f67983124 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Wed, 5 Jun 2019 01:09:39 +0200 Subject: [PATCH] [dxbc] Always use raw storage buffers if alignment requirements are met --- src/dxbc/dxbc_compiler.cpp | 20 +++++++++++++++----- src/dxbc/dxbc_options.cpp | 1 + src/dxbc/dxbc_options.h | 3 +++ 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/dxbc/dxbc_compiler.cpp b/src/dxbc/dxbc_compiler.cpp index dd1b8588..4c68ca9f 100644 --- a/src/dxbc/dxbc_compiler.cpp +++ b/src/dxbc/dxbc_compiler.cpp @@ -1076,7 +1076,11 @@ namespace dxvk { ? computeUavBinding(m_programInfo.type(), registerId) : computeSrvBinding(m_programInfo.type(), registerId); - if (m_moduleInfo.options.useRawSsbo) { + // Test whether we should use a raw SSBO for this resource + bool useRawSsbo = m_moduleInfo.options.useRawSsbo + && m_moduleInfo.options.minSsboAlignment <= resAlign; + + if (useRawSsbo) { uint32_t elemType = getScalarTypeId(DxbcScalarType::Uint32); uint32_t arrayType = m_module.defRuntimeArrayTypeUnique(elemType); uint32_t structType = m_module.defStructTypeUnique(1, &arrayType); @@ -1159,7 +1163,7 @@ namespace dxvk { // Store descriptor info for the shader interface DxvkResourceSlot resource; resource.slot = bindingId; - resource.type = m_moduleInfo.options.useRawSsbo + resource.type = useRawSsbo ? VK_DESCRIPTOR_TYPE_STORAGE_BUFFER : (isUav ? VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER @@ -2693,7 +2697,8 @@ namespace dxvk { const DxbcBufferInfo bufferInfo = getBufferInfo(ins.src[0]); bool isSsbo = m_moduleInfo.options.useRawSsbo - && bufferInfo.type != DxbcResourceType::Typed; + && m_moduleInfo.options.minSsboAlignment <= bufferInfo.align + && bufferInfo.type != DxbcResourceType::Typed; // We'll store this as a scalar unsigned integer DxbcRegisterValue result = isSsbo @@ -4835,6 +4840,7 @@ namespace dxvk { // of obtaining the final pointer are used. bool isTgsm = operand.type == DxbcOperandType::ThreadGroupSharedMemory; bool isSsbo = m_moduleInfo.options.useRawSsbo + && m_moduleInfo.options.minSsboAlignment <= resourceInfo.align && resourceInfo.type != DxbcResourceType::Typed && !isTgsm; @@ -4899,7 +4905,9 @@ namespace dxvk { // Shared memory is the only type of buffer that // is not accessed through a texel buffer view bool isTgsm = operand.type == DxbcOperandType::ThreadGroupSharedMemory; - bool isSsbo = m_moduleInfo.options.useRawSsbo && !isTgsm; + bool isSsbo = m_moduleInfo.options.useRawSsbo + && m_moduleInfo.options.minSsboAlignment <= bufferInfo.align + && !isTgsm; // Common types and IDs used while loading the data uint32_t bufferId = isTgsm || isSsbo ? 0 : m_module.opLoad(bufferInfo.typeId, bufferInfo.varId); @@ -4985,7 +4993,9 @@ namespace dxvk { // Thread Group Shared Memory is not accessed through a texel buffer view bool isTgsm = operand.type == DxbcOperandType::ThreadGroupSharedMemory; - bool isSsbo = m_moduleInfo.options.useRawSsbo && !isTgsm; + bool isSsbo = m_moduleInfo.options.useRawSsbo + && m_moduleInfo.options.minSsboAlignment <= bufferInfo.align + && !isTgsm; // Perform UAV writes only if the UAV is bound and if there // is nothing else preventing us from writing to it. diff --git a/src/dxbc/dxbc_options.cpp b/src/dxbc/dxbc_options.cpp index 6d35400b..e11794ed 100644 --- a/src/dxbc/dxbc_options.cpp +++ b/src/dxbc/dxbc_options.cpp @@ -32,6 +32,7 @@ namespace dxvk { = (devInfo.core.properties.limits.minStorageBufferOffsetAlignment <= sizeof(uint32_t)); useSdivForBufferIndex = adapter->matchesDriver(DxvkGpuVendor::Nvidia, VK_DRIVER_ID_NVIDIA_PROPRIETARY_KHR, 0, 0); + minSsboAlignment = devInfo.core.properties.limits.minStorageBufferOffsetAlignment; strictDivision = options.strictDivision; zeroInitWorkgroupMemory = options.zeroInitWorkgroupMemory; diff --git a/src/dxbc/dxbc_options.h b/src/dxbc/dxbc_options.h index 5846756b..a1e6bcda 100644 --- a/src/dxbc/dxbc_options.h +++ b/src/dxbc/dxbc_options.h @@ -42,6 +42,9 @@ namespace dxvk { /// Clear thread-group shared memory to zero bool zeroInitWorkgroupMemory = false; + + /// Minimum storage buffer alignment + VkDeviceSize minSsboAlignment = 0; }; } \ No newline at end of file