[Mesa-dev] [PATCH v2 9/9] anv, intel: Enable nir_opt_large_constants for Vulkan

Jason Ekstrand jason at jlekstrand.net
Sat Jun 30 00:13:57 UTC 2018


According to RenderDoc, this shaves 99.6% of the run time off of the
ambient occlusion pass in Skyrim Special Edition when running under DXVK
and shaves 92% off the runtime for a reasonably representative frame.
When running the actual game, Skyrim goes from being a slide-show to a
very stable and playable framerate on my SKL GT4e machine.
---
 src/intel/compiler/brw_compiler.h | 6 ++++++
 src/intel/compiler/brw_nir.c      | 7 +++++++
 src/intel/vulkan/anv_device.c     | 1 +
 3 files changed, 14 insertions(+)

diff --git a/src/intel/compiler/brw_compiler.h b/src/intel/compiler/brw_compiler.h
index 2f745d92745..9dfcfcc0115 100644
--- a/src/intel/compiler/brw_compiler.h
+++ b/src/intel/compiler/brw_compiler.h
@@ -112,6 +112,12 @@ struct brw_compiler {
     * will attempt to push everything.
     */
    bool supports_pull_constants;
+
+   /**
+    * Whether or not the driver supports NIR shader constants.  This controls
+    * whether nir_opt_large_constants will be run.
+    */
+   bool supports_shader_constants;
 };
 
 /**
diff --git a/src/intel/compiler/brw_nir.c b/src/intel/compiler/brw_nir.c
index dfeea73b06a..f4aee3d41ee 100644
--- a/src/intel/compiler/brw_nir.c
+++ b/src/intel/compiler/brw_nir.c
@@ -664,6 +664,13 @@ brw_preprocess_nir(const struct brw_compiler *compiler, nir_shader *nir)
 
    nir = brw_nir_optimize(nir, compiler, is_scalar);
 
+   /* This needs to be run after the first optimization pass but before we
+    * lower indirect derefs away
+    */
+   if (compiler->supports_shader_constants) {
+      OPT(nir_opt_large_constants, NULL, 32);
+   }
+
    nir_lower_bit_size(nir, lower_bit_size_callback, NULL);
 
    if (is_scalar) {
diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c
index b3d30675b1e..077f5c16e46 100644
--- a/src/intel/vulkan/anv_device.c
+++ b/src/intel/vulkan/anv_device.c
@@ -434,6 +434,7 @@ anv_physical_device_init(struct anv_physical_device *device,
    device->compiler->supports_pull_constants = false;
    device->compiler->constant_buffer_0_is_relative =
       device->info.gen < 8 || !device->has_context_isolation;
+   device->compiler->supports_shader_constants = true;
 
    isl_device_init(&device->isl_dev, &device->info, swizzled);
 
-- 
2.17.1



More information about the mesa-dev mailing list