Skip to content

GPU: the depth converter Wine's compiler builds too - #2919

Open
arogan178 wants to merge 2 commits into
Marvisak:mainfrom
arogan178:wine-depth-twin
Open

arogan178 wants to merge 2 commits into
Marvisak:mainfrom
arogan178:wine-depth-twin

Conversation

@arogan178

@arogan178 arogan178 commented Nov 25, 2026 •

Copy link
Copy Markdown

Under Wine and Proton, 16-bit depth that the title writes through unordered views never reaches the host's depth texture (#1860). It is moved by a compute converter compiled at run time. Wine's built-in d3dcompiler_47 (vkd3d-shader) refuses it, because it has no Load/Store on byte address buffers, and it ignores the RootSignature attribute. The converter is never made.

#1872 serializes the root signature when the compiler drops it. That is half of it: with Proton-CachyOS 11.0's compiler the shader still fails on buf.Load, and #1872's own test fails there too. This PR does both halves, the way #2913 does for the indirect clamp:

  • The buffer becomes a structured buffer of uint, indexed in words. Every offset and pitch comes from a placed footprint: offsets are 512-byte aligned, row pitches 256.
  • The root signature is serialized beside the shader, in the order the caller sets it.

The odd-width test runs the converter both ways on a 3-wide surface, with a distinct value per texel and a sentinel in each row's padding. It is adapted from #1872's test.

This PR also includes #3064's exact UNORM16 midpoint rounding and its exhaustive GPU test, with the original commit author preserved. The combined shader omits [RootSignature(RS)] because the root signature is serialized in Rust. That avoids the undeclared RS error @neonbyte1 found when integrating the two PRs.

Fixes #1860. Supersedes #1872.

Proof

On the combined head, both converter tests passed on an RX 9070 XT (RADV) using Proton-CachyOS 11.0 and Wine's built-in d3dcompiler_47. The midpoint test found zero mismatches across 393,216 inputs. Strict victory-gpu Clippy passed with default and all features for x86_64-pc-windows-msvc.

The Wine compatibility change was also tested before integrating the rounding commit.

victory-gpu tests cross-built for x86_64-pc-windows-msvc, run under Proton-CachyOS 11.0 with vkd3d-proton 3.2.0 on an RX 9070 XT (RADV):

  • Wine's built-in compiler: the new test passes. With main's shader swapped back in, it fails because the converter is never built. With the odd-width tail guard removed, it fails on the padding sentinel.
  • Microsoft's d3dcompiler_47 10.0.26100: the new test passes. The whole suite has the same 3 failures as main. They are vkd3d-proton issues fixed by GPU: the host pipeline library works under Wine (null blob for an empty library) #1722 and GPU: castable formats the host has #2101.
  • Clippy: cargo clippy -p victory-gpu --all-targets --target x86_64-pc-windows-msvc -- -D warnings, with and without --all-features, is clean. CI runs the Windows tests.

Reviewed with sol-loop: 1 round with GPT-6.2 Sol. Sol verdict: approved (its one nit, a stronger test fixture, is in).

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>

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

Verified head 13f215d5 cleanly on origin/main (63bcca43) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + D3D12 WARP + VICTORY_D3D12_DEBUG=1).

Code & Equivalence Review

  • Replacing inline [RootSignature(RS)] and RWByteAddressBuffer with explicit D3D12SerializeRootSignature (D3D_ROOT_SIGNATURE_VERSION_1_0: b0 8 constants + u0 UAV table) and RWStructuredBuffer<uint> preserves exact word addressing because placed footprint offsets (at16/at32, 512 B aligned), pitches (256 B aligned), and 2-texel thread pairs (x * 2 = 4 B aligned) are all 4-byte aligned.
  • 16-bit depth (D16_UNORM <-> D32_FLOAT) round-trip encoding (0x37800080 and saturate * 65535.0 + 0.5, plus odd-width high-half zeroing) matches bit-for-bit, and D32/D24S8 continue taking the same == true copy path.

Local Verification (--features diagnostics, VICTORY_D3D12_DEBUG=1)

  • RTX 5090 & WARP: twin::tests + draw::tests 23/23 passed on both adapters (including new the_converter_turns_16_bit_depth_into_float_and_back), zero debug-layer errors.
  • cargo clippy --locked -p victory-gpu --tests -- -D warnings (default and --features diagnostics) & cargo xtask policy (191 files ok): clean.

Looks clean and ready to merge.

@Kajanos

Kajanos commented Nov 26, 2026

Copy link
Copy Markdown

Windows 11 / NVIDIA test run, head 13f215d5a4 merged onto main 63bcca43c6.

Setup: Windows 11 Home build 26300, RTX 5080, NVIDIA 621.40, rustc 1.98.1 MSVC, VS 2022 Build Tools, Windows SDK 10.0.26100 (dxil.dll from the SDK).

  • cargo test --locked -p victory-gpu: 232 passed, 0 failed, 1 ignored (main: 231). On Windows this uses the native d3dcompiler_47, so the Wine-compiler path this PR targets is not exercised here.

Not run: the retail title, clippy, and other crates.

AI-assisted (Claude Code)

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

Verified the same conversion as #2913 applied to the depth converter: byte offsets divided to word indices (/4, b+4 -> b+1), structured uint buffer via root descriptor, root signature built beside the shader. The saturate/round u16 path is untouched. LGTM.

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Merge candidate. The 16-bit depth converter in twin.rs now builds with Wine's compiler too: the buffer is a word-indexed RWStructuredBuffer<uint> and the root signature is serialized in code (root_signature). The parameter order (b0 constants at 0, root UAV at 1) matches the caller's SetComputeRoot32BitConstants(0, ...) / SetComputeRootUnorderedAccessView(1, ...), and every offset and pitch is a multiple of 4 so the division is exact. The test runs both directions on an odd width with padding sentinels against independently computed values. If merged, #1872 looks superseded.

CI: passing.


Generated by Claude Code

@Dukestar69 Dukestar69 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 locally merged onto origin/main (63bcca4) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP):

  • Diff review: Replacing RWByteAddressBuffer with RWStructuredBuffer<uint> (using 4-byte-aligned word indices) and serializing the root signature explicitly via D3D12SerializeRootSignature cleanly avoids Wine FXC limitations while preserving exact 16-bit depth conversion semantics.
  • cargo test -p victory-gpu twin::tests -- --test-threads=1 (RTX 5090 & WARP): 3 passed, 0 failed on both (including the_converter_turns_16_bit_depth_into_float_and_back).
  • cargo test -p victory-gpu a_depth_texture_written_through_unordered_views_reads_as_depth -- --test-threads=1 (RTX 5090 & WARP): 1 passed, 0 failed on both.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

ntgata1-dotcom added a commit to ntgata1-dotcom/VIctory-Linux that referenced this pull request Nov 26, 2026
…lds too

From Marvisak/VIctory#2919 (opened by arogan178; original commits and authors kept). Not yet merged upstream.

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 26, 2026
BastienRodz added a commit to BastienRodz/VIctory that referenced this pull request Nov 26, 2026
Both were HLSL compiled at first use with D3DCompile. Under Wine that is
vkd3d-shader's compiler, which refuses them (no methods on
RWByteAddressBuffer, [RootSignature] ignored), so indirect execution was
dropped and 16-bit depth written through unordered views never reached
the depth texture. The rewrites in Marvisak#2913, Marvisak#2919 and Marvisak#2969 still need a
Wine of 11.22 or later.

victory-shader now writes both programs itself with its DXIL builder
(emit::argument_clamp, emit::depth_conversion), the same algorithm and
clamps as the HLSL, and victory-gpu makes their root signatures in code
(own.rs). No shader compiler runs, whatever the Wine version.

Tests: every_word_of_each_kind checks each word the clamp writes for
every record kind; depth_converts_both_ways runs the conversion both ways
on a buffer, with no compiler for the test either; our_programs_validate
runs both through the DXIL validator where the SDK has one. Under Wine 10
and vkd3d-proton 3.1 the 7 indirect tests and the new depth test pass
(6 indirect tests failed before), and the two draw tests that read
converted depth pass with a native compiler for their own shaders.

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

Copy link
Copy Markdown

A merge note for @andrewpozdnakov7-jpg and @arogan178 (#2919): these two PRs conflict without git noticing. #2919 removes both #define RS and [RootSignature(RS)] from the depth converter, because Wine's compiler builds it and the code makes the root signature beside the shader. #3064 keeps the [RootSignature(RS)] line. When both are merged, the attribute stays with no define. Wine's D3DCompile (vkd3d-shader) then rejects the converter with E5005: Identifier "RS" is not declared, and no depth converter exists: the log says no depth conversion: 16-bit depth written through unordered views does not reach the depth texture. In game on my fork's integration (RTX 5090, Wine 11.22 + vkd3d-proton), character close-ups get soft, skin-coloured blocks over the hair and back, and the PR's own float_depth_rounds_at_each_u16_threshold fails with depth converter.

The fix is to drop the attribute in whichever PR lands second and keep #3064's u16() as is: neonbyte1@634bcce5 (adds a CPU test that the converter source compiles without it). With that on the same tree:

  • float_depth_rounds_at_each_u16_threshold passes under Wine/vkd3d-shader, with 0 of 393 216 values misrounded. The previous (x * 65535 + 0.5) rounding misrounds 32 768 of them, the first at 0x37000080 (expected 0, got 1). So GPU: round depth-twin UNORM16 copies at the exact midpoint #3064's rounding is worth having on this compiler too.
  • In game, the blocks are gone at frames 1700 and 2048.

One unrelated note: depth_typed_and_default_uavs_write_through_the_twin fails under Wine with 0x80004005 both with and without these changes.

AI-assisted (Claude); measured on my machine, no game data shared.

@andrewpozdnakov7-jpg

Copy link
Copy Markdown
Contributor

Thanks @neonbyte1 for the integration check and @arogan178 for carrying the midpoint change into da0eca1 with the Git author preserved.

I checked that exact #2919 head. The converter source has no inline root-signature attribute, and the host creates its signature separately. Two focused tests executed on Windows WARP with graphics debug requested. The depth-to-UNORM16 test matched all 393,216 values. The 3×4 round trip passed in both directions and preserved the row padding. I repeated both with WARP availability required to rule out a silent skip. Both GPU Clippy configurations, the asset policy, and Windows CI passed.

This is Windows coverage of your current combined head. The Wine and title results in this thread are from @neonbyte1. The next step is maintainer review of #2919, which now includes the exact-midpoint conversion from #3064.

AI-assisted with OpenAI Codex.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

8 participants