Apple Silicon macOS port#1230
Conversation
|
Looks pretty good, I skimmed through the changes. I can't test it on Apple, and I don't know what is causing the problems. This is odd: It is a pixel shader which uses SV_PrimitiveID, if the primitiveID is not supported by hardware then we can emulate it with geometry shader, but you said that geometry shader is also not available so I'm not sure what could be done except using mesh shader. Is mesh shader supported? |
|
Hello, I’m also interested in this project and working on porting it to the Metal API. All M-series Macs support mesh shading, and on A-series devices it’s supported starting from the A14 (with some limitations before Apple9), according to the feature set table (https://developer.apple.com/metal/Metal-Feature-Set-Tables.pdf). Have you considered trying the Metal Shader Converter (https://developer.apple.com/metal/shader-converter/)? |
|
The DirectXShaderCompiler also seems to (now?) support compiling to Metal IR, might be worth taking a look. |
According to the docs DXC declares Geometry capability when PrimitiveId is used as an input in a pixel shader. |
No, haven't tried that. Looks promising. I was able to bypass the
Will investigate this too. |
* Disable geometry-shader dependency * Replace voxel GS with non-GS path * Gate primitiveID & update offline shader compiler * Fix Vulkan present/device-lost renderpass mismatch
I didn’t know that DXC supports Metal IR generation, but it seems to rely on the Metal Shader Converter and is still missing several features (such as compatibility flags, ray tracing pipelines, etc.).
@Anthony-Gaudino I see your work now, and it looks like you’re aiming to use MoltenVK to leverage existing Vulkan implementations. |
Clamp requested MSAA sample count to device-supported value and update TextureDesc to prevent Metal MTLTextureDescriptor sampleCount errors Fixes this error: `Texture Descriptor Validation MTLTextureDescriptor sampleCount (8) is not supported by device.` While trying to create a terrain.
Yes, I used MoltenVK because I though it would be easier and require less changes. I looked into the Metal shader converter and for handling Geometry and Tesellation pipelines I would need to use the Another option is to continue on forked MoltenVK path and try to make it work. And the third option is to use the stable MoltenVK and change existing shaders so that they don't depend on Geometry pipeline or Tesselation; or have separate shaders or code paths for Metal. I created another branch that follows option 3. In this new branch I was able to run the Editor and basic features work, complex actions, like trying to add a terrain still crash. |
Fix cartoon outline sample-count mismatch by rendering into MSAA target and resolving to a single-sample texture - Create an MSAA outline render target and a matching single-sample resolved texture when MSAA>1 - Resolve MSAA outline into the single-sampled texture and feed that into the outline postprocess - Ensure resource creation/cleanup and pipeline sample-counts are kept in sync to avoid Metal validation errors (MTLTextureDescriptor sampleCount mismatch) - Add logging and guards so pipelines/resources recreate correctly when sample count changes
Ensure SDL mouse coordinates are scaled only by the OS DPI (not the user UI scale) and map deltas consistently to the canvas logical space in wiInput.cpp. This resolves cursor/picking offsets when the Editor UI scaling is changed.
The SV_PrimitiveID is no longer used as PS input, instead two additional index buffers are used for indirection. The "provoke" contains primitiveIDs for every provoking vertex. The "reorder" contains the vertexID remapping from "provoke". On PS5 this removes the need to do additional geometry shader fallback for prepass rendering. It will be also helpful for MacOS port that doesn't support SV_PrimitiveID or geometry shader (PR: #1230 )
|
I implemented a workaround for SV_PrimitiveID, which will be useful for this pull request, now the prepass object rendering shaders (objectPS_prepass.cso) don't use the SV_PrimitiveID, so the problem will be gone for those. |
|
The commit above removes SV_RenderTargetArrayIndex from envmap pixel shaders, so they are not marked with Geometry shader capability. |
|
The objectGS_voxelizer is a proper geometry shader, that will just have to be not used on Apple, but it will be kept for other platforms (it is optional, not required usually, only used for voxel gi) |
Thank you! I will merge those changes! |
|
HI @turanszkij Sky PS shaders are still reported as using GS: |
|
@Anthony-Gaudino You're right, now it should be fixed. |
Have looked into those, but it must be something different. |
|
You could take a look at that correct swizzle is used for textures (no idea how to look at it on Apple though). By the way if you set just material color that shows up correctly? |
Yes, it does. If I set the color using the color picker it displays the correct color. |
Remove or comment code that is not strictly necessary for the functionality of the Editor.
Switch shadow atlas accesses to bindless_textures_float and treat SampleCmp/SampleLevel results as scalar floats (accumulate scalars, construct float3 only for blending). Complements previous commit: "Fix base color texturing appearing as grayscale".
Force 4-component vertex position format to avoid unsupported RGB32 texel Solves crash with: -[MTLDebugDevice minimumLinearTextureAlignmentForPixelFormat:]:3064: failed assertion `MTLPixelFormatInvalid is not supported on this device.' When activating `Quantization Disabled` in the mesh settings or when loading some meshes like the teapot.
Solves: -[MTLTextureDescriptorInternal validateWithDevice:]:1416: failed assertion `Texture Descriptor Validation MTLTextureDescriptor sampleCount (8) is not supported by device. While trying to add a terrain and loading some scenes like Sponza.
Compute depth resolve & linearization Fixes multiple visible issues: * Clouds visible trough objects * Lights disappearing after moving the camera not very far away * Lighting artifacts on objects * Water without transparency
Necessary for Sponza to load
Disable terrain virtual textures when sparse residency unsupported, allowing to load terrain on macOS. The terrain appears untextured on unsupported platforms, but at least it loads without crashing.
Ensure environment-probe pipeline state objects
are created for sample counts {1,2,4,8}, so a
valid PSO exists if the driver clamps a requested
MSAA (e.g. 8× -> 4× on MoltenVK/Apple Silicon).
This fixes env probes capturing only the sky when
MSAA is enabled and scene geometry was previously
missing.
Add a non-sparse terrain texturing path that decodes virtual texture data into per-chunk GPU textures, wiring mip generation and material binding so Metal/MoltenVK runs no longer show flat gray terrain. The new fallback also preserves underwater lighting, making the ocean caustics visible on terrain surfaces even without sparse residency support.
Makes Voxel GI functional on Apple builds by adding a no-geometry-shader fallback and ensuring the shader permutation system and pipeline state match that fallback. Changes include defining WI_DISABLE_VOXELIZATION_GEOMETRY_SHADER for macOS, guarding VOXELIZATION_GEOMETRY_SHADER_ENABLED in ShaderInterop_VXGI.h, injecting the platform define into shader compilation so the correct shader variants produced. This solution is not good and not optimal performance-wise, banding artifacts may occur and it's not stable, crashes might occur on large scenes, but at least it provides a functional fallback for Apple Silicon macOS users until a better solution is implemented.
…-Gaudino/WickedEngine into apple-silicon-macos-port
|
Hi @turanszkij, I’ve updated the branch with the latest changes and also updated the PR comment. There are still a few unresolved issues that I haven’t been able to fix, and I won’t be able to continue working on the macOS port for now. Hopefully, the current progress will be useful for anyone who wants to continue from here. Someone with more graphics programming experience, like @Snowapril, might be able to make good progress on it if interested. |
|
Thanks, it would be nice if the compile errors were resolved, after that I consider merging it to not lose all progress. |
|
@Anthony-Gaudino Thanks for sharing! I'm also interested in getting Wicked Engine running on macOS, so providing fixes for various compile errors with the Apple Clang compiler would be really helpful. |
|
Mac OS support was added here, renderer is using Metal API: 3899e47
Thank you for the work. |


This is an initial Apple Silicon macOS port.
Application builds, but trying to run the editor fails due to Vulkan issues.
Metal doesn't support Geometry shaders which are used in WickedEngine , these seem to be the shaders:
I tried simply ignoring geometry shaders without success, the editor runs without a crash, but it still point to errors, probably because of the unsupported geometry shaders.
There's a PR to implement geometry shaders in MoltenVK, so I also tried implementing it on latest stable forks: forking latest stable MoltenVK and also the necessary SPIRV-Cross
With this I got stuck on this crashing error while what seems to trying to render the first frame using Vulkan:
I built MoltenVK shared library and placed it on same dir as editor and have been using this command to run it to try to capture debug info:
I would probably need help to get this done.
Update
The editor runs stable, Sponza, Terrain with weather and the character controller scene works, but some tradeoffs were taken, unsolved bugs exists and some settings are unstable:
The terrain works, but it's texturing uses a new path since MoltenVK doesn't support virtual textures. Some thin seams are visible between terrain chunks.
There's a very annoying bug where black squares/stripes are visible on faces, the larger the face the higher the change that it happens. These back areas are not being processed trough a fragment shader.
Or just crash.
Voxel GI uses a different path to bypass geometry shaders, it's quite hacky.
There's a bug on the gizmo, while trying to move some element using the XY handle then the object coordinates are all set to
nan. The same happens with the scale all axis handle.For some reason impostors visualized in a certain angle appear with incorrect colors (pink).
Seems like IK and swimming are jittering.
Other issues might be present, I didn't test every single feature.