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 compute compute_shader GLSL
17#version 430
18layout(local_size_x=10, local_size_y=10) in;
19uniform layout (set=0, binding=0, r11f_g11f_b10f) image2D texture;
20
21void main ()
22{
23    ivec2 uv = ivec2(gl_GlobalInvocationID.xy);
24    vec4 color = vec4(uv.x - uv.y, uv.y, -uv.y, 1);
25    imageStore(texture, uv, color);
26}
27END
28
29SHADER compute compute_shader_verify GLSL
30#version 430
31layout(local_size_x=1, local_size_y=1) in;
32uniform layout (set=0, binding=0, r11f_g11f_b10f) image2D texture;
33layout(binding = 1) buffer Buf1
34{
35    int result;
36};
37
38void main ()
39{
40  result = 1;
41
42  for (int y = 0; y < 50; y++)
43      for (int x = 0; x < 50; x++)
44      {
45          ivec2 uv = ivec2(x, y);
46          vec4 color = imageLoad(texture, uv);
47          // Conversion to tiny float should clamp negative values to zero,
48          // thus the max operation here.
49          vec4 ref = max(vec4(uv.x - uv.y, uv.y, -uv.y, 1), vec4(0));
50
51          if (color != ref)
52              result = 0;
53      }
54}
55END
56
57IMAGE texture FORMAT B10G11R11_UFLOAT_PACK32 DIM_2D WIDTH 50 HEIGHT 50 FILL 0
58BUFFER result DATA_TYPE int32 SIZE 1 FILL 0
59
60PIPELINE compute pipeline
61  ATTACH compute_shader
62  BIND BUFFER texture AS storage_image DESCRIPTOR_SET 0 BINDING 0
63END
64
65PIPELINE compute verify
66  ATTACH compute_shader_verify
67  BIND BUFFER texture AS storage_image DESCRIPTOR_SET 0 BINDING 0
68  BIND BUFFER result AS storage DESCRIPTOR_SET 0 BINDING 1
69END
70
71RUN pipeline 5 5 1
72RUN verify 1 1 1
73EXPECT result IDX 0 EQ 1
74