intel/nir/rt: fix reportIntersection() hitT handling
authorLionel Landwerlin <lionel.g.landwerlin@intel.com>
Sat, 9 Sep 2023 03:30:52 +0000 (06:30 +0300)
committerEric Engestrom <eric@engestrom.ch>
Sat, 18 Nov 2023 21:18:21 +0000 (21:18 +0000)
We're currently updating the hitT value in the traversal result with
the hitT value from reportIntersection(), but this is not correct.

First the hitT value of reportIntersection() should update the
gl_RayTmaxEXT value (maps to brw_nir_rt_mem_ray_defs::t_far).

Second the hitT determined by traversal should only be updated if the
reportIntersection() hitT value has updated the gl_RayTmaxEXT and that
the new gl_RayTmaxEXT is smaller than the determined hitT value from
traversal.

Reviewed-by: Ivan Briano <ivan.briano@intel.com>
Fixes: 303378e1dd ("intel/rt: Add lowering for combined intersection/any-hit shaders")
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25146>
(cherry picked from commit 4eb4197d27aed6f5e71195a971145b2945d78330)

.pick_status.json
src/intel/compiler/brw_nir_lower_intersection_shader.c

index d53c5e1..02852cb 100644 (file)
         "description": "intel/nir/rt: fix reportIntersection() hitT handling",
         "nominated": true,
         "nomination_type": 1,
-        "resolution": 0,
+        "resolution": 1,
         "main_sha": null,
         "because_sha": "303378e1dd4119e04e0f6cb623766115a00c2eea",
         "notes": null
index 90e2f03..b26339b 100644 (file)
@@ -196,7 +196,14 @@ brw_nir_lower_intersection_shader(nir_shader *intersection,
                nir_def *hit_t = intrin->src[0].ssa;
                nir_def *hit_kind = intrin->src[1].ssa;
                nir_def *min_t = nir_load_ray_t_min(b);
-               nir_def *max_t = nir_load_global(b, t_addr, 4, 1, 32);
+
+               struct brw_nir_rt_mem_ray_defs ray_def;
+               brw_nir_rt_load_mem_ray(b, &ray_def, BRW_RT_BVH_LEVEL_WORLD);
+
+               struct brw_nir_rt_mem_hit_defs hit_in = {};
+               brw_nir_rt_load_mem_hit(b, &hit_in, false);
+
+               nir_def *max_t = ray_def.t_far;
 
                /* bool commit_tmp = false; */
                nir_variable *commit_tmp =
@@ -227,8 +234,13 @@ brw_nir_lower_intersection_shader(nir_shader *intersection,
                   nir_push_if(b, nir_load_var(b, commit_tmp));
                   {
                      nir_store_var(b, commit, nir_imm_true(b), 0x1);
+
+                     nir_def *ray_addr =
+                        brw_nir_rt_mem_ray_addr(b, brw_nir_rt_stack_addr(b), BRW_RT_BVH_LEVEL_WORLD);
+
+                     nir_store_global(b, nir_iadd_imm(b, ray_addr, 16 + 12), 4,  hit_t, 0x1);
                      nir_store_global(b, t_addr, 4,
-                                      nir_vec2(b, hit_t, hit_kind),
+                                      nir_vec2(b, nir_fmin(b, hit_t, hit_in.t), hit_kind),
                                       0x3);
                   }
                   nir_pop_if(b, NULL);