|
| 1 | +;; Ensure builtin binding isn't removed by unused gl_PerVertex builtin culling when |
| 2 | +;; the builtin is used in a function defined after (in the SPIRV) the entry point. |
| 3 | +;; |
| 4 | +;; Generated from the following glsl via `glslc` (without `-O` flag): |
| 5 | +;; |
| 6 | +;; ```glsl |
| 7 | +;; #version 450 |
| 8 | +;; |
| 9 | +;; void builtin_usage() { |
| 10 | +;; gl_Position = vec4( |
| 11 | +;; (gl_VertexIndex == 0) ? -4.0 : 1.0, |
| 12 | +;; (gl_VertexIndex == 2) ? 4.0 : -1.0, |
| 13 | +;; 0.0, |
| 14 | +;; 1.0 |
| 15 | +;; ); |
| 16 | +;; } |
| 17 | +;; |
| 18 | +;; void main() |
| 19 | +;; { |
| 20 | +;; builtin_usage(); |
| 21 | +;; } |
| 22 | +;; ``` |
| 23 | +;; |
| 24 | +; SPIR-V |
| 25 | +; Version: 1.0 |
| 26 | +; Generator: Google Shaderc over Glslang; 11 |
| 27 | +; Bound: 37 |
| 28 | +; Schema: 0 |
| 29 | + OpCapability Shader |
| 30 | + %1 = OpExtInstImport "GLSL.std.450" |
| 31 | + OpMemoryModel Logical GLSL450 |
| 32 | + OpEntryPoint Vertex %main "main" %_ %gl_VertexIndex |
| 33 | + OpSource GLSL 450 |
| 34 | + OpSourceExtension "GL_GOOGLE_cpp_style_line_directive" |
| 35 | + OpSourceExtension "GL_GOOGLE_include_directive" |
| 36 | + OpName %main "main" |
| 37 | + OpName %builtin_usage_ "builtin_usage(" |
| 38 | + OpName %gl_PerVertex "gl_PerVertex" |
| 39 | + OpMemberName %gl_PerVertex 0 "gl_Position" |
| 40 | + OpMemberName %gl_PerVertex 1 "gl_PointSize" |
| 41 | + OpMemberName %gl_PerVertex 2 "gl_ClipDistance" |
| 42 | + OpMemberName %gl_PerVertex 3 "gl_CullDistance" |
| 43 | + OpName %_ "" |
| 44 | + OpName %gl_VertexIndex "gl_VertexIndex" |
| 45 | + OpMemberDecorate %gl_PerVertex 0 BuiltIn Position |
| 46 | + OpMemberDecorate %gl_PerVertex 1 BuiltIn PointSize |
| 47 | + OpMemberDecorate %gl_PerVertex 2 BuiltIn ClipDistance |
| 48 | + OpMemberDecorate %gl_PerVertex 3 BuiltIn CullDistance |
| 49 | + OpDecorate %gl_PerVertex Block |
| 50 | + OpDecorate %gl_VertexIndex BuiltIn VertexIndex |
| 51 | + %void = OpTypeVoid |
| 52 | + %3 = OpTypeFunction %void |
| 53 | + %float = OpTypeFloat 32 |
| 54 | + %v4float = OpTypeVector %float 4 |
| 55 | + %uint = OpTypeInt 32 0 |
| 56 | + %uint_1 = OpConstant %uint 1 |
| 57 | +%_arr_float_uint_1 = OpTypeArray %float %uint_1 |
| 58 | +%gl_PerVertex = OpTypeStruct %v4float %float %_arr_float_uint_1 %_arr_float_uint_1 |
| 59 | +%_ptr_Output_gl_PerVertex = OpTypePointer Output %gl_PerVertex |
| 60 | + %_ = OpVariable %_ptr_Output_gl_PerVertex Output |
| 61 | + %int = OpTypeInt 32 1 |
| 62 | + %int_0 = OpConstant %int 0 |
| 63 | +%_ptr_Input_int = OpTypePointer Input %int |
| 64 | +%gl_VertexIndex = OpVariable %_ptr_Input_int Input |
| 65 | + %bool = OpTypeBool |
| 66 | + %float_n4 = OpConstant %float -4 |
| 67 | + %float_1 = OpConstant %float 1 |
| 68 | + %int_2 = OpConstant %int 2 |
| 69 | + %float_4 = OpConstant %float 4 |
| 70 | + %float_n1 = OpConstant %float -1 |
| 71 | + %float_0 = OpConstant %float 0 |
| 72 | +%_ptr_Output_v4float = OpTypePointer Output %v4float |
| 73 | + %main = OpFunction %void None %3 |
| 74 | + %5 = OpLabel |
| 75 | + %36 = OpFunctionCall %void %builtin_usage_ |
| 76 | + OpReturn |
| 77 | + OpFunctionEnd |
| 78 | +%builtin_usage_ = OpFunction %void None %3 |
| 79 | + %7 = OpLabel |
| 80 | + %20 = OpLoad %int %gl_VertexIndex |
| 81 | + %22 = OpIEqual %bool %20 %int_0 |
| 82 | + %25 = OpSelect %float %22 %float_n4 %float_1 |
| 83 | + %26 = OpLoad %int %gl_VertexIndex |
| 84 | + %28 = OpIEqual %bool %26 %int_2 |
| 85 | + %31 = OpSelect %float %28 %float_4 %float_n1 |
| 86 | + %33 = OpCompositeConstruct %v4float %25 %31 %float_0 %float_1 |
| 87 | + %35 = OpAccessChain %_ptr_Output_v4float %_ %int_0 |
| 88 | + OpStore %35 %33 |
| 89 | + OpReturn |
| 90 | + OpFunctionEnd |
0 commit comments