nir: remove handling IO variables from passes used by st/mesa

Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/33146>
This commit is contained in:
Marek Olšák
2024-12-24 18:08:43 -05:00
committed by Marge Bot
parent 2c5deaa98b
commit bdd85c8393
13 changed files with 76 additions and 392 deletions

View File

@@ -11,19 +11,10 @@ static nir_def *
fog_result(nir_builder *b, nir_def *color, enum gl_fog_mode fog_mode, struct gl_program_parameter_list *paramList)
{
nir_shader *s = b->shader;
nir_def *fogc;
if (b->shader->info.io_lowered) {
nir_def *baryc = nir_load_barycentric_pixel(b, 32,
.interp_mode = INTERP_MODE_SMOOTH);
fogc = nir_load_interpolated_input(b, 1, 32, baryc, nir_imm_int(b, 0),
.io_semantics.location = VARYING_SLOT_FOGC);
} else {
nir_variable *fogc_var =
nir_create_variable_with_location(s, nir_var_shader_in, VARYING_SLOT_FOGC, glsl_float_type());
s->info.inputs_read |= VARYING_BIT_FOGC;
fogc = nir_load_var(b, fogc_var);
}
nir_def *baryc = nir_load_barycentric_pixel(b, 32,
.interp_mode = INTERP_MODE_SMOOTH);
nir_def *fogc = nir_load_interpolated_input(b, 1, 32, baryc, nir_imm_int(b, 0),
.io_semantics.location = VARYING_SLOT_FOGC);
static const gl_state_index16 fog_params_tokens[STATE_LENGTH] = {STATE_FOG_PARAMS_OPTIMIZED};
static const gl_state_index16 fog_color_tokens[STATE_LENGTH] = {STATE_FOG_COLOR};
@@ -120,37 +111,13 @@ st_nir_lower_fog_instr(nir_builder *b, nir_instr *instr, void *_state)
bool
st_nir_lower_fog(nir_shader *s, enum gl_fog_mode fog_mode, struct gl_program_parameter_list *paramList)
{
if (s->info.io_lowered) {
struct lower_fog_state state = {
.fog_mode = fog_mode,
.paramList = paramList,
};
nir_shader_instructions_pass(s, st_nir_lower_fog_instr,
nir_metadata_control_flow,
&state);
} else {
nir_variable *color_var = nir_find_variable_with_location(s, nir_var_shader_out, FRAG_RESULT_COLOR);
if (!color_var) {
color_var = nir_find_variable_with_location(s, nir_var_shader_out, FRAG_RESULT_DATA0);
/* Fog result would be undefined if we had no output color (in ARB_fragment_program) */
if (!color_var)
return false;
}
assert(s->info.io_lowered);
nir_function_impl *impl = nir_shader_get_entrypoint(s);
nir_builder b = nir_builder_at(nir_after_impl(impl));
/* Note: while ARB_fragment_program plus ARB_draw_buffers allows an array
* of result colors, prog_to_nir generates separate vars per slot so we
* don't have to handle that. Fog only applies to the first color result.
*/
assert(!glsl_type_is_array(color_var->type));
nir_def *color = nir_load_var(&b, color_var);
color = fog_result(&b, color, fog_mode, paramList);
nir_store_var(&b, color_var, color, 0x7);
nir_metadata_preserve(b.impl, nir_metadata_control_flow); }
return true;
struct lower_fog_state state = {
.fog_mode = fog_mode,
.paramList = paramList,
};
return nir_shader_instructions_pass(s, st_nir_lower_fog_instr,
nir_metadata_control_flow,
&state);
}

View File

@@ -20,6 +20,7 @@ bool
st_nir_lower_position_invariant(struct nir_shader *s, bool aos,
struct gl_program_parameter_list *paramList)
{
assert(s->info.io_lowered);
nir_function_impl *impl = nir_shader_get_entrypoint(s);
nir_builder b = nir_builder_at(nir_before_impl(impl));
@@ -33,17 +34,8 @@ st_nir_lower_position_invariant(struct nir_shader *s, bool aos,
}
nir_def *result;
nir_def *in_pos;
if (s->info.io_lowered) {
in_pos = nir_load_input(&b, 4, 32, nir_imm_int(&b, 0),
.io_semantics.location = VERT_ATTRIB_POS);
} else {
in_pos = nir_load_var(&b, nir_get_variable_with_location(s, nir_var_shader_in,
VERT_ATTRIB_POS,
glsl_vec4_type()));
s->info.inputs_read |= VERT_BIT_POS;
}
nir_def *in_pos = nir_load_input(&b, 4, 32, nir_imm_int(&b, 0),
.io_semantics.location = VERT_ATTRIB_POS);
if (aos) {
nir_def *chans[4];
@@ -56,16 +48,8 @@ st_nir_lower_position_invariant(struct nir_shader *s, bool aos,
result = nir_fmad(&b, mvp[i], nir_channel(&b, in_pos, i), result);
}
if (s->info.io_lowered) {
nir_store_output(&b, result, nir_imm_int(&b, 0),
.io_semantics.location = VARYING_SLOT_POS);
} else {
nir_store_var(&b, nir_get_variable_with_location(s, nir_var_shader_out,
VARYING_SLOT_POS,
glsl_vec4_type()), result, 0xf);
s->info.outputs_written |= VARYING_BIT_POS;
}
nir_store_output(&b, result, nir_imm_int(&b, 0),
.io_semantics.location = VARYING_SLOT_POS);
nir_metadata_preserve(b.impl, nir_metadata_control_flow);
return true;