Wine: clamps Wine's HLSL compiler builds, one back edge per loop header, a large stack for pipeline workers #245

Closed
github-bot wants to merge 4 commits from github-bot/gh-245 into rx9070xt AGit
Owner

@⁠simon0302010 on GitHub · 2026-11-26 10:54 UTC · original
wine-clamps-and-loop-latches → rx9070xt · +544 −83 · 9 files · 4 commits · closed without merging

Three fixes for running under Wine/Proton. Together they take the title from a freeze while loading to the world rendering on Linux.

1. Indirect clamps that Wine's HLSL compiler builds (#183)

Under Wine, D3DCompile is vkd3d-shader's compiler. It refuses both the argument clamp (indirect.rs) and the batched clamp (indirect/batch.rs):

argument clamp: clamp:91:10: E5005: Method 'InterlockedOr' is not defined on type 'RWByteAddressBuffer'.
no argument clamp: indirect execution dropped

So every indirect draw was dropped. This uses the rewrite described in #183 (from fxceless/victory-fork#1011), applied to both clamps:

  • the two buffers each shader writes are RWStructuredBuffer<uint> indexed in words, so the bytes written are the same; the budget's diagnostics stay at the old byte offsets 4/8/12/16 (words 1–4)
  • Interlocked* are called as functions on the word
  • [allow_uav_condition] is dropped
  • the root signatures are serialized in root_signature(), because Wine's compiler embeds none from [RootSignature]

Strides, argument offsets and the batch table's places are multiples of 4: D3D12 requires it, and Table::place checks it.

This complements #243 (DXC fallback). That PR changes the same function (make_from), so whichever is merged second needs a small rebase. With this one, D3DCompile succeeds under Wine, so the fallback wouldn't be reached for the clamps.

2. One back edge per loop header (port of Marvisak/VIctory#1885, d48ec767)

vkd3d-proton's DXIL conversion (dxil-spirv) keeps one back edge per loop header. With several, it recurses without end. Under Wine that stack overflow doesn't fail the pipeline, it hangs: here the overflowing thread was holding the process heap lock, so the whole process froze:

err:virtual:virtual_setup_exception stack overflow 3456 bytes addr ... stack 0x6cc30280 (0x6cc30000-0x6cc31000-0x6dc30000)
err:sync:RtlpWaitForCriticalSection section ... "../src-wine/dlls/ntdll/heap.c: main process heap section" wait timed out in thread 0304, blocked by 02fc

Module::single_latches sends a header's back edges through one new block that joins their phi values, as DXC's output has. It runs right before write() in Shader. The upstream unit test is included, placed at the end of bitcode.rs's mod tests.

3. 256 MiB stack for the pipeline workers (port of Marvisak/VIctory#1885, 5aa10e54)

PIPELINE_STACK is 256 MiB, only reserved. The largest ray-tracing passes overflow the default 2 MiB even without the endless recursion. Only the victory-pipelines-N workers get it. The upstream change to the offline translate command is left out.

Both ports needed manual merging; neither upstream patch applied cleanly here.

Testing

Linux (Arch, kernel 7.2), Radeon 8050S (Strix Halo, RDNA 3.5), RADV / Mesa 26.2.6, GE-Proton11-14 (vkd3d-proton 3.2), Series X profile, the same save, before and after:

before (81ebb7b) after
clamp / batched clamp refused (E5005), indirect draws dropped built, no clamp warnings
stack overflows in pipeline creation 2 0
heap-lock deadlock yes, the process froze about 1 min in none
host pipelines made (mesh) 471, then the freeze 918 (260 mesh)
draws per frame at most 13 (2D only) 1,294–2,405 in the world

Not covered:

  • Frame rate. On this integrated GPU, with a cold shader cache and a machine swapping heavily, world frames took 5–7 s, mostly copies and texture uploads. I didn't investigate that, and these patches aren't about it.
  • Some indirect executions are still dropped (215–1,990 a frame in the frame lines, logged as indirect execution dropped (first time for this signature)). The clamp itself builds now; I didn't look into why these are dropped.
  • Windows/MSVC. I built with x86_64-pc-windows-gnu from Linux. On Windows, D3DCompile should take the rewritten clamps the same way, but I haven't run them there.
  • The unit tests. The new test compiles (cargo check --tests -p victory-shader), but I couldn't run the GPU or shader tests here.

No game files, captures or screenshots are included.

AI use: Claude Code (Claude Opus 5.5) ported the changes, ran the before/after tests on my machine and wrote this description; I reviewed it.

🤖 Generated with Claude Code

**@⁠simon0302010** on GitHub · 2026-11-26 10:54 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/245) `wine-clamps-and-loop-latches` → `rx9070xt` · +544 −83 · 9 files · 4 commits · closed without merging Three fixes for running under Wine/Proton. Together they take the title from a freeze while loading to the world rendering on Linux. ## 1. Indirect clamps that Wine's HLSL compiler builds (#183) Under Wine, `D3DCompile` is vkd3d-shader's compiler. It refuses both the argument clamp (`indirect.rs`) and the batched clamp (`indirect/batch.rs`): ``` argument clamp: clamp:91:10: E5005: Method 'InterlockedOr' is not defined on type 'RWByteAddressBuffer'. no argument clamp: indirect execution dropped ``` So every indirect draw was dropped. This uses the rewrite described in #183 (from fxceless/victory-fork#1011), applied to both clamps: - the two buffers each shader writes are `RWStructuredBuffer<uint>` indexed in words, so the bytes written are the same; the budget's diagnostics stay at the old byte offsets 4/8/12/16 (words 1–4) - `Interlocked*` are called as functions on the word - `[allow_uav_condition]` is dropped - the root signatures are serialized in `root_signature()`, because Wine's compiler embeds none from `[RootSignature]` Strides, argument offsets and the batch table's places are multiples of 4: D3D12 requires it, and `Table::place` checks it. This complements #243 (DXC fallback). That PR changes the same function (`make_from`), so whichever is merged second needs a small rebase. With this one, `D3DCompile` succeeds under Wine, so the fallback wouldn't be reached for the clamps. ## 2. One back edge per loop header (port of Marvisak/VIctory#1885, `d48ec767`) vkd3d-proton's DXIL conversion (dxil-spirv) keeps one back edge per loop header. With several, it recurses without end. Under Wine that stack overflow doesn't fail the pipeline, it hangs: here the overflowing thread was holding the process heap lock, so the whole process froze: ``` err:virtual:virtual_setup_exception stack overflow 3456 bytes addr ... stack 0x6cc30280 (0x6cc30000-0x6cc31000-0x6dc30000) err:sync:RtlpWaitForCriticalSection section ... "../src-wine/dlls/ntdll/heap.c: main process heap section" wait timed out in thread 0304, blocked by 02fc ``` `Module::single_latches` sends a header's back edges through one new block that joins their phi values, as DXC's output has. It runs right before `write()` in `Shader`. The upstream unit test is included, placed at the end of `bitcode.rs`'s `mod tests`. ## 3. 256 MiB stack for the pipeline workers (port of Marvisak/VIctory#1885, `5aa10e54`) `PIPELINE_STACK` is 256 MiB, only reserved. The largest ray-tracing passes overflow the default 2 MiB even without the endless recursion. Only the `victory-pipelines-N` workers get it. The upstream change to the offline `translate` command is left out. Both ports needed manual merging; neither upstream patch applied cleanly here. ## Testing Linux (Arch, kernel 7.2), Radeon 8050S (Strix Halo, RDNA 3.5), RADV / Mesa 26.2.6, GE-Proton11-14 (vkd3d-proton 3.2), Series X profile, the same save, before and after: | | before (`81ebb7b`) | after | |---|---|---| | clamp / batched clamp | refused (E5005), indirect draws dropped | built, no clamp warnings | | stack overflows in pipeline creation | 2 | 0 | | heap-lock deadlock | yes, the process froze about 1 min in | none | | host pipelines made (mesh) | 471, then the freeze | 918 (260 mesh) | | draws per frame | at most 13 (2D only) | 1,294–2,405 in the world | Not covered: - Frame rate. On this integrated GPU, with a cold shader cache and a machine swapping heavily, world frames took 5–7 s, mostly copies and texture uploads. I didn't investigate that, and these patches aren't about it. - Some indirect executions are still dropped (215–1,990 a frame in the frame lines, logged as `indirect execution dropped (first time for this signature)`). The clamp itself builds now; I didn't look into why these are dropped. - Windows/MSVC. I built with `x86_64-pc-windows-gnu` from Linux. On Windows, `D3DCompile` should take the rewritten clamps the same way, but I haven't run them there. - The unit tests. The new test compiles (`cargo check --tests -p victory-shader`), but I couldn't run the GPU or shader tests here. No game files, captures or screenshots are included. *AI use: Claude Code (Claude Opus 5.5) ported the changes, ran the before/after tests on my machine and wrote this description; I reviewed it.* 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Under Wine, D3DCompile is vkd3d-shader's compiler. It refuses both clamp
shaders (no Load/Interlocked* methods on RWByteAddressBuffer, no
[allow_uav_condition]), so every indirect draw was dropped and the world
did not render.

Both clamps now write through RWStructuredBuffer<uint> indexed in words
(the same bytes), call Interlocked* as functions, and drop
[allow_uav_condition]. Their root signatures are serialized here, as
Wine's compiler embeds none.

Ported from fxceless/victory-fork#1011, as described in
Belobug/VIctory-Belobug-AMD#183.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Ck4nRpEBizbYrjNarbDQc4
vkd3d-proton's DXIL conversion (dxil-spirv) keeps one back edge per loop
header, as DXC's code has. With several, it takes the others for forward
edges and recurses without end over the cycle that makes (in programs
with wave shuffles). Under Wine the stack overflow then hangs the thread,
and with it the process (seen here as a deadlock on the heap lock).

Before writing, Module::single_latches sends the back edges of a header
with several through one new block that joins their phi values.

Ported from Marvisak/VIctory#1885 (d48ec767, by powplusplus); see also
Marvisak/VIctory#2754.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Ck4nRpEBizbYrjNarbDQc4
vkd3d-proton converts DXIL on the thread that creates the pipeline,
recursively over its control flow. The largest ray-tracing passes
overflow the default 2 MiB, and under Wine the overflow hangs the thread
instead of failing. The pipeline workers now get 256 MiB, reserved only.

Ported from Marvisak/VIctory#1885 (5aa10e54, by powplusplus), without its
change to the offline translate command.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Ck4nRpEBizbYrjNarbDQc4
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:55:35 +00:00
Author
Owner

@⁠gut0to on GitHub · 2026-11-26 16:22 UTC · original · reviewed

AI-assisted review. I inspected the CFG rewrite and its added unit test statically; I did not run shader tests or a Wine/game build. This review suggests one focused control-flow shape to cover.

**@⁠gut0to** on GitHub · 2026-11-26 16:22 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/245#pullrequestreview-6077484927) · **reviewed** AI-assisted review. I inspected the CFG rewrite and its added unit test statically; I did not run shader tests or a Wine/game build. This review suggests one focused control-flow shape to cover.
@ -552,0 +563,4 @@
/// for a forward edge and then recurses without end over the cycle that
/// makes (in programs with wave shuffles). The back edges of a header
/// with several go through a new block that joins their phi values.
pub fn single_latches(&mut self) {
Author
Owner

@⁠gut0to on GitHub · 2026-11-26 16:22 UTC · original

AI-assisted review; I did not run tests. Could the CFG test also include nested loop headers where both loops have multiple back edges and header phis? The current fixture verifies one header with two latches; a nested case would exercise the per-header rewrite order and ensure the inner latch phi remains a valid incoming value for the outer loop after both blocks are split.

**@⁠gut0to** on GitHub · 2026-11-26 16:22 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/245#discussion_r4711052735) AI-assisted review; I did not run tests. Could the CFG test also include nested loop headers where both loops have multiple back edges and header phis? The current fixture verifies one header with two latches; a nested case would exercise the per-header rewrite order and ensure the inner latch phi remains a valid incoming value for the outer loop after both blocks are split.
github-bot closed this pull request 2026-11-26 18:10:25 +00:00

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.