From d755b18ccbed7c75835c65d9c7c3e7ed0a0ee683 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Wed, 5 Jun 2019 01:28:29 +0200 Subject: [PATCH] [dxbc] Repurpose useRawSsbo option Basically, abuse the minSsboAlignment property to convince the compiler to always/never emit raw SSBOs for raw and structured buffers, and use the actual device limit by default. --- src/dxbc/dxbc_compiler.cpp | 15 +++++---------- src/dxbc/dxbc_options.cpp | 10 ++++++---- src/dxbc/dxbc_options.h | 4 ---- tests/dxbc/test_dxbc_compiler.cpp | 2 +- 4 files changed, 12 insertions(+), 19 deletions(-) diff --git a/src/dxbc/dxbc_compiler.cpp b/src/dxbc/dxbc_compiler.cpp index 4c68ca9fb..563665be8 100644 --- a/src/dxbc/dxbc_compiler.cpp +++ b/src/dxbc/dxbc_compiler.cpp @@ -1077,8 +1077,7 @@ namespace dxvk { : computeSrvBinding(m_programInfo.type(), registerId); // Test whether we should use a raw SSBO for this resource - bool useRawSsbo = m_moduleInfo.options.useRawSsbo - && m_moduleInfo.options.minSsboAlignment <= resAlign; + bool useRawSsbo = m_moduleInfo.options.minSsboAlignment <= resAlign; if (useRawSsbo) { uint32_t elemType = getScalarTypeId(DxbcScalarType::Uint32); @@ -2696,8 +2695,7 @@ namespace dxvk { // (src0) The buffer register to query const DxbcBufferInfo bufferInfo = getBufferInfo(ins.src[0]); - bool isSsbo = m_moduleInfo.options.useRawSsbo - && m_moduleInfo.options.minSsboAlignment <= bufferInfo.align + bool isSsbo = m_moduleInfo.options.minSsboAlignment <= bufferInfo.align && bufferInfo.type != DxbcResourceType::Typed; // We'll store this as a scalar unsigned integer @@ -4839,8 +4837,7 @@ namespace dxvk { // For UAVs and shared memory, different methods // 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 + bool isSsbo = m_moduleInfo.options.minSsboAlignment <= resourceInfo.align && resourceInfo.type != DxbcResourceType::Typed && !isTgsm; @@ -4905,8 +4902,7 @@ 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 - && m_moduleInfo.options.minSsboAlignment <= bufferInfo.align + bool isSsbo = m_moduleInfo.options.minSsboAlignment <= bufferInfo.align && !isTgsm; // Common types and IDs used while loading the data @@ -4993,8 +4989,7 @@ 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 - && m_moduleInfo.options.minSsboAlignment <= bufferInfo.align + bool isSsbo = m_moduleInfo.options.minSsboAlignment <= bufferInfo.align && !isTgsm; // Perform UAV writes only if the UAV is bound and if there diff --git a/src/dxbc/dxbc_options.cpp b/src/dxbc/dxbc_options.cpp index e11794ed5..52da49eb7 100644 --- a/src/dxbc/dxbc_options.cpp +++ b/src/dxbc/dxbc_options.cpp @@ -28,11 +28,14 @@ namespace dxvk { = (devInfo.coreSubgroup.subgroupSize >= 4) && (devInfo.coreSubgroup.supportedStages & VK_SHADER_STAGE_FRAGMENT_BIT) && (devInfo.coreSubgroup.supportedOperations & VK_SUBGROUP_FEATURE_BALLOT_BIT); - useRawSsbo - = (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; + + switch (device->config().useRawSsbo) { + case Tristate::Auto: minSsboAlignment = devInfo.core.properties.limits.minStorageBufferOffsetAlignment; break; + case Tristate::True: minSsboAlignment = 4u; + case Tristate::False: minSsboAlignment = ~0u; + } strictDivision = options.strictDivision; zeroInitWorkgroupMemory = options.zeroInitWorkgroupMemory; @@ -48,7 +51,6 @@ namespace dxvk { // Apply shader-related options applyTristate(useSubgroupOpsForEarlyDiscard, device->config().useEarlyDiscard); - applyTristate(useRawSsbo, device->config().useRawSsbo); } } \ No newline at end of file diff --git a/src/dxbc/dxbc_options.h b/src/dxbc/dxbc_options.h index a1e6bcda7..7451e179f 100644 --- a/src/dxbc/dxbc_options.h +++ b/src/dxbc/dxbc_options.h @@ -25,10 +25,6 @@ namespace dxvk { /// shader invocations if derivatives remain valid. bool useSubgroupOpsForEarlyDiscard = false; - /// Use SSBOs instead of texel buffers - /// for raw and structured buffers. - bool useRawSsbo = false; - /// Use SDiv instead of SHR to converte byte offsets to /// dword offsets. Fixes RE2 and DMC5 on Nvidia drivers. bool useSdivForBufferIndex = false; diff --git a/tests/dxbc/test_dxbc_compiler.cpp b/tests/dxbc/test_dxbc_compiler.cpp index d943c8dec..d6983ea86 100644 --- a/tests/dxbc/test_dxbc_compiler.cpp +++ b/tests/dxbc/test_dxbc_compiler.cpp @@ -44,7 +44,7 @@ int WINAPI WinMain(HINSTANCE hInstance, DxbcModuleInfo moduleInfo; moduleInfo.options.useSubgroupOpsForAtomicCounters = true; moduleInfo.options.useSubgroupOpsForEarlyDiscard = true; - moduleInfo.options.useRawSsbo = true; + moduleInfo.options.minSsboAlignment = 4; moduleInfo.xfb = nullptr; Rc shader = module.compile(moduleInfo, ifileName);