• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!amber
2
3# Copyright 2019 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
18# A test for a bug found by GraphicsFuzz.
19
20# Short description: An array-manipulating fragment shader with a discard
21
22# The test passes because the discard is not dynamically reachable, and
23# data[0] ends up with the value 1.0 after the loop so that red is
24# rendered
25
26SHADER vertex variant_vertex_shader PASSTHROUGH
27
28# variant_fragment_shader is derived from the following GLSL:
29# #version 310 es
30#
31# precision highp float;
32#
33# layout(location = 0) out vec4 _GLF_color;
34#
35# void main()
36# {
37#  float data[10] = float[](0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0);
38#  for(int i = 0; i < 10; i++) {
39#    if(gl_FragCoord.x < 0.0) {
40#      discard;
41#    }
42#    data[0] = data[i];
43#  }
44#  _GLF_color = vec4(data[0], 0.0, 0.0, 1.0);
45# }
46SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
47; SPIR-V
48; Version: 1.0
49; Generator: Khronos Glslang Reference Front End; 7
50; Bound: 61
51; Schema: 0
52               OpCapability Shader
53          %1 = OpExtInstImport "GLSL.std.450"
54               OpMemoryModel Logical GLSL450
55               OpEntryPoint Fragment %4 "main" %38 %57
56               OpExecutionMode %4 OriginUpperLeft
57               OpSource ESSL 310
58               OpName %4 "main"
59               OpName %11 "data"
60               OpName %25 "i"
61               OpName %38 "gl_FragCoord"
62               OpName %57 "_GLF_color"
63               OpDecorate %25 RelaxedPrecision
64               OpDecorate %32 RelaxedPrecision
65               OpDecorate %38 BuiltIn FragCoord
66               OpDecorate %48 RelaxedPrecision
67               OpDecorate %53 RelaxedPrecision
68               OpDecorate %55 RelaxedPrecision
69               OpDecorate %57 Location 0
70          %2 = OpTypeVoid
71          %3 = OpTypeFunction %2
72          %6 = OpTypeFloat 32
73          %7 = OpTypeInt 32 0
74          %8 = OpConstant %7 10
75          %9 = OpTypeArray %6 %8
76         %10 = OpTypePointer Function %9
77         %12 = OpConstant %6 0.100000001
78         %13 = OpConstant %6 0.200000003
79         %14 = OpConstant %6 0.300000012
80         %15 = OpConstant %6 0.400000006
81         %16 = OpConstant %6 0.5
82         %17 = OpConstant %6 0.600000024
83         %18 = OpConstant %6 0.699999988
84         %19 = OpConstant %6 0.800000012
85         %20 = OpConstant %6 0.899999976
86         %21 = OpConstant %6 1
87         %22 = OpConstantComposite %9 %12 %13 %14 %15 %16 %17 %18 %19 %20 %21
88         %23 = OpTypeInt 32 1
89         %24 = OpTypePointer Function %23
90         %26 = OpConstant %23 0
91         %33 = OpConstant %23 10
92         %34 = OpTypeBool
93         %36 = OpTypeVector %6 4
94         %37 = OpTypePointer Input %36
95         %38 = OpVariable %37 Input
96         %39 = OpConstant %7 0
97         %40 = OpTypePointer Input %6
98         %43 = OpConstant %6 0
99         %49 = OpTypePointer Function %6
100         %54 = OpConstant %23 1
101         %56 = OpTypePointer Output %36
102         %57 = OpVariable %56 Output
103          %4 = OpFunction %2 None %3
104          %5 = OpLabel
105         %11 = OpVariable %10 Function
106         %25 = OpVariable %24 Function
107               OpStore %11 %22
108               OpStore %25 %26
109               OpBranch %27
110         %27 = OpLabel
111               OpLoopMerge %29 %30 None
112               OpBranch %31
113         %31 = OpLabel
114         %32 = OpLoad %23 %25
115         %35 = OpSLessThan %34 %32 %33
116               OpBranchConditional %35 %28 %29
117         %28 = OpLabel
118         %41 = OpAccessChain %40 %38 %39
119         %42 = OpLoad %6 %41
120         %44 = OpFOrdLessThan %34 %42 %43
121               OpSelectionMerge %46 None
122               OpBranchConditional %44 %45 %46
123         %45 = OpLabel
124               OpKill
125         %46 = OpLabel
126         %48 = OpLoad %23 %25
127         %50 = OpAccessChain %49 %11 %48
128         %51 = OpLoad %6 %50
129         %52 = OpAccessChain %49 %11 %26
130               OpStore %52 %51
131               OpBranch %30
132         %30 = OpLabel
133         %53 = OpLoad %23 %25
134         %55 = OpIAdd %23 %53 %54
135               OpStore %25 %55
136               OpBranch %27
137         %29 = OpLabel
138         %58 = OpAccessChain %49 %11 %26
139         %59 = OpLoad %6 %58
140         %60 = OpCompositeConstruct %36 %59 %43 %43 %21
141               OpStore %57 %60
142               OpReturn
143               OpFunctionEnd
144END
145
146# uniforms for variant
147
148
149BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
150
151PIPELINE graphics variant_pipeline
152  ATTACH variant_vertex_shader
153  ATTACH variant_fragment_shader
154  FRAMEBUFFER_SIZE 256 256
155  BIND BUFFER variant_framebuffer AS color LOCATION 0
156END
157CLEAR_COLOR variant_pipeline 0 0 0 255
158
159CLEAR variant_pipeline
160RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
161
162EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255
163