diff options
author | Lionel Landwerlin <lionel.g.landwerlin@intel.com> | 2024-08-08 21:12:30 +0300 |
---|---|---|
committer | Eric Engestrom <eric@engestrom.ch> | 2024-08-14 11:52:49 +0200 |
commit | db297c6534e0d44bcbcbffdd7af4dbafa98639a8 (patch) | |
tree | cb2e0f95eb52c04cfa1cc500b24a6ff99b81965e /src/intel | |
parent | 46ad101f67c03a07156ef23189246d78877fe505 (diff) |
brw/rt: fix ray_object_(direction|origin) for closest-hit shaders
When closest hit shader is called, the BVH object level
brw_nir_rt_load_mem_ray origin/direction is 0. What we should be using
is the ray origin/direction and apply the transform of the current
instance.
Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Fixes: 9ba7d459a3 ("intel/rt: Implement the new ray-tracing system values")
Reviewed-by: Sagar Ghuge <sagar.ghuge@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30578>
(cherry picked from commit aaff19135644049cde3bd3ddd649b48f96111fa4)
Diffstat (limited to 'src/intel')
-rw-r--r-- | src/intel/compiler/brw_nir_lower_rt_intrinsics.c | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/src/intel/compiler/brw_nir_lower_rt_intrinsics.c b/src/intel/compiler/brw_nir_lower_rt_intrinsics.c index 4b0289bdc50..9d4e222db84 100644 --- a/src/intel/compiler/brw_nir_lower_rt_intrinsics.c +++ b/src/intel/compiler/brw_nir_lower_rt_intrinsics.c @@ -25,6 +25,24 @@ #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 * build_leaf_is_procedural(nir_builder *b, struct brw_nir_rt_mem_hit_defs *hit) { switch (b->shader->info.stage) { @@ -163,11 +181,27 @@ lower_rt_intrinsics_impl(nir_function_impl *impl, break; case nir_intrinsic_load_ray_object_origin: - sysval = object_ray_in.orig; + if (stage == MESA_SHADER_CLOSEST_HIT) { + struct brw_nir_rt_bvh_instance_leaf_defs leaf; + brw_nir_rt_load_bvh_instance_leaf(b, &leaf, hit_in.inst_leaf_ptr); + + sysval = nir_build_vec3_mat_mult_col_major( + b, world_ray_in.orig, leaf.world_to_object, true); + } else { + sysval = object_ray_in.orig; + } break; case nir_intrinsic_load_ray_object_direction: - sysval = object_ray_in.dir; + if (stage == MESA_SHADER_CLOSEST_HIT) { + struct brw_nir_rt_bvh_instance_leaf_defs leaf; + brw_nir_rt_load_bvh_instance_leaf(b, &leaf, hit_in.inst_leaf_ptr); + + sysval = nir_build_vec3_mat_mult_col_major( + b, world_ray_in.dir, leaf.world_to_object, false); + } else { + sysval = object_ray_in.dir; + } break; case nir_intrinsic_load_ray_t_min: |