1#!amber
2# Copyright 2022 Google LLC
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#     http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16DEVICE_FEATURE sampleRateShading
17
18SHADER vertex vert_shader GLSL
19#version 440
20layout(location = 0) in vec4 inPosNDC;
21layout(location = 1) in vec2 inPosScreen;
22layout(location = 0) out vec2 outPosScreenArr[10];
23
24void main (void)
25{
26    gl_Position = inPosNDC;
27
28    for (int i = 0; i < 10; i++)
29        outPosScreenArr[i] = inPosScreen + vec2(i);
30}
31END
32
33SHADER fragment frag_shader GLSL
34#version 440
35layout(location = 0) sample in vec2 inPosScreenArr[10];
36layout(location = 0) out vec4 fs_out_color;
37
38void main (void)
39{
40    vec2 offset = vec2(0.75, -0.33);
41    int index = int(gl_FragCoord.x) % 10;
42    vec2 ref = interpolateAtOffset(inPosScreenArr[0], offset) + vec2(index);
43
44    if (distance(ref, interpolateAtOffset(inPosScreenArr[index], offset)) < 0.01
45        && abs(ref.y - interpolateAtOffset(inPosScreenArr[index].y, offset)) < 0.01
46        && abs(ref.y - interpolateAtOffset(inPosScreenArr[index], offset)).y < 0.01)
47    {
48        fs_out_color = vec4(0.0, 1.0, 0.0, 1.0);
49    }
50    else
51    {
52        fs_out_color = vec4(1.0, 0.0, 0.0, 1.0);
53    }
54}
55END
56
57BUFFER position DATA_TYPE vec4<float> DATA
58-1.0 -1.0 0.0 1.0
59 1.0 -1.0 0.0 1.0
60 1.0  1.0 0.0 1.0
61-1.0  1.0 0.0 1.0
62END
63
64BUFFER position_screen DATA_TYPE vec2<float> DATA
65 0.0  0.0
6664.0  0.0
6764.0 64.0
68 0.0 64.0
69END
70
71IMAGE framebufferMS FORMAT R8G8B8A8_UNORM DIM_2D WIDTH 64 HEIGHT 64 SAMPLES 4
72IMAGE framebuffer FORMAT R8G8B8A8_UNORM DIM_2D WIDTH 64 HEIGHT 64
73
74PIPELINE graphics pipeline
75  ATTACH vert_shader
76  ATTACH frag_shader
77  VERTEX_DATA position LOCATION 0
78  VERTEX_DATA position_screen LOCATION 1
79  FRAMEBUFFER_SIZE 64 64
80  BIND BUFFER framebufferMS AS color LOCATION 0
81  BIND BUFFER framebuffer AS resolve
82END
83
84RUN pipeline DRAW_ARRAY AS TRIANGLE_FAN START_IDX 0 COUNT 4
85EXPECT framebuffer IDX 0 0 SIZE 64 64 EQ_RGBA 0 255 0 255
86