Skip to content

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

Closed
BastienRodz wants to merge 2 commits into
Marvisak:mainfrom
BastienRodz:gpu/twin-converter-root-signature
Closed

BastienRodz wants to merge 2 commits into
Marvisak:mainfrom
BastienRodz:gpu/twin-converter-root-signature

Conversation

@BastienRodz

Copy link
Copy Markdown
Contributor

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 Wine: 16-bit depth written through unordered views stays clear, because the converter shader does not compile #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
  • 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

@CaravelaLabs

Copy link
Copy Markdown
Contributor

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

@BastienRodz

Copy link
Copy Markdown
Contributor Author

@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
BastienRodz marked this pull request as draft November 25, 2026 00:28
@BastienRodz

Copy link
Copy Markdown
Contributor Author

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.

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff.

Depth twin converter builds its root signature when needed: lazy root-signature creation — avoids building unused ones.

mercuryVM added a commit to mercuryVM/VIctory that referenced this pull request Nov 25, 2026
…ds its root signature when the compiler drops it (Wine)

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

@mercuryVM mercuryVM left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested 654301a on Windows 11, RTX 5070, MSVC:

  • cargo test -p victory-gpu passes on the head, apart from the 2 tests that also fail on main on this host.
  • Merged into our fork: workspace tests and clippy (both configs) clean.
  • I didn't run it under Wine.

The fallback is right. It is the same root signature the HLSL declares (RootConstants(num32BitConstants=8, b0), UAV(u0)), version 1.0, used only when CreateRootSignature refuses the blob. That is the case when vkd3d-shader drops the embedded RTS0. On native Windows the blob's own signature is still used, as here.

AI-assisted (Claude Code).

Copy link
Copy Markdown
Owner

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

…mpiler drops it (Wine)

`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 Marvisak#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 Marvisak#1860.

Co-Authored-By: Gemini 4 Neon <noreply@google.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@BastienRodz
BastienRodz force-pushed the gpu/twin-converter-root-signature branch from 654301a to 84f428c Compare November 25, 2026 17:22
…verter writes since 98c654b

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

Copy link
Copy Markdown

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.

@BastienRodz

Copy link
Copy Markdown
Contributor Author

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.

desplmfao added a commit to desplmfao/VIctory that referenced this pull request Nov 26, 2026
…ture when the compiler drops it)

twin.rs tests: main's prelude-state test and Marvisak#1872's fallback test both
kept. Main's converter now writes 32-bit float depth (0x37800080 scale),
not 24-bit, so Marvisak#1872's test expects that: 0x1234 as main's float, and
float 0.5 back to 32768. It passes with Microsoft's d3dcompiler_47; with
Wine's builtin compiler main's new converter source fails D3DCompile
(E_FAIL) before the fallback is reached.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
desplmfao added a commit to desplmfao/VIctory that referenced this pull request Nov 26, 2026
The previous renderer (old upstream base 940d32f) is the first parent and
is also kept as the branch renderer-2026-11-25-oldbase; the second parent
is the rebuild: fork main (upstream main 63bcca4 + our pull requests) with
the renderer stack merged on it: Marvisak#439 (on main: update/439-main's
resolution), Marvisak#2309, Marvisak#2167, Marvisak#2118, Marvisak#2311, Marvisak#1722, Marvisak#1751, Marvisak#688, Marvisak#1872, Marvisak#2292,
Marvisak#2310, Marvisak#2112 (opt-in), Marvisak#2230 (latch on by default), Marvisak#2389, Marvisak#2088 (small
windows opt-in), Marvisak#2099's new head, and tonight's Marvisak#491 journal fixes.
Merged upstream since: Marvisak#2143, Marvisak#2162, Marvisak#158, Marvisak#1906, Marvisak#1152; superseded by
main: Marvisak#1769, Marvisak#1763, Marvisak#2366.

The picture on this base still shows the overlay that plain upstream main
shows too; that is being looked into.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
github-actions Bot pushed a commit to KevinPratap/VIctory that referenced this pull request Nov 26, 2026
16-bit depth written through unordered views reaches the host's depth
texture through a compute converter compiled at run time. Wine's and
Proton's built-in d3dcompiler_47 refuse it (no methods on byte address
buffers) and ignore its RootSignature attribute, so the converter is
never made and that depth stays clear (Marvisak#1860).

The buffer becomes a structured buffer of uint indexed in words (every
offset and pitch is a placed footprint's, a multiple of 4), and the
root signature is serialized beside the shader. A test runs the
conversion both ways, after Marvisak#1872's.

Co-authored-by: BastienRdz <58186763+BastienRodz@users.noreply.github.com>
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.

Wine: 16-bit depth written through unordered views stays clear, because the converter shader does not compile

6 participants