Skip to content

Add Vulkan & Mac Support#614

Open
cochcoder wants to merge 12 commits into
MCRcortex:devfrom
cochcoder:vulkan
Open

Add Vulkan & Mac Support#614
cochcoder wants to merge 12 commits into
MCRcortex:devfrom
cochcoder:vulkan

Conversation

@cochcoder

Copy link
Copy Markdown

Adds a Vulkan render path that runs when MC 26.2 is on its own Vulkan backend. Following whatever MC's API is set to.

This PR was generated with AI assistance and iteratively tested in game. Everything builds clean and all 25 VK shader variants compile via glslc. Runtime verified on NVIDIA RTX 5070 Ti (Windows 11 & CachyOS) and Apple M4 (MoltenVK 1.4.2). If it's decided that no AI generated code is allowed, I'll respect that decision and hope that this PR will still help with porting Voxy to Vulkan.

When MC is on Vulkan, Voxy adopts the game's VkDevice/queue via a Blaze3D-VK adapter mixin and records all LOD rendering into MC's frame command buffer from a Sodium hook (TAIL of drawChunkLayer/OPAQUE). When MC is on OpenGL, the existing MDIC backend runs unchanged. No GL fallback either way with no GL context existing under MC-on-Vulkan.

Architecture:

  • Pure-VK render core (client/core/vk/render/): compositor, terrain renderer (indexed-indirect-count with MoltenVK fixed-count fallback), HiZ, traversal, SSAO, depth-bound culling, frame context (VkEvent retirement + deferred destruction), streams.
  • Backend-neutral seams so GL is unchanged: IDeviceBuffer, AbstractUpload/DownloadStream, IModelStore, IBasicGeometryData, INodeGpuOps, INodeCleaner, IAtlasTextureReader.
  • Shared CPU pipeline (NodeManager, mesh gen, model bakery) runs unmodified on both backends.
  • Single-source GLSL with #ifdef VOXY_VULKAN guards.

MoltenVK: drawIndirectCount feature query + fixed-count fallback, mutable-format D32S8 depth-only sampling, macOS natives for lwjgl-lmdb/lwjgl-zstd.

Verified: builds clean, 25/25 shaders compile, in-game LOD rendering on desktop Vulkan + MoltenVK, verified compatable with mods in Fabulously Optimized.

Performance: With a render distance of 260 chunks, OpenGL performance remains the same while Vulkan provides close to 200 FPS uplift on my Laptop with a RTX 5070 Ti (on CachyOS). While a Macbook Air M4 gives around 200 FPS in a vanilla world with 260 chunks.

  • Mods used in performance testing:
    - BadOptimizations
    - EntityCulling
    - FerriteCore
    - ImmediatelyFast
    - Lithium
    - Moonrise
    - More Culling
    - Sodium
    - Sodium Extra
    - Voxy World Gen V2
    - Zoomify

fixes #208, fixes #607, fixes (mostly) #432

…ture query, discrete-GPU preference, fixed-count indirect fallback (MoltenVK)
…Vulkan backend, VkComputePipeline infra, macOS host-required gate
… seams for GL/VK parity

Voxy now follows MC's own graphics API: when MC 26.2 runs on its Vulkan backend, Voxy adopts the game's VkDevice/queue via a Blaze3D-VK adapter mixin and records all LOD rendering into MC's frame command buffer from a Sodium hook (TAIL of drawChunkLayer/OPAQUE). When MC is on OpenGL, Voxy uses its existing MDIC backend unchanged. No user-facing toggle; no GL fallback either way (no GL context exists under MC-on-Vulkan).

Shared CPU pipeline (NodeManager, mesh gen, model bakery, render-distance tracker, viewport math, all GLSL sources via #ifdef VOXY_VULKAN guards) is unmodified between backends; backend-specific glue lives behind seams (IDeviceBuffer, AbstractUpload/DownloadStream, IModelStore, IBasicGeometryData, INodeGpuOps, INodeCleaner, IAtlasTextureReader).

Pure-VK render core: compositor (depth setup + alpha composite with env fog), terrain renderer (indexed-indirect-count with MoltenVK fixed-count fallback + visibility-tracked budget), HiZ pyramid (subgroup-reduced), hierarchical traversal, SSAO, depth-bound culling, node cleaner, geometry/model stores, frame context (VkEvent frame retirement + deferred destruction), upload/download streams.

MoltenVK: drawIndirectCount feature query + fixed-count fallback, mutable-format D32S8 depth-only sampling, macOS natives for lwjgl-lmdb/zstd, keep osx-arm64 RocksDB native.

CmpLog: opt-in (-Dvoxy.cmplog=<path>) A/B parity logging for GL/VK comparison; no-op when unset.

Drops the phase-1 GL-interop hybrid renderer (VulkanSectionRenderer/Viewport, SharedBuffer/Image/Semaphore, VkComputePipeline) — superseded by the pure-VK host path.
@MCJEModder2026

MCJEModder2026 commented Jul 20, 2026

Copy link
Copy Markdown

I have been using this, and so far:

  • weird glitchy stuff upon loading in, but settles and fixes itself after a bit.
  • Incompatible with meteor client unfortunately (but that is also an unreleased vulkan port so that is not supprising).

macos 26, m5 chip

@cenonym

cenonym commented Jul 22, 2026

Copy link
Copy Markdown

Been running this on an M3 Pro MBP macos 15.7.4 with no noticeable issues beyond the slight glitch on first world load mentioned above, but that disappears in a split second. I'll take this over no mac support any day.

There's an open PR in MoltenVK that adds drawIndirectCount support, which seems like it will get merged soon.

Six MoltenVK-specific fixes that resolve the macOS '2D floating blocks'
loading glitch and several latent Vulkan correctness issues:

1. VkTerrainRenderer: gate fixedCountBudget on hasAnyReadback so the
   first frame with geometry issues 0 draws (not 1024+ no-op Metal draws
   from the zeroed drawCallBuffer). renderOpaque runs BEFORE buildDrawCalls
   and uses last frame's commands; on MoltenVK each no-op slot becomes a
   real Metal drawIndexedPrimitives call, causing the glitch. Desktop
   Vulkan is unaffected (vkCmdDrawIndexedIndirectCount reads count=0).

2. VkTerrainRenderer: init fbOpaqueDraws/fbTranslucentDraws/fbTemporalDraws
   to 0 instead of MAX caps (reduces no-op count on subsequent frames too).

3. VkImage2D: UNDEFINED-layout images get TOP_OF_PIPE/0 in transition()
   and transitionBatch() (no prior producer — contents discarded). Fixes
   MoltenVK strictness on first-use image barriers.

4. VulkanContext: fix subgroup properties query to use
   vkGetPhysicalDeviceProperties2 (not Features2 — was silently returning
   all-zeroes on every device). Gate subgroup paths off via
   ENABLE_SUBGROUP_PATHS=false until validated (hiz_subgroup.comp has
   a suspect subgroupBarrier with 4/256 active lanes).

5. VkFrameHost: transition DEPTH|STENCIL aspect together (not DEPTH only)
   since separateDepthStencilLayouts is never enabled. MoltenVK requires
   both aspects in the barrier.

6. VkTerrainRenderer: prep->cmdgen barrier now includes COMPUTE in dst
   stages (cmdgen's atomics are RMW reads of prep's zeroes). Without it,
   cmdgen could see stale per-frame counters on MoltenVK, placing draw
   commands at wrong offsets.

7. VkTraversal: WAR barrier between download copy and requestBuffer fill
   (Metal blit encoders don't serialise like desktop transfer queues).

Zero impact on desktop Vulkan: hasDrawIndirectCount=true skips the
fixed-count path entirely, and the barrier fixes are strict supersets
of the original scopes.
…ection-derived caps and zeroed trailing slots

- Remove unused fbDraws/fbMax/hasAnyReadback ratchet fields and VkDownloadStream import
- Remove fixedCountBudget() wrapper (was identity), inline cap as maxDraw
- MoltenVK fallback: zero only cap-sized regions of drawCallBuffer per frame
- Include COMPUTE stage in prep->cmdgen barrier for MoltenVK atomic visibility
- Compact all comments to single-line annotations
…c with section-derived caps and zeroed trailing slots"

This reverts commit 00939a9.
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.

Voxy crashes if engine is set to Vulkan Voxy doesnt work on mac

3 participants