#!amber # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # A test for a bug found by the GraphicsFuzz project. # Short description: A fragment shader with two always false discards # The test passes because both shaders render the same image. # Optimized using spirv-opt with the following arguments: # '-O' # spirv-opt commit hash: 717e7877cac15d393fd3bb1bd872679de8b59add SHADER vertex reference_vertex_shader PASSTHROUGH # reference_fragment_shader is derived from the following GLSL: # #version 320 es # precision highp float; # # precision highp int; # # layout(location = 0) out vec4 _GLF_color; # # layout(set = 0, binding = 0) uniform buf0 # { # vec2 resolution; # }; # float compute_value(float limit, float thirty_two) # { # float result = -0.5; # for (int i = 1; i < 800; i++) # { # if ((i % 32) == 0) # { # result += 0.4; # } # else # { # if (mod(float(i), round(thirty_two)) <= 0.01) # { # result += 100.0; # } # } # if (float(i) >= limit) # { # return result; # } # } # return result; # } # void main() # { # vec3 c = vec3(7.0, 8.0, 9.0); # float thirty_two = round(resolution.x / 8.0); # c.x = compute_value(gl_FragCoord.x, thirty_two); # c.y = compute_value(gl_FragCoord.y, thirty_two); # c.z = c.x + c.y; # for (int i = 0; i < 3; i++) # { # if (c[i] >= 1.0) # { # c[i] = c[i] * c[i]; # } # } # _GLF_color = vec4(normalize(abs(c)), 1.0); # } SHADER fragment reference_fragment_shader SPIRV-ASM TARGET_ENV spv1.0 ; SPIR-V ; Version: 1.0 ; Generator: Khronos Glslang Reference Front End; 10 ; Bound: 290 ; Schema: 0 OpCapability Shader %1 = OpExtInstImport "GLSL.std.450" OpMemoryModel Logical GLSL450 OpEntryPoint Fragment %4 "main" %85 %137 OpExecutionMode %4 OriginUpperLeft OpSource ESSL 320 OpName %4 "main" OpName %66 "c" OpName %73 "buf0" OpMemberName %73 0 "resolution" OpName %75 "" OpName %85 "gl_FragCoord" OpName %137 "_GLF_color" OpMemberDecorate %73 0 Offset 0 OpDecorate %73 Block OpDecorate %75 DescriptorSet 0 OpDecorate %75 Binding 0 OpDecorate %85 BuiltIn FragCoord OpDecorate %137 Location 0 %2 = OpTypeVoid %3 = OpTypeFunction %2 %6 = OpTypeFloat 32 %7 = OpTypePointer Function %6 %14 = OpConstant %6 -0.5 %15 = OpTypeInt 32 1 %18 = OpConstant %15 1 %25 = OpConstant %15 800 %26 = OpTypeBool %29 = OpConstant %15 32 %31 = OpConstant %15 0 %35 = OpConstant %6 0.400000006 %44 = OpConstant %6 0.00999999978 %48 = OpConstant %6 100 %64 = OpTypeVector %6 3 %65 = OpTypePointer Function %64 %67 = OpConstant %6 7 %68 = OpConstant %6 8 %69 = OpConstant %6 9 %70 = OpConstantComposite %64 %67 %68 %69 %72 = OpTypeVector %6 2 %73 = OpTypeStruct %72 %74 = OpTypePointer Uniform %73 %75 = OpVariable %74 Uniform %76 = OpTypeInt 32 0 %77 = OpConstant %76 0 %78 = OpTypePointer Uniform %6 %83 = OpTypeVector %6 4 %84 = OpTypePointer Input %83 %85 = OpVariable %84 Input %87 = OpTypePointer Input %6 %95 = OpConstant %76 1 %107 = OpConstant %76 2 %116 = OpConstant %15 3 %121 = OpConstant %6 1 %136 = OpTypePointer Output %83 %137 = OpVariable %136 Output %149 = OpConstantFalse %26 %152 = OpConstantTrue %26 %261 = OpUndef %6 %289 = OpConstant %6 0.125 %4 = OpFunction %2 None %3 %5 = OpLabel %66 = OpVariable %65 Function OpStore %66 %70 %79 = OpAccessChain %78 %75 %31 %77 %80 = OpLoad %6 %79 %81 = OpFMul %6 %80 %289 %82 = OpExtInst %6 %1 Round %81 %88 = OpAccessChain %87 %85 %77 %89 = OpLoad %6 %88 OpSelectionMerge %199 None OpSwitch %77 %161 %161 = OpLabel OpBranch %162 %162 = OpLabel %248 = OpPhi %6 %14 %161 %251 %192 %247 = OpPhi %15 %18 %161 %194 %192 %165 = OpSLessThan %26 %247 %25 OpLoopMerge %195 %192 None OpBranchConditional %165 %166 %195 %166 = OpLabel %168 = OpSMod %15 %247 %29 %169 = OpIEqual %26 %168 %31 OpSelectionMerge %184 None OpBranchConditional %169 %170 %173 %170 = OpLabel %172 = OpFAdd %6 %248 %35 OpBranch %184 %173 = OpLabel %175 = OpConvertSToF %6 %247 %177 = OpExtInst %6 %1 Round %82 %178 = OpFMod %6 %175 %177 %179 = OpFOrdLessThanEqual %26 %178 %44 OpSelectionMerge %183 None OpBranchConditional %179 %180 %183 %180 = OpLabel %182 = OpFAdd %6 %248 %48 OpBranch %183 %183 = OpLabel %252 = OpPhi %6 %248 %173 %182 %180 OpBranch %184 %184 = OpLabel %251 = OpPhi %6 %172 %170 %252 %183 %186 = OpConvertSToF %6 %247 %188 = OpFOrdGreaterThanEqual %26 %186 %89 OpSelectionMerge %191 None OpBranchConditional %188 %189 %191 %189 = OpLabel OpBranch %195 %191 = OpLabel OpBranch %192 %192 = OpLabel %194 = OpIAdd %15 %247 %18 OpBranch %162 %195 = OpLabel %259 = OpPhi %6 %261 %162 %251 %189 %257 = OpPhi %6 %248 %162 %251 %189 %253 = OpPhi %26 %149 %162 %152 %189 OpSelectionMerge %197 None OpBranchConditional %253 %199 %197 %197 = OpLabel OpBranch %199 %199 = OpLabel %258 = OpPhi %6 %259 %195 %257 %197 %93 = OpAccessChain %7 %66 %77 OpStore %93 %258 %96 = OpAccessChain %87 %85 %95 %97 = OpLoad %6 %96 OpSelectionMerge %245 None OpSwitch %77 %207 %207 = OpLabel OpBranch %208 %208 = OpLabel %265 = OpPhi %6 %14 %207 %268 %238 %264 = OpPhi %15 %18 %207 %240 %238 %211 = OpSLessThan %26 %264 %25 OpLoopMerge %241 %238 None OpBranchConditional %211 %212 %241 %212 = OpLabel %214 = OpSMod %15 %264 %29 %215 = OpIEqual %26 %214 %31 OpSelectionMerge %230 None OpBranchConditional %215 %216 %219 %216 = OpLabel %218 = OpFAdd %6 %265 %35 OpBranch %230 %219 = OpLabel %221 = OpConvertSToF %6 %264 %223 = OpExtInst %6 %1 Round %82 %224 = OpFMod %6 %221 %223 %225 = OpFOrdLessThanEqual %26 %224 %44 OpSelectionMerge %229 None OpBranchConditional %225 %226 %229 %226 = OpLabel %228 = OpFAdd %6 %265 %48 OpBranch %229 %229 = OpLabel %269 = OpPhi %6 %265 %219 %228 %226 OpBranch %230 %230 = OpLabel %268 = OpPhi %6 %218 %216 %269 %229 %232 = OpConvertSToF %6 %264 %234 = OpFOrdGreaterThanEqual %26 %232 %97 OpSelectionMerge %237 None OpBranchConditional %234 %235 %237 %235 = OpLabel OpBranch %241 %237 = OpLabel OpBranch %238 %238 = OpLabel %240 = OpIAdd %15 %264 %18 OpBranch %208 %241 = OpLabel %276 = OpPhi %6 %261 %208 %268 %235 %274 = OpPhi %6 %265 %208 %268 %235 %270 = OpPhi %26 %149 %208 %152 %235 OpSelectionMerge %243 None OpBranchConditional %270 %245 %243 %243 = OpLabel OpBranch %245 %245 = OpLabel %275 = OpPhi %6 %276 %241 %274 %243 %101 = OpAccessChain %7 %66 %95 OpStore %101 %275 %103 = OpLoad %6 %93 %105 = OpLoad %6 %101 %106 = OpFAdd %6 %103 %105 %108 = OpAccessChain %7 %66 %107 OpStore %108 %106 OpBranch %110 %110 = OpLabel %285 = OpPhi %15 %31 %245 %135 %113 %117 = OpSLessThan %26 %285 %116 OpLoopMerge %112 %113 None OpBranchConditional %117 %111 %112 %111 = OpLabel %119 = OpAccessChain %7 %66 %285 %120 = OpLoad %6 %119 %122 = OpFOrdGreaterThanEqual %26 %120 %121 OpSelectionMerge %124 None OpBranchConditional %122 %123 %124 %123 = OpLabel %128 = OpLoad %6 %119 %131 = OpLoad %6 %119 %132 = OpFMul %6 %128 %131 OpStore %119 %132 OpBranch %124 %124 = OpLabel OpBranch %113 %113 = OpLabel %135 = OpIAdd %15 %285 %18 OpBranch %110 %112 = OpLabel %138 = OpLoad %64 %66 %139 = OpExtInst %64 %1 FAbs %138 %140 = OpExtInst %64 %1 Normalize %139 %141 = OpCompositeExtract %6 %140 0 %142 = OpCompositeExtract %6 %140 1 %143 = OpCompositeExtract %6 %140 2 %144 = OpCompositeConstruct %83 %141 %142 %143 %121 OpStore %137 %144 OpReturn OpFunctionEnd END # uniforms for reference # resolution BUFFER reference_resolution DATA_TYPE vec2 STD140 DATA 256.0 256.0 END BUFFER reference_framebuffer FORMAT B8G8R8A8_UNORM PIPELINE graphics reference_pipeline ATTACH reference_vertex_shader ATTACH reference_fragment_shader FRAMEBUFFER_SIZE 256 256 BIND BUFFER reference_framebuffer AS color LOCATION 0 BIND BUFFER reference_resolution AS uniform DESCRIPTOR_SET 0 BINDING 0 END CLEAR_COLOR reference_pipeline 0 0 0 255 CLEAR reference_pipeline RUN reference_pipeline DRAW_RECT POS 0 0 SIZE 256 256 SHADER vertex variant_vertex_shader PASSTHROUGH # variant_fragment_shader is derived from the following GLSL: # #version 320 es # precision highp float; # # precision highp int; # # layout(location = 0) out vec4 _GLF_color; # # layout(set = 0, binding = 0) uniform buf0 # { # vec2 resolution; # }; # layout(set = 0, binding = 1) uniform buf1 # { # vec2 injectionSwitch; // x == 0.0, y == 1.0 # }; # float compute_value(float limit, float thirty_two) # { # float result = -0.5; # for (int i = 1; i < 800; i++) # { # if ((i % 32) == 0) # { # result += 0.4; # } # else # { # if (mod(float(i), round(thirty_two)) <= 0.01) # { # result += 100.0; # } # // Always false. # if (injectionSwitch.x > injectionSwitch.y) # { # discard; # } # } # if (float(i) >= limit) # { # return result; # } # } # return result; # } # void main() # { # vec3 c = vec3(7.0, 8.0, 9.0); # float thirty_two = round(resolution.x / 8.0); # c.x = compute_value(gl_FragCoord.x, thirty_two); # c.y = compute_value(gl_FragCoord.y, thirty_two); # c.z = c.x + c.y; # for (int i = 0; i < 3; i++) # { # if (c[i] >= 1.0) # { # c[i] = c[i] * c[i]; # // Always false. # if ((injectionSwitch.x > injectionSwitch.y)) # { # discard; # } # } # } # _GLF_color = vec4(normalize(abs(c)), 1.0); # } SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0 ; SPIR-V ; Version: 1.0 ; Generator: Khronos Glslang Reference Front End; 10 ; Bound: 325 ; Schema: 0 OpCapability Shader %1 = OpExtInstImport "GLSL.std.450" OpMemoryModel Logical GLSL450 OpEntryPoint Fragment %4 "main" %97 %156 OpExecutionMode %4 OriginUpperLeft OpSource ESSL 320 OpName %4 "main" OpName %52 "buf1" OpMemberName %52 0 "injectionSwitch" OpName %54 "" OpName %82 "c" OpName %88 "buf0" OpMemberName %88 0 "resolution" OpName %90 "" OpName %97 "gl_FragCoord" OpName %156 "_GLF_color" OpMemberDecorate %52 0 Offset 0 OpDecorate %52 Block OpDecorate %54 DescriptorSet 0 OpDecorate %54 Binding 1 OpMemberDecorate %88 0 Offset 0 OpDecorate %88 Block OpDecorate %90 DescriptorSet 0 OpDecorate %90 Binding 0 OpDecorate %97 BuiltIn FragCoord OpDecorate %156 Location 0 %2 = OpTypeVoid %3 = OpTypeFunction %2 %6 = OpTypeFloat 32 %7 = OpTypePointer Function %6 %14 = OpConstant %6 -0.5 %15 = OpTypeInt 32 1 %18 = OpConstant %15 1 %25 = OpConstant %15 800 %26 = OpTypeBool %29 = OpConstant %15 32 %31 = OpConstant %15 0 %35 = OpConstant %6 0.400000006 %44 = OpConstant %6 0.00999999978 %48 = OpConstant %6 100 %51 = OpTypeVector %6 2 %52 = OpTypeStruct %51 %53 = OpTypePointer Uniform %52 %54 = OpVariable %53 Uniform %55 = OpTypeInt 32 0 %56 = OpConstant %55 0 %57 = OpTypePointer Uniform %6 %60 = OpConstant %55 1 %80 = OpTypeVector %6 3 %81 = OpTypePointer Function %80 %83 = OpConstant %6 7 %84 = OpConstant %6 8 %85 = OpConstant %6 9 %86 = OpConstantComposite %80 %83 %84 %85 %88 = OpTypeStruct %51 %89 = OpTypePointer Uniform %88 %90 = OpVariable %89 Uniform %95 = OpTypeVector %6 4 %96 = OpTypePointer Input %95 %97 = OpVariable %96 Input %99 = OpTypePointer Input %6 %118 = OpConstant %55 2 %127 = OpConstant %15 3 %132 = OpConstant %6 1 %155 = OpTypePointer Output %95 %156 = OpVariable %155 Output %168 = OpConstantFalse %26 %171 = OpConstantTrue %26 %296 = OpUndef %6 %324 = OpConstant %6 0.125 %4 = OpFunction %2 None %3 %5 = OpLabel %82 = OpVariable %81 Function OpStore %82 %86 %91 = OpAccessChain %57 %90 %31 %56 %92 = OpLoad %6 %91 %93 = OpFMul %6 %92 %324 %94 = OpExtInst %6 %1 Round %93 %100 = OpAccessChain %99 %97 %56 %101 = OpLoad %6 %100 OpSelectionMerge %225 None OpSwitch %56 %180 %180 = OpLabel OpBranch %181 %181 = OpLabel %283 = OpPhi %6 %14 %180 %286 %218 %282 = OpPhi %15 %18 %180 %220 %218 %184 = OpSLessThan %26 %282 %25 OpLoopMerge %221 %218 None OpBranchConditional %184 %185 %221 %185 = OpLabel %187 = OpSMod %15 %282 %29 %188 = OpIEqual %26 %187 %31 OpSelectionMerge %210 None OpBranchConditional %188 %189 %192 %189 = OpLabel %191 = OpFAdd %6 %283 %35 OpBranch %210 %192 = OpLabel %194 = OpConvertSToF %6 %282 %196 = OpExtInst %6 %1 Round %94 %197 = OpFMod %6 %194 %196 %198 = OpFOrdLessThanEqual %26 %197 %44 OpSelectionMerge %202 None OpBranchConditional %198 %199 %202 %199 = OpLabel %201 = OpFAdd %6 %283 %48 OpBranch %202 %202 = OpLabel %287 = OpPhi %6 %283 %192 %201 %199 %203 = OpAccessChain %57 %54 %31 %56 %204 = OpLoad %6 %203 %205 = OpAccessChain %57 %54 %31 %60 %206 = OpLoad %6 %205 %207 = OpFOrdGreaterThan %26 %204 %206 OpSelectionMerge %209 None OpBranchConditional %207 %208 %209 %208 = OpLabel OpKill %209 = OpLabel OpBranch %210 %210 = OpLabel %286 = OpPhi %6 %191 %189 %287 %209 %212 = OpConvertSToF %6 %282 %214 = OpFOrdGreaterThanEqual %26 %212 %101 OpSelectionMerge %217 None OpBranchConditional %214 %215 %217 %215 = OpLabel OpBranch %221 %217 = OpLabel OpBranch %218 %218 = OpLabel %220 = OpIAdd %15 %282 %18 OpBranch %181 %221 = OpLabel %294 = OpPhi %6 %296 %181 %286 %215 %292 = OpPhi %6 %283 %181 %286 %215 %288 = OpPhi %26 %168 %181 %171 %215 OpSelectionMerge %223 None OpBranchConditional %288 %225 %223 %223 = OpLabel OpBranch %225 %225 = OpLabel %293 = OpPhi %6 %294 %221 %292 %223 %105 = OpAccessChain %7 %82 %56 OpStore %105 %293 %107 = OpAccessChain %99 %97 %60 %108 = OpLoad %6 %107 OpSelectionMerge %279 None OpSwitch %56 %234 %234 = OpLabel OpBranch %235 %235 = OpLabel %300 = OpPhi %6 %14 %234 %303 %272 %299 = OpPhi %15 %18 %234 %274 %272 %238 = OpSLessThan %26 %299 %25 OpLoopMerge %275 %272 None OpBranchConditional %238 %239 %275 %239 = OpLabel %241 = OpSMod %15 %299 %29 %242 = OpIEqual %26 %241 %31 OpSelectionMerge %264 None OpBranchConditional %242 %243 %246 %243 = OpLabel %245 = OpFAdd %6 %300 %35 OpBranch %264 %246 = OpLabel %248 = OpConvertSToF %6 %299 %250 = OpExtInst %6 %1 Round %94 %251 = OpFMod %6 %248 %250 %252 = OpFOrdLessThanEqual %26 %251 %44 OpSelectionMerge %256 None OpBranchConditional %252 %253 %256 %253 = OpLabel %255 = OpFAdd %6 %300 %48 OpBranch %256 %256 = OpLabel %304 = OpPhi %6 %300 %246 %255 %253 %257 = OpAccessChain %57 %54 %31 %56 %258 = OpLoad %6 %257 %259 = OpAccessChain %57 %54 %31 %60 %260 = OpLoad %6 %259 %261 = OpFOrdGreaterThan %26 %258 %260 OpSelectionMerge %263 None OpBranchConditional %261 %262 %263 %262 = OpLabel OpKill %263 = OpLabel OpBranch %264 %264 = OpLabel %303 = OpPhi %6 %245 %243 %304 %263 %266 = OpConvertSToF %6 %299 %268 = OpFOrdGreaterThanEqual %26 %266 %108 OpSelectionMerge %271 None OpBranchConditional %268 %269 %271 %269 = OpLabel OpBranch %275 %271 = OpLabel OpBranch %272 %272 = OpLabel %274 = OpIAdd %15 %299 %18 OpBranch %235 %275 = OpLabel %311 = OpPhi %6 %296 %235 %303 %269 %309 = OpPhi %6 %300 %235 %303 %269 %305 = OpPhi %26 %168 %235 %171 %269 OpSelectionMerge %277 None OpBranchConditional %305 %279 %277 %277 = OpLabel OpBranch %279 %279 = OpLabel %310 = OpPhi %6 %311 %275 %309 %277 %112 = OpAccessChain %7 %82 %60 OpStore %112 %310 %114 = OpLoad %6 %105 %116 = OpLoad %6 %112 %117 = OpFAdd %6 %114 %116 %119 = OpAccessChain %7 %82 %118 OpStore %119 %117 OpBranch %121 %121 = OpLabel %320 = OpPhi %15 %31 %279 %154 %124 %128 = OpSLessThan %26 %320 %127 OpLoopMerge %123 %124 None OpBranchConditional %128 %122 %123 %122 = OpLabel %130 = OpAccessChain %7 %82 %320 %131 = OpLoad %6 %130 %133 = OpFOrdGreaterThanEqual %26 %131 %132 OpSelectionMerge %135 None OpBranchConditional %133 %134 %135 %134 = OpLabel %139 = OpLoad %6 %130 %142 = OpLoad %6 %130 %143 = OpFMul %6 %139 %142 OpStore %130 %143 %145 = OpAccessChain %57 %54 %31 %56 %146 = OpLoad %6 %145 %147 = OpAccessChain %57 %54 %31 %60 %148 = OpLoad %6 %147 %149 = OpFOrdGreaterThan %26 %146 %148 OpSelectionMerge %151 None OpBranchConditional %149 %150 %151 %150 = OpLabel OpKill %151 = OpLabel OpBranch %135 %135 = OpLabel OpBranch %124 %124 = OpLabel %154 = OpIAdd %15 %320 %18 OpBranch %121 %123 = OpLabel %157 = OpLoad %80 %82 %158 = OpExtInst %80 %1 FAbs %157 %159 = OpExtInst %80 %1 Normalize %158 %160 = OpCompositeExtract %6 %159 0 %161 = OpCompositeExtract %6 %159 1 %162 = OpCompositeExtract %6 %159 2 %163 = OpCompositeConstruct %95 %160 %161 %162 %132 OpStore %156 %163 OpReturn OpFunctionEnd END # uniforms for variant # resolution BUFFER variant_resolution DATA_TYPE vec2 STD140 DATA 256.0 256.0 END # injectionSwitch BUFFER variant_injectionSwitch DATA_TYPE vec2 STD140 DATA 0.0 1.0 END BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM PIPELINE graphics variant_pipeline ATTACH variant_vertex_shader ATTACH variant_fragment_shader FRAMEBUFFER_SIZE 256 256 BIND BUFFER variant_framebuffer AS color LOCATION 0 BIND BUFFER variant_resolution AS uniform DESCRIPTOR_SET 0 BINDING 0 BIND BUFFER variant_injectionSwitch AS uniform DESCRIPTOR_SET 0 BINDING 1 END CLEAR_COLOR variant_pipeline 0 0 0 255 CLEAR variant_pipeline RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256 EXPECT reference_framebuffer EQ_HISTOGRAM_EMD_BUFFER variant_framebuffer TOLERANCE 0.005