radv: Implement FS layer ID input as a system value.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32641>
This commit is contained in:
Timur Kristóf 2024-12-13 06:27:26 +01:00 committed by Marge Bot
parent b06b62bb13
commit dd00b3f527
6 changed files with 18 additions and 40 deletions

View file

@ -355,6 +355,9 @@ lower_abi_instr(nir_builder *b, nir_intrinsic_instr *intrin, void *state)
replacement = nir_imm_int(b, s->gfx_state->ms.rasterization_samples); replacement = nir_imm_int(b, s->gfx_state->ms.rasterization_samples);
} }
break; break;
case nir_intrinsic_load_layer_id:
replacement = ac_nir_unpack_arg(b, &s->args->ac, s->args->ac.ancillary, 16, s->gfx_level >= GFX12 ? 14 : 13);
break;
case nir_intrinsic_load_provoking_vtx_in_prim_amd: { case nir_intrinsic_load_provoking_vtx_in_prim_amd: {
if (s->gfx_state->dynamic_provoking_vtx_mode) { if (s->gfx_state->dynamic_provoking_vtx_mode) {
replacement = GET_SGPR_FIELD_NIR(s->args->ngg_state, NGG_STATE_PROVOKING_VTX); replacement = GET_SGPR_FIELD_NIR(s->args->ngg_state, NGG_STATE_PROVOKING_VTX);

View file

@ -89,14 +89,10 @@ radv_recompute_fs_input_bases_callback(UNUSED nir_builder *b, nir_intrinsic_inst
new_base = s->num_always_per_vertex; new_base = s->num_always_per_vertex;
switch (location_bit) { switch (location_bit) {
case VARYING_BIT_LAYER:
break;
case VARYING_BIT_VIEWPORT: case VARYING_BIT_VIEWPORT:
new_base += !!(s->potentially_per_primitive & VARYING_BIT_LAYER);
break; break;
case VARYING_BIT_PRIMITIVE_ID: case VARYING_BIT_PRIMITIVE_ID:
new_base += !!(s->potentially_per_primitive & VARYING_BIT_LAYER) + new_base += !!(s->potentially_per_primitive & VARYING_BIT_VIEWPORT);
!!(s->potentially_per_primitive & VARYING_BIT_VIEWPORT);
break; break;
} }
} else if (location_bit & s->always_per_primitive) { } else if (location_bit & s->always_per_primitive) {
@ -117,14 +113,13 @@ radv_recompute_fs_input_bases_callback(UNUSED nir_builder *b, nir_intrinsic_inst
bool bool
radv_recompute_fs_input_bases(nir_shader *nir) radv_recompute_fs_input_bases(nir_shader *nir)
{ {
const uint64_t always_per_vertex = nir->info.inputs_read & ~nir->info.per_primitive_inputs & const uint64_t always_per_vertex =
~(VARYING_BIT_PRIMITIVE_ID | VARYING_BIT_LAYER | VARYING_BIT_VIEWPORT); nir->info.inputs_read & ~nir->info.per_primitive_inputs & ~(VARYING_BIT_PRIMITIVE_ID | VARYING_BIT_VIEWPORT);
const uint64_t potentially_per_primitive = const uint64_t potentially_per_primitive = nir->info.inputs_read & (VARYING_BIT_PRIMITIVE_ID | VARYING_BIT_VIEWPORT);
nir->info.inputs_read & (VARYING_BIT_PRIMITIVE_ID | VARYING_BIT_LAYER | VARYING_BIT_VIEWPORT);
const uint64_t always_per_primitive = nir->info.inputs_read & nir->info.per_primitive_inputs & const uint64_t always_per_primitive =
~(VARYING_BIT_PRIMITIVE_ID | VARYING_BIT_LAYER | VARYING_BIT_VIEWPORT); nir->info.inputs_read & nir->info.per_primitive_inputs & ~(VARYING_BIT_PRIMITIVE_ID | VARYING_BIT_VIEWPORT);
radv_recompute_fs_input_bases_state s = { radv_recompute_fs_input_bases_state s = {
.always_per_vertex = always_per_vertex, .always_per_vertex = always_per_vertex,
@ -167,6 +162,9 @@ radv_nir_lower_io(struct radv_device *device, nir_shader *nir)
} }
if (nir->info.stage == MESA_SHADER_FRAGMENT) { if (nir->info.stage == MESA_SHADER_FRAGMENT) {
/* Lower explicit input load intrinsics to sysvals for the layer ID. */
NIR_PASS(_, nir, nir_lower_system_values);
/* Recompute FS input intrinsic bases to assign a location to each FS input. /* Recompute FS input intrinsic bases to assign a location to each FS input.
* The computed base will match the index of each input in SPI_PS_INPUT_CNTL_n. * The computed base will match the index of each input in SPI_PS_INPUT_CNTL_n.
*/ */

View file

@ -10,19 +10,6 @@
#include "nir_builder.h" #include "nir_builder.h"
#include "radv_nir.h" #include "radv_nir.h"
static nir_variable *
find_layer_in_var(nir_shader *nir)
{
nir_variable *var = nir_find_variable_with_location(nir, nir_var_shader_in, VARYING_SLOT_LAYER);
if (var != NULL)
return var;
var = nir_variable_create(nir, nir_var_shader_in, glsl_int_type(), "layer id");
var->data.location = VARYING_SLOT_LAYER;
var->data.interpolation = INTERP_MODE_FLAT;
return var;
}
/** /**
* We use layered rendering to implement multiview, which means we need to map * We use layered rendering to implement multiview, which means we need to map
* view_index to gl_Layer. The code generates a load from the layer_id sysval, * view_index to gl_Layer. The code generates a load from the layer_id sysval,
@ -39,7 +26,6 @@ radv_nir_lower_view_index(nir_shader *nir)
nir_function_impl *entry = nir_shader_get_entrypoint(nir); nir_function_impl *entry = nir_shader_get_entrypoint(nir);
nir_builder b = nir_builder_create(entry); nir_builder b = nir_builder_create(entry);
nir_variable *layer = NULL;
nir_foreach_block (block, entry) { nir_foreach_block (block, entry) {
nir_foreach_instr_safe (instr, block) { nir_foreach_instr_safe (instr, block) {
if (instr->type != nir_instr_type_intrinsic) if (instr->type != nir_instr_type_intrinsic)
@ -49,16 +35,10 @@ radv_nir_lower_view_index(nir_shader *nir)
if (load->intrinsic != nir_intrinsic_load_view_index) if (load->intrinsic != nir_intrinsic_load_view_index)
continue; continue;
if (!layer)
layer = find_layer_in_var(nir);
b.cursor = nir_before_instr(instr); b.cursor = nir_before_instr(instr);
nir_def *def = nir_load_var(&b, layer); nir_def *def = nir_load_layer_id(&b);
nir_def_rewrite_uses(&load->def, def); nir_def_rewrite_uses(&load->def, def);
/* Update inputs_read to reflect that the pass added a new input. */
nir->info.inputs_read |= VARYING_BIT_LAYER;
nir_instr_remove(instr); nir_instr_remove(instr);
progress = true; progress = true;
} }

View file

@ -2557,11 +2557,6 @@ radv_emit_ps_inputs(struct radv_cmd_buffer *cmd_buffer)
input_mask_to_ps_inputs(outinfo, ps, ps->info.ps.input_mask, ps_input_cntl, &ps_offset, radv_ps_in_flat); input_mask_to_ps_inputs(outinfo, ps, ps->info.ps.input_mask, ps_input_cntl, &ps_offset, radv_ps_in_flat);
/* Potentially per-primitive PS inputs */ /* Potentially per-primitive PS inputs */
if (ps->info.ps.layer_input) {
num_per_primitive_params += !!outinfo->writes_layer_per_primitive;
const enum radv_ps_in_type t = outinfo->writes_layer_per_primitive ? per_prim : radv_ps_in_flat;
ps_input_cntl[ps_offset++] = offset_to_ps_input(outinfo->vs_output_param_offset[VARYING_SLOT_LAYER], t);
}
if (ps->info.ps.viewport_index_input) { if (ps->info.ps.viewport_index_input) {
num_per_primitive_params += !!outinfo->writes_viewport_index_per_primitive; num_per_primitive_params += !!outinfo->writes_viewport_index_per_primitive;
const enum radv_ps_in_type t = outinfo->writes_viewport_index_per_primitive ? per_prim : radv_ps_in_flat; const enum radv_ps_in_type t = outinfo->writes_viewport_index_per_primitive ? per_prim : radv_ps_in_flat;

View file

@ -65,6 +65,7 @@ get_nir_options_for_stage(struct radv_physical_device *pdev, gl_shader_stage sta
options->lower_doubles_options = nir_lower_drcp | nir_lower_dsqrt | nir_lower_drsq | nir_lower_ddiv; options->lower_doubles_options = nir_lower_drcp | nir_lower_dsqrt | nir_lower_drsq | nir_lower_ddiv;
options->io_options |= nir_io_mediump_is_32bit; options->io_options |= nir_io_mediump_is_32bit;
options->varying_expression_max_cost = ac_nir_varying_expression_max_cost; options->varying_expression_max_cost = ac_nir_varying_expression_max_cost;
options->lower_layer_fs_input_to_sysval = true;
} }
void void
@ -431,7 +432,7 @@ radv_shader_spirv_to_nir(struct radv_device *device, const struct radv_shader_st
NIR_PASS(_, nir, nir_lower_input_attachments, NIR_PASS(_, nir, nir_lower_input_attachments,
&(nir_input_attachment_options){ &(nir_input_attachment_options){
.use_fragcoord_sysval = true, .use_fragcoord_sysval = true,
.use_layer_id_sysval = false, .use_layer_id_sysval = true,
}); });
nir_remove_dead_variables_options dead_vars_opts = { nir_remove_dead_variables_options dead_vars_opts = {
@ -3520,7 +3521,8 @@ radv_compute_spi_ps_input(const struct radv_physical_device *pdev, const struct
} }
} }
if (info->ps.reads_sample_id || info->ps.reads_frag_shading_rate || info->ps.reads_sample_mask_in) { if (info->ps.reads_sample_id || info->ps.reads_frag_shading_rate || info->ps.reads_sample_mask_in ||
info->ps.layer_input) {
spi_ps_input |= S_0286CC_ANCILLARY_ENA(1); spi_ps_input |= S_0286CC_ANCILLARY_ENA(1);
} }

View file

@ -952,7 +952,7 @@ gather_shader_info_fs(const struct radv_device *device, const nir_shader *nir,
info->ps.writes_memory = nir->info.writes_memory; info->ps.writes_memory = nir->info.writes_memory;
info->ps.has_pcoord = nir->info.inputs_read & VARYING_BIT_PNTC; info->ps.has_pcoord = nir->info.inputs_read & VARYING_BIT_PNTC;
info->ps.prim_id_input = nir->info.inputs_read & VARYING_BIT_PRIMITIVE_ID; info->ps.prim_id_input = nir->info.inputs_read & VARYING_BIT_PRIMITIVE_ID;
info->ps.layer_input = nir->info.inputs_read & VARYING_BIT_LAYER; info->ps.layer_input = BITSET_TEST(nir->info.system_values_read, SYSTEM_VALUE_LAYER_ID);
info->ps.viewport_index_input = nir->info.inputs_read & VARYING_BIT_VIEWPORT; info->ps.viewport_index_input = nir->info.inputs_read & VARYING_BIT_VIEWPORT;
info->ps.writes_z = nir->info.outputs_written & BITFIELD64_BIT(FRAG_RESULT_DEPTH); info->ps.writes_z = nir->info.outputs_written & BITFIELD64_BIT(FRAG_RESULT_DEPTH);
info->ps.writes_stencil = nir->info.outputs_written & BITFIELD64_BIT(FRAG_RESULT_STENCIL); info->ps.writes_stencil = nir->info.outputs_written & BITFIELD64_BIT(FRAG_RESULT_STENCIL);