1#!amber 2 3# Copyright 2018 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# A test for a bug found by GraphicsFuzz. 18 19# A fragment shader that uses struct initializers. 20# Derived from the following GLSL fragment shader. 21# We check that all pixels are red. The test passes because main does 22# some computation and then writes red to _GLF_color. 23 24# #version 310 es 25# 26# precision highp float; 27# precision highp int; 28# 29# layout(location = 0) out vec4 _GLF_color; 30# 31# struct S { 32# bool b; 33# }; 34# 35# S foo() 36# { 37# if(true) 38# { 39# return S(true); 40# } 41# return S(true); 42# } 43# void main(void) 44# { 45# foo(); 46# _GLF_color = vec4(1.0, 0.0, 0.0, 1.0); 47# } 48 49SHADER vertex variant_vertex_shader PASSTHROUGH 50 51SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0 52; SPIR-V 53; Version: 1.0 54; Generator: Khronos SPIR-V Tools Assembler; 0 55; Bound: 23 56; Schema: 0 57 OpCapability Shader 58 %1 = OpExtInstImport "GLSL.std.450" 59 OpMemoryModel Logical GLSL450 60 OpEntryPoint Fragment %2 "main" %3 61 OpExecutionMode %2 OriginUpperLeft 62 OpSource ESSL 310 63 OpName %2 "main" 64 OpName %4 "S" 65 OpMemberName %4 0 "b" 66 OpName %5 "foo(" 67 OpName %3 "_GLF_color" 68 OpDecorate %3 Location 0 69 %6 = OpTypeVoid 70 %7 = OpTypeFunction %6 71 %8 = OpTypeBool 72 %4 = OpTypeStruct %8 73 %9 = OpTypeFunction %4 74 %10 = OpConstantTrue %8 75 %11 = OpConstantComposite %4 %10 76 %12 = OpTypeFloat 32 77 %13 = OpTypeVector %12 4 78 %14 = OpTypePointer Output %13 79 %3 = OpVariable %14 Output 80 %15 = OpConstant %12 1 81 %16 = OpConstant %12 0 82 %17 = OpConstantComposite %13 %15 %16 %16 %15 83 %2 = OpFunction %6 None %7 84 %18 = OpLabel 85 %19 = OpFunctionCall %4 %5 86 OpStore %3 %17 87 OpReturn 88 OpFunctionEnd 89 %5 = OpFunction %4 None %9 90 %20 = OpLabel 91 OpSelectionMerge %21 None 92 OpBranchConditional %10 %22 %21 93 %22 = OpLabel 94 OpReturnValue %11 95 %21 = OpLabel 96 OpReturnValue %11 97 OpFunctionEnd 98END 99 100 101BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM 102 103PIPELINE graphics variant_pipeline 104 ATTACH variant_vertex_shader 105 ATTACH variant_fragment_shader 106 FRAMEBUFFER_SIZE 256 256 107 BIND BUFFER variant_framebuffer AS color LOCATION 0 108END 109CLEAR_COLOR variant_pipeline 0 0 0 255 110 111CLEAR variant_pipeline 112RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256 113 114EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255 115