Repository navigation
D3D12.X: preserve concrete sRGB plane formats in PresentX compositor SRVs - #2537
ramon-victor wants to merge 1 commit into
Conversation
|
Verification on RTX 3060 Ti (Windows 11), branch merged with current
Thanks! |
|
Independent AMD RDNA4 (native wave64) test report on exact head Tested
Regression run (60 s retail-title smoke, (Matched Not tested
AI use
|
|
Tested: current PR head merged onto current
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
left a comment
There was a problem hiding this comment.
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.
…cl-dev#2480 + xcl-dev#2537) (cherry picked from commit b114829419c3fb66a8c680c8bbc7cb1acbad8c19)
|
Independent desktop NVIDIA verification of PR #2537 at head Environment
Targeted release tests & build (
|
| Command | Result |
|---|---|
cargo test --release -p xcl --lib compositor_preserves_concrete_srgb_plane_srv_format -- --nocapture (3 consecutive runs) |
1 passed; 0 failed; 0 ignored; 1324 filtered out × 3 (0.02s × 3, 0 skipped) |
cargo test --release -p xcl --lib hle::d3d12x::present:: -- --test-threads=1 (3 consecutive runs) |
10 passed; 0 failed; 0 ignored; 1315 filtered out × 3 (0.05s × 3, 0 skipped) |
cargo build --release -p xcl |
Clean build (1m 11s, exit 0, 0 new warnings) |
Paired quiet 60 s retail smoke (title: 29640639)
Exact parent & merge-base (6d12f58a229bc73889878a448c64dc3af25eeba0, cached baseline on the same machine):
xcl-smoke v1
commit: 6d12f58a229bc73889878a448c64dc3af25eeba0
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1606 (PresentX 1606)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14004 MB
PR #2537 (e8d2258c5af20f108770ad8e0e983e9ecba8581e):
xcl-smoke v1
commit: e8d2258c5af20f108770ad8e0e983e9ecba8581e
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1588 (PresentX 1589)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 13973 MB
Runtime log observations (xcl.log)
9219log lines,0[ERROR]/ device-removal / panic lines.- Final draw/memory telemetry in log:
19564 draws with translated pipelines (0 skipped, 0 with PC pipelines), 1024 dispatches (0 skipped); last memory sample13973 MB committed by the process; video memory 6116 MB local, 4651 MB non-local.
Limits of coverage
- Preserving concrete sRGB plane formats in
PresentXcompositor SRV descriptors was verified viacompositor_preserves_concrete_srgb_plane_srv_format(3/3) andhle::d3d12x::present::(10/10× 3,0skipped). - The 60 s retail smoke on
title: 29640639exercises livePresentXpresentation (1588frames shown,1589PresentXcalls) with zero device removals or crashes (frame-count delta vs. cached parent reflects single-run startup variance, not this PR); visual pixel-level sRGB/SDR/HDR colorimetry inspection of an sRGB plane title was not performed here.
AI disclosure: test execution and report drafting assisted by Google Antigravity (Gemini 4 Neon).
|
Follow-up to the sRGB output review, checked against head I changed the WARP fixture to use two opaque copies of the same concrete sRGB plane, which is the path that invokes One bounded correction is to keep the existing encoded-domain UNORM blend, while re-encoding the RGB sampled through a concrete sRGB SRV when writing to an integer SDR target. Set the decision per plane; keep alpha unchanged and leave FP16 output linear. The local candidate below restored Local checks on Windows 11 build 26300, RTX 3080 Ti 621.35, Ryzen 7 9800X3D, DXC 1.8.2502.11: Tested candidate diff against #2537 headdiff --git a/crates/xcl/src/hle/d3d12x/present.rs b/crates/xcl/src/hle/d3d12x/present.rs
index ef778cd9..fcfec040 100644
--- a/crates/xcl/src/hle/d3d12x/present.rs
+++ b/crates/xcl/src/hle/d3d12x/present.rs
@@ -289,6 +289,12 @@ fn plane_srv_format(f: DXGI_FORMAT) -> DXGI_FORMAT {
}
}
+fn encode_srgb_for_output(src: DXGI_FORMAT, dst: DXGI_FORMAT) -> bool {
+ let integer_sdr = matches!(dst, DXGI_FORMAT_R8G8B8A8_UNORM | DXGI_FORMAT_B8G8R8A8_UNORM | DXGI_FORMAT_R10G10B10A2_UNORM);
+ let srgb_source = matches!(src, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB | DXGI_FORMAT_B8G8R8A8_UNORM_SRGB);
+ integer_sdr && srgb_source
+}
+
unsafe fn backbuffer_like(res: usize) -> Option<D3D12_RESOURCE_DESC> {
let raw = res as *mut c_void;
let r = ID3D12Resource::from_raw_borrowed(&raw)?;
@@ -715,8 +721,15 @@ fn compositor_shaders() -> Option<&'static (Vec<u8>, Vec<u8>)> {
let ps = compile_fx(
"Texture2D tex : register(t0);\n\
SamplerState smp : register(s0);\n\
+ cbuffer Encode : register(b1) { uint encode_srgb; };\n\
float4 main(float4 pos : SV_Position, float2 uv : TEXCOORD0) : SV_Target {\n\
- return tex.Sample(smp, uv);\n\
+ float4 c = tex.Sample(smp, uv);\n\
+ if (encode_srgb != 0) {\n\
+ float3 lo = 12.92 * c.rgb;\n\
+ float3 hi = 1.055 * pow(max(c.rgb, 0.0), 1.0 / 2.4) - 0.055;\n\
+ c.rgb = (c.rgb <= 0.0031308) ? lo : hi;\n\
+ }\n\
+ return c;\n\
}",
"ps_5_0",
)?;
@@ -757,6 +770,13 @@ impl Compositor {
},
ShaderVisibility: D3D12_SHADER_VISIBILITY_PIXEL,
},
+ D3D12_ROOT_PARAMETER {
+ ParameterType: D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS,
+ Anonymous: D3D12_ROOT_PARAMETER_0 {
+ Constants: D3D12_ROOT_CONSTANTS { ShaderRegister: 1, RegisterSpace: 0, Num32BitValues: 1 },
+ },
+ ShaderVisibility: D3D12_SHADER_VISIBILITY_PIXEL,
+ },
];
let sampler = D3D12_STATIC_SAMPLER_DESC {
Filter: D3D12_FILTER_MIN_MAG_MIP_LINEAR,
@@ -886,9 +906,10 @@ impl Compositor {
list.SetDescriptorHeaps(&[Some(self.srv_heap.clone())]);
list.IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
let srv_gpu_base = self.srv_heap.GetGPUDescriptorHandleForHeapStart();
- for (i, (_, _, uv_rect)) in planes.iter().take(MAX_PLANES).enumerate() {
+ for (i, (_, desc, uv_rect)) in planes.iter().take(MAX_PLANES).enumerate() {
list.SetPipelineState(if i == 0 { &opaque_pso } else { &blend_pso });
list.SetGraphicsRoot32BitConstants(0, 4, uv_rect.as_ptr() as *const c_void, 0);
+ list.SetGraphicsRoot32BitConstant(2, u32::from(encode_srgb_for_output(desc.Format, dst_fmt)), 0);
let mut gpu = srv_gpu_base;
gpu.ptr += ((first + i) as u64) * (self.srv_inc as u64);
list.SetGraphicsRootDescriptorTable(1, gpu);
@@ -1842,6 +1863,10 @@ mod frame_dump_tests {
#[test]
fn compositor_preserves_concrete_srgb_plane_srv_format() {
+ assert!(encode_srgb_for_output(DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, DXGI_FORMAT_R8G8B8A8_UNORM));
+ assert!(encode_srgb_for_output(DXGI_FORMAT_B8G8R8A8_UNORM_SRGB, DXGI_FORMAT_R10G10B10A2_UNORM));
+ assert!(!encode_srgb_for_output(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM));
+ assert!(!encode_srgb_for_output(DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, DXGI_FORMAT_R16G16B16A16_FLOAT));
assert_eq!(plane_srv_format(DXGI_FORMAT_R8G8B8A8_UNORM_SRGB), DXGI_FORMAT_R8G8B8A8_UNORM_SRGB);
assert_eq!(plane_srv_format(DXGI_FORMAT_B8G8R8A8_UNORM_SRGB), DXGI_FORMAT_B8G8R8A8_UNORM_SRGB);
assert_eq!(plane_srv_format(DXGI_FORMAT_R8G8B8A8_TYPELESS), DXGI_FORMAT_R8G8B8A8_UNORM);
@@ -1948,7 +1973,12 @@ mod frame_dump_tests {
transition(&out, D3D12_RESOURCE_STATE_COMMON, D3D12_RESOURCE_STATE_RENDER_TARGET),
]);
- let planes = [(srgb.clone(), srgb.GetDesc(), [0.0, 0.0, 1.0, 1.0])];
+ // Two planes select the compositor in present_now; an opaque second copy of the
+ // same texture must still preserve the bytes of the single-plane copy path.
+ let planes = [
+ (srgb.clone(), srgb.GetDesc(), [0.0, 0.0, 1.0, 1.0]),
+ (srgb.clone(), srgb.GetDesc(), [0.0, 0.0, 1.0, 1.0]),
+ ];
assert!(comp.record(&dev, &list, &out, 4, 4, DXGI_FORMAT_R8G8B8A8_UNORM, &planes, 0));
list.ResourceBarrier(&[transition(&out, D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_COPY_SOURCE)]);
let out_desc = out.GetDesc();
@@ -1966,11 +1996,11 @@ mod frame_dump_tests {
let px = std::slice::from_raw_parts((rp as *const u8).add(off), 4);
let got = [px[0], px[1], px[2], px[3]];
rb.Unmap(0, None);
- // Concrete R8G8B8A8_UNORM_SRGB sampled with an sRGB SRV decodes sRGB -> linear
- // (~[128, 55, 0, 255]), whereas forcing UNORM fails SRV creation or skips sRGB decode.
+ // The compositor must leave an opaque sRGB plane at the same display-space value
+ // as the single-plane copy path, despite the sRGB SRV decoding the source.
assert!(
- (125..=131).contains(&got[0]) && (52..=58).contains(&got[1]) && got[2] == 0 && got[3] == 255,
- "expected sRGB-decoded concrete plane sample ~[128, 55, 0, 255], got {got:?}"
+ (187..=189).contains(&got[0]) && (127..=129).contains(&got[1]) && got[2] == 0 && got[3] == 255,
+ "expected display-space parity with a single-plane copy ~[188, 128, 0, 255], got {got:?}"
);
}
}
AI use: Codex (GPT-6.2 Sol) wrote and ran the local candidate and drafted this report; Codex (GPT-6.2 Astra) independently reviewed the color-space and blending choices. |
|
merge-check claim |
|
merge-check |
|
@ramon-victor heads-up on an overlap: I have a local change (not pushed yet) that lets a single presented plane in a packed-float format (R11G11B10_FLOAT / R9G9B9E5_SHAREDEXP) go through the compositor instead of being dropped by AI use: Claude Code (Claude Opus 5.5) wrote this. |
|
#2480 fixes the other half of #2456 (RTV tracking); nothing else makes this change. AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human. |
Preserves concrete
*_UNORM_SRGBresource formats when creating shader-resource views for compositedPresentXplanes inCompositor::record, resolving only*_TYPELESSformats to concrete SRV formats.Previously
Compositor::recordpassedswap_format(desc.Format).unwrap_or(desc.Format)toCreateShaderResourceView. Becauseswap_formatmapsDXGI_FORMAT_R8G8B8A8_UNORM_SRGBandDXGI_FORMAT_B8G8R8A8_UNORM_SRGBto*_UNORMfor flip-model swap-chain creation, concrete sRGB plane textures received an invalid non-sRGB SRV format (CREATESHADERRESOURCEVIEW_INVALIDFORMATin 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:plane_srv_format(f)resolving only*_TYPELESSformats (R8G8B8A8_TYPELESS,B8G8R8A8_TYPELESS,R10G10B10A2_TYPELESS,R16G16B16A16_TYPELESS) to concrete SRV formats while preserving concrete formats (including*_UNORM_SRGB).plane_srv_format(desc.Format)inCompositor::recordwhen buildingD3D12_SHADER_RESOURCE_VIEW_DESC.frame_dump_tests::compositor_preserves_concrete_srgb_plane_srv_formatverifyingplane_srv_formatacross concrete sRGB, typeless, and UNORM/float formats and exercisingCompositor::recordon WARP with a concreteDXGI_FORMAT_R8G8B8A8_UNORM_SRGBplane texture.Tested
621.24, wave32), AMD Ryzen 7 5700X, 32 GiB RAM, Windows 11 Pro (26300),rustc 1.99.0(x86_64-pc-windows-msvc), DXC/DXIL1.8.2502.11(Windows SDK10.0.26100.0).cargo test -p xcl --lib compositor_preserves_concrete_srgb_plane_srv_format -- --nocapturefailed (0 passed, 1 failed:expected sRGB-decoded concrete plane sample ~[128, 55, 0, 255], got [188, 128, 0, 255]).cargo test -p xcl --lib hle::d3d12x::present -- --test-threads=1 --nocapture:10 passed, 0 failed, 0 ignored..\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).cargo build --release -p xcl) and clean 60 s retail smoke run (.\scripts\smoke.ps1).Regression run
Baseline (
main):PR (
e8d2258):Not tested
*_UNORM_SRGBplanes (the retail smoke title presents a single plane; multi-plane concrete sRGB compositing is covered by the WARP regression test).AI use
plane_srv_formatand its WARP regression test, ran.\scripts\test.ps1, release build, and the 60 ssmoke.ps1run, and drafted this PR description.