• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!amber
2
3# Copyright 2021 Google LLC
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#     http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17# Division by zero test. Specification states:
18#
19# "Some calculations require division. In such cases (including implied divisions performed by
20#  vector normalization), division by zero produces an unspecified result but must not lead to
21#  Vulkan interruption or termination."
22#
23# This test performs various divisions (both implicit and explicit) and succeeds if it doesn't crash.
24
25SHADER vertex vert_shader PASSTHROUGH
26SHADER fragment frag_shader GLSL
27#version 430
28layout(location = 0) out vec4 color_out;
29void main() {
30  ivec4 ifragcoord = ivec4(gl_FragCoord);
31  vec4 fragcoord = vec4(ifragcoord);
32  // Generate one pixel we can be certain about
33  if (ifragcoord.x == 0 && ifragcoord.y == 0)
34  {
35    color_out = vec4(1.0, 0.0, 0.0, 1.0);
36  }
37  else
38  {
39    // Generate sweep of values which hit 0 as divisor.
40    // When ifragcoord.y hits 8, the integer case becomes "7 / (8 - 8)"
41    switch(ifragcoord.x % 32)
42    {
43    case 0:
44      // int div
45      color_out = vec4(7 / (ifragcoord.y - 8), 1.0, 0.0, 1.0);
46      break;
47    case 1:
48      // float div
49      color_out = vec4(7 / (fragcoord.y - 8.0), 1.0, 0.0, 1.0);
50      break;
51    case 2:
52      // normalize float
53      color_out = vec4(normalize(fragcoord.y - 8.0), 1.0, 0.0, 1.0);
54      break;
55    case 3:
56      // normalize vec2
57      color_out = vec4(normalize(fragcoord.yy - vec2(8.0)), 0.0, 1.0);
58      break;
59    case 4:
60      // normalize vec3
61      color_out = vec4(normalize(fragcoord.yyy - vec3(8.0)), 1.0);
62      break;
63    case 5:
64      // normalize vec4
65      color_out = normalize(fragcoord.yyyy - vec4(8.0));
66      break;
67    case 6:
68      // integer mod
69      color_out = vec4((7 % (ifragcoord.y - 8)), 1.0, 0.0, 1.0);
70      break;
71    case 7:
72      // float mod
73      color_out = vec4(mod(7.0, (fragcoord.y - 8.0)), 1.0, 0.0, 1.0);
74      break;
75    case 8:
76      // vec2 mod
77      color_out = vec4(mod(vec2(7.0), (fragcoord.yy - vec2(8.0))), 0.0, 1.0);
78      break;
79     case 9:
80      // vec3 mod
81      color_out = vec4(mod(vec3(7.0), (fragcoord.yyy - vec3(8.0))), 1.0);
82      break;
83    case 10:
84      // vec4 mod
85      color_out = mod(vec4(7.0), (fragcoord.yyyy - vec4(8.0)));
86      break;
87    case 11:
88      // float smoothstep
89      color_out = vec4(smoothstep(7.0, (fragcoord.y - 8.0), 0.3), 1.0, 0.0, 1.0);
90      break;
91    case 12:
92      // vec2 smoothstep
93      color_out = vec4(smoothstep(vec2(7.0), vec2(fragcoord.y - 8.0), vec2(0.3)), 0.0, 1.0);
94      break;
95    case 13:
96      // vec3 smoothstep
97      color_out = vec4(smoothstep(vec3(7.0), vec3(fragcoord.y - 8.0), vec3(0.3)), 1.0);
98      break;
99    case 14:
100      // vec4 smoothstep
101      color_out = smoothstep(vec4(7.0), vec4(fragcoord.y - 8.0), vec4(0.3));
102      break;
103    case 15:
104      // float atan2
105      color_out = vec4(atan(7.0, (fragcoord.y - 8.0)), 1.0, 0.0, 1.0);
106      break;
107    case 16:
108      // vec2 atan2
109      color_out = vec4(atan(vec2(7.0), (fragcoord.yy - vec2(8.0))), 0.0, 1.0);
110      break;
111    case 17:
112      // vec3 atan2
113      color_out = vec4(atan(vec3(7.0), (fragcoord.yyy - vec3(8.0))), 1.0);
114      break;
115    case 18:
116      // vec4 atan2
117      color_out = atan(vec4(7.0), (fragcoord.yyyy - vec4(8.0)));
118      break;
119    default:
120      color_out = vec4(0.0, 0.0, 1.0, 1.0);
121    }
122  }
123}
124END
125
126BUFFER framebuffer FORMAT B8G8R8A8_UNORM
127
128PIPELINE graphics my_pipeline
129  ATTACH vert_shader
130  ATTACH frag_shader
131  BIND BUFFER framebuffer AS color LOCATION 0
132END
133
134RUN my_pipeline DRAW_RECT POS 0 0 SIZE 32 32
135# Check that the pixel we expect is fine
136EXPECT framebuffer IDX 0 0 SIZE 1 1 EQ_RGBA 255 0 0 255
137