Shaders: restore early-Z on sampled-mark-only pixel shaders and batch uniform marks #4713

Open
github-bot wants to merge 1 commit from github-bot/gh-4712 into main AGit
Owner

@⁠nidea1 on GitHub · 2026-12-01 03:10 UTC · original
nidea1:perf/shader-sampled-marks-early-z-and-batching → main · +578 −19 · 3 files · 1 commits · open

What it changes

Fixes two DXIL lowering costs introduced by VICTORY_SAMPLED_MARKS=1 (SLOT_SAMPLED) without disabling sampled-slot tracking or sacrificing eviction accuracy:

  1. Restores ShaderFlags::EARLY_DEPTH_STENCIL on pixel shaders whose only UAV is SLOT_SAMPLED:

    • Binding SLOT_SAMPLED adds a UAV to otherwise UAV-free pixel shaders, causing D3D12/NVIDIA hardware to disable automatic early-Z and shade occluded pixels in full.
    • Tracks descriptor-heap UAV creation via Shader::has_heap_uav (crates/victory-shader/src/emit/shader.rs) and real pixel discards via Lower::emitted_real_discard (crates/victory-shader/src/emit/lower.rs, distinct from the loop-cap abort_block safety exit).
    • Restores flags::EARLY_DEPTH_STENCIL only when all safety preconditions hold: pixel shader, neither EARLY_DEPTH_STENCIL nor ROVS already set, !writes_uavs, !has_heap_uav, !emitted_real_discard, root_uavs == [SLOT_SAMPLED] (single root UAV), console DB_SHADER_CONTROL selected an early-Z order (Z_ORDER 1 | 3 or DEPTH_BEFORE_SHADER) with none of KILL_ENABLE / COVERAGE_TO_MASK_ENABLE / EXEC_ON_HIER_FAIL / EXEC_ON_NOOP / CONSERVATIVE_Z_EXPORT / PRIMITIVE_ORDERED_PIXEL_SHADER set, and early_depth_of(...) == EarlyDepth::Given (no depth/stencil/coverage exports).
  2. Batches wave-uniform sampled-slot marks per basic block under one waveIsFirstLane guard:

    • Queues wave-uniform (!per_lane) sampled-slot indices in Lower::block_marks and flushes them together inside a single waveIsFirstLane guard (flush_block_marks / emit_sampled_mark) before whole-wave sections, s_barrier, pixel Exp exports, and block exits, keeping back-to-back texture fetches unsplit while still marking every slot.
    • Adds no new environment variables (shader_cache.rs untouched).

How it was tested

  • GPU and profile (Series X or S, resolution, DLSS, frame generation, ray tracing): RTX 3060 Ti 8 GB / 32 GB RAM, Series S profile, DLSS Quality, FSR 3 frame generation (--fg-type fsr --framegen 3), ray tracing off, VICTORY_SAMPLED_EVICT=1, VICTORY_WINDOW_GROW=1, VICTORY_POOL_SMALL=0, VICTORY_RIPE_BLOCKS=12, VICTORY_AMBIENT=0.8, VICTORY_AMBIENT_SPECULAR=1.
  • Before: Pixel shaders using SLOT_SAMPLED as their only UAV lost early-Z (EARLY_DEPTH_STENCIL unset), and each wave-uniform texture fetch emitted its own waveIsFirstLane guard splitting texture fetches.
  • After:
    • Unit, census, compute GPU/WARP, and graphics PSO tests in crates/victory-shader/src/emit/waterfall_tests.rs verify: (a) two distinct uniform sampled slots in one block share a single wave_op (waveIsFirstLane) while still marking both slots on GPU/WARP, and s_barrier flushes queued marks before the barrier; (b) EARLY_DEPTH_STENCIL is restored on safe SLOT_SAMPLED-only pixel shaders (including ones with loop-cap abort_block), and stays off when marks are disabled, when the console asks for LATE_Z/RE_Z or kill/coverage/depth export, or when any real discard or other UAV is present.
    • Live soak (measured on the combined 14-branch local optimization stack on 7d93ee0759 rather than isolated A/B): offline warm --used --jobs 4 stored 2,396/2,396 pipelines cleanly (189.7 s), and a 12-minute (720.7 s in-world, 16,447 frames) uncontested soak passed with 0 crashes, 0 device losses, 0 Victory errors, 0 >100 ms hitches in the final 8.7 minutes, and visually verified start (+31 s), mid (+361 s), and end (+701 s) frames with clean depth ordering and zero alpha-to-coverage/foliage/hair artifacts.
  • For shader changes, the wave sizes tested (32 and/or 64 lanes): Wave32 (wave64: false in the new waterfall_tests.rs unit/GPU/WARP tests and RTX 3060 Ti Wave32 live soak). Wave64 was not tested on AMD hardware.
  • cargo test passed for the crates it touches: yes (on e3f4f708, base 7d93ee0759)
    • New tests in crates/victory-shader/src/emit/waterfall_tests.rs: sampled_marks_batch_uniform_slots_and_mark_every_slot_on_gpu and sampled_marks_restore_early_depth_only_when_safe_in_pixel_shaders (included in the victory-shader test run on e3f4f708).
    • cargo build --release --locked -j 4 -p victory (0 warnings) and cargo xtask policy passed on 7d93ee0759.
    • Note: current main (5fabb46e) has 5 pre-existing clippy errors in crates/victory-gpu/src/host/{font,menu,panel}.rs from #4634 (tracked in #4679 / #4707); this PR does not touch those files.

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches. Related: #4507, #3501, #3641, #4174, #4037
    • #4506 works around VICTORY_SAMPLED_MARKS=1 GPU cost by disabling it by default; this PR addresses the DXIL lowering root cause so sampled marks remain cheap without losing eviction tracking.
    • #3501 deduplicates repeated SLOT_SAMPLED marks (guard_depth == 0) — complementary; does not batch distinct uniform slots under one waveIsFirstLane or restore early-Z.
    • #3641 / #4173 add page write marks (VICTORY_VIEW_MARKS=1); if a second root UAV is bound for write marks, root_uavs.len() == 1 here keeps early-Z safely off.
    • #4037, #4680, and #4683 touch lower.rs / shader.rs for unrelated features with no functional overlap.
**@⁠nidea1** on GitHub · 2026-12-01 03:10 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4712) `nidea1:perf/shader-sampled-marks-early-z-and-batching` → `main` · +578 −19 · 3 files · 1 commits · open ## What it changes Fixes two DXIL lowering costs introduced by `VICTORY_SAMPLED_MARKS=1` (`SLOT_SAMPLED`) without disabling sampled-slot tracking or sacrificing eviction accuracy: 1. **Restores `ShaderFlags::EARLY_DEPTH_STENCIL` on pixel shaders whose only UAV is `SLOT_SAMPLED`:** - Binding `SLOT_SAMPLED` adds a UAV to otherwise UAV-free pixel shaders, causing D3D12/NVIDIA hardware to disable automatic early-Z and shade occluded pixels in full. - Tracks descriptor-heap UAV creation via `Shader::has_heap_uav` (`crates/victory-shader/src/emit/shader.rs`) and real pixel discards via `Lower::emitted_real_discard` (`crates/victory-shader/src/emit/lower.rs`, distinct from the loop-cap `abort_block` safety exit). - Restores `flags::EARLY_DEPTH_STENCIL` only when all safety preconditions hold: pixel shader, neither `EARLY_DEPTH_STENCIL` nor `ROVS` already set, `!writes_uavs`, `!has_heap_uav`, `!emitted_real_discard`, `root_uavs == [SLOT_SAMPLED]` (single root UAV), console `DB_SHADER_CONTROL` selected an early-Z order (`Z_ORDER` `1 | 3` or `DEPTH_BEFORE_SHADER`) with none of `KILL_ENABLE` / `COVERAGE_TO_MASK_ENABLE` / `EXEC_ON_HIER_FAIL` / `EXEC_ON_NOOP` / `CONSERVATIVE_Z_EXPORT` / `PRIMITIVE_ORDERED_PIXEL_SHADER` set, and `early_depth_of(...) == EarlyDepth::Given` (no depth/stencil/coverage exports). 2. **Batches wave-uniform sampled-slot marks per basic block under one `waveIsFirstLane` guard:** - Queues wave-uniform (`!per_lane`) sampled-slot indices in `Lower::block_marks` and flushes them together inside a single `waveIsFirstLane` guard (`flush_block_marks` / `emit_sampled_mark`) before whole-wave sections, `s_barrier`, pixel `Exp` exports, and block exits, keeping back-to-back texture fetches unsplit while still marking every slot. - Adds no new environment variables (`shader_cache.rs` untouched). ## How it was tested - GPU and profile (Series X or S, resolution, DLSS, frame generation, ray tracing): RTX 3060 Ti 8 GB / 32 GB RAM, Series S profile, DLSS Quality, FSR 3 frame generation (`--fg-type fsr --framegen 3`), ray tracing off, `VICTORY_SAMPLED_EVICT=1`, `VICTORY_WINDOW_GROW=1`, `VICTORY_POOL_SMALL=0`, `VICTORY_RIPE_BLOCKS=12`, `VICTORY_AMBIENT=0.8`, `VICTORY_AMBIENT_SPECULAR=1`. - Before: Pixel shaders using `SLOT_SAMPLED` as their only UAV lost early-Z (`EARLY_DEPTH_STENCIL` unset), and each wave-uniform texture fetch emitted its own `waveIsFirstLane` guard splitting texture fetches. - After: - Unit, census, compute GPU/WARP, and graphics PSO tests in `crates/victory-shader/src/emit/waterfall_tests.rs` verify: (a) two distinct uniform sampled slots in one block share a single `wave_op` (`waveIsFirstLane`) while still marking both slots on GPU/WARP, and `s_barrier` flushes queued marks before the barrier; (b) `EARLY_DEPTH_STENCIL` is restored on safe `SLOT_SAMPLED`-only pixel shaders (including ones with loop-cap `abort_block`), and stays off when marks are disabled, when the console asks for `LATE_Z`/`RE_Z` or kill/coverage/depth export, or when any real discard or other UAV is present. - Live soak (measured on the combined 14-branch local optimization stack on `7d93ee0759` rather than isolated A/B): offline `warm --used --jobs 4` stored `2,396/2,396` pipelines cleanly (`189.7 s`), and a 12-minute (`720.7 s` in-world, `16,447` frames) uncontested soak passed with `0` crashes, `0` device losses, `0` Victory errors, `0` `>100 ms` hitches in the final `8.7` minutes, and visually verified start (`+31 s`), mid (`+361 s`), and end (`+701 s`) frames with clean depth ordering and zero alpha-to-coverage/foliage/hair artifacts. - For shader changes, the wave sizes tested (32 and/or 64 lanes): Wave32 (`wave64: false` in the new `waterfall_tests.rs` unit/GPU/WARP tests and RTX 3060 Ti Wave32 live soak). Wave64 was not tested on AMD hardware. - `cargo test` passed for the crates it touches: yes (on `e3f4f708`, base `7d93ee0759`) - New tests in `crates/victory-shader/src/emit/waterfall_tests.rs`: `sampled_marks_batch_uniform_slots_and_mark_every_slot_on_gpu` and `sampled_marks_restore_early_depth_only_when_safe_in_pixel_shaders` (included in the `victory-shader` test run on `e3f4f708`). - `cargo build --release --locked -j 4 -p victory` (0 warnings) and `cargo xtask policy` passed on `7d93ee0759`. - Note: current `main` (`5fabb46e`) has 5 pre-existing clippy errors in `crates/victory-gpu/src/host/{font,menu,panel}.rs` from `#4634` (tracked in `#4679` / `#4707`); this PR does not touch those files. ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. Related: #4507, #3501, #3641, #4174, #4037 - `#4506` works around `VICTORY_SAMPLED_MARKS=1` GPU cost by disabling it by default; this PR addresses the DXIL lowering root cause so sampled marks remain cheap without losing eviction tracking. - `#3501` deduplicates repeated `SLOT_SAMPLED` marks (`guard_depth == 0`) — complementary; does not batch distinct uniform slots under one `waveIsFirstLane` or restore early-Z. - `#3641` / `#4173` add page write marks (`VICTORY_VIEW_MARKS=1`); if a second root UAV is bound for write marks, `root_uavs.len() == 1` here keeps early-Z safely off. - `#4037`, `#4680`, and `#4683` touch `lower.rs` / `shader.rs` for unrelated features with no functional overlap.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 03:16:15 +00:00
Author
Owner

@⁠Aniseto on GitHub · 2026-12-01 07:23 UTC · original

Ran the gpu_profile tests at 3ef4593d on an NVIDIA Blackwell desktop part with 16 GB of VRAM.

Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, 16 GB, mesh shaders) driver 32.0.16.2140 (621.40), Intel Core i5-12400F, 64 GB RAM, rustc 1.100.0 (0ef1bc386 2026-11-09), MSVC 14.44.35207, DXC 1.9.2609.5, debug build, XCL_ADAPTER=NVIDIA, detached worktree at the exact PR head, no local patches.

XCL_ADAPTER=NVIDIA cargo test -q -p xcl --lib gpu_profile::tests -- --test-threads=1
3 passed; 0 failed; 0 ignored; 2767 filtered out      (exit 0)

XCL_ADAPTER=NVIDIA cargo test -q -p xcl --lib gpu_profile::tests::compute_lists_are_timed_only_when_asked -- --test-threads=1
1 passed; 0 failed; 0 ignored; 2769 filtered out      (exit 0)

Both counts match the new test of the description and the three tests in that module at this exact head; the named test passes on this adapter.

Not tested: the full workspace suite, the standalone D3D12 reproduction of the driver bug, a title run with XCL_GPU_PROFILE=1 on a compute queue, an A/B against a build without the change, AMD and Intel GPUs, Wine, native wave64 hosts, release profile, game data.

AI-assisted (OpenCode), model: MiMo-V2.6-Flash Free - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified; no game data was used.

**@⁠Aniseto** on GitHub · 2026-12-01 07:23 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4712#issuecomment-7304008751) Ran the `gpu_profile` tests at `3ef4593d` on an NVIDIA Blackwell desktop part with 16 GB of VRAM. Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, 16 GB, mesh shaders) driver 32.0.16.2140 (621.40), Intel Core i5-12400F, 64 GB RAM, rustc 1.100.0 (0ef1bc386 2026-11-09), MSVC 14.44.35207, DXC 1.9.2609.5, debug build, `XCL_ADAPTER=NVIDIA`, detached worktree at the exact PR head, no local patches. ``` XCL_ADAPTER=NVIDIA cargo test -q -p xcl --lib gpu_profile::tests -- --test-threads=1 3 passed; 0 failed; 0 ignored; 2767 filtered out (exit 0) XCL_ADAPTER=NVIDIA cargo test -q -p xcl --lib gpu_profile::tests::compute_lists_are_timed_only_when_asked -- --test-threads=1 1 passed; 0 failed; 0 ignored; 2769 filtered out (exit 0) ``` Both counts match the new test of the description and the three tests in that module at this exact head; the named test passes on this adapter. Not tested: the full workspace suite, the standalone D3D12 reproduction of the driver bug, a title run with `XCL_GPU_PROFILE=1` on a compute queue, an A/B against a build without the change, AMD and Intel GPUs, Wine, native wave64 hosts, release profile, game data. AI-assisted (OpenCode), model: **MiMo-V2.6-Flash Free** - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified; no game data was used.
Author
Owner

@⁠Aniseto on GitHub · 2026-12-01 07:24 UTC · original

This supersedes my immediately preceding comment in this thread (#4713). That body was the wrong local draft, posted because two publishes shared one temporary file; please disregard it. This is the measured report for e3f4f708.

Ran the two named waterfall_tests cases and the whole module at e3f4f708 on an NVIDIA Blackwell desktop part with 16 GB of VRAM.

Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, 16 GB, mesh shaders) driver 32.0.16.2140 (621.40), Intel Core i5-12400F, 64 GB RAM, rustc 1.100.0 (0ef1bc386 2026-11-09), MSVC 14.44.35207, DXC 1.9.2609.5, debug build, detached worktree at the exact PR head, own CARGO_TARGET_DIR, no local patches.

cargo test -q -p victory-shader --lib sampled_marks_batch_uniform_slots_and_mark_every_slot_on_gpu -- --test-threads=1
1 passed; 0 failed; 0 ignored; 547 filtered out      (exit 0)

cargo test -q -p victory-shader --lib sampled_marks_restore_early_depth_only_when_safe_in_pixel_shaders -- --test-threads=1
1 passed; 0 failed; 0 ignored; 547 filtered out      (exit 0)

cargo test -q -p victory-shader --lib waterfall_tests -- --test-threads=1
10 passed; 0 failed; 0 ignored; 538 filtered out      (exit 0)

Both new cases of the description pass here, as does the whole module (10 tests). This adapter is wave32 only; the description's GPU/WARP checks and its 12-minute soak were done on a different stack, so the two synthetic cases here are a second host for the wave32 path, not a repeat of the soak.

Not tested: the full workspace suite, the offline warm --used precompile, the live 12-minute title soak, WARP as a separate device, wave64 and AMD hardware, DLSS/frame generation, a title that supplies SLOT_SAMPLED marks, release profile, game data.

AI-assisted (OpenCode), model: MiMo-V2.6-Flash Free - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified; no game data was used.

**@⁠Aniseto** on GitHub · 2026-12-01 07:24 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4712#issuecomment-7304024611) This supersedes my immediately preceding comment in this thread (https://git.gtahub.st/github/trustno1-coder--VIctory-NVIDIA/pulls/4713). That body was the wrong local draft, posted because two publishes shared one temporary file; please disregard it. This is the measured report for `e3f4f708`. Ran the two named `waterfall_tests` cases and the whole module at `e3f4f708` on an NVIDIA Blackwell desktop part with 16 GB of VRAM. Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, 16 GB, mesh shaders) driver 32.0.16.2140 (621.40), Intel Core i5-12400F, 64 GB RAM, rustc 1.100.0 (0ef1bc386 2026-11-09), MSVC 14.44.35207, DXC 1.9.2609.5, debug build, detached worktree at the exact PR head, own `CARGO_TARGET_DIR`, no local patches. ``` cargo test -q -p victory-shader --lib sampled_marks_batch_uniform_slots_and_mark_every_slot_on_gpu -- --test-threads=1 1 passed; 0 failed; 0 ignored; 547 filtered out (exit 0) cargo test -q -p victory-shader --lib sampled_marks_restore_early_depth_only_when_safe_in_pixel_shaders -- --test-threads=1 1 passed; 0 failed; 0 ignored; 547 filtered out (exit 0) cargo test -q -p victory-shader --lib waterfall_tests -- --test-threads=1 10 passed; 0 failed; 0 ignored; 538 filtered out (exit 0) ``` Both new cases of the description pass here, as does the whole module (10 tests). This adapter is wave32 only; the description's GPU/WARP checks and its 12-minute soak were done on a different stack, so the two synthetic cases here are a second host for the wave32 path, not a repeat of the soak. Not tested: the full workspace suite, the offline `warm --used` precompile, the live 12-minute title soak, WARP as a separate device, wave64 and AMD hardware, DLSS/frame generation, a title that supplies `SLOT_SAMPLED` marks, release profile, game data. AI-assisted (OpenCode), model: **MiMo-V2.6-Flash Free** - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified; no game data was used.
Author
Owner

@⁠nidea1 on GitHub · 2026-12-01 09:36 UTC · original

Thanks @⁠Aniseto for verifying e3f4f708 on an RTX 5070 Ti (Blackwell Wave32) and confirming both new cases and the full waterfall_tests module pass (10/10). Having independent Wave32 hardware confirmation alongside our earlier checks is very helpful.

**@⁠nidea1** on GitHub · 2026-12-01 09:36 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4712#issuecomment-7306944661) Thanks @⁠Aniseto for verifying `e3f4f708` on an RTX 5070 Ti (Blackwell Wave32) and confirming both new cases and the full `waterfall_tests` module pass (`10/10`). Having independent Wave32 hardware confirmation alongside our earlier checks is very helpful.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
The changes on this branch are already on the target branch. This will be an empty commit.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/4713/head:github-bot/gh-4712'
git switch 'github-bot/gh-4712'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-4712'
git switch 'github-bot/gh-4712'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-4712'
git switch 'github-bot/gh-4712'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-4712'
git switch 'main'
git merge --squash 'github-bot/gh-4712'
git switch 'main'
git merge --ff-only 'github-bot/gh-4712'
git switch 'main'
git merge 'github-bot/gh-4712'
git push origin 'main'
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!4713
No description provided.