nir: Add new variable modes for ray-tracing

If we were desperate to reduce bits, we could probably also use
shader_in/out for hit attributes as they really are an output from
intersection shaders and read-only in any-hit and closest-hit shaders.
However, other passes such as nir_gether_info like to assume that
anything with nir_var_shader_in/out is indexed using vec4 locations for
interface matching.  It's easier to just add a new variable mode.

Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Reviewed-by: Caio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6479>
This commit is contained in:
Jason Ekstrand
2020-07-29 14:00:29 -05:00
committed by Marge Bot
parent aa4ea9c7ea
commit 84a8ca1db8
6 changed files with 33 additions and 5 deletions

View File

@@ -179,6 +179,8 @@ nir_shader_add_variable(nir_shader *shader, nir_variable *var)
case nir_var_system_value: case nir_var_system_value:
case nir_var_mem_push_const: case nir_var_mem_push_const:
case nir_var_mem_constant: case nir_var_mem_constant:
case nir_var_shader_call_data:
case nir_var_ray_hit_attrib:
break; break;
case nir_var_mem_global: case nir_var_mem_global:

View File

@@ -134,9 +134,13 @@ typedef enum {
nir_var_mem_global), nir_var_mem_global),
nir_var_mem_push_const = (1 << 10), /* not actually used for variables */ nir_var_mem_push_const = (1 << 10), /* not actually used for variables */
nir_var_mem_constant = (1 << 11), nir_var_mem_constant = (1 << 11),
/** Incoming call or ray payload data for ray-tracing shaders */
nir_var_shader_call_data = (1 << 12),
/** Ray hit attributes */
nir_var_ray_hit_attrib = (1 << 13),
nir_var_read_only_modes = nir_var_shader_in | nir_var_uniform | nir_var_read_only_modes = nir_var_shader_in | nir_var_uniform |
nir_var_system_value | nir_var_mem_constant, nir_var_system_value | nir_var_mem_constant,
nir_num_variable_modes = 12, nir_num_variable_modes = 14,
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)
@@ -345,7 +349,7 @@ typedef struct nir_variable {
* *
* \sa nir_variable_mode * \sa nir_variable_mode
*/ */
unsigned mode:12; unsigned mode:14;
/** /**
* Is the variable read-only? * Is the variable read-only?

View File

@@ -473,6 +473,10 @@ get_variable_mode_str(nir_variable_mode mode, bool want_local_global_mode)
return want_local_global_mode ? "shader_temp" : ""; return want_local_global_mode ? "shader_temp" : "";
case nir_var_function_temp: case nir_var_function_temp:
return want_local_global_mode ? "function_temp" : ""; return want_local_global_mode ? "function_temp" : "";
case nir_var_shader_call_data:
return "shader_call_data";
case nir_var_ray_hit_attrib:
return "ray_hit_attrib";
default: default:
return ""; return "";
} }

View File

@@ -637,9 +637,9 @@ union packed_instr {
unsigned instr_type:4; unsigned instr_type:4;
unsigned deref_type:3; unsigned deref_type:3;
unsigned cast_type_same_as_last:1; unsigned cast_type_same_as_last:1;
unsigned modes:12; /* deref_var redefines this */ unsigned modes:14; /* deref_var redefines this */
unsigned packed_src_ssa_16bit:1; /* deref_var redefines this */ unsigned packed_src_ssa_16bit:1; /* deref_var redefines this */
unsigned _pad:3; /* deref_var redefines this */ unsigned _pad:1; /* deref_var redefines this */
unsigned dest:8; unsigned dest:8;
} deref; } deref;
struct { struct {
@@ -984,7 +984,7 @@ static void
write_deref(write_ctx *ctx, const nir_deref_instr *deref) write_deref(write_ctx *ctx, const nir_deref_instr *deref)
{ {
assert(deref->deref_type < 8); assert(deref->deref_type < 8);
assert(deref->modes < (1 << 12)); assert(deref->modes < (1 << 14));
union packed_instr header; union packed_instr header;
header.u32 = 0; header.u32 = 0;

View File

@@ -1551,6 +1551,14 @@ nir_validate_shader(nir_shader *shader, const char *when)
nir_var_mem_push_const | nir_var_mem_push_const |
nir_var_mem_constant; nir_var_mem_constant;
if (gl_shader_stage_is_callable(shader->info.stage))
valid_modes |= nir_var_shader_call_data;
if (shader->info.stage == MESA_SHADER_ANY_HIT ||
shader->info.stage == MESA_SHADER_CLOSEST_HIT ||
shader->info.stage == MESA_SHADER_INTERSECTION)
valid_modes |= nir_var_ray_hit_attrib;
exec_list_validate(&shader->variables); exec_list_validate(&shader->variables);
nir_foreach_variable_in_shader(var, shader) nir_foreach_variable_in_shader(var, shader)
validate_var_decl(var, valid_modes, &state); validate_var_decl(var, valid_modes, &state);

View File

@@ -72,6 +72,16 @@ gl_shader_stage_is_compute(gl_shader_stage stage)
return stage == MESA_SHADER_COMPUTE || stage == MESA_SHADER_KERNEL; return stage == MESA_SHADER_COMPUTE || stage == MESA_SHADER_KERNEL;
} }
static inline bool
gl_shader_stage_is_callable(gl_shader_stage stage)
{
return stage == MESA_SHADER_ANY_HIT ||
stage == MESA_SHADER_CLOSEST_HIT ||
stage == MESA_SHADER_MISS ||
stage == MESA_SHADER_INTERSECTION ||
stage == MESA_SHADER_CALLABLE;
}
/** /**
* Number of STATE_* values we need to address any GL state. * Number of STATE_* values we need to address any GL state.
* Used to dimension arrays. * Used to dimension arrays.