radv: Override the uniform buffer offset alignment for World War Z.
authorBas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Thu, 30 Jul 2020 00:49:33 +0000 (02:49 +0200)
committerBas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Tue, 18 Aug 2020 18:31:15 +0000 (20:31 +0200)
Game does the equivalent of a

ALIGN(..., minUniformBufferOffsetAlignment >> 4)

which breaks when said alignment is <16 with a SIGFPE.

CC: <mesa-stable@lists.freedesktop.org>
Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6120>

src/amd/vulkan/radv_device.c
src/util/00-mesa-defaults.conf
src/util/driconf.h

index 0f40db2cceb468ae16012a2904401e49e42b4b4a..dda535d553822d4468f9bb6c1dda5f55e2c2c24e 100644 (file)
@@ -615,6 +615,7 @@ DRI_CONF_BEGIN
                DRI_CONF_RADV_REPORT_LLVM9_VERSION_STRING("false")
                DRI_CONF_RADV_ENABLE_MRT_OUTPUT_NAN_FIXUP("false")
                DRI_CONF_RADV_NO_DYNAMIC_BOUNDS("false")
+               DRI_CONF_RADV_OVERRIDE_UNIFORM_OFFSET_ALIGNMENT(0)
        DRI_CONF_SECTION_END
 
        DRI_CONF_SECTION_DEBUG
@@ -1445,6 +1446,21 @@ radv_max_descriptor_set_size()
                   64 /* storage image */);
 }
 
+static uint32_t
+radv_uniform_buffer_offset_alignment(const struct radv_physical_device *pdevice)
+{
+       uint32_t uniform_offset_alignment = driQueryOptioni(&pdevice->instance->dri_options,
+                                                          "radv_override_uniform_offset_alignment");
+       if (!util_is_power_of_two_or_zero(uniform_offset_alignment)) {
+               fprintf(stderr, "ERROR: invalid radv_override_uniform_offset_alignment setting %d:"
+                               "not a power of two\n", uniform_offset_alignment);
+               uniform_offset_alignment = 0;
+       }
+
+       /* Take at least the hardware limit. */
+       return MAX2(uniform_offset_alignment, 4);
+}
+
 void radv_GetPhysicalDeviceProperties(
        VkPhysicalDevice                            physicalDevice,
        VkPhysicalDeviceProperties*                 pProperties)
@@ -1527,7 +1543,7 @@ void radv_GetPhysicalDeviceProperties(
                .viewportSubPixelBits                     = 8,
                .minMemoryMapAlignment                    = 4096, /* A page */
                .minTexelBufferOffsetAlignment            = 4,
-               .minUniformBufferOffsetAlignment          = 4,
+               .minUniformBufferOffsetAlignment          = radv_uniform_buffer_offset_alignment(pdevice),
                .minStorageBufferOffsetAlignment          = 4,
                .minTexelOffset                           = -32,
                .maxTexelOffset                           = 31,
index 2a1dd8f26fee217e29b6e24adc2f2a0ec1405a98..5cd65ccf18d5be11939af1263d6f0627c734eae8 100644 (file)
@@ -733,5 +733,9 @@ TODO: document the other workarounds.
         <application name="Path of Exile (32-bit)" executable="PathOfExile.exe">
             <option name="radv_no_dynamic_bounds" value="true" />
         </application>
+
+       <application name="World War Z" application_name_match="WWZ">
+            <option name="radv_override_uniform_offset_alignment" value="16" />
+        </application>
     </device>
 </driconf>
index c922e94b9f9461b7f9bf1069181dbf4ed765f506..d7c734464cc698286ec11a0a37988266269f1a1f 100644 (file)
@@ -508,4 +508,8 @@ DRI_CONF_OPT_BEGIN_B(radv_no_dynamic_bounds, def) \
         DRI_CONF_DESC("Disabling bounds checking for dynamic buffer descriptors") \
 DRI_CONF_OPT_END
 
+#define DRI_CONF_RADV_OVERRIDE_UNIFORM_OFFSET_ALIGNMENT(def) \
+DRI_CONF_OPT_BEGIN_V(radv_override_uniform_offset_alignment, int, def, "0:128") \
+        DRI_CONF_DESC("Override the minUniformBufferOffsetAlignment exposed to the application. (0 = default)") \
+DRI_CONF_OPT_END
 #endif