Shader: a load through a built CODE descriptor starts the constant table at the byte it reads #3153
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/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?
Imported from Marvisak/VIctory. Originally posted by pablogonz12 on 2026-11-26T10:27:34Z.
What
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.
Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-26T10:40:09Z.
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).Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T11:11:16Z.
Review: APPROVED
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).
Imported from Marvisak/VIctory. Originally posted by futurepro62 on 2026-11-26T21:43:57Z.
NVIDIA full-suite run, to go with the reports above by Dukestar69, cloph-dsp, since none of them names a GPU run. Tested exact head
e86940c(on its base63bcca4).Tested
dxil.dllfrom Windows SDK 10.0.26100 (the loader's default), debug.cargo build --workspace --locked, thencargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware: 867 passed, 0 failed, 10 ignored.the_code_table_starts_at_the_lowest_byte_a_load_reads.--skipleaves out tests that fail on main63bcca4on this card too, not because of this PR:heap_direct_texture_reads_mark_their_heap_indexends thevictory-shadertest process with0xc0000005(#2571), so without the skip the rest of that crate never reports;dynamic_slots_are_held_until_released,lists_share_a_table_and_copies_keep_their_viewsand the twostride_testshit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317);gathers_at_a_level_match_the_hardwarefails on lane 0 (#1744).Not tested
AI use
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T22:20:25Z.
Review: APPROVED
Verified on
e86940c2:cargo xtask policy:192 files ok;crates/victory-shader/src/emit/lower.rssize is521,519bytes.cargo clippy --locked -p victory-shader --all-targets -- -D warnings(default and--all-features): clean.cargo test --locked -p victory-shader --lib -- --test-threads=1 resource::tests:: emit::lower:: emit::stride_tests::: 77 passed, 0 failed underVICTORY_WARP=1(includingemit::lower::tests::code_table::the_code_table_starts_at_the_lowest_byte_a_load_reads); 75 passed, 2 failed underVICTORY_WARP=0(only the two pre-existinga_heap_buffer_read_*tests atstride_tests.rs:300, 350).Recording effective
Source::BuiltCODEload addresses (address.offset.wrapping_add(*offset as u32)) intoResources::code_readscleanly fixes constant-table truncation when ans_buffer_load_*uses a negative immediate offset below the descriptor base. Three minor non-blocking notes:resource.rs:252only pushescode_readswhensoffsetisNULL, so a nonzero/constant-SGPRsoffsetstill falls back to the descriptor base alone.crates/victory-shader/src/emit/lower/tests/code_table.rs:20,0x7E02_030Cencodesv_mov_b32 v1, v12rather thanv_mov_b32 v1, s12(0x7E02_020C), though the assertions onl.code_tablestill exercise the lowering fix.rustfmt --edition 2024 --checkflags line 37 ofcode_table.rs(wrapping theassert_eq!call).LGTM.
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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.