From b39236bc0ff767e07651c087a9f2a0d36787d91a Mon Sep 17 00:00:00 2001 From: John Stiles Date: Fri, 20 Aug 2021 10:10:02 -0400 Subject: [PATCH] Add `floatBitsToInt` family of ES3 intrinsics to SkSL public ES3. These now have proper testing and compile-time optimization support. Change-Id: I7978161ec126e1c3096b9ca9dfbb2be7d8ea02f5 Bug: skia:12202 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/440859 Commit-Queue: John Stiles Commit-Queue: Brian Osman Auto-Submit: John Stiles Reviewed-by: Brian Osman --- resources/sksl/intrinsics/FloatBitsToInt.sksl | 21 +- .../sksl/intrinsics/FloatBitsToUint.sksl | 21 +- resources/sksl/intrinsics/IntBitsToFloat.sksl | 21 +- .../sksl/intrinsics/UintBitsToFloat.sksl | 21 +- .../generated/sksl_public.dehydrated.sksl | 1345 +++++++++-------- src/sksl/ir/SkSLFunctionCall.cpp | 28 + src/sksl/sksl_public.sksl | 8 +- tests/SkSLTest.cpp | 4 + tests/sksl/intrinsics/FloatBitsToInt.asm.frag | 144 +- tests/sksl/intrinsics/FloatBitsToInt.glsl | 11 +- tests/sksl/intrinsics/FloatBitsToInt.metal | 13 +- .../sksl/intrinsics/FloatBitsToUint.asm.frag | 144 +- tests/sksl/intrinsics/FloatBitsToUint.glsl | 11 +- tests/sksl/intrinsics/FloatBitsToUint.metal | 13 +- tests/sksl/intrinsics/IntBitsToFloat.asm.frag | 148 +- tests/sksl/intrinsics/IntBitsToFloat.glsl | 11 +- tests/sksl/intrinsics/IntBitsToFloat.metal | 13 +- .../sksl/intrinsics/UintBitsToFloat.asm.frag | 148 +- tests/sksl/intrinsics/UintBitsToFloat.glsl | 11 +- tests/sksl/intrinsics/UintBitsToFloat.metal | 13 +- 20 files changed, 1404 insertions(+), 745 deletions(-) diff --git a/resources/sksl/intrinsics/FloatBitsToInt.sksl b/resources/sksl/intrinsics/FloatBitsToInt.sksl index cf6cb3ac9c..12970f41a5 100644 --- a/resources/sksl/intrinsics/FloatBitsToInt.sksl +++ b/resources/sksl/intrinsics/FloatBitsToInt.sksl @@ -1 +1,20 @@ -uniform float a; void main() { sk_FragColor.x = half(floatBitsToInt(a)); } +uniform float testInput; +uniform float2x2 testMatrix2x2; +uniform half4 colorGreen, colorRed; + +half4 main(float2 coords) { + const float4 constVal = float4(-1, 0, 1, 2); + const int4 expectedA = int4(-0x40800000, 0x00000000, 0x3F800000, 0x40000000); + + float4 input = float4(testMatrix2x2) * float4(1, 1, -1, -1); + const int4 expectedB = int4(0x3F800000, 0x40000000, -0x3FC00000, -0x3F800000); + + return (floatBitsToInt(constVal.x) == expectedA.x && + floatBitsToInt(constVal.xy) == expectedA.xy && + floatBitsToInt(constVal.xyz) == expectedA.xyz && + floatBitsToInt(constVal.xyzw) == expectedA.xyzw && + floatBitsToInt(input.x) == expectedB.x && + floatBitsToInt(input.xy) == expectedB.xy && + floatBitsToInt(input.xyz) == expectedB.xyz && + floatBitsToInt(input.xyzw) == expectedB.xyzw) ? colorGreen : colorRed; +} diff --git a/resources/sksl/intrinsics/FloatBitsToUint.sksl b/resources/sksl/intrinsics/FloatBitsToUint.sksl index 94e3d1934f..294d49aac0 100644 --- a/resources/sksl/intrinsics/FloatBitsToUint.sksl +++ b/resources/sksl/intrinsics/FloatBitsToUint.sksl @@ -1 +1,20 @@ -uniform float a; void main() { sk_FragColor.x = half(floatBitsToUint(a)); } +uniform float testInput; +uniform float2x2 testMatrix2x2; +uniform half4 colorGreen, colorRed; + +half4 main(float2 coords) { + const float4 constVal = float4(-1, 0, 1, 2); + const uint4 expectedA = uint4(0xBF800000, 0x00000000, 0x3F800000, 0x40000000); + + float4 input = float4(testMatrix2x2) * float4(1, 1, -1, -1); + const uint4 expectedB = uint4(0x3F800000, 0x40000000, 0xC0400000, 0xC0800000); + + return (floatBitsToUint(constVal.x) == expectedA.x && + floatBitsToUint(constVal.xy) == expectedA.xy && + floatBitsToUint(constVal.xyz) == expectedA.xyz && + floatBitsToUint(constVal.xyzw) == expectedA.xyzw && + floatBitsToUint(input.x) == expectedB.x && + floatBitsToUint(input.xy) == expectedB.xy && + floatBitsToUint(input.xyz) == expectedB.xyz && + floatBitsToUint(input.xyzw) == expectedB.xyzw) ? colorGreen : colorRed; +} diff --git a/resources/sksl/intrinsics/IntBitsToFloat.sksl b/resources/sksl/intrinsics/IntBitsToFloat.sksl index e25b69536c..ddf3b56dae 100644 --- a/resources/sksl/intrinsics/IntBitsToFloat.sksl +++ b/resources/sksl/intrinsics/IntBitsToFloat.sksl @@ -1 +1,20 @@ -uniform int a; void main() { sk_FragColor.x = half(intBitsToFloat(a)); } +uniform float testInput; +uniform float2x2 testMatrix2x2; +uniform half4 colorGreen, colorRed; + +half4 main(float2 coords) { + const float4 constVal = float4(-1, 0, 1, 2); + const int4 expectedA = int4(-0x40800000, 0x00000000, 0x3F800000, 0x40000000); + + float4 input = float4(testMatrix2x2) * float4(1, 1, -1, -1); + int4 expectedB = int4(0x3F800000, 0x40000000, -0x3FC00000, -0x3F800000); + + return (constVal.x == intBitsToFloat(expectedA.x) && + constVal.xy == intBitsToFloat(expectedA.xy) && + constVal.xyz == intBitsToFloat(expectedA.xyz) && + constVal.xyzw == intBitsToFloat(expectedA.xyzw) && + input.x == intBitsToFloat(expectedB.x) && + input.xy == intBitsToFloat(expectedB.xy) && + input.xyz == intBitsToFloat(expectedB.xyz) && + input.xyzw == intBitsToFloat(expectedB.xyzw)) ? colorGreen : colorRed; +} diff --git a/resources/sksl/intrinsics/UintBitsToFloat.sksl b/resources/sksl/intrinsics/UintBitsToFloat.sksl index 90ac67be9f..d98bc91c12 100644 --- a/resources/sksl/intrinsics/UintBitsToFloat.sksl +++ b/resources/sksl/intrinsics/UintBitsToFloat.sksl @@ -1 +1,20 @@ -uniform uint a; void main() { sk_FragColor.x = half(uintBitsToFloat(a)); } +uniform float testInput; +uniform float2x2 testMatrix2x2; +uniform half4 colorGreen, colorRed; + +half4 main(float2 coords) { + const float4 constVal = float4(-1, 0, 1, 2); + const uint4 expectedA = uint4(0xBF800000, 0x00000000, 0x3F800000, 0x40000000); + + float4 input = float4(testMatrix2x2) * float4(1, 1, -1, -1); + uint4 expectedB = uint4(0x3F800000, 0x40000000, 0xC0400000, 0xC0800000); + + return (constVal.x == uintBitsToFloat(expectedA.x) && + constVal.xy == uintBitsToFloat(expectedA.xy) && + constVal.xyz == uintBitsToFloat(expectedA.xyz) && + constVal.xyzw == uintBitsToFloat(expectedA.xyzw) && + input.x == uintBitsToFloat(expectedB.x) && + input.xy == uintBitsToFloat(expectedB.xy) && + input.xyz == uintBitsToFloat(expectedB.xyz) && + input.xyzw == uintBitsToFloat(expectedB.xyzw)) ? colorGreen : colorRed; +} diff --git a/src/sksl/generated/sksl_public.dehydrated.sksl b/src/sksl/generated/sksl_public.dehydrated.sksl index 6589de8cfe..4191389de1 100644 --- a/src/sksl/generated/sksl_public.dehydrated.sksl +++ b/src/sksl/generated/sksl_public.dehydrated.sksl @@ -1,4 +1,4 @@ -static uint8_t SKSL_INCLUDE_sksl_public[] = {173,2, +static uint8_t SKSL_INCLUDE_sksl_public[] = {5,3, 7,100,101,103,114,101,101,115, 8,36,103,101,110,84,121,112,101, 7,114,97,100,105,97,110,115, @@ -47,6 +47,13 @@ static uint8_t SKSL_INCLUDE_sksl_public[] = {173,2, 5,101,100,103,101,48, 5,101,100,103,101,49, 10,115,109,111,111,116,104,115,116,101,112, +5,118,97,108,117,101, +14,102,108,111,97,116,66,105,116,115,84,111,73,110,116, +9,36,103,101,110,73,84,121,112,101, +15,102,108,111,97,116,66,105,116,115,84,111,85,105,110,116, +9,36,103,101,110,85,84,121,112,101, +14,105,110,116,66,105,116,115,84,111,70,108,111,97,116, +15,117,105,110,116,66,105,116,115,84,111,70,108,111,97,116, 6,108,101,110,103,116,104, 2,112,48, 2,112,49, @@ -103,7 +110,7 @@ static uint8_t SKSL_INCLUDE_sksl_public[] = {173,2, 1,112, 4,100,70,100,120, 4,100,70,100,121, -48,215,1, +48,223,1, 52,1,0, 17,2,0, 49,2,0,10,0,3, @@ -927,745 +934,773 @@ static uint8_t SKSL_INCLUDE_sksl_public[] = {173,2, 46,5,0, 46,10,1, 52,11,1, -17,55,0, +17,16,1, 46,2,0,3, 29,12,1, -17,16,1,1,11,1, -46,145,0, -52,13,1, -17,55,0, -46,5,0,3, -51,14,1,2, -46,12,1, +37, +16,0,16,0,0,22,1,1,11,1, +49,13,1,37,1, +52,14,1, +17,16,1, +46,2,0,3, 29,15,1, -17,16,1,1,13,1, -46,153,0, -46,15,1, -52,16,1, -17,23,1, -46,2,0,3, +37, +16,0,16,0,0,47,1,1,14,1, +49,16,1,63,1, 52,17,1, -17,26,1, -46,2,0,3, +17,16,1, +46,13,1,3, 29,18,1, -17,29,1,2,16,1,17,1, -46,145,0, +37, +16,0,16,0,0,73,1,1,17,1, +46,2,0, 52,19,1, -17,23,1, -46,5,0,3, -52,20,1, -17,26,1, -46,5,0,3, -51,21,1,2, -46,18,1, +17,16,1, +46,16,1,3, +29,20,1, +37, +16,0,16,0,0,88,1,1,19,1, +46,2,0, +52,21,1, +17,55,0, +46,2,0,3, 29,22,1, -17,29,1,2,19,1,20,1, -46,153,0, -46,22,1, +17,104,1,1,21,1, +46,145,0, 52,23,1, 17,55,0, -46,2,0,3, -52,24,1, -17,67,0, -46,2,0,3, +46,5,0,3, +51,24,1,2, +46,22,1, 29,25,1, -17,38,1,2,23,1,24,1, -46,145,0, -52,26,1, -17,55,0, -46,5,0,3, -52,27,1, -17,67,0, -46,5,0,3, -51,28,1,2, +17,104,1,1,23,1, +46,153,0, 46,25,1, -29,29,1, -17,38,1,2,26,1,27,1, -46,153,0, -46,29,1, -52,30,1, -17,55,0, -49,31,1,42,1,3, -52,32,1, -17,67,0, -46,31,1,3, -29,33,1, -17,49,1,2,30,1,32,1, -46,31,1, -52,34,1, -17,55,0, -49,35,1,55,1,3, -52,36,1, -17,67,0, -46,35,1,3, -51,37,1,2, -46,33,1, -29,38,1, -17,49,1,2,34,1,36,1, -46,35,1, -46,38,1, -52,39,1, -17,55,0, +52,26,1, +17,111,1, 46,2,0,3, -29,40,1, -17,61,1,1,39,1, -46,2,0, -52,41,1, -17,55,0, -46,5,0,3, -51,42,1,2, -46,40,1, -29,43,1, -17,61,1,1,41,1, -46,5,0, -46,43,1, -52,44,1, -17,71,1, +52,27,1, +17,114,1, 46,2,0,3, -52,45,1, -17,73,1, -46,2,0,3, -52,46,1, -17,75,1, -46,2,0,3, -29,47,1, -17,80,1,3,44,1,45,1,46,1, -46,2,0, -52,48,1, -17,71,1, -46,5,0,3, -52,49,1, -17,73,1, -46,5,0,3, -52,50,1, -17,75,1, -46,5,0,3, -51,51,1,2, -46,47,1, -29,52,1, -17,80,1,3,48,1,49,1,50,1, -46,5,0, -46,52,1, -52,53,1, -17,73,1, -46,2,0,3, -52,54,1, -17,71,1, -46,2,0,3, -29,55,1, -17,92,1,2,53,1,54,1, -46,2,0, -52,56,1, -17,73,1, -46,5,0,3, -52,57,1, -17,71,1, -46,5,0,3, -51,58,1,2, -46,55,1, -29,59,1, -17,92,1,2,56,1,57,1, -46,5,0, -46,59,1, -52,60,1, -17,73,1, -46,2,0,3, -52,61,1, -17,71,1, -46,2,0,3, -52,62,1, -17,100,1, -46,145,0,3, -29,63,1, -17,104,1,3,60,1,61,1,62,1, -46,2,0, -52,64,1, -17,73,1, -46,5,0,3, -52,65,1, -17,71,1, -46,5,0,3, -52,66,1, -17,100,1, -46,153,0,3, -51,67,1,2, -46,63,1, -29,68,1, -17,104,1,3,64,1,65,1,66,1, -46,5,0, -46,68,1, -52,69,1, -17,55,0, -49,70,1,112,1,3, -52,71,1, -17,67,0, -46,70,1,3, -29,72,1, -17,123,1,2,69,1,71,1, -46,70,1, -52,73,1, -17,55,0, -49,74,1,138,1,3, -52,75,1, -17,67,0, -46,74,1,3, -51,76,1,2, -46,72,1, -29,77,1, -17,123,1,2,73,1,75,1, -46,74,1, -46,77,1, -52,78,1, -17,150,1, -46,70,1,3, -29,79,1, -37, -16,0,16,0,0,152,1,1,78,1, +29,28,1, +17,117,1,2,26,1,27,1, 46,145,0, -52,80,1, -17,150,1, -46,74,1,3, -51,81,1,2, -46,79,1, -29,82,1, -37, -16,0,16,0,0,152,1,1,80,1, +52,29,1, +17,111,1, +46,5,0,3, +52,30,1, +17,114,1, +46,5,0,3, +51,31,1,2, +46,28,1, +29,32,1, +17,117,1,2,29,1,30,1, 46,153,0, -46,82,1, +46,32,1, +52,33,1, +17,55,0, +46,2,0,3, +52,34,1, +17,67,0, +46,2,0,3, +29,35,1, +17,126,1,2,33,1,34,1, +46,145,0, +52,36,1, +17,55,0, +46,5,0,3, +52,37,1, +17,67,0, +46,5,0,3, +51,38,1,2, +46,35,1, +29,39,1, +17,126,1,2,36,1,37,1, +46,153,0, +46,39,1, +52,40,1, +17,55,0, +49,41,1,130,1,3, +52,42,1, +17,67,0, +46,41,1,3, +29,43,1, +17,137,1,2,40,1,42,1, +46,41,1, +52,44,1, +17,55,0, +49,45,1,143,1,3, +52,46,1, +17,67,0, +46,45,1,3, +51,47,1,2, +46,43,1, +29,48,1, +17,137,1,2,44,1,46,1, +46,45,1, +46,48,1, +52,49,1, +17,55,0, +46,2,0,3, +29,50,1, +17,149,1,1,49,1, +46,2,0, +52,51,1, +17,55,0, +46,5,0,3, +51,52,1,2, +46,50,1, +29,53,1, +17,149,1,1,51,1, +46,5,0, +46,53,1, +52,54,1, +17,159,1, +46,2,0,3, +52,55,1, +17,161,1, +46,2,0,3, +52,56,1, +17,163,1, +46,2,0,3, +29,57,1, +17,168,1,3,54,1,55,1,56,1, +46,2,0, +52,58,1, +17,159,1, +46,5,0,3, +52,59,1, +17,161,1, +46,5,0,3, +52,60,1, +17,163,1, +46,5,0,3, +51,61,1,2, +46,57,1, +29,62,1, +17,168,1,3,58,1,59,1,60,1, +46,5,0, +46,62,1, +52,63,1, +17,161,1, +46,2,0,3, +52,64,1, +17,159,1, +46,2,0,3, +29,65,1, +17,180,1,2,63,1,64,1, +46,2,0, +52,66,1, +17,161,1, +46,5,0,3, +52,67,1, +17,159,1, +46,5,0,3, +51,68,1,2, +46,65,1, +29,69,1, +17,180,1,2,66,1,67,1, +46,5,0, +46,69,1, +52,70,1, +17,161,1, +46,2,0,3, +52,71,1, +17,159,1, +46,2,0,3, +52,72,1, +17,188,1, +46,145,0,3, +29,73,1, +17,192,1,3,70,1,71,1,72,1, +46,2,0, +52,74,1, +17,161,1, +46,5,0,3, +52,75,1, +17,159,1, +46,5,0,3, +52,76,1, +17,188,1, +46,153,0,3, +51,77,1,2, +46,73,1, +29,78,1, +17,192,1,3,74,1,75,1,76,1, +46,5,0, +46,78,1, +52,79,1, +17,55,0, +49,80,1,200,1,3, +52,81,1, +17,67,0, +46,80,1,3, +29,82,1, +17,211,1,2,79,1,81,1, +46,80,1, 52,83,1, -17,150,1, -46,70,1,3, -29,84,1, -37, -16,0,16,0,0,164,1,1,83,1, -46,70,1, +17,55,0, +49,84,1,226,1,3, 52,85,1, -17,150,1, -46,74,1,3, +17,67,0, +46,84,1,3, 51,86,1,2, -46,84,1, +46,82,1, 29,87,1, -37, -16,0,16,0,0,164,1,1,85,1, -46,74,1, +17,211,1,2,83,1,85,1, +46,84,1, 46,87,1, 52,88,1, -17,150,1, -49,89,1,174,1,3, -51,90,1,3, -46,84,1, -46,87,1, -29,91,1, +17,238,1, +46,80,1,3, +29,89,1, 37, -16,0,16,0,0,164,1,1,88,1, -49,92,1,183,1, -46,91,1, +16,0,16,0,0,240,1,1,88,1, +46,145,0, +52,90,1, +17,238,1, +46,84,1,3, +51,91,1,2, +46,89,1, +29,92,1, +37, +16,0,16,0,0,240,1,1,90,1, +46,153,0, +46,92,1, 52,93,1, -17,150,1, -49,94,1,192,1,3, -51,95,1,4, -46,84,1, -46,87,1, -46,91,1, -29,96,1, +17,238,1, +46,80,1,3, +29,94,1, 37, -16,0,16,0,0,164,1,1,93,1, -49,97,1,200,1, -46,96,1, -52,98,1, -17,150,1, -49,99,1,208,1,3, -51,100,1,5, +16,0,16,0,0,252,1,1,93,1, +46,80,1, +52,95,1, +17,238,1, +46,84,1,3, +51,96,1,2, +46,94,1, +29,97,1, +37, +16,0,16,0,0,252,1,1,95,1, 46,84,1, -46,87,1, -46,91,1, -46,96,1, +46,97,1, +52,98,1, +17,238,1, +49,99,1,6,2,3, +51,100,1,3, +46,94,1, +46,97,1, 29,101,1, 37, -16,0,16,0,0,164,1,1,98,1, -49,102,1,217,1, +16,0,16,0,0,252,1,1,98,1, +49,102,1,15,2, 46,101,1, 52,103,1, -17,150,1, -49,104,1,226,1,3, -51,105,1,6, -46,84,1, -46,87,1, -46,91,1, -46,96,1, +17,238,1, +49,104,1,24,2,3, +51,105,1,4, +46,94,1, +46,97,1, 46,101,1, 29,106,1, 37, -16,0,16,0,0,164,1,1,103,1, -49,107,1,234,1, +16,0,16,0,0,252,1,1,103,1, +49,107,1,32,2, 46,106,1, 52,108,1, -17,150,1, -46,92,1,3, -51,109,1,7, -46,84,1, -46,87,1, -46,91,1, -46,96,1, -46,101,1, -46,106,1, -29,110,1, -37, -16,0,16,0,0,164,1,1,108,1, -46,89,1, -46,110,1, -52,111,1, -17,150,1, -46,97,1,3, -51,112,1,8, -46,84,1, -46,87,1, -46,91,1, -46,96,1, -46,101,1, -46,106,1, -46,110,1, -29,113,1, -37, -16,0,16,0,0,164,1,1,111,1, +17,238,1, +49,109,1,40,2,3, +51,110,1,5, 46,94,1, -46,113,1, -52,114,1, -17,150,1, -49,115,1,242,1,3, -51,116,1,9, -46,84,1, -46,87,1, -46,91,1, -46,96,1, +46,97,1, 46,101,1, 46,106,1, -46,110,1, -46,113,1, -29,117,1, +29,111,1, 37, -16,0,16,0,0,164,1,1,114,1, -49,118,1,251,1, -46,117,1, -52,119,1, -17,150,1, -49,120,1,4,2,3, -51,121,1,10, -46,84,1, -46,87,1, -46,91,1, -46,96,1, +16,0,16,0,0,252,1,1,108,1, +49,112,1,49,2, +46,111,1, +52,113,1, +17,238,1, +49,114,1,58,2,3, +51,115,1,6, +46,94,1, +46,97,1, 46,101,1, 46,106,1, -46,110,1, -46,113,1, -46,117,1, -29,122,1, +46,111,1, +29,116,1, 37, -16,0,16,0,0,164,1,1,119,1, -49,123,1,12,2, -46,122,1, -52,124,1, -17,150,1, +16,0,16,0,0,252,1,1,113,1, +49,117,1,66,2, +46,116,1, +52,118,1, +17,238,1, 46,102,1,3, -51,125,1,11, -46,84,1, -46,87,1, -46,91,1, -46,96,1, +51,119,1,7, +46,94,1, +46,97,1, 46,101,1, 46,106,1, -46,110,1, -46,113,1, -46,117,1, -46,122,1, -29,126,1, +46,111,1, +46,116,1, +29,120,1, 37, -16,0,16,0,0,164,1,1,124,1, +16,0,16,0,0,252,1,1,118,1, 46,99,1, -46,126,1, -52,127,1, -17,150,1, +46,120,1, +52,121,1, +17,238,1, 46,107,1,3, -51,128,1,12, -46,84,1, -46,87,1, -46,91,1, -46,96,1, +51,122,1,8, +46,94,1, +46,97,1, 46,101,1, 46,106,1, -46,110,1, -46,113,1, -46,117,1, -46,122,1, -46,126,1, -29,129,1, +46,111,1, +46,116,1, +46,120,1, +29,123,1, 37, -16,0,16,0,0,164,1,1,127,1, +16,0,16,0,0,252,1,1,121,1, 46,104,1, -46,129,1, -52,130,1, -17,150,1, -46,118,1,3, -51,131,1,13, -46,84,1, -46,87,1, -46,91,1, -46,96,1, +46,123,1, +52,124,1, +17,238,1, +49,125,1,74,2,3, +51,126,1,9, +46,94,1, +46,97,1, 46,101,1, 46,106,1, -46,110,1, -46,113,1, -46,117,1, -46,122,1, -46,126,1, -46,129,1, +46,111,1, +46,116,1, +46,120,1, +46,123,1, +29,127,1, +37, +16,0,16,0,0,252,1,1,124,1, +49,128,1,83,2, +46,127,1, +52,129,1, +17,238,1, +49,130,1,92,2,3, +51,131,1,10, +46,94,1, +46,97,1, +46,101,1, +46,106,1, +46,111,1, +46,116,1, +46,120,1, +46,123,1, +46,127,1, 29,132,1, 37, -16,0,16,0,0,164,1,1,130,1, -46,115,1, +16,0,16,0,0,252,1,1,129,1, +49,133,1,100,2, 46,132,1, -52,133,1, -17,150,1, -46,123,1,3, -51,134,1,14, -46,84,1, -46,87,1, -46,91,1, -46,96,1, +52,134,1, +17,238,1, +46,112,1,3, +51,135,1,11, +46,94,1, +46,97,1, 46,101,1, 46,106,1, -46,110,1, -46,113,1, -46,117,1, -46,122,1, -46,126,1, -46,129,1, -46,132,1, -29,135,1, -37, -16,0,16,0,0,164,1,1,133,1, +46,111,1, +46,116,1, 46,120,1, -46,135,1, -52,136,1, -17,150,1, -46,70,1,3, -29,137,1, -17,20,2,1,136,1, -46,70,1, -52,138,1, -17,150,1, -46,74,1,3, -51,139,1,2, -46,137,1, -29,140,1, -17,20,2,1,138,1, -46,74,1, -46,140,1, -52,141,1, -17,55,0, -49,142,1,28,2,3, +46,123,1, +46,127,1, +46,132,1, +29,136,1, +37, +16,0,16,0,0,252,1,1,134,1, +46,109,1, +46,136,1, +52,137,1, +17,238,1, +46,117,1,3, +51,138,1,12, +46,94,1, +46,97,1, +46,101,1, +46,106,1, +46,111,1, +46,116,1, +46,120,1, +46,123,1, +46,127,1, +46,132,1, +46,136,1, +29,139,1, +37, +16,0,16,0,0,252,1,1,137,1, +46,114,1, +46,139,1, +52,140,1, +17,238,1, +46,128,1,3, +51,141,1,13, +46,94,1, +46,97,1, +46,101,1, +46,106,1, +46,111,1, +46,116,1, +46,120,1, +46,123,1, +46,127,1, +46,132,1, +46,136,1, +46,139,1, +29,142,1, +37, +16,0,16,0,0,252,1,1,140,1, +46,125,1, +46,142,1, 52,143,1, -17,67,0, -46,142,1,3, -29,144,1, -17,33,2,2,141,1,143,1, -49,145,1,42,2, -52,146,1, -17,55,0, -49,147,1,48,2,3, -52,148,1, -17,67,0, -46,147,1,3, -51,149,1,2, -46,144,1, -29,150,1, -17,33,2,2,146,1,148,1, +17,238,1, +46,133,1,3, +51,144,1,14, +46,94,1, +46,97,1, +46,101,1, +46,106,1, +46,111,1, +46,116,1, +46,120,1, +46,123,1, +46,127,1, +46,132,1, +46,136,1, +46,139,1, +46,142,1, +29,145,1, +37, +16,0,16,0,0,252,1,1,143,1, +46,130,1, 46,145,1, +52,146,1, +17,238,1, +46,80,1,3, +29,147,1, +17,108,2,1,146,1, +46,80,1, +52,148,1, +17,238,1, +46,84,1,3, +51,149,1,2, +46,147,1, +29,150,1, +17,108,2,1,148,1, +46,84,1, 46,150,1, 52,151,1, 17,55,0, -49,152,1,54,2,3, +49,152,1,116,2,3, 52,153,1, 17,67,0, 46,152,1,3, -51,154,1,3, -46,144,1, -46,150,1, -29,155,1, -17,33,2,2,151,1,153,1, -46,145,1, -46,155,1, +29,154,1, +17,121,2,2,151,1,153,1, +49,155,1,130,2, 52,156,1, 17,55,0, -46,142,1,3, -52,157,1, +49,157,1,136,2,3, +52,158,1, 17,67,0, -46,142,1,3, -29,158,1, -17,60,2,2,156,1,157,1, -46,145,1, -52,159,1, +46,157,1,3, +51,159,1,2, +46,154,1, +29,160,1, +17,121,2,2,156,1,158,1, +46,155,1, +46,160,1, +52,161,1, 17,55,0, -46,147,1,3, -52,160,1, -17,67,0, -46,147,1,3, -51,161,1,2, -46,158,1, -29,162,1, -17,60,2,2,159,1,160,1, -46,145,1, -46,162,1, +49,162,1,142,2,3, 52,163,1, +17,67,0, +46,162,1,3, +51,164,1,3, +46,154,1, +46,160,1, +29,165,1, +17,121,2,2,161,1,163,1, +46,155,1, +46,165,1, +52,166,1, 17,55,0, 46,152,1,3, -52,164,1, -17,67,0, -46,152,1,3, -51,165,1,3, -46,158,1, -46,162,1, -29,166,1, -17,60,2,2,163,1,164,1, -46,145,1, -46,166,1, 52,167,1, -17,55,0, -46,142,1,3, -52,168,1, 17,67,0, -46,142,1,3, -29,169,1, -17,74,2,2,167,1,168,1, -46,145,1, +46,152,1,3, +29,168,1, +17,148,2,2,166,1,167,1, +46,155,1, +52,169,1, +17,55,0, +46,157,1,3, 52,170,1, -17,55,0, -46,147,1,3, -52,171,1, 17,67,0, -46,147,1,3, -51,172,1,2, -46,169,1, -29,173,1, -17,74,2,2,170,1,171,1, -46,145,1, -46,173,1, +46,157,1,3, +51,171,1,2, +46,168,1, +29,172,1, +17,148,2,2,169,1,170,1, +46,155,1, +46,172,1, +52,173,1, +17,55,0, +46,162,1,3, 52,174,1, +17,67,0, +46,162,1,3, +51,175,1,3, +46,168,1, +46,172,1, +29,176,1, +17,148,2,2,173,1,174,1, +46,155,1, +46,176,1, +52,177,1, 17,55,0, 46,152,1,3, -52,175,1, -17,67,0, -46,152,1,3, -51,176,1,3, -46,169,1, -46,173,1, -29,177,1, -17,74,2,2,174,1,175,1, -46,145,1, -46,177,1, 52,178,1, -17,55,0, -46,142,1,3, -52,179,1, 17,67,0, -46,142,1,3, -29,180,1, -17,86,2,2,178,1,179,1, -46,145,1, +46,152,1,3, +29,179,1, +17,162,2,2,177,1,178,1, +46,155,1, +52,180,1, +17,55,0, +46,157,1,3, 52,181,1, -17,55,0, -46,147,1,3, -52,182,1, 17,67,0, -46,147,1,3, -51,183,1,2, -46,180,1, -29,184,1, -17,86,2,2,181,1,182,1, -46,145,1, -46,184,1, +46,157,1,3, +51,182,1,2, +46,179,1, +29,183,1, +17,162,2,2,180,1,181,1, +46,155,1, +46,183,1, +52,184,1, +17,55,0, +46,162,1,3, 52,185,1, +17,67,0, +46,162,1,3, +51,186,1,3, +46,179,1, +46,183,1, +29,187,1, +17,162,2,2,184,1,185,1, +46,155,1, +46,187,1, +52,188,1, 17,55,0, 46,152,1,3, -52,186,1, -17,67,0, -46,152,1,3, -51,187,1,3, -46,180,1, -46,184,1, -29,188,1, -17,86,2,2,185,1,186,1, -46,145,1, -46,188,1, 52,189,1, -17,55,0, -46,142,1,3, -52,190,1, 17,67,0, -46,142,1,3, -29,191,1, -17,103,2,2,189,1,190,1, -46,145,1, +46,152,1,3, +29,190,1, +17,174,2,2,188,1,189,1, +46,155,1, +52,191,1, +17,55,0, +46,157,1,3, 52,192,1, -17,55,0, -46,147,1,3, -52,193,1, 17,67,0, -46,147,1,3, -51,194,1,2, -46,191,1, -29,195,1, -17,103,2,2,192,1,193,1, -46,145,1, -46,195,1, +46,157,1,3, +51,193,1,2, +46,190,1, +29,194,1, +17,174,2,2,191,1,192,1, +46,155,1, +46,194,1, +52,195,1, +17,55,0, +46,162,1,3, 52,196,1, +17,67,0, +46,162,1,3, +51,197,1,3, +46,190,1, +46,194,1, +29,198,1, +17,174,2,2,195,1,196,1, +46,155,1, +46,198,1, +52,199,1, 17,55,0, 46,152,1,3, -52,197,1, -17,67,0, -46,152,1,3, -51,198,1,3, -46,191,1, -46,195,1, -29,199,1, -17,103,2,2,196,1,197,1, -46,145,1, -46,199,1, 52,200,1, -17,55,0, -46,145,1,3, -52,201,1, 17,67,0, -46,145,1,3, -51,202,1,4, -46,191,1, -46,195,1, -46,199,1, -29,203,1, -17,103,2,2,200,1,201,1, -46,145,1, -46,203,1, -52,204,1, +46,152,1,3, +29,201,1, +17,191,2,2,199,1,200,1, +46,155,1, +52,202,1, 17,55,0, -46,142,1,3, -52,205,1, +46,157,1,3, +52,203,1, 17,67,0, -46,142,1,3, -29,206,1, -17,109,2,2,204,1,205,1, -46,145,1, +46,157,1,3, +51,204,1,2, +46,201,1, +29,205,1, +17,191,2,2,202,1,203,1, +46,155,1, +46,205,1, +52,206,1, +17,55,0, +46,162,1,3, 52,207,1, -17,55,0, -46,147,1,3, -52,208,1, 17,67,0, -46,147,1,3, -51,209,1,2, -46,206,1, -29,210,1, -17,109,2,2,207,1,208,1, -46,145,1, -46,210,1, +46,162,1,3, +51,208,1,3, +46,201,1, +46,205,1, +29,209,1, +17,191,2,2,206,1,207,1, +46,155,1, +46,209,1, +52,210,1, +17,55,0, +46,155,1,3, 52,211,1, +17,67,0, +46,155,1,3, +51,212,1,4, +46,201,1, +46,205,1, +46,209,1, +29,213,1, +17,191,2,2,210,1,211,1, +46,155,1, +46,213,1, +52,214,1, 17,55,0, 46,152,1,3, -52,212,1, -17,67,0, -46,152,1,3, -51,213,1,3, -46,206,1, -46,210,1, -29,214,1, -17,109,2,2,211,1,212,1, -46,145,1, -46,214,1, 52,215,1, -17,55,0, -46,145,1,3, -52,216,1, 17,67,0, -46,145,1,3, -51,217,1,4, -46,206,1, -46,210,1, -46,214,1, -29,218,1, -17,109,2,2,215,1,216,1, -46,145,1, -46,218,1, -52,219,1, +46,152,1,3, +29,216,1, +17,197,2,2,214,1,215,1, +46,155,1, +52,217,1, 17,55,0, -46,145,1,3, +46,157,1,3, +52,218,1, +17,67,0, +46,157,1,3, +51,219,1,2, +46,216,1, 29,220,1, -17,118,2,1,219,1, -49,221,1,122,2, +17,197,2,2,217,1,218,1, +46,155,1, +46,220,1, +52,221,1, +17,55,0, +46,162,1,3, 52,222,1, +17,67,0, +46,162,1,3, +51,223,1,3, +46,216,1, +46,220,1, +29,224,1, +17,197,2,2,221,1,222,1, +46,155,1, +46,224,1, +52,225,1, 17,55,0, -46,145,1,3, -29,223,1, -17,127,2,1,222,1, -46,221,1, -52,224,1, -17,55,0, -46,145,1,3, -29,225,1, -17,131,2,1,224,1, -46,145,1, +46,155,1,3, 52,226,1, -17,135,2, -49,227,1,141,2,3, +17,67,0, +46,155,1,3, +51,227,1,4, +46,216,1, +46,220,1, +46,224,1, 29,228,1, -17,147,2,1,226,1, -46,227,1, -52,229,1, -17,135,2, -49,230,1,156,2,3, -51,231,1,2, +17,197,2,2,225,1,226,1, +46,155,1, 46,228,1, -29,232,1, -17,147,2,1,229,1, -46,230,1, -46,232,1, -52,233,1, -17,163,2, -46,2,0,3, -29,234,1, -37, -16,0,16,0,0,165,2,1,233,1, -46,2,0, -52,235,1, -17,163,2, -46,2,0,3, -29,236,1, -37, -16,0,16,0,0,170,2,1,235,1, -46,2,0, -52,237,1, -17,163,2, -46,5,0,3, -51,238,1,2, -46,234,1, -29,239,1, -37, -16,0,16,0,0,165,2,1,237,1, -46,5,0, -46,239,1, -52,240,1, -17,163,2, -46,5,0,3, +52,229,1, +17,55,0, +46,155,1,3, +29,230,1, +17,206,2,1,229,1, +49,231,1,210,2, +52,232,1, +17,55,0, +46,155,1,3, +29,233,1, +17,215,2,1,232,1, +46,231,1, +52,234,1, +17,55,0, +46,155,1,3, +29,235,1, +17,219,2,1,234,1, +46,155,1, +52,236,1, +17,223,2, +49,237,1,229,2,3, +29,238,1, +17,235,2,1,236,1, +46,237,1, +52,239,1, +17,223,2, +49,240,1,244,2,3, 51,241,1,2, -46,236,1, +46,238,1, 29,242,1, +17,235,2,1,239,1, +46,240,1, +46,242,1, +52,243,1, +17,251,2, +46,2,0,3, +29,244,1, 37, -16,0,16,0,0,170,2,1,240,1, +16,0,16,0,0,253,2,1,243,1, +46,2,0, +52,245,1, +17,251,2, +46,2,0,3, +29,246,1, +37, +16,0,16,0,0,2,3,1,245,1, +46,2,0, +52,247,1, +17,251,2, +46,5,0,3, +51,248,1,2, +46,244,1, +29,249,1, +37, +16,0,16,0,0,253,2,1,247,1, 46,5,0, -46,242,1,58,0, +46,249,1, +52,250,1, +17,251,2, +46,5,0,3, +51,251,1,2, +46,246,1, +29,252,1, +37, +16,0,16,0,0,2,3,1,250,1, +46,5,0, +46,252,1,62,0, 118,0, 33,0, 71,0, -197,1, -195,1, +205,1, +203,1, 28,0, 66,0, 46,0, @@ -1674,40 +1709,43 @@ static uint8_t SKSL_INCLUDE_sksl_public[] = {173,2, 202,0, 18,0, 56,0, -30,1, -210,1, -213,1, +38,1, +218,1, +221,1, 8,0, -72,1, -16,1, -23,1, -177,1, +80,1, +24,1, +31,1, +185,1, 88,0, 98,0, -44,1, +52,1, +7,1, +9,1, 128,0, 138,0, -151,1, -162,1, -118,1, +159,1, +170,1, +11,1, +126,1, 113,0, -9,1, -129,1, -140,1, +17,1, +137,1, +148,1, 93,0, 103,0, -67,1, +75,1, 183,0, 168,0, 226,0, 153,0, -35,1, -199,1, -192,1, +43,1, +207,1, +200,1, 83,0, 3,0, -51,1, -60,1, +59,1, +68,1, 207,0, 123,0, 13,0, @@ -1717,42 +1755,43 @@ static uint8_t SKSL_INCLUDE_sksl_public[] = {173,2, 241,0, 23,0, 61,0, -113,1, -203,1, +121,1, +13,1, +211,1, 20, -28,228,1, +28,238,1, 2, 48,0,0,0,0,1, 40, 8, -46,227,1,2, +46,237,1,2, 1, 45, -55,226,1,0,3,0,1,2,50, +55,236,1,0,3,0,1,2,50, 27, 46,153,0,185,0,2, 45, -55,226,1,0,1,3, +55,236,1,0,1,3, 25, 46,153,0,23,183,209,56, 45, -55,226,1,0,1,3,1,0, -28,232,1, +55,236,1,0,1,3,1,0, +28,242,1, 2, 48,0,0,0,0,1, 40, 8, -46,230,1,2, +46,240,1,2, 1, 45, -55,229,1,0,3,0,1,2,50, +55,239,1,0,3,0,1,2,50, 27, 46,145,0,177,0,2, 45, -55,229,1,0,1,3, +55,239,1,0,1,3, 25, 46,145,0,23,183,209,56, 45, -55,229,1,0,1,3,1,0, +55,239,1,0,1,3,1,0, 21,}; static constexpr size_t SKSL_INCLUDE_sksl_public_LENGTH = sizeof(SKSL_INCLUDE_sksl_public); diff --git a/src/sksl/ir/SkSLFunctionCall.cpp b/src/sksl/ir/SkSLFunctionCall.cpp index 102a5a48c3..20a8770f77 100644 --- a/src/sksl/ir/SkSLFunctionCall.cpp +++ b/src/sksl/ir/SkSLFunctionCall.cpp @@ -351,6 +351,18 @@ static std::unique_ptr evaluate_3_way_intrinsic(const Context& conte arguments[2].get(), returnType, eval); } +template +static double pun_value(double val) { + // Interpret `val` as a value of type T1. + static_assert(sizeof(T1) == sizeof(T2)); + T1 inputValue = (T1)val; + // Reinterpret those bits as a value of type T2. + T2 outputValue; + memcpy(&outputValue, &inputValue, sizeof(T2)); + // Return the value-of-type-T2 as a double. (Non-finite values will prohibit optimization.) + return (double)outputValue; +} + // Helper functions for optimizing all of our intrinsics. namespace Intrinsics { namespace { @@ -419,6 +431,10 @@ double evaluate_cosh(double a, double, double) { return std::cosh(a); } double evaluate_tanh(double a, double, double) { return std::tanh(a); } double evaluate_trunc(double a, double, double) { return std::trunc(a); } double evaluate_round(double a, double, double) { return std::round(a / 2) * 2; } +double evaluate_floatBitsToInt(double a, double, double) { return pun_value (a); } +double evaluate_floatBitsToUint(double a, double, double) { return pun_value(a); } +double evaluate_intBitsToFloat(double a, double, double) { return pun_value(a); } +double evaluate_uintBitsToFloat(double a, double, double) { return pun_value(a); } } // namespace } // namespace Intrinsics @@ -741,6 +757,18 @@ static std::unique_ptr optimize_intrinsic_call(const Context& contex case k_roundEven_IntrinsicKind: // and is allowed to behave identically to `roundEven`. return evaluate_intrinsic(context, arguments, returnType, Intrinsics::evaluate_round); + case k_floatBitsToInt_IntrinsicKind: + return evaluate_intrinsic(context, arguments, returnType, + Intrinsics::evaluate_floatBitsToInt); + case k_floatBitsToUint_IntrinsicKind: + return evaluate_intrinsic(context, arguments, returnType, + Intrinsics::evaluate_floatBitsToUint); + case k_intBitsToFloat_IntrinsicKind: + return evaluate_intrinsic(context, arguments, returnType, + Intrinsics::evaluate_intBitsToFloat); + case k_uintBitsToFloat_IntrinsicKind: + return evaluate_intrinsic(context, arguments, returnType, + Intrinsics::evaluate_uintBitsToFloat); default: return nullptr; } diff --git a/src/sksl/sksl_public.sksl b/src/sksl/sksl_public.sksl index 77f539a24d..7300864f5c 100644 --- a/src/sksl/sksl_public.sksl +++ b/src/sksl/sksl_public.sksl @@ -3,7 +3,6 @@ // See "The OpenGL ES Shading Language, Section 8" // 8.1 : Angle and Trigonometry Functions (Version 1.0) - $genType radians($genType degrees); $genHType radians($genHType degrees); $genType degrees($genType radians); @@ -26,7 +25,6 @@ $genType atan($genType y_over_x); $genHType atan($genHType y_over_x); // 8.1 : Angle and Trigonometry Functions (Version 3.0) - $es3 $genType sinh($genType x); $es3 $genHType sinh($genHType x); $es3 $genType cosh($genType x); @@ -100,6 +98,12 @@ $genType smoothstep(float edge0, float edge1, $genType x); $genHType smoothstep($genHType edge0, $genHType edge1, $genHType x); $genHType smoothstep(half edge0, half edge1, $genHType x); +// 8.3 : Common Functions (Version 3.0) +$es3 $genIType floatBitsToInt ($genType value); +$es3 $genUType floatBitsToUint($genType value); +$es3 $genType intBitsToFloat ($genIType value); +$es3 $genType uintBitsToFloat($genUType value); + // 8.4 : Geometric Functions float length($genType x); half length($genHType x); diff --git a/tests/SkSLTest.cpp b/tests/SkSLTest.cpp index 71ce98ffe2..4a97da8d0f 100644 --- a/tests/SkSLTest.cpp +++ b/tests/SkSLTest.cpp @@ -211,6 +211,10 @@ SKSL_TEST(SkSLIntrinsicCeil, "intrinsics/Ceil.sksl") SKSL_TEST_ES3(SkSLIntrinsicDeterminant, "intrinsics/Determinant.sksl") SKSL_TEST_ES3(SkSLIntrinsicDFdx, "intrinsics/DFdx.sksl") SKSL_TEST_ES3(SkSLIntrinsicDFdy, "intrinsics/DFdy.sksl") +SKSL_TEST_ES3(SkSLIntrinsicFloatBitsToInt, "intrinsics/FloatBitsToInt.sksl") +SKSL_TEST_ES3(SkSLIntrinsicFloatBitsToUint, "intrinsics/FloatBitsToUint.sksl") +SKSL_TEST_ES3(SkSLIntrinsicIntBitsToFloat, "intrinsics/IntBitsToFloat.sksl") +SKSL_TEST_ES3(SkSLIntrinsicUintBitsToFloat, "intrinsics/UintBitsToFloat.sksl") // TODO(johnstiles): test broken on Adreno 6xx + Vulkan //SKSL_TEST(SkSLIntrinsicClampFloat, "intrinsics/ClampFloat.sksl") SKSL_TEST(SkSLIntrinsicMaxFloat, "intrinsics/MaxFloat.sksl") diff --git a/tests/sksl/intrinsics/FloatBitsToInt.asm.frag b/tests/sksl/intrinsics/FloatBitsToInt.asm.frag index 4b4faba8d1..d7bef78809 100644 --- a/tests/sksl/intrinsics/FloatBitsToInt.asm.frag +++ b/tests/sksl/intrinsics/FloatBitsToInt.asm.frag @@ -1,22 +1,37 @@ OpCapability Shader %1 = OpExtInstImport "GLSL.std.450" OpMemoryModel Logical GLSL450 -OpEntryPoint Fragment %main "main" %sk_FragColor %sk_Clockwise -OpExecutionMode %main OriginUpperLeft +OpEntryPoint Fragment %_entrypoint_v "_entrypoint" %sk_FragColor %sk_Clockwise +OpExecutionMode %_entrypoint_v OriginUpperLeft OpName %sk_FragColor "sk_FragColor" OpName %sk_Clockwise "sk_Clockwise" OpName %_UniformBuffer "_UniformBuffer" -OpMemberName %_UniformBuffer 0 "a" +OpMemberName %_UniformBuffer 0 "testInput" +OpMemberName %_UniformBuffer 1 "testMatrix2x2" +OpMemberName %_UniformBuffer 2 "colorGreen" +OpMemberName %_UniformBuffer 3 "colorRed" +OpName %_entrypoint_v "_entrypoint_v" OpName %main "main" +OpName %input "input" +OpName %expectedB "expectedB" OpDecorate %sk_FragColor RelaxedPrecision OpDecorate %sk_FragColor Location 0 OpDecorate %sk_FragColor Index 0 OpDecorate %sk_Clockwise BuiltIn FrontFacing OpMemberDecorate %_UniformBuffer 0 Offset 0 +OpMemberDecorate %_UniformBuffer 1 Offset 16 +OpMemberDecorate %_UniformBuffer 1 ColMajor +OpMemberDecorate %_UniformBuffer 1 MatrixStride 16 +OpMemberDecorate %_UniformBuffer 2 Offset 48 +OpMemberDecorate %_UniformBuffer 2 RelaxedPrecision +OpMemberDecorate %_UniformBuffer 3 Offset 64 +OpMemberDecorate %_UniformBuffer 3 RelaxedPrecision OpDecorate %_UniformBuffer Block OpDecorate %10 Binding 0 OpDecorate %10 DescriptorSet 0 -OpDecorate %22 RelaxedPrecision +OpDecorate %95 RelaxedPrecision +OpDecorate %98 RelaxedPrecision +OpDecorate %99 RelaxedPrecision %float = OpTypeFloat 32 %v4float = OpTypeVector %float 4 %_ptr_Output_v4float = OpTypePointer Output %v4float @@ -24,22 +39,117 @@ OpDecorate %22 RelaxedPrecision %bool = OpTypeBool %_ptr_Input_bool = OpTypePointer Input %bool %sk_Clockwise = OpVariable %_ptr_Input_bool Input -%_UniformBuffer = OpTypeStruct %float +%v2float = OpTypeVector %float 2 +%mat2v2float = OpTypeMatrix %v2float 2 +%_UniformBuffer = OpTypeStruct %float %mat2v2float %v4float %v4float %_ptr_Uniform__UniformBuffer = OpTypePointer Uniform %_UniformBuffer %10 = OpVariable %_ptr_Uniform__UniformBuffer Uniform %void = OpTypeVoid -%14 = OpTypeFunction %void -%_ptr_Uniform_float = OpTypePointer Uniform %float +%17 = OpTypeFunction %void +%float_0 = OpConstant %float 0 +%20 = OpConstantComposite %v2float %float_0 %float_0 +%_ptr_Function_v2float = OpTypePointer Function %v2float +%24 = OpTypeFunction %v4float %_ptr_Function_v2float +%_ptr_Function_v4float = OpTypePointer Function %v4float +%_ptr_Uniform_mat2v2float = OpTypePointer Uniform %mat2v2float %int = OpTypeInt 32 1 -%int_0 = OpConstant %int 0 -%_ptr_Output_float = OpTypePointer Output %float -%main = OpFunction %void None %14 -%15 = OpLabel -%17 = OpAccessChain %_ptr_Uniform_float %10 %int_0 -%21 = OpLoad %float %17 -%16 = OpBitcast %int %21 -%22 = OpConvertSToF %float %16 -%23 = OpAccessChain %_ptr_Output_float %sk_FragColor %int_0 -OpStore %23 %22 +%int_1 = OpConstant %int 1 +%float_1 = OpConstant %float 1 +%float_n1 = OpConstant %float -1 +%41 = OpConstantComposite %v4float %float_1 %float_1 %float_n1 %float_n1 +%v4int = OpTypeVector %int 4 +%_ptr_Function_v4int = OpTypePointer Function %v4int +%int_1065353216 = OpConstant %int 1065353216 +%int_1073741824 = OpConstant %int 1073741824 +%int_n1069547520 = OpConstant %int -1069547520 +%int_n1065353216 = OpConstant %int -1065353216 +%50 = OpConstantComposite %v4int %int_1065353216 %int_1073741824 %int_n1069547520 %int_n1065353216 +%false = OpConstantFalse %bool +%v2int = OpTypeVector %int 2 +%62 = OpConstantComposite %v2int %int_1065353216 %int_1073741824 +%v2bool = OpTypeVector %bool 2 +%v3float = OpTypeVector %float 3 +%v3int = OpTypeVector %int 3 +%74 = OpConstantComposite %v3int %int_1065353216 %int_1073741824 %int_n1069547520 +%v3bool = OpTypeVector %bool 3 +%v4bool = OpTypeVector %bool 4 +%_ptr_Uniform_v4float = OpTypePointer Uniform %v4float +%int_2 = OpConstant %int 2 +%int_3 = OpConstant %int 3 +%_entrypoint_v = OpFunction %void None %17 +%18 = OpLabel +%21 = OpVariable %_ptr_Function_v2float Function +OpStore %21 %20 +%23 = OpFunctionCall %v4float %main %21 +OpStore %sk_FragColor %23 OpReturn OpFunctionEnd +%main = OpFunction %v4float None %24 +%25 = OpFunctionParameter %_ptr_Function_v2float +%26 = OpLabel +%input = OpVariable %_ptr_Function_v4float Function +%expectedB = OpVariable %_ptr_Function_v4int Function +%88 = OpVariable %_ptr_Function_v4float Function +%29 = OpAccessChain %_ptr_Uniform_mat2v2float %10 %int_1 +%33 = OpLoad %mat2v2float %29 +%34 = OpCompositeExtract %float %33 0 0 +%35 = OpCompositeExtract %float %33 0 1 +%36 = OpCompositeExtract %float %33 1 0 +%37 = OpCompositeExtract %float %33 1 1 +%38 = OpCompositeConstruct %v4float %34 %35 %36 %37 +%42 = OpFMul %v4float %38 %41 +OpStore %input %42 +OpStore %expectedB %50 +%53 = OpLoad %v4float %input +%54 = OpCompositeExtract %float %53 0 +%52 = OpBitcast %int %54 +%55 = OpIEqual %bool %52 %int_1065353216 +OpSelectionMerge %57 None +OpBranchConditional %55 %56 %57 +%56 = OpLabel +%59 = OpLoad %v4float %input +%60 = OpVectorShuffle %v2float %59 %59 0 1 +%58 = OpBitcast %v2int %60 +%63 = OpIEqual %v2bool %58 %62 +%65 = OpAll %bool %63 +OpBranch %57 +%57 = OpLabel +%66 = OpPhi %bool %false %26 %65 %56 +OpSelectionMerge %68 None +OpBranchConditional %66 %67 %68 +%67 = OpLabel +%70 = OpLoad %v4float %input +%71 = OpVectorShuffle %v3float %70 %70 0 1 2 +%69 = OpBitcast %v3int %71 +%75 = OpIEqual %v3bool %69 %74 +%77 = OpAll %bool %75 +OpBranch %68 +%68 = OpLabel +%78 = OpPhi %bool %false %57 %77 %67 +OpSelectionMerge %80 None +OpBranchConditional %78 %79 %80 +%79 = OpLabel +%82 = OpLoad %v4float %input +%81 = OpBitcast %v4int %82 +%83 = OpLoad %v4int %expectedB +%84 = OpIEqual %v4bool %81 %83 +%86 = OpAll %bool %84 +OpBranch %80 +%80 = OpLabel +%87 = OpPhi %bool %false %68 %86 %79 +OpSelectionMerge %91 None +OpBranchConditional %87 %89 %90 +%89 = OpLabel +%92 = OpAccessChain %_ptr_Uniform_v4float %10 %int_2 +%95 = OpLoad %v4float %92 +OpStore %88 %95 +OpBranch %91 +%90 = OpLabel +%96 = OpAccessChain %_ptr_Uniform_v4float %10 %int_3 +%98 = OpLoad %v4float %96 +OpStore %88 %98 +OpBranch %91 +%91 = OpLabel +%99 = OpLoad %v4float %88 +OpReturnValue %99 +OpFunctionEnd diff --git a/tests/sksl/intrinsics/FloatBitsToInt.glsl b/tests/sksl/intrinsics/FloatBitsToInt.glsl index 10cda58e5a..0410c4365b 100644 --- a/tests/sksl/intrinsics/FloatBitsToInt.glsl +++ b/tests/sksl/intrinsics/FloatBitsToInt.glsl @@ -1,6 +1,11 @@ out vec4 sk_FragColor; -uniform float a; -void main() { - sk_FragColor.x = float(floatBitsToInt(a)); +uniform float testInput; +uniform mat2 testMatrix2x2; +uniform vec4 colorGreen; +uniform vec4 colorRed; +vec4 main() { + vec4 input = vec4(testMatrix2x2) * vec4(1.0, 1.0, -1.0, -1.0); + const ivec4 expectedB = ivec4(1065353216, 1073741824, -1069547520, -1065353216); + return ((floatBitsToInt(input.x) == 1065353216 && floatBitsToInt(input.xy) == ivec2(1065353216, 1073741824)) && floatBitsToInt(input.xyz) == ivec3(1065353216, 1073741824, -1069547520)) && floatBitsToInt(input) == expectedB ? colorGreen : colorRed; } diff --git a/tests/sksl/intrinsics/FloatBitsToInt.metal b/tests/sksl/intrinsics/FloatBitsToInt.metal index 4bd142d130..59c1e58f24 100644 --- a/tests/sksl/intrinsics/FloatBitsToInt.metal +++ b/tests/sksl/intrinsics/FloatBitsToInt.metal @@ -2,16 +2,25 @@ #include using namespace metal; struct Uniforms { - float a; + float testInput; + float2x2 testMatrix2x2; + float4 colorGreen; + float4 colorRed; }; struct Inputs { }; struct Outputs { float4 sk_FragColor [[color(0)]]; }; + +float4 float4_from_float2x2(float2x2 x) { + return float4(x[0].xy, x[1].xy); +} fragment Outputs fragmentMain(Inputs _in [[stage_in]], constant Uniforms& _uniforms [[buffer(0)]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) { Outputs _out; (void)_out; - _out.sk_FragColor.x = float(as_type(_uniforms.a)); + float4 input = float4_from_float2x2(_uniforms.testMatrix2x2) * float4(1.0, 1.0, -1.0, -1.0); + const int4 expectedB = int4(1065353216, 1073741824, -1069547520, -1065353216); + _out.sk_FragColor = ((as_type(input.x) == 1065353216 && all(as_type(input.xy) == int2(1065353216, 1073741824))) && all(as_type(input.xyz) == int3(1065353216, 1073741824, -1069547520))) && all(as_type(input) == expectedB) ? _uniforms.colorGreen : _uniforms.colorRed; return _out; } diff --git a/tests/sksl/intrinsics/FloatBitsToUint.asm.frag b/tests/sksl/intrinsics/FloatBitsToUint.asm.frag index 1abe64addd..b10eb1a9fd 100644 --- a/tests/sksl/intrinsics/FloatBitsToUint.asm.frag +++ b/tests/sksl/intrinsics/FloatBitsToUint.asm.frag @@ -1,22 +1,37 @@ OpCapability Shader %1 = OpExtInstImport "GLSL.std.450" OpMemoryModel Logical GLSL450 -OpEntryPoint Fragment %main "main" %sk_FragColor %sk_Clockwise -OpExecutionMode %main OriginUpperLeft +OpEntryPoint Fragment %_entrypoint_v "_entrypoint" %sk_FragColor %sk_Clockwise +OpExecutionMode %_entrypoint_v OriginUpperLeft OpName %sk_FragColor "sk_FragColor" OpName %sk_Clockwise "sk_Clockwise" OpName %_UniformBuffer "_UniformBuffer" -OpMemberName %_UniformBuffer 0 "a" +OpMemberName %_UniformBuffer 0 "testInput" +OpMemberName %_UniformBuffer 1 "testMatrix2x2" +OpMemberName %_UniformBuffer 2 "colorGreen" +OpMemberName %_UniformBuffer 3 "colorRed" +OpName %_entrypoint_v "_entrypoint_v" OpName %main "main" +OpName %input "input" +OpName %expectedB "expectedB" OpDecorate %sk_FragColor RelaxedPrecision OpDecorate %sk_FragColor Location 0 OpDecorate %sk_FragColor Index 0 OpDecorate %sk_Clockwise BuiltIn FrontFacing OpMemberDecorate %_UniformBuffer 0 Offset 0 +OpMemberDecorate %_UniformBuffer 1 Offset 16 +OpMemberDecorate %_UniformBuffer 1 ColMajor +OpMemberDecorate %_UniformBuffer 1 MatrixStride 16 +OpMemberDecorate %_UniformBuffer 2 Offset 48 +OpMemberDecorate %_UniformBuffer 2 RelaxedPrecision +OpMemberDecorate %_UniformBuffer 3 Offset 64 +OpMemberDecorate %_UniformBuffer 3 RelaxedPrecision OpDecorate %_UniformBuffer Block OpDecorate %10 Binding 0 OpDecorate %10 DescriptorSet 0 -OpDecorate %23 RelaxedPrecision +OpDecorate %96 RelaxedPrecision +OpDecorate %99 RelaxedPrecision +OpDecorate %100 RelaxedPrecision %float = OpTypeFloat 32 %v4float = OpTypeVector %float 4 %_ptr_Output_v4float = OpTypePointer Output %v4float @@ -24,23 +39,118 @@ OpDecorate %23 RelaxedPrecision %bool = OpTypeBool %_ptr_Input_bool = OpTypePointer Input %bool %sk_Clockwise = OpVariable %_ptr_Input_bool Input -%_UniformBuffer = OpTypeStruct %float +%v2float = OpTypeVector %float 2 +%mat2v2float = OpTypeMatrix %v2float 2 +%_UniformBuffer = OpTypeStruct %float %mat2v2float %v4float %v4float %_ptr_Uniform__UniformBuffer = OpTypePointer Uniform %_UniformBuffer %10 = OpVariable %_ptr_Uniform__UniformBuffer Uniform %void = OpTypeVoid -%14 = OpTypeFunction %void -%_ptr_Uniform_float = OpTypePointer Uniform %float +%17 = OpTypeFunction %void +%float_0 = OpConstant %float 0 +%20 = OpConstantComposite %v2float %float_0 %float_0 +%_ptr_Function_v2float = OpTypePointer Function %v2float +%24 = OpTypeFunction %v4float %_ptr_Function_v2float +%_ptr_Function_v4float = OpTypePointer Function %v4float +%_ptr_Uniform_mat2v2float = OpTypePointer Uniform %mat2v2float %int = OpTypeInt 32 1 -%int_0 = OpConstant %int 0 +%int_1 = OpConstant %int 1 +%float_1 = OpConstant %float 1 +%float_n1 = OpConstant %float -1 +%41 = OpConstantComposite %v4float %float_1 %float_1 %float_n1 %float_n1 %uint = OpTypeInt 32 0 -%_ptr_Output_float = OpTypePointer Output %float -%main = OpFunction %void None %14 -%15 = OpLabel -%17 = OpAccessChain %_ptr_Uniform_float %10 %int_0 -%21 = OpLoad %float %17 -%16 = OpBitcast %uint %21 -%23 = OpConvertUToF %float %16 -%24 = OpAccessChain %_ptr_Output_float %sk_FragColor %int_0 -OpStore %24 %23 +%v4uint = OpTypeVector %uint 4 +%_ptr_Function_v4uint = OpTypePointer Function %v4uint +%uint_1065353216 = OpConstant %uint 1065353216 +%uint_1073741824 = OpConstant %uint 1073741824 +%uint_3225419776 = OpConstant %uint 3225419776 +%uint_3229614080 = OpConstant %uint 3229614080 +%51 = OpConstantComposite %v4uint %uint_1065353216 %uint_1073741824 %uint_3225419776 %uint_3229614080 +%false = OpConstantFalse %bool +%v2uint = OpTypeVector %uint 2 +%63 = OpConstantComposite %v2uint %uint_1065353216 %uint_1073741824 +%v2bool = OpTypeVector %bool 2 +%v3float = OpTypeVector %float 3 +%v3uint = OpTypeVector %uint 3 +%75 = OpConstantComposite %v3uint %uint_1065353216 %uint_1073741824 %uint_3225419776 +%v3bool = OpTypeVector %bool 3 +%v4bool = OpTypeVector %bool 4 +%_ptr_Uniform_v4float = OpTypePointer Uniform %v4float +%int_2 = OpConstant %int 2 +%int_3 = OpConstant %int 3 +%_entrypoint_v = OpFunction %void None %17 +%18 = OpLabel +%21 = OpVariable %_ptr_Function_v2float Function +OpStore %21 %20 +%23 = OpFunctionCall %v4float %main %21 +OpStore %sk_FragColor %23 OpReturn OpFunctionEnd +%main = OpFunction %v4float None %24 +%25 = OpFunctionParameter %_ptr_Function_v2float +%26 = OpLabel +%input = OpVariable %_ptr_Function_v4float Function +%expectedB = OpVariable %_ptr_Function_v4uint Function +%89 = OpVariable %_ptr_Function_v4float Function +%29 = OpAccessChain %_ptr_Uniform_mat2v2float %10 %int_1 +%33 = OpLoad %mat2v2float %29 +%34 = OpCompositeExtract %float %33 0 0 +%35 = OpCompositeExtract %float %33 0 1 +%36 = OpCompositeExtract %float %33 1 0 +%37 = OpCompositeExtract %float %33 1 1 +%38 = OpCompositeConstruct %v4float %34 %35 %36 %37 +%42 = OpFMul %v4float %38 %41 +OpStore %input %42 +OpStore %expectedB %51 +%54 = OpLoad %v4float %input +%55 = OpCompositeExtract %float %54 0 +%53 = OpBitcast %uint %55 +%56 = OpIEqual %bool %53 %uint_1065353216 +OpSelectionMerge %58 None +OpBranchConditional %56 %57 %58 +%57 = OpLabel +%60 = OpLoad %v4float %input +%61 = OpVectorShuffle %v2float %60 %60 0 1 +%59 = OpBitcast %v2uint %61 +%64 = OpIEqual %v2bool %59 %63 +%66 = OpAll %bool %64 +OpBranch %58 +%58 = OpLabel +%67 = OpPhi %bool %false %26 %66 %57 +OpSelectionMerge %69 None +OpBranchConditional %67 %68 %69 +%68 = OpLabel +%71 = OpLoad %v4float %input +%72 = OpVectorShuffle %v3float %71 %71 0 1 2 +%70 = OpBitcast %v3uint %72 +%76 = OpIEqual %v3bool %70 %75 +%78 = OpAll %bool %76 +OpBranch %69 +%69 = OpLabel +%79 = OpPhi %bool %false %58 %78 %68 +OpSelectionMerge %81 None +OpBranchConditional %79 %80 %81 +%80 = OpLabel +%83 = OpLoad %v4float %input +%82 = OpBitcast %v4uint %83 +%84 = OpLoad %v4uint %expectedB +%85 = OpIEqual %v4bool %82 %84 +%87 = OpAll %bool %85 +OpBranch %81 +%81 = OpLabel +%88 = OpPhi %bool %false %69 %87 %80 +OpSelectionMerge %92 None +OpBranchConditional %88 %90 %91 +%90 = OpLabel +%93 = OpAccessChain %_ptr_Uniform_v4float %10 %int_2 +%96 = OpLoad %v4float %93 +OpStore %89 %96 +OpBranch %92 +%91 = OpLabel +%97 = OpAccessChain %_ptr_Uniform_v4float %10 %int_3 +%99 = OpLoad %v4float %97 +OpStore %89 %99 +OpBranch %92 +%92 = OpLabel +%100 = OpLoad %v4float %89 +OpReturnValue %100 +OpFunctionEnd diff --git a/tests/sksl/intrinsics/FloatBitsToUint.glsl b/tests/sksl/intrinsics/FloatBitsToUint.glsl index 31c93ab275..ea39150cc1 100644 --- a/tests/sksl/intrinsics/FloatBitsToUint.glsl +++ b/tests/sksl/intrinsics/FloatBitsToUint.glsl @@ -1,6 +1,11 @@ out vec4 sk_FragColor; -uniform float a; -void main() { - sk_FragColor.x = float(floatBitsToUint(a)); +uniform float testInput; +uniform mat2 testMatrix2x2; +uniform vec4 colorGreen; +uniform vec4 colorRed; +vec4 main() { + vec4 input = vec4(testMatrix2x2) * vec4(1.0, 1.0, -1.0, -1.0); + const uvec4 expectedB = uvec4(1065353216u, 1073741824u, 3225419776u, 3229614080u); + return ((floatBitsToUint(input.x) == 1065353216u && floatBitsToUint(input.xy) == uvec2(1065353216u, 1073741824u)) && floatBitsToUint(input.xyz) == uvec3(1065353216u, 1073741824u, 3225419776u)) && floatBitsToUint(input) == expectedB ? colorGreen : colorRed; } diff --git a/tests/sksl/intrinsics/FloatBitsToUint.metal b/tests/sksl/intrinsics/FloatBitsToUint.metal index d4e1995dd7..7d1a9c7563 100644 --- a/tests/sksl/intrinsics/FloatBitsToUint.metal +++ b/tests/sksl/intrinsics/FloatBitsToUint.metal @@ -2,16 +2,25 @@ #include using namespace metal; struct Uniforms { - float a; + float testInput; + float2x2 testMatrix2x2; + float4 colorGreen; + float4 colorRed; }; struct Inputs { }; struct Outputs { float4 sk_FragColor [[color(0)]]; }; + +float4 float4_from_float2x2(float2x2 x) { + return float4(x[0].xy, x[1].xy); +} fragment Outputs fragmentMain(Inputs _in [[stage_in]], constant Uniforms& _uniforms [[buffer(0)]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) { Outputs _out; (void)_out; - _out.sk_FragColor.x = float(as_type(_uniforms.a)); + float4 input = float4_from_float2x2(_uniforms.testMatrix2x2) * float4(1.0, 1.0, -1.0, -1.0); + const uint4 expectedB = uint4(1065353216u, 1073741824u, 3225419776u, 3229614080u); + _out.sk_FragColor = ((as_type(input.x) == 1065353216u && all(as_type(input.xy) == uint2(1065353216u, 1073741824u))) && all(as_type(input.xyz) == uint3(1065353216u, 1073741824u, 3225419776u))) && all(as_type(input) == expectedB) ? _uniforms.colorGreen : _uniforms.colorRed; return _out; } diff --git a/tests/sksl/intrinsics/IntBitsToFloat.asm.frag b/tests/sksl/intrinsics/IntBitsToFloat.asm.frag index 20804c09d4..9bb90d1222 100644 --- a/tests/sksl/intrinsics/IntBitsToFloat.asm.frag +++ b/tests/sksl/intrinsics/IntBitsToFloat.asm.frag @@ -1,21 +1,37 @@ OpCapability Shader %1 = OpExtInstImport "GLSL.std.450" OpMemoryModel Logical GLSL450 -OpEntryPoint Fragment %main "main" %sk_FragColor %sk_Clockwise -OpExecutionMode %main OriginUpperLeft +OpEntryPoint Fragment %_entrypoint_v "_entrypoint" %sk_FragColor %sk_Clockwise +OpExecutionMode %_entrypoint_v OriginUpperLeft OpName %sk_FragColor "sk_FragColor" OpName %sk_Clockwise "sk_Clockwise" OpName %_UniformBuffer "_UniformBuffer" -OpMemberName %_UniformBuffer 0 "a" +OpMemberName %_UniformBuffer 0 "testInput" +OpMemberName %_UniformBuffer 1 "testMatrix2x2" +OpMemberName %_UniformBuffer 2 "colorGreen" +OpMemberName %_UniformBuffer 3 "colorRed" +OpName %_entrypoint_v "_entrypoint_v" OpName %main "main" +OpName %input "input" +OpName %expectedB "expectedB" OpDecorate %sk_FragColor RelaxedPrecision OpDecorate %sk_FragColor Location 0 OpDecorate %sk_FragColor Index 0 OpDecorate %sk_Clockwise BuiltIn FrontFacing OpMemberDecorate %_UniformBuffer 0 Offset 0 +OpMemberDecorate %_UniformBuffer 1 Offset 16 +OpMemberDecorate %_UniformBuffer 1 ColMajor +OpMemberDecorate %_UniformBuffer 1 MatrixStride 16 +OpMemberDecorate %_UniformBuffer 2 Offset 48 +OpMemberDecorate %_UniformBuffer 2 RelaxedPrecision +OpMemberDecorate %_UniformBuffer 3 Offset 64 +OpMemberDecorate %_UniformBuffer 3 RelaxedPrecision OpDecorate %_UniformBuffer Block OpDecorate %10 Binding 0 OpDecorate %10 DescriptorSet 0 +OpDecorate %99 RelaxedPrecision +OpDecorate %102 RelaxedPrecision +OpDecorate %103 RelaxedPrecision %float = OpTypeFloat 32 %v4float = OpTypeVector %float 4 %_ptr_Output_v4float = OpTypePointer Output %v4float @@ -23,21 +39,121 @@ OpDecorate %10 DescriptorSet 0 %bool = OpTypeBool %_ptr_Input_bool = OpTypePointer Input %bool %sk_Clockwise = OpVariable %_ptr_Input_bool Input -%int = OpTypeInt 32 1 -%_UniformBuffer = OpTypeStruct %int +%v2float = OpTypeVector %float 2 +%mat2v2float = OpTypeMatrix %v2float 2 +%_UniformBuffer = OpTypeStruct %float %mat2v2float %v4float %v4float %_ptr_Uniform__UniformBuffer = OpTypePointer Uniform %_UniformBuffer %10 = OpVariable %_ptr_Uniform__UniformBuffer Uniform %void = OpTypeVoid -%15 = OpTypeFunction %void -%_ptr_Uniform_int = OpTypePointer Uniform %int -%int_0 = OpConstant %int 0 -%_ptr_Output_float = OpTypePointer Output %float -%main = OpFunction %void None %15 -%16 = OpLabel -%18 = OpAccessChain %_ptr_Uniform_int %10 %int_0 -%21 = OpLoad %int %18 -%17 = OpBitcast %float %21 -%22 = OpAccessChain %_ptr_Output_float %sk_FragColor %int_0 -OpStore %22 %17 +%17 = OpTypeFunction %void +%float_0 = OpConstant %float 0 +%20 = OpConstantComposite %v2float %float_0 %float_0 +%_ptr_Function_v2float = OpTypePointer Function %v2float +%24 = OpTypeFunction %v4float %_ptr_Function_v2float +%_ptr_Function_v4float = OpTypePointer Function %v4float +%_ptr_Uniform_mat2v2float = OpTypePointer Uniform %mat2v2float +%int = OpTypeInt 32 1 +%int_1 = OpConstant %int 1 +%float_1 = OpConstant %float 1 +%float_n1 = OpConstant %float -1 +%41 = OpConstantComposite %v4float %float_1 %float_1 %float_n1 %float_n1 +%v4int = OpTypeVector %int 4 +%_ptr_Function_v4int = OpTypePointer Function %v4int +%int_1065353216 = OpConstant %int 1065353216 +%int_1073741824 = OpConstant %int 1073741824 +%int_n1069547520 = OpConstant %int -1069547520 +%int_n1065353216 = OpConstant %int -1065353216 +%50 = OpConstantComposite %v4int %int_1065353216 %int_1073741824 %int_n1069547520 %int_n1065353216 +%false = OpConstantFalse %bool +%v2int = OpTypeVector %int 2 +%v2bool = OpTypeVector %bool 2 +%v3float = OpTypeVector %float 3 +%v3int = OpTypeVector %int 3 +%v3bool = OpTypeVector %bool 3 +%v4bool = OpTypeVector %bool 4 +%_ptr_Uniform_v4float = OpTypePointer Uniform %v4float +%int_2 = OpConstant %int 2 +%int_3 = OpConstant %int 3 +%_entrypoint_v = OpFunction %void None %17 +%18 = OpLabel +%21 = OpVariable %_ptr_Function_v2float Function +OpStore %21 %20 +%23 = OpFunctionCall %v4float %main %21 +OpStore %sk_FragColor %23 OpReturn OpFunctionEnd +%main = OpFunction %v4float None %24 +%25 = OpFunctionParameter %_ptr_Function_v2float +%26 = OpLabel +%input = OpVariable %_ptr_Function_v4float Function +%expectedB = OpVariable %_ptr_Function_v4int Function +%92 = OpVariable %_ptr_Function_v4float Function +%29 = OpAccessChain %_ptr_Uniform_mat2v2float %10 %int_1 +%33 = OpLoad %mat2v2float %29 +%34 = OpCompositeExtract %float %33 0 0 +%35 = OpCompositeExtract %float %33 0 1 +%36 = OpCompositeExtract %float %33 1 0 +%37 = OpCompositeExtract %float %33 1 1 +%38 = OpCompositeConstruct %v4float %34 %35 %36 %37 +%42 = OpFMul %v4float %38 %41 +OpStore %input %42 +OpStore %expectedB %50 +%52 = OpLoad %v4float %input +%53 = OpCompositeExtract %float %52 0 +%55 = OpLoad %v4int %expectedB +%56 = OpCompositeExtract %int %55 0 +%54 = OpBitcast %float %56 +%57 = OpFOrdEqual %bool %53 %54 +OpSelectionMerge %59 None +OpBranchConditional %57 %58 %59 +%58 = OpLabel +%60 = OpLoad %v4float %input +%61 = OpVectorShuffle %v2float %60 %60 0 1 +%63 = OpLoad %v4int %expectedB +%64 = OpVectorShuffle %v2int %63 %63 0 1 +%62 = OpBitcast %v2float %64 +%66 = OpFOrdEqual %v2bool %61 %62 +%68 = OpAll %bool %66 +OpBranch %59 +%59 = OpLabel +%69 = OpPhi %bool %false %26 %68 %58 +OpSelectionMerge %71 None +OpBranchConditional %69 %70 %71 +%70 = OpLabel +%72 = OpLoad %v4float %input +%73 = OpVectorShuffle %v3float %72 %72 0 1 2 +%76 = OpLoad %v4int %expectedB +%77 = OpVectorShuffle %v3int %76 %76 0 1 2 +%75 = OpBitcast %v3float %77 +%79 = OpFOrdEqual %v3bool %73 %75 +%81 = OpAll %bool %79 +OpBranch %71 +%71 = OpLabel +%82 = OpPhi %bool %false %59 %81 %70 +OpSelectionMerge %84 None +OpBranchConditional %82 %83 %84 +%83 = OpLabel +%85 = OpLoad %v4float %input +%87 = OpLoad %v4int %expectedB +%86 = OpBitcast %v4float %87 +%88 = OpFOrdEqual %v4bool %85 %86 +%90 = OpAll %bool %88 +OpBranch %84 +%84 = OpLabel +%91 = OpPhi %bool %false %71 %90 %83 +OpSelectionMerge %95 None +OpBranchConditional %91 %93 %94 +%93 = OpLabel +%96 = OpAccessChain %_ptr_Uniform_v4float %10 %int_2 +%99 = OpLoad %v4float %96 +OpStore %92 %99 +OpBranch %95 +%94 = OpLabel +%100 = OpAccessChain %_ptr_Uniform_v4float %10 %int_3 +%102 = OpLoad %v4float %100 +OpStore %92 %102 +OpBranch %95 +%95 = OpLabel +%103 = OpLoad %v4float %92 +OpReturnValue %103 +OpFunctionEnd diff --git a/tests/sksl/intrinsics/IntBitsToFloat.glsl b/tests/sksl/intrinsics/IntBitsToFloat.glsl index 2326b8bd0e..e14b37e9bb 100644 --- a/tests/sksl/intrinsics/IntBitsToFloat.glsl +++ b/tests/sksl/intrinsics/IntBitsToFloat.glsl @@ -1,6 +1,11 @@ out vec4 sk_FragColor; -uniform int a; -void main() { - sk_FragColor.x = intBitsToFloat(a); +uniform float testInput; +uniform mat2 testMatrix2x2; +uniform vec4 colorGreen; +uniform vec4 colorRed; +vec4 main() { + vec4 input = vec4(testMatrix2x2) * vec4(1.0, 1.0, -1.0, -1.0); + ivec4 expectedB = ivec4(1065353216, 1073741824, -1069547520, -1065353216); + return ((input.x == intBitsToFloat(expectedB.x) && input.xy == intBitsToFloat(expectedB.xy)) && input.xyz == intBitsToFloat(expectedB.xyz)) && input == intBitsToFloat(expectedB) ? colorGreen : colorRed; } diff --git a/tests/sksl/intrinsics/IntBitsToFloat.metal b/tests/sksl/intrinsics/IntBitsToFloat.metal index 61327d37d5..5312bb9a50 100644 --- a/tests/sksl/intrinsics/IntBitsToFloat.metal +++ b/tests/sksl/intrinsics/IntBitsToFloat.metal @@ -2,16 +2,25 @@ #include using namespace metal; struct Uniforms { - int a; + float testInput; + float2x2 testMatrix2x2; + float4 colorGreen; + float4 colorRed; }; struct Inputs { }; struct Outputs { float4 sk_FragColor [[color(0)]]; }; + +float4 float4_from_float2x2(float2x2 x) { + return float4(x[0].xy, x[1].xy); +} fragment Outputs fragmentMain(Inputs _in [[stage_in]], constant Uniforms& _uniforms [[buffer(0)]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) { Outputs _out; (void)_out; - _out.sk_FragColor.x = as_type(_uniforms.a); + float4 input = float4_from_float2x2(_uniforms.testMatrix2x2) * float4(1.0, 1.0, -1.0, -1.0); + int4 expectedB = int4(1065353216, 1073741824, -1069547520, -1065353216); + _out.sk_FragColor = ((input.x == as_type(expectedB.x) && all(input.xy == as_type(expectedB.xy))) && all(input.xyz == as_type(expectedB.xyz))) && all(input == as_type(expectedB)) ? _uniforms.colorGreen : _uniforms.colorRed; return _out; } diff --git a/tests/sksl/intrinsics/UintBitsToFloat.asm.frag b/tests/sksl/intrinsics/UintBitsToFloat.asm.frag index 312ce9b55e..236150c878 100644 --- a/tests/sksl/intrinsics/UintBitsToFloat.asm.frag +++ b/tests/sksl/intrinsics/UintBitsToFloat.asm.frag @@ -1,21 +1,37 @@ OpCapability Shader %1 = OpExtInstImport "GLSL.std.450" OpMemoryModel Logical GLSL450 -OpEntryPoint Fragment %main "main" %sk_FragColor %sk_Clockwise -OpExecutionMode %main OriginUpperLeft +OpEntryPoint Fragment %_entrypoint_v "_entrypoint" %sk_FragColor %sk_Clockwise +OpExecutionMode %_entrypoint_v OriginUpperLeft OpName %sk_FragColor "sk_FragColor" OpName %sk_Clockwise "sk_Clockwise" OpName %_UniformBuffer "_UniformBuffer" -OpMemberName %_UniformBuffer 0 "a" +OpMemberName %_UniformBuffer 0 "testInput" +OpMemberName %_UniformBuffer 1 "testMatrix2x2" +OpMemberName %_UniformBuffer 2 "colorGreen" +OpMemberName %_UniformBuffer 3 "colorRed" +OpName %_entrypoint_v "_entrypoint_v" OpName %main "main" +OpName %input "input" +OpName %expectedB "expectedB" OpDecorate %sk_FragColor RelaxedPrecision OpDecorate %sk_FragColor Location 0 OpDecorate %sk_FragColor Index 0 OpDecorate %sk_Clockwise BuiltIn FrontFacing OpMemberDecorate %_UniformBuffer 0 Offset 0 +OpMemberDecorate %_UniformBuffer 1 Offset 16 +OpMemberDecorate %_UniformBuffer 1 ColMajor +OpMemberDecorate %_UniformBuffer 1 MatrixStride 16 +OpMemberDecorate %_UniformBuffer 2 Offset 48 +OpMemberDecorate %_UniformBuffer 2 RelaxedPrecision +OpMemberDecorate %_UniformBuffer 3 Offset 64 +OpMemberDecorate %_UniformBuffer 3 RelaxedPrecision OpDecorate %_UniformBuffer Block OpDecorate %10 Binding 0 OpDecorate %10 DescriptorSet 0 +OpDecorate %100 RelaxedPrecision +OpDecorate %103 RelaxedPrecision +OpDecorate %104 RelaxedPrecision %float = OpTypeFloat 32 %v4float = OpTypeVector %float 4 %_ptr_Output_v4float = OpTypePointer Output %v4float @@ -23,22 +39,122 @@ OpDecorate %10 DescriptorSet 0 %bool = OpTypeBool %_ptr_Input_bool = OpTypePointer Input %bool %sk_Clockwise = OpVariable %_ptr_Input_bool Input -%uint = OpTypeInt 32 0 -%_UniformBuffer = OpTypeStruct %uint +%v2float = OpTypeVector %float 2 +%mat2v2float = OpTypeMatrix %v2float 2 +%_UniformBuffer = OpTypeStruct %float %mat2v2float %v4float %v4float %_ptr_Uniform__UniformBuffer = OpTypePointer Uniform %_UniformBuffer %10 = OpVariable %_ptr_Uniform__UniformBuffer Uniform %void = OpTypeVoid -%15 = OpTypeFunction %void -%_ptr_Uniform_uint = OpTypePointer Uniform %uint +%17 = OpTypeFunction %void +%float_0 = OpConstant %float 0 +%20 = OpConstantComposite %v2float %float_0 %float_0 +%_ptr_Function_v2float = OpTypePointer Function %v2float +%24 = OpTypeFunction %v4float %_ptr_Function_v2float +%_ptr_Function_v4float = OpTypePointer Function %v4float +%_ptr_Uniform_mat2v2float = OpTypePointer Uniform %mat2v2float %int = OpTypeInt 32 1 -%int_0 = OpConstant %int 0 -%_ptr_Output_float = OpTypePointer Output %float -%main = OpFunction %void None %15 -%16 = OpLabel -%18 = OpAccessChain %_ptr_Uniform_uint %10 %int_0 -%22 = OpLoad %uint %18 -%17 = OpBitcast %float %22 -%23 = OpAccessChain %_ptr_Output_float %sk_FragColor %int_0 -OpStore %23 %17 +%int_1 = OpConstant %int 1 +%float_1 = OpConstant %float 1 +%float_n1 = OpConstant %float -1 +%41 = OpConstantComposite %v4float %float_1 %float_1 %float_n1 %float_n1 +%uint = OpTypeInt 32 0 +%v4uint = OpTypeVector %uint 4 +%_ptr_Function_v4uint = OpTypePointer Function %v4uint +%uint_1065353216 = OpConstant %uint 1065353216 +%uint_1073741824 = OpConstant %uint 1073741824 +%uint_3225419776 = OpConstant %uint 3225419776 +%uint_3229614080 = OpConstant %uint 3229614080 +%51 = OpConstantComposite %v4uint %uint_1065353216 %uint_1073741824 %uint_3225419776 %uint_3229614080 +%false = OpConstantFalse %bool +%v2uint = OpTypeVector %uint 2 +%v2bool = OpTypeVector %bool 2 +%v3float = OpTypeVector %float 3 +%v3uint = OpTypeVector %uint 3 +%v3bool = OpTypeVector %bool 3 +%v4bool = OpTypeVector %bool 4 +%_ptr_Uniform_v4float = OpTypePointer Uniform %v4float +%int_2 = OpConstant %int 2 +%int_3 = OpConstant %int 3 +%_entrypoint_v = OpFunction %void None %17 +%18 = OpLabel +%21 = OpVariable %_ptr_Function_v2float Function +OpStore %21 %20 +%23 = OpFunctionCall %v4float %main %21 +OpStore %sk_FragColor %23 OpReturn OpFunctionEnd +%main = OpFunction %v4float None %24 +%25 = OpFunctionParameter %_ptr_Function_v2float +%26 = OpLabel +%input = OpVariable %_ptr_Function_v4float Function +%expectedB = OpVariable %_ptr_Function_v4uint Function +%93 = OpVariable %_ptr_Function_v4float Function +%29 = OpAccessChain %_ptr_Uniform_mat2v2float %10 %int_1 +%33 = OpLoad %mat2v2float %29 +%34 = OpCompositeExtract %float %33 0 0 +%35 = OpCompositeExtract %float %33 0 1 +%36 = OpCompositeExtract %float %33 1 0 +%37 = OpCompositeExtract %float %33 1 1 +%38 = OpCompositeConstruct %v4float %34 %35 %36 %37 +%42 = OpFMul %v4float %38 %41 +OpStore %input %42 +OpStore %expectedB %51 +%53 = OpLoad %v4float %input +%54 = OpCompositeExtract %float %53 0 +%56 = OpLoad %v4uint %expectedB +%57 = OpCompositeExtract %uint %56 0 +%55 = OpBitcast %float %57 +%58 = OpFOrdEqual %bool %54 %55 +OpSelectionMerge %60 None +OpBranchConditional %58 %59 %60 +%59 = OpLabel +%61 = OpLoad %v4float %input +%62 = OpVectorShuffle %v2float %61 %61 0 1 +%64 = OpLoad %v4uint %expectedB +%65 = OpVectorShuffle %v2uint %64 %64 0 1 +%63 = OpBitcast %v2float %65 +%67 = OpFOrdEqual %v2bool %62 %63 +%69 = OpAll %bool %67 +OpBranch %60 +%60 = OpLabel +%70 = OpPhi %bool %false %26 %69 %59 +OpSelectionMerge %72 None +OpBranchConditional %70 %71 %72 +%71 = OpLabel +%73 = OpLoad %v4float %input +%74 = OpVectorShuffle %v3float %73 %73 0 1 2 +%77 = OpLoad %v4uint %expectedB +%78 = OpVectorShuffle %v3uint %77 %77 0 1 2 +%76 = OpBitcast %v3float %78 +%80 = OpFOrdEqual %v3bool %74 %76 +%82 = OpAll %bool %80 +OpBranch %72 +%72 = OpLabel +%83 = OpPhi %bool %false %60 %82 %71 +OpSelectionMerge %85 None +OpBranchConditional %83 %84 %85 +%84 = OpLabel +%86 = OpLoad %v4float %input +%88 = OpLoad %v4uint %expectedB +%87 = OpBitcast %v4float %88 +%89 = OpFOrdEqual %v4bool %86 %87 +%91 = OpAll %bool %89 +OpBranch %85 +%85 = OpLabel +%92 = OpPhi %bool %false %72 %91 %84 +OpSelectionMerge %96 None +OpBranchConditional %92 %94 %95 +%94 = OpLabel +%97 = OpAccessChain %_ptr_Uniform_v4float %10 %int_2 +%100 = OpLoad %v4float %97 +OpStore %93 %100 +OpBranch %96 +%95 = OpLabel +%101 = OpAccessChain %_ptr_Uniform_v4float %10 %int_3 +%103 = OpLoad %v4float %101 +OpStore %93 %103 +OpBranch %96 +%96 = OpLabel +%104 = OpLoad %v4float %93 +OpReturnValue %104 +OpFunctionEnd diff --git a/tests/sksl/intrinsics/UintBitsToFloat.glsl b/tests/sksl/intrinsics/UintBitsToFloat.glsl index 4a3d39ae71..5dd78c3566 100644 --- a/tests/sksl/intrinsics/UintBitsToFloat.glsl +++ b/tests/sksl/intrinsics/UintBitsToFloat.glsl @@ -1,6 +1,11 @@ out vec4 sk_FragColor; -uniform uint a; -void main() { - sk_FragColor.x = uintBitsToFloat(a); +uniform float testInput; +uniform mat2 testMatrix2x2; +uniform vec4 colorGreen; +uniform vec4 colorRed; +vec4 main() { + vec4 input = vec4(testMatrix2x2) * vec4(1.0, 1.0, -1.0, -1.0); + uvec4 expectedB = uvec4(1065353216u, 1073741824u, 3225419776u, 3229614080u); + return ((input.x == uintBitsToFloat(expectedB.x) && input.xy == uintBitsToFloat(expectedB.xy)) && input.xyz == uintBitsToFloat(expectedB.xyz)) && input == uintBitsToFloat(expectedB) ? colorGreen : colorRed; } diff --git a/tests/sksl/intrinsics/UintBitsToFloat.metal b/tests/sksl/intrinsics/UintBitsToFloat.metal index 7157353695..811881dd64 100644 --- a/tests/sksl/intrinsics/UintBitsToFloat.metal +++ b/tests/sksl/intrinsics/UintBitsToFloat.metal @@ -2,16 +2,25 @@ #include using namespace metal; struct Uniforms { - uint a; + float testInput; + float2x2 testMatrix2x2; + float4 colorGreen; + float4 colorRed; }; struct Inputs { }; struct Outputs { float4 sk_FragColor [[color(0)]]; }; + +float4 float4_from_float2x2(float2x2 x) { + return float4(x[0].xy, x[1].xy); +} fragment Outputs fragmentMain(Inputs _in [[stage_in]], constant Uniforms& _uniforms [[buffer(0)]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) { Outputs _out; (void)_out; - _out.sk_FragColor.x = as_type(_uniforms.a); + float4 input = float4_from_float2x2(_uniforms.testMatrix2x2) * float4(1.0, 1.0, -1.0, -1.0); + uint4 expectedB = uint4(1065353216u, 1073741824u, 3225419776u, 3229614080u); + _out.sk_FragColor = ((input.x == as_type(expectedB.x) && all(input.xy == as_type(expectedB.xy))) && all(input.xyz == as_type(expectedB.xyz))) && all(input == as_type(expectedB)) ? _uniforms.colorGreen : _uniforms.colorRed; return _out; }