Bug 227723 - WebGL shader link error in iOS 15 beta: "Internal error compiling shader with Metal backend"
Summary: WebGL shader link error in iOS 15 beta: "Internal error compiling shader with...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebGL (show other bugs)
Version: Safari Technology Preview
Hardware: iPhone / iPad Other
: P2 Normal
Assignee: Kyle Piddington
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2021-07-06 15:01 PDT by Mike Turitzin
Modified: 2021-08-12 13:31 PDT (History)
7 users (show)

See Also:


Attachments
Patch (1.79 KB, patch)
2021-07-06 16:19 PDT, Kyle Piddington
no flags Details | Formatted Diff | Diff
Patch for landing (6.23 KB, patch)
2021-07-07 12:03 PDT, Kyle Piddington
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Mike Turitzin 2021-07-06 15:01:26 PDT
We are seeing this error (which is new in the iOS 15 beta) when linking some shader programs used by Figma's prototype viewer. I have personally repro'ed it on an iPad running iOS 15 (19A5281j). Shaders that previously compiled and linked without issue now fail when linking with this `getProgramInfoLog` message: 

  "Internal error compiling shader with Metal backend. Please submit this shader, or website as a bug to https://bugs.webkit.org"

I have put together a minimal repro that appears to demonstrate the issue is with usage of the comma operator (see repro steps below). (We have a shader minifier that in some cases replaces semicolons with commas.) I believe the usage below is valid GLSL syntax, and it does compile and link properly on prior versions of Safari and other browsers.

Steps to Reproduce:

1. Run the following Javascript in Safari on iOS 15:
(JSFiddle link: https://jsfiddle.net/9p1f3t5r/2/ )

----------------------------------------------------------------------------------------
const VERTEX_SHADER_SOURCE = "void f(vec2 a) {} void main() { f(vec2(0.)), gl_Position = vec4(0.,0.,0.,1.); }";
// Vertex shader with comma (in main()) changed to semicolon.
//const VERTEX_SHADER_SOURCE = "void f(vec2 a) {} void main() { f(vec2(0.)); gl_Position = vec4(0.,0.,0.,1.); }";
const FRAGMENT_SHADER_SOURCE = "void main() { gl_FragColor = vec4(0.); }";

const log = (msg) => {
	console.log(msg);
	document.body.innerHTML += "<p>" + msg + "</p>";
};

const canvas = document.createElement("canvas");
const gl = canvas.getContext("webgl");

const vertexShader = gl.createShader(gl.VERTEX_SHADER);
gl.shaderSource(vertexShader, VERTEX_SHADER_SOURCE);
gl.compileShader(vertexShader);
if (!gl.getShaderParameter(vertexShader, gl.COMPILE_STATUS)) {
	log("error compiling vertex shader: " + gl.getShaderInfoLog(vertexShader));
}

const fragmentShader = gl.createShader(gl.FRAGMENT_SHADER);
gl.shaderSource(fragmentShader, FRAGMENT_SHADER_SOURCE);
gl.compileShader(fragmentShader);
if (!gl.getShaderParameter(fragmentShader, gl.COMPILE_STATUS)) {
	log("error compiling fragment shader: " + gl.getShaderInfoLog(fragmentShader));
}

const program = gl.createProgram();
gl.attachShader(program, vertexShader);
gl.attachShader(program, fragmentShader);
gl.linkProgram(program);
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
	log("error linking program: " + gl.getProgramInfoLog(program));
}

log("DONE");
----------------------------------------------------------------------------------------

Expected Results:

The shader program compiles/links without error.

Actual Results:

This error is logged when linking the program: "Internal error compiling shader with Metal backend. Please submit this shader, or website as a bug to https://bugs.webkit.org".

An alternate version of the vertex shader with the usage of the comma operator in `main` replaced with a semicolon is included (commented out) in the repro code above. This change to the vertex shader causes the shader to compile/link without error.
Comment 1 Radar WebKit Bug Importer 2021-07-06 15:13:10 PDT
<rdar://problem/80233657>
Comment 2 Kyle Piddington 2021-07-06 16:19:40 PDT
Created attachment 432985 [details]
Patch
Comment 3 EWS Watchlist 2021-07-06 16:20:54 PDT
Note that there are important steps to take when updating ANGLE. See https://trac.webkit.org/wiki/UpdatingANGLE
Comment 4 Dean Jackson 2021-07-06 18:14:27 PDT
Comment on attachment 432985 [details]
Patch

Can we include a test?
Comment 5 Kyle Piddington 2021-07-07 12:03:30 PDT
Created attachment 433058 [details]
Patch for landing
Comment 6 EWS 2021-07-07 12:35:49 PDT
Committed r279656 (239469@main): <https://commits.webkit.org/239469@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 433058 [details].
Comment 7 Kenneth Russell 2021-07-09 14:25:00 PDT
Note: filed https://github.com/KhronosGroup/WebGL/issues/3299 about upstreaming this test case to the WebGL conformance suite.