Shader: a load through a built CODE descriptor starts the constant table at the byte it reads #3155
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!3155
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3155"
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?
@pablogonz12 on GitHub · 2026-11-26 10:27 UTC · original
pablogonz12:up/197→main· +98 −8 · 3 files · 1 commits · openWhat
code_table_startpicks the first byte of the program's constant table from the trackedCODEaddresses: the scalars_load_*throughs_getpc_b64, and every built descriptor's base.A buffer load through a built
CODEdescriptor (s_buffer_load_dwordon a descriptor the code builds arounds_getpc_b64) reads its base plus the load's own byte offset, and that offset can be negative (s_sub_u32againsts_getpc_b64), so the byte the load reads can lie below the base. Only the base was recorded, the table started there, and the load's index was then rebased against a start the load never reaches: it read a dword of the table shifted by the difference, or past its end.Now
resource::trackrecords the effective byte of every fixeds_buffer_*load whose descriptor is built around the code (Resources::code_reads: base plus the load's offset,wrapping_add, so a load below the base wraps low as the instruction does), andcode_dwordlets those bytes take part in choosing the table's start. Loads whose offset is not a constant, and descriptors that are not built around the code, are untouched.Why
This is a correctness fix, not a size or speed one: the wrong dword ends up in the emitted module wherever the code does this, and the console would have read the right one.
How tested
lower::tests::code_table::the_code_table_starts_at_the_lowest_byte_a_load_reads: a program whose instructions end at0xa0, a descriptor built arounds_getpc_b64with base0x80, a buffer load reading byte0x40through it. It asserts the table starts at0x40. Without the change it fails ("the table starts at the load's byte": start0x80), so the case is real and not accepted silently.cargo xwin test -p victory-shader --lib(x86_64-pc-windows-msvc, under Wine on Linux): 215 passed, 88 failed, 3 ignored. The 88 are the tests that need an SM 6.6 D3D12 device ("no SM 6.6 device");mainon the same host gives 214 passed, 88 failed, 3 ignored - same 88, one more pass from the new test.cargo xwin clippy --workspace --all-targets --locked --target x86_64-pc-windows-msvc -- -D warnings: clean.cargo xwin check -p victory-shader --all-targets --target x86_64-pc-windows-msvc: clean.The translated DXIL is unchanged for every program that has no fixed load through a built
CODEdescriptor: the address listcode_table_startsees only gains entries in that case, andcode_readsis empty otherwise. This tree has no offline dump example, so I did not put a per-program DXIL count next to it.Other hardware
The change is in the shader translator, ahead of any adapter: it adds tracked addresses and can only move the table's start down to a byte a load actually reads, which is what the console reads. Nothing is gated on vendor or wave width, and the emitted module's layout is unchanged (same
codeconstant array and indices; only its first byte can differ).x86_64-pc-windows-msvcbuild and tests as above; not tested on NVIDIA hardware, and not run in a game.Written with an AI assistant.
@cloph-dsp on GitHub · 2026-11-26 10:40 UTC · original
Independent local verification of head
e86940con Windows 11, Rust 1.100.0/MSVC:cargo test --locked -p victory-shader --lib emit::lower::tests::code_table::the_code_table_starts_at_the_lowest_byte_a_load_reads— 1 passed, 0 failed.git diff --check origin/main HEAD— clean.I used a worktree-local
CARGO_TARGET_DIRbecause the shared target dir served a stale test binary from a different worktree of the same crate. Synthetic shader inputs only; no game assets, extracted shaders or DRM material used. AI-assisted (Hy4 flash).@Dukestar69 on GitHub · 2026-11-26 11:11 UTC · original · approved these changes
Verified against
origin/main(63bcca4):cargo test -p victory-shader --lib emit::lower::tests:: -- --test-threads=1: 34/34 passed (includingcode_table::the_code_table_starts_at_the_lowest_byte_a_load_reads).cargo clippy -p victory-shader --all-targets -- -D warnings: clean.cargo xtask policy: 192 files ok.Cleanly starts the constant table at the lowest byte read through a built
CODEdescriptor.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
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.