Shader tests: measure what the emulated ray/node test costs on the card #65

Closed
github-bot wants to merge 1 commit from gh-pr/65/head into gh-pr/65/base
Owner

@⁠marquezinii on GitHub · 2026-11-24 21:04 UTC · original
marquezinii:bench/bvh-intersect-cost → main · +134 −2 · 2 files · 1 commits · closed without merging

docs/fork-ray-tracing.md listed "Cost on the GPU is unmeasured" for the emulated image_bvh64_intersect_ray. This adds an ignored test that measures the node test alone, and records what it gives on an RTX 5070.

How it measures

intersect_cost_on_the_card takes the program of the existing node tests and puts the instruction in a scalar loop. It dispatches 65535 groups of 32 threads with 1025 passes and with 1 pass, and prints the time difference per added test. It does this for 32-bit box nodes, 16-bit box nodes and triangle nodes, each using the cases of scene().

Without care, the host compiler would make the loop nearly free, so I took two measures:

  • Each pass adds a zero, read from the record at run time, to the ray's origin, direction and inverse direction. A first version only touched the extent, and the slab tests could then be hoisted.
  • Each pass XORs all four result dwords into one register, so no part of the result can be dropped as dead code.

The stored XOR is compared with the reference for every thread, so a broken loop fails the test instead of giving a number. Each dispatch stays far under the 2 s TDR limit (about 30 ms on this card).

Results

RTX 5070, driver 621.40, Windows 11. Best of five per dispatch, over several runs:

node tests per second (whole card)
box, 32-bit bounds 72–88 G
box, 16-bit bounds 72–78 G
triangle 82–114 G

At the 2.9 GHz the card ran, that is about 150 to 250 lane-cycles a test. Doubling the passes to 2049 doubles the time (58 ms against 30 ms), so the number is the test and not fixed overhead. The range comes from the clock and from other work on the card between runs.

What it means for #17

This is only the per-node test, with the nodes in cache. It does not cover the title's traversal loops (stack in LDS, raw-address loads), cache misses on real structures, or the builder. A million rays at 40 node tests each would be about 0.5 ms of node tests. So, on this card, the emulated instruction is unlikely to be what makes ray tracing expensive. Comparing with host DXR still needs the traversal and memory traffic measured on the title's own programs, which I can't run (no game files here).

cargo test -p victory-shader --locked: 210 passed, 3 ignored. cargo clippy --workspace --all-targets --locked -- -D warnings is clean. Anyone can reproduce on another GPU with:

cargo test -p victory-shader --lib intersect_cost -- --ignored --nocapture
**@⁠marquezinii** on GitHub · 2026-11-24 21:04 UTC · [original](https://github.com/fxceless/victory-fork/pull/65) `marquezinii:bench/bvh-intersect-cost` → `main` · +134 −2 · 2 files · 1 commits · closed without merging `docs/fork-ray-tracing.md` listed "Cost on the GPU is unmeasured" for the emulated `image_bvh64_intersect_ray`. This adds an ignored test that measures the node test alone, and records what it gives on an RTX 5070. ### How it measures `intersect_cost_on_the_card` takes the program of the existing node tests and puts the instruction in a scalar loop. It dispatches 65535 groups of 32 threads with 1025 passes and with 1 pass, and prints the time difference per added test. It does this for 32-bit box nodes, 16-bit box nodes and triangle nodes, each using the cases of `scene()`. Without care, the host compiler would make the loop nearly free, so I took two measures: - Each pass adds a zero, read from the record at run time, to the ray's origin, direction and inverse direction. A first version only touched the extent, and the slab tests could then be hoisted. - Each pass XORs all four result dwords into one register, so no part of the result can be dropped as dead code. The stored XOR is compared with the reference for every thread, so a broken loop fails the test instead of giving a number. Each dispatch stays far under the 2 s TDR limit (about 30 ms on this card). ### Results RTX 5070, driver 621.40, Windows 11. Best of five per dispatch, over several runs: | node | tests per second (whole card) | |---|---| | box, 32-bit bounds | 72–88 G | | box, 16-bit bounds | 72–78 G | | triangle | 82–114 G | At the 2.9 GHz the card ran, that is about 150 to 250 lane-cycles a test. Doubling the passes to 2049 doubles the time (58 ms against 30 ms), so the number is the test and not fixed overhead. The range comes from the clock and from other work on the card between runs. ### What it means for #17 This is only the per-node test, with the nodes in cache. It does not cover the title's traversal loops (stack in LDS, raw-address loads), cache misses on real structures, or the builder. A million rays at 40 node tests each would be about 0.5 ms of node tests. So, on this card, the emulated instruction is unlikely to be what makes ray tracing expensive. Comparing with host DXR still needs the traversal and memory traffic measured on the title's own programs, which I can't run (no game files here). `cargo test -p victory-shader --locked`: 210 passed, 3 ignored. `cargo clippy --workspace --all-targets --locked -- -D warnings` is clean. Anyone can reproduce on another GPU with: ``` cargo test -p victory-shader --lib intersect_cost -- --ignored --nocapture ```
An ignored test runs the 64-bit node test in a loop of 1025 passes and
of one, over 65535 groups, and prints the difference per test for box
nodes of both widths and for triangle nodes. Each pass moves the ray by a
zero read at run time and XORs all four result dwords, so the host
compiler can neither hoist the test nor drop part of it; the stored XOR is
checked against the reference. The ray-tracing notes record what it
gives on an RTX 5070.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:35:30 +00:00
github-bot closed this pull request 2026-11-26 03:35:30 +00:00
Author
Owner

@⁠marquezinii on GitHub · 2026-11-24 21:04 UTC · original

Closing: duplicate of #46, which measures the same node test and updates the same doc line.

**@⁠marquezinii** on GitHub · 2026-11-24 21:04 UTC · [original](https://github.com/fxceless/victory-fork/pull/65#issuecomment-7144446356) Closing: duplicate of #46, which measures the same node test and updates the same doc line.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.