| # Copyright 2018 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 GraphicsFuzz. |
| # A fragment shader that uses FragCoord and somewhat complex control flow. |
| # Derived from the following GLSL fragment shader. |
| # We check that the top-left pixel is red. The test passes because _GLF_color is |
| # initially set to red, all other writes to _GLF_color write red, and the discard |
| # statement only executes for pixels with an x coordinate >= 10000000. |
| |
| # #version 310 es |
| # |
| # precision highp float; |
| # precision highp int; |
| # |
| # layout(location=0) out vec4 _GLF_color; |
| # |
| # void main() { |
| # _GLF_color = vec4(1.0, 0.0, 0.0, 1.0); |
| # for (int i = 0; i < 1; i++) { |
| # if (int(gl_FragCoord.x) < 10000000) { |
| # } else { |
| # |
| # if (int(gl_FragCoord.x) < 10000000) { |
| # |
| # for (int j = 0; j < 1; j++) { |
| # for (int k = 0; k < 1; k++) { |
| # _GLF_color = vec4(1.0, 0.0, 0.0, 1.0); |
| # } |
| # } |
| # vec4 backup; |
| # for (int l = 0; l < 1; l++) { |
| # backup = vec4(1.0, 0.0, 0.0, 1.0); |
| # } |
| # _GLF_color = backup; |
| # } else { |
| # discard; |
| # } |
| # } |
| # } |
| # } |
| |
| [vertex shader passthrough] |
| |
| [fragment shader spirv] |
| ; SPIR-V |
| ; Version: 1.0 |
| ; Generator: Khronos Glslang Reference Front End; 7 |
| ; Bound: 98 |
| ; Schema: 0 |
| OpCapability Shader |
| %1 = OpExtInstImport "GLSL.std.450" |
| OpMemoryModel Logical GLSL450 |
| OpEntryPoint Fragment %main "main" %_GLF_color %gl_FragCoord |
| OpExecutionMode %main OriginUpperLeft |
| OpSource ESSL 310 |
| OpName %main "main" |
| OpName %_GLF_color "_GLF_color" |
| OpName %gl_FragCoord "gl_FragCoord" |
| OpDecorate %_GLF_color Location 0 |
| OpDecorate %gl_FragCoord BuiltIn FragCoord |
| %void = OpTypeVoid |
| %3 = OpTypeFunction %void |
| %float = OpTypeFloat 32 |
| %v4float = OpTypeVector %float 4 |
| %_ptr_Output_v4float = OpTypePointer Output %v4float |
| %_GLF_color = OpVariable %_ptr_Output_v4float Output |
| %float_1 = OpConstant %float 1 |
| %float_0 = OpConstant %float 0 |
| %12 = OpConstantComposite %v4float %float_1 %float_0 %float_0 %float_1 |
| %int = OpTypeInt 32 1 |
| %int_0 = OpConstant %int 0 |
| %int_1 = OpConstant %int 1 |
| %bool = OpTypeBool |
| %_ptr_Input_v4float = OpTypePointer Input %v4float |
| %gl_FragCoord = OpVariable %_ptr_Input_v4float Input |
| %uint = OpTypeInt 32 0 |
| %uint_0 = OpConstant %uint 0 |
| %_ptr_Input_float = OpTypePointer Input %float |
| %int_10000000 = OpConstant %int 10000000 |
| %88 = OpUndef %v4float |
| %main = OpFunction %void None %3 |
| %5 = OpLabel |
| OpStore %_GLF_color %12 |
| OpBranch %17 |
| %17 = OpLabel |
| %87 = OpPhi %v4float %88 %5 %95 %37 |
| %82 = OpPhi %int %int_0 %5 %81 %37 |
| %25 = OpSLessThan %bool %82 %int_1 |
| OpLoopMerge %19 %37 None |
| OpBranchConditional %25 %18 %19 |
| %18 = OpLabel |
| %31 = OpAccessChain %_ptr_Input_float %gl_FragCoord %uint_0 |
| %32 = OpLoad %float %31 |
| %33 = OpConvertFToS %int %32 |
| %35 = OpSLessThan %bool %33 %int_10000000 |
| OpSelectionMerge %96 None |
| OpBranchConditional %35 %36 %38 |
| %36 = OpLabel |
| OpBranch %37 |
| %38 = OpLabel |
| OpSelectionMerge %44 None |
| OpBranchConditional %35 %43 %78 |
| %43 = OpLabel |
| OpBranch %46 |
| %46 = OpLabel |
| %83 = OpPhi %int %int_0 %43 %64 %56 |
| %52 = OpSLessThan %bool %83 %int_1 |
| OpLoopMerge %48 %56 None |
| OpBranchConditional %52 %47 %48 |
| %47 = OpLabel |
| OpBranch %54 |
| %54 = OpLabel |
| %89 = OpPhi %int %int_0 %47 %62 %55 |
| %60 = OpSLessThan %bool %89 %int_1 |
| OpLoopMerge %97 %55 None |
| OpBranchConditional %60 %55 %97 |
| %55 = OpLabel |
| OpStore %_GLF_color %12 |
| %62 = OpIAdd %int %89 %int_1 |
| OpBranch %54 |
| %97 = OpLabel |
| OpBranch %56 |
| %56 = OpLabel |
| %64 = OpIAdd %int %83 %int_1 |
| OpBranch %46 |
| %48 = OpLabel |
| OpBranch %66 |
| %66 = OpLabel |
| %85 = OpPhi %v4float %87 %48 %12 %67 |
| %84 = OpPhi %int %int_0 %48 %76 %67 |
| %72 = OpSLessThan %bool %84 %int_1 |
| OpLoopMerge %68 %67 None |
| OpBranchConditional %72 %67 %68 |
| %67 = OpLabel |
| %76 = OpIAdd %int %84 %int_1 |
| OpBranch %66 |
| %68 = OpLabel |
| OpStore %_GLF_color %85 |
| OpBranch %44 |
| %78 = OpLabel |
| OpKill |
| %44 = OpLabel |
| OpBranch %37 |
| %96 = OpLabel |
| OpBranch %37 |
| %37 = OpLabel |
| %95 = OpPhi %v4float %87 %36 %85 %44 %88 %96 |
| %81 = OpIAdd %int %82 %int_1 |
| OpBranch %17 |
| %19 = OpLabel |
| OpReturn |
| OpFunctionEnd |
| |
| |
| [test] |
| draw rect -1 -1 2 2 |
| probe rgba (0, 0) (1, 0, 0, 1) |