Skip to content

R-7: read buffer view addresses by view heap slot (CS_TraceShadowRays_*) - #67

Merged
ShinniUwU merged 1 commit into
ProjectLeonidaL:mainfrom
sanchaton:fix/r7-trace-shadow-rays
Nov 27, 2026
Merged

ShinniUwU merged 1 commit into
ProjectLeonidaL:mainfrom
sanchaton:fix/r7-trace-shadow-rays

Conversation

@sanchaton

Copy link
Copy Markdown
Contributor

What changed

R-7 (untranslated shaders): the 5 CS_TraceShadowRays_* compute programs ("emit: a descriptor read only as data") load a buffer descriptor from the view heap at an index they compute and only take its address. The host's table of element strides by heap slot (SLOT_STRIDES) now goes on with two dwords per slot, the title address of the slot's buffer view (SLOT_VIEW_ADDRESSES, 0 when the slot holds no buffer view), written whenever the stride is. view_address in emit/lower.rs reads it for a descriptor picked from the heap. CS_TraceShadowRays_FullAdaptive then hit a second cause: the compiler reuses an SGPR holding a compare's mask on one path and a dword from s_buffer_load on the other, then uses the join as a number. In structure.rs, a join with an argument read by a scalar memory load is no longer a lane mask.

No change to draw.rs or the pipeline: the addresses share the existing SLOT_STRIDES root SRV.

Independent of #56, #64 and #66. It meets #56 in emit/lower.rs (both add code near the descriptor helpers) and all of them at the top of docs/fork-notes.md; whichever merges later needs a small rebase.

How it was tested

  • Not run in game: tests only. Why: a shader translation fix, measured with translate --list --validate and unit tests; no game run was made with this branch.

Checks run on this branch:

  • cargo test --workspace --locked: no new failure compared with main
  • cargo clippy --workspace --all-targets --locked -- -D warnings
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings
  • cargo xtask policy

New unit tests, each failing before the change:

  • emit::lower::tests::a_view_picked_from_the_heap_for_its_address_reads_it_from_the_host
  • structure::tests::a_register_joining_a_mask_with_loaded_data_is_no_mask
  • descriptor::host::tests::the_slot_table_holds_each_buffer_views_address (the address follows slot writes and goes back to 0)

Full census, translate --list --validate --jobs 2 in release, main (f3c94ca) against this branch, compared program by program over 25,953 programs:

main this branch
Compute programs validated 2729 of 2734 2734 of 2734
Vertex and pixel programs validated 14111 14111
Mesh programs validated 8657 8657

The 5 CS_TraceShadowRays_* programs go from failing to validated. No program that passed now fails, and no failing program changes its cause, so the new join rule in structure.rs changes nothing else.

Memory cost: the table is one upload buffer per host view heap, in upload (shared system) memory, not dedicated video memory. It grows from 8 MiB to 24 MiB per view heap. A host view heap is made only for a shader-visible view heap the title draws with. Each of the 29 runs logged on 2026-11-26/27 shows one, the title's 1,245,184-view heap capped at 1,000,000, so the cost is 16 MiB more. A smaller extra view heap would only show at debug level; each would add another 16 MiB.

AI

  • AI-assisted (say which parts): the diagnosis, the code, the tests, the census comparison and this description were done by an AI coding agent (Claude Opus 5.5 in OpenCode).

@ShinniUwU

Copy link
Copy Markdown
Contributor

This needs a rebase on main (conflict in docs/fork-notes.md). Before it merges, two parts reach past the 5 CS_TraceShadowRays_* programs:

  1. The structure.rs change treats any join with an argument from a scalar memory load as no mask, in every shader.
  2. The slot table's upload buffer grows from 8 to 24 MiB per view heap.

Could you post full leonida translate --list --validate counts over every program for main and this branch (as on #60 and #66), showing nothing that validated before is refused now?

@sanchaton

Copy link
Copy Markdown
Contributor Author

Rebased on main (now 5f7d402 on top of f259ee5). Conflicts: the top of "Newest" in docs/fork-notes.md (this note first, every note from main kept) and the end of emit/lower.rs's test module, where #56's a_sampler_chosen_by_control_flow_samples_with_each and this branch's test were appended at the same place; both are kept. The code change is unchanged.

On the full counts: the description already has a census over every program, leonida translate --list --validate --jobs 2 in release, main at f3c94ca against this branch, compared program by program over 25,953 programs:

main this branch
Compute validated 2729 of 2734 2734 of 2734
Vertex and pixel validated 14111 14111
Mesh validated 8657 8657

No program that validated before is refused, and no refused program changes its message, so the structure.rs join rule changes nothing outside the 5 CS_TraceShadowRays_* programs. Since #56 and #60 changed lower.rs and bitcode.rs since then, I will run the same census again on the new main and on this rebased branch, and post the counts here together with clippy, the tests and the policy on 5f7d402. The machine is busy with game measurements for the next few hours, so that will come after them.

On memory: the 16 MiB is in the slot table's upload heap, not dedicated video memory, and every run logged here shows a single host view heap. If you would rather not pay it for every view heap, I can allocate the address half only when a pipeline reads a view by its address.

@sanchaton
sanchaton force-pushed the fix/r7-trace-shadow-rays branch from dd31651 to 5f7d402 Compare November 27, 2026 05:46
@ShinniUwU

Copy link
Copy Markdown
Contributor

CI fails on 5f7d402 in the asset-policy test, not in the shader code: crates/leonida-shader/src/emit/lower.rs: 524879 bytes exceeds the 524288-byte limit (591 bytes over). cargo xtask policy allows files up to 512 KiB. Could you move this PR's new code or its test out of lower.rs (for example slot_view_address and its test into a module of their own under emit/) so the file stays under the limit? The full validate counts on the current main are still wanted too.

@sanchaton
sanchaton force-pushed the fix/r7-trace-shadow-rays branch from 5f7d402 to a5a79d8 Compare November 27, 2026 06:02
The host table of element strides by heap slot (SLOT_STRIDES) goes on with two dwords per slot: the title address of its buffer view (SLOT_VIEW_ADDRESSES), written with the stride. view_address reads it for a descriptor picked from the heap at a computed index. A join of a lane mask with a dword from a scalar memory load is no lane mask. The 5 CS_TraceShadowRays_* programs translate and validate.
@ShinniUwU
ShinniUwU force-pushed the fix/r7-trace-shadow-rays branch from a5a79d8 to 1c6bf53 Compare November 27, 2026 06:37
@ShinniUwU
ShinniUwU merged commit 718e5cc into ProjectLeonidaL:main Nov 27, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants