3 # Copyright 2021 Google LLC
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
9 # http://www.apache.org/licenses/LICENSE-2.0
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.
17 # Division by zero test. Specification states:
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."
23 # This test performs various divisions (both implicit and explicit) and succeeds if it doesn't crash.
25 SHADER vertex vert_shader PASSTHROUGH
26 SHADER fragment frag_shader GLSL
28 layout(location = 0) out vec4 color_out;
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)
35 color_out = vec4(1.0, 0.0, 0.0, 1.0);
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)
45 color_out = vec4(7 / (ifragcoord.y - 8), 1.0, 0.0, 1.0);
49 color_out = vec4(7 / (fragcoord.y - 8.0), 1.0, 0.0, 1.0);
53 color_out = vec4(normalize(fragcoord.y - 8.0), 1.0, 0.0, 1.0);
57 color_out = vec4(normalize(fragcoord.yy - vec2(8.0)), 0.0, 1.0);
61 color_out = vec4(normalize(fragcoord.yyy - vec3(8.0)), 1.0);
65 color_out = normalize(fragcoord.yyyy - vec4(8.0));
69 color_out = vec4((7 % (ifragcoord.y - 8)), 1.0, 0.0, 1.0);
73 color_out = vec4(mod(7.0, (fragcoord.y - 8.0)), 1.0, 0.0, 1.0);
77 color_out = vec4(mod(vec2(7.0), (fragcoord.yy - vec2(8.0))), 0.0, 1.0);
81 color_out = vec4(mod(vec3(7.0), (fragcoord.yyy - vec3(8.0))), 1.0);
85 color_out = mod(vec4(7.0), (fragcoord.yyyy - vec4(8.0)));
89 color_out = vec4(smoothstep(7.0, (fragcoord.y - 8.0), 0.3), 1.0, 0.0, 1.0);
93 color_out = vec4(smoothstep(vec2(7.0), vec2(fragcoord.y - 8.0), vec2(0.3)), 0.0, 1.0);
97 color_out = vec4(smoothstep(vec3(7.0), vec3(fragcoord.y - 8.0), vec3(0.3)), 1.0);
101 color_out = smoothstep(vec4(7.0), vec4(fragcoord.y - 8.0), vec4(0.3));
105 color_out = vec4(atan(7.0, (fragcoord.y - 8.0)), 1.0, 0.0, 1.0);
109 color_out = vec4(atan(vec2(7.0), (fragcoord.yy - vec2(8.0))), 0.0, 1.0);
113 color_out = vec4(atan(vec3(7.0), (fragcoord.yyy - vec3(8.0))), 1.0);
117 color_out = atan(vec4(7.0), (fragcoord.yyyy - vec4(8.0)));
120 color_out = vec4(0.0, 0.0, 1.0, 1.0);
126 BUFFER framebuffer FORMAT B8G8R8A8_UNORM
128 PIPELINE graphics my_pipeline
131 BIND BUFFER framebuffer AS color LOCATION 0
134 RUN my_pipeline DRAW_RECT POS 0 0 SIZE 32 32
135 # Check that the pixel we expect is fine
136 EXPECT framebuffer IDX 0 0 SIZE 1 1 EQ_RGBA 255 0 0 255