xref: /aosp_15_r20/external/skia/tests/sksl/shared/SampleLocations.wgsl (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1diagnostic(off, derivative_uniformity);
2diagnostic(off, chromium.unreachable_code);
3struct VSIn {
4  @builtin(instance_index) sk_InstanceID: u32,
5  @builtin(vertex_index) sk_VertexID: u32,
6};
7struct VSOut {
8  @builtin(position) sk_Position: vec4<f32>,
9  @location(1) @interpolate(linear) vcoord_Stage0: vec2<f32>,
10};
11/* unsupported */ var<private> sk_PointSize: f32;
12fn _skslMain(_stageIn: VSIn, _stageOut: ptr<function, VSOut>) {
13  {
14    let x: i32 = i32(_stageIn.sk_InstanceID) % 200;
15    let y: i32 = i32(_stageIn.sk_InstanceID) / 200;
16    let ileft: i32 = (i32(_stageIn.sk_InstanceID) * 929) % 17;
17    let iright: i32 = (ileft + 1) + (i32(_stageIn.sk_InstanceID) * 1637) % (17 - ileft);
18    let itop: i32 = (i32(_stageIn.sk_InstanceID) * 313) % 17;
19    let ibot: i32 = (itop + 1) + (i32(_stageIn.sk_InstanceID) * 1901) % (17 - itop);
20    var outset: f32 = 0.03125;
21    outset = select(outset, -outset, 0 == ((x + y) % 2));
22    let l: f32 = f32(ileft) * 0.0625 - outset;
23    let r: f32 = f32(iright) * 0.0625 + outset;
24    let t: f32 = f32(itop) * 0.0625 - outset;
25    let b: f32 = f32(ibot) * 0.0625 + outset;
26    var vertexpos: vec2<f32>;
27    vertexpos.x = f32(x) + (select(r, l, 0 == (i32(_stageIn.sk_VertexID) % 2)));
28    vertexpos.y = f32(y) + (select(b, t, 0 == (i32(_stageIn.sk_VertexID) / 2)));
29    (*_stageOut).vcoord_Stage0.x = f32(select(1, -1, 0 == (i32(_stageIn.sk_VertexID) % 2)));
30    (*_stageOut).vcoord_Stage0.y = f32(select(1, -1, 0 == (i32(_stageIn.sk_VertexID) / 2)));
31    (*_stageOut).sk_Position = vec4<f32>(vertexpos.x, vertexpos.y, 0.0, 1.0);
32  }
33}
34@vertex fn main(_stageIn: VSIn) -> VSOut {
35  var _stageOut: VSOut;
36  _skslMain(_stageIn, &_stageOut);
37  return _stageOut;
38}
39