Skip to content

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

Open
denkencar-sketch wants to merge 2 commits into
Marvisak:mainfrom
denkencar-sketch:fix/dhost-004
Open

denkencar-sketch wants to merge 2 commits into
Marvisak:mainfrom
denkencar-sketch:fix/dhost-004

Conversation

@denkencar-sketch

Copy link
Copy Markdown
Contributor

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 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

clquwu added a commit to clquwu/leonida-ultimate that referenced this pull request Nov 25, 2026
…efaults & depth/rect fixes

- Reserve a dedicated 64 KiB zero-filled guard page inside kArenaReserved (kTitleGuardOffset)
  at arena creation and route uncommitted, past-cap, or arena-full title-memory VAs to it
  instead of handing raw CPU pointers to shaders (prevents VK_ERROR_DEVICE_LOST page faults;
  adapted from ubiquitarianism/leonida#1631, GPL-3.0).
- Raise default unset LEONIDA_ARENA_MB up to 4095 MiB on >=16 GiB 64-bit hosts (with graceful
  step-down retry and system-RAM preference on <=12 GiB ReBAR GPUs) and default
  LEONIDA_TITLE_WINDOWS_MB from 256 to 512 MiB (up to 35% of arena).
- Reclaim retired arena ranges on submit and across buffer/heap/shader/title-window allocations,
  and add bounded LRU eviction of idle title windows from earlier epochs without disturbing
  active submission windows.
- Amortize large raw-texture recheck sweeps (>256 entries) over 16 rotating passes (adapted
  from MESIA-Unified@de27b6d, GPL-3.0).
- Map Xbox slot-70/raw typed depth SRV formats (D32_FLOAT/D16_UNORM/D24S8/D32S8) to readable
  depth-plane colour formats (ported from Marvisak/VIctory#2294, GPL-3.0).
- Remove duplicate if (rect_list) geometry-stage block in PipelineState::create_graphics that
  always failed after vs_stage.words was cleared.
- Add guard-page, arena-reclaim, LRU-eviction, Xbox slot-70 depth SRV, and low-VRAM arena
  policy tests in runtime/test/d3d12_xmem_shadow_test.cpp.
@steven-seagull27

steven-seagull27 commented Nov 25, 2026 •

Copy link
Copy Markdown

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.

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

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

…adable colour format

The host refuses a depth format for a shader resource view; the view of a
typeless depth texture took the title's.
@denkencar-sketch

Copy link
Copy Markdown
Contributor Author

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.

r4tedx added a commit to r4tedx/VIctory that referenced this pull request Nov 26, 2026
…his line has them

placed_uav_textures_create_real_host_uavs (main's, Marvisak#1273): Marvisak#2294 (96f6894)
makes a typed depth format in a shader resource view in its readable colour
format (fits, DEPTH_READABLE), so an SRV of an R32_TYPELESS or R16_TYPELESS
texture in D32_FLOAT or D16_UNORM is now a real R32_FLOAT or R16_UNORM view,
not the null fallback. The debug layer logs nothing for it, as the test
checks. SRV cases 0 and 1 now expect a real view. The unordered-access cases
stay null.

query_resolves_after_unordered_access_to_destination (Marvisak#159's): main's clamp
(315cea1) reads the title's records through a root view and writes into the
list's own argument buffer, so the destination's copy is never written or
left in unordered access. The test checks the title's records stay as
written and that the resolve lands, and is renamed
query_resolves_after_a_clamp_reads_destination. This is the author-branch
fix gpu/host-queries ba872ae2 with this line's bound() arguments.

PLAY-MAIN-781E846.md: both traced and fixed in the tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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