Skip to content

Game: recover depth-bounds-enabled states in pipeline prebuild - #3040

Closed
fuzeofficlal wants to merge 1 commit into
Marvisak:mainfrom
fuzeofficlal:fix/game-pipelines-depth-bounds
Closed

fuzeofficlal wants to merge 1 commit into
Marvisak:mainfrom
fuzeofficlal:fix/game-pipelines-depth-bounds

Conversation

@fuzeofficlal

Copy link
Copy Markdown
Contributor

Problem

crates/victory-game/src/pipelines.rs documents compact depth-stencil byte 15 as depth-bounds test and serializes c[15] into D3D12_DEPTH_STENCIL_DESC1.DepthBoundsTestEnable at offset 0x34 (which victory-gpu now honors on the host after #158).

However, when Named::find recovers depth-stencil states not present in an SGD5 database:

  • depth_from_registers reads DB_DEPTH_CONTROL bits 0..2, 4..10, and 20..22 but skips bit 3 (DEPTH_BOUNDS_ENABLE), leaving b[15] = 0.
  • depth_space also leaves b[15] = 0.

As a result, any graphics pipeline in a shader pack whose depth-stencil state enables the depth bounds test misses both register recovery and fallback enumeration, so Named::find fails to resolve its hash and prebuild skips it as Unnamed::DepthStencil.

Fix

  • Decode DB_DEPTH_CONTROL bit 3 (control >> 3 & 1) into compact byte 15 in depth_from_registers. When depth_on is false and bit 3 is clear, try both 0 and 1 (mirroring how depth_on == false enumerates depth enable/write/func in case the driver cleared DB_DEPTH_CONTROL without a depth target).
  • Enumerate b[15] in [0, 1] for the stencil-off loop in depth_space (+128 candidates, leaving the 2.5M stencil-on enumeration unchanged).

Verification

  • cargo test --locked -p victory-game (17 passed, including new unit tests covering depth_from_registers, depth_space, and end-to-end Named::find + stream recovery of a depth-bounds-enabled graphics record with no databases)
  • cargo test --locked -p victory (18 passed)
  • cargo clippy --locked -p victory-game -p victory --all-targets -- -D warnings
  • rustfmt --edition 2024 --check crates/victory-game/src/pipelines.rs
  • cargo xtask policy (191 files ok)

`pipelines::depth_stencil_desc` already serializes compact depth-stencil
byte 15 into `D3D12_DEPTH_STENCIL_DESC1.DepthBoundsTestEnable` (used by
`victory-gpu` after Marvisak#158), but both `depth_from_registers` and the
stencil-off fallback enumeration in `depth_space` always left byte 15 at
zero.

Decode `DB_DEPTH_CONTROL` bit 3 (`DEPTH_BOUNDS_ENABLE`) in
`depth_from_registers` (and try both `0` and `1` when the hardware depth
test bit is off, matching the existing depth-enable/write/func recovery),
and include `b[15] in [0, 1]` in the stencil-off `depth_space` fallback.
@fuzeofficlal

Copy link
Copy Markdown
Contributor Author

Note for maintainers: #3048 (stacked on #3047) also addresses b[15] recovery in depth_from_registers alongside b[14] and stencil fields (trying b[15] in 0..=1 even when DB_DEPTH_CONTROL bit 3 is clear). Happy to close this in favour of #3048 if the #3047/#3048 stack is preferred, or keep this as the standalone b[15] + depth_space patch.

@kotekompotek kotekompotek 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.

Verified: control >> 3 & 1 is the console's DB_DEPTH_CONTROL depth-bounds bit; the bounds choice is conservative in the right direction — [1] when set, [0] when depth is on without it (a description claiming otherwise would be wrong), [0,1] only when depth is fully off and the registers can't keep it. The stencil-off mask re-emit is preserved per bounds value, and the end-to-end pack→name→stream test asserts DepthBoundsTestEnable lands in the pipeline stream.

Maintainer note: this and #3048 implement the same depth-bounds recovery in depth_space/depth_from_registers on different bases — the second to merge will conflict; whichever direction the stack takes, the other needs rebasing.

@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 origin/main (63bcca4) on Windows 11 x64:

  • Diff review: Adding depth-bounds (b[15]) coverage to depth_space and decoding DB_DEPTH_CONTROL bit 3 in depth_from_registers (emitting both 0 and 1 when depth test is off and bit 3 is cleared) cleanly recovers depth-bounds-enabled states during pipeline prebuild.
  • cargo test -p victory-game: 17 passed, 0 failed (including registers_name_depth_bounds_states and named_find_recovers_depth_bounds_pipeline_from_registers).
  • cargo clippy -p victory-game --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

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

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

The gap is real. In crates/victory-game/src/pipelines.rs, depth_from_registers and depth_space never set compact byte 15 (the depth-bounds test), so a state with it set cannot be named. Reading DB_DEPTH_CONTROL bit 3 as DEPTH_BOUNDS_ENABLE matches the public register layout. Two things stand in the way of merging it as is:

The tests use synthetic registers and a synthetic pack only, with no title data, which is fine.


Generated by Claude Code

@fuzeofficlal

Copy link
Copy Markdown
Contributor Author

Closing in favour of #3048 (stacked on #3047), which already covers b[15] in depth_from_registers unconditionally with measured shader-pack results.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants