Shaders: an address with two computed terms is lowered, not refused (#773) #809

Manually merged
github merged 1 commit from github-bot/gh-809 into gh-pr/809/base 2026-11-29 02:17:45 +00:00 AGit
Owner

@⁠xiepeixuan on GitHub · 2026-11-28 06:34 UTC · original
xiepeixuan:codex/shader-two-address-terms-773 → main · +287 −26 · 4 files · 1 commits · merged 2026-11-29 02:13 UTC

Fixes #773

What it changes

A load was refused when its tracked base had a computed index and its scalar or VGPR offset was also computed. The run in #773 reported about 913 refused shader hashes and 200–270 dropped draws per frame.

Fix as described by @⁠traeb0n in #773

The tracer now keeps the computed base index and the computed instruction offset separately, and lowering adds both to the static byte offset. PC-relative tables and shortcuts that prove a single computed term keep their existing restrictions.

Rebased on d4b5d517; the only conflict was in emit/lower.rs (kept main's new tests next to this PR's test hook). The new Address uses on main (emit/lds.rs, wave64_tests.rs) need no change.

Workspace audit

dynamic2 is present only when dynamic is present. I found three direct arithmetic consumers of Address::dynamic, all in lowering; heap indexing is arithmetic on the original instruction operands, not on those fields.

Use Verdict
resource.rs: Address, Source::Built, Resources::scalar, track Both terms travel with the address. Derived equality includes both, and the scalar-site collection and lowerer lookup copy the entire value.
resource.rs: Tracer::address, flat_address, smem_address, by_address, classify, test helper at The first two computed terms come from the traced base and instruction offset, in that order. Sum still represents one input expression; its .dynamic reads (including base diagnosis and the PC-join recognizer) are not Address reads. The s_getpc_b64 path still refuses two terms, MEMORY and static test addresses have neither, and classification of a built descriptor passes no extra term.
resource.rs: root_indexed_view, first_lane_offset, fetched Both one-term shortcuts refuse a second term. Fetched descriptor dwords must now agree on (param, dynamic, dynamic2) as well as line up at their byte offsets.
resource.rs: anywhere (Built and Loaded) and lane_copies They require dynamic.is_none() for the constant-address shortcuts; that excludes dynamic2. Lane-copy equality also sees both terms. Existing single-term and static test assertions retain their original meaning.
emit/lower.rs: flat, code_smem, built_offset flat adds both byte terms. code_smem keeps the single-term code-table arithmetic and explicitly refuses a second term. built_offset adds both terms and then any root-view bias; smem and buffer consume the combined result once.
emit/lower.rs: heap_index, fetched_index, lane_heap_index The scalar path uses the SGPR base, instruction immediate, descriptor dword offset and real soffset; the fetched path uses its SGPR/VGPR address operands and immediate. Both shift the resulting byte address for the descriptor size. Address is used for the root-kind check only; the lane dispatcher combines these real indices.
emit/lower.rs: entry, sized_view, view_address, descriptor_data Static entry/size/address shortcuts exclude dynamic addresses. The image-size-only branch infers descriptor kind, not an index. descriptor_data compares whole addresses for equivalent loads; its static lane-copy branch is guarded by the tracer’s proof.
emit/lower.rs: code_dword, smem and flat dispatch, memory_smem, memory_flat code_dword finds the start of the code table from the static offsets; the code-table path still cannot carry two terms. CODE/MEMORY checks select the lowering route, and raw-memory lowering reconstructs the address from the real operands.
emit/lower.rs: used_kind, root_address, root_memory, handle, raw_twin, slot_word Root and binding metadata are separate from the address arithmetic. used_kind uses the existing static table-range anchor, not the run-time index. Root-memory lowering receives the already-combined offset; heap handles, twins and slot words use operand-derived indices.
apps/victory/src/translate.rs: tally_resources (scalar and Built) Both .dynamic uses count dynamic addresses, not terms, so the invariant makes the old predicates correct. I changed the root-layout lookup to skip both sentinels: an accepted two-computation load with no traced base can use MEMORY and still be classified as a descriptor source before lowering.
victory-gpu/src/picked.rs: stores_picked; downstream RootIndexedView consumers The picked-UAV test needs only the heap kind or the presence of a dynamic address, so it already handles two terms. Draw/cache consumers get a RootIndexedView only after the one-term guard. Other workspace Address names and .dynamic fields (descriptor allocation and tally counters) are unrelated.

How it was tested

  • GPU and profile (Series X or S, resolution, DLSS, frame generation, ray tracing): None; unit tests only.
  • Before: upstream main at d4b5d517: Linux 249 passed and Windows 348 passed, zero failures.
  • After: rebased 3b864508: Linux 255 passed and Windows 354 passed, zero failures. The ignored counts stayed at two on Linux and eight on Windows.
  • For shader changes, the wave sizes tested (32 and/or 64 lanes): 32 lanes (wave32) for the six new address regressions; this PR adds no wave64 address regression.
  • cargo test passed for the crates it touches: Yes — cargo test -p victory-shader --lib (Linux, Windows). Windows cargo check --workspace --locked also passed.

The six synthetic cases check the scalar table index, the global root-SRV byte offset, PC-relative refusal, both one-term shape guards, and raw-memory fallback. The offset tests evaluate emitted operands with known user-data inputs. Full CI hit the same two Clippy diagnostics in lower.rs as plain main.

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches. Related: #716 (raw title-memory address classification), #550 (code-table placement), #1074 (sampled slot marking), and #865 (lane-index lowering). None lowers a tracked address with both a computed base index and a computed instruction offset.

AI-assisted (Codex). Not run in the game here. Unit-tested in victory-shader.

**@⁠xiepeixuan** on GitHub · 2026-11-28 06:34 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/809) `xiepeixuan:codex/shader-two-address-terms-773` → `main` · +287 −26 · 4 files · 1 commits · merged 2026-11-29 02:13 UTC Fixes #773 ## What it changes A load was refused when its tracked base had a computed index and its scalar or VGPR offset was also computed. The run in #773 reported about 913 refused shader hashes and 200–270 dropped draws per frame. Fix as described by @⁠traeb0n in #773 The tracer now keeps the computed base index and the computed instruction offset separately, and lowering adds both to the static byte offset. PC-relative tables and shortcuts that prove a single computed term keep their existing restrictions. Rebased on d4b5d517; the only conflict was in emit/lower.rs (kept main's new tests next to this PR's test hook). The new Address uses on main (emit/lds.rs, wave64_tests.rs) need no change. ### Workspace audit `dynamic2` is present only when `dynamic` is present. I found three direct arithmetic consumers of `Address::dynamic`, all in lowering; heap indexing is arithmetic on the original instruction operands, not on those fields. | Use | Verdict | | --- | --- | | `resource.rs`: `Address`, `Source::Built`, `Resources::scalar`, `track` | Both terms travel with the address. Derived equality includes both, and the scalar-site collection and lowerer lookup copy the entire value. | | `resource.rs`: `Tracer::address`, `flat_address`, `smem_address`, `by_address`, `classify`, test helper `at` | The first two computed terms come from the traced base and instruction offset, in that order. `Sum` still represents **one** input expression; its `.dynamic` reads (including base diagnosis and the PC-join recognizer) are not `Address` reads. The `s_getpc_b64` path still refuses two terms, `MEMORY` and static test addresses have neither, and classification of a built descriptor passes no extra term. | | `resource.rs`: `root_indexed_view`, `first_lane_offset`, `fetched` | Both one-term shortcuts refuse a second term. Fetched descriptor dwords must now agree on `(param, dynamic, dynamic2)` as well as line up at their byte offsets. | | `resource.rs`: `anywhere` (`Built` and `Loaded`) and `lane_copies` | They require `dynamic.is_none()` for the constant-address shortcuts; that excludes `dynamic2`. Lane-copy equality also sees both terms. Existing single-term and static test assertions retain their original meaning. | | `emit/lower.rs`: `flat`, `code_smem`, `built_offset` | `flat` adds both byte terms. `code_smem` keeps the single-term code-table arithmetic and explicitly refuses a second term. `built_offset` adds both terms and then any root-view bias; `smem` and `buffer` consume the combined result once. | | `emit/lower.rs`: `heap_index`, `fetched_index`, `lane_heap_index` | The scalar path uses the SGPR base, instruction immediate, descriptor dword offset and real `soffset`; the fetched path uses its SGPR/VGPR address operands and immediate. Both shift the resulting byte address for the descriptor size. `Address` is used for the root-kind check only; the lane dispatcher combines these real indices. | | `emit/lower.rs`: `entry`, `sized_view`, `view_address`, `descriptor_data` | Static entry/size/address shortcuts exclude dynamic addresses. The image-size-only branch infers descriptor kind, not an index. `descriptor_data` compares whole addresses for equivalent loads; its static lane-copy branch is guarded by the tracer’s proof. | | `emit/lower.rs`: `code_dword`, `smem` and `flat` dispatch, `memory_smem`, `memory_flat` | `code_dword` finds the start of the code table from the static offsets; the code-table path still cannot carry two terms. `CODE`/`MEMORY` checks select the lowering route, and raw-memory lowering reconstructs the address from the real operands. | | `emit/lower.rs`: `used_kind`, `root_address`, `root_memory`, `handle`, `raw_twin`, `slot_word` | Root and binding metadata are separate from the address arithmetic. `used_kind` uses the existing static table-range anchor, not the run-time index. Root-memory lowering receives the already-combined offset; heap handles, twins and slot words use operand-derived indices. | | `apps/victory/src/translate.rs`: `tally_resources` (scalar and `Built`) | Both `.dynamic` uses count dynamic **addresses**, not terms, so the invariant makes the old predicates correct. I changed the root-layout lookup to skip both sentinels: an accepted two-computation load with no traced base can use `MEMORY` and still be classified as a descriptor source before lowering. | | `victory-gpu/src/picked.rs`: `stores_picked`; downstream `RootIndexedView` consumers | The picked-UAV test needs only the heap kind or the presence of a dynamic address, so it already handles two terms. Draw/cache consumers get a `RootIndexedView` only after the one-term guard. Other workspace `Address` names and `.dynamic` fields (descriptor allocation and tally counters) are unrelated. | ## How it was tested - GPU and profile (Series X or S, resolution, DLSS, frame generation, ray tracing): None; unit tests only. - Before: upstream `main` at `d4b5d517`: Linux **249 passed** and Windows **348 passed**, zero failures. - After: rebased `3b864508`: Linux **255 passed** and Windows **354 passed**, zero failures. The ignored counts stayed at two on Linux and eight on Windows. - For shader changes, the wave sizes tested (32 and/or 64 lanes): **32 lanes (wave32)** for the six new address regressions; this PR adds no wave64 address regression. - `cargo test` passed for the crates it touches: Yes — `cargo test -p victory-shader --lib` ([Linux](https://github.com/xiepeixuan/VIctory-NVIDIA/actions/runs/46198215476/job/141144187879), [Windows](https://github.com/xiepeixuan/VIctory-NVIDIA/actions/runs/46198215476/job/141144188077)). Windows `cargo check --workspace --locked` also passed. The six synthetic cases check the scalar table index, the global root-SRV byte offset, PC-relative refusal, both one-term shape guards, and raw-memory fallback. The offset tests evaluate emitted operands with known user-data inputs. Full CI hit the same two Clippy diagnostics in `lower.rs` as [plain main](https://github.com/xiepeixuan/VIctory-NVIDIA/actions/runs/46198215476/job/141144188060). ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. Related: #716 (raw title-memory address classification), #550 (code-table placement), #1074 (sampled slot marking), and #865 (lane-index lowering). None lowers a tracked address with both a computed base index and a computed instruction offset. AI-assisted (Codex). Not run in the game here. Unit-tested in victory-shader.
Fix as described by @traeb0n in #773. Keep code-table and one-term shape restrictions, and exercise emitted offsets with synthetic shaders.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-28 06:35:12 +00:00
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-28 07:08 UTC · original · approved these changes

Tested locally merged onto main (63b902f).

  • Merge & Policy: Clean merge; cargo xtask policy passed (294 files ok).
  • Tests:
    • cargo test -p victory-shader --lib emit::lower::tests:: passed (17 passed; 0 failed; 1 ignored, including global_load_adds_the_root_view_index_and_computed_vgpr_offset and scalar_table_load_uses_the_base_index_and_computed_soffset).
    • cargo test -p victory-shader --lib emit::tests:: passed (22 passed; 0 failed; 1 ignored).
    • cargo test -p victory-shader --lib resource:: passed (42 passed; 0 failed, including a_pc_relative_address_still_refuses_two_computed_terms and a_first_lane_offset_does_not_prove_a_two_term_address).
  • Lint & App Check: cargo clippy -p victory-shader --lib -- -D warnings passed with 0 warnings; cargo check -p victory --tests succeeded cleanly.

Solid generalization of two-term computed address lowering while preserving the strict PC-relative and first-lane guards. LGTM.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

**@⁠Dukestar69** on GitHub · 2026-11-28 07:08 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/809#pullrequestreview-6096405883) · **approved these changes** Tested locally merged onto `main` (`63b902f`). - **Merge & Policy**: Clean merge; `cargo xtask policy` passed (`294 files ok`). - **Tests**: - `cargo test -p victory-shader --lib emit::lower::tests::` passed (`17 passed; 0 failed; 1 ignored`, including `global_load_adds_the_root_view_index_and_computed_vgpr_offset` and `scalar_table_load_uses_the_base_index_and_computed_soffset`). - `cargo test -p victory-shader --lib emit::tests::` passed (`22 passed; 0 failed; 1 ignored`). - `cargo test -p victory-shader --lib resource::` passed (`42 passed; 0 failed`, including `a_pc_relative_address_still_refuses_two_computed_terms` and `a_first_lane_offset_does_not_prove_a_two_term_address`). - **Lint & App Check**: `cargo clippy -p victory-shader --lib -- -D warnings` passed with 0 warnings; `cargo check -p victory --tests` succeeded cleanly. Solid generalization of two-term computed address lowering while preserving the strict PC-relative and first-lane guards. LGTM. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Author
Owner

@⁠jptorres96 on GitHub · 2026-11-28 09:16 UTC · original

Tested on top of main: cargo test -p victory-shader --lib → 299 passed, 0 failed, 5 ignored. No regressions.

Env: RTX 4080 SUPER (driver 621.01), Ryzen 5 5600X, Windows build 26300, rustc 1.98.1, DXC 1.9.2609.5 (VICTORY_DXIL), --test-threads=1. VICTORY_INDIRECT_REST=1 set to sidestep main's two indirect budget-test failures (fixed in #67), unrelated to this PR.

**@⁠jptorres96** on GitHub · 2026-11-28 09:16 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/809#issuecomment-7237128932) Tested on top of main: `cargo test -p victory-shader --lib` → 299 passed, 0 failed, 5 ignored. No regressions. Env: RTX 4080 SUPER (driver 621.01), Ryzen 5 5600X, Windows build 26300, rustc 1.98.1, DXC 1.9.2609.5 (`VICTORY_DXIL`), `--test-threads=1`. `VICTORY_INDIRECT_REST=1` set to sidestep main's two indirect budget-test failures (fixed in #67), unrelated to this PR.
github-bot force-pushed github-bot/gh-809 from 73d9691d9b to 3b8645086b 2026-11-28 23:08:17 +00:00 Compare
github-bot referenced this pull request from a commit 2026-11-29 00:27:22 +00:00
github-bot changed target branch from main to gh-pr/809/base 2026-11-29 02:17:44 +00:00
github manually merged commit 3b8645086b into gh-pr/809/base 2026-11-29 02:17:45 +00:00
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/trustno1-coder--VIctory-NVIDIA!809
No description provided.