skia2/tests/sksl/shared/NumberConversions.sksl
John Stiles ab8ed92a0c 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>
2021-01-05 16:30:11 +00:00

51 lines
1.3 KiB
Plaintext

bool b = true;
short s = short(sqrt(1));
int i = int(sqrt(1));
ushort us = ushort(sqrt(1));
uint ui = uint(sqrt(1));
half h = half(sqrt(1));
float f = sqrt(1);
short s2s = s;
short i2s = short(i);
short us2s = short(us);
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 +
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);
}