-
Notifications
You must be signed in to change notification settings - Fork 550
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[MSL] textureGrad -> sample_compare translation doesn't work on macOS #796
Comments
Sigh. Okay...looks like Apple introduced that restriction (at least documented it) in MSL 2.1. Yes...SPRIV-Cross can emit different code for macOS and iOS...but in this case...do we want to? Do we want to simply output a Thoughts, everyone? |
It’s not quite the same thing, but a similar translation happens the other way, from SampleCmpLevelZero in HLSL to textureGrad in GLSL: |
So, there is a similar case for GLSL already. In HLSL, you can SampleCmpLevelZero for the Cascaded case. Unfortunately, there is no textureLod() for sampler2DArrayShadow, so I go the other way, detect a constant 0 LOD and turn that into a constant 0 gradient. We can do the opposite case for MSL. If the gradient is not possible to prove to be constant 0, we can bail. I don't think we should special case just iOS here unless proven to be vitally important for some obscure use case. I'll get to it. |
Was simple enough to just check for macOS vs iOS so implemented that as well. Should be a best-effort implementation for our purpose. |
Awesome, thank you for the fix! |
Shader Playground link
This GLSL:
is currently converted (via glslang) to this MSL:
This is correct for iOS. However, as noted in the Metal Shading Language Specification:
On macOS, changing the above MSL to the following makes it compile:
I don't know if there is precedent for compiling MSL differently for iOS and macOS?
(Of course, all this would probably be unnecessary if GLSL had a
textureLod
overload that takes asampler2DArrayShadow
...)Edit: I was rather laser-focused on my particular usage for cascaded shadow mapping. The above “fix” for macOS of course only works when the gradient parameters are 0.
The text was updated successfully, but these errors were encountered: