nir: add support for pixel_local_storage variables

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Reviewed-by: Eric R. Smith <eric.smith@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/37110>
This commit is contained in:
Ryan Mckeever 2025-09-26 12:32:23 -07:00 committed by Marge Bot
parent bfee8d3a14
commit 75263ce911
8 changed files with 49 additions and 9 deletions

View file

@ -466,6 +466,11 @@ struct glsl_struct_field {
*/ */
unsigned precision:2; unsigned precision:2;
/**
* Pixel local storage qualifier
*/
unsigned pixel_local_storage:2;
/** /**
* Memory qualifiers, applicable to buffer variables defined in shader * Memory qualifiers, applicable to buffer variables defined in shader
* storage buffer objects (SSBOs) * storage buffer objects (SSBOs)

View file

@ -256,6 +256,9 @@ nir_shader_add_variable(nir_shader *shader, nir_variable *var)
case nir_var_mem_node_payload: case nir_var_mem_node_payload:
case nir_var_mem_node_payload_in: case nir_var_mem_node_payload_in:
case nir_var_mem_global: case nir_var_mem_global:
case nir_var_mem_pixel_local_in:
case nir_var_mem_pixel_local_out:
case nir_var_mem_pixel_local_inout:
break; break;
default: default:

View file

@ -448,7 +448,7 @@ typedef struct nir_variable {
* *
* :c:struct:`nir_variable_mode` * :c:struct:`nir_variable_mode`
*/ */
unsigned mode : 21; unsigned mode : 24;
/** /**
* Is the variable read-only? * Is the variable read-only?

View file

@ -76,18 +76,21 @@ typedef enum {
nir_var_mem_task_payload = (1 << 11), nir_var_mem_task_payload = (1 << 11),
nir_var_mem_node_payload = (1 << 12), nir_var_mem_node_payload = (1 << 12),
nir_var_mem_node_payload_in = (1 << 13), nir_var_mem_node_payload_in = (1 << 13),
nir_var_mem_pixel_local_in = (1 << 14),
nir_var_mem_pixel_local_out = (1 << 15),
nir_var_mem_pixel_local_inout = (1 << 16),
nir_var_function_in = (1 << 14), nir_var_function_in = (1 << 17),
nir_var_function_out = (1 << 15), nir_var_function_out = (1 << 18),
nir_var_function_inout = (1 << 16), nir_var_function_inout = (1 << 19),
/* Generic modes intentionally come last. See encode_dref_modes() in /* Generic modes intentionally come last. See encode_dref_modes() in
* nir_serialize.c for more details. * nir_serialize.c for more details.
*/ */
nir_var_shader_temp = (1 << 17), nir_var_shader_temp = (1 << 20),
nir_var_function_temp = (1 << 18), nir_var_function_temp = (1 << 21),
nir_var_mem_shared = (1 << 19), nir_var_mem_shared = (1 << 22),
nir_var_mem_global = (1 << 20), nir_var_mem_global = (1 << 23),
nir_var_mem_generic = (nir_var_shader_temp | nir_var_mem_generic = (nir_var_shader_temp |
nir_var_function_temp | nir_var_function_temp |
@ -105,7 +108,13 @@ typedef enum {
nir_var_mem_shared | nir_var_mem_global | nir_var_mem_shared | nir_var_mem_global |
nir_var_mem_push_const | nir_var_mem_task_payload | nir_var_mem_push_const | nir_var_mem_task_payload |
nir_var_shader_out | nir_var_system_value, nir_var_shader_out | nir_var_system_value,
nir_num_variable_modes = 21,
/* modes that can serve as fragment shader outputs */
nir_var_any_pixel_local = nir_var_mem_pixel_local_in |
nir_var_mem_pixel_local_out |
nir_var_mem_pixel_local_inout,
nir_num_variable_modes = 24,
nir_var_all = (1 << nir_num_variable_modes) - 1, nir_var_all = (1 << nir_num_variable_modes) - 1,
} nir_variable_mode; } nir_variable_mode;
MESA_DEFINE_CPP_ENUM_BITFIELD_OPERATORS(nir_variable_mode) MESA_DEFINE_CPP_ENUM_BITFIELD_OPERATORS(nir_variable_mode)

View file

@ -514,6 +514,9 @@ gather_intrinsic_info(nir_intrinsic_instr *instr, nir_shader *shader)
} }
if (nir_intrinsic_writes_external_memory(instr)) if (nir_intrinsic_writes_external_memory(instr))
shader->info.writes_memory = true; shader->info.writes_memory = true;
if (shader->info.stage == MESA_SHADER_FRAGMENT &&
nir_deref_mode_is_one_of(deref, nir_var_any_pixel_local))
shader->info.fs.accesses_pixel_local_storage = true;
break; break;
} }
case nir_intrinsic_image_deref_load: case nir_intrinsic_image_deref_load:
@ -1049,6 +1052,7 @@ nir_shader_gather_info(nir_shader *shader, nir_function_impl *entrypoint)
shader->info.vs.double_inputs = 0; shader->info.vs.double_inputs = 0;
} }
if (shader->info.stage == MESA_SHADER_FRAGMENT) { if (shader->info.stage == MESA_SHADER_FRAGMENT) {
shader->info.fs.accesses_pixel_local_storage = false;
shader->info.fs.uses_sample_qualifier = false; shader->info.fs.uses_sample_qualifier = false;
shader->info.fs.uses_discard = false; shader->info.fs.uses_discard = false;
shader->info.fs.color_is_dual_source = false; shader->info.fs.color_is_dual_source = false;

View file

@ -752,6 +752,12 @@ get_variable_mode_str(nir_variable_mode mode, bool want_local_global_mode)
return "push_const"; return "push_const";
case nir_var_mem_constant: case nir_var_mem_constant:
return "constant"; return "constant";
case nir_var_mem_pixel_local_in:
return "pixel_local_in";
case nir_var_mem_pixel_local_out:
return "pixel_local_out";
case nir_var_mem_pixel_local_inout:
return "pixel_local";
case nir_var_image: case nir_var_image:
return "image"; return "image";
case nir_var_shader_temp: case nir_var_shader_temp:
@ -1054,6 +1060,11 @@ print_deref_link(const nir_deref_instr *instr, bool whole_chain, print_state *st
case nir_deref_type_struct: case nir_deref_type_struct:
fprintf(fp, "%s%s", is_parent_pointer ? "->" : ".", fprintf(fp, "%s%s", is_parent_pointer ? "->" : ".",
glsl_get_struct_elem_name(parent->type, instr->strct.index)); glsl_get_struct_elem_name(parent->type, instr->strct.index));
if (whole_chain &&
parent->type->fields.structure[instr->strct.index].pixel_local_storage) {
fprintf(fp, " (%s)",
util_format_short_name(parent->type->fields.structure[instr->strct.index].image_format));
}
break; break;
case nir_deref_type_array: case nir_deref_type_array:

View file

@ -2284,6 +2284,9 @@ nir_validate_shader(nir_shader *shader, const char *when)
nir_var_mem_global | nir_var_mem_global |
nir_var_mem_push_const | nir_var_mem_push_const |
nir_var_mem_constant | nir_var_mem_constant |
nir_var_mem_pixel_local_in |
nir_var_mem_pixel_local_out |
nir_var_mem_pixel_local_inout |
nir_var_image; nir_var_image;
if (mesa_shader_stage_is_callable(shader->info.stage)) if (mesa_shader_stage_is_callable(shader->info.stage))

View file

@ -459,6 +459,11 @@ typedef struct shader_info {
bool sample_interlock_ordered:1; bool sample_interlock_ordered:1;
bool sample_interlock_unordered:1; bool sample_interlock_unordered:1;
/**
* whether this shader has pixel_local_storage load/store instructions
*/
bool accesses_pixel_local_storage:1;
/** /**
* Flags whether NIR's base types on the FS color outputs should be * Flags whether NIR's base types on the FS color outputs should be
* ignored. * ignored.