1#!amber
2# Copyright 2020 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
16SHADER vertex vert_shader GLSL
17#version 430
18layout(location = 0) in vec2 position_in;
19layout(location = 1) in vec4 color_in[3];
20layout(location = 0) smooth out vec4 color_out[3];
21
22void main()
23{
24    gl_Position = vec4(position_in, 0, 1);
25    for (int i = 0; i < 3; i++)
26        color_out[i] = color_in[i];
27}
28END
29
30SHADER fragment frag_shader GLSL
31#version 430
32layout(location = 0) smooth in vec4 color_in[3];
33layout(location = 0) out mediump vec2 frag_out[3];
34void main()
35{
36    for (int i = 0; i < 3; i++)
37        frag_out[i] = color_in[i].xy;
38}
39END
40
41SHADER vertex vert_shader_ref GLSL
42#version 430
43layout(location = 0) in vec2 position_in;
44layout(location = 1) in vec4 color_in;
45layout(location = 0) smooth out vec4 color_out;
46
47void main()
48{
49	gl_Position = vec4(position_in, 0, 1);
50    color_out = color_in;
51}
52END
53
54SHADER fragment frag_shader_ref GLSL
55#version 430
56layout(location = 0) smooth in vec4 color_in;
57layout(location = 0) out mediump vec2 frag_out;
58void main()
59{
60    frag_out = color_in.xy;
61}
62END
63
64SHADER vertex vert_shader_verify GLSL
65#version 430
66layout(location = 0) in vec2 position_in;
67layout(location = 1) in vec2 texcoord_in;
68layout(location = 0) out vec2 texcoord_out;
69
70void main()
71{
72    gl_Position = vec4(position_in, 0, 1);
73    texcoord_out = texcoord_in;
74}
75END
76
77SHADER fragment frag_shader_verify GLSL
78#version 430
79layout(location = 0) in vec2 texcoord_in;
80layout(location = 0) out vec4 frag_out;
81uniform layout(set=0, binding=0) sampler2D result_sampler;
82uniform layout(set=0, binding=1) sampler2D ref_sampler;
83void main()
84{
85    vec2 result = texture(result_sampler, texcoord_in).xy;
86    vec2 ref = texture(ref_sampler, texcoord_in).xy;
87    if (distance(result, ref) > 0.1)
88        frag_out = vec4(1, 0, 0, 1);
89    else
90        frag_out = vec4(0, 1, 0, 1);
91}
92END
93
94BUFFER framebuffer0 FORMAT B8G8R8A8_UNORM
95BUFFER framebuffer1 FORMAT B8G8R8A8_UNORM
96BUFFER framebuffer2 FORMAT B8G8R8A8_UNORM
97
98BUFFER ref0 FORMAT B8G8R8A8_UNORM
99BUFFER ref1 FORMAT B8G8R8A8_UNORM
100BUFFER ref2 FORMAT B8G8R8A8_UNORM
101
102BUFFER result0 FORMAT B8G8R8A8_UNORM
103BUFFER result1 FORMAT B8G8R8A8_UNORM
104BUFFER result2 FORMAT B8G8R8A8_UNORM
105
106BUFFER position DATA_TYPE vec2<float> DATA
107-1.0 -1.0
108 1.0 -1.0
109 1.0  1.0
110-1.0  1.0
111END
112
113BUFFER texcoord DATA_TYPE vec2<float> DATA
1140.0 0.0
1151.0 0.0
1161.0 1.0
1170.0 1.0
118END
119
120BUFFER color0 DATA_TYPE B8G8R8A8_UNORM DATA
121255   0   0 255
122  0 255   0 255
123  0   0 255 255
124255 255   0 255
125END
126
127BUFFER color1 DATA_TYPE B8G8R8A8_UNORM DATA
128  0 255   0 255
129  0   0 255 255
130255 255   0 255
131255   0   0 255
132END
133
134BUFFER color2 DATA_TYPE B8G8R8A8_UNORM DATA
135  0   0 255 255
136255 255   0 255
137255   0   0 255
138  0 255   0 255
139END
140
141
142SAMPLER sampler
143
144PIPELINE graphics pipeline
145  ATTACH vert_shader
146  ATTACH frag_shader
147  VERTEX_DATA position LOCATION 0
148  VERTEX_DATA color0 LOCATION 1
149  VERTEX_DATA color1 LOCATION 2
150  VERTEX_DATA color2 LOCATION 3
151  BIND BUFFER framebuffer0 AS color LOCATION 0
152  BIND BUFFER framebuffer1 AS color LOCATION 1
153  BIND BUFFER framebuffer2 AS color LOCATION 2
154  FRAMEBUFFER_SIZE 60 60
155END
156
157PIPELINE graphics pipeline_ref0
158  ATTACH vert_shader_ref
159  ATTACH frag_shader_ref
160  VERTEX_DATA position LOCATION 0
161  VERTEX_DATA color0 LOCATION 1
162  BIND BUFFER ref0 AS color LOCATION 0
163  FRAMEBUFFER_SIZE 60 60
164END
165
166PIPELINE graphics pipeline_ref1
167  ATTACH vert_shader_ref
168  ATTACH frag_shader_ref
169  VERTEX_DATA position LOCATION 0
170  VERTEX_DATA color1 LOCATION 1
171  BIND BUFFER ref1 AS color LOCATION 0
172  FRAMEBUFFER_SIZE 60 60
173END
174
175PIPELINE graphics pipeline_ref2
176  ATTACH vert_shader_ref
177  ATTACH frag_shader_ref
178  VERTEX_DATA position LOCATION 0
179  VERTEX_DATA color2 LOCATION 1
180  BIND BUFFER ref2 AS color LOCATION 0
181  FRAMEBUFFER_SIZE 60 60
182END
183
184PIPELINE graphics pipeline_verify0
185  ATTACH vert_shader_verify
186  ATTACH frag_shader_verify
187  VERTEX_DATA position LOCATION 0
188  VERTEX_DATA texcoord LOCATION 1
189  BIND BUFFER framebuffer0 AS combined_image_sampler SAMPLER sampler DESCRIPTOR_SET 0 BINDING 0
190  BIND BUFFER ref0 AS combined_image_sampler SAMPLER sampler DESCRIPTOR_SET 0 BINDING 1
191  BIND BUFFER result0 AS color LOCATION 0
192  FRAMEBUFFER_SIZE 60 60
193END
194
195PIPELINE graphics pipeline_verify1
196  ATTACH vert_shader_verify
197  ATTACH frag_shader_verify
198  VERTEX_DATA position LOCATION 0
199  VERTEX_DATA texcoord LOCATION 1
200  BIND BUFFER framebuffer1 AS combined_image_sampler SAMPLER sampler DESCRIPTOR_SET 0 BINDING 0
201  BIND BUFFER ref1 AS combined_image_sampler SAMPLER sampler DESCRIPTOR_SET 0 BINDING 1
202  BIND BUFFER result1 AS color LOCATION 0
203  FRAMEBUFFER_SIZE 60 60
204END
205
206PIPELINE graphics pipeline_verify2
207  ATTACH vert_shader_verify
208  ATTACH frag_shader_verify
209  VERTEX_DATA position LOCATION 0
210  VERTEX_DATA texcoord LOCATION 1
211  BIND BUFFER framebuffer2 AS combined_image_sampler SAMPLER sampler DESCRIPTOR_SET 0 BINDING 0
212  BIND BUFFER ref2 AS combined_image_sampler SAMPLER sampler DESCRIPTOR_SET 0 BINDING 1
213  BIND BUFFER result2 AS color LOCATION 0
214  FRAMEBUFFER_SIZE 60 60
215END
216
217CLEAR_COLOR pipeline 0 0 0 0
218CLEAR pipeline
219RUN pipeline DRAW_ARRAY AS TRIANGLE_FAN START_IDX 0 COUNT 4
220CLEAR_COLOR pipeline_ref0 0 0 0 0
221CLEAR pipeline_ref0
222RUN pipeline_ref0 DRAW_ARRAY AS TRIANGLE_FAN START_IDX 0 COUNT 4
223CLEAR_COLOR pipeline_ref1 0 0 0 0
224CLEAR pipeline_ref1
225RUN pipeline_ref1 DRAW_ARRAY AS TRIANGLE_FAN START_IDX 0 COUNT 4
226CLEAR_COLOR pipeline_ref2 0 0 0 0
227CLEAR pipeline_ref2
228RUN pipeline_ref2 DRAW_ARRAY AS TRIANGLE_FAN START_IDX 0 COUNT 4
229CLEAR_COLOR pipeline_verify0 0 0 0 0
230CLEAR pipeline_verify0
231RUN pipeline_verify0 DRAW_ARRAY AS TRIANGLE_FAN START_IDX 0 COUNT 4
232CLEAR_COLOR pipeline_verify1 0 0 0 0
233CLEAR pipeline_verify1
234RUN pipeline_verify1 DRAW_ARRAY AS TRIANGLE_FAN START_IDX 0 COUNT 4
235CLEAR_COLOR pipeline_verify2 0 0 0 0
236CLEAR pipeline_verify2
237RUN pipeline_verify2 DRAW_ARRAY AS TRIANGLE_FAN START_IDX 0 COUNT 4
238
239EXPECT result0 IDX 0 0 SIZE 60 60 EQ_RGBA 0 255 0 255
240EXPECT result1 IDX 0 0 SIZE 60 60 EQ_RGBA 0 255 0 255
241EXPECT result2 IDX 0 0 SIZE 60 60 EQ_RGBA 0 255 0 255
242