gpu(native): preserve unselected planes in depth/stencil clears #41

Merged
shabouwcaw merged 4 commits from upstream-pr/41 into main 2026-11-26 12:58:02 +00:00
shabouwcaw commented 2026-11-26 11:08:10 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by shabouwcaw on 2026-11-26T11:08:10Z.


What this changes

Native ClearDepthStencilView discarded the stencil value and skipped stencil-only clears. Metal also cleared stencil to zero whenever depth was cleared. A depth-only clear between two stencil-tested draws therefore erased the mask and rejected the second draw.

Carry independent depth/stencil clear values through the native command list and render pass. Clear only the selected planes, preserve the other plane with Metal's load action, and use the requested stencil value. Test setup that needs both planes initialized now requests both explicitly.

This is a separate, newly reproduced graphics-state defect under ROADMAP §1. No overlapping stencil-clear PR was open when checked. The behavior follows Microsoft's ClearDepthStencilView contract. No claim is made that this explains the brightness logo or black present reports.

How it was tested

On Apple Silicon with the locally installed Metal Shader Converter, using only repository-owned HLSL and synthetic geometry:

Check Before / mutation Fixed
Depth-only clear preserves a stencil mask On original 8bf47c3, the expected green pixel stayed red Pass
Final regression tests with the old Metal clear logic restored temporarily Both new tests fail Both pass
Temporarily turn depth-only clear into a no-op Regression fails Pass

The final tests require depth to actually change, preserve stencil after a stencil-writing draw, and exercise stencil-only and combined clears with values 0, 173 and 255. Exact depth/stencil comparisons select the expected color; subsequent draws with mismatching stencil and depth must both be rejected. Command snapshots are exercised too. GPU waits retain the existing 10-second deadline. All mutations were removed.

All builds ran under nice, with at most six jobs and the configured local environment:

  • Native arm64: cargo test -j6 --locked -p victory-shader -p victory-hle -p victory -p victory-gpu -p victory-metal -p xtask: 519 passed, 0 failed, 4 ignored, including all seven native graphics-state GPU tests.
  • cargo test -j6 --locked --target x86_64-apple-darwin -p victory-hle -p victory-loader -p victory: 267 passed, 0 failed, 4 ignored, including all 16 native-probe tests under Rosetta.
  • cargo clippy -j6 --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings, also with --all-features.
  • cargo run -j6 --locked --quiet -p xtask -- policy: 363 files OK; git diff --check passed.
  • Game run not needed for this reproduction; no game files were accessed. GPU regressions exercise NativeList through Metal, not a game's COM call sequence. They follow the existing skip convention when the converter is absent; it was present for these runs.

Upstream CI run 45807790420 passed on 81dda1d: both Windows Clippy configurations and workspace tests.

Native clears are gated to full clears of mip 0 on single-layer, single-sampled 1D or 2D textures. Rectangle counts, nonzero mip slices, array views and unknown dimensions are rejected before recording, for all clear flags; default/null DSV descriptions also require a single-layer, single-sampled 1D or 2D resource. Rectangle and subresource clears remain unsupported. docs/native-host.md records the behavior and limits.

A bridge regression calls the title-facing clear ABI with real resources and descriptor records. It verifies unsupported requests record no command and supported explicit/default views still record depth-only, stencil-only and combined clears. Removing the rectangle guard or view guard independently makes the regression fail. The bridge test also preserves explicit/default TEXTURE1D base-view clears and rejects a default DSV on a multisampled resource for all three clear-flag combinations. The 1D case fails before the fix; removing the sample-count guard makes the default multisampled case fail. On 12762b1, the required local test suite passed (288 passed, 2 ignored), Windows-target Clippy passed with both default and all features, and the asset policy and whitespace checks passed.

Checklist

  • No game files, game code, disassembly listings or SDK files are included
  • No new guesses about undocumented console behavior
  • No new diagnostics
<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:6625325402 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/41). Originally posted by [shabouwcaw](https://github.com/shabouwcaw) on 2026-11-26T11:08:10Z. --- ## What this changes Native `ClearDepthStencilView` discarded the stencil value and skipped stencil-only clears. Metal also cleared stencil to zero whenever depth was cleared. A depth-only clear between two stencil-tested draws therefore erased the mask and rejected the second draw. Carry independent depth/stencil clear values through the native command list and render pass. Clear only the selected planes, preserve the other plane with Metal's load action, and use the requested stencil value. Test setup that needs both planes initialized now requests both explicitly. This is a separate, newly reproduced graphics-state defect under [ROADMAP §1](https://github.com/LakshanSivakumar/Native-Victory-macOS/blob/main/docs/ROADMAP.md#1-from-the-ui-target-to-the-window-graphics). No overlapping stencil-clear PR was open when checked. The behavior follows Microsoft's [ClearDepthStencilView contract](https://learn.microsoft.com/en-us/windows/win32/api/d3d12/nf-d3d12-id3d12graphicscommandlist-cleardepthstencilview). No claim is made that this explains the brightness logo or black present reports. ## How it was tested On Apple Silicon with the locally installed Metal Shader Converter, using only repository-owned HLSL and synthetic geometry: | Check | Before / mutation | Fixed | | --- | --- | --- | | Depth-only clear preserves a stencil mask | On original `8bf47c3`, the expected green pixel stayed red | Pass | | Final regression tests with the old Metal clear logic restored temporarily | Both new tests fail | Both pass | | Temporarily turn depth-only clear into a no-op | Regression fails | Pass | The final tests require depth to actually change, preserve stencil after a stencil-writing draw, and exercise stencil-only and combined clears with values 0, 173 and 255. Exact depth/stencil comparisons select the expected color; subsequent draws with mismatching stencil and depth must both be rejected. Command snapshots are exercised too. GPU waits retain the existing 10-second deadline. All mutations were removed. All builds ran under `nice`, with at most six jobs and the configured local environment: - [x] Native arm64: `cargo test -j6 --locked -p victory-shader -p victory-hle -p victory -p victory-gpu -p victory-metal -p xtask`: **519 passed, 0 failed, 4 ignored**, including all seven native graphics-state GPU tests. - [x] `cargo test -j6 --locked --target x86_64-apple-darwin -p victory-hle -p victory-loader -p victory`: **267 passed, 0 failed, 4 ignored**, including all 16 native-probe tests under Rosetta. - [x] `cargo clippy -j6 --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings`, also with `--all-features`. - [x] `cargo run -j6 --locked --quiet -p xtask -- policy`: **363 files OK**; `git diff --check` passed. - [x] Game run not needed for this reproduction; no game files were accessed. GPU regressions exercise `NativeList` through Metal, not a game's COM call sequence. They follow the existing skip convention when the converter is absent; it was present for these runs. Upstream [CI run 45807790420](https://github.com/LakshanSivakumar/Native-Victory-macOS/actions/runs/45807790420) passed on `81dda1d`: both Windows Clippy configurations and workspace tests. Native clears are gated to full clears of mip 0 on single-layer, single-sampled 1D or 2D textures. Rectangle counts, nonzero mip slices, array views and unknown dimensions are rejected before recording, for all clear flags; default/null DSV descriptions also require a single-layer, single-sampled 1D or 2D resource. Rectangle and subresource clears remain unsupported. `docs/native-host.md` records the behavior and limits. A bridge regression calls the title-facing clear ABI with real resources and descriptor records. It verifies unsupported requests record no command and supported explicit/default views still record depth-only, stencil-only and combined clears. Removing the rectangle guard or view guard independently makes the regression fail. The bridge test also preserves explicit/default TEXTURE1D base-view clears and rejects a default DSV on a multisampled resource for all three clear-flag combinations. The 1D case fails before the fix; removing the sample-count guard makes the default multisampled case fail. On `12762b1`, the required local test suite passed (288 passed, 2 ignored), Windows-target Clippy passed with both default and all features, and the asset policy and whitespace checks passed. ## Checklist - [x] No game files, game code, disassembly listings or SDK files are included - [x] No new guesses about undocumented console behavior - [x] No new diagnostics
LakshanSivakumar commented 2026-11-26 11:22:17 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T11:22:17Z.

Review: CHANGES_REQUESTED


The independent Metal load actions look right, and the new draw tests cover full clears well. Two cases need care now that stencil-only clears are real:

  1. Rectangles. clear_dsv_impl still drops count/rects. That was already true for depth, but now a stencil-only clear of a small rectangle wipes the whole stencil mask too. Please either honour the rectangles, or keep partial (rect) clears out of the new path.
  2. Mip selection. The bridge resolves the DSV to its resource and drops the view's subresource selection (native/glue.rs:~496), so a stencil-only clear of a MipSlice = 1 view clears mip 0. Please gate the path on views it can represent, or carry the subresource through.

A bridge-level regression test for both cases would be great.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:review:6073281361 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/41#pullrequestreview-6073281361). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-26T11:22:17Z. **Review:** CHANGES_REQUESTED --- The independent Metal load actions look right, and the new draw tests cover full clears well. Two cases need care now that stencil-only clears are real: 1. **Rectangles.** `clear_dsv_impl` still drops `count`/`rects`. That was already true for depth, but now a stencil-only clear of a small rectangle wipes the whole stencil mask too. Please either honour the rectangles, or keep partial (rect) clears out of the new path. 2. **Mip selection.** The bridge resolves the DSV to its resource and drops the view's subresource selection (`native/glue.rs:~496`), so a stencil-only clear of a `MipSlice = 1` view clears mip 0. Please gate the path on views it can represent, or carry the subresource through. A bridge-level regression test for both cases would be great.
LakshanSivakumar commented 2026-11-26 11:51:49 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T11:51:49Z.

Review: CHANGES_REQUESTED


The rectangle and mip guards address both earlier requests, and the bridge test covers them. There are two remaining shape cases. Please keep full mip-0 clears for single-layer TEXTURE1D views, which already have height-one Metal backing, and reject a default DSV on a multisampled resource, which currently passes the guard. Both fit in the bridge test.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:review:6073658095 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/41#pullrequestreview-6073658095). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-26T11:51:49Z. **Review:** CHANGES_REQUESTED --- The rectangle and mip guards address both earlier requests, and the bridge test covers them. There are two remaining shape cases. Please keep full mip-0 clears for single-layer `TEXTURE1D` views, which already have height-one Metal backing, and reject a default DSV on a multisampled resource, which currently passes the guard. Both fit in the bridge test.
LakshanSivakumar commented 2026-11-26 12:48:35 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T12:48:35Z.

Review: APPROVED


Thanks: full mip-0 1D clears are kept and a default DSV on a multisampled resource is refused, both covered in the bridge test. Approved. (Optional: a row for an explicit TEXTURE2D view over a multisampled resource.)

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:review:6074391029 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/41#pullrequestreview-6074391029). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-26T12:48:35Z. **Review:** APPROVED --- Thanks: full mip-0 1D clears are kept and a default DSV on a multisampled resource is refused, both covered in the bridge test. Approved. (Optional: a row for an explicit TEXTURE2D view over a multisampled resource.)
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
LakshanSivakumar/Native-Victory-macOS!41
No description provided.