skia2/tests/sksl/intrinsics/Modf.glsl
John Stiles 14c3175d7a Add ES3 intrinsic modf to sksl_public.
The test has been improved and now covers a variety of values. Because
this intrinsic has side-effects (an out-param), we do not support
optimizing it or treating it as a constant-expression.

The modf documentation doesn't mention anything about constant-
expression support or lack thereof. Experimentally, modf is also not
treated as a constant-expression by Apple GLSL or glslang:

http://screen/4RWwYKr6vCjxCPQ
http://screen/45ttDTVAFGDRyxP

Change-Id: I15bb1de80e90fa97ddf8e9d3803352603b9608d0
Bug: skia:12202
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/446396
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
2021-09-08 18:45:16 +00:00

22 lines
807 B
GLSL

out vec4 sk_FragColor;
uniform vec4 colorGreen;
uniform vec4 colorRed;
vec4 main() {
vec4 value = vec4(2.5, -2.5, 8.0, -0.125);
const vec4 expectedWhole = vec4(2.0, -2.0, 8.0, 0.0);
const vec4 expectedFraction = vec4(0.5, -0.5, 0.0, -0.125);
bvec4 ok = bvec4(false);
vec4 whole;
vec4 fraction;
fraction.x = modf(value.x, whole.x);
ok.x = whole.x == 2.0 && fraction.x == 0.5;
fraction.xy = modf(value.xy, whole.xy);
ok.y = whole.xy == vec2(2.0, -2.0) && fraction.xy == vec2(0.5, -0.5);
fraction.xyz = modf(value.xyz, whole.xyz);
ok.z = whole.xyz == vec3(2.0, -2.0, 8.0) && fraction.xyz == vec3(0.5, -0.5, 0.0);
fraction = modf(value, whole);
ok.w = whole == expectedWhole && fraction == expectedFraction;
return all(ok) ? colorGreen : colorRed;
}