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

Closed
marquezinii wants to merge 1 commit from upstream-pr/65 into main
marquezinii commented 2026-11-24 21:04:05 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by marquezinii on 2026-11-24T21:04:05Z.


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
<!-- greyfinch-sync:fxceless/victory-fork:issue:6591374496 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/65). Originally posted by [marquezinii](https://github.com/marquezinii) on 2026-11-24T21:04:05Z. --- `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 ```
upstream-sync closed this pull request 2026-11-24 21:30:27 +00:00
marquezinii commented 2026-11-24 21:30:42 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by marquezinii on 2026-11-24T21:04:46Z.


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

<!-- greyfinch-sync:fxceless/victory-fork:comment:7144446356 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/65#issuecomment-7144446356). Originally posted by [marquezinii](https://github.com/marquezinii) on 2026-11-24T21:04:46Z. --- Closing: duplicate of #46, which measures the same node test and updates the same doc line.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
fxceless/victory-fork!65
No description provided.