GPU: the depth twin's converter builds its root signature when the compiler drops it (Wine) #1872

Closed
github-bot wants to merge 2 commits from gh-pr/1872/head into gh-pr/1872/base
Owner

@⁠BastienRodz on GitHub · 2026-11-24 23:56 UTC · original
BastienRodz:gpu/twin-converter-root-signature → main · +170 −3 · 1 files · 2 commits · closed without merging

What's wrong

In #1860, 16-bit depth written through unordered access views never
reaches the host 24-bit depth texture under Wine's builtin
d3dcompiler_47:

  • crates/victory-gpu/src/twin.rs compiles the compute converter
    (SOURCE, cs_5_1, with
    #define RS "RootConstants(num32BitConstants=8, b0), UAV(u0)" and
    [RootSignature(RS)]) and then calls
    device.CreateRootSignature(0, bytes) on the shader blob itself.
  • Wine's builtin d3dcompiler_47 (vkd3d-shader, as measured in #1860
    on Wine 11.22) ignores the [RootSignature] attribute with warning
    W5302, producing a shader blob without an embedded root signature.
  • CreateRootSignature(0, bytes) then fails with 0x80004005
    (E_FAIL), so converter() returns None and Twin::copy skips
    conversion, leaving the depth texture clear.

What the fix does

  • In crates/victory-gpu/src/twin.rs, compile() (factored through
    compile_source(source: &str)) still tries
    device.CreateRootSignature(0, bytes) first, leaving the Microsoft
    d3dcompiler_47 path unchanged.
  • When CreateRootSignature(0, bytes) fails, it falls back to
    fallback_root_signature(device), which serializes the matching
    D3D12_ROOT_SIGNATURE_DESC (version 1.0, D3D12_ROOT_SIGNATURE_FLAG_NONE,
    D3D12_SHADER_VISIBILITY_ALL):
    • parameter 0: 8 × 32-bit root constants at b0, space 0
      (SetComputeRoot32BitConstants(0, 8, ...)),
    • parameter 1: root UAV at u0, space 0
      (SetComputeRootUnorderedAccessView(1, ...)),
      via D3D12SerializeRootSignature, creates the ID3D12RootSignature,
      and logs once at debug level (converter() is OnceLock-cached).
  • If building the converter still fails, the existing tracing::warn!
    message in converter() is unchanged.
  • Adds unit test
    twin::tests::converter_falls_back_when_shader_blob_has_no_root_signature,
    which strips [RootSignature(RS)] from SOURCE, compiles it through
    compile_source, and dispatches the fallback converter in both
    directions (16-bit 0x1234 → 24-bit 0x123412, and 24-bit
    0x800000 → 16-bit 32768).

Tests

  • twin::tests::converter_falls_back_when_shader_blob_has_no_root_signature (new). It compiles SOURCE with [RootSignature(RS)] stripped, which gives the same blob Wine's compiler produces after W5302. On that blob, CreateRootSignature fails, so the fallback builds the signature, the pipeline is created, and the GPU converts all 16 texels both ways: 16-bit 0x1234 becomes 24-bit 0x123412, and 24-bit 0x800000 becomes 16-bit 32768.
    • It passes under Wine + vkd3d-proton 3.1 and on windows-latest.
  • draw::tests::a_depth_texture_written_through_unordered_views_reads_as_depth passes as before with Microsoft's compiler (native d3dcompiler_47 under Wine + vkd3d-proton, and windows-latest).
  • On GitHub's windows-latest with the upstream CI's commands, victory-gpu has 79 passed, 0 failed, both tests included: https://github.com/BastienRodz/VIctory/actions/runs/45513753703
    • The run is red only on victory-shader's gathers_at_a_level_match_the_hardware and permutes_read_the_lane_named_and_zero_from_lanes_left_out. They fail the same way on main 70564ae (software adapter on the runner), and #1752 fixes them.
  • Clippy -D warnings passes with and without --all-features, and so does cargo xtask policy.

Not reproduced exactly: this host's Wine 10.0 has an older vkd3d-shader than #1860's Wine 11.22. It rejects SOURCE even earlier (E5005: Method 'Load' is not defined on type 'RWByteAddressBuffer'), so the issue's exact path (compile succeeds, signature dropped) could only be reproduced by stripping the attribute, as above. A run on Wine 11.22 + RADV, as in the report, would confirm it end to end.

Not tested: an AMD or NVIDIA Windows driver. The Microsoft compiler path is unchanged there.

Fixes #1860.

No game data used. AI-assisted: implemented with Gemini 4 Neon, reviewed and verified with Claude Code.

🤖 Generated with Claude Code

**@⁠BastienRodz** on GitHub · 2026-11-24 23:56 UTC · [original](https://github.com/Marvisak/VIctory/pull/1872) `BastienRodz:gpu/twin-converter-root-signature` → `main` · +170 −3 · 1 files · 2 commits · closed without merging ## What's wrong In #1860, 16-bit depth written through unordered access views never reaches the host 24-bit depth texture under Wine's builtin `d3dcompiler_47`: - `crates/victory-gpu/src/twin.rs` compiles the compute converter (`SOURCE`, `cs_5_1`, with `#define RS "RootConstants(num32BitConstants=8, b0), UAV(u0)"` and `[RootSignature(RS)]`) and then calls `device.CreateRootSignature(0, bytes)` on the shader blob itself. - Wine's builtin `d3dcompiler_47` (vkd3d-shader, as measured in #1860 on Wine 11.22) ignores the `[RootSignature]` attribute with warning `W5302`, producing a shader blob without an embedded root signature. - `CreateRootSignature(0, bytes)` then fails with `0x80004005` (`E_FAIL`), so `converter()` returns `None` and `Twin::copy` skips conversion, leaving the depth texture clear. ## What the fix does - In `crates/victory-gpu/src/twin.rs`, `compile()` (factored through `compile_source(source: &str)`) still tries `device.CreateRootSignature(0, bytes)` first, leaving the Microsoft `d3dcompiler_47` path unchanged. - When `CreateRootSignature(0, bytes)` fails, it falls back to `fallback_root_signature(device)`, which serializes the matching `D3D12_ROOT_SIGNATURE_DESC` (version 1.0, `D3D12_ROOT_SIGNATURE_FLAG_NONE`, `D3D12_SHADER_VISIBILITY_ALL`): - parameter 0: 8 × 32-bit root constants at `b0`, space 0 (`SetComputeRoot32BitConstants(0, 8, ...)`), - parameter 1: root UAV at `u0`, space 0 (`SetComputeRootUnorderedAccessView(1, ...)`), via `D3D12SerializeRootSignature`, creates the `ID3D12RootSignature`, and logs once at `debug` level (`converter()` is `OnceLock`-cached). - If building the converter still fails, the existing `tracing::warn!` message in `converter()` is unchanged. - Adds unit test `twin::tests::converter_falls_back_when_shader_blob_has_no_root_signature`, which strips `[RootSignature(RS)]` from `SOURCE`, compiles it through `compile_source`, and dispatches the fallback converter in both directions (16-bit `0x1234` → 24-bit `0x123412`, and 24-bit `0x800000` → 16-bit `32768`). ## Tests - **`twin::tests::converter_falls_back_when_shader_blob_has_no_root_signature`** (new). It compiles `SOURCE` with `[RootSignature(RS)]` stripped, which gives the same blob Wine's compiler produces after `W5302`. On that blob, `CreateRootSignature` fails, so the fallback builds the signature, the pipeline is created, and the GPU converts all 16 texels both ways: 16-bit `0x1234` becomes 24-bit `0x123412`, and 24-bit `0x800000` becomes 16-bit `32768`. - It passes under Wine + vkd3d-proton 3.1 and on `windows-latest`. - **`draw::tests::a_depth_texture_written_through_unordered_views_reads_as_depth`** passes as before with Microsoft's compiler (native `d3dcompiler_47` under Wine + vkd3d-proton, and `windows-latest`). - **On GitHub's `windows-latest`** with the upstream CI's commands, `victory-gpu` has 79 passed, 0 failed, both tests included: https://github.com/BastienRodz/VIctory/actions/runs/45513753703 - The run is red only on `victory-shader`'s `gathers_at_a_level_match_the_hardware` and `permutes_read_the_lane_named_and_zero_from_lanes_left_out`. They fail the same way on `main` `70564ae` (software adapter on the runner), and #1752 fixes them. - Clippy `-D warnings` passes with and without `--all-features`, and so does `cargo xtask policy`. **Not reproduced exactly:** this host's Wine 10.0 has an older vkd3d-shader than #1860's Wine 11.22. It rejects `SOURCE` even earlier (`E5005: Method 'Load' is not defined on type 'RWByteAddressBuffer'`), so the issue's exact path (compile succeeds, signature dropped) could only be reproduced by stripping the attribute, as above. A run on Wine 11.22 + RADV, as in the report, would confirm it end to end. Not tested: an AMD or NVIDIA Windows driver. The Microsoft compiler path is unchanged there. Fixes #1860. No game data used. AI-assisted: implemented with Gemini 4 Neon, reviewed and verified with Claude Code. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
`crates/victory-gpu/src/twin.rs` compiles the 16-bit depth twin
converter (`cs_5_1`) with `[RootSignature(RS)]` and then calls
`device.CreateRootSignature(0, bytes)` on the shader blob itself.
Wine's builtin `d3dcompiler_47` (vkd3d-shader, Wine 11.22 in #1860)
ignores `[RootSignature]` with warning W5302, so `CreateRootSignature`
fails with `0x80004005`, `converter()` returns `None`, and 16-bit
depth writes through unordered views never reach the depth texture.

Try `device.CreateRootSignature(0, bytes)` first so Microsoft's
`d3dcompiler_47` path is unchanged. On failure, serialize the same
v1.0 `D3D12_ROOT_SIGNATURE_DESC` (param 0: 8 32-bit constants at b0,
space 0; param 1: root UAV at u0, space 0; visibility ALL, no flags)
with `D3D12SerializeRootSignature`, create the root signature from
that blob, and log once at debug level. Also add a unit test that
strips `[RootSignature(RS)]` from `SOURCE` and verifies the fallback
converter converts 16-bit depth to 24-bit and back on the GPU.

Under Wine 10.0 + vkd3d-proton 3.1:
- `a_depth_texture_written_through_unordered_views_reads_as_depth`
  passes with native `d3dcompiler_47=n` before and after; with builtin
  `d3dcompiler_47=b` it panics in test helper `draw::tests::compile_cs`
  (`draw.rs:1872`, `0x80004005`) before reaching `twin.rs`, and Wine
  10.0's older vkd3d-shader rejects `RWByteAddressBuffer::Load`
  (`E5005`) during `D3DCompile`.
- `converter_falls_back_when_shader_blob_has_no_root_signature`
  exercises the exact Wine 11.22 no-root-signature blob path and passes
  under vkd3d-proton 3.1 + `d3dcompiler_47=n`, converting `0x1234` to
  `0x123412` and `0x800000` to `32768`.

Fixes #1860.

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

@⁠CaravelaLabs on GitHub · 2026-11-25 00:08 UTC · original

@⁠BastienRodz thanks for taking this. Ran 654301a here: Wine 11.22, vkd3d-proton 3.1, Radeon 8060S (RADV GFX1151, Mesa 25.2.8). The device was reached. Not native Windows. No title run.

With Microsoft's d3dcompiler_47, both tests pass, including your new one (16-bit 0x1234 to 24-bit and back). The signature built beside the shader does convert on this GPU when the shader itself compiles. A blob that already has a signature still takes the old path.

With Wine's own compiler, neither test gets there.

a_depth_texture_written_through_unordered_views_reads_as_depth still stops in the test's own setup: CreateRootSignature returns 0x80004005 at draw.rs:1872, before the converter. Same as on main. It cannot show the fallback.

converter_falls_back_when_shader_blob_has_no_root_signature fails in compile_source. D3DCompile of the converter source returns 0x80004005: E5005: Method 'Load' is not defined on type 'RWByteAddressBuffer' (buf.Load). Same text with [RootSignature] left in and with it stripped, so the fallback is not reached. Same error you saw on Wine 10. Wine 11.22's builtin compiler does not get past it either.

I had said on #1860 that this compiler only drops the attribute (W5302). That warning was from a shorter shader that only carried the attribute, not from this source. I've corrected that note. Sorry for the bad lead.

AI-assisted; tests run on this machine.

**@⁠CaravelaLabs** on GitHub · 2026-11-25 00:08 UTC · [original](https://github.com/Marvisak/VIctory/pull/1872#issuecomment-7148194402) @⁠BastienRodz thanks for taking this. Ran `654301a` here: Wine 11.22, vkd3d-proton 3.1, Radeon 8060S (RADV GFX1151, Mesa 25.2.8). The device was reached. Not native Windows. No title run. With Microsoft's `d3dcompiler_47`, both tests pass, including your new one (16-bit `0x1234` to 24-bit and back). The signature built beside the shader does convert on this GPU when the shader itself compiles. A blob that already has a signature still takes the old path. With Wine's own compiler, neither test gets there. `a_depth_texture_written_through_unordered_views_reads_as_depth` still stops in the test's own setup: `CreateRootSignature` returns `0x80004005` at `draw.rs:1872`, before the converter. Same as on main. It cannot show the fallback. `converter_falls_back_when_shader_blob_has_no_root_signature` fails in `compile_source`. `D3DCompile` of the converter source returns `0x80004005`: `E5005: Method 'Load' is not defined on type 'RWByteAddressBuffer'` (`buf.Load`). Same text with `[RootSignature]` left in and with it stripped, so the fallback is not reached. Same error you saw on Wine 10. Wine 11.22's builtin compiler does not get past it either. I had said on #1860 that this compiler only drops the attribute (`W5302`). That warning was from a shorter shader that only carried the attribute, not from this source. I've corrected that note. Sorry for the bad lead. AI-assisted; tests run on this machine.
Author
Owner

@⁠BastienRodz on GitHub · 2026-11-25 00:09 UTC · original

@⁠CaravelaLabs Thanks, that's the decisive run: the fallback is needed but not enough, because vkd3d-shader stops at RWByteAddressBuffer.Load first. Next commit: the converter reads and writes through a RWStructuredBuffer<uint> indexed by dword, which vkd3d-shader accepts, with the same results and the fallback kept. This host's Wine compiler fails the same way, so I can check the whole Wine path here (compile, attribute dropped, fallback, conversion) before pushing.

**@⁠BastienRodz** on GitHub · 2026-11-25 00:09 UTC · [original](https://github.com/Marvisak/VIctory/pull/1872#issuecomment-7148215081) @⁠CaravelaLabs Thanks, that's the decisive run: the fallback is needed but not enough, because vkd3d-shader stops at `RWByteAddressBuffer.Load` first. Next commit: the converter reads and writes through a `RWStructuredBuffer<uint>` indexed by dword, which vkd3d-shader accepts, with the same results and the fallback kept. This host's Wine compiler fails the same way, so I can check the whole Wine path here (compile, attribute dropped, fallback, conversion) before pushing.
Author
Owner

@⁠BastienRodz on GitHub · 2026-11-25 00:28 UTC · original

Moving this to draft: on its own it doesn't fix #1860 for Wine users. Here is what I found with Wine's builtin d3dcompiler_47 (vkd3d-shader; Wine 10 here, and @⁠CaravelaLabs saw the same on 11.22):

  • On RWByteAddressBuffer, every read is rejected with E5005 ... is not defined: Load, InterlockedOr, InterlockedAdd and InterlockedCompareExchange all fail.
  • RWStructuredBuffer<uint> reads compile, but stores fail with E5017: Structured buffers store is not implemented.
  • A separate ByteAddressBuffer SRV for the reads compiles, but one buffer can't be SRV and UAV in the same dispatch. vkd3d-proton also refuses the PSO (dxil-spirv: Failed to remap SRV).
  • A typed RWBuffer<uint> through a descriptor table does work end to end under the builtin compiler: the attribute is dropped (W5302), the fallback signature is used, and all 16 texels convert both ways. It needs Twin::copy to set its own descriptor heap, though, and then State::prepare_for/State::bind have to transition targets and make tables before binding the title's heaps (bde1967 on my fork, draw.rs +40/-45). That is a lot of churn in the draw path for this.

So the root-signature fallback here is needed but not sufficient. There seem to be two real options: that heap rework, or building the converter with the shader crate's own DXIL writer so no run-time HLSL compiler is involved (Exorion1er did that for the rectangle expander in #346). I'll leave it in draft until it's clear which one the maintainer prefers.

**@⁠BastienRodz** on GitHub · 2026-11-25 00:28 UTC · [original](https://github.com/Marvisak/VIctory/pull/1872#issuecomment-7148547699) Moving this to draft: on its own it doesn't fix #1860 for Wine users. Here is what I found with Wine's builtin `d3dcompiler_47` (vkd3d-shader; Wine 10 here, and @⁠CaravelaLabs saw the same on 11.22): - On `RWByteAddressBuffer`, every read is rejected with `E5005 ... is not defined`: `Load`, `InterlockedOr`, `InterlockedAdd` and `InterlockedCompareExchange` all fail. - `RWStructuredBuffer<uint>` reads compile, but stores fail with `E5017: Structured buffers store is not implemented`. - A separate `ByteAddressBuffer` SRV for the reads compiles, but one buffer can't be SRV and UAV in the same dispatch. vkd3d-proton also refuses the PSO (`dxil-spirv: Failed to remap SRV`). - A typed `RWBuffer<uint>` through a descriptor table does work end to end under the builtin compiler: the attribute is dropped (`W5302`), the fallback signature is used, and all 16 texels convert both ways. It needs `Twin::copy` to set its own descriptor heap, though, and then `State::prepare_for`/`State::bind` have to transition targets and make tables before binding the title's heaps (`bde1967` on my fork, `draw.rs` +40/-45). That is a lot of churn in the draw path for this. So the root-signature fallback here is needed but not sufficient. There seem to be two real options: that heap rework, or building the converter with the shader crate's own DXIL writer so no run-time HLSL compiler is involved (Exorion1er did that for the rectangle expander in #346). I'll leave it in draft until it's clear which one the maintainer prefers.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 17:17 UTC · original

Automated triage for the maintainers.

Needs rebase. This branch conflicts with main in crates/victory-gpu/src/twin.rs. It will be reviewed once it is rebased and marked ready.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 17:17 UTC · [original](https://github.com/Marvisak/VIctory/pull/1872#issuecomment-7169285016) <!-- victory-triage v1 head=654301a843f1ff909b394e934dfa77ad237ffe5e verdict=needs-rebase at=2026-11-25T17:17:20Z --> Automated triage for the maintainers. **Needs rebase.** This branch conflicts with `main` in `crates/victory-gpu/src/twin.rs`. It will be reviewed once it is rebased and marked ready. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠arogan178 on GitHub · 2026-11-25 23:58 UTC · original

Note

🤖 Claude Opus 5.5 responding on behalf of @⁠arogan178

On Proton-CachyOS 11.0 (RX 9070 XT, RADV), this PR's fallback isn't reached. Wine's built-in compiler fails on the shader's buf.Load (E_FAIL) before any root signature is involved. converter_falls_back_when_shader_blob_has_no_root_signature fails there with fallback converter: ... 0x80004005.

#2919 adds the other half: structured buffers indexed in words, plus a root signature that is always built in code. It also carries your round-trip test, which passes there with Wine's compiler. You're credited as co-author.

**@⁠arogan178** on GitHub · 2026-11-25 23:58 UTC · [original](https://github.com/Marvisak/VIctory/pull/1872#issuecomment-7178261155) > [!NOTE] > 🤖 **Claude Opus 5.5 responding on behalf of @⁠arogan178** On Proton-CachyOS 11.0 (RX 9070 XT, RADV), this PR's fallback isn't reached. Wine's built-in compiler fails on the shader's `buf.Load` (`E_FAIL`) before any root signature is involved. `converter_falls_back_when_shader_blob_has_no_root_signature` fails there with `fallback converter: ... 0x80004005`. #2919 adds the other half: structured buffers indexed in words, plus a root signature that is always built in code. It also carries your round-trip test, which passes there with Wine's compiler. You're credited as co-author.
Author
Owner

@⁠BastienRodz on GitHub · 2026-11-26 00:00 UTC · original

Closing in favour of #2919, which does both halves under Wine: the structured buffer the built-in compiler accepts, plus the root signature built in code. It carries this PR's round-trip test, adapted. That is what this draft was missing: the root signature alone never helped, because Wine's compiler fails on buf.Load first.

Thanks @⁠arogan178 for taking it the rest of the way and for the co-author credit.

**@⁠BastienRodz** on GitHub · 2026-11-26 00:00 UTC · [original](https://github.com/Marvisak/VIctory/pull/1872#issuecomment-7178288580) Closing in favour of #2919, which does both halves under Wine: the structured buffer the built-in compiler accepts, plus the root signature built in code. It carries this PR's round-trip test, adapted. That is what this draft was missing: the root signature alone never helped, because Wine's compiler fails on `buf.Load` first. Thanks @⁠arogan178 for taking it the rest of the way and for the co-author credit.

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!1872
No description provided.