Shaders: pixel programs the console depth-tests before they run declare early depth (glass prepass over characters) #907

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

@⁠SpaghettiMaster545 on GitHub · 2026-11-25 12:23 UTC · original
SpaghettiMaster545:pr/early-depth → main · +110 −1 · 4 files · 1 commits · open

What was wrong

A pixel program's DB_SHADER_CONTROL (in its native record) says whether the console runs the depth and stencil tests before the shader: bit 12, DEPTH_BEFORE_SHADER, which the console compiler sets for HLSL [earlydepthstencil]. The translation never declared it, so the host tested after the shader, and a program that writes unordered views wrote them for pixels the depth test then rejected.

How it shows in game

The glass prepass (PS_AlphaPrepass, DB_SHADER_CONTROL 0x1450) writes the glass's depth and motion to a view. With late tests it wrote them for every pixel of a window pane, including a character standing in front of it, and PS_AlphaVelocityDepthResolve then copied those over the character's depth and motion vectors. Inside each pane the character lost her depth and motion (rectangles cut out of the depth and velocity targets) and moved with ghosted, staircase-edged smears.

What the change does

Pixel programs with DEPTH_BEFORE_SHADER set get ShaderFlags ForceEarlyDepthStencil (bit 3), unless they export depth, stencil or coverage. 3,023 of the pack's 12,101 pixel programs have the bit (DB_SHADER_CONTROL 0x1050: 1,718, 0x1450: 705, 0x1010: 380, 0x1410: 220). victory shader-info now prints a pixel program's DB_SHADER_CONTROL, which is how they were counted.

How it was tested

  • New test a_pixel_program_tested_before_it_runs_declares_early_depth; cargo test --locked -p victory-shader --lib passes on this branch (216 passed, 3 ignored).
  • cargo clippy -p victory-shader --all-targets --locked -- -D warnings is clean. (A workspace-wide clippy fails on main already, in victory-gpu: placed_filler_twins unused, sort_unstable_by_key, is_multiple_of; this change does not touch that crate.)
  • Game runs: the cut-out rectangles and smears behind window panes are gone.
  • GPU and driver: NVIDIA GeForce RTX 5070 Ti, driver 621.40, Windows 11.

Developed with AI assistance (Claude Code).

**@⁠SpaghettiMaster545** on GitHub · 2026-11-25 12:23 UTC · [original](https://github.com/fxceless/victory-fork/pull/907) `SpaghettiMaster545:pr/early-depth` → `main` · +110 −1 · 4 files · 1 commits · open ## What was wrong A pixel program's DB_SHADER_CONTROL (in its native record) says whether the console runs the depth and stencil tests before the shader: bit 12, DEPTH_BEFORE_SHADER, which the console compiler sets for HLSL `[earlydepthstencil]`. The translation never declared it, so the host tested after the shader, and a program that writes unordered views wrote them for pixels the depth test then rejected. ## How it shows in game The glass prepass (`PS_AlphaPrepass`, DB_SHADER_CONTROL 0x1450) writes the glass's depth and motion to a view. With late tests it wrote them for every pixel of a window pane, including a character standing in front of it, and `PS_AlphaVelocityDepthResolve` then copied those over the character's depth and motion vectors. Inside each pane the character lost her depth and motion (rectangles cut out of the depth and velocity targets) and moved with ghosted, staircase-edged smears. ## What the change does Pixel programs with DEPTH_BEFORE_SHADER set get `ShaderFlags` ForceEarlyDepthStencil (bit 3), unless they export depth, stencil or coverage. 3,023 of the pack's 12,101 pixel programs have the bit (DB_SHADER_CONTROL 0x1050: 1,718, 0x1450: 705, 0x1010: 380, 0x1410: 220). `victory shader-info` now prints a pixel program's DB_SHADER_CONTROL, which is how they were counted. ## How it was tested - New test `a_pixel_program_tested_before_it_runs_declares_early_depth`; `cargo test --locked -p victory-shader --lib` passes on this branch (216 passed, 3 ignored). - `cargo clippy -p victory-shader --all-targets --locked -- -D warnings` is clean. (A workspace-wide clippy fails on `main` already, in `victory-gpu`: `placed_filler_twins` unused, `sort_unstable_by_key`, `is_multiple_of`; this change does not touch that crate.) - Game runs: the cut-out rectangles and smears behind window panes are gone. - GPU and driver: NVIDIA GeForce RTX 5070 Ti, driver 621.40, Windows 11. Developed with AI assistance (Claude Code).
A pixel program's DB_SHADER_CONTROL (in its native record) says whether the
console runs the depth and stencil tests before the shader: bit 12,
DEPTH_BEFORE_SHADER, which the console compiler sets for HLSL
[earlydepthstencil]. The translation never said so, so the host tested
after the shader, and a program that writes unordered views wrote them for
pixels the depth test then rejected. The title's glass prepass
(PS_AlphaPrepass, DB_SHADER_CONTROL 0x1450) writes the glass's depth and
motion to a view: with late tests it wrote them for every pixel of a
window pane, the character standing in front of it too, and
PS_AlphaVelocityDepthResolve then copied those over the character's depth
and motion vectors. Inside each pane the character lost her depth and
motion (rectangles cut out of the depth and velocity targets), and moved
with ghosted, staircase-edged smears where the pane was.

Such programs now get ShaderFlags ForceEarlyDepthStencil (bit 3), unless
they export depth, stencil or coverage. 3,023 of the pack's 12,101 pixel
programs have the bit (DB_SHADER_CONTROL 0x1050 1,718, 0x1450 705, 0x1010
380, 0x1410 220; counted with shader-info, which now prints a pixel
program's DB_SHADER_CONTROL).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 291bdc4ff1df5694c3dec9a7801ea0b3da3a045a)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:53:35 +00:00
Author
Owner

@⁠avt0m4t48 on GitHub · 2026-11-25 12:31 UTC · original

Independent synthetic check of 6f358fc6 against a2537066. GitHub's test merge has the same tree as the checked head.

  • In the eligible color shader, setting only DB_SHADER_CONTROL bit 12 changed DXIL entry-point ShaderFlags from 0x0 to 0x8. The disassembled instructions, signatures, PSV0 and SFI0 were identical.
  • The other 15 cases emitted byte-identical containers across the two revisions. These cover the late color control, each of the four DB export bits individually, and actual exports of SV_Depth, SV_DepthLessEqual, SV_DepthGreaterEqual, SV_StencilRef and SV_Coverage, each with bit 12 unset and set. The stencil output retained its existing ShaderFlags 0x800 and SFI0 0x200.
  • The untouched head passed the Linux shader suite (172 passed, 2 ignored) and MSVC cross-target cargo check --all-targets -p victory-shader -p victory --features blake3/pure. The cross-check emitted the existing placed_filler_twins warning in victory-gpu.

The color fixture uses the GFX10 words 7e0002f0 7e020287 f800180f 00000000 bf810000 and an OSG1 signature with one float4 SV_Target. LLVM 19 read a copy of each DXIL module with the legacy i8 alignment spelling adapted for disassembly. Microsoft DXIL validation, native Windows execution, and depth-tested UAV writes on a D3D12 device remain unverified by this check. No game files were used.

**@⁠avt0m4t48** on GitHub · 2026-11-25 12:31 UTC · [original](https://github.com/fxceless/victory-fork/pull/907#issuecomment-7162481647) Independent synthetic check of `6f358fc6` against `a2537066`. GitHub's test merge has the same tree as the checked head. - In the eligible color shader, setting only DB_SHADER_CONTROL bit 12 changed DXIL entry-point ShaderFlags from `0x0` to `0x8`. The disassembled instructions, signatures, PSV0 and SFI0 were identical. - The other 15 cases emitted byte-identical containers across the two revisions. These cover the late color control, each of the four DB export bits individually, and actual exports of `SV_Depth`, `SV_DepthLessEqual`, `SV_DepthGreaterEqual`, `SV_StencilRef` and `SV_Coverage`, each with bit 12 unset and set. The stencil output retained its existing ShaderFlags `0x800` and SFI0 `0x200`. - The untouched head passed the Linux shader suite (172 passed, 2 ignored) and MSVC cross-target `cargo check --all-targets -p victory-shader -p victory --features blake3/pure`. The cross-check emitted the existing `placed_filler_twins` warning in `victory-gpu`. The color fixture uses the GFX10 words `7e0002f0 7e020287 f800180f 00000000 bf810000` and an OSG1 signature with one float4 `SV_Target`. LLVM 19 read a copy of each DXIL module with the legacy i8 alignment spelling adapted for disassembly. Microsoft DXIL validation, native Windows execution, and depth-tested UAV writes on a D3D12 device remain unverified by this check. No game files were used.
Author
Owner

@⁠iGoldenNinja on GitHub · 2026-11-25 12:53 UTC · original

Independent native Windows result for PR head 6f358fc6, integrated as 74becd8. RTX 5080 16 GB, 617.14, Windows 11 Pro 25H2 build 26200.9974, Ryzen 9 5900X, 32 GB RAM. Base bbc35d0 and candidate both emitted, validated and created D3D12 test pipelines for ten alpha prepass shaders bound in the baseline. All ten show DB_SHADER_CONTROL=0x1450. The native early-depth test passed, and all ten matching programs built and bound during the candidate's successful run.

Both reached the controllable Series X prison view. At 2542 × 1396 before the same replayed pan, the candidate showed wall detail and a smaller dark shoulder band. Mean encoded luma in the same 250 × 120 wall region was 7.39 and 44.87, respectively. Indirect draw windows were off in both of these captures. The captures are from separate launches with different shader-cache history and idle poses. Direct depth and motion target validation remains open.

One earlier candidate launch failed a 1 MiB host allocation at world entry, with minimum sampled commit headroom around 0.01 GiB. The same executable reached the view on an isolated retry with a fresh profile copy and its warm cache, and ended deliberately with no logged device removal. Revisions and results. Testing and reporting assisted by OpenAI Codex.

**@⁠iGoldenNinja** on GitHub · 2026-11-25 12:53 UTC · [original](https://github.com/fxceless/victory-fork/pull/907#issuecomment-7163005516) Independent native Windows result for PR head `6f358fc6`, integrated as `74becd8`. RTX 5080 16 GB, 617.14, Windows 11 Pro 25H2 build 26200.9974, Ryzen 9 5900X, 32 GB RAM. Base `bbc35d0` and candidate both emitted, validated and created D3D12 test pipelines for ten alpha prepass shaders bound in the baseline. All ten show `DB_SHADER_CONTROL=0x1450`. The native early-depth test passed, and all ten matching programs built and bound during the candidate's successful run. Both reached the controllable Series X prison view. At 2542 × 1396 before the same replayed pan, the candidate showed wall detail and a smaller dark shoulder band. Mean encoded luma in the same 250 × 120 wall region was 7.39 and 44.87, respectively. Indirect draw windows were off in both of these captures. The captures are from separate launches with different shader-cache history and idle poses. Direct depth and motion target validation remains open. One earlier candidate launch failed a 1 MiB host allocation at world entry, with minimum sampled commit headroom around 0.01 GiB. The same executable reached the view on an isolated retry with a fresh profile copy and its warm cache, and ended deliberately with no logged device removal. [Revisions and results](https://github.com/iGoldenNinja/victory-fork/blob/367c754479a8ff4933ff1f1e521c9af468f72b3c/docs/rtx5080-early-depth-and-draw-windows.md). Testing and reporting assisted by OpenAI Codex.
Author
Owner

@⁠naixue2233 on GitHub · 2026-11-25 15:19 UTC · original

Heads up from a Windows 10 host, in case it saves someone else a power cycle. I am not claiming the change is wrong — I am reporting what happened and offering data.

I merged this (6f358fc) into a fork on top of #867 + #916 and ran the title on Windows 10 19045, RTX 3080 (driver 32.0.16.1742), --console series-x, the same scene and flags as the run before it. The machine then went down hard and had to be power-cycled, twice:

  • Kernel-Power 41 — "the system has rebooted without cleanly shutting down first" — with no BugCheck 1001 and no bugcheck code anywhere in the log. The box hung; it did not bugcheck.
  • No VIctory crash log, no unhandled exception in the run log (victory_gpu=info); frames were still being presented when the machine stopped responding.
  • The build from before this merge (6a6d66e, identical environment variables and scene) ran the same prologue corridor for about forty minutes with no hang. Three such unexpected shutdowns happened tonight in total; the two that I can line up with a build carry this change.

What makes me suspect an interaction rather than a wrong flag: 3,023 programs switch from testing depth after the shader to testing it before, while the title's prepasses are exactly the ones that also write unordered views in that same pass. Any ordering mistake there is a read/write hazard between a pass and the pass that consumes its targets, and this title's glass prepass (PS_AlphaPrepass) feeds several resolves.

I have reverted the merge in my fork for now (dcdbccb, everything else kept) so that I can test the rest of the stack. Two questions:

  1. Has anyone seen a device hang, TDR or hard lock with this on NVIDIA? nvidia-smi is not usable on this box, so I cannot show a TDR counter — only that there is no bugcheck.
  2. Do you want the data? I can attach the run log and the D3D12 debug-layer output for the programs with DB_SHADER_CONTROL 0x1050 / 0x1450, including the resource-state and barrier lines around PS_AlphaPrepass and its resolves.

If you want to bisect from your side, a narrowed variant would be cheap for me to test: only 0x1050, or only programs that write no unordered view. Happy to run either.

**@⁠naixue2233** on GitHub · 2026-11-25 15:19 UTC · [original](https://github.com/fxceless/victory-fork/pull/907#issuecomment-7166674262) Heads up from a Windows 10 host, in case it saves someone else a power cycle. I am **not** claiming the change is wrong — I am reporting what happened and offering data. I merged this (`6f358fc`) into a fork on top of `#867` + `#916` and ran the title on **Windows 10 19045, RTX 3080 (driver 32.0.16.1742), `--console series-x`**, the same scene and flags as the run before it. The machine then went down hard and had to be power-cycled, twice: - `Kernel-Power 41` — "the system has rebooted without cleanly shutting down first" — with **no `BugCheck 1001`** and no bugcheck code anywhere in the log. The box hung; it did not bugcheck. - No VIctory crash log, no `unhandled exception` in the run log (`victory_gpu=info`); frames were still being presented when the machine stopped responding. - The build from *before* this merge (`6a6d66e`, identical environment variables and scene) ran the same prologue corridor for about forty minutes with no hang. Three such unexpected shutdowns happened tonight in total; the two that I can line up with a build carry this change. What makes me suspect an interaction rather than a wrong flag: 3,023 programs switch from testing depth after the shader to testing it before, while the title's prepasses are exactly the ones that also write unordered views in that same pass. Any ordering mistake there is a read/write hazard between a pass and the pass that consumes its targets, and this title's glass prepass (`PS_AlphaPrepass`) feeds several resolves. I have reverted the merge in my fork for now (`dcdbccb`, everything else kept) so that I can test the rest of the stack. Two questions: 1. Has anyone seen a device hang, TDR or hard lock with this on NVIDIA? `nvidia-smi` is not usable on this box, so I cannot show a TDR counter — only that there is no bugcheck. 2. Do you want the data? I can attach the run log and the D3D12 debug-layer output for the programs with `DB_SHADER_CONTROL` `0x1050` / `0x1450`, including the resource-state and barrier lines around `PS_AlphaPrepass` and its resolves. If you want to bisect from your side, a narrowed variant would be cheap for me to test: only `0x1050`, or only programs that write no unordered view. Happy to run either.
Author
Owner

@⁠SpaghettiMaster545 on GitHub · 2026-11-25 15:34 UTC · original

Thanks for the report. To your two questions:

  1. We have not seen a hang, TDR or hard lock with this change on the RTX 5070 Ti (NVIDIA 621.40, Windows 11), in the prologue or in the world. That does not rule out an interaction on other drivers. Your driver 32.0.16.1742 is 617.42.
  2. Yes, please. The D3D12 debug-layer output around PS_AlphaPrepass and its resolves (resource states and barriers) would help most. Please leave out shader code.

On the narrowed variants: the programs that matter here are the ones that write unordered views. Without them the flag only moves the test, so "only programs that write no unordered view" would leave out the fix itself. "Only 0x1050" is a useful split, though, because the glass prepass is 0x1450. If it helps you A/B without rebuilding, I can add a switch that turns the flag off.

**@⁠SpaghettiMaster545** on GitHub · 2026-11-25 15:34 UTC · [original](https://github.com/fxceless/victory-fork/pull/907#issuecomment-7167064348) Thanks for the report. To your two questions: 1. We have not seen a hang, TDR or hard lock with this change on the RTX 5070 Ti (NVIDIA 621.40, Windows 11), in the prologue or in the world. That does not rule out an interaction on other drivers. Your driver 32.0.16.1742 is 617.42. 2. Yes, please. The D3D12 debug-layer output around `PS_AlphaPrepass` and its resolves (resource states and barriers) would help most. Please leave out shader code. On the narrowed variants: the programs that matter here are the ones that write unordered views. Without them the flag only moves the test, so "only programs that write no unordered view" would leave out the fix itself. "Only `0x1050`" is a useful split, though, because the glass prepass is `0x1450`. If it helps you A/B without rebuilding, I can add a switch that turns the flag off.
Author
Owner

@⁠Exopus-0x65f7ad0 on GitHub · 2026-11-26 14:36 UTC · original

Tested on an RTX 5060 Ti 8 GB (Windows 11, 16 GB RAM, Series S profile). I ported it onto our tree (fork main plus PRs). There were two small conflicts: flags in shader.rs, where RAW_BUFFERS already exists, and the signature lines in Lower::new. a_pixel_program_tested_before_it_runs_declares_early_depth passes.

In game I ran one warm-up run after the translator change, then the same scripted walk: cell window, dormitory windows, corridor, up to the guard room. Results:

  • Lucia's hair stays clean in front of the panes. Before, it went grey and grainy with staircase edges near the windows.
  • The door and window panes show what is behind them without smears.
  • No device loss and no new refused pipelines.

AI-assisted (Claude Code). Counts and descriptions only, nothing from the game.

**@⁠Exopus-0x65f7ad0** on GitHub · 2026-11-26 14:36 UTC · [original](https://github.com/fxceless/victory-fork/pull/907#issuecomment-7195052507) Tested on an RTX 5060 Ti 8 GB (Windows 11, 16 GB RAM, Series S profile). I ported it onto our tree (fork main plus PRs). There were two small conflicts: `flags` in `shader.rs`, where `RAW_BUFFERS` already exists, and the signature lines in `Lower::new`. `a_pixel_program_tested_before_it_runs_declares_early_depth` passes. In game I ran one warm-up run after the translator change, then the same scripted walk: cell window, dormitory windows, corridor, up to the guard room. Results: - Lucia's hair stays clean in front of the panes. Before, it went grey and grainy with staircase edges near the windows. - The door and window panes show what is behind them without smears. - No device loss and no new refused pipelines. AI-assisted (Claude Code). Counts and descriptions only, nothing from the game.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
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/907/head:github-bot/gh-907'
git switch 'github-bot/gh-907'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-907'
git switch 'github-bot/gh-907'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-907'
git switch 'github-bot/gh-907'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-907'
git switch 'main'
git merge --squash 'github-bot/gh-907'
git switch 'main'
git merge --ff-only 'github-bot/gh-907'
git switch 'main'
git merge 'github-bot/gh-907'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.