GPU: make shared sRGB textures typeless for unordered access #2679

Open
github-bot wants to merge 1 commit from github-bot/gh-2679 into main AGit
Owner

@⁠fuzeofficlal on GitHub · 2026-11-25 18:01 UTC · original
fuzeofficlal:fix/gpu-shared-texture-srgb-uav → main · +189 −3 · 2 files · 1 commits · open

Summary

  • Extract typeless_if_unordered_srgb in crates/victory-gpu/src/resource.rs and call it again in shared_texture after merging sibling USES flags from TEXTURES_AT, so an sRGB render target sharing memory with an unordered-access texture is promoted to its typeless family before make_texture.
  • Generalize typed_store validation in crates/victory-gpu/src/descriptor/host.rs::fits to cover default (view == 0) and same-family unordered views in addition to cross-family casts (pairing with #2462 so promoting B8G8R8X8_UNORM_SRGB -> B8G8R8X8_TYPELESS never lets an unsupported B8G8R8X8_UNORM UAV reach CreateUnorderedAccessView if this PR lands ahead of #2462).
  • Add regression tests in resource::tests::shared_srgb_render_targets_with_unordered_access_are_typeless (covering RGBA8, BGRA8, and BGRX8 shared RT + UAV creation, verifying RGBA8/BGRA8 UAVs succeed, unsupported BGRX8 linear/sRGB UAVs stay null without device removal, and castable R32_UINT UAVs still succeed) and descriptor::host::tests::unsupported_same_family_and_default_uavs_are_refused.

Verification

  • cargo clippy --locked -p victory-gpu --all-targets -- -D warnings and --features diagnostics: 0 warnings.
  • NVIDIA GeForce RTX 5090 (rustc 1.98.1 MSVC): shared_srgb_render_targets_with_unordered_access_are_typeless and unsupported_same_family_and_default_uavs_are_refused pass (GetDeviceRemovedReason() == S_OK).
  • WARP (VICTORY_D3D12_WARP=1): cargo test --locked -p victory-gpu --features diagnostics --lib -- --test-threads=1 -> 200 passed, 0 failed, 1 ignored.
  • cargo xtask policy: 184 files ok.
**@⁠fuzeofficlal** on GitHub · 2026-11-25 18:01 UTC · [original](https://github.com/Marvisak/VIctory/pull/2679) `fuzeofficlal:fix/gpu-shared-texture-srgb-uav` → `main` · +189 −3 · 2 files · 1 commits · open ## Summary - Extract `typeless_if_unordered_srgb` in `crates/victory-gpu/src/resource.rs` and call it again in `shared_texture` after merging sibling `USES` flags from `TEXTURES_AT`, so an sRGB render target sharing memory with an unordered-access texture is promoted to its typeless family before `make_texture`. - Generalize `typed_store` validation in `crates/victory-gpu/src/descriptor/host.rs::fits` to cover default (`view == 0`) and same-family unordered views in addition to cross-family casts (pairing with #2462 so promoting `B8G8R8X8_UNORM_SRGB` -> `B8G8R8X8_TYPELESS` never lets an unsupported `B8G8R8X8_UNORM` UAV reach `CreateUnorderedAccessView` if this PR lands ahead of #2462). - Add regression tests in `resource::tests::shared_srgb_render_targets_with_unordered_access_are_typeless` (covering RGBA8, BGRA8, and BGRX8 shared RT + UAV creation, verifying RGBA8/BGRA8 UAVs succeed, unsupported BGRX8 linear/sRGB UAVs stay null without device removal, and castable `R32_UINT` UAVs still succeed) and `descriptor::host::tests::unsupported_same_family_and_default_uavs_are_refused`. ## Verification - `cargo clippy --locked -p victory-gpu --all-targets -- -D warnings` and `--features diagnostics`: 0 warnings. - NVIDIA GeForce RTX 5090 (`rustc 1.98.1` MSVC): `shared_srgb_render_targets_with_unordered_access_are_typeless` and `unsupported_same_family_and_default_uavs_are_refused` pass (`GetDeviceRemovedReason() == S_OK`). - WARP (`VICTORY_D3D12_WARP=1`): `cargo test --locked -p victory-gpu --features diagnostics --lib -- --test-threads=1` -> 200 passed, 0 failed, 1 ignored. - `cargo xtask policy`: 184 files ok.
When a shared host texture is first created for an sRGB render target
and a sibling title texture at the same memory has ALLOW_UNORDERED_ACCESS,
`shared_texture` merges sibling `USES` flags after `host_desc` already ran.
Without re-applying the sRGB-to-typeless promotion, `make_texture` attempts
to create a typed sRGB texture with ALLOW_UNORDERED_ACCESS, which D3D12
rejects.

Extract `typeless_if_unordered_srgb` and apply it in both `host_desc` and
`shared_texture` after merging sibling uses.

Because promoting `B8G8R8X8_UNORM_SRGB` to `B8G8R8X8_TYPELESS` allows
resource creation to succeed even on hosts where `B8G8R8X8_UNORM` does not
support typed UAVs, also generalize the `typed_store` check in
`descriptor::host::fits` to cover default and same-family unordered views
(matching #2462), keeping unsupported typed UAV slots null instead of
removing the device.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:11:51 +00:00
Author
Owner

@⁠DrDarkDK on GitHub · 2026-11-25 18:12 UTC · original

The BGRX family still needs a UAV capability check after typeless promotion. I ran a standalone D3D12 probe on an RTX 4070 Ti (driver 621.01, Windows 11 build 26300), using 64×64 textures with both render-target and unordered-access flags.

Host resource after promotion Resource creation Typed UAV support for the linear format
R8G8B8A8_TYPELESS S_OK Yes
B8G8R8A8_TYPELESS S_OK Yes
B8G8R8X8_TYPELESS S_OK No

The same-family view path bypasses typed_store, so successful BGRX resource creation can still lead to an unsupported B8G8R8X8_UNORM UAV. Could we pair this with the check in #2462 and test that the unsupported view stays null?

The probe checked resource creation and reported format support. I didn’t create the unsupported view or run VIctory.

AI-assisted with Codex.

**@⁠DrDarkDK** on GitHub · 2026-11-25 18:12 UTC · [original](https://github.com/Marvisak/VIctory/pull/2679#issuecomment-7170584438) The BGRX family still needs a UAV capability check after typeless promotion. I ran a standalone D3D12 probe on an RTX 4070 Ti (driver 621.01, Windows 11 build 26300), using 64×64 textures with both render-target and unordered-access flags. | Host resource after promotion | Resource creation | Typed UAV support for the linear format | | --- | --- | --- | | `R8G8B8A8_TYPELESS` | `S_OK` | Yes | | `B8G8R8A8_TYPELESS` | `S_OK` | Yes | | `B8G8R8X8_TYPELESS` | `S_OK` | No | The same-family view path bypasses `typed_store`, so successful BGRX resource creation can still lead to an unsupported `B8G8R8X8_UNORM` UAV. Could we pair this with the check in #2462 and test that the unsupported view stays null? The probe checked resource creation and reported format support. I didn’t create the unsupported view or run VIctory. *AI-assisted with Codex.*
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-25 18:29 UTC · original

Thanks for the hardware probe and catch, @⁠DrDarkDK! You're completely right — without the same-family typed_store check from #2462, promoting a shared B8G8R8X8_UNORM_SRGB + UNORDERED texture to B8G8R8X8_TYPELESS would allow resource creation to succeed and then pass an unsupported B8G8R8X8_UNORM UAV to CreateUnorderedAccessView if this PR merged ahead of #2462.

Updated in b5c7f9d:

  • Generalized descriptor::host::fits so typed_store checks the effective view format for default (view == 0), same-family, and castable unordered views alike (matching #2462's safeguard so this PR is safe standalone; happy to rebase cleanly if #2462 lands first).
  • Extended resource::tests::shared_srgb_render_targets_with_unordered_access_are_typeless to cover all three SRGB families (RGBA8, BGRA8, and BGRX8), creating actual UAV descriptors via HostHeap::make_at and asserting that:
    • supported R8G8B8A8_UNORM / B8G8R8A8_UNORM UAVs succeed,
    • unsupported B8G8R8X8_UNORM (and B8G8R8X8_UNORM_SRGB rewritten to linear) UAVs stay null with GetDeviceRemovedReason() == S_OK,
    • castable R32_UINT UAVs on the promoted B8G8R8X8_TYPELESS texture still succeed.
  • Added descriptor::host::tests::unsupported_same_family_and_default_uavs_are_refused covering fits directly for typeless same-family and typed default/same-family unsupported UAVs.

Re-verified on NVIDIA GeForce RTX 5090 (both new tests pass, B8G8R8X8_UNORM typed UAV confirmed unsupported and kept null) and WARP (200 passed, 0 failed, 1 ignored, clippy 0 warnings, xtask policy ok).

**@⁠fuzeofficlal** on GitHub · 2026-11-25 18:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/2679#issuecomment-7170970635) Thanks for the hardware probe and catch, @⁠DrDarkDK! You're completely right — without the same-family `typed_store` check from #2462, promoting a shared `B8G8R8X8_UNORM_SRGB` + `UNORDERED` texture to `B8G8R8X8_TYPELESS` would allow resource creation to succeed and then pass an unsupported `B8G8R8X8_UNORM` UAV to `CreateUnorderedAccessView` if this PR merged ahead of #2462. Updated in `b5c7f9d`: - Generalized `descriptor::host::fits` so `typed_store` checks the effective view format for default (`view == 0`), same-family, and castable unordered views alike (matching #2462's safeguard so this PR is safe standalone; happy to rebase cleanly if #2462 lands first). - Extended `resource::tests::shared_srgb_render_targets_with_unordered_access_are_typeless` to cover all three `SRGB` families (`RGBA8`, `BGRA8`, and `BGRX8`), creating actual UAV descriptors via `HostHeap::make_at` and asserting that: - supported `R8G8B8A8_UNORM` / `B8G8R8A8_UNORM` UAVs succeed, - unsupported `B8G8R8X8_UNORM` (and `B8G8R8X8_UNORM_SRGB` rewritten to linear) UAVs stay null with `GetDeviceRemovedReason() == S_OK`, - castable `R32_UINT` UAVs on the promoted `B8G8R8X8_TYPELESS` texture still succeed. - Added `descriptor::host::tests::unsupported_same_family_and_default_uavs_are_refused` covering `fits` directly for typeless same-family and typed default/same-family unsupported UAVs. Re-verified on NVIDIA GeForce RTX 5090 (both new tests pass, `B8G8R8X8_UNORM` typed UAV confirmed unsupported and kept null) and WARP (`200 passed, 0 failed, 1 ignored`, `clippy` 0 warnings, `xtask policy` ok).
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-25 18:37 UTC · original

Correct on both sides: the shared-texture merge now re-runs the sRGB->typeless promotion after sibling USES flags are merged (the case host_desc can't see alone), and fits() covers the two holes the promotion opens - a default view (view==0) on a typed texture, and a same-family view on a typeless one - both checking typed_store on the effective format. The test matrix (RGBA8/BGRA8 succeed, BGRX8 refused without device removal, R32_UINT cast still works) covers exactly the promotion's edge cases.

**@⁠kotekompotek** on GitHub · 2026-11-25 18:37 UTC · [original](https://github.com/Marvisak/VIctory/pull/2679#issuecomment-7171176351) Correct on both sides: the shared-texture merge now re-runs the sRGB->typeless promotion after sibling USES flags are merged (the case host_desc can't see alone), and fits() covers the two holes the promotion opens - a default view (view==0) on a typed texture, and a same-family view on a typeless one - both checking typed_store on the effective format. The test matrix (RGBA8/BGRA8 succeed, BGRX8 refused without device removal, R32_UINT cast still works) covers exactly the promotion's edge cases.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 22:16 UTC · original · edited 2026-11-26 03:22 UTC

Automated triage for the maintainers.

Verdict: merge candidate. I reviewed the rebased head e59bde5. The functional change is one call: shared_texture (crates/victory-gpu/src/resource.rs) runs the sRGB-to-typeless promotion (now typeless_if_unordered_srgb) again after merging sibling USES flags. Before, an sRGB render target that shared memory with an unordered-access texture was created as a typed sRGB resource with UAV access, which the host does not support. The view-side guard the description talks about (fits checking typed_store for default and same-family views) is already on main via #2462, so the descriptor/host.rs hunk here is now a test of that code only.

Small point: unsupported_same_family_and_default_uavs_are_refused asserts !typed_store(B8G8R8X8_UNORM) outright. The other test checks support at runtime, and this one should too, in case some adapter reports support.

CI: check passing.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 22:16 UTC · [original](https://github.com/Marvisak/VIctory/pull/2679#issuecomment-7176166738) · edited 2026-11-26 03:22 UTC <!-- victory-triage v1 head=e59bde5d05f017cd722678f4aa2e0e65ce77e17b verdict=merge-candidate at=2026-11-26T03:22:24Z --> Automated triage for the maintainers. **Verdict: merge candidate.** I reviewed the rebased head `e59bde5`. The functional change is one call: `shared_texture` (`crates/victory-gpu/src/resource.rs`) runs the sRGB-to-typeless promotion (now `typeless_if_unordered_srgb`) again after merging sibling `USES` flags. Before, an sRGB render target that shared memory with an unordered-access texture was created as a typed sRGB resource with UAV access, which the host does not support. The view-side guard the description talks about (`fits` checking `typed_store` for default and same-family views) is already on `main` via #2462, so the `descriptor/host.rs` hunk here is now a test of that code only. Small point: `unsupported_same_family_and_default_uavs_are_refused` asserts `!typed_store(B8G8R8X8_UNORM)` outright. The other test checks support at runtime, and this one should too, in case some adapter reports support. CI: `check` passing. --- _Generated by [Claude Code](https://claude.ai/code)_
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2679/head:github-bot/gh-2679'
git switch 'github-bot/gh-2679'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2679'
git switch 'github-bot/gh-2679'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2679'
git switch 'github-bot/gh-2679'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2679'
git switch 'main'
git merge --squash 'github-bot/gh-2679'
git switch 'main'
git merge --ff-only 'github-bot/gh-2679'
git switch 'main'
git merge 'github-bot/gh-2679'
git push origin 'main'
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!2679
No description provided.