From 9806744bd239f5806a4007e1099d2cc21078403e Mon Sep 17 00:00:00 2001 From: Vonsek <45567075+Vonsek@users.noreply.github.com> Date: Sun, 22 Nov 2026 18:31:47 +0100 Subject: [PATCH] fix(tools): derive TLAS bounds from the stored transform A float32 instance transform can move an edge outside the bounds derived from the unrounded source matrix. --- tests/test_xdxr_bvh.py | 23 +++++++++++++++++++++++ tools/xdxr_bvh.py | 3 ++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/tests/test_xdxr_bvh.py b/tests/test_xdxr_bvh.py index 61730d009..3d04d526d 100644 --- a/tests/test_xdxr_bvh.py +++ b/tests/test_xdxr_bvh.py @@ -208,6 +208,29 @@ class ClosestHit(unittest.TestCase): self.assertGreater(hits, 50) self.assertGreater(rec, 0) + def test_tlas_bounds_and_inverse_use_the_stored_transform(self) -> None: + triangles = [[(1, 0, 0), (2, 0, 0), (1, 1, 0)]] + blas, info = X.build_blas(triangles) + mem = X.Memory() + blas_va = mem.place(0x100000, blas) + # The x scale rounds down in float32. Its translation then places + # the triangle's left edge at x = 0 rather than x = 1. + matrix = [[16777217, 0, 0, -16777216], [0, 1, 0, 0], [0, 0, 1, 0]] + instance = X.Instance(matrix, blas_va, info["root"], info["bounds"]) + tlas, metadata = X.build_tlas([instance]) + root = X.ptr_offset(metadata["root"]) + instance_offset = X.ptr_offset(struct.unpack_from("