shaders: replace switch with if/else in world2d fragment shader - #1817
ranawaqas-ai wants to merge 2 commits into
Conversation
Apple's OpenGL shader compiler crashes while linking this shader. The stack ends in glpLLVMCGSwitchStatement, and the crash reproduces with both Homebrew clang and Apple clang, so it is a driver bug rather than a build problem. Using if/else avoids the compiler path entirely and lets the world render stage load on macOS. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
TheJJ
left a comment
There was a problem hiding this comment.
hmm, but the switch is the more efficient implementation, isn't there some better fix for macos? since other platforms compile this correctly, i don't think we should workaround a mac bug for all platforms :) is there a way you somehow use a more compliant glsl compiler?
|
Fair point on not penalising other platforms for a Mac bug. On the compiler question: the GLSL compiler here is part of Apple's OpenGL driver, not something the build picks. The crash is a SIGSEGV inside the driver while linking, with the stack running Two narrower options if you prefer to keep the switch for everyone:
I am not set up to iterate on this any further right now, so please feel free to take it over, adapt it, or close it. Happy either way, and thanks for the quick review on #1818. |
|
my (unrequested 馃檭) two cents: Opengl on macos is deprecated. currently stuck on an old version and they could even remove it completely in the future. If we want a clean solution we can 1) drop support for macos. and possibly keep a (painful to keep up to date) macos branch with the workarounds to make it compile. 2) drop opengl and move to vulkan or webgpu |
|
I'd say move to vulkan - but so far the renderer was built largely for opengl... why, macos, why. |
Apple's OpenGL shader compiler crashes with SIGSEGV while linking
world2d.frag.glsl. The stack ends inglpLLVMCGSwitchStatementinsidegleLinkProgram, so theswitch (alpha)block is what trips it.Reproduced on macOS 27 (arm64) with Qt 6.11.2, using both Homebrew clang 23.1.1 and Apple clang 21.0.0, so it is a driver bug rather than a toolchain problem. Any demo that loads the world render stage dies on startup, including
renderer_demo 3.Rewriting the switch as if/else avoids that compiler path. After the change the world render stage loads and
renderer_demo 3renders terrain and sprites normally.Also adds me to
copying.mdas a first-time contributor, per doc/contributing.md.make checkmergepasses.