Skip to content

Link victory.exe with a 16 MiB default thread stack - #151

Open
ItsYusei99 wants to merge 1 commit into
Marvisak:mainfrom
ItsYusei99:fix/default-thread-stack
Open

ItsYusei99 wants to merge 1 commit into
Marvisak:mainfrom
ItsYusei99:fix/default-thread-stack

Conversation

@ItsYusei99

Copy link
Copy Markdown

Threads that are created without a stack size get the size the executable's header names, and the linker's default is 1 MiB. The host graphics stack creates such threads: vkd3d-proton's own threads and the driver's. When they compile the title's large world shaders, 1 MiB is not always enough.

Under Wine with vkd3d-proton on an RTX 4070 (driver 620.70.06), loading into the world overflowed the stack of four of those threads at once, all at the same Unix-side address in the driver. One of them was vkd3d-proton's pipeline-library disk thread:

01c8:err:virtual:virtual_setup_exception stack overflow 1792 bytes addr 0x6f44ef27e623 stack 0x10da4c0900 (0x10da4c0000-0x10da4c1000-0x10da5c0000)
01d8:err:virtual:virtual_setup_exception stack overflow 2880 bytes addr 0x6f44ef27e623 stack 0x10dcd604c0 (0x10dcd60000-0x10dcd61000-0x10dce60000)

apps/victory/build.rs now passes /STACK:16777216 to the linker for MSVC targets only. That is a reservation: pages are committed as they are used, so threads that stay shallow cost nothing extra. Threads that ask for an explicit size, such as Rust's std::thread with its 2 MiB default, are unaffected.

Tested

Linux, Wine 11.22, RTX 4070, Ryzen 7 9800X3D, title loaded by hand into the world. I checked the header field of the built exe (SizeOfStackReserve = 16777216, release and diag).

  • Before: 1 MiB stacks, four stack overflows during the world load (one run).
  • After: no stack overflow in a run that reached further into pipeline creation (one run).

Caveat: the "after" run was on a newer main that also includes #43. That PR fixes a stack overflow inside VIctory's shader lowering, which is a different place from the driver address above. I have not yet isolated the two with an A/B run on the same commit. The run then hit a separate driver fault in vkCreateComputePipelines (0xc0000005), reported in #144.

Not tested on native Windows. On Windows the same thread pools exist, so a larger reserve should be harmless there.

🤖 Generated with Claude Code

Threads created without a stack size take the executable's default
reserve, 1 MiB from the linker. vkd3d-proton's and the driver's own
threads compiling the title's large world shaders overflowed it under
Wine on an RTX 4070 (four threads at one driver address during the world
load). Reserve 16 MiB for MSVC targets; pages are committed only as used.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
edsuuu referenced this pull request in edsuuu/VI-BR-PORT Nov 24, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@NathansDomainSolutions

Copy link
Copy Markdown

An A/B test on Linux, with both runs on main d2a4bae. The only difference is this PR's build.rs change. I checked the built exe: SizeOfStackReserve is 16777216 with the PR and 1048576 without it.

Setup: Arch (kernel 7.3.5), Proton Experimental experimental-11.0-20261112, RTX 4070 on driver 620.73.04, Ryzen 7 7800X3D, title 1.0.2.1. Diag build cross-compiled with cargo-xwin 0.24.1. Run offline with a scripted Enter press every 8 s (VICTORY_KEYS).

  • Without the PR: passed the player prompt and the first-boot "Finish setup?" screen, and showed a loading spinner. About 3.5 min in it was back at the player prompt. The process exited at about 4 min with nothing in crashes.log. Wine debug output wasn't captured in this run, so I can't confirm it was a stack overflow.
  • With the PR (next run, settings saved): reached the loading-screen artwork at frame 1024, past where the run without the PR stopped. At about 2 min, the frame after 2047, it hung on err:vulkan:vkCreateComputePipelines Exception 0xc0000005 in Unix call. This is the driver fault from Wine + vkd3d-proton on NVIDIA: the driver crashes in vkCreateComputePipelines while the world loads (0xc000001d / 0xc0000005, earlier stack overflows) #144. There was no stack overflow line in the Wine err output (WINEDEBUG=err+all).

So the PR moves the failure from a silent exit to #144's driver fault. One caveat: the second run started with saved settings, so the two runs didn't take exactly the same path.

AI use: Claude Code (Claude Opus 5.5) ran the builds and runs and wrote this comment. The results come from the runs described above.

@mercuryVM mercuryVM 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 d77408b on Windows 11, RTX 5070, MSVC: cargo build -p victory succeeds. The built victory.exe has SizeOfStackReserve = 0x1000000 (16 MiB) in its optional header, so the linker argument takes effect. On this branch, cargo test --workspace fails to compile with E0428: the name tests is defined multiple times in crates/victory-gpu/src/host.rs. That is the duplicate test module #129 fixed on main after this branch was cut, not this change. Merged onto current main, the workspace tests pass.

  • Safety screen: the new build.rs only prints cargo:rustc-link-arg-bins=/STACK:16777216, gated on CARGO_CFG_TARGET_ENV == "msvc". It runs nothing, reads nothing and touches no network.
  • -bins keeps it to binaries, so test harnesses and libraries are unaffected. As you say, it is a reservation, so only threads created with a 0 stack size get the larger default.
  • The reservation also applies to the title's own threads that pass 0. That is 16 MiB of address space each on 64-bit, which is harmless.

No issues found. A rebase onto main would let the branch test cleanly by itself.

AI-assisted (Claude Code).

github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 24, 2026
github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 24, 2026
github-actions Bot pushed a commit to KevinPratap/VIctory that referenced this pull request Nov 24, 2026
Merges Marvisak#115 Marvisak#151 Marvisak#238 Marvisak#353 Marvisak#378 Marvisak#476 Marvisak#482 Marvisak#535 Marvisak#649 Marvisak#664 Marvisak#1177 onto main
(ffe310e), each head unchanged, no conflicts.

One change of mine: Marvisak#378 turns the duplicate check in translate.rs into a
nested `if !seen.insert(..) { if !list { .. } }`, which
clippy::collapsible_if rejects under -D warnings; it is now one
`if !seen.insert(..) && !list` (clippy --fix, same behaviour).

cargo clippy --workspace --all-targets --locked -- -D warnings, with and
without --all-features, is clean and cargo test --workspace --locked passes
(354 passed, 6 ignored; main has 342 passed, 6 ignored).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 24, 2026

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Needs work: needs the maintainer's decision. This adds a new apps/victory/build.rs that passes /STACK:16777216 to the linker for MSVC targets. Build scripts and linker settings are the maintainer's call. The change is small and only raises the reserve for threads created without an explicit size. What would help that decision: (1) an A/B on one commit showing the stack overflow lines without the PR and none with it (the runs so far were on Wine/vkd3d-proton, the "after" run also included #43, and the two runs in the comments took different paths); (2) whether the overflow happens on native Windows drivers at all.

CI: no check runs on the head commit.


Generated by Claude Code

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.

4 participants