3 # Copyright 2020 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.
18 # A test for a bug found by the GraphicsFuzz project.
20 # Short description: A fragment shader with clamped float in determinant matrix
22 # The test passes because both shaders render the same image.
24 SHADER vertex reference_vertex_shader PASSTHROUGH
26 # reference_fragment_shader is derived from the following GLSL:
28 # precision highp float;
30 # precision highp int;
32 # layout(location = 0) out vec4 _GLF_color;
34 # layout(set = 0, binding = 0) uniform buf0
38 # float compute_value(float limit, float thirty_two)
40 # float result = -0.5;
41 # for (int i = 1; i < 800; i++)
49 # if (mod(float(i), round(thirty_two)) <= 0.01)
54 # if (float(i) >= limit)
63 # vec3 c = vec3(7.0, 8.0, 9.0);
64 # float thirty_two = round(resolution.x / 8.0);
65 # c.x = compute_value(gl_FragCoord.x, thirty_two);
66 # c.y = compute_value(gl_FragCoord.y, thirty_two);
68 # for (int i = 0; i < 3; i++)
75 # _GLF_color = vec4(normalize(abs(c)), 1.0);
77 SHADER fragment reference_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
80 ; Generator: Khronos Glslang Reference Front End; 10
84 %1 = OpExtInstImport "GLSL.std.450"
85 OpMemoryModel Logical GLSL450
86 OpEntryPoint Fragment %4 "main" %85 %137
87 OpExecutionMode %4 OriginUpperLeft
90 OpName %11 "compute_value(f1;f1;"
92 OpName %10 "thirty_two"
96 OpName %71 "thirty_two"
98 OpMemberName %73 0 "resolution"
100 OpName %85 "gl_FragCoord"
106 OpName %137 "_GLF_color"
107 OpMemberDecorate %73 0 Offset 0
109 OpDecorate %75 DescriptorSet 0
110 OpDecorate %75 Binding 0
111 OpDecorate %85 BuiltIn FragCoord
112 OpDecorate %137 Location 0
114 %3 = OpTypeFunction %2
116 %7 = OpTypePointer Function %6
117 %8 = OpTypeFunction %6 %7 %7
118 %14 = OpConstant %6 -0.5
120 %16 = OpTypePointer Function %15
121 %18 = OpConstant %15 1
122 %25 = OpConstant %15 800
124 %29 = OpConstant %15 32
125 %31 = OpConstant %15 0
126 %35 = OpConstant %6 0.400000006
127 %44 = OpConstant %6 0.00999999978
128 %48 = OpConstant %6 100
129 %64 = OpTypeVector %6 3
130 %65 = OpTypePointer Function %64
131 %67 = OpConstant %6 7
132 %68 = OpConstant %6 8
133 %69 = OpConstant %6 9
134 %70 = OpConstantComposite %64 %67 %68 %69
135 %72 = OpTypeVector %6 2
136 %73 = OpTypeStruct %72
137 %74 = OpTypePointer Uniform %73
138 %75 = OpVariable %74 Uniform
140 %77 = OpConstant %76 0
141 %78 = OpTypePointer Uniform %6
142 %83 = OpTypeVector %6 4
143 %84 = OpTypePointer Input %83
144 %85 = OpVariable %84 Input
145 %87 = OpTypePointer Input %6
146 %95 = OpConstant %76 1
147 %107 = OpConstant %76 2
148 %116 = OpConstant %15 3
149 %121 = OpConstant %6 1
150 %136 = OpTypePointer Output %83
151 %137 = OpVariable %136 Output
152 %4 = OpFunction %2 None %3
154 %66 = OpVariable %65 Function
155 %71 = OpVariable %7 Function
156 %86 = OpVariable %7 Function
157 %90 = OpVariable %7 Function
158 %94 = OpVariable %7 Function
159 %98 = OpVariable %7 Function
160 %109 = OpVariable %16 Function
162 %79 = OpAccessChain %78 %75 %31 %77
164 %81 = OpFDiv %6 %80 %68
165 %82 = OpExtInst %6 %1 Round %81
167 %88 = OpAccessChain %87 %85 %77
172 %92 = OpFunctionCall %6 %11 %86 %90
173 %93 = OpAccessChain %7 %66 %77
175 %96 = OpAccessChain %87 %85 %95
180 %100 = OpFunctionCall %6 %11 %94 %98
181 %101 = OpAccessChain %7 %66 %95
183 %102 = OpAccessChain %7 %66 %77
184 %103 = OpLoad %6 %102
185 %104 = OpAccessChain %7 %66 %95
186 %105 = OpLoad %6 %104
187 %106 = OpFAdd %6 %103 %105
188 %108 = OpAccessChain %7 %66 %107
193 OpLoopMerge %112 %113 None
196 %115 = OpLoad %15 %109
197 %117 = OpSLessThan %26 %115 %116
198 OpBranchConditional %117 %111 %112
200 %118 = OpLoad %15 %109
201 %119 = OpAccessChain %7 %66 %118
202 %120 = OpLoad %6 %119
203 %122 = OpFOrdGreaterThanEqual %26 %120 %121
204 OpSelectionMerge %124 None
205 OpBranchConditional %122 %123 %124
207 %125 = OpLoad %15 %109
208 %126 = OpLoad %15 %109
209 %127 = OpAccessChain %7 %66 %126
210 %128 = OpLoad %6 %127
211 %129 = OpLoad %15 %109
212 %130 = OpAccessChain %7 %66 %129
213 %131 = OpLoad %6 %130
214 %132 = OpFMul %6 %128 %131
215 %133 = OpAccessChain %7 %66 %125
221 %134 = OpLoad %15 %109
222 %135 = OpIAdd %15 %134 %18
226 %138 = OpLoad %64 %66
227 %139 = OpExtInst %64 %1 FAbs %138
228 %140 = OpExtInst %64 %1 Normalize %139
229 %141 = OpCompositeExtract %6 %140 0
230 %142 = OpCompositeExtract %6 %140 1
231 %143 = OpCompositeExtract %6 %140 2
232 %144 = OpCompositeConstruct %83 %141 %142 %143 %121
236 %11 = OpFunction %6 None %8
237 %9 = OpFunctionParameter %7
238 %10 = OpFunctionParameter %7
240 %13 = OpVariable %7 Function
241 %17 = OpVariable %16 Function
246 OpLoopMerge %21 %22 None
250 %27 = OpSLessThan %26 %24 %25
251 OpBranchConditional %27 %20 %21
254 %30 = OpSMod %15 %28 %29
255 %32 = OpIEqual %26 %30 %31
256 OpSelectionMerge %34 None
257 OpBranchConditional %32 %33 %38
260 %37 = OpFAdd %6 %36 %35
265 %40 = OpConvertSToF %6 %39
267 %42 = OpExtInst %6 %1 Round %41
268 %43 = OpFMod %6 %40 %42
269 %45 = OpFOrdLessThanEqual %26 %43 %44
270 OpSelectionMerge %47 None
271 OpBranchConditional %45 %46 %47
274 %50 = OpFAdd %6 %49 %48
281 %52 = OpConvertSToF %6 %51
283 %54 = OpFOrdGreaterThanEqual %26 %52 %53
284 OpSelectionMerge %56 None
285 OpBranchConditional %54 %55 %56
293 %60 = OpIAdd %15 %59 %18
302 # uniforms for reference
305 BUFFER reference_resolution DATA_TYPE vec2<float> STD140 DATA
309 BUFFER reference_framebuffer FORMAT B8G8R8A8_UNORM
311 PIPELINE graphics reference_pipeline
312 ATTACH reference_vertex_shader
313 ATTACH reference_fragment_shader
314 FRAMEBUFFER_SIZE 256 256
315 BIND BUFFER reference_framebuffer AS color LOCATION 0
316 BIND BUFFER reference_resolution AS uniform DESCRIPTOR_SET 0 BINDING 0
318 CLEAR_COLOR reference_pipeline 0 0 0 255
320 CLEAR reference_pipeline
321 RUN reference_pipeline DRAW_RECT POS 0 0 SIZE 256 256
324 SHADER vertex variant_vertex_shader PASSTHROUGH
326 # variant_fragment_shader is derived from the following GLSL:
328 # precision highp float;
330 # precision highp int;
332 # layout(location = 0) out vec4 _GLF_color;
334 # layout(set = 0, binding = 0) uniform buf0
338 # float compute_value(float limit, float thirty_two)
340 # float result = -0.5;
341 # for (int i = 1; i < 800; i++)
349 # if (mod(float(i), round(thirty_two)) <= 0.01)
354 # if (float(i) >= limit)
357 # float clamp_a = clamp((1.0), (1.0), ((gl_FragCoord.y < 0.0) ? (-1.0) : (false ? exp(result) : 1.0)));
359 # float det_a = determinant(mat4(1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, clamp_a));
360 # // Type casting matrix to float takes the first value in matrix.
361 # // float_a == result
362 # float float_a = float(mat4x3(((result) / det_a), 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 1.0));
371 # vec3 c = vec3(7.0, 8.0, 9.0);
372 # float thirty_two = round(resolution.x / 8.0);
373 # c.x = compute_value(gl_FragCoord.x, thirty_two);
374 # c.y = compute_value(gl_FragCoord.y, thirty_two);
376 # for (int i = 0; i < 3; i++)
380 # c[i] = c[i] * c[i];
383 # _GLF_color = vec4(normalize(abs(c)), 1.0);
385 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
388 ; Generator: Khronos Glslang Reference Front End; 10
392 %1 = OpExtInstImport "GLSL.std.450"
393 OpMemoryModel Logical GLSL450
394 OpEntryPoint Fragment %4 "main" %61 %177
395 OpExecutionMode %4 OriginUpperLeft
398 OpName %11 "compute_value(f1;f1;"
400 OpName %10 "thirty_two"
404 OpName %61 "gl_FragCoord"
408 OpName %118 "thirty_two"
410 OpMemberName %120 0 "resolution"
417 OpName %177 "_GLF_color"
418 OpDecorate %61 BuiltIn FragCoord
419 OpMemberDecorate %120 0 Offset 0
420 OpDecorate %120 Block
421 OpDecorate %122 DescriptorSet 0
422 OpDecorate %122 Binding 0
423 OpDecorate %177 Location 0
425 %3 = OpTypeFunction %2
427 %7 = OpTypePointer Function %6
428 %8 = OpTypeFunction %6 %7 %7
429 %14 = OpConstant %6 -0.5
431 %16 = OpTypePointer Function %15
432 %18 = OpConstant %15 1
433 %25 = OpConstant %15 800
435 %29 = OpConstant %15 32
436 %31 = OpConstant %15 0
437 %35 = OpConstant %6 0.400000006
438 %44 = OpConstant %6 0.00999999978
439 %48 = OpConstant %6 100
440 %58 = OpConstant %6 1
441 %59 = OpTypeVector %6 4
442 %60 = OpTypePointer Input %59
443 %61 = OpVariable %60 Input
445 %63 = OpConstant %62 1
446 %64 = OpTypePointer Input %6
447 %67 = OpConstant %6 0
448 %72 = OpConstant %6 -1
449 %74 = OpConstantFalse %26
450 %86 = OpTypeMatrix %59 4
451 %97 = OpTypeVector %6 3
452 %98 = OpTypeMatrix %97 4
453 %112 = OpTypePointer Function %97
454 %114 = OpConstant %6 7
455 %115 = OpConstant %6 8
456 %116 = OpConstant %6 9
457 %117 = OpConstantComposite %97 %114 %115 %116
458 %119 = OpTypeVector %6 2
459 %120 = OpTypeStruct %119
460 %121 = OpTypePointer Uniform %120
461 %122 = OpVariable %121 Uniform
462 %123 = OpConstant %62 0
463 %124 = OpTypePointer Uniform %6
464 %148 = OpConstant %62 2
465 %157 = OpConstant %15 3
466 %176 = OpTypePointer Output %59
467 %177 = OpVariable %176 Output
468 %4 = OpFunction %2 None %3
470 %113 = OpVariable %112 Function
471 %118 = OpVariable %7 Function
472 %129 = OpVariable %7 Function
473 %132 = OpVariable %7 Function
474 %136 = OpVariable %7 Function
475 %139 = OpVariable %7 Function
476 %150 = OpVariable %16 Function
478 %125 = OpAccessChain %124 %122 %31 %123
479 %126 = OpLoad %6 %125
480 %127 = OpFDiv %6 %126 %115
481 %128 = OpExtInst %6 %1 Round %127
483 %130 = OpAccessChain %64 %61 %123
484 %131 = OpLoad %6 %130
486 %133 = OpLoad %6 %118
488 %134 = OpFunctionCall %6 %11 %129 %132
489 %135 = OpAccessChain %7 %113 %123
491 %137 = OpAccessChain %64 %61 %63
492 %138 = OpLoad %6 %137
494 %140 = OpLoad %6 %118
496 %141 = OpFunctionCall %6 %11 %136 %139
497 %142 = OpAccessChain %7 %113 %63
499 %143 = OpAccessChain %7 %113 %123
500 %144 = OpLoad %6 %143
501 %145 = OpAccessChain %7 %113 %63
502 %146 = OpLoad %6 %145
503 %147 = OpFAdd %6 %144 %146
504 %149 = OpAccessChain %7 %113 %148
509 OpLoopMerge %153 %154 None
512 %156 = OpLoad %15 %150
513 %158 = OpSLessThan %26 %156 %157
514 OpBranchConditional %158 %152 %153
516 %159 = OpLoad %15 %150
517 %160 = OpAccessChain %7 %113 %159
518 %161 = OpLoad %6 %160
519 %162 = OpFOrdGreaterThanEqual %26 %161 %58
520 OpSelectionMerge %164 None
521 OpBranchConditional %162 %163 %164
523 %165 = OpLoad %15 %150
524 %166 = OpLoad %15 %150
525 %167 = OpAccessChain %7 %113 %166
526 %168 = OpLoad %6 %167
527 %169 = OpLoad %15 %150
528 %170 = OpAccessChain %7 %113 %169
529 %171 = OpLoad %6 %170
530 %172 = OpFMul %6 %168 %171
531 %173 = OpAccessChain %7 %113 %165
537 %174 = OpLoad %15 %150
538 %175 = OpIAdd %15 %174 %18
542 %178 = OpLoad %97 %113
543 %179 = OpExtInst %97 %1 FAbs %178
544 %180 = OpExtInst %97 %1 Normalize %179
545 %181 = OpCompositeExtract %6 %180 0
546 %182 = OpCompositeExtract %6 %180 1
547 %183 = OpCompositeExtract %6 %180 2
548 %184 = OpCompositeConstruct %59 %181 %182 %183 %58
552 %11 = OpFunction %6 None %8
553 %9 = OpFunctionParameter %7
554 %10 = OpFunctionParameter %7
556 %13 = OpVariable %7 Function
557 %17 = OpVariable %16 Function
558 %57 = OpVariable %7 Function
559 %69 = OpVariable %7 Function
560 %75 = OpVariable %7 Function
561 %84 = OpVariable %7 Function
562 %93 = OpVariable %7 Function
567 OpLoopMerge %21 %22 None
571 %27 = OpSLessThan %26 %24 %25
572 OpBranchConditional %27 %20 %21
575 %30 = OpSMod %15 %28 %29
576 %32 = OpIEqual %26 %30 %31
577 OpSelectionMerge %34 None
578 OpBranchConditional %32 %33 %38
581 %37 = OpFAdd %6 %36 %35
586 %40 = OpConvertSToF %6 %39
588 %42 = OpExtInst %6 %1 Round %41
589 %43 = OpFMod %6 %40 %42
590 %45 = OpFOrdLessThanEqual %26 %43 %44
591 OpSelectionMerge %47 None
592 OpBranchConditional %45 %46 %47
595 %50 = OpFAdd %6 %49 %48
602 %52 = OpConvertSToF %6 %51
604 %54 = OpFOrdGreaterThanEqual %26 %52 %53
605 OpSelectionMerge %56 None
606 OpBranchConditional %54 %55 %56
608 %65 = OpAccessChain %64 %61 %63
610 %68 = OpFOrdLessThan %26 %66 %67
611 OpSelectionMerge %71 None
612 OpBranchConditional %68 %70 %73
617 OpSelectionMerge %77 None
618 OpBranchConditional %74 %76 %80
621 %79 = OpExtInst %6 %1 Exp %78
633 %83 = OpExtInst %6 %1 FClamp %58 %58 %82
636 %87 = OpCompositeConstruct %59 %58 %58 %58 %58
637 %88 = OpCompositeConstruct %59 %67 %58 %58 %67
638 %89 = OpCompositeConstruct %59 %67 %67 %58 %67
639 %90 = OpCompositeConstruct %59 %67 %67 %67 %85
640 %91 = OpCompositeConstruct %86 %87 %88 %89 %90
641 %92 = OpExtInst %6 %1 Determinant %91
645 %96 = OpFDiv %6 %94 %95
646 %99 = OpCompositeConstruct %97 %96 %67 %67
647 %100 = OpCompositeConstruct %97 %67 %67 %67
648 %101 = OpCompositeConstruct %97 %67 %58 %58
649 %102 = OpCompositeConstruct %97 %58 %67 %58
650 %103 = OpCompositeConstruct %98 %99 %100 %101 %102
651 %104 = OpCompositeExtract %6 %103 0 0
658 %107 = OpLoad %15 %17
659 %108 = OpIAdd %15 %107 %18
668 # uniforms for variant
671 BUFFER variant_resolution DATA_TYPE vec2<float> STD140 DATA
675 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
677 PIPELINE graphics variant_pipeline
678 ATTACH variant_vertex_shader
679 ATTACH variant_fragment_shader
680 FRAMEBUFFER_SIZE 256 256
681 BIND BUFFER variant_framebuffer AS color LOCATION 0
682 BIND BUFFER variant_resolution AS uniform DESCRIPTOR_SET 0 BINDING 0
684 CLEAR_COLOR variant_pipeline 0 0 0 255
686 CLEAR variant_pipeline
687 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
689 EXPECT reference_framebuffer EQ_HISTOGRAM_EMD_BUFFER variant_framebuffer TOLERANCE 0.005