Skip to content

perf(shader): prove first-lane inputs from fixed code-table loads - #714

Open
GDemay wants to merge 1 commit into
pragyaangaur:mainfrom
GDemay:codex/first-lane-proof
Open

GDemay wants to merge 1 commit into
pragyaangaur:mainfrom
GDemay:codex/first-lane-proof

Conversation

@GDemay

@GDemay GDemay commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

Summary

For #553, treat scalar results as wave-uniform when an unguarded load in wave-uniform control flow reads a fixed, aligned range entirely inside the shader's private code data. The proof shares the scalar load width decoder with lowering. Existing scalar and vector rules propagate the fact and checks for inactive destinations and other halves requirements still apply.

Performance

Metric Before After Change
One embedded first-lane read, median completion 2.126 ms 1.946 ms −0.180 ms (−8.48%)
Eight reads feeding scalar branches, median completion 2.105 ms 2.041 ms −0.064 ms (−3.02%), inconclusive
Scalar control, median completion 2.003 ms 1.968 ms −0.035 ms (−1.76%), control
Varying-source fallback, median completion 2.062 ms 2.162 ms +0.099 ms (+4.82%), noisy control
Workload Before mode / barriers / DXIL bytes After mode / barriers / DXIL bytes
Embedded halves / 3 / 2,764 per-lane / 0 / 2,380
Eight reads halves / 17 / 3,508 per-lane / 0 / 2,692
Scalar control per-lane / 0 / 2,308 per-lane / 0 / 2,308
Varying source halves / 3 / 2,728 halves / 3 / 2,728

Apple M5 (Mac17,2, 24 GiB), macOS 27.0 (26A428), CrossOver Wine 11.0,
D3DMetal 4.0 beta 3, Rust 1.98.1, x86_64-pc-windows-gnullvm release. Pinned
main 27380446e227799438b2c41693426ebb5c5e4420 versus
2db44ab1a64e447e054731dcaf5aaef4716373b1. Both builds run the same four
original shaders at 8,192 groups × 128 lanes. Four batches per arm, ABBA/BAAB,
three warm-up and 15 measured dispatches per workload per process, with no
concurrent builds. Timer starts before command-list submission through a
fence event. It includes list uploads and copies and excludes translation,
pipeline creation, command recording and readback mapping. No GPU timestamps.

The single-read fixture was faster in all four paired batch medians. Its
middle 50% went from 1.986–2.270 to 1.745–2.105 ms. Eight reads had a slow
candidate batch which also affected the unchanged varying-source control.
The timing effect of the eight-read workload remains inconclusive. The four
process-level translation setup medians were 2,146 → 2,102 μs for the first
fixture and 479 → 372 μs for the eight-read fixture. These small samples
are descriptive. Driver register pressure and game frame time were unmeasured.

All 576 dispatches, including the 96 within-process warm-ups, matched
603,979,776 independently calculated output dwords. The checks expect 17 in
the simple and scalar control fixtures, lane + 576 in the eight-read fixture,
and the console-wave first lane's ID (0 or 64) in the varying-source fixture.

Verification

Final head passed native workspace (859 passed, 23 ignored), full serial Wine
workspace (1,782 passed, 58 ignored), Windows-gnullvm Clippy with default and
all features, and the asset policy (365 files).

The strict Wine/D3DMetal test exercised 36 additional dispatches at 64, 96
and 128 threads, with lower-only, upper-only, both-half and empty EXEC. It
checked 27,648 output dwords including the raw first-lane value, branch
result, guarded store and restored-mask stores. The structural test and
emitted pipeline metadata check that short-table, mutable, and stale-lane
cases retain the fallback. The native test rejects proof when only the
second word of a two-dword load falls outside the code table.

cargo test -p victory-shader a_fixed_code_smem_load
WINE=/absolute/path/to/target/wine-cx/bin/wine \
WINEDLLOVERRIDES="d3d12,d3d12core,dxgi=b" \
tools/macos/test-wine.sh -p victory-shader bounded_code_scalar \
  -- --include-ignored --nocapture --test-threads=1

For matched timing, copy the PR's test-only files into a worktree at the
pinned baseline (everything in this PR except emit/lower.rs,
emit/lower/halves.rs and emit/lower/tests.rs). Build and save both test binary
paths before sampling, with separate targets:

cargo test -p victory-shader --lib --release \
  --target x86_64-pc-windows-gnullvm --no-run --message-format=json

With the checkout's Wine and WINEDLLOVERRIDES=d3d12,d3d12core,dxgi=b, run
each binary once to warm the runtime. Then run each serially in ABBA/BAAB order
with emit::first_lane_bench::embedded_code_first_lane_gpu_completion --exact --ignored --nocapture --test-threads=1. Record the sample lines (nanoseconds)
and mode setup lines. Unset VICTORY_WARP.

Scope

The public culling analysis traces eight first-lane inputs per shader to
LDS reads feeding scalar branches. The CODE proof could help a code-derived
address or scalar operand where the existing LDS stability checks already
hold. Coverage of 87bf9e3f2bf2f052,
9f017d9011377efa, 0452fc2d2e2fc4c3 and the wider set of 29 programs is
unverified. Related prior proof work is in #671 by 0b101010-lab. No title
shaders or game assets were used.

A game owner can run victory translate --wave32 --list --jobs 1 on the
same private inputs at both commits with the three hashes in
VICTORY_TRANSLATE_ONLY. Keep the emitted DXIL local, count emitted
dx.op.barrier calls, and report hash, before/after mode, proof site and
load width, and any translation failure in text. A fixed-scene follow-up
can use a prewarmed cache per binary, the same save, settings and still
input replay, alternating AB and BA with 120 warm-up and 300 measured
frames. Compare frame median and tail, useful draw and dispatch counts
(VICTORY_DISPATCH_CENSUS=1), and visual correctness locally.

Reuse scalar lowering’s address and width rules to admit in-bounds private code data to lane uniformity. Require common control flow and retain existing EXEC checks and fallback.

Related proof work: pragyaangaur#671 (0b101010-lab).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant