26487162fe
Compiling a program with "allow narrowing conversions" actually fixes up narrowing casts in the program by inserting casts wherever they would be needed for type-correctness. For instance, compiling the statement `half h = myFloat;` inserts an appropriate narrowing cast: `half h = half(myFloat);`. The Pipeline stage code generator relies on this behavior, as when it re-emits a runtime effect into a complete SkSL program, the narrowing- conversions flag will no longer be set, but that is okay, because the emitted code now contains typecasts anywhere they would be necessary. Logically, this implies that anything which supports narrowing conversions must be castable between high and low precision. In GLSL and SPIR-V, such a cast is trivial, because the types are the same and the precision qualifiers are treated as individual hints on each variable. In Metal, we dodge the issue by only emitting full-precision types. But we also need to emit raw SkSL from an SkSL program (that is what the Pipeline stage generator does). SkSL already supported every typical cast, but GLSL lacked any syntax for casting an array to a different type. This meant SkSL had no array casting syntax as well. SkSL now has array-cast syntax, but it is only allowed for casting low/high-precision arrays to the same base type. (You can't cast an int array to float, or a signed array to unsigned.) Change-Id: Ia20933541c3bd4a946c1ea38209f93008acdb9cb Bug: skia:12248 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/437687 Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
23 lines
624 B
Plaintext
23 lines
624 B
Plaintext
/*#pragma settings UsesPrecisionModifiers*/
|
|
|
|
uniform half4 colorGreen, colorRed;
|
|
|
|
half4 main(float2 coords) {
|
|
float f[4] = float[4](1, 2, 3, 4);
|
|
half h[4] = half[4](f);
|
|
f = float[4](h);
|
|
h = half[4](f);
|
|
|
|
int3 i3[3] = int3[3](int3(1), int3(2), int3(3));
|
|
short3 s3[3] = short3[3](i3);
|
|
i3 = int3[3](s3);
|
|
s3 = short3[3](i3);
|
|
|
|
half2x2 h2x2[2] = half2x2[2](half2x2(1, 2, 3, 4), half2x2(5, 6, 7, 8));
|
|
float2x2 f2x2[2] = float2x2[2](h2x2);
|
|
f2x2 = float2x2[2](h2x2);
|
|
h2x2 = half2x2[2](f2x2);
|
|
|
|
return (f == h && i3 == s3 && f2x2 == h2x2) ? colorGreen : colorRed;
|
|
}
|