Skip to content

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

Closed
AnoHunted wants to merge 1 commit into
Marvisak:mainfrom
AnoHunted:srgb-typed-cast-views
Closed

AnoHunted wants to merge 1 commit into
Marvisak:mainfrom
AnoHunted:srgb-typed-cast-views

Conversation

@AnoHunted

Copy link
Copy Markdown
Contributor

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 GPU: create host textures without the uses the host refuses #55 and gpu: packed 16-bit render targets are R8G8B8A8 where the GPU cannot render to them #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 <noreply@anthropic.com>
muhammed-aksoy pushed a commit to muhammed-aksoy/VIctory that referenced this pull request Nov 24, 2026
edsuuu referenced this pull request in edsuuu/VIctory-fork Nov 24, 2026
…eir own curve

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jeremygold02

Copy link
Copy Markdown
Contributor

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

@DeerSilver

Copy link
Copy Markdown

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).

Xeltax pushed a commit to Xeltax/VIcky that referenced this pull request Nov 24, 2026
Xeltax pushed a commit to Xeltax/VIcky that referenced this pull request Nov 24, 2026
…Marvisak#358 Marvisak#89 Marvisak#331 Marvisak#86 Marvisak#83 Marvisak#211 Marvisak#260 Marvisak#275)

Conflict in crates/victory-gpu/src/descriptor/host.rs: gpu-state (Marvisak#251)
moved the dynamic-slot search into free_table(); gpu-draw (Marvisak#86) bounds
the search by the heap's spare slots instead of DYNAMIC. free_table() works
over taken.len(), which is the spare count, so the helper is kept with
gpu-draw's spare-based cursor wrap. Both sides' tests kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
edsuuu referenced this pull request in edsuuu/VIctory-fork Nov 24, 2026
The tester tree (upstream main ffe310e plus its PRs, update 8; see its
INTEGRATION.md) ran 11-25 minutes in the world on an RTX 5070 without a
device removal. Where both sides carry the same PR (the wave64 stack
#223/#233/#320 with #439 and #180, #454, #336, #259, #331 and others), the
tester tree's newer head is taken; our own work and the PRs only we
merged are kept.

Conflicts, file by file:

- descriptor/host.rs: the tester layout (`spare`, the guard slot after the
  dynamic slots, `free_table`, the capped sampler heap). A capped view
  heap keeps `capped_reserve()` dynamic slots, now 2^18 by default (the
  tester measurement, and our 91fed158), still `VICTORY_DYNAMIC_SLOTS` in
  diagnostics builds; uncapped hosts keep our 2^19. Our slot statistics
  (TAKEN/PEAK/SHORT), the bindless plan cache (`CommittedRegions`,
  `timed_valid_title_address`, `timed_find`, `title_bounds`) and the
  revision triple are kept beside the tester's `guard_slot`.
- Buffer states: the tester tree's buffer-state tracker (#334: every list
  moves host copies of title memory between GENERIC_READ and
  UNORDERED_ACCESS and back to common before it closes) and depth twins
  (#469) are taken. #40's enhanced/legacy indirect barriers (the indirect
  prelude, `use_indirect_buffers`, the title buffer handoff mirrored in
  `host_barrier`) cannot share buffers with that tracker and are dropped;
  #40's argument checks (`byte_len`, exact spans, overflow-safe clamp
  shader, aligned counts) stay. `indirect::bound` and #282's
  `rectangles` go through `buffer_state`, and `indirect::execute` (#334)
  replaces `done`. #178's DXC fallback compiles both of our passes.
  Our segments (#387: `close` ends the segment, `close_native` closes a
  native list) carry the tracker: each native list returns its buffers
  to common and its twins to their depth targets, and each prelude also
  holds our texture uploads.
- shadow.rs: our write flow (`queue_write`, one `snapshot` after the
  batch's refreshes, `finish_writes`, the unchanged-page cache) with
  #261's copy-back that also gives the snapshot the title's bytes; its
  tests run through our flow.
- pipeline/make.rs: #275's per-frame budget and per-pipeline wake pair,
  with our compute waits (a dispatch waits for its pipeline, up to 20 s).
- pipeline/library.rs: the tester version (#347, #275's saver thread);
  our concurrent-write test kept. shader_cache.rs: our byte-returning
  cache API with #358's "translated, only not kept".
- draw.rs: #493's root SRV tables; where no table can stand in, our
  drop of a draw whose root view is unset or outside title buffers. Our
  refusal of a table offset past the capped heap stays.
- resource.rs: `HostTexture` has both our `staged` generation and the
  depth twin.
- Shaders: the tester's lower.rs for the wave64 stack, #160's image
  sampling (it covers our #73 and #136 sample forms) and #453/#587; kept
  from our side: #136's preference for an image or buffer use of a
  descriptor read as data and its `s_buffer_` arm, #422's nearest-even
  narrowing (also for #169's d16 loads and #453's interpolation), #452's
  spin-wait limit, #391's LDS limit, #302's spilled root arguments (now in
  `NativeProgram::translation_ir`), #136's PSV0 interpolation beside the
  tester's row harmonisation. split_tests.rs, lane_read_loop_tests.rs and
  docs/wave64-on-wave32.md are the tester versions (the same PRs at newer
  heads).
- Tests: #483's heap guard dwords filled in our GPU tests of #200
  (v_div_scale) and #437 (scalar loads from a raw view), which read
  through the guard slot otherwise; #334's debug-layer test passes an
  offset to our `indirect::bound`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 24, 2026
github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 24, 2026
@Marvisak Marvisak closed this Nov 24, 2026
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.

4 participants