[Mesa-dev] [PATCH 2/2] mesa/st: only do scalar lowerings if driver benefits
Christian Gmeiner
christian.gmeiner at gmail.com
Thu Jun 7 19:32:38 UTC 2018
As not every (upcoming) backend compiler is happy with
nir_lower_xxx_to_scalar lowerings do them only if the backend
is scalar (and not vec4) based.
Signed-off-by: Christian Gmeiner <christian.gmeiner at gmail.com>
---
src/mesa/state_tracker/st_glsl_to_nir.cpp | 26 +++++++++++++++--------
src/mesa/state_tracker/st_nir.h | 2 +-
2 files changed, 18 insertions(+), 10 deletions(-)
diff --git a/src/mesa/state_tracker/st_glsl_to_nir.cpp b/src/mesa/state_tracker/st_glsl_to_nir.cpp
index de906e60c3..44c90e66c6 100644
--- a/src/mesa/state_tracker/st_glsl_to_nir.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_nir.cpp
@@ -315,15 +315,18 @@ st_nir_assign_uniform_locations(struct gl_context *ctx,
}
void
-st_nir_opts(nir_shader *nir)
+st_nir_opts(nir_shader *nir, bool scalar)
{
bool progress;
do {
progress = false;
NIR_PASS_V(nir, nir_lower_vars_to_ssa);
- NIR_PASS_V(nir, nir_lower_alu_to_scalar);
- NIR_PASS_V(nir, nir_lower_phis_to_scalar);
+
+ if (scalar) {
+ NIR_PASS_V(nir, nir_lower_alu_to_scalar);
+ NIR_PASS_V(nir, nir_lower_phis_to_scalar);
+ }
NIR_PASS_V(nir, nir_lower_pack);
NIR_PASS(progress, nir, nir_copy_prop);
@@ -361,6 +364,8 @@ st_glsl_to_nir(struct st_context *st, struct gl_program *prog,
{
const nir_shader_compiler_options *options =
st->ctx->Const.ShaderCompilerOptions[prog->info.stage].NirOptions;
+ struct pipe_screen *screen = st->pipe->screen;
+ bool is_scalar = screen->get_param(screen, PIPE_CAP_SCALAR_ISA);
assert(options);
if (prog->nir)
@@ -403,7 +408,7 @@ st_glsl_to_nir(struct st_context *st, struct gl_program *prog,
NIR_PASS_V(nir, nir_split_var_copies);
NIR_PASS_V(nir, nir_lower_var_copies);
- st_nir_opts(nir);
+ st_nir_opts(nir, is_scalar);
return nir;
}
@@ -585,7 +590,7 @@ st_nir_get_mesa_program(struct gl_context *ctx,
}
static void
-st_nir_link_shaders(nir_shader **producer, nir_shader **consumer)
+st_nir_link_shaders(nir_shader **producer, nir_shader **consumer, bool scalar)
{
nir_lower_io_arrays_to_elements(*producer, *consumer);
@@ -612,8 +617,8 @@ st_nir_link_shaders(nir_shader **producer, nir_shader **consumer)
NIR_PASS_V(*producer, nir_lower_indirect_derefs, indirect_mask);
NIR_PASS_V(*consumer, nir_lower_indirect_derefs, indirect_mask);
- st_nir_opts(*producer);
- st_nir_opts(*consumer);
+ st_nir_opts(*producer, scalar);
+ st_nir_opts(*consumer, scalar);
}
}
@@ -624,6 +629,8 @@ st_link_nir(struct gl_context *ctx,
struct gl_shader_program *shader_program)
{
struct st_context *st = st_context(ctx);
+ struct pipe_screen *screen = st->pipe->screen;
+ bool is_scalar = screen->get_param(screen, PIPE_CAP_SCALAR_ISA);
/* Determine first and last stage. */
unsigned first = MESA_SHADER_STAGES;
@@ -652,7 +659,7 @@ st_link_nir(struct gl_context *ctx,
nir_shader *nir = shader->Program->nir;
NIR_PASS_V(nir, nir_lower_io_to_scalar_early, mask);
- st_nir_opts(nir);
+ st_nir_opts(nir, is_scalar);
}
/* Linking the stages in the opposite order (from fragment to vertex)
@@ -667,7 +674,8 @@ st_link_nir(struct gl_context *ctx,
continue;
st_nir_link_shaders(&shader->Program->nir,
- &shader_program->_LinkedShaders[next]->Program->nir);
+ &shader_program->_LinkedShaders[next]->Program->nir,
+ is_scalar);
next = i;
}
diff --git a/src/mesa/state_tracker/st_nir.h b/src/mesa/state_tracker/st_nir.h
index 15f1ce93e5..71e3aec519 100644
--- a/src/mesa/state_tracker/st_nir.h
+++ b/src/mesa/state_tracker/st_nir.h
@@ -42,7 +42,7 @@ void st_finalize_nir(struct st_context *st, struct gl_program *prog,
struct gl_shader_program *shader_program,
struct nir_shader *nir);
-void st_nir_opts(struct nir_shader *nir);
+void st_nir_opts(struct nir_shader *nir, bool scalar);
bool
st_link_nir(struct gl_context *ctx,
--
2.17.1
More information about the mesa-dev
mailing list