Skip to content

GPU: build the indirect-argument clamp with our own writer (no shader compiler at run time) - #190

Closed
LaunchDoesntCode wants to merge 1 commit into
Marvisak:mainfrom
LaunchDoesntCode:gpu/clamp-as-dxil
Closed

LaunchDoesntCode wants to merge 1 commit into
Marvisak:mainfrom
LaunchDoesntCode:gpu/clamp-as-dxil

Conversation

@LaunchDoesntCode

Copy link
Copy Markdown
Contributor

Closes #170. An alternative to #178, which fixes the same thing by falling back to DXC; the comparison is at the end.

What

Under Wine and Proton, indirect::clamp() fails and every indirect execution is dropped, because the clamp is HLSL compiled at run time by D3DCompile, and Wine's d3dcompiler_47 cannot compile it. As #170 records, rewriting the HLSL does not help: that compiler has no store to a raw or structured buffer and ignores the [RootSignature] attribute.

This emits the same shader as DXIL with the shader crate's own writer and makes its root signature from a description, so no shader compiler is involved on any host.

Changes

  • victory-shader/src/emit/clamp.rs (new): argument_clamp() returns the clamp as a DXIL container. Same behaviour as the HLSL it replaces: one thread per record; draws, dispatches and mesh dispatches clamped in place with the same bounds; the cost added to the list's budget atomically; a record past the budget emptied.
  • emit/shader.rs: the builder learns root UAVs (raw buffers) beside root CBVs and SRVs: root_uav_handle, their dx.resources records and their PSV0 bindings. Translated shaders do not use it, so their output is unchanged.
  • victory-gpu/src/indirect.rs: make() takes that DXIL and a root signature from pipeline::host::root_signature (now pub(crate)). D3DCompile and the Win32_Graphics_Direct3D_Fxc feature are gone.
  • emit/host.rs (test harness): Root::Uav, a root UAV whose contents come back after the dispatch, and root_signature_of, split out of root_signature_for.

Tested

Cross-built for x86_64-pc-windows-msvc on Linux Mint, Proton 10.0 (wine-10.0, vkd3d-proton), RTX 5090, driver 595.99.2, main at d2a4bae:

  • indirect::tests::argument_clamp_builds: fails on main, passes here.
  • Two new GPU tests in emit::clamp run the clamp and read the buffers back:
    • records_are_clamped_in_place: records of all four kinds against the bounds written out in Rust, the untouched fourth dword of each record, a record past the count left alone, and the budget's total.
    • records_past_the_budget_run_empty: a record that fits exactly, one that crosses the budget and one after it is spent, for draws and for a dispatch.
  • cargo test -p victory-shader: 70 passed, 1 failed (stub_pipeline_is_created, which fails the same way on main under Proton).
  • cargo test -p victory-gpu: 41 passed, 2 failed, both failing on main too (a_rejected_blob_gives_an_empty_library, and buffer_data_reaches_the_host_texture, which is Wine/vkd3d: deferred uploads are skipped because VirtualQuery() reports mapped memory as MEM_FREE #128).

Not tested: Windows, and the title

  • No run on Windows. The container goes through the same writer and hash as every translated shader, but dxil.dll validation of this particular module and a run on a Windows driver are unchecked. A Windows run of cargo test -p victory-shader clamp and -p victory-gpu argument_clamp would settle it.
  • Not run in the title. With VICTORY_INDIRECT=1 under Proton this should turn "indirect execution dropped" into executed draws; I have not captured that.

Against #178

#178 (DXC fallback) this
Size +63 −8 +559 −103, most of it the shader and its tests
Needs at run time dxcompiler.dll in the prefix when D3DCompile refuses nothing
Windows path unchanged changed: the same DXIL on every host
Evidence seen working in the title under Wine clamp results checked on the GPU; not seen in the title

They are not exclusive in spirit but they do touch the same function, so only one should land. #178 is the smaller change and is already seen working in the title; this one removes the dependency instead of adding a second compiler. Your call.

No game data used. AI-assisted (Claude Code).

🤖 Generated with Claude Code

The clamp was HLSL compiled at run time by the system's D3DCompile. Wine's
d3dcompiler_47 rejects it (no Load on RWByteAddressBuffer, no store to a
structured buffer, and the RootSignature attribute is ignored), so under
Wine and Proton clamp() failed and every indirect execution was dropped.

The same shader is now emitted as DXIL by the shader crate
(emit::clamp::argument_clamp) and its root signature is made from a
description, so no shader compiler is needed on any host. For that the
shader builder learns root UAVs (raw buffers), beside root CBVs and SRVs.

Two GPU tests run the clamp over records of each kind and compare with
the bounds written out in Rust, and check that records past the list's
budget run empty.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@raffclar

Copy link
Copy Markdown
Contributor

Reviewing

@raffclar

raffclar commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

This will conflict with #178 and #40 They're all touching indirect.rs and it's getting a little hectic. Worth noting for merge order

/// The clamp as a DXIL container. Its user data is four dwords: the kind
/// of record (0 and 1 draws, 2 dispatches, else mesh dispatches), the
/// records' stride in bytes, their count, and one unused.
pub fn argument_clamp() -> Vec<u8> {

@raffclar raffclar Nov 24, 2026 •

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.

The DirectX IL matches op for op with the old HLSL. Same limits, branches etc so it's fine

@SkippySteve

Copy link
Copy Markdown

Independent run of #190 under Proton on a second machine. Synthetic crate tests only; no game data and no title run.

Host: Arch Linux (kernel 7.2), RTX 2060 SUPER, NVIDIA 615.78.08. Runtime: UMU-Proton 11.0-2e (its files/bin/wine), a fresh dedicated prefix, WINEDLLOVERRIDES="d3d12=n;d3d12core=n;dxgi=n;d3d11=n" so the prefix's vkd3d-proton and DXVK DLLs are used. +loaddll shows native d3d12.dll/d3d12core.dll, and vkd3d-proton reports SM 6.8.

Build: cargo xwin test --target x86_64-pc-windows-msvc -p victory-shader -p victory-gpu --no-run at ffa1310, then the test exes run under wine. D3DCompile, Direct3D_Fxc and dxcompiler do not appear anywhere in the tree on this branch, so the clamp is built with no runtime shader compiler.

main @ d2a4bae #190 @ ffa1310
victory-gpu indirect::tests::argument_clamp_builds FAIL (clamp().is_some() at indirect.rs:215) pass
victory-shader emit::clamp::tests::records_are_clamped_in_place (not on main) pass
victory-shader emit::clamp::tests::records_past_the_budget_run_empty (not on main) pass
cargo test -p victory-shader, all tests 68 pass / 1 fail 70 pass / 1 fail
cargo test -p victory-gpu, all tests 40 pass / 3 fail / 1 ignored 41 pass / 2 fail / 1 ignored

The failures left on this branch are the same ones that fail on main here: stub_pipeline_is_created, a_rejected_blob_gives_an_empty_library and buffer_data_reaches_the_host_texture (#128). That is the same as your Proton 10 / RTX 5090 numbers, so the result holds on an older Turing card and a newer Proton.

Against #178: git merge-tree pr190 pr178 conflicts in crates/victory-gpu/Cargo.toml and crates/victory-gpu/src/indirect.rs, as you said. Both change make()/the Fxc feature, so only one of them can land as-is. I have not run this on Windows, so the open dxil.dll validation question from the PR body still stands.

@DaviTostes

Copy link
Copy Markdown

Tested ffa1310 under Wine 11.22 + vkd3d-proton 3.1 on Arch Linux x86_64 (AMD RX 9060 XT, RADV 26.3.1), Windows build, with Wine's builtin d3dcompiler_47 and no dxcompiler.dll: pass.

No game data used.

@raffclar

Copy link
Copy Markdown
Contributor

I think it's worth really thinking about whether to go down this route of adding DirectX's IL. It's more to maintain. This should be fixed upstream in Wine/Proton if possible

@raffclar

Copy link
Copy Markdown
Contributor

I'd refactor this into its own little garden so as Wine/Proton support increases, it can be pruned

@xstraok

xstraok commented Nov 24, 2026

Copy link
Copy Markdown

Tested on Linux under Proton, where the clamp is the only thing between the world and dropping every indirect execution.

Setup

  • 58fed37 (main) with this PR's ffa1310 merged on top, diag build (--profile diag --features diagnostics), cross-built for x86_64-pc-windows-gnu with Rust 1.92.0
  • Arch Linux, kernel 7.2.15, AMD RX 9060 XT (RDNA4), Mesa 26.2.6 RADV, Ryzen 5 7600, 32 GB
  • Proton Experimental (11.0-20261112), vkd3d-proton for D3D12

Without this PR (main 8d23f07, same setup): Wine's D3DCompile (vkd3d-shader) refuses the clamp:
argument clamp: clamp:19:27: E5005: Method 'Load' is not defined on type 'RWByteAddressBuffer'.
so every indirect execution is dropped. World: 93–1,279 draws/frame.

With this PR: no clamp warning; world 1,151–3,005 draws/frame (last 8 stats lines), 1.4–3.2 s/frame, no device removal, no amdgpu page fault in the kernel log. The picture is still mostly black (shaders that do not translate), with some geometry and the post-processing (blur, chromatic aberration) visible.

Not tested: Windows; NVIDIA; release build; cargo test under Wine.

Report written with Claude Code (Claude Opus 5.5) from runs on my machine.

@Exorion1er

Copy link
Copy Markdown
Contributor

Tested in the title on Linux: RX 9070 XT (RDNA4), Fedora 44, kernel 7.3.5, Mesa 26.2.7 RADV. GE-Proton11-12's Wine with Proton Experimental's vkd3d-proton 3.2.0 (d3d12,d3d12core,dxgi=n,b), no dxcompiler.dll anywhere. Diagnostics builds, Series X files, menus driven by VICTORY_KEYS, VICTORY_NO_WATCHDOG=1.

main f67c50c f67c50c + #190 #454 #493 #579 #89 6db02ea + #190 #454 #493 #579, VICTORY_SHADER_LOOP_LIMIT=32
clamp E5005: Method 'Load' is not defined on type 'RWByteAddressBuffer' → no argument clamp: indirect execution dropped no clamp warning no clamp warning
"not bounded (no clamp…)" drop lines 68 0 0
indirect drops per world frame, median (range) 3,988 (2,035–9,996), 15 frames 1,382 (495–2,438), 35 frames 959 (298–2,828), 70 frames

What's still dropped on the stacked builds is prepare failed (compute false, mesh false), not the clamp.

With the stack, the scene reaches the G-buffer. At frame 1600 of the third run, the 2560×1440 depth target is about 92% covered and the richest f28 target about 85%, with the buildings and street correctly placed. The lighting targets (f26) are empty and the presented frame is black, like the Windows reports on #71. One run per column, so treat the numbers loosely, but the clamp result was the same in all three.

So on RADV, #190 (at ffa1310) does in the title what DaviTostes's test showed, without needing DXC.

Counts only, no game data. AI-assisted (Claude Code).

@MichaelSmithAI

Copy link
Copy Markdown

For the open validator question: Microsoft’s Windows dxil.dll accepted the 3,012-byte production argument-clamp shader through VIctory’s IDxcValidator wrapper under Wine. Microsoft’s Linux dxv also accepted it. The shader emitted at ffa1310 and after merging it onto ffe310e was byte-identical, SHA-256 9aeebc09369dab28bafc2182724063778e241ee7f065a4262f2e42cba5aef67e.

This verifies the emitted container with the Microsoft validator. Native Windows pipeline creation remains a separate check.

@rouges78

rouges78 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Native Windows run on NVIDIA, as asked for in the PR body. Synthetic crate tests only: no game data, no title run.

Host: Windows 11 Pro (build 26300), RTX 4080, NVIDIA driver 621.14 (32.0.16.2114), D3D12Core.dll 10.0.26100.9818, Rust 1.98.1, native x86_64-pc-windows-msvc. The machine also has a Radeon iGPU, so I checked by adapter LUID that D3D12CreateDevice(None) is the 4080 and that the WARP runs are the Microsoft Basic Render Driver.

Tested: ffa1310 merged onto main @ ffe310e (clean merge), compared with ffe310e.

test WARP RTX 4080, 621.14
victory-shader emit::clamp::tests::records_are_clamped_in_place pass pass
victory-shader emit::clamp::tests::records_past_the_budget_run_empty pass pass
victory-gpu indirect::tests::argument_clamp_builds (--features diagnostics) pass pass

Run with --nocapture --test-threads=1; none took the "no SM 6.6 device; skipped" path. argument_clamp_builds returns silently without a host, so I also ran a local probe (not part of the PR) that fails instead: make() returned Ok on both adapters. So the NVIDIA driver takes the hand-written DXIL: the root signature and the compute pipeline are created, and the two readback tests get the expected buffers and budget.

Full suites, passed / failed / ignored:

main @ ffe310e #190 merged
cargo test -p victory-shader, WARP (VICTORY_WARP=1) 120 / 0 / 1 122 / 0 / 1
cargo test -p victory-shader, RTX 4080 120 / 0 / 1 122 / 0 / 1
cargo test -p victory-gpu --features diagnostics, WARP (VICTORY_D3D12_WARP=1) 53 / 0 / 1 53 / 0 / 1
cargo test -p victory-gpu, RTX 4080 50 / 0 / 1 50 / 0 / 1

Notes:

  • dxil.dll: the native validator from SDK 10.0.26100 (1.8.2502.11) accepts the module and leaves our digest unchanged. 3,012 bytes, SHA-256 9aeebc09369dab28bafc2182724063778e241ee7f065a4262f2e42cba5aef67e, the same hash MichaelSmithAI reported above.
  • Debug layer: not observed. Graphics Tools is not installed here (D3D12GetDebugInterface returns DXGI_ERROR_SDK_COMPONENT_MISSING), so no info-queue messages were captured.
  • On both trees, 4 of the passing shader tests are diff_tests that return early here ("no console compiler; skipped"). They are not the clamp tests.
  • One flake, not from this PR: frame::tests::waits_end_on_ticks_and_count_frames (frame.rs is identical in both trees) failed in some runs of both trees with skipped ticks, e.g. [4, 5, 7, 8] at frame.rs:221, and in 0 of 60 later runs per tree. That is the late wake-up GPU frame test: tolerate a late wake-up instead of requiring consecutive flips #985 already addresses. The victory-gpu rows above are the runs without it.
  • Not measured: timings and the budget wrap (the PR keeps main's plain atomic add). Not run in the title; I don't have it.

AI-assisted (Claude Code), from runs on my machine.

@hh-ze

hh-ze commented Nov 24, 2026

Copy link
Copy Markdown

Verified #190 on an RTX 5060 Ti with NVIDIA driver 595.99.02. All three targeted GPU tests passed, and a Story Mode run got past the Wine D3DCompile failure that previously prevented the indirect-argument clamp from running.

Setup

GPU verification

Test Result
victory-gpu · indirect::tests::argument_clamp_builds Pass
victory-shader · emit::clamp::tests::records_are_clamped_in_place Pass
victory-shader · emit::clamp::tests::records_past_the_budget_run_empty Pass

The first test created the clamp pipeline. The two readback tests dispatched the shader on the RTX 5060 Ti and checked the resulting argument records and budget handling.

Story Mode verification

I ran the local Series X 1.0.2.1 build. The baseline reproduced the failure from #170 when it reached world rendering:

argument clamp: clamp:19:27: E5005: Method 'Load' is not defined on type 'RWByteAddressBuffer'.
no argument clamp: indirect execution dropped ... (0x80004005)

With ffa1310 applied, the run passed that point with the clamp active. These are samples from the last world-rendering intervals before each run exited:

Build Draws/frame Indirect executions dropped/frame Last frame number logged
Base 234f049 369 5,826 1200+ (last logged 1299)
Base + ffa1310 1,413 2,077 1361

These were diagnostic runs with separate caches and different skip lists. The baseline skipped three confirmed crashing compute shaders. The patched run also skipped a3d1a26ad0c8c2cd, which reproduced the crash in a standalone pipeline-creation test. The numbers describe those runs and should be read as diagnostic samples.

The patched run still exited with vkCreateComputePipelines Exception 0xc0000005 in Unix call after reaching roughly 0.2–0.3 fps in the world. The GPU and desktop stayed responsive, and the kernel logged no NVIDIA Xid during the tests. The clamp fix worked on this setup. Playable world rendering remains blocked by the compute-pipeline crash and substantial remaining rendering drops.

AI-assisted testing and log analysis. Log excerpts and test results only.

@x3ero0

x3ero0 commented Nov 24, 2026

Copy link
Copy Markdown

One more NVIDIA data point, on a card not yet in this thread.

Setup: RTX 5080, driver 620.70, CachyOS (kernel 7.3.5), GE-Proton11-6's Wine with its bundled vkd3d-proton, ffa1310 cherry-picked onto main ffe310e (applies cleanly), cross-built with cargo xwin for x86_64-pc-windows-msvc.

Test ffe310e ffe310e + this PR
indirect::tests::argument_clamp_builds fails (E5005: Method 'Load' is not defined on type 'RWByteAddressBuffer') passes
emit::clamp::tests::records_are_clamped_in_place n/a passes
emit::clamp::tests::records_past_the_budget_run_empty n/a passes

Synthetic tests only; I did not run the title on this tree.

For what it is worth as a cross-check of the design: I had written the same thing independently before finding this PR (#1470, now closed as a duplicate). That version gave the same buffers as the HLSL clamp compiled by DXC on 5,461 random records, on a native Linux build of vkd3d-proton, and Microsoft's libdxil.so (DXC v1.9.2609) accepted its container.

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Needs rebase. This PR does not merge cleanly into current main (ac2525d). Conflicting files: crates/victory-shader/src/emit/host.rs, crates/victory-shader/src/emit/mod.rs, crates/victory-shader/src/emit/shader.rs.

The content has not been reviewed yet; it will be once the branch is rebased onto main.


Generated by Claude Code

@LaunchDoesntCode LaunchDoesntCode closed this by deleting the head repository Nov 25, 2026
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/vkd3d: indirect execution is dropped because the argument clamp cannot be compiled there; rewriting its HLSL does not help