Skip to content

GPU: shaders of our own that Wine's compiler builds too - #2969

Open
neonbyte1 wants to merge 1 commit into
Marvisak:mainfrom
neonbyte1:pr/wine-compile
Open

neonbyte1 wants to merge 1 commit into
Marvisak:mainfrom
neonbyte1:pr/wine-compile

Conversation

@neonbyte1

@neonbyte1 neonbyte1 commented Nov 26, 2026 •

Copy link
Copy Markdown

Under Wine, D3DCompile is Wine's d3dcompiler_47 (vkd3d-shader's HLSL). It has no methods on writable byte address buffers (E5005: Method 'Load' is not defined on type 'RWByteAddressBuffer'), and it ignores [RootSignature], so the blob carries no root signature to create. Every shader VIctory compiles at run time failed there:

  • the indirect-argument clamp: no argument clamp: indirect execution dropped, after which every indirect draw and dispatch is dropped as not bounded;
  • the depth twin's 16-bit conversion: no depth conversion;
  • the tests' own shaders.

On Linux this alone keeps the world from drawing. In a run on main with the NVIDIA fixes below, indirect drops summed to about 5,000 a frame, including the mesh dispatches that carry the world's geometry.

What changes

  • A new module, compute, compiles a shader and builds its root signature in Rust from the parameters the host binds.
  • The clamp keeps main's design: one group, tiles of 64, groupshared costs charged in order, the list's budget, the rest of each record copied. The title's records are now a StructuredBuffer<uint> (t0), and the clamped records and the budget are RWStructuredBuffer<uint> (u0, u1), indexed in words. bound() already refuses addresses and strides that aren't multiples of 4. The root signature is b0 (4 constants), SRV t0, UAV u1, UAV u0, in the order bound() binds them.
  • The depth conversion indexes its scratch buffer in words, with b0 (8 constants) and UAV u0.
  • The tests' shaders drop their [RootSignature] attributes the same way. The marked-write test ORs its page bit through a RWStructuredBuffer<uint>.
  • A new test checks every word the clamp writes for draws, indexed draws, dispatches, mesh dispatches, records past the budget and the budget spent.

The approach is @Mumogg's from #1279 (structured buffers indexed in words, the root signature built beside the shader). #1279 no longer applies to main's rewritten clamp, so this ports it and extends it to the depth conversion. #2093 takes the other route, compiling these shaders on Windows at build time. Either fixes the run-time failure; this one needs no change to the build.

Tested on an RTX 5090 (driver 620.73.04), Linux, Wine 11.22, vkd3d-proton 3.1-83 (GE-Proton11-14), with cargo xtask wine-test (#1218):

Not tested on Windows. Microsoft's compiler accepts the same HLSL, but I haven't run it.

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

Under Wine, D3DCompile is Wine's d3dcompiler_47 (vkd3d-shader HLSL): it
has no methods on writable byte address buffers (E5005 'Load' is not
defined on RWByteAddressBuffer) and ignores a [RootSignature] attribute,
so the code holds no root signature to make. Every run-time shader of
ours failed there: the argument clamp ("no argument clamp: indirect
execution dropped", every indirect draw and dispatch then dropped as
not bounded), the depth twin's 16-bit conversion ("no depth
conversion"), and the tests' own shaders.

A new module, compute, compiles a shader and serializes its root
signature in Rust from the parameters the host binds. The clamp keeps
main's design (one group, tiles of 64, groupshared costs charged in
order, the list's budget, the record's rest copied) with the title's
records a StructuredBuffer<uint> (t0) and the clamped records and the
budget RWStructuredBuffer<uint> (u0, u1), indexed in words: bound()
already refuses addresses and strides not multiples of 4. Its root
signature is b0 (4 constants), SRV t0, UAV u1, UAV u0, as bound()
binds them. The depth conversion indexes its scratch buffer in words
(footprint offsets and pitches are multiples of 4) with b0 (8
constants) and UAV u0. Test shaders lose their RootSignature
attributes the same way.

A new test checks every word the clamp writes for draws, indexed
draws, dispatches, mesh dispatches, records past the budget and the
budget spent.

The approach is Mumogg's (Marvisak#1279: structured buffers indexed in words,
the root signature serialized beside the shader), ported to main's
rewritten clamp and extended to the depth conversion.

The tests that bound their own root signatures:
The marked-UAV, placed-view and depth-twin rebind tests compile their
shaders with a [RootSignature] attribute Wine's compiler ignores, and
the marked write ORs its page bit through a byte address buffer method
it lacks. Their root signatures are made with crate::compute from what
the tests bind, and the bitmap is a RWStructuredBuffer<uint> indexed in
words.

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

Reviewed and verified against main (63bcca43) on Windows 11 (RTX 5090 + WARP, VICTORY_D3D12_DEBUG=1) — clean refactor and ready to merge:

  • crates/victory-gpu/src/compute.rs cleanly replaces inline [RootSignature] annotations across all 8 call sites with explicit D3D12SerializeRootSignature 1.0 builders matching the previous register spaces and slot ordering 1-for-1, and converting writable RWByteAddressBuffer usages (indirect.rs, twin.rs, draw.rs, pipeline/library.rs) to StructuredBuffer<uint> / RWStructuredBuffer<uint> preserves 4-byte alignment and atomic bit indexing.
  • Native Windows FXC compilation and D3D12 Debug Layer run with zero warnings on both hardware and WARP.

Local verification:

  • victory-gpu (compute::, draw::tests::, bindless::, indirect::, twin::, host::tests::, pipeline:: with VICTORY_D3D12_DEBUG=1): 81/81 passed on both RTX 5090 and WARP (excluding pre-existing NVIDIA 1M view-heap baseline test)
  • cargo clippy --locked -p victory-gpu --tests -- -D warnings: 0 warnings
  • cargo xtask policy: 192 files ok

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

LGTM — verified the port preserves semantics on Windows while staying inside Wine's compiler subset.

What I checked:

  • compute.rs: root parameters built in Rust and serialized via D3D12SerializeRootSignature — this removes the RootSignature attribute dependency entirely (Wine's d3dcompiler ignores it, so the blob carried no signature to create). Error blobs are still logged on failure.
  • indirect.rs: byte→word conversions are consistent throughout (Load(at+4)→args[at+1], Store3(at+8)→dest[at+2..at+4] conditional on kind==1 as before); the draw copy-out writes words +2/+3 unconditionally and +4 only for indexed draws, matching Store2/Store3 exactly. The (stride/4) indexing is safe because bound() refuses non-4-multiple addresses and strides. Root params preserve the RS order: b0, t0, u1 (budget), u0 (dest). clamped_records_hold_every_word is a strong test — every output word asserted per kind, budget charged per the cost model, past-budget records run empty while keeping their non-count words.
  • twin.rs: (at16 + y·pitch16)/4 + id.x is exact because each thread owns a 2-pixel pair in one word; x*4 bytes = x words on the 32-bit side. Round-trip constants unchanged (0x37800080 / saturate*65535+0.5), so the tiled-lighting EQUAL-float behavior is preserved.
  • memory.rs test pipelines: table/root-view/constants params match the old RS strings register-for-register, including space=2 placements and unbounded ranges.

Note (non-blocking): several test-only shaders still use RWByteAddressBuffer.Store (e.g. dst in bindless/memory tests) — under Wine those tests would still not compile, which is presumably #2973's scope. Runtime paths are all Wine-safe now.

@steven-seagull27

Copy link
Copy Markdown

I exercised the format-118 depth/stencil conversion through the production Twin::copy path on Windows. The RTX 5080 and built-in WARP both returned exact results on 16080c4 and its parent 63bcca4. On each adapter and build, all 174,342 depth texels and 174,342 stencil bytes matched in each direction.

The fixture uses a 259×257 texture, three mips and two array slices. It covers all 65,536 D16 values, both pixels packed into a word, odd row widths, differing row pitches and an independent stencil pattern. It compares the intermediate D32 bit patterns against the material-depth formula, overwrites the twin, then checks the copy back to D16/S8. As a sensitivity check, deliberately reading the low 16 bits for both pixels failed at (1, 0) on both adapters with 0x00000000 instead of 0x3f1e379e.

The test-only commit 3708bd0 can be cherry-picked onto this branch. Run cargo test --locked -p victory-gpu --features diagnostics --lib depth_twin_preserves_every_u16 -- --nocapture. Set VICTORY_D3D12_WARP=1 for the software pass. The three twin tests, strict Clippy and asset policy passed here. This measures the Windows conversion path; the in-game Wine observation is the author's.

@postblink

Copy link
Copy Markdown

Tested on Linux with an NVIDIA card: it works there too.

Setup: CachyOS (Linux 7.3.6), RTX 5080 (driver 620.73.04), Ryzen 7 9800X3D. GE-Proton11-14's wine run directly, with vkd3d-proton master 71cae091 (dxil-spirv b540c8a) in the prefix and DXVK's dxgi. main 63bcca4 with #2723 and #189 on top, diag build, retail 1.0.2.1, Series X mode.

before (main + #2723) with #2969 (and #189)
no argument clamp: indirect execution dropped logged absent
indirect executions dropped, median per frame in the world about 4,770 about 730
draws reaching the host, median per frame about 800 about 4,000, up to 6,300
picture nearly black, scattered lights lit opening cutscene, then the first playable section (camera input works)

#189 removes refused wave64 pipelines and doesn't touch the clamp. The indirect numbers moved with the clamp alone: a run with my own port of #1279 instead of #2969, and no #189, already showed about 760 indirect drops and up to 8,600 draws per frame. The remaining indirect drops are not the clamp. Most are no dynamic slots for root views on NVIDIA's capped view heap (#747), which I'm comparing separately.

Before trying this PR I carried #1279 onto main myself as a check. Its indirect tests went from 0 of 6 to 6 of 6 under GE-Proton's Wine compiler on the RTX 5080. Yours takes the same approach and covers the depth twin too (I ran its in-game path above, not its tests), so I dropped mine.

AI-assisted (Claude), runs and numbers from my own hardware.

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Merge candidate. The PR moves VIctory's run-time compute shaders (the indirect-argument clamp in indirect.rs, the depth twin's 16-bit conversion in twin.rs, and the test shaders) off RWByteAddressBuffer methods and [RootSignature] attributes, which Wine's D3DCompile does not support, onto uint structured buffers indexed in words, with the root signatures built in Rust (new compute.rs). main already makes allowances for Wine (host.rs, pipeline/library.rs, xmem::on_wine), so this is in scope, and it needs no build change, unlike the build-time route in #2093. I checked the clamp's word arithmetic against the old byte offsets (records stride / 4 words apart; bound() already refuses unaligned addresses and strides), the root parameter order against what bound() and Twin::copy bind, and the twin's (at16 + y * pitch16) / 4 + id.x against the old x * 2 byte offset with even x. The new clamped_records_hold_every_word expectations work out by hand. A commenter reports bit-exact twin conversion on Windows (RTX 5080 and WARP) and another reports the in-game effect under Wine.

The author has not run it on Windows; a maintainer run of victory-gpu tests on a Windows GPU would close that gap.

CI: passing. Recommending a look, not approving.


Generated by Claude Code

@postblink

Copy link
Copy Markdown

Follow-up on my earlier comment, which said I hadn't run this PR's tests. I've now run them: the whole victory-gpu suite under Wine, on main 63bcca4 and on this head 16080c4. Same machine and prefix (RTX 5080, GE-Proton11-14's wine, vkd3d-proton master 71cae091), one top-level module per process.

main #2969
passed 184 206
failed 25 4

Not run: resource::tests::a_list_waiting_for_another_queues_write_reads_what_it_wrote, which hangs under Wine on both builds. Run all together, the suite also took the headless X server down after about two minutes, so I ran it one module at a time. This is still Wine, not Windows, so the Windows run the triage asks for is still open.

AI-assisted (Claude), runs and numbers from my own hardware.

@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):

  • cargo test -p victory-gpu indirect::tests -- --test-threads=1 (RTX 5090 & WARP): 7 passed, 0 failed on both.
  • cargo test -p victory-gpu twin::tests -- --test-threads=1: 2 passed, 0 failed.
  • cargo test -p victory-gpu present_compositor_builds_both_pipeline_states -- --test-threads=1: 1 passed, 0 failed.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 192 files ok.

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

@neonbyte1

Copy link
Copy Markdown
Author

@postblink Thanks for running the whole suite. I reproduced it on an RTX 5090 under GE-Proton11-14's Wine and vkd3d-proton, 3 runs per build, with a print at each place the library tests return early:

I'm leaving the test as it is, because it now catches a real problem. When there's no saved library yet, the host asks for an empty one the same way, and under Wine without #1722 it ends up with no pipeline library at all. Making the test skip there would hide that, and the fix belongs to #1722. I've added a sentence about it to the description.

In a full victory-gpu run (one module per process, the hanging resource test skipped), this is the only test that fails with this PR and not on main: 30 failures on main, 6 with this PR. It's also the only test whose skip at the compile step this PR turns into a real run; the other tests whose shaders fail to compile on main already failed rather than skipping.

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

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

7 participants