Skip to content

Conversation

@kolkov
Copy link
Contributor

@kolkov kolkov commented Dec 27, 2025

Summary

  • Fixes critical Windows stack overflow when calling Vulkan/WebGPU APIs
  • Replaces custom callWin64 assembly with syscall.SyscallN
  • Uses Go runtime's built-in asmstdcall mechanism (matches purego approach)

Problem

The custom Windows FFI assembly used NOSPLIT, $32 which prevents Go runtime stack growth. When C functions (especially Vulkan APIs) require more stack space, this caused STACK_OVERFLOW (Exception 0xc00000fd).

Solution

Replace custom assembly with Go's syscall.SyscallN which internally uses runtime.cgocall + asmstdcall. This is the same proven approach used by purego.

Changes

  • internal/syscall/syscall_windows_amd64.go - New SyscallN wrapper
  • internal/arch/amd64/call_windows.go - Updated to use new syscall
  • internal/arch/amd64/call_windows.s - Removed (source of bug)

Test Plan

  • All tests pass (89.1% coverage)
  • Pre-release script passes
  • Linter: 0 issues
  • FFI overhead: ~74 ns/op (within threshold)
  • Manual Vulkan API testing on Windows

Related

Bug report: gogpu/wgpu issues - Windows stack overflow on Vulkan calls

- Replace custom callWin64 assembly with syscall.SyscallN
- The NOSPLIT,2 directive prevented Go runtime stack growth
- Now uses Go runtime's asmstdcall mechanism (like purego)
- Fixes Exception 0xc00000fd (STACK_OVERFLOW) on Windows

Changed:
- internal/arch/amd64/call_windows.go: Use syscall.CallWin64
- internal/syscall/syscall_windows_amd64.go: New SyscallN wrapper

Removed:
- internal/arch/amd64/call_windows.s: Source of the bug
@kolkov kolkov merged commit 9f9c843 into main Dec 27, 2025
8 checks passed
@kolkov kolkov deleted the fix/windows-stack-overflow branch December 27, 2025 10:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants