diff --git a/src/compiler/nir/nir.c b/src/compiler/nir/nir.c index f261711517f..fbfee92d5d4 100644 --- a/src/compiler/nir/nir.c +++ b/src/compiler/nir/nir.c @@ -2232,6 +2232,10 @@ nir_intrinsic_from_system_value(gl_system_value val) return nir_intrinsic_load_ray_t_min; case SYSTEM_VALUE_RAY_T_MAX: return nir_intrinsic_load_ray_t_max; + case SYSTEM_VALUE_RAY_OBJECT_TO_WORLD: + return nir_intrinsic_load_ray_object_to_world; + case SYSTEM_VALUE_RAY_WORLD_TO_OBJECT: + return nir_intrinsic_load_ray_world_to_object; case SYSTEM_VALUE_RAY_HIT_KIND: return nir_intrinsic_load_ray_hit_kind; case SYSTEM_VALUE_RAY_FLAGS: @@ -2363,6 +2367,10 @@ nir_system_value_from_intrinsic(nir_intrinsic_op intrin) return SYSTEM_VALUE_RAY_T_MIN; case nir_intrinsic_load_ray_t_max: return SYSTEM_VALUE_RAY_T_MAX; + case nir_intrinsic_load_ray_object_to_world: + return SYSTEM_VALUE_RAY_OBJECT_TO_WORLD; + case nir_intrinsic_load_ray_world_to_object: + return SYSTEM_VALUE_RAY_WORLD_TO_OBJECT; case nir_intrinsic_load_ray_hit_kind: return SYSTEM_VALUE_RAY_HIT_KIND; case nir_intrinsic_load_ray_flags: diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index ba835cd221d..de29aab1e27 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -1791,6 +1791,11 @@ typedef enum { */ NIR_INTRINSIC_COMPONENT, + /** + * Column index for matrix intrinsics. + */ + NIR_INTRINSIC_COLUMN, + /** * Interpolation mode (only meaningful for FS inputs). */ @@ -2057,6 +2062,7 @@ INTRINSIC_IDX_ACCESSORS(range_base, RANGE_BASE, unsigned) INTRINSIC_IDX_ACCESSORS(desc_set, DESC_SET, unsigned) INTRINSIC_IDX_ACCESSORS(binding, BINDING, unsigned) INTRINSIC_IDX_ACCESSORS(component, COMPONENT, unsigned) +INTRINSIC_IDX_ACCESSORS(column, COLUMN, unsigned) INTRINSIC_IDX_ACCESSORS(interp_mode, INTERP_MODE, unsigned) INTRINSIC_IDX_ACCESSORS(reduction_op, REDUCTION_OP, unsigned) INTRINSIC_IDX_ACCESSORS(cluster_size, CLUSTER_SIZE, unsigned) diff --git a/src/compiler/nir/nir_intrinsics.py b/src/compiler/nir/nir_intrinsics.py index d136687e19f..b8e0ebd87d9 100644 --- a/src/compiler/nir/nir_intrinsics.py +++ b/src/compiler/nir/nir_intrinsics.py @@ -101,6 +101,8 @@ DESC_SET = "NIR_INTRINSIC_DESC_SET" BINDING = "NIR_INTRINSIC_BINDING" # Component offset COMPONENT = "NIR_INTRINSIC_COMPONENT" +# Column index for matrix system values +COLUMN = "NIR_INTRINSIC_COLUMN" # Interpolation mode (only meaningful for FS inputs) INTERP_MODE = "NIR_INTRINSIC_INTERP_MODE" # A binary nir_op to use when performing a reduction or scan operation @@ -667,6 +669,8 @@ system_value("ray_object_origin", 3) system_value("ray_object_direction", 3) system_value("ray_t_min", 1) system_value("ray_t_max", 1) +system_value("ray_object_to_world", 3, indices=[COLUMN]) +system_value("ray_world_to_object", 3, indices=[COLUMN]) system_value("ray_hit_kind", 1) system_value("ray_flags", 1) system_value("ray_geometry_index", 1) diff --git a/src/compiler/nir/nir_lower_system_values.c b/src/compiler/nir/nir_lower_system_values.c index d48cf0c3d8b..c4295d52bce 100644 --- a/src/compiler/nir/nir_lower_system_values.c +++ b/src/compiler/nir/nir_lower_system_values.c @@ -113,14 +113,20 @@ lower_system_value_instr(nir_builder *b, nir_instr *instr, void *_state) if (!nir_deref_mode_is(deref, nir_var_system_value)) return NULL; + nir_ssa_def *column = NULL; if (deref->deref_type != nir_deref_type_var) { - /* The only one system value that is an array and that is - * gl_SampleMask which is always an array of one element. + /* The only one system values that aren't plane variables are + * gl_SampleMask which is always an array of one element and a + * couple of ray-tracing intrinsics which are matrices. */ assert(deref->deref_type == nir_deref_type_array); + assert(deref->arr.index.is_ssa); + column = deref->arr.index.ssa; deref = nir_deref_instr_parent(deref); assert(deref->deref_type == nir_deref_type_var); - assert(deref->var->data.location == SYSTEM_VALUE_SAMPLE_MASK_IN); + assert(deref->var->data.location == SYSTEM_VALUE_SAMPLE_MASK_IN || + deref->var->data.location == SYSTEM_VALUE_RAY_OBJECT_TO_WORLD || + deref->var->data.location == SYSTEM_VALUE_RAY_WORLD_TO_OBJECT); } nir_variable *var = deref->var; @@ -186,9 +192,25 @@ lower_system_value_instr(nir_builder *b, nir_instr *instr, void *_state) nir_intrinsic_op sysval_op = nir_intrinsic_from_system_value(var->data.location); - return nir_load_system_value(b, sysval_op, 0, + if (glsl_type_is_matrix(var->type)) { + assert(nir_intrinsic_infos[sysval_op].index_map[NIR_INTRINSIC_COLUMN] > 0); + unsigned num_cols = glsl_get_matrix_columns(var->type); + ASSERTED unsigned num_rows = glsl_get_vector_elements(var->type); + assert(num_rows == intrin->dest.ssa.num_components); + + nir_ssa_def *cols[4]; + for (unsigned i = 0; i < num_cols; i++) { + cols[i] = nir_load_system_value(b, sysval_op, i, + intrin->dest.ssa.num_components, + intrin->dest.ssa.bit_size); + assert(cols[i]->num_components == num_rows); + } + return nir_select_from_ssa_def_array(b, cols, num_cols, column); + } else { + return nir_load_system_value(b, sysval_op, 0, intrin->dest.ssa.num_components, intrin->dest.ssa.bit_size); + } } default: diff --git a/src/compiler/nir/nir_print.c b/src/compiler/nir/nir_print.c index c8e4bc14792..e1c17ccbb2b 100644 --- a/src/compiler/nir/nir_print.c +++ b/src/compiler/nir/nir_print.c @@ -830,6 +830,7 @@ print_intrinsic_instr(nir_intrinsic_instr *instr, print_state *state) [NIR_INTRINSIC_DESC_SET] = "desc-set", [NIR_INTRINSIC_BINDING] = "binding", [NIR_INTRINSIC_COMPONENT] = "component", + [NIR_INTRINSIC_COLUMN] = "column", [NIR_INTRINSIC_INTERP_MODE] = "interp_mode", [NIR_INTRINSIC_REDUCTION_OP] = "reduction_op", [NIR_INTRINSIC_CLUSTER_SIZE] = "cluster_size",