mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-05 00:58:05 +02:00
st/glsl: refactor st_link_nir()
The functional change here is moving the nir_lower_io_to_scalar_early()
calls inside st_nir_link_shaders() and moving the st_nir_opts() call
after the call to nir_lower_io_arrays_to_elements().
This fixes a bug with the following piglit test due to the current code
not cleaning up dead code after we lower arrays. This was causing an
assert in the new duplicate varyings link time opt introduced in
70be9afccb.
tests/spec/glsl-1.10/execution/vsfs-unused-array-member.shader_test
Moving the nir_lower_io_to_scalar_early() calls also allows us to tidy
up the code a little and merge some loops.
Reviewed-by: Eric Anholt <eric@anholt.net>
This commit is contained in:
parent
8847370424
commit
17fac39398
1 changed files with 17 additions and 37 deletions
|
|
@ -586,8 +586,16 @@ st_nir_get_mesa_program(struct gl_context *ctx,
|
|||
static void
|
||||
st_nir_link_shaders(nir_shader **producer, nir_shader **consumer, bool scalar)
|
||||
{
|
||||
if (scalar) {
|
||||
NIR_PASS_V(*producer, nir_lower_io_to_scalar_early, nir_var_shader_out);
|
||||
NIR_PASS_V(*consumer, nir_lower_io_to_scalar_early, nir_var_shader_in);
|
||||
}
|
||||
|
||||
nir_lower_io_arrays_to_elements(*producer, *consumer);
|
||||
|
||||
st_nir_opts(*producer, scalar);
|
||||
st_nir_opts(*consumer, scalar);
|
||||
|
||||
if (nir_link_opt_varyings(*producer, *consumer))
|
||||
st_nir_opts(*consumer, scalar);
|
||||
|
||||
|
|
@ -663,51 +671,23 @@ st_link_nir(struct gl_context *ctx,
|
|||
struct pipe_screen *screen = st->pipe->screen;
|
||||
bool is_scalar[MESA_SHADER_STAGES];
|
||||
|
||||
/* Determine scalar property of each shader stage */
|
||||
for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) {
|
||||
struct gl_linked_shader *shader = shader_program->_LinkedShaders[i];
|
||||
enum pipe_shader_type type;
|
||||
|
||||
if (shader == NULL)
|
||||
continue;
|
||||
|
||||
type = pipe_shader_type_from_mesa(shader->Stage);
|
||||
is_scalar[i] = screen->get_shader_param(screen, type, PIPE_SHADER_CAP_SCALAR_ISA);
|
||||
}
|
||||
|
||||
/* Determine first and last stage. */
|
||||
unsigned first = MESA_SHADER_STAGES;
|
||||
unsigned last = 0;
|
||||
for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) {
|
||||
if (!shader_program->_LinkedShaders[i])
|
||||
continue;
|
||||
if (first == MESA_SHADER_STAGES)
|
||||
first = i;
|
||||
last = i;
|
||||
}
|
||||
|
||||
unsigned last_stage = 0;
|
||||
for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) {
|
||||
struct gl_linked_shader *shader = shader_program->_LinkedShaders[i];
|
||||
if (shader == NULL)
|
||||
continue;
|
||||
|
||||
/* Determine scalar property of each shader stage */
|
||||
enum pipe_shader_type type = pipe_shader_type_from_mesa(shader->Stage);
|
||||
is_scalar[i] = screen->get_shader_param(screen, type,
|
||||
PIPE_SHADER_CAP_SCALAR_ISA);
|
||||
|
||||
st_nir_get_mesa_program(ctx, shader_program, shader);
|
||||
|
||||
nir_variable_mode mask = (nir_variable_mode) 0;
|
||||
if (i != first)
|
||||
mask = (nir_variable_mode)(mask | nir_var_shader_in);
|
||||
|
||||
if (i != last)
|
||||
mask = (nir_variable_mode)(mask | nir_var_shader_out);
|
||||
|
||||
nir_shader *nir = shader->Program->nir;
|
||||
last_stage = i;
|
||||
|
||||
if (is_scalar[i]) {
|
||||
NIR_PASS_V(nir, nir_lower_io_to_scalar_early, mask);
|
||||
NIR_PASS_V(nir, nir_lower_load_const_to_scalar);
|
||||
NIR_PASS_V(shader->Program->nir, nir_lower_load_const_to_scalar);
|
||||
}
|
||||
|
||||
st_nir_opts(nir, is_scalar[i]);
|
||||
}
|
||||
|
||||
/* Linking the stages in the opposite order (from fragment to vertex)
|
||||
|
|
@ -715,7 +695,7 @@ st_link_nir(struct gl_context *ctx,
|
|||
* are eliminated if they are (transitively) not used in a later
|
||||
* stage.
|
||||
*/
|
||||
int next = last;
|
||||
int next = last_stage;
|
||||
for (int i = next - 1; i >= 0; i--) {
|
||||
struct gl_linked_shader *shader = shader_program->_LinkedShaders[i];
|
||||
if (shader == NULL)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue