Skip to content

D3D12.X: on a native host every depth + stencil family is depth only - #1649

Open
shortside wants to merge 4 commits into
xcl-dev:mainfrom
shortside:d3d12x/native-host-depth-only
Open

shortside wants to merge 4 commits into
xcl-dev:mainfrom
shortside:d3d12x/native-host-depth-only

Conversation

@shortside

@shortside shortside commented Nov 24, 2026 •

Copy link
Copy Markdown

The depth formats piece of @Ahmet-Dedeler's Mac port (mac-on-main-wip 8fc0600, with its test from aaf191b), rebased onto main as he suggested in #258 (comment). Part of #258.

Metal makes no depth-only view of a depth + stencil texture and no view in another depth family than the texture's: its assertion ends the process, where a Windows driver takes or refuses the view. The console reads its depth buffers through exactly such views. So on a native D3D12 host (Apple's D3DMetal) every depth + stencil family becomes the R32 one (R32_TYPELESS / D32_FLOAT / R32_FLOAT), and the stencil plane is lost there: stencil views read the depth. XCL_DEPTH_STENCIL=1 restores the PC mapping. On Windows nothing changes: the host's D3D12 is a PE module and the switch is never on.

What it does not do: it does not keep stencil. Losing the stencil plane is a real cost, not a format rename: the title writes material numbers through the stencil plane of some depth targets and tests against them later, so on such a host those passes read depth where they expect stencil (@Ahmet-Dedeler, in the comments). That is a known limit of this mapping and outside this PR.

What is in it (4 commits, +170 / -4; the first three are Ahmet's code with him as author)

  • D3D12.X: note a native D3D12 host when its first object is adopted (gpu/shader.rs, hle/d3d12x/real.rs, +12): class_for already asks which module the host's first method is in; none means a native host, kept in gpu::shader::NATIVE_HOST_MEMORY and logged once. The depth change needs it and main does not have it: it is 12 lines out of the port's e97bc3a ("Mac host basics"), nothing else of that commit. Kept here at @Ahmet-Dedeler's request: his vtable branch will read the flag from this place when it is opened.
  • Depth formats on D3DMetal: … (hle/d3d12x/device_x.rs, real.rs): 8fc0600, cherry-picked. One conflict, with pc_initial_state, added on main at the same place; both kept.
  • Tests: a native host's depth-only formats (device_x.rs): the device_x half of aaf191b.
  • Tests: the depth format tests name their host; a native host's mapping runs everywhere (device_x.rs, real.rs), mine: depth_only is the process's, so after a test had adopted a native host's device, the two tests of the PC's formats that ran later in the same process failed (below). A test now says which host it describes (depth_only_for_test, a thread-local in test builds only), and depth_stencil_families_become_the_r32_family checks both answers through the real functions, so the native mapping is tested on Windows too.

Tested

  • Rebased 2026-11-25 onto main 1a0bbe3; new head 579e0be (was fcdb447). Three conflict hunks, both sides kept: in pc_resource_desc, main's new unordered-access flag strip runs first and the depth-only mapping after it; pc_initial_state_for_desc stays ahead of depth_only; in dev_create_uav_x, main's pc_shader_view_format path keeps this PR's view trace. After the rebase, the 14 lib tests in hle::d3d12x::device_x and hle::d3d12x::real:: that touch depth formats, view formats and unordered access, one per process: 11 passed, 1 failed, 2 crashed. The same three (gpu_depth_buffer_created_for_unordered_access_is_placed, gpu_placed_console_depth_target_with_clear_value, gpu_uav_companion_srv_and_null_image_views) fail or crash the same way on main 1a0bbe3 on this host. The other counts below are from head fcdb447, before the rebase, and were not repeated.
  • MacBook Pro M5 Pro, macOS 27.2.1, Rosetta 2; CrossOver 26.3 (Wine 11.0), Windows 10 bottle, D3DMetal; DXC 1.9.2609. Cross-built for x86_64-pc-windows-msvc with clang-cl / lld-link 23.1.6 and an xwin SDK 10.0.26100, Rust 1.100.0, debug. The lib test binary run under Wine. main is 9e3831e (this branch's base), the head is fcdb447; it merges into main c160d86 without conflicts.
  • The 22 lib tests whose names match device_x::|depth|console_format|dsv|format_query, one per process (--exact, 60 s cap), first three commits: main 19 passed, 1 failed, 1 without a result at the cap, and the new test does not exist; branch 20 passed, the same 1 failed (gpu_depth_buffer_created_for_unordered_access_is_placed: "UNORDERED_ACCESS without the UAV flag") and the same 1 without a result (gpu_placed_console_depth_target_with_clear_value). No test changed outcome.
  • hle::d3d12x:: --skip ::gpu_ --test-threads=1 in one process, skipping 6 tests that crash or hang this host on main too (create_list_reset_and_clear_state_track_initial_pso_on_d3d12, placed_title_textures_share_vram_and_preserve_pixels, d32s8_targets_take_their_own_size_of_video_memory, transitions_apply_when_their_list_is_submitted, and the two sparse::tests that stopped the run on both sides):
    • main: 130 passed, 4 failed, 1 ignored.
    • first three commits: 129 passed, 6 failed. The two more are console_depth_buffers_and_their_views_are_the_pcs (left: (39, 2), right: (44, 2)) and console_formats_are_asked_as_the_pcs (left: (Some(118), 40), right: (Some(118), 45)).
    • head fcdb447: 131 passed, 4 failed, 1 ignored: main's four (timestamps_outside_unified_memory_land_after_the_queue, write_buffer_immediate_on_open_existing_heap_visible_to_cpu, mapped_frame_dump_distinguishes_dark_bright_and_undecoded_content, reservable_agrees_with_the_driver) and the new test passing.
  • The three tests the last commit touches, each alone on the head: passed.

Regression run

  • On this Mac (M5 Pro, CrossOver 26.3, D3DMetal), after the rebase, 60 s each on a fresh data folder, scripts/smoke.ps1 unchanged. Neither build shows a frame in 60 s on this host, so this pair only shows that the change adds no crash or device removal here; it does not exercise the depth formats.

main:

xcl-smoke v1
commit: 1a0bbe3a2ba91ea8f5b6fc29130a053868d3c9e6
gpu: AMD Compatibility Mode
title: 1b7000bb
seconds: 60
exit: 0x0
frames shown: 0 (PresentX 0)
presents per 2 s (last 3): 0 0 0
device removals: 0
crashes: 0
peak commit: 0 MB

this PR:

xcl-smoke v1
commit: 579e0be524aab2d2ab662024acb2352223fa0778
gpu: AMD Compatibility Mode
title: 1b7000bb
seconds: 60
exit: 0x0
frames shown: 0 (PresentX 0)
presents per 2 s (last 3): 0 0 0
device removals: 0
crashes: 0
peak commit: 0 MB

main:

xcl-smoke v1
commit: 85e38262ff94aecd75d6f83fa8156a8b7697bd13
gpu: NVIDIA GeForce RTX 4080 SUPER
title: t1
seconds: 60
exit: 0x0
frames shown: 1333 (PresentX 1333)
presents per 2 s (last 3): 11 21 49
device removals: 0
crashes: 0
peak commit: 25722 MB

this PR:

xcl-smoke v1
commit: fcdb447f60ffbed10c2f7eb89494823ca80c8ebb
gpu: NVIDIA GeForce RTX 4080 SUPER
title: t1
seconds: 60
exit: 0x0
frames shown: 1614 (PresentX 1614)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15812 MB

Not tested

AI use

  • Claude Code with Claude Fable 5.2: rebased the commits, resolved the conflict, found the shared-process failures, wrote the last commit and this description, and ran the tests above on my machine.

🤖 Generated with Claude Code

@Ahmet-Dedeler

Copy link
Copy Markdown

Thanks for taking this one. Keep the flag here, that's the better order. My vtable branch isn't open as a PR yet and it's still on 508a0c7, so it's easier for me to rebase it onto this than for you to wait on it. When I open it, class_for will read NATIVE_HOST_MEMORY from where you put it.

One thing to say clearly in the description, since reviewers on Windows will ask: losing the stencil plane is a real cost and not only a format rename. The title writes material numbers through the stencil plane of some depth targets and tests against them later, so on this host those passes read depth where they expect stencil. That's a known limit of this mapping and not something this PR should try to fix, but it's worth one line under what it does not do.

I can't add a Windows pair. A Mac pair with a title from my port has to wait for its next rebase.

@papasmurph0

Copy link
Copy Markdown

Regression run for this PR on Windows / NVIDIA, since it has no xcl-smoke pair yet.

Tested

main:

xcl-smoke v1
commit: 85e38262ff94aecd75d6f83fa8156a8b7697bd13
gpu: NVIDIA GeForce RTX 4080 SUPER
title: t1
seconds: 60
exit: 0x0
frames shown: 1333 (PresentX 1333)
presents per 2 s (last 3): 11 21 49
device removals: 0
crashes: 0
peak commit: 25722 MB

this PR:

xcl-smoke v1
commit: fcdb447f60ffbed10c2f7eb89494823ca80c8ebb
gpu: NVIDIA GeForce RTX 4080 SUPER
title: t1
seconds: 60
exit: 0x0
frames shown: 1614 (PresentX 1614)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15812 MB

Both runs started from the same state (the title's settings already saved, so no first-run screens). The PR's run is within the limits: 121 % of main's frames, 61 % of its peak commit, no crash, no device removal.

Not tested: the change itself: on Windows the host's D3D12 is a PE module, so the depth + stencil mapping is never switched on here (as the description says) and the run is a regression check only. D3DMetal and stencil behaviour there are not covered.

AI use: Claude Code (Claude Opus 5.5) built the trees, made the runs on my PC and wrote this report; I asked for it to be posted.

@shortside
shortside marked this pull request as ready for review November 24, 2026 20:45
@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~22 ignored. (Intermittent single-test flake under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified main.)

Thanks!

@JJAutoCompare

Copy link
Copy Markdown

XCL PR #1649 — Windows / Intel Arc A770

Clean head fcdb447f60ffbed10c2f7eb89494823ca80c8ebb on STOR-WINLAB. Windows 11 Enterprise Evaluation x64 (build 26200), AMD Family 23 Model 113, Intel Arc A770 (driver 32.0.101.9175), DXC 1.9.2609.5, rustc 1.100.0 (0ef1bc386, x86_64-pc-windows-msvc). Unoptimized dev/test builds, no debuginfo or incremental compilation.

Tested

  • cargo build --workspace and cargo test --workspace --no-run both exited 0 outside the Arc mutex.
  • CPU-only focused commands (each 1 passed, 0 failed, 0 ignored, 0 skipped) ran outside the mutex with XCL_ADAPTER=NONE_CPU_ONLY:
cargo test -p xcl --lib hle::d3d12x::device_x::tests::console_depth_buffers_and_their_views_are_the_pcs -- --exact
cargo test -p xcl --lib hle::d3d12x::device_x::tests::depth_stencil_families_become_the_r32_family -- --exact
cargo test -p xcl --lib hle::d3d12x::real::console_format_query_tests::console_formats_are_asked_as_the_pcs -- --exact

Tests covered forced native-host R32 resource, shader-view and depth-view mappings, including stencil views reading depth. Windows assertions covered D16S8-to-D24S8 mapping, stencil plane selection and format-query translation.

  • cargo test --workspace --no-fail-fast -- --test-threads=4 ran once via Invoke-ArcTest.ps1 -WaitMinutes 120 with XCL_ADAPTER=A770 and RUST_TEST_NOCAPTURE=1. Arc A770 confirmed in the log. Exit 101. The 20 summaries (19 binaries and one doctest target) totaled 761 harness passes, 16 failures, 41 ignored. The three focused tests passed again.

Workspace failures and skips

  • 15 GPU recompiler failures. Eleven reported CreateComputePipelineState error 0x80070057. Four reported mismatches in fused FMA overflow, implicit-LOD sampling, the high half of v_add_f16, or wave64 pixel reductions.
  • One test-title e2e failure. The RSSetDepthBiasX check returned blue where it expected green.
  • Six exact SKIPPED lines in pr1649-suite.log. Two cited missing wave64, two cited missing debug-layer support, one cited tiled tier below 2, and one cited unavailable heap windows. The harness counts all six as passes. Coverage excludes them.

Not tested

Apple D3DMetal/Wine, native-host detection and depth/stencil view creation on that backend, other GPUs, and retail title smoke runs. Failure attribution requires a matched main run.

AI use

T3 Code / Codex (gpt-6.2-sol, reasoningEffort: high) ran the build and verification. Coordinator #2 (T3 Code / Antigravity, gemini-4-neon) verified counts against pr1649-suite.log and published.

Ahmet-Dedeler and others added 4 commits November 25, 2026 13:27
Apple's D3DMetal (macOS under CrossOver) is native code in no PE module:
`class_for` already asks which module the host's first method is in, and
gets none there. That is now kept in `gpu::shader::NATIVE_HOST_MEMORY`
and logged once. Nothing reads it yet; the depth formats of such a host
are the first use (next commit).

The flag and its place are those of `mac-on-main-wip` (e97bc3a, "Mac host
basics"), taken out on their own; the rest of that commit is not here.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…, on top of upstream's PC formats

Metal makes no depth-only view of a depth + stencil texture and no view in another depth
family than the texture's: its assertion ("failed assertion `Texture Creation`") ends the
process where a Windows driver takes or refuses the view. Upstream now makes depth buffers
typeless and reads them through R24_UNORM_X8 / R32_FLOAT_X8X24 views with stencil in plane 1
– that combination. On a native host (`device_x::depth_only`, XCL_DEPTH_STENCIL=1 restores
upstream's mapping) the override sits on upstream's functions:

- pc_resource_desc: R32G8X24 / R24G8 families (and the console's D16S8, which upstream
  maps to R24G8) → R32_TYPELESS / D32_FLOAT / R32_FLOAT (`depth_only_format`).
- pc_view_format (pipelines' DSV formats, clear values, format queries) the same.
- pc_shader_view_format: any depth-family or stencil view of an R32-family resource → R32_FLOAT
  (stencil views read the depth: the stencil plane is lost); of a 16-bit depth buffer → R16_UNORM.
- pc_depth_view_format: a DSV takes the depth format of the resource's family.
- XCL_TRACE_DEPTH_VIEWS=1 logs every view made of a depth-family resource, flushed.

Upstream's mappings of B5G5R5A1 / B4G4R4A4 targets and of the console's 116 / 117 are as
upstream has them (the local pc_format and view_format_for are gone).

Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
(cherry picked from commit 8fc0600)
`depth_only_format` takes both depth + stencil families to the R32 one,
role for role, and leaves 16-bit depth and colour formats alone; off a
native host the PC mapping is unchanged.

The `device_x` part of `mac-on-main-wip` aaf191b; its `isa` tests are not here.

Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
…g runs everywhere

`depth_only` is the process's: once a test has adopted a device of a native
host, the tests of the PC's depth formats that run after it in the same
process saw the depth-only mapping and failed
(`console_depth_buffers_and_their_views_are_the_pcs`: (39, 2) for (44, 2);
`console_formats_are_asked_as_the_pcs`: 40 for 45; CrossOver 26.3, D3DMetal,
`hle::d3d12x:: --test-threads=1`). Alone they passed.

A test now says which host it describes (`depth_only_for_test`, a
thread-local in test builds only). The two tests of the PC's formats say
"not a native host"; `depth_stencil_families_become_the_r32_family` checks
both answers through the real functions (resource descriptions, pipeline
and clear-value formats, shader views, depth views), so the native mapping
is tested on Windows too, where no host turns it on.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@shortside
shortside force-pushed the d3d12x/native-host-depth-only branch from fcdb447 to 579e0be Compare November 25, 2026 12:29
@jennydeth

Copy link
Copy Markdown

First Windows (MSVC) build and run of this head (listed under Not tested).

Setup: RTX 3060 12 GB (32-lane waves, driver 32.0.16.2101), Ryzen 5 5600X, 32 GB RAM, Windows 11 build 26300, Rust 1.100.0 stable-x86_64-pc-windows-msvc, DXC 1.9.2609.5, debug build. Head 579e0be.

Result: builds with MSVC; cargo test --workspace -- --test-threads=4: 1251 passed, 0 failed, 46 ignored. SKIPPED: 18 GPU tests for no wave64 (expected on this card); 2 debug-layer tests (no d3d12SDKLayers.dll).

Not tested: a title run on Windows.

AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this report.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants