GPU: sRGB and linear views of one texture read with their own curve #331

Closed
github-bot wants to merge 1 commit from gh-pr/331/head into gh-pr/331/base
Owner

@⁠AnoHunted on GitHub · 2026-11-24 02:21 UTC · original
AnoHunted:srgb-typed-cast-views → main · +251 −6 · 2 files · 1 commits · closed without merging

What

  • fits (descriptor/host.rs) keeps the title's view format when the view is the sRGB or linear
    twin of a typed texture's format and the host reports CastingFullyTypedFormatSupported
    (D3D12_FEATURE_D3D12_OPTIONS3). An R8G8B8A8_UNORM_SRGB view of an R8G8B8A8_UNORM texture now
    converts sRGB to linear when a shader reads it, and an R8G8B8A8_UNORM view of an sRGB texture no
    longer does.
  • casts_typed asks for the cap once. A host without it keeps today's behaviour and logs a warning
    once.
  • resource::SRGB gains the BC1, BC2, BC3 and BC7 pairs. Its other users handle sRGB unordered
    access, which block-compressed textures never have.
  • Nothing else changes. Host textures are made as before, and other casts within a family (UINT of
    UNORM, say) still read in the texture's own format.
  • New host GPU test, resource::tests::srgb_and_linear_views_of_one_texture_read_their_own_curve.
    It makes 4x4 textures through create_committed: R8G8B8A8, B8G8R8A8 and BC1, each in its linear
    and its sRGB format. It fills their memory with 0x80 (BC1: one block of red 16/31) and makes three
    views with create_srv: sRGB, linear, and one with no description. They are mirrored into a host
    heap as for a draw, uploaded by texture::upload, and a compute shader Loads each view once.

Why

The console lets a title view a texture in any format of its family. When the view format differed
from a typed texture's own, fits swapped in the texture's own format, which its comment flagged as
a shortcut. An sRGB view of a UNORM texture then read with no sRGB-to-linear conversion, and a UNORM
view of an sRGB texture converted anyway, so colours came out with the wrong gamma.

Microsoft's D3D12 documentation describes CastingFullyTypedFormatSupported as casting "from one
fully typed format to another, compatible, format". The DirectX relaxed casting spec defines that as
an SRV, UAV, RTV or DSV in any fully qualified format of the resource's family. Its own example is an
R8G8B8A8_UNORM resource with an R8G8B8A8_UNORM_SRGB SRV. It never allows SNORM to UNORM, or FLOAT to
non-FLOAT. sRGB and UNORM twins are neither, so only those pairs are let through. Depth formats are
not touched.

Two other approaches were weighed:

  • Typeless host copies, as the layer already makes for depth textures that shaders read and for
    sRGB textures with unordered access. A view of a typeless resource must name a format; a null
    description "inherits the resource format and dimension (if not typeless)". So every null-description
    SRV, UAV and RTV of an RGBA8, BGRA8 or BC texture would need a whole-resource description built per
    dimension, and frame capture would need to know the typeless formats. That means more code in more
    places, overlapping host_texture, which #55 and #89 also change.
  • Castable formats through ID3D12Device10::CreateCommittedResource3. That call takes an
    enhanced-barrier initial layout instead of a resource state and needs Agility SDK 1.7 or later. The
    layer uses ID3D12Device and legacy states throughout.

Casting fully typed formats needs neither: one feature query and one condition in fits.

Render target views already pass the title's format to the host (RtvRecord::host_desc), so they
need no change. sRGB unordered access views still become their linear twin, as before: the host has no
sRGB UAVs.

Tested

Windows 11, NVIDIA GeForce RTX 5080, Rust 1.98.1, and WARP.

  • The new test run against main (the test alone, without the fix) fails on the RTX 5080 and on
    WARP alike. One view of every texture reads with the wrong curve; the values below are on the RTX
    5080:

    texture sRGB view linear view no description
    R8G8B8A8_UNORM 0.502 (want 0.216) 0.502 0.502
    R8G8B8A8_UNORM_SRGB 0.216 0.216 (want 0.502) 0.216
    B8G8R8A8_UNORM 0.502 (want 0.216) 0.502 0.502
    B8G8R8A8_UNORM_SRGB 0.216 0.216 (want 0.502) 0.216
    BC1_UNORM 0.518 (want 0.230) 0.518 0.518
    BC1_UNORM_SRGB 0.230 0.230 (want 0.518) 0.230

    On this branch it passes. Every sRGB view reads 0.216 (BC1: 0.230), every linear view 0.502 (BC1:
    0.518), and views without a description read in the texture's own format. WARP's values are within
    0.0003 of these (--features diagnostics, VICTORY_D3D12_WARP=1).

  • cargo test -p victory-gpu: main 43 passed, 0 failed, 1 ignored; branch 44 passed (the new test),
    0 failed, 1 ignored.

  • cargo test --workspace: main 264 passed, 0 failed, 4 ignored; branch 265 passed, 0 failed, 4
    ignored.

  • cargo clippy -p victory-gpu --all-targets: no new warnings; the one warning, in host.rs, is on
    main too. cargo xtask policy: ok.

  • rustfmt --check on the two files reports nothing in the lines this change adds. The other
    differences it reports are already on main.

Not tested

  • AMD and Intel GPUs; Linux with vkd3d-proton.
  • The D3D12 debug layer was not available on the test machine, so it was not run.
  • A host without CastingFullyTypedFormatSupported, where the old behaviour and the warning apply.
  • BC2, BC3, BC7 and B8G8R8X8 sRGB views, which take the same path as the tested pairs.
  • sRGB render target views of a UNORM texture: that code is unchanged and was not exercised.
  • The title: not tested.

Overlap

#301 (opened while this was being tested) also fixes the sRGB part, as one piece of a larger change (non-stream PSOs, stream subobjects 25..=28, texture-to-buffer readbacks): it makes sRGB-castable host textures typeless and synthesises view descriptions. This PR is the sRGB fix on its own, with a different mechanism (fully typed format casting, no change to how host textures are made), in case a smaller, separate change is easier to review. The two conflict textually in resource.rs; if #301 lands first, this one can be closed, and its test could still be moved onto #301's version.

AI-assisted (Claude Code, Claude Opus 5.5). No game files were used.

**@⁠AnoHunted** on GitHub · 2026-11-24 02:21 UTC · [original](https://github.com/Marvisak/VIctory/pull/331) `AnoHunted:srgb-typed-cast-views` → `main` · +251 −6 · 2 files · 1 commits · closed without merging ## What - `fits` (`descriptor/host.rs`) keeps the title's view format when the view is the sRGB or linear twin of a typed texture's format and the host reports `CastingFullyTypedFormatSupported` (`D3D12_FEATURE_D3D12_OPTIONS3`). An R8G8B8A8_UNORM_SRGB view of an R8G8B8A8_UNORM texture now converts sRGB to linear when a shader reads it, and an R8G8B8A8_UNORM view of an sRGB texture no longer does. - `casts_typed` asks for the cap once. A host without it keeps today's behaviour and logs a warning once. - `resource::SRGB` gains the BC1, BC2, BC3 and BC7 pairs. Its other users handle sRGB unordered access, which block-compressed textures never have. - Nothing else changes. Host textures are made as before, and other casts within a family (UINT of UNORM, say) still read in the texture's own format. - New host GPU test, `resource::tests::srgb_and_linear_views_of_one_texture_read_their_own_curve`. It makes 4x4 textures through `create_committed`: R8G8B8A8, B8G8R8A8 and BC1, each in its linear and its sRGB format. It fills their memory with 0x80 (BC1: one block of red 16/31) and makes three views with `create_srv`: sRGB, linear, and one with no description. They are mirrored into a host heap as for a draw, uploaded by `texture::upload`, and a compute shader `Load`s each view once. ## Why The console lets a title view a texture in any format of its family. When the view format differed from a typed texture's own, `fits` swapped in the texture's own format, which its comment flagged as a shortcut. An sRGB view of a UNORM texture then read with no sRGB-to-linear conversion, and a UNORM view of an sRGB texture converted anyway, so colours came out with the wrong gamma. Microsoft's D3D12 documentation describes `CastingFullyTypedFormatSupported` as casting "from one fully typed format to another, compatible, format". The DirectX relaxed casting spec defines that as an SRV, UAV, RTV or DSV in any fully qualified format of the resource's family. Its own example is an R8G8B8A8_UNORM resource with an R8G8B8A8_UNORM_SRGB SRV. It never allows SNORM to UNORM, or FLOAT to non-FLOAT. sRGB and UNORM twins are neither, so only those pairs are let through. Depth formats are not touched. Two other approaches were weighed: - **Typeless host copies**, as the layer already makes for depth textures that shaders read and for sRGB textures with unordered access. A view of a typeless resource must name a format; a null description "inherits the resource format and dimension (if not typeless)". So every null-description SRV, UAV and RTV of an RGBA8, BGRA8 or BC texture would need a whole-resource description built per dimension, and frame capture would need to know the typeless formats. That means more code in more places, overlapping `host_texture`, which #55 and #89 also change. - **Castable formats** through `ID3D12Device10::CreateCommittedResource3`. That call takes an enhanced-barrier initial layout instead of a resource state and needs Agility SDK 1.7 or later. The layer uses `ID3D12Device` and legacy states throughout. Casting fully typed formats needs neither: one feature query and one condition in `fits`. Render target views already pass the title's format to the host (`RtvRecord::host_desc`), so they need no change. sRGB unordered access views still become their linear twin, as before: the host has no sRGB UAVs. ## Tested Windows 11, NVIDIA GeForce RTX 5080, Rust 1.98.1, and WARP. - The new test run against main (the test alone, without the fix) fails on the RTX 5080 and on WARP alike. One view of every texture reads with the wrong curve; the values below are on the RTX 5080: | texture | sRGB view | linear view | no description | |---|---|---|---| | R8G8B8A8_UNORM | 0.502 (want 0.216) | 0.502 | 0.502 | | R8G8B8A8_UNORM_SRGB | 0.216 | 0.216 (want 0.502) | 0.216 | | B8G8R8A8_UNORM | 0.502 (want 0.216) | 0.502 | 0.502 | | B8G8R8A8_UNORM_SRGB | 0.216 | 0.216 (want 0.502) | 0.216 | | BC1_UNORM | 0.518 (want 0.230) | 0.518 | 0.518 | | BC1_UNORM_SRGB | 0.230 | 0.230 (want 0.518) | 0.230 | On this branch it passes. Every sRGB view reads 0.216 (BC1: 0.230), every linear view 0.502 (BC1: 0.518), and views without a description read in the texture's own format. WARP's values are within 0.0003 of these (`--features diagnostics`, `VICTORY_D3D12_WARP=1`). - `cargo test -p victory-gpu`: main 43 passed, 0 failed, 1 ignored; branch 44 passed (the new test), 0 failed, 1 ignored. - `cargo test --workspace`: main 264 passed, 0 failed, 4 ignored; branch 265 passed, 0 failed, 4 ignored. - `cargo clippy -p victory-gpu --all-targets`: no new warnings; the one warning, in `host.rs`, is on main too. `cargo xtask policy`: ok. - `rustfmt --check` on the two files reports nothing in the lines this change adds. The other differences it reports are already on main. ## Not tested - AMD and Intel GPUs; Linux with vkd3d-proton. - The D3D12 debug layer was not available on the test machine, so it was not run. - A host without `CastingFullyTypedFormatSupported`, where the old behaviour and the warning apply. - BC2, BC3, BC7 and B8G8R8X8 sRGB views, which take the same path as the tested pairs. - sRGB render target views of a UNORM texture: that code is unchanged and was not exercised. - The title: not tested. ## Overlap #301 (opened while this was being tested) also fixes the sRGB part, as one piece of a larger change (non-stream PSOs, stream subobjects 25..=28, texture-to-buffer readbacks): it makes sRGB-castable host textures typeless and synthesises view descriptions. This PR is the sRGB fix on its own, with a different mechanism (fully typed format casting, no change to how host textures are made), in case a smaller, separate change is easier to review. The two conflict textually in `resource.rs`; if #301 lands first, this one can be closed, and its test could still be moved onto #301's version. AI-assisted (Claude Code, Claude Opus 5.5). No game files were used.
The console lets a title view a texture in any format of its family: an
R8G8B8A8_UNORM texture as R8G8B8A8_UNORM_SRGB, say, or the reverse. `fits`
gave every such view of a typed host texture the texture's own format, so
the hardware did no sRGB-to-linear conversion where the title asked for
one, or converted where it did not: colours came out with the wrong gamma.

Hosts that report CastingFullyTypedFormatSupported (D3D12 options 3) let
views of a fully typed resource name another format of its family, with no
change to how the resource is made. sRGB and linear twins (8-bit RGBA,
BGRA, BGRX, and BC1, BC2, BC3 and BC7) now keep the title's view format on
such hosts; other casts within a family read as before, and hosts without
the cap keep today's behaviour with a warning.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:59:33 +00:00
github-bot closed this pull request 2026-11-26 03:59:33 +00:00
Author
Owner

@⁠jeremygold02 on GitHub · 2026-11-24 04:21 UTC · original

Tested PR #331 at head ccdecb80807826e49ce82a5d9aa6e7814d2b8376 (state at test time: OPEN). Pre-comment refresh: state OPEN, head unchanged at ccdecb80807826e49ce82a5d9aa6e7814d2b8376.

  • cargo test --locked -p victory-gpu srgb_and_linear_views_of_one_texture_read_their_own_curve — passed (ok. 1 passed; 0 failed; 0 ignored; 0 measured; 44 filtered out; finished in 0.40s ); cases: resource::tests::srgb_and_linear_views_of_one_texture_read_their_own_curve.

Behavior covered: Checks linear and sRGB texture views of one resource use their own color curve; this is a host GPU test.
Code: crates/victory-gpu/src/descriptor/host.rs, crates/victory-gpu/src/resource.rs

**@⁠jeremygold02** on GitHub · 2026-11-24 04:21 UTC · [original](https://github.com/Marvisak/VIctory/pull/331#issuecomment-7121940103) Tested PR #331 at head `ccdecb80807826e49ce82a5d9aa6e7814d2b8376` (state at test time: OPEN). Pre-comment refresh: state OPEN, head unchanged at `ccdecb80807826e49ce82a5d9aa6e7814d2b8376`. - `cargo test --locked -p victory-gpu srgb_and_linear_views_of_one_texture_read_their_own_curve` — passed (ok. 1 passed; 0 failed; 0 ignored; 0 measured; 44 filtered out; finished in 0.40s ); cases: resource::tests::srgb_and_linear_views_of_one_texture_read_their_own_curve. Behavior covered: Checks linear and sRGB texture views of one resource use their own color curve; this is a host GPU test. Code: [crates/victory-gpu/src/descriptor/host.rs](https://github.com/Marvisak/VIctory/blob/ccdecb80807826e49ce82a5d9aa6e7814d2b8376/crates/victory-gpu/src/descriptor/host.rs), [crates/victory-gpu/src/resource.rs](https://github.com/Marvisak/VIctory/blob/ccdecb80807826e49ce82a5d9aa6e7814d2b8376/crates/victory-gpu/src/resource.rs)
Author
Owner

@⁠DeerSilver on GitHub · 2026-11-24 10:51 UTC · original

Tested head ccdecb8 merged onto main ffe310e (clean merge) on NVIDIA GeForce RTX 5060 Laptop GPU (Blackwell), driver 621.24, Windows 11 26300, Rust 1.98.1. No game files: the test suite only: pass.

  • srgb_and_linear_views_of_one_texture_read_their_own_curve ran on the RTX 5060 (DXGI adapter 0 on this laptop) and passed. So sRGB and linear views of one texture each read back with their own curve on NVIDIA.
  • cargo test --workspace --locked: 343 passed, 0 failed, 6 ignored, against 342 / 6 on main.
  • cargo clippy --workspace --all-targets --locked -- -D warnings: clean.

AI-assisted (Claude Code).

**@⁠DeerSilver** on GitHub · 2026-11-24 10:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/331#issuecomment-7129331046) Tested head `ccdecb8` merged onto `main` `ffe310e` (clean merge) on **NVIDIA GeForce RTX 5060 Laptop GPU** (Blackwell), driver 621.24, Windows 11 26300, Rust 1.98.1. No game files: the test suite only: **pass.** - `srgb_and_linear_views_of_one_texture_read_their_own_curve` ran on the RTX 5060 (DXGI adapter 0 on this laptop) and passed. So sRGB and linear views of one texture each read back with their own curve on NVIDIA. - `cargo test --workspace --locked`: **343 passed, 0 failed, 6 ignored**, against 342 / 6 on `main`. - `cargo clippy --workspace --all-targets --locked -- -D warnings`: clean. AI-assisted (Claude Code).

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!331
No description provided.