Shaders: LDS accesses past the program's allocation read 0 and drop writes #336
No reviewers
Labels
No labels
accessibility
already-solved
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
merged
needs-decision
needs-game-run
needs-rebase
not-merged
nvidia
obsolete
question
security
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/avatarmanz--VIctory-7900XTX!336
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-336"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@DiosET3RN0 on GitHub · 2026-11-26 17:28 UTC · original
DiosET3RN0:lds-bounds→main· +93 −12 · 4 files · 1 commits · openWhat
dslowering assumed every LDS address was in bounds(
shortcut: LDS addresses are taken as dword-aligned and in bounds). On theconsole an access past the program's LDS reads 0 and drops the write; in DXIL
an out-of-range
groupsharedindex is undefined behaviour (garbage, memorycorruption or a device hang, depending on the driver).
It is worse than plain UB here: the translator places its own dwords right
after the program's LDS (the wave64-on-32 lane exchange and the
wave_basecounter), so a title overflow silently corrupted the wave64 emulation. The
BVH traversal keeps a per-thread stack in LDS, which is exactly where such an
overflow would come from.
How
Shader::lds_title_dwords: the LDS size the console program declares (setwhere
lds_dwordsis set for CS and MS, before the layer's own dwords areadded).
ds, each dword access computesindex < lds_title_dwords, uses anindex clamped into range (always valid), and:
ds_read_*, bytes/halves, d16) give 0 out of range;ds_write_*,write2) are guarded per dword;ds_add…,cmpst,min/max_f32) do not run and return 0; lanesswitched off by EXEC keep their value, as before.
shortcut:.TRANSLATOR_VERSION1 → 2: the DXIL of every program using LDS changes, socached translations must not be reused (per the rule in
lib.rs).Tests
New GPU test
ds_past_the_program_lds_reads_zero_and_drops_writes(512-byte LDS; addresses 4 and 508 in bounds, 512, 0x10000 and 0xFFFFFFFC out).
Run on NVIDIA RTX 4060 8 GB (32-lane waves; driver 621.24, Windows 11), Rust 1.98.1:
cargo test -p victory-shader --locked ds_: all pass, the new test included(it runs on the hardware adapter; WARP refuses its
WaveSize(32)).cargo test --workspace --locked: 1029 passed, 0 failed, 45 ignored.cargo clippy -p victory-shader --all-targets --locked -- -D warnings: clean.cargo clippy --workspace ...fails onmainalready, before this change, invictory-loader/src/descriptor_sites.rs:277(transmute used without annotations, Rust 1.98.1); this PR does not touch that crate.byte 0x200 (the first out-of-range access), so it does catch the bug.
Not run in the title (no dump on this machine): it should be a no-op for well-
behaved programs; a run of
victory shaderswill report how many translationschanged.
Originally written for a fork of fxceless/victory-fork and ported here.
🤖 Generated with Claude Code
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.