st: Lower uniforms in st in the !PIPE_CAP_PACKED_UNIFORMS case as well.
authorEric Anholt <eric@anholt.net>
Mon, 8 Apr 2019 23:32:01 +0000 (16:32 -0700)
committerEric Anholt <eric@anholt.net>
Wed, 10 Apr 2019 18:44:20 +0000 (11:44 -0700)
PIPE_CAP_PACKED_UNIFORMS conflates several things: Lowering uniforms i/o
at the st level instead of the backend, packing uniforms with no padding
at all, and lowering to UBOs.

Requiring backends to lower uniforms i/o for !PIPE_CAP_PACKED_UNIFORMS
leads to the driver needing to either link against the type size function
in mesa/st, or duplicating it in the backend.  Given that all backends
want this lower-io as far as I can tell, just move it to mesa/st to
resolve the link issue and avoid the driver author needing to understand
st's uniforms layout.

Incidentally, fixes uniform layout failures in nouveau in:

dEQP-GLES2.functional.shaders.struct.uniform.sampler_nested_fragment
dEQP-GLES2.functional.shaders.struct.uniform.sampler_nested_vertex
dEQP-GLES2.functional.shaders.struct.uniform.sampler_array_fragment
dEQP-GLES2.functional.shaders.struct.uniform.sampler_array_vertex

and I think in Lima as well.

v2: fix indents

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
src/gallium/drivers/panfrost/midgard/midgard_compile.c
src/gallium/drivers/v3d/v3d_program.c
src/gallium/drivers/vc4/vc4_program.c
src/mesa/state_tracker/st_glsl_to_nir.cpp
src/mesa/state_tracker/st_glsl_types.cpp
src/mesa/state_tracker/st_glsl_types.h
src/mesa/state_tracker/st_nir_builtins.c

index f91fa972246bef342e9880a5a4154c77e717ab04..8104d442f82c06ed700a232640ff91e1dd4a3b03 100644 (file)
@@ -3532,8 +3532,7 @@ midgard_compile_shader_nir(nir_shader *nir, midgard_program *program, bool is_bl
         NIR_PASS_V(nir, nir_lower_var_copies);
         NIR_PASS_V(nir, nir_lower_vars_to_ssa);
 
-        NIR_PASS_V(nir, nir_lower_io, nir_var_uniform, uniform_type_size, 0);
-        NIR_PASS_V(nir, nir_lower_io, nir_var_all & ~nir_var_uniform, glsl_type_size, 0);
+        NIR_PASS_V(nir, nir_lower_io, nir_var_all, glsl_type_size, 0);
 
         /* Append vertex epilogue before optimisation, so the epilogue itself
          * is optimised */
index b8da87c779777f36c3782be046d92abc696de840..e3515335502a237028627e0f0929444176b45c52 100644 (file)
@@ -36,7 +36,6 @@
 #include "compiler/v3d_compiler.h"
 #include "v3d_context.h"
 #include "broadcom/cle/v3d_packet_v33_pack.h"
-#include "mesa/state_tracker/st_glsl_types.h"
 
 static struct v3d_compiled_shader *
 v3d_get_compiled_shader(struct v3d_context *v3d, struct v3d_key *key);
@@ -175,12 +174,6 @@ type_size(const struct glsl_type *type)
         return glsl_count_attribute_slots(type, false);
 }
 
-static int
-uniforms_type_size(const struct glsl_type *type)
-{
-        return st_glsl_storage_type_size(type, false);
-}
-
 /**
  * Precompiles a shader variant at shader state creation time if
  * V3D_DEBUG=precompile is set.  Used for shader-db
@@ -262,10 +255,6 @@ v3d_shader_state_create(struct pipe_context *pctx,
                  * creation.
                  */
                 s = cso->ir.nir;
-
-                NIR_PASS_V(s, nir_lower_io, nir_var_uniform,
-                           uniforms_type_size,
-                           (nir_lower_io_options)0);
         } else {
                 assert(cso->type == PIPE_SHADER_IR_TGSI);
 
index 91a99d0574b5b8dce57ee11ac1d09fd8756151f6..135d4bc7198c1c1577756c827a3acb81414d7749 100644 (file)
@@ -2487,10 +2487,6 @@ vc4_shader_state_create(struct pipe_context *pctx,
                  * creation.
                  */
                 s = cso->ir.nir;
-
-                NIR_PASS_V(s, nir_lower_io, nir_var_uniform,
-                           uniforms_type_size,
-                           (nir_lower_io_options)0);
        } else {
                 assert(cso->type == PIPE_SHADER_IR_TGSI);
 
@@ -2503,8 +2499,7 @@ vc4_shader_state_create(struct pipe_context *pctx,
                 s = tgsi_to_nir(cso->tokens, pctx->screen);
         }
 
-        NIR_PASS_V(s, nir_lower_io, nir_var_all & ~nir_var_uniform,
-                   type_size,
+        NIR_PASS_V(s, nir_lower_io, nir_var_all, type_size,
                    (nir_lower_io_options)0);
 
         NIR_PASS_V(s, nir_lower_regs_to_ssa);
index fb10869c9f968f5660f267f9f0adf030fb7698d3..bb693dc70f75c8f0dae25dc68628d09641970f88 100644 (file)
@@ -945,6 +945,9 @@ st_finalize_nir(struct st_context *st, struct gl_program *prog,
       NIR_PASS_V(nir, nir_lower_io, nir_var_uniform, st_glsl_type_dword_size,
                  (nir_lower_io_options)0);
       NIR_PASS_V(nir, nir_lower_uniforms_to_ubo, 4);
+   } else {
+      NIR_PASS_V(nir, nir_lower_io, nir_var_uniform, st_glsl_uniforms_type_size,
+                 (nir_lower_io_options)0);
    }
 
    st_nir_lower_samplers(screen, nir, shader_program, prog);
index 42d4e9cef2d9fd1a21f59e45c429da7b7b8dfdfa..277b91c4a5c060de64816c54de94d05b2ea50337 100644 (file)
@@ -155,3 +155,14 @@ st_glsl_type_dword_size(const struct glsl_type *type)
 
    return 0;
 }
+
+/**
+ * Returns the type size of uniforms when !PIPE_CAP_PACKED_UNIFORMS -- each
+ * value or array element is aligned to a vec4 offset and expanded out to a
+ * vec4.
+ */
+int
+st_glsl_uniforms_type_size(const struct glsl_type *type)
+{
+   return st_glsl_storage_type_size(type, false);
+}
index 16b31b684f38701752ed5cd0c952bbcb0ee1225c..e0aff12366a110d1e0ff24597f319979d7448fc6 100644 (file)
@@ -36,6 +36,8 @@ extern "C" {
 int st_glsl_storage_type_size(const struct glsl_type *type,
                               bool is_bindless);
 
+int st_glsl_uniforms_type_size(const struct glsl_type *type);
+
 int st_glsl_type_dword_size(const struct glsl_type *type);
 
 #ifdef __cplusplus
index 8ec320cbb9cd79c9a64caf297994069d074a7db1..01663b702ac23de996405268a7b6a98c5e13f4e3 100644 (file)
@@ -67,6 +67,9 @@ st_nir_finish_builtin_shader(struct st_context *st,
       NIR_PASS_V(nir, nir_lower_io, nir_var_uniform, st_glsl_type_dword_size,
                  (nir_lower_io_options)0);
       NIR_PASS_V(nir, nir_lower_uniforms_to_ubo, 4);
+   } else {
+      NIR_PASS_V(nir, nir_lower_io, nir_var_uniform, st_glsl_uniforms_type_size,
+                 (nir_lower_io_options)0);
    }
 
    struct pipe_shader_state state = {