blob: 31fb80083be2117ffc1efc3ac04c1120de29ba99 [file] [log] [blame]
#!amber
# Copyright 2019 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.
# Short description: A fragment shader with uniform comparison in loop
# The test passes because main always writes the color red
# Optimized using spirv-opt with the following arguments:
# '--eliminate-dead-inserts'
# '--combine-access-chains'
# '--eliminate-local-single-block'
# '--ccp'
# '--eliminate-dead-branches'
# '--merge-blocks'
# '--eliminate-dead-branches'
# '--merge-return'
# '--eliminate-local-multi-store'
# '--simplify-instructions'
# '--private-to-local'
# '--combine-access-chains'
# '--simplify-instructions'
# '--if-conversion'
# '--eliminate-dead-code-aggressive'
# '--eliminate-dead-code-aggressive'
# '--ccp'
# '--copy-propagate-arrays'
# '--ccp'
# '--private-to-local'
# '--eliminate-dead-code-aggressive'
# spirv-opt commit hash: 6b072126595dd8c2448eb1fda616251c5e6d7079
SHADER vertex variant_vertex_shader PASSTHROUGH
# variant_fragment_shader is derived from the following GLSL:
# #version 310 es
# precision highp float;
#
# layout(location = 0) out vec4 _GLF_color;
#
# layout(set = 0, binding = 0) uniform buf0
# {
# vec2 injectionSwitch;
# };
#
# float makeFrame()
# {
# for (int i = 0; i < 1; i++)
# {
# for (int _injected_loop_counter = 0; 1 < int(injectionSwitch.y); 1)
# {
# return 1.0;
# }
# }
# return 1.0;
# }
#
# void main()
# {
# makeFrame();
# _GLF_color = vec4(1.0, 0.0, 0.0, 1.0); // Writes the color red
# }
SHADER fragment variant_fragment_shader SPIRV-ASM
; SPIR-V
; Version: 1.0
; Generator: Khronos Glslang Reference Front End; 7
; Bound: 85
; Schema: 0
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %4 "main" %49
OpExecutionMode %4 OriginUpperLeft
OpSource ESSL 310
OpName %4 "main"
OpName %8 "makeFrame("
OpName %30 "buf0"
OpMemberName %30 0 "injectionSwitch"
OpName %32 ""
OpName %49 "_GLF_color"
OpMemberDecorate %30 0 Offset 0
OpDecorate %30 Block
OpDecorate %32 DescriptorSet 0
OpDecorate %32 Binding 0
OpDecorate %43 RelaxedPrecision
OpDecorate %49 Location 0
OpDecorate %67 RelaxedPrecision
OpDecorate %73 RelaxedPrecision
%2 = OpTypeVoid
%3 = OpTypeFunction %2
%6 = OpTypeFloat 32
%7 = OpTypeFunction %6
%10 = OpTypeInt 32 1
%13 = OpConstant %10 0
%20 = OpConstant %10 1
%21 = OpTypeBool
%29 = OpTypeVector %6 2
%30 = OpTypeStruct %29
%31 = OpTypePointer Uniform %30
%32 = OpVariable %31 Uniform
%33 = OpTypeInt 32 0
%34 = OpConstant %33 1
%35 = OpTypePointer Uniform %6
%40 = OpConstant %6 1
%47 = OpTypeVector %6 4
%48 = OpTypePointer Output %47
%49 = OpVariable %48 Output
%50 = OpConstant %6 0
%51 = OpConstantComposite %47 %40 %50 %50 %40
%59 = OpConstantFalse %21
%62 = OpConstantTrue %21
%79 = OpUndef %6
%82 = OpUndef %21
%83 = OpUndef %10
%4 = OpFunction %2 None %3
%5 = OpLabel
%46 = OpFunctionCall %6 %8
OpStore %49 %51
OpReturn
OpFunctionEnd
%8 = OpFunction %6 None %7
%9 = OpLabel
OpBranch %56
%56 = OpLabel
OpLoopMerge %52 %58 None
OpBranch %57
%57 = OpLabel
OpBranch %14
%14 = OpLabel
%70 = OpPhi %21 %59 %57 %68 %63
%67 = OpPhi %10 %13 %57 %43 %63
%77 = OpPhi %6 %79 %57 %80 %63
%22 = OpSLessThan %21 %67 %20
OpLoopMerge %16 %63 None
OpBranchConditional %22 %15 %16
%15 = OpLabel
OpBranch %24
%24 = OpLabel
%81 = OpPhi %6 %77 %15 %79 %27
%73 = OpPhi %10 %67 %15 %83 %27
%69 = OpPhi %21 %70 %15 %82 %27
%36 = OpAccessChain %35 %32 %13 %34
%37 = OpLoad %6 %36
%38 = OpConvertFToS %10 %37
%39 = OpSLessThan %21 %20 %38
OpLoopMerge %26 %27 None
OpBranchConditional %39 %25 %26
%25 = OpLabel
OpBranch %26
%27 = OpLabel
OpBranch %24
%26 = OpLabel
%80 = OpPhi %6 %81 %24 %40 %25
%68 = OpPhi %21 %69 %24 %62 %25
OpSelectionMerge %84 None
OpBranchConditional %68 %16 %84
%84 = OpLabel
OpBranch %63
%63 = OpLabel
%43 = OpIAdd %10 %73 %20
OpBranch %14
%16 = OpLabel
%76 = OpPhi %6 %77 %14 %80 %26
%74 = OpPhi %21 %70 %14 %68 %26
OpSelectionMerge %65 None
OpBranchConditional %74 %52 %65
%65 = OpLabel
OpBranch %52
%58 = OpLabel
OpBranch %56
%52 = OpLabel
%75 = OpPhi %6 %76 %16 %40 %65
OpReturnValue %75
OpFunctionEnd
END
# uniforms for variant
# injectionSwitch
BUFFER variant_injectionSwitch DATA_TYPE vec2<float> 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_injectionSwitch AS uniform DESCRIPTOR_SET 0 BINDING 0
END
CLEAR_COLOR variant_pipeline 0 0 0 255
CLEAR variant_pipeline
RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255