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 GraphicsFuzz.
20 # Short description: A fragment shader with vec3 values set from matrix4x2
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
39 # float compute_value(float limit, float thirty_two)
41 # float result = -0.5;
42 # for (int i = 1; i < 800; i++)
50 # if (mod(float(i), round(thirty_two)) <= 0.01)
55 # if (float(i) >= limit)
65 # vec3 c = vec3(7.0, 8.0, 9.0);
66 # float thirty_two = round(resolution.x / 8.0);
67 # c.x = compute_value(gl_FragCoord.x, thirty_two);
68 # c.y = compute_value(gl_FragCoord.y, thirty_two);
70 # for (int i = 0; i < 3; i++)
77 # _GLF_color = vec4(normalize(abs(c)), 1.0);
79 SHADER fragment reference_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
82 ; Generator: Khronos Glslang Reference Front End; 10
86 %1 = OpExtInstImport "GLSL.std.450"
87 OpMemoryModel Logical GLSL450
88 OpEntryPoint Fragment %4 "main" %85 %137
89 OpExecutionMode %4 OriginUpperLeft
92 OpName %11 "compute_value(f1;f1;"
94 OpName %10 "thirty_two"
98 OpName %71 "thirty_two"
100 OpMemberName %73 0 "resolution"
102 OpName %85 "gl_FragCoord"
108 OpName %137 "_GLF_color"
109 OpMemberDecorate %73 0 Offset 0
111 OpDecorate %75 DescriptorSet 0
112 OpDecorate %75 Binding 0
113 OpDecorate %85 BuiltIn FragCoord
114 OpDecorate %137 Location 0
116 %3 = OpTypeFunction %2
118 %7 = OpTypePointer Function %6
119 %8 = OpTypeFunction %6 %7 %7
120 %14 = OpConstant %6 -0.5
122 %16 = OpTypePointer Function %15
123 %18 = OpConstant %15 1
124 %25 = OpConstant %15 800
126 %29 = OpConstant %15 32
127 %31 = OpConstant %15 0
128 %35 = OpConstant %6 0.400000006
129 %44 = OpConstant %6 0.00999999978
130 %48 = OpConstant %6 100
131 %64 = OpTypeVector %6 3
132 %65 = OpTypePointer Function %64
133 %67 = OpConstant %6 7
134 %68 = OpConstant %6 8
135 %69 = OpConstant %6 9
136 %70 = OpConstantComposite %64 %67 %68 %69
137 %72 = OpTypeVector %6 2
138 %73 = OpTypeStruct %72
139 %74 = OpTypePointer Uniform %73
140 %75 = OpVariable %74 Uniform
142 %77 = OpConstant %76 0
143 %78 = OpTypePointer Uniform %6
144 %83 = OpTypeVector %6 4
145 %84 = OpTypePointer Input %83
146 %85 = OpVariable %84 Input
147 %87 = OpTypePointer Input %6
148 %95 = OpConstant %76 1
149 %107 = OpConstant %76 2
150 %116 = OpConstant %15 3
151 %121 = OpConstant %6 1
152 %136 = OpTypePointer Output %83
153 %137 = OpVariable %136 Output
154 %4 = OpFunction %2 None %3
156 %66 = OpVariable %65 Function
157 %71 = OpVariable %7 Function
158 %86 = OpVariable %7 Function
159 %90 = OpVariable %7 Function
160 %94 = OpVariable %7 Function
161 %98 = OpVariable %7 Function
162 %109 = OpVariable %16 Function
164 %79 = OpAccessChain %78 %75 %31 %77
166 %81 = OpFDiv %6 %80 %68
167 %82 = OpExtInst %6 %1 Round %81
169 %88 = OpAccessChain %87 %85 %77
174 %92 = OpFunctionCall %6 %11 %86 %90
175 %93 = OpAccessChain %7 %66 %77
177 %96 = OpAccessChain %87 %85 %95
182 %100 = OpFunctionCall %6 %11 %94 %98
183 %101 = OpAccessChain %7 %66 %95
185 %102 = OpAccessChain %7 %66 %77
186 %103 = OpLoad %6 %102
187 %104 = OpAccessChain %7 %66 %95
188 %105 = OpLoad %6 %104
189 %106 = OpFAdd %6 %103 %105
190 %108 = OpAccessChain %7 %66 %107
195 OpLoopMerge %112 %113 None
198 %115 = OpLoad %15 %109
199 %117 = OpSLessThan %26 %115 %116
200 OpBranchConditional %117 %111 %112
202 %118 = OpLoad %15 %109
203 %119 = OpAccessChain %7 %66 %118
204 %120 = OpLoad %6 %119
205 %122 = OpFOrdGreaterThanEqual %26 %120 %121
206 OpSelectionMerge %124 None
207 OpBranchConditional %122 %123 %124
209 %125 = OpLoad %15 %109
210 %126 = OpLoad %15 %109
211 %127 = OpAccessChain %7 %66 %126
212 %128 = OpLoad %6 %127
213 %129 = OpLoad %15 %109
214 %130 = OpAccessChain %7 %66 %129
215 %131 = OpLoad %6 %130
216 %132 = OpFMul %6 %128 %131
217 %133 = OpAccessChain %7 %66 %125
223 %134 = OpLoad %15 %109
224 %135 = OpIAdd %15 %134 %18
228 %138 = OpLoad %64 %66
229 %139 = OpExtInst %64 %1 FAbs %138
230 %140 = OpExtInst %64 %1 Normalize %139
231 %141 = OpCompositeExtract %6 %140 0
232 %142 = OpCompositeExtract %6 %140 1
233 %143 = OpCompositeExtract %6 %140 2
234 %144 = OpCompositeConstruct %83 %141 %142 %143 %121
238 %11 = OpFunction %6 None %8
239 %9 = OpFunctionParameter %7
240 %10 = OpFunctionParameter %7
242 %13 = OpVariable %7 Function
243 %17 = OpVariable %16 Function
248 OpLoopMerge %21 %22 None
252 %27 = OpSLessThan %26 %24 %25
253 OpBranchConditional %27 %20 %21
256 %30 = OpSMod %15 %28 %29
257 %32 = OpIEqual %26 %30 %31
258 OpSelectionMerge %34 None
259 OpBranchConditional %32 %33 %38
262 %37 = OpFAdd %6 %36 %35
267 %40 = OpConvertSToF %6 %39
269 %42 = OpExtInst %6 %1 Round %41
270 %43 = OpFMod %6 %40 %42
271 %45 = OpFOrdLessThanEqual %26 %43 %44
272 OpSelectionMerge %47 None
273 OpBranchConditional %45 %46 %47
276 %50 = OpFAdd %6 %49 %48
283 %52 = OpConvertSToF %6 %51
285 %54 = OpFOrdGreaterThanEqual %26 %52 %53
286 OpSelectionMerge %56 None
287 OpBranchConditional %54 %55 %56
295 %60 = OpIAdd %15 %59 %18
304 # uniforms for reference
307 BUFFER reference_resolution DATA_TYPE vec2<float> DATA
311 BUFFER reference_framebuffer FORMAT B8G8R8A8_UNORM
313 PIPELINE graphics reference_pipeline
314 ATTACH reference_vertex_shader
315 ATTACH reference_fragment_shader
316 FRAMEBUFFER_SIZE 256 256
317 BIND BUFFER reference_framebuffer AS color LOCATION 0
318 BIND BUFFER reference_resolution AS uniform DESCRIPTOR_SET 0 BINDING 0
320 CLEAR_COLOR reference_pipeline 0 0 0 255
322 CLEAR reference_pipeline
323 RUN reference_pipeline DRAW_RECT POS 0 0 SIZE 256 256
326 SHADER vertex variant_vertex_shader PASSTHROUGH
328 # variant_fragment_shader is derived from the following GLSL:
330 # precision highp float;
332 # precision highp int;
334 # layout(location = 0) out vec4 _GLF_color;
336 # layout(set = 0, binding = 0) uniform buf0
341 # float compute_value(float limit, float thirty_two)
343 # float result = -0.5;
344 # for (int i = 1; i < 800; i++)
352 # if (mod(float(i), round(thirty_two)) <= 0.01)
357 # if (float(i) >= limit)
367 # vec3 c = vec3(7.0, 8.0, 9.0);
368 # float thirty_two = round(resolution.x / 8.0);
369 # c.x = compute_value(gl_FragCoord.x, thirty_two);
370 # c.y = compute_value(gl_FragCoord.y, thirty_two);
371 # // Line below is the same as c.z = c.x + c.y.
372 # // Extra calculations for c.x and c.y should not have effect on end result (compared to reference shader).
373 # c.z = ((c)*mat3(1.0)).x + (vec3(mat4x2(c, 1.0, exp(0.0), abs(0.0), 1.0, sqrt(0.0)))).y;
374 # for (int i = 0; i < 3; i++)
378 # c[i] = c[i] * c[i];
379 # // gl_FragCoord.y cannot be below 0.0,
380 # // therefore this if statement should have no effect.
381 # if ((gl_FragCoord.y < 0.0))
387 # _GLF_color = vec4(normalize(abs(c)), 1.0);
389 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
392 ; Generator: Khronos Glslang Reference Front End; 10
396 %1 = OpExtInstImport "GLSL.std.450"
397 OpMemoryModel Logical GLSL450
398 OpEntryPoint Fragment %4 "main" %85 %163
399 OpExecutionMode %4 OriginUpperLeft
402 OpName %11 "compute_value(f1;f1;"
404 OpName %10 "thirty_two"
408 OpName %71 "thirty_two"
410 OpMemberName %73 0 "resolution"
412 OpName %85 "gl_FragCoord"
418 OpName %163 "_GLF_color"
419 OpMemberDecorate %73 0 Offset 0
421 OpDecorate %75 DescriptorSet 0
422 OpDecorate %75 Binding 0
423 OpDecorate %85 BuiltIn FragCoord
424 OpDecorate %163 Location 0
426 %3 = OpTypeFunction %2
428 %7 = OpTypePointer Function %6
429 %8 = OpTypeFunction %6 %7 %7
430 %14 = OpConstant %6 -0.5
432 %16 = OpTypePointer Function %15
433 %18 = OpConstant %15 1
434 %25 = OpConstant %15 800
436 %29 = OpConstant %15 32
437 %31 = OpConstant %15 0
438 %35 = OpConstant %6 0.400000006
439 %44 = OpConstant %6 0.00999999978
440 %48 = OpConstant %6 100
441 %64 = OpTypeVector %6 3
442 %65 = OpTypePointer Function %64
443 %67 = OpConstant %6 7
444 %68 = OpConstant %6 8
445 %69 = OpConstant %6 9
446 %70 = OpConstantComposite %64 %67 %68 %69
447 %72 = OpTypeVector %6 2
448 %73 = OpTypeStruct %72
449 %74 = OpTypePointer Uniform %73
450 %75 = OpVariable %74 Uniform
452 %77 = OpConstant %76 0
453 %78 = OpTypePointer Uniform %6
454 %83 = OpTypeVector %6 4
455 %84 = OpTypePointer Input %83
456 %85 = OpVariable %84 Input
457 %87 = OpTypePointer Input %6
458 %95 = OpConstant %76 1
459 %103 = OpTypeMatrix %64 3
460 %104 = OpConstant %6 1
461 %105 = OpConstant %6 0
462 %106 = OpConstantComposite %64 %104 %105 %105
463 %107 = OpConstantComposite %64 %105 %104 %105
464 %108 = OpConstantComposite %64 %105 %105 %104
465 %109 = OpConstantComposite %103 %106 %107 %108
466 %113 = OpTypeMatrix %72 4
467 %128 = OpConstant %76 2
468 %137 = OpConstant %15 3
469 %162 = OpTypePointer Output %83
470 %163 = OpVariable %162 Output
471 %4 = OpFunction %2 None %3
473 %66 = OpVariable %65 Function
474 %71 = OpVariable %7 Function
475 %86 = OpVariable %7 Function
476 %90 = OpVariable %7 Function
477 %94 = OpVariable %7 Function
478 %98 = OpVariable %7 Function
479 %130 = OpVariable %16 Function
481 %79 = OpAccessChain %78 %75 %31 %77
483 %81 = OpFDiv %6 %80 %68
484 %82 = OpExtInst %6 %1 Round %81
486 %88 = OpAccessChain %87 %85 %77
491 %92 = OpFunctionCall %6 %11 %86 %90
492 %93 = OpAccessChain %7 %66 %77
494 %96 = OpAccessChain %87 %85 %95
499 %100 = OpFunctionCall %6 %11 %94 %98
500 %101 = OpAccessChain %7 %66 %95
502 %102 = OpLoad %64 %66
503 %110 = OpVectorTimesMatrix %64 %102 %109
504 %111 = OpCompositeExtract %6 %110 0
505 %112 = OpLoad %64 %66
506 %114 = OpCompositeExtract %6 %112 0
507 %115 = OpCompositeExtract %6 %112 1
508 %116 = OpCompositeExtract %6 %112 2
509 %117 = OpCompositeConstruct %72 %114 %115
510 %118 = OpCompositeConstruct %72 %116 %104
511 %119 = OpCompositeConstruct %72 %104 %105
512 %120 = OpCompositeConstruct %72 %104 %105
513 %121 = OpCompositeConstruct %113 %117 %118 %119 %120
514 %122 = OpCompositeExtract %6 %121 0 0
515 %123 = OpCompositeExtract %6 %121 0 1
516 %124 = OpCompositeExtract %6 %121 1 0
517 %125 = OpCompositeConstruct %64 %122 %123 %124
518 %126 = OpCompositeExtract %6 %125 1
519 %127 = OpFAdd %6 %111 %126
520 %129 = OpAccessChain %7 %66 %128
525 OpLoopMerge %133 %134 None
528 %136 = OpLoad %15 %130
529 %138 = OpSLessThan %26 %136 %137
530 OpBranchConditional %138 %132 %133
532 %139 = OpLoad %15 %130
533 %140 = OpAccessChain %7 %66 %139
534 %141 = OpLoad %6 %140
535 %142 = OpFOrdGreaterThanEqual %26 %141 %104
536 OpSelectionMerge %144 None
537 OpBranchConditional %142 %143 %144
539 %145 = OpLoad %15 %130
540 %146 = OpLoad %15 %130
541 %147 = OpAccessChain %7 %66 %146
542 %148 = OpLoad %6 %147
543 %149 = OpLoad %15 %130
544 %150 = OpAccessChain %7 %66 %149
545 %151 = OpLoad %6 %150
546 %152 = OpFMul %6 %148 %151
547 %153 = OpAccessChain %7 %66 %145
549 %154 = OpAccessChain %87 %85 %95
550 %155 = OpLoad %6 %154
551 %156 = OpFOrdLessThan %26 %155 %105
552 OpSelectionMerge %158 None
553 OpBranchConditional %156 %157 %158
561 %160 = OpLoad %15 %130
562 %161 = OpIAdd %15 %160 %18
566 %164 = OpLoad %64 %66
567 %165 = OpExtInst %64 %1 FAbs %164
568 %166 = OpExtInst %64 %1 Normalize %165
569 %167 = OpCompositeExtract %6 %166 0
570 %168 = OpCompositeExtract %6 %166 1
571 %169 = OpCompositeExtract %6 %166 2
572 %170 = OpCompositeConstruct %83 %167 %168 %169 %104
576 %11 = OpFunction %6 None %8
577 %9 = OpFunctionParameter %7
578 %10 = OpFunctionParameter %7
580 %13 = OpVariable %7 Function
581 %17 = OpVariable %16 Function
586 OpLoopMerge %21 %22 None
590 %27 = OpSLessThan %26 %24 %25
591 OpBranchConditional %27 %20 %21
594 %30 = OpSMod %15 %28 %29
595 %32 = OpIEqual %26 %30 %31
596 OpSelectionMerge %34 None
597 OpBranchConditional %32 %33 %38
600 %37 = OpFAdd %6 %36 %35
605 %40 = OpConvertSToF %6 %39
607 %42 = OpExtInst %6 %1 Round %41
608 %43 = OpFMod %6 %40 %42
609 %45 = OpFOrdLessThanEqual %26 %43 %44
610 OpSelectionMerge %47 None
611 OpBranchConditional %45 %46 %47
614 %50 = OpFAdd %6 %49 %48
621 %52 = OpConvertSToF %6 %51
623 %54 = OpFOrdGreaterThanEqual %26 %52 %53
624 OpSelectionMerge %56 None
625 OpBranchConditional %54 %55 %56
633 %60 = OpIAdd %15 %59 %18
642 # uniforms for variant
645 BUFFER variant_resolution DATA_TYPE vec2<float> DATA
649 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
651 PIPELINE graphics variant_pipeline
652 ATTACH variant_vertex_shader
653 ATTACH variant_fragment_shader
654 FRAMEBUFFER_SIZE 256 256
655 BIND BUFFER variant_framebuffer AS color LOCATION 0
656 BIND BUFFER variant_resolution AS uniform DESCRIPTOR_SET 0 BINDING 0
658 CLEAR_COLOR variant_pipeline 0 0 0 255
660 CLEAR variant_pipeline
661 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
663 EXPECT reference_framebuffer EQ_HISTOGRAM_EMD_BUFFER variant_framebuffer TOLERANCE 0.005