Bug 223316

Summary: webgl/1.0.x/conformance/glsl/bugs/vector-matrix-constructor-scalarization.html fails
Product: WebKit Reporter: Kimmo Kinnunen <kkinnunen>
Component: WebGLAssignee: Kyle Piddington <kpiddington>
Status: RESOLVED CONFIGURATION CHANGED    
Severity: Normal CC: dino, gman, kbr, kkinnunen, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: Other   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on: 229958    
Bug Blocks: 222812, 228996    
Attachments:
Description Flags
msl and errors none

Description Kimmo Kinnunen 2021-03-16 23:34:30 PDT
webgl/1.0.4/conformance/glsl/bugs/vector-matrix-constructor-scalarization.html fails
Comment 1 Kimmo Kinnunen 2021-03-17 01:22:22 PDT
https://www.khronos.org/registry/webgl/sdk/tests/conformance/glsl/bugs/vector-matrix-constructor-scalarization.html?webglVersion=1&quiet=0&quick=1



Vector and matrix constructor scalarization workaround (SH_SCALARIZE_VEC_AND_MAT_CONSTRUCTOR_ARGS) caused bugs

On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".


Regression test for crbug.com/1165751
PASS WebGL context creation succeeded
Ensure that shader translation isn't broken by the vector and matrix constructor scalarization workaround
vertex shader
vertex shader translated for driver
fragment_shader
fragment_shader translated for driver
FAIL should be 5,20,0,255
at (0, 192) expected: 5,20,0,255 was 20,20,0,255
FAIL should be 45,165,0,255
at (4, 192) expected: 45,165,0,255 was 165,165,0,255
FAIL should be 83,247,0,255
at (8, 192) expected: 83,247,0,255 was 247,247,0,255
FAIL should be 120,237,0,255
at (12, 192) expected: 120,237,0,255 was 237,237,0,255
FAIL should be 153,136,0,255
at (16, 192) expected: 153,136,0,255 was 136,136,0,255
FAIL should be 183,0,0,255
at (20, 192) expected: 183,0,0,255 was 0,0,0,255
FAIL should be 208,0,0,255
at (24, 192) expected: 208,0,0,255 was 0,0,0,255
FAIL should be 229,0,0,255
at (28, 192) expected: 229,0,0,255 was 0,0,0,255
FAIL should be 243,0,0,255
at (32, 192) expected: 243,0,0,255 was 0,0,0,255
FAIL should be 252,0,0,255
at (36, 192) expected: 252,0,0,255 was 0,0,0,255
FAIL should be 255,11,0,255
at (40, 192) expected: 255,11,0,255 was 11,11,0,255
FAIL should be 251,158,0,255
at (44, 192) expected: 251,158,0,255 was 158,158,0,255
PASS should be 242,245,0,255
FAIL should be 226,240,0,255
at (52, 192) expected: 226,240,0,255 was 240,240,0,255
FAIL should be 205,143,0,255
at (56, 192) expected: 205,143,0,255 was 143,143,0,255
FAIL should be 179,0,0,255
at (60, 192) expected: 179,0,0,255 was 0,0,0,255
FAIL should be 149,0,0,255
at (64, 192) expected: 149,0,0,255 was 0,0,0,255
FAIL should be 114,0,0,255
at (68, 192) expected: 114,0,0,255 was 0,0,0,255
FAIL should be 78,0,0,255
at (72, 192) expected: 78,0,0,255 was 0,0,0,255
FAIL should be 39,0,0,255
at (76, 192) expected: 39,0,0,255 was 0,0,0,255
PASS should be 0,3,0,255
FAIL should be 0,152,0,255
at (84, 192) expected: 0,152,0,255 was 152,152,0,255
FAIL should be 0,243,0,255
at (88, 192) expected: 0,243,0,255 was 243,243,0,255
FAIL should be 0,242,0,255
at (92, 192) expected: 0,242,0,255 was 242,242,0,255
FAIL should be 0,150,0,255
at (96, 192) expected: 0,150,0,255 was 150,150,0,255
PASS should be 0,1,0,255
PASS should be 0,0,0,255
PASS should be 0,0,0,255
PASS should be 0,0,0,255
PASS should be 0,0,0,255
PASS should be 0,0,0,255
FAIL should be 0,145,0,255
at (124, 192) expected: 0,145,0,255 was 145,145,0,255
FAIL should be 0,240,0,255
at (128, 192) expected: 0,240,0,255 was 240,240,0,255
FAIL should be 0,245,0,255
at (132, 192) expected: 0,245,0,255 was 245,245,0,255
FAIL should be 0,157,0,255
at (136, 192) expected: 0,157,0,255 was 157,157,0,255
FAIL should be 0,10,0,255
at (140, 192) expected: 0,10,0,255 was 10,10,0,255
PASS should be 0,0,0,255
PASS should be 0,0,0,255
PASS should be 0,0,0,255
PASS should be 0,0,0,255
PASS should be 0,0,0,255
FAIL should be 36,138,0,255
at (164, 192) expected: 36,138,0,255 was 138,138,0,255
FAIL should be 75,237,0,255
at (168, 192) expected: 75,237,0,255 was 237,237,0,255
FAIL should be 112,247,0,255
at (172, 192) expected: 112,247,0,255 was 247,247,0,255
FAIL should be 146,163,0,255
at (176, 192) expected: 146,163,0,255 was 163,163,0,255
FAIL should be 177,18,0,255
at (180, 192) expected: 177,18,0,255 was 18,18,0,255
FAIL should be 203,0,0,255
at (184, 192) expected: 203,0,0,255 was 0,0,0,255
FAIL should be 225,0,0,255
at (188, 192) expected: 225,0,0,255 was 0,0,0,255
FAIL should be 241,0,0,255
at (192, 192) expected: 241,0,0,255 was 0,0,0,255
FAIL should be 251,0,0,255
at (196, 192) expected: 251,0,0,255 was 0,0,0,255
FAIL should be 255,0,0,255
at (200, 192) expected: 255,0,0,255 was 0,0,0,255
FAIL should be 253,130,0,255
at (204, 192) expected: 253,130,0,255 was 130,130,0,255
FAIL should be 244,234,0,255
at (208, 192) expected: 244,234,0,255 was 234,234,0,255
FAIL should be 230,249,0,255
at (212, 192) expected: 230,249,0,255 was 249,249,0,255
FAIL should be 210,170,0,255
at (216, 192) expected: 210,170,0,255 was 170,170,0,255
FAIL should be 185,27,0,255
at (220, 192) expected: 185,27,0,255 was 27,27,0,255
FAIL should be 155,0,0,255
at (224, 192) expected: 155,0,0,255 was 0,0,0,255
FAIL should be 122,0,0,255
at (228, 192) expected: 122,0,0,255 was 0,0,0,255
FAIL should be 86,0,0,255
at (232, 192) expected: 86,0,0,255 was 0,0,0,255
FAIL should be 47,0,0,255
at (236, 192) expected: 47,0,0,255 was 0,0,0,255
PASS should be 8,0,0,255
FAIL should be 0,123,0,255
at (244, 192) expected: 0,123,0,255 was 123,123,0,255
FAIL should be 0,230,0,255
at (248, 192) expected: 0,230,0,255 was 230,230,0,255
FAIL should be 0,251,0,255
at (252, 192) expected: 0,251,0,255 was 251,251,0,255
Running compilation test
vertex shader
vertex shader translated for driver
fragment_shader
fragment_shader translated for driver
PASS Shader previously requiring SH_SCALARIZE_VEC_AND_MAT_CONSTRUCTOR_ARGS compiled successfully
PASS successfullyParsed is true

TEST COMPLETE
Comment 2 Kimmo Kinnunen 2021-03-17 01:37:28 PDT
*** Bug 223333 has been marked as a duplicate of this bug. ***
Comment 3 Kimmo Kinnunen 2021-03-17 01:45:47 PDT
At least macOS 11.3, iMacPro1,1, Radeon Pro Vega 56
Comment 4 Radar WebKit Bug Importer 2021-03-23 23:35:14 PDT
<rdar://problem/75772589>
Comment 5 Kimmo Kinnunen 2021-08-11 04:45:00 PDT
Created attachment 435334 [details]
msl and errors
Comment 6 Kimmo Kinnunen 2021-08-11 04:45:51 PDT
GLSL constructs something along the lines of:
 mat2(vec4(1))
Which gets translated to MSL:
 float2x2(float4(1))

.. which is not valid.

We need to add a cast operator and emit it?

see the attachments for the msl and errors.

GLSL:
precision mediump float;
varying vec2 vTexCoord;
float a = 0.;
#define A 0.
#define r(a)    mat2( cos( a + vec4(0,-1.5708,1.5708,0) ) )
vec2 c;
#define f(U,a)  ( c = (U) * r(a) , sin(10.*c.x) )
void main() {
    vec2 U = vTexCoord;
    gl_FragColor = U.y > .5
        ? vec4( f(U,a) , f(U*4.,a) , 0,1.0)   // top
        : vec4( f(U,A) , f(U*4.,A) , 0,1.0);  // bottom
}
Comment 7 Kimmo Kinnunen 2021-08-11 04:50:30 PDT
webkit-patch apply-from-bug 228996
git commit -a -m temporary

..then fix the issue.
Comment 8 Kimmo Kinnunen 2021-08-30 11:06:33 PDT
> We need to add a cast operator and emit it?

Turns out all 24038 mat constructor operators would need a cast operator each.
Maybe it would be better to fix the scalarization.

Upstream bugs:

https://bugs.chromium.org/p/angleproject/issues/detail?id=6306
https://bugs.chromium.org/p/angleproject/issues/detail?id=6341
https://bugs.chromium.org/p/angleproject/issues/detail?id=6340
Comment 9 Kenneth Russell 2021-08-30 17:15:08 PDT
Let's please discuss upstream on ANGLE's issue tracker. We've had fairly extensive discussions about this already with the ANGLE team on Slack (Kimmo, just added you to the thread) - I don't think we should reintroduce and fix the scalarization workaround, but instead lazily generate the needed constructors. Gregg from our team is already working on this, so let's not duplicate work.
Comment 10 Kenneth Russell 2021-09-02 16:52:11 PDT
Please note that Gregg's fixed this in the direct-to-Metal translator upstream in ANGLE in:

Conversions of one type to another (mat2x2->vec4) fail in direct metal backend
https://bugs.chromium.org/p/angleproject/issues/detail?id=6306

and specifically:

Convert constructors to function calls where needed.
https://chromium-review.googlesource.com/c/angle/angle/+/3134963

Would you consider cherry-picking this fix to allow the SH_SCALARIZE_VEC_AND_MAT_CONSTRUCTOR_ARGS workaround (Bug 228996) to be disabled in WebKit's copy of ANGLE?
Comment 11 Kimmo Kinnunen 2022-08-10 23:51:59 PDT
Fixed by ANGLE update a while ago that brought Gregg's fix.