Bug 241728

Summary: WebGL Internal error compiling shader with Metal backend.
Product: WebKit Reporter: Christopher Dyken <cdyk-bugzilla>
Component: WebGLAssignee: Nobody <webkit-unassigned>
Status: NEW ---    
Severity: Normal CC: dino, geofflang, gman, jonahr, kbr, kkinnunen, kpiddington, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: Safari 15   
Hardware: Mac (Intel)   
OS: macOS 12   
Attachments:
Description Flags
Failure log from Chromium with ANGLE's Metal backend none

Description Christopher Dyken 2022-06-17 14:34:05 PDT
On Safari 15 (both MacOs 12 and iOS 15.5), my shaders have started to fail linking with the message "Internal error compiling shader with Metal backend". They work fine on chrome and firefox.

I have reduced one shader to the following repro case (https://jsfiddle.net/cdyk1/12whq53t/11/):

const canvas = document.getElementById("foo");
const gl = canvas.getContext("webgl2")

const vs = gl.createShader(gl.VERTEX_SHADER);
gl.shaderSource(vs, `#version 300 es 
precision highp float; 
in vec3 a_POSITION0; 
void main() 
{ 
  gl_Position = vec4(a_POSITION0, 1.0); 
} 
`);
gl.compileShader(vs);
console.log(gl.getShaderInfoLog(vs));

const fs = gl.createShader(gl.FRAGMENT_SHADER);
gl.shaderSource(fs, `#version 300 es 
precision highp float; 
uniform MaterialParameters { 
  float specularPower; 
}; 

layout(location=0) out vec4 fragColor; 

void main() 
{ 
  fragColor = vec4(specularPower != 0.0 ? specularPower : 80.0); 
} 
`
);
gl.compileShader(fs);
console.log(gl.getShaderInfoLog(fs));

const prog = gl.createProgram();
gl.attachShader(prog, vs);
gl.attachShader(prog, fs);
gl.linkProgram(prog);
console.log(gl.getProgramInfoLog(prog));  // Outputs "Internal error compiling shader with Metal backend."
Comment 1 Kenneth Russell 2022-06-17 15:50:47 PDT
Created attachment 460316 [details]
Failure log from Chromium with ANGLE's Metal backend

Failure log from Chromium with ANGLE's Metal backend
Comment 2 Kenneth Russell 2022-06-17 15:52:01 PDT
Attached is the failure log from top-of-tree Chromium with ANGLE's Metal backend. It looks like there's a bug in translation of the uniform block containing a single float.

Hopefully Kyle's ongoing work to change how uniform blocks are translated will implicitly address this.
Comment 3 Christopher Dyken 2022-06-18 01:49:37 PDT
It looks like the failure is tied to fetching the true-expression from a uniform block:

Putting more data into MaterialParameter still fails to link:
----------------------------------------
#version 300 es 
precision highp float; 
uniform MaterialParameters { 
  vec4 bar;
  float specularPower;
  float baz;
}; 
layout(location=0) out vec4 fragColor; 
void main() 
{ 
  fragColor = vec4(specularPower != 0.0 ? specularPower : 80.0,
                   bar.xy,
                   baz); 
}
----------------------------------------


Moving specularPower out of the block into a single uniform links successfully:
----------------------------------------
#version 300 es 
precision highp float; 
uniform MaterialParameters { 
  vec4 bar;
  float baz;
}; 
uniform float specularPower;
layout(location=0) out vec4 fragColor; 
void main() 
{ 
  fragColor = vec4(specularPower != 0.0 ? specularPower : 80.0,
                   bar.xy,
                   baz); 
}
----------------------------------------


Adding a float-cast to the true-expression links successfully:
----------------------------------------
#version 300 es 
precision highp float; 
uniform MaterialParameters { 
  float specularPower; 
}; 
layout(location=0) out vec4 fragColor; 
void main() 
{ 
  fragColor = vec4(specularPower != 0.0 ? float(specularPower) : 80.0); 
}
----------------------------------------


Fetching from the false-expression links successfully:
----------------------------------------
#version 300 es 
precision highp float; 
uniform MaterialParameters { 
  float specularPower; 
}; 
layout(location=0) out vec4 fragColor; 
void main() 
{ 
  fragColor = vec4(specularPower == 0.0 ? 80.0 : specularPower); 
}
Comment 4 Radar WebKit Bug Importer 2022-06-24 14:35:13 PDT
<rdar://problem/95880969>