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

Closed
fuzeofficlal wants to merge 1 commit from upstream-pr/3040 into main
fuzeofficlal commented 2026-11-26 04:57:27 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T04:57:27Z.


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)
<!-- greyfinch-sync:Marvisak/VIctory:issue:6619833591 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3040). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T04:57:27Z. --- ### 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)
kotekompotek commented 2026-11-26 06:03:25 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-26T05:28:13Z.

Review: APPROVED


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.

<!-- greyfinch-sync:Marvisak/VIctory:review:6068984013 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3040#pullrequestreview-6068984013). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-26T05:28:13Z. **Review:** APPROVED --- 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 commented 2026-11-26 06:03:25 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T05:28:51Z.

Review: APPROVED


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

<!-- greyfinch-sync:Marvisak/VIctory:review:6068988315 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3040#pullrequestreview-6068988315). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T05:28:51Z. **Review:** APPROVED --- 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).
fuzeofficlal commented 2026-11-26 06:03:40 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T05:20:39Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7183401250 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3040#issuecomment-7183401250). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T05:20:39Z. --- 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.
upstream-sync closed this pull request 2026-11-26 07:01:21 +00:00
Marvisak commented 2026-11-26 07:01:44 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T06:15:11Z.


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 decision rule rests on an assumption with no evidence behind it. When depth is on and bit 3 is clear, depth_from_registers tries only b[15] = 0. #3048 measured shaders.rpf and reports the opposite: several descriptions set b14/b15 while DEPTH_BOUNDS_ENABLE is clear, so it tries both values in every case. If that measurement holds, this PR still misses those states. Please give evidence for the rule (states from a shader pack it names that are otherwise unnamed), or try both values as #3048 does.
  • It overlaps #3048, which is stacked on #3047 and changes the same function with measured results. Only one approach should land. You already offered to step back in favour of #3048. The part #3048 does not cover is the depth_space enumeration of b[15]. If that is worth keeping, a rebase on top of #3048 with a pack measurement showing that it names something would make this a clear, separate change.

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


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7184243817 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3040#issuecomment-7184243817). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-26T06:15:11Z. --- <!-- victory-triage v1 head=5130555f184bc4bc16704d3adf04bba80fa1ac83 verdict=needs-work at=2026-11-26T06:24:00Z --> 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 decision rule rests on an assumption with no evidence behind it.** When depth is on and bit 3 is clear, `depth_from_registers` tries only `b[15] = 0`. #3048 measured `shaders.rpf` and reports the opposite: several descriptions set b14/b15 while `DEPTH_BOUNDS_ENABLE` is clear, so it tries both values in every case. If that measurement holds, this PR still misses those states. Please give evidence for the rule (states from a shader pack it names that are otherwise unnamed), or try both values as #3048 does. - **It overlaps #3048**, which is stacked on #3047 and changes the same function with measured results. Only one approach should land. You already offered to step back in favour of #3048. The part #3048 does not cover is the `depth_space` enumeration of `b[15]`. If that is worth keeping, a rebase on top of #3048 with a pack measurement showing that it names something would make this a clear, separate change. The tests use synthetic registers and a synthetic pack only, with no title data, which is fine. --- _Generated by [Claude Code](https://claude.ai/code)_
fuzeofficlal commented 2026-11-26 07:01:50 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T06:26:25Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7184430816 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3040#issuecomment-7184430816). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T06:26:25Z. --- Closing in favour of #3048 (stacked on #3047), which already covers `b[15]` in `depth_from_registers` unconditionally with measured shader-pack results.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!3038
No description provided.