skia2/resources/sksl/runtime/LoopFloat.rts
John Stiles 1991780081 Update LoopFloat/LoopInt tests to reduce hoisting.
Previously, none of our `runtime` tests relied on the input coordinate
in any way, so all of the logic was hoisted above the main loop in every
test. This CL adds an artificial reliance on the input coordinate so
that we have at least some SkVM tests with real code in the main loop.
This lets us see debug trace instructions interleaved with real code.

The input coordinate is clamped against a known uniform value
(`colorGreen` always contains 0101) so that the final test output
remains consistent in practice.

Additionally, I noticed that this test was only enabled in ES3, but
it doesn't seem to have anything ES3-specific in it, so it's now
enabled across the board.

Change-Id: Ie82f40b1060edb6071e300040ac59fb7d27094b0
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/470397
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
2021-11-12 13:45:59 +00:00

123 lines
3.2 KiB
Plaintext

/*#pragma settings SkVMDebugTrace*/
uniform half4 colorRed, colorGreen;
// Should return 5
const float kZero = 0;
float return_loop(float five) {
for (float i = kZero; i < 10; ++i) {
if (i == five) { return i; }
}
return 0;
}
// Should return 35
const float kTen = kZero + 10;
float continue_loop(float five) {
float sum = 0;
for (float i = 0; i < kTen; ++i) {
if (i < five) { continue; }
sum += i;
}
return sum;
}
// Should return 15
float break_loop(float five) {
float sum = 0;
const float kOne = 1;
for (float i = 0; i < 10; i += kOne) {
if (i > five) { break; }
sum += i;
}
return sum;
}
// Should return a value close to zero
float float_loop() {
float sum = 0;
for (float i = 0.123; i < 0.6; i += 0.111) {
sum += i;
}
return sum - 1.725;
}
bool loop_operator_le() {
// These loops are inside-out and execute zero times.
for (float i = 3; i <= 1; ++i) { return false; }
for (float i = 3; i <= 1; --i) { return false; }
float4 result = float4(9);
for (float i = 1; i <= 3; ++i) {
result = float4(result.yzw, i);
}
return result == float4(9, 1, 2, 3);
}
bool loop_operator_lt() {
// These loops are inside-out and execute zero times.
for (float i = 4; i < 1; ++i) { return false; }
for (float i = 4; i < 1; --i) { return false; }
float4 result = float4(9);
for (float i = 1; i < 4; ++i) {
result = float4(result.yzw, i);
}
return result == float4(9, 1, 2, 3);
}
bool loop_operator_ge() {
// These loops are inside-out and execute zero times.
for (float i = 1; i >= 3; ++i) { return false; }
for (float i = 1; i >= 3; --i) { return false; }
float4 result = float4(9);
for (float i = 3; i >= 1; --i) {
result = float4(result.yzw, i);
}
return result == float4(9, 3, 2, 1);
}
bool loop_operator_gt() {
// These loops are inside-out and execute zero times.
for (float i = 0; i > 3; ++i) { return false; }
for (float i = 0; i > 3; --i) { return false; }
float4 result = float4(9);
for (float i = 3; i > 0; --i) {
result = float4(result.yzw, i);
}
return result == float4(9, 3, 2, 1);
}
bool loop_operator_ne() {
// This loop executes zero times.
for (int i = 1; i != 1; ++i) { return false; }
float4 result = float4(9);
for (float i = 1; i != 4; ++i) {
result = float4(result.yzw, i);
}
return result == float4(9, 1, 2, 3);
}
bool loop_operator_eq() {
// This loops mismatches and executes zero times.
for (float i = 1; i == 2; ++i) { return false; }
float4 result = float4(9);
for (float i = 1; i == 1; ++i) {
result = float4(result.yzw, i);
}
return result == float4(9, 9, 9, 1);
}
half4 main(float2 pos) {
float five = clamp(pos.x, colorGreen.g, colorGreen.a) * 5.0;
return (return_loop(five) == 5 && continue_loop(five) == 35 &&
break_loop(five) == 15 && abs(float_loop()) < 0.025 &&
loop_operator_le() && loop_operator_lt() &&
loop_operator_ge() && loop_operator_gt() &&
loop_operator_eq() && loop_operator_ne()) ? colorGreen : colorRed;
}