Skip to content

D3D12.X: preserve concrete sRGB plane formats in PresentX compositor SRVs - #2537

Open
ramon-victor wants to merge 1 commit into
xcl-dev:mainfrom
ramon-victor:fix/compositor-srgb-plane-srv
Open

ramon-victor wants to merge 1 commit into
xcl-dev:mainfrom
ramon-victor:fix/compositor-srgb-plane-srv

Conversation

@ramon-victor

Copy link
Copy Markdown
Contributor

Preserves concrete *_UNORM_SRGB resource formats when creating shader-resource views for composited PresentX planes in Compositor::record, resolving only *_TYPELESS formats to concrete SRV formats.

Previously Compositor::record passed swap_format(desc.Format).unwrap_or(desc.Format) to CreateShaderResourceView. Because swap_format maps DXGI_FORMAT_R8G8B8A8_UNORM_SRGB and DXGI_FORMAT_B8G8R8A8_UNORM_SRGB to *_UNORM for flip-model swap-chain creation, concrete sRGB plane textures received an invalid non-sRGB SRV format (CREATESHADERRESOURCEVIEW_INVALIDFORMAT in D3D12) and skipped sRGB-to-linear decoding on WARP.

Part of #2456 (specifically the sRGB plane SRV format issue left open by #2480).

What is in it

  • crates/xcl/src/hle/d3d12x/present.rs:
    • Add plane_srv_format(f) resolving only *_TYPELESS formats (R8G8B8A8_TYPELESS, B8G8R8A8_TYPELESS, R10G10B10A2_TYPELESS, R16G16B16A16_TYPELESS) to concrete SRV formats while preserving concrete formats (including *_UNORM_SRGB).
    • Use plane_srv_format(desc.Format) in Compositor::record when building D3D12_SHADER_RESOURCE_VIEW_DESC.
    • Add frame_dump_tests::compositor_preserves_concrete_srgb_plane_srv_format verifying plane_srv_format across concrete sRGB, typeless, and UNORM/float formats and exercising Compositor::record on WARP with a concrete DXGI_FORMAT_R8G8B8A8_UNORM_SRGB plane texture.

Tested

  • Hardware / toolchain: NVIDIA GeForce RTX 3070 8 GiB (driver 621.24, wave32), AMD Ryzen 7 5700X, 32 GiB RAM, Windows 11 Pro (26300), rustc 1.99.0 (x86_64-pc-windows-msvc), DXC/DXIL 1.8.2502.11 (Windows SDK 10.0.26100.0).
  • Failing-first before fix: cargo test -p xcl --lib compositor_preserves_concrete_srgb_plane_srv_format -- --nocapture failed (0 passed, 1 failed: expected sRGB-decoded concrete plane sample ~[128, 55, 0, 255], got [188, 128, 0, 255]).
  • After fix: cargo test -p xcl --lib hle::d3d12x::present -- --test-threads=1 --nocapture: 10 passed, 0 failed, 0 ignored.
  • Full workspace suite (.\scripts\test.ps1, debug): 1424 passed, 0 failed, 46 ignored (skipped on this adapter: wave64-only GPU tests, unsupported per-lane semantics variants, no heap windows).
  • Release build (cargo build --release -p xcl) and clean 60 s retail smoke run (.\scripts\smoke.ps1).

Regression run

Baseline (main):

xcl-smoke v1
commit: f087b998d0d51a9f11bbfa0761967a63e778edd9
gpu: NVIDIA GeForce RTX 3070
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1618 (PresentX 1618)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14467 MB

PR (e8d2258):

xcl-smoke v1
commit: e8d2258c5af20f108770ad8e0e983e9ecba8581e
gpu: NVIDIA GeForce RTX 3070
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1622 (PresentX 1622)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14037 MB

Not tested

  • Multi-plane retail title with concrete *_UNORM_SRGB planes (the retail smoke title presents a single plane; multi-plane concrete sRGB compositing is covered by the WARP regression test).
  • AMD / Intel GPUs and Wine / macOS hosts.

AI use

@DavidM1911

Copy link
Copy Markdown
Contributor

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

Thanks!

@emirduran707

Copy link
Copy Markdown
Contributor

Independent AMD RDNA4 (native wave64) test report on exact head e8d2258c5af20f108770ad8e0e983e9ecba8581e (clean detached checkout, no local changes).

Tested

  • AMD Radeon RX 9060 XT 16 GB (RDNA4, native wave64, driver 32.0.31044.16), Ryzen 5 5600, 32 GB RAM, Windows 11 Pro 26300, Rust 1.100.0 (stable-x86_64-pc-windows-msvc), DXC 1.9.2602.17; tests debug, smoke release.
  • cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4: 1422 passed, 2 failed, 46 ignored; 8 SKIPPED (6 in lower_dxil::tests::{f16,f32}_programs_on_the_gpu refused by per-lane form; heap_window_out_of_memory_falls_back_to_the_switch_form; pso_measurement_compiles_an_exact_synthetic_record). All native wave64 GPU tests ran and passed.
    • The PR's test passed: hle::d3d12x::present::frame_dump_tests::compositor_preserves_concrete_srgb_plane_srv_format.
    • The 2 failures (gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1 seed 722 and fuzz_validate_and_gpu_3 seed 1599) are pre-existing on unmodified main on this GPU.

Regression run (60 s retail-title smoke, XCL_NETWORK=0, release)

xcl-smoke v1
commit: e8d2258c5af20f108770ad8e0e983e9ecba8581e
gpu: AMD Radeon RX 9060 XT
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1591 (PresentX 1591)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 13937 MB

(Matched main 68a284a baseline on the same machine today: 1573 frames, 14420 MB peak, 0 device removals, 0 crashes.)

Not tested

  • D3D12 debug layer; Intel GPUs.

AI use

  • Antigravity with Gemini 4 Neon ran the build, test suite, and smoke run and drafted this report.

@SlopTart

Copy link
Copy Markdown

Tested: current PR head merged onto current origin/main (clean), Linux (Arch, kernel 7.2.15), Mesa 26.2.5 RADV, Radeon RX 7900 XT (NAVI31), cargo target x86_64-pc-windows-gnu run under wine-11.0 (Proton), rustc 1.94.0, vkd3d-proton 3.1 with the XCL patch, official MS DXC (binaries 2026-09-29).

gpu_ suite (cold cache): 165 passed / 3 failed, no crashes. The three are the known baseline on this lane (seed-1003 fuzz, mad/mac contraction, promoted-UAV-clear driver gap, PR #2490); none caused by this PR.
Targeted run of compositor_preserves_concrete_srgb_plane_srv_format: passed.

Not tested: retail titles (no title data on this lane, counts only).

AI use: Hermes agent (local Qwen-class) ran both machines and drafted this; I checked it before posting.

@luckyteagirl luckyteagirl 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.

Could the compositor re-encode its linear result for the SDR swap chain? This change correctly decodes a concrete sRGB plane through its SRV, but the compositor shader writes the linear sample directly to the UNORM RTV/PSO selected by swap_format. The swap chain still presents those integer bytes as sRGB. For an opaque midtone encoded as 188, the new test expects about 128 in the UNORM target; that is the decoded linear value, so a real SDR presentation would appear darker. The test confirms decoding but not the display-space round trip.

A two-plane case with an opaque sRGB base and a transparent overlay could compare the presented color with the existing single-plane copy path. Microsoft's color-space guidance says that linear shader output must be converted back to sRGB for integer screen presentation, for example through an sRGB RTV. Exact-head source review of e8d2258c5af20f108770ad8e0e983e9ecba8581e; I did not run a display capture or title. AI-assisted review with Codex.

rootw0rm pushed a commit to rootw0rm/xcl that referenced this pull request Nov 26, 2026
…cl-dev#2480 + xcl-dev#2537)

(cherry picked from commit b114829419c3fb66a8c680c8bbc7cb1acbad8c19)
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.

5 participants