Add unit test for casting between float, int and bool.
This actually exposed a latent bug: we don't support bool(1.23) or
bool(1) casts, but these are valid in GLSL:
https://www.khronos.org/opengl/wiki/Data_Type_(GLSL)#Conversion_constructors
"to bool: A value equal to 0 or 0.0 becomes false; anything else is
true."
Change-Id: Ia929a09914ffc96f081d0402d7bb05b5428f8db6
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/349977
Auto-Submit: John Stiles <johnstiles@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
diff --git a/gn/sksl_tests.gni b/gn/sksl_tests.gni
index 54bc170..7006683 100644
--- a/gn/sksl_tests.gni
+++ b/gn/sksl_tests.gni
@@ -333,6 +333,7 @@
"$_tests/sksl/shared/NoFragCoordsPosRT.vert",
"$_tests/sksl/shared/NormalizationGeo.geom",
"$_tests/sksl/shared/NormalizationVert.vert",
+ "$_tests/sksl/shared/NumberCasts.sksl",
"$_tests/sksl/shared/NumberConversions.sksl",
"$_tests/sksl/shared/Offset.sksl",
"$_tests/sksl/shared/Operators.sksl",
diff --git a/tests/sksl/shared/NumberCasts.sksl b/tests/sksl/shared/NumberCasts.sksl
new file mode 100644
index 0000000..f91c72e
--- /dev/null
+++ b/tests/sksl/shared/NumberCasts.sksl
@@ -0,0 +1,23 @@
+bool BF = bool(1.23);
+bool BI = bool(1);
+bool BB = bool(true);
+
+float FF = float(1.23);
+float FI = float(1);
+float FB = float(true);
+
+int IF = int(1.23);
+int II = int(1);
+int IB = int(true);
+
+void main() {
+ sk_FragColor.x = half(BF);
+ sk_FragColor.x = half(BI);
+ sk_FragColor.x = half(BB);
+ sk_FragColor.x = half(FF);
+ sk_FragColor.x = half(FI);
+ sk_FragColor.x = half(FB);
+ sk_FragColor.x = half(IF);
+ sk_FragColor.x = half(II);
+ sk_FragColor.x = half(IB);
+}
diff --git a/tests/sksl/shared/NumberConversions.sksl b/tests/sksl/shared/NumberConversions.sksl
index 1021b06..cfc5c06 100644
--- a/tests/sksl/shared/NumberConversions.sksl
+++ b/tests/sksl/shared/NumberConversions.sksl
@@ -1,3 +1,4 @@
+bool b = true;
short s = short(sqrt(1));
int i = int(sqrt(1));
ushort us = ushort(sqrt(1));
@@ -10,34 +11,40 @@
short ui2s = short(ui);
short h2s = short(h);
short f2s = short(f);
+short b2s = short(b);
int s2i = s;
int i2i = i;
int us2i = int(us);
int ui2i = int(ui);
int h2i = int(h);
int f2i = int(f);
+int b2i = int(b);
ushort s2us = ushort(s);
ushort i2us = ushort(i);
ushort us2us = us;
ushort ui2us = ushort(ui);
ushort h2us = ushort(h);
ushort f2us = ushort(f);
+ushort b2us = ushort(b);
uint s2ui = uint(s);
uint i2ui = uint(i);
uint us2ui = us;
uint ui2ui = ui;
uint h2ui = uint(h);
uint f2ui = uint(f);
+uint b2ui = uint(b);
float s2f = s;
float i2f = i;
float us2f = us;
float ui2f = ui;
float h2f = h;
float f2f = f;
+float b2f = float(b); // bool-to-float is not implicitly convertible
void main() {
sk_FragColor.r = half(s + i + us + half(ui) + h + f + s2s + i2s + us2s + ui2s + h2s + f2s +
- s2i + i2i + us2i + ui2i + h2i + f2i + s2us + i2us + us2us);
- sk_FragColor.r += half(ui2us + h2us + f2us + half(s2ui) + half(i2ui) + half(us2ui) + half(ui2ui)
- + half(h2ui) + half(f2ui) + s2f + i2f + us2f + ui2f + h2f + f2f);
+ b2s + s2i + i2i + us2i + ui2i + h2i + f2i + b2i + s2us + i2us + us2us);
+ sk_FragColor.r += half(ui2us + h2us + f2us + b2us + half(s2ui) + half(i2ui) + half(us2ui) +
+ half(ui2ui) + half(h2ui) + half(f2ui) + half(b2ui) + s2f + i2f + us2f +
+ ui2f + h2f + f2f + b2f);
}
diff --git a/tests/sksl/shared/golden/NumberCasts.asm.frag b/tests/sksl/shared/golden/NumberCasts.asm.frag
new file mode 100644
index 0000000..054aa0f
--- /dev/null
+++ b/tests/sksl/shared/golden/NumberCasts.asm.frag
@@ -0,0 +1,6 @@
+### Compilation failed:
+
+error: 1: cannot construct 'bool'
+error: 2: cannot construct 'bool'
+error: 14: unknown identifier 'BF'
+3 errors
diff --git a/tests/sksl/shared/golden/NumberCasts.glsl b/tests/sksl/shared/golden/NumberCasts.glsl
new file mode 100644
index 0000000..054aa0f
--- /dev/null
+++ b/tests/sksl/shared/golden/NumberCasts.glsl
@@ -0,0 +1,6 @@
+### Compilation failed:
+
+error: 1: cannot construct 'bool'
+error: 2: cannot construct 'bool'
+error: 14: unknown identifier 'BF'
+3 errors
diff --git a/tests/sksl/shared/golden/NumberCasts.metal b/tests/sksl/shared/golden/NumberCasts.metal
new file mode 100644
index 0000000..054aa0f
--- /dev/null
+++ b/tests/sksl/shared/golden/NumberCasts.metal
@@ -0,0 +1,6 @@
+### Compilation failed:
+
+error: 1: cannot construct 'bool'
+error: 2: cannot construct 'bool'
+error: 14: unknown identifier 'BF'
+3 errors
diff --git a/tests/sksl/shared/golden/NumberConversions.asm.frag b/tests/sksl/shared/golden/NumberConversions.asm.frag
index c8ef98c..3eccfe0 100644
--- a/tests/sksl/shared/golden/NumberConversions.asm.frag
+++ b/tests/sksl/shared/golden/NumberConversions.asm.frag
@@ -5,6 +5,7 @@
OpExecutionMode %main OriginUpperLeft
OpName %sk_FragColor "sk_FragColor"
OpName %sk_Clockwise "sk_Clockwise"
+OpName %b "b"
OpName %s "s"
OpName %i "i"
OpName %us "us"
@@ -17,93 +18,110 @@
OpName %ui2s "ui2s"
OpName %h2s "h2s"
OpName %f2s "f2s"
+OpName %b2s "b2s"
OpName %s2i "s2i"
OpName %i2i "i2i"
OpName %us2i "us2i"
OpName %ui2i "ui2i"
OpName %h2i "h2i"
OpName %f2i "f2i"
+OpName %b2i "b2i"
OpName %s2us "s2us"
OpName %i2us "i2us"
OpName %us2us "us2us"
OpName %ui2us "ui2us"
OpName %h2us "h2us"
OpName %f2us "f2us"
+OpName %b2us "b2us"
OpName %s2ui "s2ui"
OpName %i2ui "i2ui"
OpName %us2ui "us2ui"
OpName %ui2ui "ui2ui"
OpName %h2ui "h2ui"
OpName %f2ui "f2ui"
+OpName %b2ui "b2ui"
OpName %s2f "s2f"
OpName %i2f "i2f"
OpName %us2f "us2f"
OpName %ui2f "ui2f"
OpName %h2f "h2f"
OpName %f2f "f2f"
+OpName %b2f "b2f"
OpName %main "main"
OpDecorate %sk_FragColor RelaxedPrecision
OpDecorate %sk_FragColor Location 0
OpDecorate %sk_FragColor Index 0
OpDecorate %sk_Clockwise RelaxedPrecision
OpDecorate %sk_Clockwise BuiltIn FrontFacing
+OpDecorate %b RelaxedPrecision
OpDecorate %s RelaxedPrecision
OpDecorate %us RelaxedPrecision
OpDecorate %h RelaxedPrecision
OpDecorate %s2s RelaxedPrecision
-OpDecorate %33 RelaxedPrecision
+OpDecorate %36 RelaxedPrecision
OpDecorate %i2s RelaxedPrecision
OpDecorate %us2s RelaxedPrecision
-OpDecorate %38 RelaxedPrecision
+OpDecorate %41 RelaxedPrecision
OpDecorate %ui2s RelaxedPrecision
OpDecorate %h2s RelaxedPrecision
-OpDecorate %44 RelaxedPrecision
+OpDecorate %47 RelaxedPrecision
OpDecorate %f2s RelaxedPrecision
-OpDecorate %49 RelaxedPrecision
-OpDecorate %54 RelaxedPrecision
-OpDecorate %60 RelaxedPrecision
+OpDecorate %b2s RelaxedPrecision
+OpDecorate %52 RelaxedPrecision
+OpDecorate %57 RelaxedPrecision
+OpDecorate %62 RelaxedPrecision
+OpDecorate %68 RelaxedPrecision
+OpDecorate %73 RelaxedPrecision
OpDecorate %s2us RelaxedPrecision
-OpDecorate %66 RelaxedPrecision
+OpDecorate %77 RelaxedPrecision
OpDecorate %i2us RelaxedPrecision
OpDecorate %us2us RelaxedPrecision
-OpDecorate %71 RelaxedPrecision
+OpDecorate %82 RelaxedPrecision
OpDecorate %ui2us RelaxedPrecision
OpDecorate %h2us RelaxedPrecision
-OpDecorate %76 RelaxedPrecision
-OpDecorate %f2us RelaxedPrecision
-OpDecorate %82 RelaxedPrecision
OpDecorate %87 RelaxedPrecision
+OpDecorate %f2us RelaxedPrecision
+OpDecorate %b2us RelaxedPrecision
OpDecorate %92 RelaxedPrecision
OpDecorate %98 RelaxedPrecision
-OpDecorate %104 RelaxedPrecision
-OpDecorate %109 RelaxedPrecision
-OpDecorate %116 RelaxedPrecision
-OpDecorate %120 RelaxedPrecision
-OpDecorate %124 RelaxedPrecision
+OpDecorate %103 RelaxedPrecision
+OpDecorate %108 RelaxedPrecision
+OpDecorate %113 RelaxedPrecision
+OpDecorate %119 RelaxedPrecision
OpDecorate %125 RelaxedPrecision
-OpDecorate %126 RelaxedPrecision
OpDecorate %130 RelaxedPrecision
-OpDecorate %133 RelaxedPrecision
-OpDecorate %136 RelaxedPrecision
-OpDecorate %139 RelaxedPrecision
-OpDecorate %142 RelaxedPrecision
+OpDecorate %134 RelaxedPrecision
+OpDecorate %141 RelaxedPrecision
OpDecorate %145 RelaxedPrecision
-OpDecorate %166 RelaxedPrecision
-OpDecorate %169 RelaxedPrecision
-OpDecorate %172 RelaxedPrecision
-OpDecorate %178 RelaxedPrecision
-OpDecorate %180 RelaxedPrecision
-OpDecorate %181 RelaxedPrecision
-OpDecorate %182 RelaxedPrecision
-OpDecorate %183 RelaxedPrecision
-OpDecorate %184 RelaxedPrecision
-OpDecorate %187 RelaxedPrecision
-OpDecorate %190 RelaxedPrecision
-OpDecorate %193 RelaxedPrecision
-OpDecorate %196 RelaxedPrecision
-OpDecorate %199 RelaxedPrecision
-OpDecorate %202 RelaxedPrecision
+OpDecorate %149 RelaxedPrecision
+OpDecorate %150 RelaxedPrecision
+OpDecorate %151 RelaxedPrecision
+OpDecorate %155 RelaxedPrecision
+OpDecorate %158 RelaxedPrecision
+OpDecorate %161 RelaxedPrecision
+OpDecorate %164 RelaxedPrecision
+OpDecorate %167 RelaxedPrecision
+OpDecorate %170 RelaxedPrecision
+OpDecorate %173 RelaxedPrecision
+OpDecorate %197 RelaxedPrecision
+OpDecorate %200 RelaxedPrecision
+OpDecorate %203 RelaxedPrecision
+OpDecorate %208 RelaxedPrecision
+OpDecorate %210 RelaxedPrecision
+OpDecorate %211 RelaxedPrecision
+OpDecorate %212 RelaxedPrecision
+OpDecorate %213 RelaxedPrecision
+OpDecorate %214 RelaxedPrecision
OpDecorate %215 RelaxedPrecision
+OpDecorate %216 RelaxedPrecision
+OpDecorate %219 RelaxedPrecision
+OpDecorate %222 RelaxedPrecision
+OpDecorate %225 RelaxedPrecision
+OpDecorate %228 RelaxedPrecision
+OpDecorate %231 RelaxedPrecision
+OpDecorate %234 RelaxedPrecision
+OpDecorate %237 RelaxedPrecision
+OpDecorate %252 RelaxedPrecision
%float = OpTypeFloat 32
%v4float = OpTypeVector %float 4
%_ptr_Output_v4float = OpTypePointer Output %v4float
@@ -111,6 +129,9 @@
%bool = OpTypeBool
%_ptr_Input_bool = OpTypePointer Input %bool
%sk_Clockwise = OpVariable %_ptr_Input_bool Input
+%_ptr_Private_bool = OpTypePointer Private %bool
+%b = OpVariable %_ptr_Private_bool Private
+%true = OpConstantTrue %bool
%int = OpTypeInt 32 1
%_ptr_Private_int = OpTypePointer Private %int
%s = OpVariable %_ptr_Private_int Private
@@ -129,232 +150,272 @@
%ui2s = OpVariable %_ptr_Private_int Private
%h2s = OpVariable %_ptr_Private_int Private
%f2s = OpVariable %_ptr_Private_int Private
+%b2s = OpVariable %_ptr_Private_int Private
+%int_1 = OpConstant %int 1
+%int_0 = OpConstant %int 0
%s2i = OpVariable %_ptr_Private_int Private
%i2i = OpVariable %_ptr_Private_int Private
%us2i = OpVariable %_ptr_Private_int Private
%ui2i = OpVariable %_ptr_Private_int Private
%h2i = OpVariable %_ptr_Private_int Private
%f2i = OpVariable %_ptr_Private_int Private
+%b2i = OpVariable %_ptr_Private_int Private
%s2us = OpVariable %_ptr_Private_uint Private
%i2us = OpVariable %_ptr_Private_uint Private
%us2us = OpVariable %_ptr_Private_uint Private
%ui2us = OpVariable %_ptr_Private_uint Private
%h2us = OpVariable %_ptr_Private_uint Private
%f2us = OpVariable %_ptr_Private_uint Private
+%b2us = OpVariable %_ptr_Private_uint Private
%s2ui = OpVariable %_ptr_Private_uint Private
%i2ui = OpVariable %_ptr_Private_uint Private
%us2ui = OpVariable %_ptr_Private_uint Private
%ui2ui = OpVariable %_ptr_Private_uint Private
%h2ui = OpVariable %_ptr_Private_uint Private
%f2ui = OpVariable %_ptr_Private_uint Private
+%b2ui = OpVariable %_ptr_Private_uint Private
+%uint_1 = OpConstant %uint 1
+%uint_0 = OpConstant %uint 0
%s2f = OpVariable %_ptr_Private_float Private
%i2f = OpVariable %_ptr_Private_float Private
%us2f = OpVariable %_ptr_Private_float Private
%ui2f = OpVariable %_ptr_Private_float Private
%h2f = OpVariable %_ptr_Private_float Private
%f2f = OpVariable %_ptr_Private_float Private
+%b2f = OpVariable %_ptr_Private_float Private
+%float_0 = OpConstant %float 0
%void = OpTypeVoid
-%113 = OpTypeFunction %void
+%138 = OpTypeFunction %void
%_ptr_Output_float = OpTypePointer Output %float
-%int_0 = OpConstant %int 0
-%main = OpFunction %void None %113
-%114 = OpLabel
-%14 = OpExtInst %float %1 Sqrt %float_1
-%13 = OpConvertFToS %int %14
-OpStore %s %13
-%18 = OpExtInst %float %1 Sqrt %float_1
-%17 = OpConvertFToS %int %18
-OpStore %i %17
-%23 = OpExtInst %float %1 Sqrt %float_1
-%22 = OpConvertFToU %uint %23
-OpStore %us %22
+%main = OpFunction %void None %138
+%139 = OpLabel
+OpStore %b %true
+%17 = OpExtInst %float %1 Sqrt %float_1
+%16 = OpConvertFToS %int %17
+OpStore %s %16
+%21 = OpExtInst %float %1 Sqrt %float_1
+%20 = OpConvertFToS %int %21
+OpStore %i %20
%26 = OpExtInst %float %1 Sqrt %float_1
%25 = OpConvertFToU %uint %26
-OpStore %ui %25
+OpStore %us %25
%29 = OpExtInst %float %1 Sqrt %float_1
-OpStore %h %29
-%31 = OpExtInst %float %1 Sqrt %float_1
-OpStore %f %31
-%33 = OpLoad %int %s
-OpStore %s2s %33
-%35 = OpLoad %int %i
-OpStore %i2s %35
-%38 = OpLoad %uint %us
-%37 = OpBitcast %int %38
-OpStore %us2s %37
-%41 = OpLoad %uint %ui
+%28 = OpConvertFToU %uint %29
+OpStore %ui %28
+%32 = OpExtInst %float %1 Sqrt %float_1
+OpStore %h %32
+%34 = OpExtInst %float %1 Sqrt %float_1
+OpStore %f %34
+%36 = OpLoad %int %s
+OpStore %s2s %36
+%38 = OpLoad %int %i
+OpStore %i2s %38
+%41 = OpLoad %uint %us
%40 = OpBitcast %int %41
-OpStore %ui2s %40
-%44 = OpLoad %float %h
-%43 = OpConvertFToS %int %44
-OpStore %h2s %43
-%47 = OpLoad %float %f
+OpStore %us2s %40
+%44 = OpLoad %uint %ui
+%43 = OpBitcast %int %44
+OpStore %ui2s %43
+%47 = OpLoad %float %h
%46 = OpConvertFToS %int %47
-OpStore %f2s %46
-%49 = OpLoad %int %s
-OpStore %s2i %49
-%51 = OpLoad %int %i
-OpStore %i2i %51
-%54 = OpLoad %uint %us
-%53 = OpBitcast %int %54
-OpStore %us2i %53
-%57 = OpLoad %uint %ui
-%56 = OpBitcast %int %57
-OpStore %ui2i %56
-%60 = OpLoad %float %h
-%59 = OpConvertFToS %int %60
-OpStore %h2i %59
-%63 = OpLoad %float %f
-%62 = OpConvertFToS %int %63
-OpStore %f2i %62
-%66 = OpLoad %int %s
-%65 = OpBitcast %uint %66
-OpStore %s2us %65
-%69 = OpLoad %int %i
-%68 = OpBitcast %uint %69
-OpStore %i2us %68
-%71 = OpLoad %uint %us
-OpStore %us2us %71
-%73 = OpLoad %uint %ui
-OpStore %ui2us %73
-%76 = OpLoad %float %h
-%75 = OpConvertFToU %uint %76
-OpStore %h2us %75
-%79 = OpLoad %float %f
-%78 = OpConvertFToU %uint %79
-OpStore %f2us %78
-%82 = OpLoad %int %s
-%81 = OpBitcast %uint %82
-OpStore %s2ui %81
-%85 = OpLoad %int %i
-%84 = OpBitcast %uint %85
-OpStore %i2ui %84
-%87 = OpLoad %uint %us
-OpStore %us2ui %87
-%89 = OpLoad %uint %ui
-OpStore %ui2ui %89
-%92 = OpLoad %float %h
-%91 = OpConvertFToU %uint %92
-OpStore %h2ui %91
-%95 = OpLoad %float %f
-%94 = OpConvertFToU %uint %95
-OpStore %f2ui %94
+OpStore %h2s %46
+%50 = OpLoad %float %f
+%49 = OpConvertFToS %int %50
+OpStore %f2s %49
+%52 = OpLoad %bool %b
+%53 = OpSelect %int %52 %int_1 %int_0
+OpStore %b2s %53
+%57 = OpLoad %int %s
+OpStore %s2i %57
+%59 = OpLoad %int %i
+OpStore %i2i %59
+%62 = OpLoad %uint %us
+%61 = OpBitcast %int %62
+OpStore %us2i %61
+%65 = OpLoad %uint %ui
+%64 = OpBitcast %int %65
+OpStore %ui2i %64
+%68 = OpLoad %float %h
+%67 = OpConvertFToS %int %68
+OpStore %h2i %67
+%71 = OpLoad %float %f
+%70 = OpConvertFToS %int %71
+OpStore %f2i %70
+%73 = OpLoad %bool %b
+%74 = OpSelect %int %73 %int_1 %int_0
+OpStore %b2i %74
+%77 = OpLoad %int %s
+%76 = OpBitcast %uint %77
+OpStore %s2us %76
+%80 = OpLoad %int %i
+%79 = OpBitcast %uint %80
+OpStore %i2us %79
+%82 = OpLoad %uint %us
+OpStore %us2us %82
+%84 = OpLoad %uint %ui
+OpStore %ui2us %84
+%87 = OpLoad %float %h
+%86 = OpConvertFToU %uint %87
+OpStore %h2us %86
+%90 = OpLoad %float %f
+%89 = OpConvertFToU %uint %90
+OpStore %f2us %89
+%92 = OpLoad %bool %b
+%94 = OpBitcast %uint %int_1
+%95 = OpBitcast %uint %int_0
+%93 = OpSelect %uint %92 %94 %95
+OpStore %b2us %93
%98 = OpLoad %int %s
-%97 = OpConvertSToF %float %98
-OpStore %s2f %97
+%97 = OpBitcast %uint %98
+OpStore %s2ui %97
%101 = OpLoad %int %i
-%100 = OpConvertSToF %float %101
-OpStore %i2f %100
-%104 = OpLoad %uint %us
-%103 = OpConvertUToF %float %104
-OpStore %us2f %103
-%107 = OpLoad %uint %ui
-%106 = OpConvertUToF %float %107
-OpStore %ui2f %106
-%109 = OpLoad %float %h
-OpStore %h2f %109
+%100 = OpBitcast %uint %101
+OpStore %i2ui %100
+%103 = OpLoad %uint %us
+OpStore %us2ui %103
+%105 = OpLoad %uint %ui
+OpStore %ui2ui %105
+%108 = OpLoad %float %h
+%107 = OpConvertFToU %uint %108
+OpStore %h2ui %107
%111 = OpLoad %float %f
-OpStore %f2f %111
-%116 = OpLoad %int %s
-%117 = OpLoad %int %i
-%118 = OpIAdd %int %116 %117
-%120 = OpLoad %uint %us
-%119 = OpBitcast %int %120
-%121 = OpIAdd %int %118 %119
-%115 = OpConvertSToF %float %121
-%123 = OpLoad %uint %ui
-%122 = OpConvertUToF %float %123
-%124 = OpFAdd %float %115 %122
-%125 = OpLoad %float %h
-%126 = OpFAdd %float %124 %125
-%127 = OpLoad %float %f
-%128 = OpFAdd %float %126 %127
-%130 = OpLoad %int %s2s
-%129 = OpConvertSToF %float %130
-%131 = OpFAdd %float %128 %129
-%133 = OpLoad %int %i2s
-%132 = OpConvertSToF %float %133
-%134 = OpFAdd %float %131 %132
-%136 = OpLoad %int %us2s
-%135 = OpConvertSToF %float %136
-%137 = OpFAdd %float %134 %135
-%139 = OpLoad %int %ui2s
-%138 = OpConvertSToF %float %139
-%140 = OpFAdd %float %137 %138
-%142 = OpLoad %int %h2s
-%141 = OpConvertSToF %float %142
-%143 = OpFAdd %float %140 %141
-%145 = OpLoad %int %f2s
-%144 = OpConvertSToF %float %145
-%146 = OpFAdd %float %143 %144
-%148 = OpLoad %int %s2i
-%147 = OpConvertSToF %float %148
-%149 = OpFAdd %float %146 %147
-%151 = OpLoad %int %i2i
-%150 = OpConvertSToF %float %151
-%152 = OpFAdd %float %149 %150
-%154 = OpLoad %int %us2i
-%153 = OpConvertSToF %float %154
-%155 = OpFAdd %float %152 %153
-%157 = OpLoad %int %ui2i
-%156 = OpConvertSToF %float %157
-%158 = OpFAdd %float %155 %156
-%160 = OpLoad %int %h2i
-%159 = OpConvertSToF %float %160
-%161 = OpFAdd %float %158 %159
-%163 = OpLoad %int %f2i
-%162 = OpConvertSToF %float %163
-%164 = OpFAdd %float %161 %162
-%166 = OpLoad %uint %s2us
-%165 = OpConvertUToF %float %166
-%167 = OpFAdd %float %164 %165
-%169 = OpLoad %uint %i2us
-%168 = OpConvertUToF %float %169
-%170 = OpFAdd %float %167 %168
-%172 = OpLoad %uint %us2us
-%171 = OpConvertUToF %float %172
-%173 = OpFAdd %float %170 %171
-%174 = OpAccessChain %_ptr_Output_float %sk_FragColor %int_0
-OpStore %174 %173
-%177 = OpAccessChain %_ptr_Output_float %sk_FragColor %int_0
-%178 = OpLoad %float %177
-%180 = OpLoad %uint %ui2us
-%181 = OpLoad %uint %h2us
-%182 = OpIAdd %uint %180 %181
-%183 = OpLoad %uint %f2us
-%184 = OpIAdd %uint %182 %183
-%179 = OpConvertUToF %float %184
-%186 = OpLoad %uint %s2ui
-%185 = OpConvertUToF %float %186
-%187 = OpFAdd %float %179 %185
-%189 = OpLoad %uint %i2ui
-%188 = OpConvertUToF %float %189
-%190 = OpFAdd %float %187 %188
-%192 = OpLoad %uint %us2ui
-%191 = OpConvertUToF %float %192
-%193 = OpFAdd %float %190 %191
-%195 = OpLoad %uint %ui2ui
-%194 = OpConvertUToF %float %195
-%196 = OpFAdd %float %193 %194
-%198 = OpLoad %uint %h2ui
-%197 = OpConvertUToF %float %198
-%199 = OpFAdd %float %196 %197
-%201 = OpLoad %uint %f2ui
-%200 = OpConvertUToF %float %201
-%202 = OpFAdd %float %199 %200
-%203 = OpLoad %float %s2f
-%204 = OpFAdd %float %202 %203
-%205 = OpLoad %float %i2f
-%206 = OpFAdd %float %204 %205
-%207 = OpLoad %float %us2f
-%208 = OpFAdd %float %206 %207
-%209 = OpLoad %float %ui2f
-%210 = OpFAdd %float %208 %209
-%211 = OpLoad %float %h2f
-%212 = OpFAdd %float %210 %211
-%213 = OpLoad %float %f2f
-%214 = OpFAdd %float %212 %213
-%215 = OpFAdd %float %178 %214
-OpStore %177 %215
+%110 = OpConvertFToU %uint %111
+OpStore %f2ui %110
+%113 = OpLoad %bool %b
+%114 = OpSelect %uint %113 %uint_1 %uint_0
+OpStore %b2ui %114
+%119 = OpLoad %int %s
+%118 = OpConvertSToF %float %119
+OpStore %s2f %118
+%122 = OpLoad %int %i
+%121 = OpConvertSToF %float %122
+OpStore %i2f %121
+%125 = OpLoad %uint %us
+%124 = OpConvertUToF %float %125
+OpStore %us2f %124
+%128 = OpLoad %uint %ui
+%127 = OpConvertUToF %float %128
+OpStore %ui2f %127
+%130 = OpLoad %float %h
+OpStore %h2f %130
+%132 = OpLoad %float %f
+OpStore %f2f %132
+%134 = OpLoad %bool %b
+%135 = OpSelect %float %134 %float_1 %float_0
+OpStore %b2f %135
+%141 = OpLoad %int %s
+%142 = OpLoad %int %i
+%143 = OpIAdd %int %141 %142
+%145 = OpLoad %uint %us
+%144 = OpBitcast %int %145
+%146 = OpIAdd %int %143 %144
+%140 = OpConvertSToF %float %146
+%148 = OpLoad %uint %ui
+%147 = OpConvertUToF %float %148
+%149 = OpFAdd %float %140 %147
+%150 = OpLoad %float %h
+%151 = OpFAdd %float %149 %150
+%152 = OpLoad %float %f
+%153 = OpFAdd %float %151 %152
+%155 = OpLoad %int %s2s
+%154 = OpConvertSToF %float %155
+%156 = OpFAdd %float %153 %154
+%158 = OpLoad %int %i2s
+%157 = OpConvertSToF %float %158
+%159 = OpFAdd %float %156 %157
+%161 = OpLoad %int %us2s
+%160 = OpConvertSToF %float %161
+%162 = OpFAdd %float %159 %160
+%164 = OpLoad %int %ui2s
+%163 = OpConvertSToF %float %164
+%165 = OpFAdd %float %162 %163
+%167 = OpLoad %int %h2s
+%166 = OpConvertSToF %float %167
+%168 = OpFAdd %float %165 %166
+%170 = OpLoad %int %f2s
+%169 = OpConvertSToF %float %170
+%171 = OpFAdd %float %168 %169
+%173 = OpLoad %int %b2s
+%172 = OpConvertSToF %float %173
+%174 = OpFAdd %float %171 %172
+%176 = OpLoad %int %s2i
+%175 = OpConvertSToF %float %176
+%177 = OpFAdd %float %174 %175
+%179 = OpLoad %int %i2i
+%178 = OpConvertSToF %float %179
+%180 = OpFAdd %float %177 %178
+%182 = OpLoad %int %us2i
+%181 = OpConvertSToF %float %182
+%183 = OpFAdd %float %180 %181
+%185 = OpLoad %int %ui2i
+%184 = OpConvertSToF %float %185
+%186 = OpFAdd %float %183 %184
+%188 = OpLoad %int %h2i
+%187 = OpConvertSToF %float %188
+%189 = OpFAdd %float %186 %187
+%191 = OpLoad %int %f2i
+%190 = OpConvertSToF %float %191
+%192 = OpFAdd %float %189 %190
+%194 = OpLoad %int %b2i
+%193 = OpConvertSToF %float %194
+%195 = OpFAdd %float %192 %193
+%197 = OpLoad %uint %s2us
+%196 = OpConvertUToF %float %197
+%198 = OpFAdd %float %195 %196
+%200 = OpLoad %uint %i2us
+%199 = OpConvertUToF %float %200
+%201 = OpFAdd %float %198 %199
+%203 = OpLoad %uint %us2us
+%202 = OpConvertUToF %float %203
+%204 = OpFAdd %float %201 %202
+%205 = OpAccessChain %_ptr_Output_float %sk_FragColor %int_0
+OpStore %205 %204
+%207 = OpAccessChain %_ptr_Output_float %sk_FragColor %int_0
+%208 = OpLoad %float %207
+%210 = OpLoad %uint %ui2us
+%211 = OpLoad %uint %h2us
+%212 = OpIAdd %uint %210 %211
+%213 = OpLoad %uint %f2us
+%214 = OpIAdd %uint %212 %213
+%215 = OpLoad %uint %b2us
+%216 = OpIAdd %uint %214 %215
+%209 = OpConvertUToF %float %216
+%218 = OpLoad %uint %s2ui
+%217 = OpConvertUToF %float %218
+%219 = OpFAdd %float %209 %217
+%221 = OpLoad %uint %i2ui
+%220 = OpConvertUToF %float %221
+%222 = OpFAdd %float %219 %220
+%224 = OpLoad %uint %us2ui
+%223 = OpConvertUToF %float %224
+%225 = OpFAdd %float %222 %223
+%227 = OpLoad %uint %ui2ui
+%226 = OpConvertUToF %float %227
+%228 = OpFAdd %float %225 %226
+%230 = OpLoad %uint %h2ui
+%229 = OpConvertUToF %float %230
+%231 = OpFAdd %float %228 %229
+%233 = OpLoad %uint %f2ui
+%232 = OpConvertUToF %float %233
+%234 = OpFAdd %float %231 %232
+%236 = OpLoad %uint %b2ui
+%235 = OpConvertUToF %float %236
+%237 = OpFAdd %float %234 %235
+%238 = OpLoad %float %s2f
+%239 = OpFAdd %float %237 %238
+%240 = OpLoad %float %i2f
+%241 = OpFAdd %float %239 %240
+%242 = OpLoad %float %us2f
+%243 = OpFAdd %float %241 %242
+%244 = OpLoad %float %ui2f
+%245 = OpFAdd %float %243 %244
+%246 = OpLoad %float %h2f
+%247 = OpFAdd %float %245 %246
+%248 = OpLoad %float %f2f
+%249 = OpFAdd %float %247 %248
+%250 = OpLoad %float %b2f
+%251 = OpFAdd %float %249 %250
+%252 = OpFAdd %float %208 %251
+OpStore %207 %252
OpReturn
OpFunctionEnd
diff --git a/tests/sksl/shared/golden/NumberConversions.glsl b/tests/sksl/shared/golden/NumberConversions.glsl
index c38b42a..37b02c5 100644
--- a/tests/sksl/shared/golden/NumberConversions.glsl
+++ b/tests/sksl/shared/golden/NumberConversions.glsl
@@ -1,5 +1,6 @@
out vec4 sk_FragColor;
+bool b = true;
int s = int(sqrt(1.0));
int i = int(sqrt(1.0));
uint us = uint(sqrt(1.0));
@@ -12,31 +13,36 @@
int ui2s = int(ui);
int h2s = int(h);
int f2s = int(f);
+int b2s = b ? 1 : 0;
int s2i = s;
int i2i = i;
int us2i = int(us);
int ui2i = int(ui);
int h2i = int(h);
int f2i = int(f);
+int b2i = b ? 1 : 0;
uint s2us = uint(s);
uint i2us = uint(i);
uint us2us = us;
uint ui2us = ui;
uint h2us = uint(h);
uint f2us = uint(f);
+uint b2us = b ? uint(1) : uint(0);
uint s2ui = uint(s);
uint i2ui = uint(i);
uint us2ui = us;
uint ui2ui = ui;
uint h2ui = uint(h);
uint f2ui = uint(f);
+uint b2ui = b ? 1u : 0u;
float s2f = float(s);
float i2f = float(i);
float us2f = float(us);
float ui2f = float(ui);
float h2f = h;
float f2f = f;
+float b2f = b ? 1.0 : 0.0;
void main() {
- sk_FragColor.x = (((((((((((((((((float((s + i) + int(us)) + float(ui)) + h) + f) + float(s2s)) + float(i2s)) + float(us2s)) + float(ui2s)) + float(h2s)) + float(f2s)) + float(s2i)) + float(i2i)) + float(us2i)) + float(ui2i)) + float(h2i)) + float(f2i)) + float(s2us)) + float(i2us)) + float(us2us);
- sk_FragColor.x += (((((((((((float((ui2us + h2us) + f2us) + float(s2ui)) + float(i2ui)) + float(us2ui)) + float(ui2ui)) + float(h2ui)) + float(f2ui)) + s2f) + i2f) + us2f) + ui2f) + h2f) + f2f;
+ sk_FragColor.x = (((((((((((((((((((float((s + i) + int(us)) + float(ui)) + h) + f) + float(s2s)) + float(i2s)) + float(us2s)) + float(ui2s)) + float(h2s)) + float(f2s)) + float(b2s)) + float(s2i)) + float(i2i)) + float(us2i)) + float(ui2i)) + float(h2i)) + float(f2i)) + float(b2i)) + float(s2us)) + float(i2us)) + float(us2us);
+ sk_FragColor.x += (((((((((((((float(((ui2us + h2us) + f2us) + b2us) + float(s2ui)) + float(i2ui)) + float(us2ui)) + float(ui2ui)) + float(h2ui)) + float(f2ui)) + float(b2ui)) + s2f) + i2f) + us2f) + ui2f) + h2f) + f2f) + b2f;
}
diff --git a/tests/sksl/shared/golden/NumberConversions.metal b/tests/sksl/shared/golden/NumberConversions.metal
index 1869dc6..9a813b1 100644
--- a/tests/sksl/shared/golden/NumberConversions.metal
+++ b/tests/sksl/shared/golden/NumberConversions.metal
@@ -7,6 +7,7 @@
float4 sk_FragColor [[color(0)]];
};
struct Globals {
+ bool b;
short s;
int i;
ushort us;
@@ -19,30 +20,35 @@
short ui2s;
short h2s;
short f2s;
+ short b2s;
int s2i;
int i2i;
int us2i;
int ui2i;
int h2i;
int f2i;
+ int b2i;
ushort s2us;
ushort i2us;
ushort us2us;
ushort ui2us;
ushort h2us;
ushort f2us;
+ ushort b2us;
uint s2ui;
uint i2ui;
uint us2ui;
uint ui2ui;
uint h2ui;
uint f2ui;
+ uint b2ui;
float s2f;
float i2f;
float us2f;
float ui2f;
float h2f;
float f2f;
+ float b2f;
};
@@ -80,13 +86,19 @@
+
+
+
+
+
+
fragment Outputs fragmentMain(Inputs _in [[stage_in]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) {
- Globals globalStruct{short(sqrt(1.0)), int(sqrt(1.0)), ushort(sqrt(1.0)), uint(sqrt(1.0)), sqrt(1.0), sqrt(1.0), _globals->s, short(_globals->i), short(_globals->us), short(_globals->ui), short(_globals->h), short(_globals->f), int(_globals->s), _globals->i, int(_globals->us), int(_globals->ui), int(_globals->h), int(_globals->f), ushort(_globals->s), ushort(_globals->i), _globals->us, ushort(_globals->ui), ushort(_globals->h), ushort(_globals->f), uint(_globals->s), uint(_globals->i), uint(_globals->us), _globals->ui, uint(_globals->h), uint(_globals->f), float(_globals->s), float(_globals->i), float(_globals->us), float(_globals->ui), _globals->h, _globals->f};
+ Globals globalStruct{true, short(sqrt(1.0)), int(sqrt(1.0)), ushort(sqrt(1.0)), uint(sqrt(1.0)), sqrt(1.0), sqrt(1.0), _globals->s, short(_globals->i), short(_globals->us), short(_globals->ui), short(_globals->h), short(_globals->f), _globals->b ? short(1) : short(0), int(_globals->s), _globals->i, int(_globals->us), int(_globals->ui), int(_globals->h), int(_globals->f), _globals->b ? 1 : 0, ushort(_globals->s), ushort(_globals->i), _globals->us, ushort(_globals->ui), ushort(_globals->h), ushort(_globals->f), _globals->b ? ushort(1) : ushort(0), uint(_globals->s), uint(_globals->i), uint(_globals->us), _globals->ui, uint(_globals->h), uint(_globals->f), _globals->b ? 1u : 0u, float(_globals->s), float(_globals->i), float(_globals->us), float(_globals->ui), _globals->h, _globals->f, _globals->b ? 1.0 : 0.0};
thread Globals* _globals = &globalStruct;
(void)_globals;
Outputs _outputStruct;
thread Outputs* _out = &_outputStruct;
- _out->sk_FragColor.x = (((((((((((((((((float((int(_globals->s) + _globals->i) + int(_globals->us)) + float(_globals->ui)) + _globals->h) + _globals->f) + float(_globals->s2s)) + float(_globals->i2s)) + float(_globals->us2s)) + float(_globals->ui2s)) + float(_globals->h2s)) + float(_globals->f2s)) + float(_globals->s2i)) + float(_globals->i2i)) + float(_globals->us2i)) + float(_globals->ui2i)) + float(_globals->h2i)) + float(_globals->f2i)) + float(_globals->s2us)) + float(_globals->i2us)) + float(_globals->us2us);
- _out->sk_FragColor.x = _out->sk_FragColor.x + (((((((((((float((_globals->ui2us + _globals->h2us) + _globals->f2us) + float(_globals->s2ui)) + float(_globals->i2ui)) + float(_globals->us2ui)) + float(_globals->ui2ui)) + float(_globals->h2ui)) + float(_globals->f2ui)) + _globals->s2f) + _globals->i2f) + _globals->us2f) + _globals->ui2f) + _globals->h2f) + _globals->f2f;
+ _out->sk_FragColor.x = (((((((((((((((((((float((int(_globals->s) + _globals->i) + int(_globals->us)) + float(_globals->ui)) + _globals->h) + _globals->f) + float(_globals->s2s)) + float(_globals->i2s)) + float(_globals->us2s)) + float(_globals->ui2s)) + float(_globals->h2s)) + float(_globals->f2s)) + float(_globals->b2s)) + float(_globals->s2i)) + float(_globals->i2i)) + float(_globals->us2i)) + float(_globals->ui2i)) + float(_globals->h2i)) + float(_globals->f2i)) + float(_globals->b2i)) + float(_globals->s2us)) + float(_globals->i2us)) + float(_globals->us2us);
+ _out->sk_FragColor.x = _out->sk_FragColor.x + (((((((((((((float(((_globals->ui2us + _globals->h2us) + _globals->f2us) + _globals->b2us) + float(_globals->s2ui)) + float(_globals->i2ui)) + float(_globals->us2ui)) + float(_globals->ui2ui)) + float(_globals->h2ui)) + float(_globals->f2ui)) + float(_globals->b2ui)) + _globals->s2f) + _globals->i2f) + _globals->us2f) + _globals->ui2f) + _globals->h2f) + _globals->f2f) + _globals->b2f;
return *_out;
}