Skip to content

32 bit CUDA support#651

Merged
vosen merged 87 commits into
masterfrom
zluda32
Jul 8, 2026
Merged

32 bit CUDA support#651
vosen merged 87 commits into
masterfrom
zluda32

Conversation

@vosen

@vosen vosen commented Jun 26, 2026

Copy link
Copy Markdown
Owner

This is far from ready, but if one is inclined to try it the steps are. Just remember you do this at your own risk:

  • Get source code
  • Adjust hard-coded paths in zluda32\src\ipc.rs from C:\dev\ZLUDA to whatever is your path
  • Build for 64 bit and 32bit: cargo xtask -r and cargo xtask --target=i686-pc-windows-msvc -r
  • Copy 32 bit nvapi.dll and nvcuda.dll from target\i686-pc-windows-msvc\release to C:\Windows\SysWOW64
  • Launch your app, it might work or not

@vosen

vosen commented Jul 5, 2026

Copy link
Copy Markdown
Owner Author

@Nuck-TH
I am not quite following what you did with the dlls, but it seems to be fine. Your workload is failing because it uses cuCtxCreate, which was not implemented (I've added it now). Probably an older version of physx.

You can download PhysX SDK samples from here: https://developer.download.nvidia.com/PhysX/2.8.1/PhysX_2.8.1_SDK_Core.msi

You can also try fluidmark (support added today): https://www.geeks3d.com/20130308/fluidmark-1-5-1-physx-benchmark-fluid-sph-simulation-opengl-download/

@Nuck-TH

Nuck-TH commented Jul 5, 2026

Copy link
Copy Markdown

Next bunch(Alice):
https://gist.github.com/Nuck-TH/3536fb55103d8303025db233a4c584d4
According to pcgamingwiki and file versions it uses physx 2.8.4.4

Do i need both logs or one(which) is sufficient?

Fluidmark gets stuck at initializing fluid 0%, nvidia samples segfault. If fluidmark is started any(x64/i686) zluda.exe - it errors out with "could not load particle texture".
Seems like i'm doing something wrong after all :( Figures what...

Also, for some reason, zluda stopped creating cahe file, even if i run precompile...

I am not quite following what you did with the dlls

Did what is told in OP

Copy 32 bit nvapi.dll and nvcuda.dll from target\i686-pc-windows-msvc\release to C:\Windows\SysWOW64

@RunnerFaith

RunnerFaith commented Jul 5, 2026

Copy link
Copy Markdown

Managed to get Mirror's Edge working with this - followed the steps provided here and then all the steps under the "Install and enable the latest PhysX update" section on PCGamingWiki so that the game uses the newer version of PhysX and loads the ZLUDA DLLs along with it.

Settings used:
Mirror's Edge game settings - all settings maxed @ 1440p with 8XQ anti-aliasing
FPS limit removed using Mirror's Edge Tweaks.

Run-through of chapter 1 (checkpoint B): https://youtu.be/_wMEfFz_KLQ
CPU PhysX run of the same level for comparison: https://youtu.be/Lni8RE-mr60

Notes:

  • Performance when glass breaks is far better with ZLUDA vs CPU PhysX. For example, the scene @ 3:21 is basically a slideshow with CPU PhysX at single digit frames compared to ZLUDA. See the comparison video above for more.
  • Stuttering @ 0:38 seems to be present only when using ZLUDA. The other stutters @ 1:48 & 3:45 seem to happen regardless, I assume this is a game issue but will double check with PhysX off. Disregard, this is unrelated to ZLUDA.
  • Least performant areas look to be the chopper scene @ 1:00 & the elevator hallway scene @ 2:20 - I assume this is down to multiple cloth simulations in these scenes (blinds/shades & tarp respectively) but not 100% sure

zluda_trace compressed log.txt (different run from the recording but same level): zluda_trace.zip - I can provide the full log output if needed.

@Nuck-TH

Nuck-TH commented Jul 5, 2026

Copy link
Copy Markdown

This is what i get after just installing this and moving to HIP nightlies
(unlike for mirrors edge i didn't replace filed in game folder as it refuses to start with that)
AliceMadnessReturns.exe.zip

This got FluidMark and nvidia samples working :)

@R4to0

R4to0 commented Jul 5, 2026

Copy link
Copy Markdown

Managed to get Mirror's Edge working with this - followed the steps provided here and then steps 2 & 3 of the "Install and enable the latest PhysX update" section on PCGamingWiki so that the game loads the ZLUDA DLLs.

Thank you! Worked fine on my end following your instructions.

Here's some recordings:
ZLUDA OFF

2026-07-05_13-38-42_1.mp4

ZLUDA ON

2026-07-05_13-43-12_1.mp4

Hardware:
AMD Radeon RX 6600 8GB
AMD Ryzen 5 3600X
32GB DDR4@3200MT/s

Edit: test with Batman Arkham Origins, framerate wasn't that bad running on the CPU but was a lot choppy too.

ZLUDA OFF

2026-07-05_16-08-11_1.mp4

ZLUDA ON

2026-07-05_16-13-33_1.mp4

@vosen

vosen commented Jul 6, 2026

Copy link
Copy Markdown
Owner Author

@Nuck-TH try the most recent commit, it should work with Alice: Madness Returns now

As for performance, in general there's not much improvement to be made. Maybe by redoing the communication between 32-bit ZLUDA and 64-bit server from named pipes to shared memory. But that's a bit tricky.

Thanks for testing it, I did not consider installing latest physx system-wide (I already had it installed by the NV drivers). I'll be focusing on cleaning it up for merge and updating documentation (turns out you don't need to put nvcuda.dll in syswow64, you can just launch from steam by setting the command to "<PATH_TO\zluda.exe>" -- %command%), but if you have more games feel free to upload logs here before the merge

@Nuck-TH

Nuck-TH commented Jul 6, 2026

Copy link
Copy Markdown

After this changes Alice actually works \^_^/

Though some effects lower fps still, which is odd for a game that uses phys for very few select things. Seems like RPC is bottleneck after all, because compute load doesn't rise beyond certain amount(same as with FluidMark). Probably implementation of integration into engine and/or effects is bad and spams too much calls. I wouldn't be surprised, because it works horribly on CPU.

But there is peculiarity with zluda.exe - if i run the game via 64bit one i don't get any trace log. If i run with 32bit one - physx fails exact same way as in comment #4885364121... So i can't capture trace of things working.

Another thing is that there are issues with reinitializing physics - in fluidmark if you start and abort test/benchmark a few times it eventually fails and falls back to cpu. Same with nvidia samples(like SampleCloth.exe) that can switch scenes or toggle hardware acceleration.

@vosen

vosen commented Jul 6, 2026

Copy link
Copy Markdown
Owner Author

Running with 64 bit zluda.exe will do nothing, you need to run 32 bit zluda.exe: those two are different and each only works with their corresponding bitness. I want to eventually provide a single loader that supports any bitness, but that will have to wait.

The best way to run it is to change your Steam launch options to "<PATH_TO_I686\zluda.exe>" -- %command% or, if you want logs, to "<PATH_TO_I686\zluda.exe>" --zluda-trace -- %command%. Or if it's not on Steam, run directly with <PATH_TO_I686\zluda.exe> -- <PATH_TO_GAME_EXE>

As for reinitialization I agree it's a problem, I'll work on it after merging this PR.

Thanks for testing

@Nuck-TH

Nuck-TH commented Jul 6, 2026

Copy link
Copy Markdown

Running with 64 bit zluda.exe will do nothing, you need to run 32 bit zluda.exe: those two are different and each only works with their corresponding bitness.

As i written - i figured as much.

or, if you want logs, to "<PATH_TO_I686\zluda.exe>" --zluda-trace -- %command%

I know, yet:

If i run with 32bit one - physx fails exact same way as in #651 (comment)... So i can't capture trace of things working.

Physx works if game is run by itself, but not if via 32bit zluda executable.

@vosen

vosen commented Jul 6, 2026

Copy link
Copy Markdown
Owner Author

If it's a Steam game, it doesn't work if you start it through zluda.exe outside of Steam. The game executable instead of running normally goes into special mode where it messages Steam to do the actual launch and it closes. Then Steam relaunches it, totally separately and outside of zluda.exe control

@pchome

pchome commented Jul 6, 2026

Copy link
Copy Markdown

Looks promising. Linux, WINE basic wow64 unixlib.
zluda_gpu_caps_pre
log.txt

@vosen vosen mentioned this pull request Jul 6, 2026

Copilot AI left a comment

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.

Pull request overview

This PR introduces an early/experimental 32-bit CUDA support path by adding a 32-bit nvcuda.dll shim that IPCs into a 64-bit CUDA “server”, plus associated metadata plumbing (kernel arg layouts, globals) and packaging/CI updates to build and ship both 64-bit and 32-bit artifacts.

Changes:

  • Add new zluda32 (32-bit nvcuda.dll) and zluda64_server (64-bit named-pipe server) with a shared wire protocol in zluda_server_common.
  • Extend PTX/LLVM pipeline + kernel metadata to carry 32-bit-specific globals and explicit argument size/align info.
  • Add NVAPI stub + NVAPI tracing, update tracing/logging ABI, and update xtask + CI workflows to produce 32-bit zip outputs.

Reviewed changes

Copilot reviewed 53 out of 56 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
zluda64_server/src/main.rs New 64-bit CUDA server handling IPC opcodes and emulating 32-bit pointers/handles.
zluda64_server/Cargo.toml New crate manifest for the 64-bit server binary.
zluda32/src/lib.rs New 32-bit nvcuda shim exporting CUDA driver API and forwarding via IPC.
zluda32/src/ipc.rs New Windows named-pipe IPC + child-process spawning for the 64-bit server.
zluda32/Cargo.toml New crate manifest for the 32-bit nvcuda cdylib.
zluda/src/impl/tex.rs Handle null device pointer by unbinding texture in ref_set_address_v2.
zluda/src/impl/module.rs Add optional 32-bit metadata (globals + explicit arg layouts) to modules and cache pipeline.
zluda/src/impl/library.rs Thread 32-bit module metadata through lazy module initialization.
zluda/src/impl/hipfix.rs Avoid touching texture objects when none is set.
zluda/src/impl/function.rs Store optional explicit arg size/align metadata on functions.
zluda/src/impl/driver.rs Fix CLS handling of null context and expose a ZLUDA32 dark API export table.
zluda_windows/src/lib.rs Add NVAPI library entry, 32-bit library list split, and kill_child_on_process_exit helper.
zluda_trace/src/trace.rs Adjust fatbin/PTX extraction to optionally strip trailing zero.
zluda_trace/src/log.rs Add NVAPI function-name variant for logging.
zluda_trace/src/lib.rs Update logged-call ABI to include NVAPI interface id; add platform Drop cleanup.
zluda_trace/Cargo.toml Update dynasm/dynasmrt versions; mark crate as 32-bit-capable in metadata.
zluda_trace_sparse/src/lib.rs Pass new nvapi_interface parameter (0) to trace export table.
zluda_trace_nvml/src/lib.rs Pass new nvapi_interface parameter (0) to trace export table.
zluda_trace_fft/src/lib.rs Pass new nvapi_interface parameter (0) to trace export table.
zluda_trace_dnn9/src/lib.rs Pass new nvapi_interface parameter (0) to trace export table.
zluda_trace_dnn8/src/lib.rs Pass new nvapi_interface parameter (0) to trace export table.
zluda_trace_blaslt/src/lib.rs Pass new nvapi_interface parameter (0) to trace export table.
zluda_trace_blas/src/lib.rs Pass new nvapi_interface parameter (0) to trace export table.
zluda_server_common/src/lib.rs New wire protocol: opcode enum + message structs + 32-bit encoding helpers.
zluda_server_common/Cargo.toml New crate manifest for the shared server protocol.
zluda_redirect/Cargo.toml Mark redirect crate as 32-bit-capable in metadata.
zluda_inject/src/bin.rs Reuse zluda_windows::kill_child_on_process_exit helper.
zluda_inject/Cargo.toml Remove direct JobObjects dependency; mark as 32-bit-capable in metadata.
zluda_dnn9/Cargo.toml Relax rand version requirement to 0.9.
zluda_common/src/os_win.rs Fix function-pointer-to-usize cast.
zluda_common/src/lib.rs Gate some transmute-based FromCuda impls to 64-bit builds.
zluda_common/src/constants.rs Gate 64-bit-only constant to 64-bit builds.
xtask/src/main.rs Add --target support, 32-bit project filtering, and per-arch windows_paths selection.
ptx/src/test/spirv_run/mod.rs Update tests for new explicit arg size/align metadata shape.
ptx/src/pass/replace_instructions_with_functions.rs Adjust dtype handling for 32-bit texture path.
ptx/src/pass/llvm/emit.rs Skip pointer space conversions when using base 32-bit memory mapping.
ptx/src/pass/convert_32bit_to_64bit.rs Record explicit argument size/align per kernel (replacing arg-count-only metadata).
ptx/lib/zluda_ptx_impl.cpp Formatting-only tweak.
ptx_parser/src/lib.rs Extend parser to accept .u32 dtype in relevant grammar.
ptx_parser/Cargo.toml Bump strum to 0.28.
nvapi/src/lib.rs New NVAPI stub library with nvapi_QueryInterface and a small set of implementations.
nvapi/Cargo.toml New NVAPI crate manifest and packaging metadata for 32-bit/trace outputs.
nvapi_trace/src/lib.rs New NVAPI tracing shim that logs calls through the trace export table.
nvapi_trace/Cargo.toml New manifest for NVAPI tracing shim (includes dynasm for x86 thunks).
kernel_metadata/src/lib.rs Change 32-bit metadata from arg-count to explicit arg size/align vector.
dark_api/src/lib.rs Extend trace ABI with NVAPI interface id; add FunctionArgInfo; add ZLUDA32 internal dark API.
dark_api/src/fatbin.rs Add optional “strip trailing zero” behavior when decompressing payloads.
dark_api/Cargo.toml Add rkyv dependency.
cuda_types/src/dark_api.rs Add CUDA / OpenCL fatbin header flags.
cuda_macros/src/lib.rs Add proc-macros for generating IPC input/output structs and wire-object field handling.
cuda_check/Cargo.toml Relax rand version requirement to 0.9.
Cargo.toml Add new workspace members (zluda32, zluda64_server, nvapi, nvapi_trace, zluda_server_common).
.github/workflows/push_master.yml Build/package a 32-bit zip alongside 64-bit; exclude new crates from test bundle.
.github/workflows/pr_master.yml Same as above for PR CI workflow.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread zluda64_server/src/main.rs
Comment thread zluda64_server/src/main.rs
Comment thread zluda64_server/src/main.rs
Comment thread zluda64_server/src/main.rs
Comment thread zluda64_server/src/main.rs
Comment thread zluda32/src/ipc.rs Outdated
Comment thread nvapi_trace/src/lib.rs
@vosen vosen marked this pull request as ready for review July 8, 2026 04:24
@vosen vosen merged commit 9c8d00c into master Jul 8, 2026
7 checks passed
@vosen

vosen commented Jul 8, 2026

Copy link
Copy Markdown
Owner Author

Now that it has been merged, please move follow-up discussion to Issues/Discussion in this repo or to Discord.
#656 contains the list of things I plan to do to improve/fix this feature

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.

9 participants