Skip to content

D3D12.X: sRGB textures with unordered access are typeless on the PC - #3626

Draft
CharlyRien wants to merge 1 commit into
xcl-dev:mainfrom
CharlyRien:pr/srgb-typeless-uav
Draft

CharlyRien wants to merge 1 commit into
xcl-dev:mainfrom
CharlyRien:pr/srgb-typeless-uav

Conversation

@CharlyRien

Copy link
Copy Markdown
Contributor

The console lets a title create an R8G8B8A8_UNORM_SRGB / B8G8R8A8_UNORM_SRGB texture with unordered access and write it through a UNORM UAV. The PC has no sRGB UAV: pc_resource_desc drops ALLOW_UNORDERED_ACCESS from such a texture, and every UAV of it is a null view, so what the title writes there is lost. On the retail title the hair keeps its strands but loses its volume: one sees through it.

With XCL_SRGB_TYPELESS (default on, =0 for the old behaviour) such a texture is created in the TYPELESS family with unordered access. SRVs, RTVs and clears keep the title's sRGB format (null and UNKNOWN-format views too), UAVs are UNORM; a view with an explicit typed format of the family (UNORM, UINT, SNORM, SINT) keeps it. B8G8R8X8 sRGB is never made typeless (its sibling has no typed UAV on the PC). A live counter keeps the table's locks off resource release and view creation while no such texture lives.

Found by Jockerino, who traced the retail title's see-through hair to this (the hair pass writes an sRGB texture through a UNORM UAV). Same approach as VIctory's (https://github.com/Marvisak/VIctory, GPL-3.0; credited in THIRD_PARTY.md) and amd-dev's opt-in XCL_SRGB_UAV (a68f609). Related: #3291 makes placed and reserved resources drop the UAV flag the way committed ones do; this PR keeps the flag instead (the two meet in pc_resource_desc_for_device; whichever lands second needs a small rebase).

What is in it

  • d3d12x/device_x.rs: the typeless description, the PC formats of views and clears of such textures.
  • d3d12x/real.rs: the table of typeless sRGB textures (SRGB_TEXTURES, live counter), SRV / RTV / UAV / clear formats, forgetting on release.
  • d3d12x/bind.rs, present.rs: target matching and frame dumps use the title's format, not the typeless one (console_format_of); title_textures.rs: the GPU-owned layout check accepts the typeless storage of an sRGB texture.
  • README.md: the switch.
  • Tests (6: srgb_typeless_views_keep_the_titles_explicit_formats, srgb_uav_resource_desc_selects_typeless_only_for_eligible_textures, srgb_uav_clear_value_keeps_the_title_format, srgb_typeless_views_use_typed_defaults_and_keep_explicit_ranges, gpu_owned_metadata_accepts_exact_colour_layouts_only, gpu_srgb_typeless_uav_clear_and_copy_to_srgb).

Tested

Regression run

  • scripts/smoke.ps1, 60 s, the retail title, XCL_PREPARE=0, cold shader cache on every run, two runs a side, alternating (head, main, head, main): main 1c8b5514 480 and 503 frames, this head 345 and 496; peak commit 16,183 / 16,186 MB vs 16,041 / 16,389 MB; no removal, no crash. The 345 lost its frames at the start (after the title's first frames, one 2 s window with no present and two slow ones; steady 60 a 2 s afterwards, as the others); the second pair is 496 vs 503 (99 %). Blocks of the second pair:
xcl-smoke v1
commit: 1c8b551475e1e7bfe48f94448492a4c3544a2e0f
gpu: NVIDIA GeForce RTX 3090
title: 16b5e5d4
seconds: 60
exit: 0x0
frames shown: 503 (PresentX 503)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 16186 MB
xcl-smoke v1
commit: 45fbb0701602f6c28621344716657afc57abc05e
gpu: NVIDIA GeForce RTX 3090
title: 16b5e5d4
seconds: 60
exit: 0x0
frames shown: 496 (PresentX 496)
presents per 2 s (last 3): 60 61 60
device removals: 0
crashes: 0
peak commit: 16389 MB

Not tested

  • AMD; plain main in the world (our tree carries other changes, listed above); titles other than the retail one; XCL_SRGB_TYPELESS=0 in the game (the old behaviour).

AI use

  • Codex (GPT-6.2 Sol) wrote the first version; Antigravity CLI (Gemini 4 Neon) reviewed it read-only; Claude Code (Claude Opus 5.5) applied the review, ported it onto main, ran the builds, tests and game runs and wrote this description. Opened as a draft by Claude Code at my request; I check it before it leaves draft.

The console lets a title create an R8G8B8A8_UNORM_SRGB / B8G8R8A8_UNORM_SRGB
texture with unordered access and write it through a UNORM UAV. The PC has no
sRGB UAV: pc_resource_desc dropped ALLOW_UNORDERED_ACCESS and every such UAV
was a null view. A retail title's hair pass writes its colour that way: the
hair kept its strands but lost its volume (one saw through it).

With XCL_SRGB_TYPELESS (default on, =0 for the old behaviour) such a texture is
created in the TYPELESS family with unordered access. SRVs, RTVs and clears
keep the title's sRGB format (null and UNKNOWN views too), UAVs are UNORM; a
view with an explicit typed format of the family (UNORM, UINT, SNORM, SINT)
keeps it. B8G8R8X8 sRGB is never made typeless (no typed UAV of its sibling on
the PC). A live counter keeps the table's locks off resource release and view
creation while no such texture lives.

Found by Jockerino (the retail title's hair, written through a UNORM UAV of
an sRGB texture). Same approach as VIctory (GPL-3.0, credited in THIRD_PARTY.md) and amd-dev's
opt-in XCL_SRGB_UAV (a68f609).

Assisted-by: Codex CLI (GPT-6.2 Sol)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:docs-ci Documentation, scripts, workflows, repo governance gpu:amd Code is specific to AMD / RDNA / wave64 GPUs (scope tag; see needs:amd-test) labels Dec 1, 2026
@Foniass

Foniass commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Review (head 45fbb07, diff read, not a merge-check; draft):

  • On by default with little evidence for the default. XCL_SRGB_TYPELESS is on unless set to 0 (device_x.rs ~824), which changes the PC resource format, initial state, clear value and every SRV/RTV/UAV of single-sampled R8G8B8A8_UNORM_SRGB / B8G8R8A8_UNORM_SRGB textures with unordered access in every title. The fixed hair was seen on a local tree with 42 other commits and lab switches, not on this head; only one NVIDIA GPU, no AMD; and by the description one of the two head smoke runs reached 345 frames against main's 480 (72 %, under the 80 % bar), with only the other pair pasted.
  • The full suite was not run. Tested gives only the 6 new tests (with the switch unset and =1), though pc_resource_desc (~847) now returns a different desc for these textures and other modules' tests call it.
  • Two uncapped log lines on the resource-creation path. note_srgb_texture (real.rs ~2039, ~2042) logs an xlog_info line for every sRGB texture with unordered access created through the committed, display-target, CreatePlacedResourceX and heap CreatePlacedResource paths, and still logs the "stripped" line with XCL_SRGB_TYPELESS=0. A title that places transient targets every frame gets a line per texture per frame; the nearby create-path logs are capped (once(&N, 4), N.fetch_add(..) < 8).

Fine: the device check falls back to the old desc when the UNORM sibling has no typed UAV; SRGB_TEXTURES is cleared in res_release before recycling and every path that creates a typeless texture notes it; the UAV-at path goes through the checked UAV format mapping; the download and GPU-owned layout checks accept the typeless format of the same family; the new tests fail without the change. #3291, #3418 and #3376 touch the same functions (pc_resource_desc_for_device, pc_clear_for_desc, create_display_target), so expect rebases.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

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

Labels

area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:docs-ci Documentation, scripts, workflows, repo governance gpu:amd Code is specific to AMD / RDNA / wave64 GPUs (scope tag; see needs:amd-test)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants