GPU: a typed depth format in a shader resource view is made in the readable colour format #2292

Open
denkencar-sketch wants to merge 2 commits from upstream-pr/2294 into main
denkencar-sketch commented 2026-11-25 10:05:20 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by denkencar-sketch on 2026-11-25T10:05:20Z.


Summary

The host refuses a depth format for a shader resource view, but the view of a typeless depth texture took the title's format. A typed depth format in a shader resource view is now made in the matching readable colour format (depth 20/40/45/55 map to 21/41/46/56). fits() is only used for SRV/UAV, and a depth texture cannot carry a UAV. The branch has a second, comment-only commit that keeps two doc comments with their items.

Testing

Test depth_formats_in_shader_resource_views_are_made_readable fails on main and passes with this change. cargo test --workspace --locked passes apart from known flakes: modules::dstorage::tests::a_page_list_filled_after_its_request_starts fails now and then on main too, and so does a parallel-run flake in victory-gpu's lib tests (watch:: and descriptor::host:: tests, 2 of 40 runs on pristine main).

Not tried: a run in the game, or the D3D12 debug layer rejecting a D32_FLOAT SRV.

AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5489187599 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2294). Originally posted by [denkencar-sketch](https://github.com/denkencar-sketch) on 2026-11-25T10:05:20Z. --- ## Summary The host refuses a depth format for a shader resource view, but the view of a typeless depth texture took the title's format. A typed depth format in a shader resource view is now made in the matching readable colour format (depth 20/40/45/55 map to 21/41/46/56). `fits()` is only used for SRV/UAV, and a depth texture cannot carry a UAV. The branch has a second, comment-only commit that keeps two doc comments with their items. ## Testing Test `depth_formats_in_shader_resource_views_are_made_readable` fails on `main` and passes with this change. `cargo test --workspace --locked` passes apart from known flakes: `modules::dstorage::tests::a_page_list_filled_after_its_request_starts` fails now and then on `main` too, and so does a parallel-run flake in `victory-gpu`'s lib tests (`watch::` and `descriptor::host::` tests, 2 of 40 runs on pristine `main`). Not tried: a run in the game, or the D3D12 debug layer rejecting a D32_FLOAT SRV. AI-assisted.
catminou4 commented 2026-11-25 10:19:12 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T10:19:12Z.

Review: COMMENTED


Typed depth formats in shader resource views made readable (DEPTH_READABLE mapping). Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1.

<!-- greyfinch-sync:Marvisak/VIctory:review:6055712358 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2294#pullrequestreview-6055712358). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T10:19:12Z. **Review:** COMMENTED --- Typed depth formats in shader resource views made readable (DEPTH_READABLE mapping). Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1.
steven-seagull27 commented 2026-11-25 11:05:42 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by steven-seagull27 on 2026-11-25T10:48:26Z.


I checked the D3D12 depth-SRV question on 298a0067 against main 940d32f6. On an RTX 5080 (621.40) and built-in Microsoft WARP (10.0.26100.10068), all four SRV formats selected by the PR were accepted by the D3D12 debug layer and returned the expected depth samples. Windows 11 build 26300.10075, separate hardware and WARP processes.

Guest depth format SRV format selected by the PR RTX 5080 samples correct WARP samples correct
D32_FLOAT_S8X24_UINT R32_FLOAT_X8X24_TYPELESS 16/16 16/16
D32_FLOAT R32_FLOAT 16/16 16/16
D24_UNORM_S8_UINT R24_UNORM_X8_TYPELESS 16/16 16/16
D16_UNORM R16_UNORM 16/16 16/16

The probe created a real 4×4 typeless depth resource in each family, passed its typed depth format through the runtime's fits, and used the selected format to create a shader resource view. Two depth clears wrote 0.75 to the left half and 0.25 to the right. A compute shader loaded every texel through that SRV into a readback buffer. The D32 variants returned exact floats. D16 returned about 0.7499962 and 0.2500038, within one UNORM step.

On pristine main, fits retained all four typed depth formats. Both adapters reported shader loads unsupported for those four selections. In a separate creation-only baseline check, both debug layers explicitly rejected the first selection, D32_FLOAT_S8X24_UINT, with message 28 (CREATESHADERRESOURCEVIEW_INVALIDFORMAT) before any dispatch. Using the explicit readable SRV formats as a positive control on main gave 64/64 correct samples per adapter. This covers the depth plane and descriptor creation with synthetic data. The game and stencil-plane reads were outside this test.

Reproduction on Windows. I put the opt-in readback in a single source-only commit on this PR head. This version creates the title’s SRV through the production descriptor path. It compiles its shader at test time. From the PR branch at 298a0067, with Windows Graphics Tools installed, run in PowerShell:

git fetch https://github.com/steven-seagull27/VIctory.git refs/heads/codex/pr2294-depth-srv-readback
git cherry-pick 53a1725153001bacaa2e91d3988eac5017f7a787
$env:VICTORY_D3D12_DEBUG = '1'
foreach ($warp in '0', '1') {
    $env:VICTORY_D3D12_WARP = $warp
    cargo test --locked -p victory-gpu --lib --features diagnostics draw::tests::typed_depth_srvs_read_the_rendered_depth -- --exact --ignored --nocapture --test-threads=1
    if ($LASTEXITCODE -ne 0) { break }
}

I ran these Cargo invocations on the published commit. Each process printed its real adapter name and four 16/16 readbacks, for 64/64 on the RTX and 64/64 on WARP.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7160198715 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2294#issuecomment-7160198715). Originally posted by [steven-seagull27](https://github.com/steven-seagull27) on 2026-11-25T10:48:26Z. --- I checked the D3D12 depth-SRV question on `298a0067` against `main` `940d32f6`. On an RTX 5080 (621.40) and built-in Microsoft WARP (10.0.26100.10068), all four SRV formats selected by the PR were accepted by the D3D12 debug layer and returned the expected depth samples. Windows 11 build 26300.10075, separate hardware and WARP processes. | Guest depth format | SRV format selected by the PR | RTX 5080 samples correct | WARP samples correct | |---|---|---:|---:| | D32_FLOAT_S8X24_UINT | R32_FLOAT_X8X24_TYPELESS | 16/16 | 16/16 | | D32_FLOAT | R32_FLOAT | 16/16 | 16/16 | | D24_UNORM_S8_UINT | R24_UNORM_X8_TYPELESS | 16/16 | 16/16 | | D16_UNORM | R16_UNORM | 16/16 | 16/16 | The probe created a real 4×4 typeless depth resource in each family, passed its typed depth format through the runtime's `fits`, and used the selected format to create a shader resource view. Two depth clears wrote 0.75 to the left half and 0.25 to the right. A compute shader loaded every texel through that SRV into a readback buffer. The D32 variants returned exact floats. D16 returned about 0.7499962 and 0.2500038, within one UNORM step. On pristine `main`, `fits` retained all four typed depth formats. Both adapters reported shader loads unsupported for those four selections. In a separate creation-only baseline check, both debug layers explicitly rejected the first selection, `D32_FLOAT_S8X24_UINT`, with message 28 (`CREATESHADERRESOURCEVIEW_INVALIDFORMAT`) before any dispatch. Using the explicit readable SRV formats as a positive control on `main` gave 64/64 correct samples per adapter. This covers the depth plane and descriptor creation with synthetic data. The game and stencil-plane reads were outside this test. **Reproduction on Windows.** I put the opt-in readback in [a single source-only commit on this PR head](https://github.com/steven-seagull27/VIctory/commit/53a1725153001bacaa2e91d3988eac5017f7a787). This version creates the title’s SRV through the production descriptor path. It compiles its shader at test time. From the PR branch at `298a0067`, with Windows Graphics Tools installed, run in PowerShell: ```powershell git fetch https://github.com/steven-seagull27/VIctory.git refs/heads/codex/pr2294-depth-srv-readback git cherry-pick 53a1725153001bacaa2e91d3988eac5017f7a787 $env:VICTORY_D3D12_DEBUG = '1' foreach ($warp in '0', '1') { $env:VICTORY_D3D12_WARP = $warp cargo test --locked -p victory-gpu --lib --features diagnostics draw::tests::typed_depth_srvs_read_the_rendered_depth -- --exact --ignored --nocapture --test-threads=1 if ($LASTEXITCODE -ne 0) { break } } ``` I ran these Cargo invocations on the published commit. Each process printed its real adapter name and four `16/16` readbacks, for 64/64 on the RTX and 64/64 on WARP.
Marvisak commented 2026-11-25 15:04:29 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T14:52:00Z.


Automated triage for the maintainers.

Merge candidate (worth a look). Rebased onto current main. In fits (crates/victory-gpu/src/descriptor/host.rs), a shader resource view described in a typed depth format is made in the matching readable format (DEPTH_READABLE: D32_FLOAT_S8X24_UINT -> R32_FLOAT_X8X24_TYPELESS, D32_FLOAT -> R32_FLOAT, D24_UNORM_S8_UINT -> R24_UNORM_X8_TYPELESS, D16_UNORM -> R16_UNORM). I checked these against the public DXGI format list: D3D12 does not allow depth formats in an SRV, and these are the documented readable equivalents. UAVs are left alone. The new test depth_formats_in_shader_resource_views_are_made_readable covers it. CI check passes and it merges cleanly.

On your reply: the two updated expectations in placed_uav_textures_create_real_host_uavs (R32_TYPELESS + D32_FLOAT and R16_TYPELESS + D16_UNORM now make real views instead of the null fallback) follow from this change.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7165937010 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2294#issuecomment-7165937010). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T14:52:00Z. --- <!-- victory-triage v1 head=3968b02a51f462dc2a5f757312709aeeef6ec1cf verdict=merge-candidate at=2026-11-26T00:23:24Z --> Automated triage for the maintainers. **Merge candidate (worth a look).** Rebased onto current `main`. In `fits` (`crates/victory-gpu/src/descriptor/host.rs`), a shader resource view described in a typed depth format is made in the matching readable format (`DEPTH_READABLE`: D32_FLOAT_S8X24_UINT -> R32_FLOAT_X8X24_TYPELESS, D32_FLOAT -> R32_FLOAT, D24_UNORM_S8_UINT -> R24_UNORM_X8_TYPELESS, D16_UNORM -> R16_UNORM). I checked these against the public DXGI format list: D3D12 does not allow depth formats in an SRV, and these are the documented readable equivalents. UAVs are left alone. The new test `depth_formats_in_shader_resource_views_are_made_readable` covers it. CI `check` passes and it merges cleanly. On your reply: the two updated expectations in `placed_uav_textures_create_real_host_uavs` (`R32_TYPELESS + D32_FLOAT` and `R16_TYPELESS + D16_UNORM` now make real views instead of the null fallback) follow from this change. --- _Generated by [Claude Code](https://claude.ai/code)_
denkencar-sketch commented 2026-11-26 00:03:30 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by denkencar-sketch on 2026-11-25T23:25:22Z.


Rebased onto current \main\ (\842b0cb) and updated the two \R32_TYPELESS + D32_FLOAT\ / \R16_TYPELESS + D16_UNORM\ expectations in \placed_uav_textures_create_real_host_uavs\ (added by #1273) now that those SRVs create real readable host views without D3D12 errors. \descriptor::host::tests\ (16/16) and \clippy\ pass.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7177538316 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2294#issuecomment-7177538316). Originally posted by [denkencar-sketch](https://github.com/denkencar-sketch) on 2026-11-25T23:25:22Z. --- Rebased onto current \main\ (\842b0cb\) and updated the two \R32_TYPELESS + D32_FLOAT\ / \R16_TYPELESS + D16_UNORM\ expectations in \placed_uav_textures_create_real_host_uavs\ (added by #1273) now that those SRVs create real readable host views without D3D12 errors. \descriptor::host::tests\ (16/16) and \clippy\ pass.
fuzeofficlal commented 2026-11-26 19:44:47 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T19:44:47Z.

Review: APPROVED


Reviewed and verified 3968b02a51f462dc2a5f757312709aeeef6ec1cf merged onto origin/main (63bcca43c6a00a758510398fa43096ce7e4f7df0) on Windows 11 x64 (RTX 5090 + Microsoft WARP, --features diagnostics with VICTORY_D3D12_DEBUG=1, Rust 1.98.1 MSVC).

Code Audit

  • In fits (crates/victory-gpu/src/descriptor/host.rs:1339, 1380-1390), rewriting typed depth SRV formats via DEPTH_READABLE (20 -> 21, 40 -> 41, 45 -> 46, 55 -> 56) only when !unordered produces the valid D3D12 readable colour formats for typeless depth textures while keeping depth UAVs rejected and stencil SRVs (22, 47) untouched.
  • Because srv_desc (L950-952) runs resource::pc_format beforehand, console 16-bit depth/stencil (118) maps 118 -> 20 -> 21 (DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS) through the same path, and DENY_SHADER_RESOURCE depth textures remain refused at L1357.
  • The two updated expectations in placed_uav_textures_create_real_host_uavs (L2481-2482) align cleanly with the new behavior.

Local Verification

  • cargo xtask policy — pass (191 files ok).
  • cargo clippy --locked -p victory-gpu --all-targets -- -D warnings (default and --all-features) — 0 warnings.
  • cargo test --locked -p victory-gpu --features diagnostics --lib for depth_formats_in_shader_resource_views_are_made_readable and placed_uav_textures_create_real_host_uavs (RTX 5090 and WARP) — passed.
  • Additional 14-case CreateShaderResourceView probe through production make_view under VICTORY_D3D12_DEBUG=1: tested all 5 title depth formats (20, 40, 45, 55, and console 118) with both explicit depth format and DXGI_FORMAT_UNKNOWN (0), stencil SRVs (22 and 47 with PlaneSlice = 1), and negative controls (unordered = true UAV and DENY_SHADER_RESOURCE depth texture) — all passed on both RTX 5090 and WARP with GetDeviceRemovedReason() == Ok(()) and 0 ID3D12InfoQueue messages.

Looks good to merge.

<!-- greyfinch-sync:Marvisak/VIctory:review:6079708193 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2294#pullrequestreview-6079708193). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T19:44:47Z. **Review:** APPROVED --- Reviewed and verified `3968b02a51f462dc2a5f757312709aeeef6ec1cf` merged onto `origin/main` (`63bcca43c6a00a758510398fa43096ce7e4f7df0`) on Windows 11 x64 (RTX 5090 + Microsoft WARP, `--features diagnostics` with `VICTORY_D3D12_DEBUG=1`, Rust 1.98.1 MSVC). ### Code Audit - In `fits` (`crates/victory-gpu/src/descriptor/host.rs:1339, 1380-1390`), rewriting typed depth SRV formats via `DEPTH_READABLE` (`20 -> 21`, `40 -> 41`, `45 -> 46`, `55 -> 56`) only when `!unordered` produces the valid D3D12 readable colour formats for typeless depth textures while keeping depth UAVs rejected and stencil SRVs (`22`, `47`) untouched. - Because `srv_desc` (`L950-952`) runs `resource::pc_format` beforehand, console 16-bit depth/stencil (`118`) maps `118 -> 20 -> 21` (`DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS`) through the same path, and `DENY_SHADER_RESOURCE` depth textures remain refused at `L1357`. - The two updated expectations in `placed_uav_textures_create_real_host_uavs` (`L2481-2482`) align cleanly with the new behavior. ### Local Verification - `cargo xtask policy` — pass (`191 files ok`). - `cargo clippy --locked -p victory-gpu --all-targets -- -D warnings` (default and `--all-features`) — 0 warnings. - `cargo test --locked -p victory-gpu --features diagnostics --lib` for `depth_formats_in_shader_resource_views_are_made_readable` and `placed_uav_textures_create_real_host_uavs` (RTX 5090 and WARP) — passed. - Additional 14-case `CreateShaderResourceView` probe through production `make_view` under `VICTORY_D3D12_DEBUG=1`: tested all 5 title depth formats (`20`, `40`, `45`, `55`, and console `118`) with both explicit depth format and `DXGI_FORMAT_UNKNOWN (0)`, stencil SRVs (`22` and `47` with `PlaneSlice = 1`), and negative controls (`unordered = true` UAV and `DENY_SHADER_RESOURCE` depth texture) — all passed on both RTX 5090 and WARP with `GetDeviceRemovedReason() == Ok(())` and 0 `ID3D12InfoQueue` messages. Looks good to merge.
Dukestar69 commented 2026-11-26 22:10:28 +00:00 (Migrated from github.com)

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

Review: APPROVED


LGTM — verified on RTX 5090 (Windows / D3D12) against origin/main (63bcca4).

  • Remapping typed depth formats (D32_FLOAT_S8X24_UINT, D32_FLOAT, D24_UNORM_S8_UINT, D16_UNORM) to their readable SRV color formats in fits() avoids falling back to null descriptors when shaders sample depth textures.
  • cargo test -p victory-gpu --lib descriptor::host::tests:: -- --skip dynamic_slots_are_held_until_released --test-threads=1: 15 passed, 0 failed (including depth_formats_in_shader_resource_views_are_made_readable).
  • cargo clippy -p victory-gpu --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:6081014738 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2294#pullrequestreview-6081014738). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T22:10:28Z. **Review:** APPROVED --- LGTM — verified on RTX 5090 (Windows / D3D12) against `origin/main` (`63bcca4`). - Remapping typed depth formats (`D32_FLOAT_S8X24_UINT`, `D32_FLOAT`, `D24_UNORM_S8_UINT`, `D16_UNORM`) to their readable SRV color formats in `fits()` avoids falling back to null descriptors when shaders sample depth textures. - `cargo test -p victory-gpu --lib descriptor::host::tests:: -- --skip dynamic_slots_are_held_until_released --test-threads=1`: 15 passed, 0 failed (including `depth_formats_in_shader_resource_views_are_made_readable`). - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2294:upstream-pr/2294'
git switch 'upstream-pr/2294'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/2294'
git switch 'upstream-pr/2294'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2294'
git switch 'upstream-pr/2294'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2294'
git switch 'main'
git merge --squash 'upstream-pr/2294'
git switch 'main'
git merge --ff-only 'upstream-pr/2294'
git switch 'main'
git merge 'upstream-pr/2294'
git push origin 'main'
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!2292
No description provided.