Repository navigation
shader: fixed buffer loads through built CODE descriptors can read below the code table - #197
Conversation
…table low A load through a descriptor the code builds around s_getpc_b64 reads the descriptor's base plus the load's own byte offset, which can lie below the base (a sub against s_getpc_b64). Tracking recorded only the base, so the constant table started after it and the load's index rebased below the table and clamped to its last dword: the wrong value. Track the effective byte of fixed loads through a CODE descriptor (Resources::code_reads) and let code_table_start see it. Fixes #135
No program of the 751- and 2,912-shader dumps changes, so the switch is the only way to get the pre-fix table start back.
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the
Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. Walkthrough
Change: Bug fix · Severity of issue fixed: Medium Merge Risk:
|
A translation cached with the switch on was served to a run with it unset and the other way round (CodeRabbit on #197).
|
Fixed in 554d89b: |
The cache key moved to victory_shader::emit::settings_bytes, so the switch goes in its SWITCHES list (the key_tests test checks it) and the edit to shader_cache.rs is main's.
|
Re-measured after merging hub/main (HEAD 3b54914, base 6e0b5da): |
|
merged main in d61f82e: kept the CODE-descriptor buffer-load fix; descriptors are traced at the instruction's site. cargo xwin clippy --workspace --all-targets -D warnings green. |
|
gates: victory-gpu tests under Wine (VICTORY_TEST_ADAPTER=hw, RADV, native dxgi, --test-threads=1) or victory-shader on Linux — victory-shader 201 passed, 0 failed, no 'skipped: no device'. |
Fixes #135.
What
code_table_start(crates/victory-shader/src/emit/lower.rs) picks the first byte of the constant table from the trackedCODEaddresses: every 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, so the byte the load reads can lie below the base. Tracking recorded only the base, the table started there, and the load's index then rebased below the table and clamped to its last dword — a wrong constant where the code before the table-start change read the right one.crates/victory-shader/src/resource.rs:Resources::code_readsrecords the effective byte (address.offset.wrapping_add(load offset)) of a load through a builtCODEdescriptor whose own offset is fixed (soffsetNULL); thedescriptorclosure intracknow returns the source it classified so thes_buffer_*arm can see it.crates/victory-shader/src/emit/lower.rs:code_dwordchainscode_readsinto theminthat sets the table's first byte. Dynamic terms are unchanged (the entry carriesaddress.dynamic, as before, and thelowestclamp stays).Test
crates/victory-shader/src/emit/lower/tests/code_table.rs, hand-built words:s_getpc_b64+s_add_u32 0x7cbuilds a descriptor whose base is0x80, ands_buffer_load_dword s12, s[8:11], -64reads byte0x40, below the base. The test asserts the table starts at0x40and holds the code from there.code_readsentry the same words giveleft: 128, right: 64: that is the bug, reproduced.crates/victory-shader/src/emit/lower.rs:1262).Gates
cargo test -p victory-shader: 188 passed, 0 failed, 2 ignored (unchanged).cargo xwin clippy --target x86_64-pc-windows-msvc --workspace --all-targets -- -D warnings: clean.offline-check.shonxcl-bin/shaders-dump: 751/751 programs ok through all four stages (translation, dxil-spirv, spirv-val, RADV pipeline), so 751 pipelines. DXIL changed: 0/751.offline-check.shonxcl-bin/victory-run: 2912/2912 translated; 2909/2912 ok through all four stages (pipelines ≥ 2909). DXIL changed: 0/2912. The 3 (compute-559d9f0184e15fe3,compute-a1b20bc47e3c9597,compute-e8c962358d862e3f) segfault insidedxil-spirvon DXIL byte-identical to main's (checked program by program), so they are the converter's pre-existing crash, not this change: they fail on main's DXIL too, and older reports show the same three.cargo xtask policy: 245 files ok;git grep -iE "gta ?(vi|6)|grand theft|rockstar": empty.Off switch
VICTORY_CODE_READS=0— the table starts at the descriptor's base again, as before. No program of either dump changes, so the switch has nothing to change on those; it is there if a title program's code table comes out wrong in a run.Not tested in a game run.
Summary by CodeRabbit