Skip to content

RR runtime: compile thread dies of a stack overflow under Proton with current vkd3d-proton (fix included) #149

Closed

Description

@j0nsh1n

Under Proton with a current vkd3d-proton (master 5b1089c8), the RR runtime's background compile thread dies of a stack overflow while it compiles the opt-in verification kernels (WG_RR_HEAD=exact/strict/debug, WG_RR_BODY=X/Z, WG_RR_PATHS=verified). Nothing is logged. compile_failed is never set, so the opt-in variants stay "still being prepared" for good. The menu modes (Exact, Accurate, Fast) are compiled in the earlier passes, so they still run.

Windows with AMD's driver is not affected. This comes from the D3D12-to-Vulkan translation.

Cause

vkd3d-proton translates each kernel on the thread that calls CreateComputePipelineState. dxil-spirv's rewritten structurizer (in vkd3d-proton master, so in upcoming Proton releases) recurses about once per branch, and it needs roughly twice the stack it used to: reported upstream as HansKristian-Work/dxil-spirv#366. Measured on Linux, stage.D4-F needs 2 MB and stage.IN0 1 MB, and Windows/Wine needs more. A std::thread gets the game's default stack:

  • 1 MB in rr_test_host: stage.IN0 overflows.
  • 2 MB in Cyberpunk 2077: stage.D4-F overflows.
err:virtual:virtual_setup_exception stack overflow 3392 bytes addr ... stack 0x91a02c0 (0x91a0000-0x91a1000-0x93a0000)

Proposed fix

One file, clean/rr_f/runtime/src/rr_runtime.cpp, diff below:

  • The compile thread gets a 64 MB stack reservation through CreateThread with STACK_SIZE_PARAM_IS_A_RESERVATION. That is address space only; pages are committed as they are used.
  • make_pso logs the kernel name, its size and the HRESULT when CreateComputePipelineState fails, so a failed pipeline shows up in wronggpu-rr.log.
  • If the thread cannot start, set-device logs it and fails, as its other failures do.

The thread is a small CompileThread class with joinable() and join(), so the existing call sites stay as they are.

Tested

The runtime was built from main 926859b with llvm-mingw. It has not been built with MSVC. rr_runtime.cpp is unchanged on main since then.

  • rr_test_host under GE-Proton 11-11 with vkd3d-proton 5b1089c8 + dxil-spirv#362:
    • Before: the thread died at stage.IN0; the verification head ran 0 of 30 frames.
    • After: all 148 kernels compiled with no overflow; 30 of 30 frames.
  • With the old runtime and the menu's Exact mode on the same build: 30 of 30 frames, but the thread still died in the background pass.
  • In game (Cyberpunk 2077, GE-Proton 11-11, RX 9070 XT, the same vkd3d-proton):
    • RR was ready 14.5 s after start, and the opt-in variants were prepared at 89.5 s.
    • 12,898 evaluates, 0 failed; clean shutdown.
    • Fast 7.0 ms and Accurate 7.3 ms of GPU time per frame, unchanged.
Diff against main
diff --git a/clean/rr_f/runtime/src/rr_runtime.cpp b/clean/rr_f/runtime/src/rr_runtime.cpp
index c39ddf6..22b4d0c 100644
--- a/clean/rr_f/runtime/src/rr_runtime.cpp
+++ b/clean/rr_f/runtime/src/rr_runtime.cpp
@@ -38,6 +38,7 @@
 #include <algorithm>
 #include <atomic>
 #include <cmath>
+#include <functional>
 #include <map>
 #include <mutex>
 #include <string>
@@ -143,6 +144,34 @@ void log_line(const std::string& s) {
   fclose(f);
 }
 
+// The pipeline compiles' worker thread, with a 64 MB stack reservation (address space; pages are committed as used).
+// Under Proton, vkd3d-proton translates each kernel on the calling thread, and dxil-spirv's structurizer (rewritten in
+// its commit 71967a38) recurses about once per branch: the opt-in kernels stage.IN0 and stage.D4-F overflowed a
+// std::thread's default stack (1 MB in the test host, 2 MB in Cyberpunk), the worker died without setting
+// compile_failed, and the opt-in variants never became ready.
+class CompileThread {
+ public:
+  bool start(std::function<void()> f) {
+    fn_ = std::move(f);
+    h_ = CreateThread(nullptr, 64u << 20, run, this, STACK_SIZE_PARAM_IS_A_RESERVATION, nullptr);
+    return h_ != nullptr;
+  }
+  bool joinable() const { return h_ != nullptr; }
+  void join() {
+    WaitForSingleObject(h_, INFINITE);
+    CloseHandle(h_);
+    h_ = nullptr;
+  }
+
+ private:
+  static DWORD WINAPI run(void* self) {
+    static_cast<CompileThread*>(self)->fn_();
+    return 0;
+  }
+  HANDLE h_ = nullptr;
+  std::function<void()> fn_;
+};
+
 // RDNA 4 boards (the rule of clean/runtime/rdna4.h on clean/rdna4-dx12, WrongGPU's own code)
 bool rdna4_adapter(uint32_t vendor, bool software, const std::string& d) {
   return vendor == 0x1002 && !software && (d.find("RX 9070") != std::string::npos || d.find("RX 9060") != std::string::npos);
@@ -388,7 +417,7 @@ struct Runtime {
   // clean/rr-f-live2: the frame kernels' pipelines are made on a worker thread (a cold driver cache needs minutes
   // for them; set-device must not block the game that long). Evaluates fail (the proxy passes the frame through)
   // until kernels_ready. The worker never takes mu; drop_device cancels and joins it.
-  std::thread compile_thread;
+  CompileThread compile_thread;
   std::atomic<bool> kernels_ready{false}, compile_cancel{false};
   // clean/rr-f-flow: kernels_ready = the default frame's kernels (compiled first); all_ready = every kernel, the opt-in
   // variants' too (WG_RR_HEAD=exact/strict/debug, WG_RR_BODY=X/Z, WG_RR_PATHS=verified), compiled after them
@@ -884,7 +913,11 @@ ID3D12PipelineState* make_pso(ID3D12Device* dev, ID3D12RootSignature* rs, const
   pd.pRootSignature = rs;
   pd.CS = {b->data, b->size};
   ID3D12PipelineState* p = nullptr;
-  if (FAILED(dev->CreateComputePipelineState(&pd, IID_PPV_ARGS(&p)))) return nullptr;
+  const HRESULT hr = dev->CreateComputePipelineState(&pd, IID_PPV_ARGS(&p));
+  if (FAILED(hr)) {
+    log_line(fmt("pipeline state for %s (%u bytes) failed: hr 0x%08lx", b->name, (unsigned)b->size, (unsigned long)hr));
+    return nullptr;
+  }
   return p;
 }
 
@@ -1338,7 +1371,7 @@ uint32_t set_device_locked(ID3D12Device* given) {
                      "(the default is used)", bad ? bad : "?"));
     }
     const unsigned start_vbits = rt.start_vbits;
-    rt.compile_thread = std::thread([dev, rs, blobs, start_vbits] {
+    const bool started = rt.compile_thread.start([dev, rs, blobs, start_vbits] {
       Runtime& r = R();
       const ULONGLONG t0 = GetTickCount64();
       // the helper (g_prep.on): its passes only, progress per kernel (the two made at set-device count as done)
@@ -1396,6 +1429,11 @@ uint32_t set_device_locked(ID3D12Device* given) {
       }
       }
     });
+    if (!started) {
+      log_line(fmt("set-device: the kernel compile thread could not start (error %lu)", (unsigned long)GetLastError()));
+      drop_device();
+      return WG_E_D3D_API;
+    }
     // a warm driver cache needs well under a second: wait a little so that warm starts run RR from the first frame
     char wv[16] = {};
     const DWORD wait_ms = GetEnvironmentVariableA("WG_RR_COMPILE_WAIT_MS", wv, sizeof wv) ? (DWORD)atoi(wv) : 3000u;

🤖 Generated with Claude Code

Activity

  1. added
    bug
    on Nov 14, 2026
  2. added this to the 0.6.2 milestone on Nov 14, 2026
  3. added
    area: ray-reconstruction
    area: linux
    on Nov 14, 2026
  4. phantoslayer21 commented on Nov 14, 2026

    @phantoslayer21
    Owner

    The cause is well pinned down, thanks. Labelled as an RR bug under Proton, milestone 0.6.2. It affects only the opt-in verification kernels, not the menu modes (Exact, Accurate, Fast), so I'm not holding 0.6.1 for it.

    Please open the diff as a pull request, with the clean-room statement and sign-off from CONTRIBUTING. Because it changes how the compile thread starts for every player, it will get an MSVC build and a Windows run before it's merged.

  5. added a commit that references this issue on Nov 14, 2026
    05336c7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: linuxarea: ray-reconstructionbug

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions