Mesa (master): gallium: Plumb through a way to disable GLSL const lowering

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Sep 5 11:48:58 UTC 2019


Module: Mesa
Branch: master
Commit: 2af431cf7fe9303bbfbd719e4612f00043583f40
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=2af431cf7fe9303bbfbd719e4612f00043583f40

Author: Connor Abbott <cwabbott0 at gmail.com>
Date:   Fri Aug 30 17:57:18 2019 +0200

gallium: Plumb through a way to disable GLSL const lowering

For radeonsi, we will prefer the NIR pass as it'll generate better code
(some index calculation and a single load vs. a load, then index
calculation, then another load) and oftentimes NIR optimization can kick
in and make all the access indices constant.

Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
Reviewed-by: Timothy Arceri <tarceri at itsqueeze.com>

---

 src/compiler/glsl/linker.cpp           | 3 ++-
 src/gallium/auxiliary/util/u_screen.c  | 4 ++++
 src/gallium/docs/source/screen.rst     | 4 ++++
 src/gallium/include/pipe/p_defines.h   | 1 +
 src/mesa/main/context.c                | 2 ++
 src/mesa/main/mtypes.h                 | 5 +++++
 src/mesa/state_tracker/st_extensions.c | 2 ++
 7 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/src/compiler/glsl/linker.cpp b/src/compiler/glsl/linker.cpp
index 281d59d12a5..c52c665a4c2 100644
--- a/src/compiler/glsl/linker.cpp
+++ b/src/compiler/glsl/linker.cpp
@@ -5211,7 +5211,8 @@ link_shaders(struct gl_context *ctx, struct gl_shader_program *prog)
       linker_optimisation_loop(ctx, prog->_LinkedShaders[i]->ir, i);
 
       /* Call opts after lowering const arrays to copy propagate things. */
-      if (lower_const_arrays_to_uniforms(prog->_LinkedShaders[i]->ir, i))
+      if (ctx->Const.GLSLLowerConstArrays &&
+          lower_const_arrays_to_uniforms(prog->_LinkedShaders[i]->ir, i))
          linker_optimisation_loop(ctx, prog->_LinkedShaders[i]->ir, i);
 
       propagate_invariance(prog->_LinkedShaders[i]->ir);
diff --git a/src/gallium/auxiliary/util/u_screen.c b/src/gallium/auxiliary/util/u_screen.c
index 88f4945e755..879e49d8d5b 100644
--- a/src/gallium/auxiliary/util/u_screen.c
+++ b/src/gallium/auxiliary/util/u_screen.c
@@ -296,6 +296,10 @@ u_pipe_screen_get_param_defaults(struct pipe_screen *pscreen,
        */
       return 1;
 
+   case PIPE_CAP_PREFER_IMM_ARRAYS_AS_CONSTBUF:
+      /* Don't unset this unless your driver can do better */
+      return 1;
+
    case PIPE_CAP_POST_DEPTH_COVERAGE:
    case PIPE_CAP_BINDLESS_TEXTURE:
    case PIPE_CAP_NIR_SAMPLERS_AS_DEREF:
diff --git a/src/gallium/docs/source/screen.rst b/src/gallium/docs/source/screen.rst
index d149a2f4c9f..1df04b6c3bf 100644
--- a/src/gallium/docs/source/screen.rst
+++ b/src/gallium/docs/source/screen.rst
@@ -548,6 +548,10 @@ The integer capabilities:
   types with texture functions having interaction with LOD of texture lookup.
 * ``PIPE_CAP_SHADER_SAMPLES_IDENTICAL``: True if the driver supports a shader query to tell whether all samples of a multisampled surface are definitely identical.
 * ``PIPE_CAP_TGSI_ATOMINC_WRAP``: Atomic increment/decrement + wrap around are supported.
+* ``PIPE_CAP_PREFER_IMM_ARRAYS_AS_CONSTBUF``: True if the state tracker should
+  turn arrays whose contents can be deduced at compile time into constant
+  buffer loads, or false if the driver can handle such arrays itself in a more
+  efficient manner.
 
 .. _pipe_capf:
 
diff --git a/src/gallium/include/pipe/p_defines.h b/src/gallium/include/pipe/p_defines.h
index 808c2b8cfaf..8530994d9ad 100644
--- a/src/gallium/include/pipe/p_defines.h
+++ b/src/gallium/include/pipe/p_defines.h
@@ -897,6 +897,7 @@ enum pipe_cap
    PIPE_CAP_TEXTURE_SHADOW_LOD,
    PIPE_CAP_SHADER_SAMPLES_IDENTICAL,
    PIPE_CAP_TGSI_ATOMINC_WRAP,
+   PIPE_CAP_PREFER_IMM_ARRAYS_AS_CONSTBUF,
 };
 
 /**
diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c
index c68be8d01e5..d77647ccda9 100644
--- a/src/mesa/main/context.c
+++ b/src/mesa/main/context.c
@@ -633,6 +633,8 @@ _mesa_init_constants(struct gl_constants *consts, gl_api api)
    consts->GLSLVersion = api == API_OPENGL_CORE ? 130 : 120;
    consts->GLSLVersionCompat = consts->GLSLVersion;
 
+   consts->GLSLLowerConstArrays = true;
+
    /* Assume that if GLSL 1.30+ (or GLSL ES 3.00+) is supported that
     * gl_VertexID is implemented using a native hardware register with OpenGL
     * semantics.
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index b740671559b..f035287ac7e 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -3929,6 +3929,11 @@ struct gl_constants
    bool GLSLOptimizeConservatively;
 
    /**
+    * Whether to call lower_const_arrays_to_uniforms() during linking.
+    */
+   bool GLSLLowerConstArrays;
+
+   /**
     * True if gl_TessLevelInner/Outer[] in the TES should be inputs
     * (otherwise, they're system values).
     */
diff --git a/src/mesa/state_tracker/st_extensions.c b/src/mesa/state_tracker/st_extensions.c
index 50471d63f2b..4da6e559ed5 100644
--- a/src/mesa/state_tracker/st_extensions.c
+++ b/src/mesa/state_tracker/st_extensions.c
@@ -344,6 +344,8 @@ void st_init_limits(struct pipe_screen *screen,
 
    c->GLSLOptimizeConservatively =
       screen->get_param(screen, PIPE_CAP_GLSL_OPTIMIZE_CONSERVATIVELY);
+   c->GLSLLowerConstArrays =
+      screen->get_param(screen, PIPE_CAP_PREFER_IMM_ARRAYS_AS_CONSTBUF);
    c->GLSLTessLevelsAsInputs =
       screen->get_param(screen, PIPE_CAP_GLSL_TESS_LEVELS_AS_INPUTS);
    c->LowerTessLevel =




More information about the mesa-commit mailing list