radv: add a workaround for Monster Hunter World and LLVM 7&8
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>
Tue, 7 May 2019 14:09:46 +0000 (16:09 +0200)
committerSamuel Pitoiset <samuel.pitoiset@gmail.com>
Fri, 17 May 2019 09:41:19 +0000 (11:41 +0200)
The load/store optimizer pass doesn't handle WaW hazards correctly
and this is the root cause of the reflection issue with Monster
Hunter World. AFAIK, it's the only game that are affected by this
issue.

This is fixed with LLVM r361008, but we need a workaround for older
LLVM versions unfortunately.

Cc: "19.0" "19.1" <mesa-stable@lists.freedesktop.org>
Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
src/amd/common/ac_llvm_util.c
src/amd/common/ac_llvm_util.h
src/amd/vulkan/radv_debug.h
src/amd/vulkan/radv_device.c
src/amd/vulkan/radv_shader.c

index 69446863b95167b7435f3ca16240e28dab0e1cf5..6063411310b849adedcb761f94cb9bf76fc04013 100644 (file)
@@ -151,13 +151,14 @@ static LLVMTargetMachineRef ac_create_target_machine(enum radeon_family family,
        LLVMTargetRef target = ac_get_llvm_target(triple);
 
        snprintf(features, sizeof(features),
-                "+DumpCode,-fp32-denormals,+fp64-denormals%s%s%s%s%s",
+                "+DumpCode,-fp32-denormals,+fp64-denormals%s%s%s%s%s%s",
                 HAVE_LLVM >= 0x0800 ? "" : ",+vgpr-spilling",
                 tm_options & AC_TM_SISCHED ? ",+si-scheduler" : "",
                 tm_options & AC_TM_FORCE_ENABLE_XNACK ? ",+xnack" : "",
                 tm_options & AC_TM_FORCE_DISABLE_XNACK ? ",-xnack" : "",
-                tm_options & AC_TM_PROMOTE_ALLOCA_TO_SCRATCH ? ",-promote-alloca" : "");
-       
+                tm_options & AC_TM_PROMOTE_ALLOCA_TO_SCRATCH ? ",-promote-alloca" : "",
+                tm_options & AC_TM_NO_LOAD_STORE_OPT ? ",-load-store-opt" : "");
+
        LLVMTargetMachineRef tm = LLVMCreateTargetMachine(
                                     target,
                                     triple,
index 6d961c06f8a8b384b2aa1f88922ceb4f4e7137b5..ca00540da8063cc9e4586beb5406fc14b3f3f924 100644 (file)
@@ -65,6 +65,7 @@ enum ac_target_machine_options {
        AC_TM_CHECK_IR = (1 << 5),
        AC_TM_ENABLE_GLOBAL_ISEL = (1 << 6),
        AC_TM_CREATE_LOW_OPT = (1 << 7),
+       AC_TM_NO_LOAD_STORE_OPT = (1 << 8),
 };
 
 enum ac_float_mode {
index 17a2f3370c0889ec8af69ebb1d75c7996dcaff93..652a3b677d2f50db9e2b03ea3827ad9745731d54 100644 (file)
@@ -51,6 +51,7 @@ enum {
        RADV_DEBUG_CHECKIR           = 0x200000,
        RADV_DEBUG_NOTHREADLLVM      = 0x400000,
        RADV_DEBUG_NOBINNING         = 0x800000,
+       RADV_DEBUG_NO_LOAD_STORE_OPT = 0x1000000,
 };
 
 enum {
index c0e317a97e56277fcef0b8a39f4351439ae87649..4203074a4cdaf69529454af0fc99f4d91201604d 100644 (file)
@@ -464,6 +464,7 @@ static const struct debug_control radv_debug_options[] = {
        {"checkir", RADV_DEBUG_CHECKIR},
        {"nothreadllvm", RADV_DEBUG_NOTHREADLLVM},
        {"nobinning", RADV_DEBUG_NOBINNING},
+       {"noloadstoreopt", RADV_DEBUG_NO_LOAD_STORE_OPT},
        {NULL, 0}
 };
 
@@ -510,6 +511,13 @@ radv_handle_per_app_options(struct radv_instance *instance,
        } else if (!strcmp(name, "DOOM_VFR")) {
                /* Work around a Doom VFR game bug */
                instance->debug_flags |= RADV_DEBUG_NO_DYNAMIC_BOUNDS;
+       } else if (!strcmp(name, "MonsterHunterWorld.exe")) {
+               /* Workaround for a WaW hazard when LLVM moves/merges
+                * load/store memory operations.
+                * See https://reviews.llvm.org/D61313
+                */
+               if (HAVE_LLVM < 0x900)
+                       instance->debug_flags |= RADV_DEBUG_NO_LOAD_STORE_OPT;
        }
 }
 
index dfa50155c068f34e002ebd74277e9d2f0d4d37d7..c585bac860f03784a5f87d81947e782d8e6e44ca 100644 (file)
@@ -649,6 +649,8 @@ shader_variant_create(struct radv_device *device,
                tm_options |= AC_TM_SISCHED;
        if (options->check_ir)
                tm_options |= AC_TM_CHECK_IR;
+       if (device->instance->debug_flags & RADV_DEBUG_NO_LOAD_STORE_OPT)
+               tm_options |= AC_TM_NO_LOAD_STORE_OPT;
 
        thread_compiler = !(device->instance->debug_flags & RADV_DEBUG_NOTHREADLLVM);
        radv_init_llvm_once();