xref: /aosp_15_r20/external/skia/tests/sksl/shared/VectorScalarMath.wgsl (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1diagnostic(off, derivative_uniformity);
2diagnostic(off, chromium.unreachable_code);
3struct FSOut {
4  @location(0) sk_FragColor: vec4<f32>,
5};
6struct _GlobalUniforms {
7  colorRed: vec4<f32>,
8  colorGreen: vec4<f32>,
9  unknownInput: f32,
10};
11@binding(0) @group(0) var<uniform> _globalUniforms: _GlobalUniforms;
12fn test_int_b() -> bool {
13  {
14    var ok: bool = true;
15    let inputRed: vec4<i32> = vec4<i32>(_globalUniforms.colorRed);
16    let inputGreen: vec4<i32> = vec4<i32>(_globalUniforms.colorGreen);
17    var x: vec4<i32> = inputRed + 2;
18    ok = ok && all(x == vec4<i32>(3, 2, 2, 3));
19    x = inputGreen.ywxz - 2;
20    ok = ok && all(x == vec4<i32>(-1, -1, -2, -2));
21    x = inputRed + inputGreen.y;
22    ok = ok && all(x == vec4<i32>(2, 1, 1, 2));
23    x = vec4<i32>((inputGreen.wyw * 9), x.w);
24    ok = ok && all(x == vec4<i32>(9, 9, 9, 2));
25    x = vec4<i32>((x.zw / 4), x.zw);
26    ok = ok && all(x == vec4<i32>(2, 0, 9, 2));
27    x = (inputRed * 5).yxwz;
28    ok = ok && all(x == vec4<i32>(0, 5, 5, 0));
29    x = 2 + inputRed;
30    ok = ok && all(x == vec4<i32>(3, 2, 2, 3));
31    x = 10 - inputGreen.ywxz;
32    ok = ok && all(x == vec4<i32>(9, 9, 10, 10));
33    x = inputRed.x + inputGreen;
34    ok = ok && all(x == vec4<i32>(1, 2, 1, 2));
35    x = vec4<i32>((8 * inputGreen.wyw), x.w);
36    ok = ok && all(x == vec4<i32>(8, 8, 8, 2));
37    x = vec4<i32>((36 / x.zw), x.zw);
38    ok = ok && all(x == vec4<i32>(4, 18, 8, 2));
39    x = (37 / x).yxwz;
40    ok = ok && all(x == vec4<i32>(2, 9, 18, 4));
41    x = x + 2;
42    x = x * 2;
43    x = x - 4;
44    x = x / 2;
45    ok = ok && all(x == vec4<i32>(2, 9, 18, 4));
46    x = x + 2;
47    x = x * 2;
48    x = x - 4;
49    x = x / 2;
50    ok = ok && all(x == vec4<i32>(2, 9, 18, 4));
51    return ok;
52  }
53}
54fn _skslMain(coords: vec2<f32>) -> vec4<f32> {
55  {
56    var _0_ok: bool = true;
57    let _1_inputRed: vec4<f32> = _globalUniforms.colorRed;
58    let _2_inputGreen: vec4<f32> = _globalUniforms.colorGreen;
59    var _3_x: vec4<f32> = _1_inputRed + 2.0;
60    _0_ok = _0_ok && all(_3_x == vec4<f32>(3.0, 2.0, 2.0, 3.0));
61    _3_x = _2_inputGreen.ywxz - 2.0;
62    _0_ok = _0_ok && all(_3_x == vec4<f32>(-1.0, -1.0, -2.0, -2.0));
63    _3_x = _1_inputRed + _2_inputGreen.y;
64    _0_ok = _0_ok && all(_3_x == vec4<f32>(2.0, 1.0, 1.0, 2.0));
65    _3_x = vec4<f32>((_2_inputGreen.wyw * 9.0), _3_x.w);
66    _0_ok = _0_ok && all(_3_x == vec4<f32>(9.0, 9.0, 9.0, 2.0));
67    _3_x = vec4<f32>((_3_x.zw * 2.0), _3_x.zw);
68    _0_ok = _0_ok && all(_3_x == vec4<f32>(18.0, 4.0, 9.0, 2.0));
69    _3_x = (_1_inputRed * 5.0).yxwz;
70    _0_ok = _0_ok && all(_3_x == vec4<f32>(0.0, 5.0, 5.0, 0.0));
71    _3_x = 2.0 + _1_inputRed;
72    _0_ok = _0_ok && all(_3_x == vec4<f32>(3.0, 2.0, 2.0, 3.0));
73    _3_x = 10.0 - _2_inputGreen.ywxz;
74    _0_ok = _0_ok && all(_3_x == vec4<f32>(9.0, 9.0, 10.0, 10.0));
75    _3_x = _1_inputRed.x + _2_inputGreen;
76    _0_ok = _0_ok && all(_3_x == vec4<f32>(1.0, 2.0, 1.0, 2.0));
77    _3_x = vec4<f32>((8.0 * _2_inputGreen.wyw), _3_x.w);
78    _0_ok = _0_ok && all(_3_x == vec4<f32>(8.0, 8.0, 8.0, 2.0));
79    _3_x = vec4<f32>((32.0 / _3_x.zw), _3_x.zw);
80    _0_ok = _0_ok && all(_3_x == vec4<f32>(4.0, 16.0, 8.0, 2.0));
81    _3_x = (32.0 / _3_x).yxwz;
82    _0_ok = _0_ok && all(_3_x == vec4<f32>(2.0, 8.0, 16.0, 4.0));
83    _3_x = _3_x + 2.0;
84    _3_x = _3_x * 2.0;
85    _3_x = _3_x - 4.0;
86    _3_x = _3_x * 0.5;
87    _0_ok = _0_ok && all(_3_x == vec4<f32>(2.0, 8.0, 16.0, 4.0));
88    _3_x = _3_x + 2.0;
89    _3_x = _3_x * 2.0;
90    _3_x = _3_x - 4.0;
91    _3_x = _3_x * 0.5;
92    _0_ok = _0_ok && all(_3_x == vec4<f32>(2.0, 8.0, 16.0, 4.0));
93    var _skTemp0: vec4<f32>;
94    var _skTemp1: bool;
95    if _0_ok {
96      let _skTemp2 = test_int_b();
97      _skTemp1 = _skTemp2;
98    } else {
99      _skTemp1 = false;
100    }
101    if _skTemp1 {
102      _skTemp0 = _globalUniforms.colorGreen;
103    } else {
104      _skTemp0 = _globalUniforms.colorRed;
105    }
106    return _skTemp0;
107  }
108}
109@fragment fn main() -> FSOut {
110  var _stageOut: FSOut;
111  _stageOut.sk_FragColor = _skslMain(/*fragcoord*/ vec2<f32>());
112  return _stageOut;
113}
114