Skip to content

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

Open
xiepeixuan wants to merge 1 commit into
trustno1-coder:mainfrom
xiepeixuan:codex/shader-two-address-terms-773
Open

xiepeixuan wants to merge 1 commit into
trustno1-coder:mainfrom
xiepeixuan:codex/shader-two-address-terms-773

Conversation

@xiepeixuan

@xiepeixuan xiepeixuan commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

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 d4b5d51; 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

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

@xiepeixuan
xiepeixuan marked this pull request as ready for review November 28, 2026 06:38

@Dukestar69 Dukestar69 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

MystifiedSky pushed a commit to MystifiedSky/VIctory-NVIDIA-Improved that referenced this pull request Nov 28, 2026
@jptorres96

Copy link
Copy Markdown

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.

Fix as described by @traeb0n in trustno1-coder#773. Keep code-table and one-term shape restrictions, and exercise emitted offsets with synthetic shaders.
@xiepeixuan
xiepeixuan force-pushed the codex/shader-two-address-terms-773 branch from 73d9691 to 3b86450 Compare November 28, 2026 23:03
@xiepeixuan xiepeixuan changed the title Shaders: an address with two computed terms is lowered, not refused (#773) [pr-fix][shaders] Shaders: an address with two computed terms is lowered, not refused (#773) Nov 28, 2026
@github-actions github-actions Bot added pr-fix Pull request: fixes a bug shaders Shader translation, preload or pipeline building labels Nov 28, 2026
@github-actions github-actions Bot changed the title [pr-fix][shaders] Shaders: an address with two computed terms is lowered, not refused (#773) Shaders: an address with two computed terms is lowered, not refused (#773) Nov 28, 2026
trustno1-coder added a commit that referenced this pull request Nov 29, 2026
trustno1-coder added a commit that referenced this pull request Nov 29, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5CFykxe6G44cMPrmExrcw
trustno1-coder added a commit that referenced this pull request Nov 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-fix Pull request: fixes a bug shaders Shader translation, preload or pipeline building

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Shaders: "an address with two computed terms" drops ~900 vertex/pixel programs (200–270 draws a frame); a small fix

3 participants