When I attempted to port a Metal shader from iOS, I tried rewriting the shader in SKSL and running it on iOS. The program compiles and runs, but there are some precision issues. After debugging with the Metal Debugger, I discovered that the problem arises because SKSL uses half for textures and samplers by default. Is there a way to make SKSL use float for textures and samplers when it ultimately compiles to iOS’s MSL?
My SKSL looks like:
uniform shader child;
uniform float scale;
uniform float imageWH[2];
float4 srgbToLinear(float4 coord) {
......
float4 color = child.eval(coord)
And the result in debugger:
kernel float4
srgbToLinear(texture2d<half, access::sample> inTexture xxxx
.......
float4 p0 = float4(inTexture.sample(smp, coord))