Bug 241728 - WebGL Internal error compiling shader with Metal backend.
Summary: WebGL Internal error compiling shader with Metal backend.
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebGL (show other bugs)
Version: Safari 15
Hardware: Mac (Intel) macOS 12
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2022-06-17 14:34 PDT by Christopher Dyken
Modified: 2022-06-24 14:35 PDT (History)
8 users (show)

See Also:


Attachments
Failure log from Chromium with ANGLE's Metal backend (29.13 KB, text/plain)
2022-06-17 15:50 PDT, Kenneth Russell
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
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>