brw/rt: Move nir_build_vec3_mat_mult_col_major helper to header

Signed-off-by: Sagar Ghuge <sagar.ghuge@intel.com>
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/36853>
This commit is contained in:
Sagar Ghuge 2025-08-18 18:50:07 -07:00 committed by Marge Bot
parent 09e091fbdf
commit 3edeb1e191
2 changed files with 20 additions and 20 deletions

View file

@ -24,24 +24,6 @@
#include "brw_nir_rt.h" #include "brw_nir_rt.h"
#include "brw_nir_rt_builder.h" #include "brw_nir_rt_builder.h"
static nir_def *
nir_build_vec3_mat_mult_col_major(nir_builder *b, nir_def *vec,
nir_def *matrix[], bool translation)
{
nir_def *result_components[3] = {
nir_channel(b, matrix[3], 0),
nir_channel(b, matrix[3], 1),
nir_channel(b, matrix[3], 2),
};
for (unsigned i = 0; i < 3; ++i) {
for (unsigned j = 0; j < 3; ++j) {
nir_def *v = nir_fmul(b, nir_channels(b, vec, 1 << j), nir_channels(b, matrix[j], 1 << i));
result_components[i] = (translation || j) ? nir_fadd(b, result_components[i], v) : v;
}
}
return nir_vec(b, result_components, 3);
}
static nir_def * static nir_def *
build_leaf_is_procedural(nir_builder *b, struct brw_nir_rt_mem_hit_defs *hit) build_leaf_is_procedural(nir_builder *b, struct brw_nir_rt_mem_hit_defs *hit)
{ {
@ -193,7 +175,7 @@ lower_rt_intrinsics_impl(nir_function_impl *impl,
brw_nir_rt_load_bvh_instance_leaf(b, &leaf, hit_in.inst_leaf_ptr, brw_nir_rt_load_bvh_instance_leaf(b, &leaf, hit_in.inst_leaf_ptr,
devinfo); devinfo);
sysval = nir_build_vec3_mat_mult_col_major( sysval = brw_nir_build_vec3_mat_mult_col_major(
b, world_ray_in.orig, leaf.world_to_object, true); b, world_ray_in.orig, leaf.world_to_object, true);
} else { } else {
sysval = object_ray_in.orig; sysval = object_ray_in.orig;
@ -206,7 +188,7 @@ lower_rt_intrinsics_impl(nir_function_impl *impl,
brw_nir_rt_load_bvh_instance_leaf(b, &leaf, hit_in.inst_leaf_ptr, brw_nir_rt_load_bvh_instance_leaf(b, &leaf, hit_in.inst_leaf_ptr,
devinfo); devinfo);
sysval = nir_build_vec3_mat_mult_col_major( sysval = brw_nir_build_vec3_mat_mult_col_major(
b, world_ray_in.dir, leaf.world_to_object, false); b, world_ray_in.dir, leaf.world_to_object, false);
} else { } else {
sysval = object_ray_in.dir; sysval = object_ray_in.dir;

View file

@ -84,6 +84,24 @@ nir_shader *
brw_nir_create_null_ahs_shader(const struct brw_compiler *compiler, brw_nir_create_null_ahs_shader(const struct brw_compiler *compiler,
void *mem_ctx); void *mem_ctx);
static inline nir_def *
brw_nir_build_vec3_mat_mult_col_major(nir_builder *b, nir_def *vec,
nir_def *matrix[], bool translation)
{
nir_def *result_components[3] = {
nir_channel(b, matrix[3], 0),
nir_channel(b, matrix[3], 1),
nir_channel(b, matrix[3], 2),
};
for (unsigned i = 0; i < 3; ++i) {
for (unsigned j = 0; j < 3; ++j) {
nir_def *v = nir_fmul(b, nir_channels(b, vec, 1 << j), nir_channels(b, matrix[j], 1 << i));
result_components[i] = (translation || j) ? nir_fadd(b, result_components[i], v) : v;
}
}
return nir_vec(b, result_components, 3);
}
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif