Skip to content

Instantly share code, notes, and snippets.

@seanbaxter
Last active July 7, 2020 15:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seanbaxter/608e855c1247e921c59f5672bd65f9f9 to your computer and use it in GitHub Desktop.
Save seanbaxter/608e855c1247e921c59f5672bd65f9f9 to your computer and use it in GitHub Desktop.
#version 450 core // note the GLSL version!
layout(location=0) out vec4 FragColor;
layout(binding=2) uniform ProgramBlock {
ivec2 counter;
};
int func(int x, int y) {
int sum = 0;
for(int i = 0; i < x; ++i) {
sum += i * i;
if((i % y) == 4)
continue;
}
sum /= 2;
return sum;
}
void main()
{
FragColor.z = func(counter.x, counter.y);
}
; SPIR-V
; Version: 1.0
; Generator: Google Shaderc over Glslang; 9
; Bound: 70
; Schema: 0
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %main "main" %FragColor
OpExecutionMode %main OriginUpperLeft
OpSource GLSL 450
OpSourceExtension "GL_GOOGLE_cpp_style_line_directive"
OpSourceExtension "GL_GOOGLE_include_directive"
OpName %main "main"
OpName %func_i1_i1_ "func(i1;i1;"
OpName %x "x"
OpName %y "y"
OpName %sum "sum"
OpName %i "i"
OpName %FragColor "FragColor"
OpName %ProgramBlock "ProgramBlock"
OpMemberName %ProgramBlock 0 "counter"
OpName %_ ""
OpName %param "param"
OpName %param_0 "param"
OpDecorate %FragColor Location 0
OpMemberDecorate %ProgramBlock 0 Offset 0
OpDecorate %ProgramBlock Block
OpDecorate %_ DescriptorSet 0
OpDecorate %_ Binding 2
%void = OpTypeVoid
%3 = OpTypeFunction %void
%int = OpTypeInt 32 1
%_ptr_Function_int = OpTypePointer Function %int
%8 = OpTypeFunction %int %_ptr_Function_int %_ptr_Function_int
%int_0 = OpConstant %int 0
%bool = OpTypeBool
%int_4 = OpConstant %int 4
%int_1 = OpConstant %int 1
%int_2 = OpConstant %int 2
%float = OpTypeFloat 32
%v4float = OpTypeVector %float 4
%_ptr_Output_v4float = OpTypePointer Output %v4float
%FragColor = OpVariable %_ptr_Output_v4float Output
%v2int = OpTypeVector %int 2
%ProgramBlock = OpTypeStruct %v2int
%_ptr_Uniform_ProgramBlock = OpTypePointer Uniform %ProgramBlock
%_ = OpVariable %_ptr_Uniform_ProgramBlock Uniform
%uint = OpTypeInt 32 0
%uint_0 = OpConstant %uint 0
%_ptr_Uniform_int = OpTypePointer Uniform %int
%uint_1 = OpConstant %uint 1
%uint_2 = OpConstant %uint 2
%_ptr_Output_float = OpTypePointer Output %float
%main = OpFunction %void None %3
%5 = OpLabel
%param = OpVariable %_ptr_Function_int Function
%param_0 = OpVariable %_ptr_Function_int Function
%59 = OpAccessChain %_ptr_Uniform_int %_ %int_0 %uint_0
%60 = OpLoad %int %59
OpStore %param %60
%63 = OpAccessChain %_ptr_Uniform_int %_ %int_0 %uint_1
%64 = OpLoad %int %63
OpStore %param_0 %64
%65 = OpFunctionCall %int %func_i1_i1_ %param %param_0
%66 = OpConvertSToF %float %65
%69 = OpAccessChain %_ptr_Output_float %FragColor %uint_2
OpStore %69 %66
OpReturn
OpFunctionEnd
%func_i1_i1_ = OpFunction %int None %8
%x = OpFunctionParameter %_ptr_Function_int
%y = OpFunctionParameter %_ptr_Function_int
%12 = OpLabel
%sum = OpVariable %_ptr_Function_int Function
%i = OpVariable %_ptr_Function_int Function
OpStore %sum %int_0
OpStore %i %int_0
OpBranch %16
%16 = OpLabel
OpLoopMerge %18 %19 None
OpBranch %20
%20 = OpLabel
%21 = OpLoad %int %i
%22 = OpLoad %int %x
%24 = OpSLessThan %bool %21 %22
OpBranchConditional %24 %17 %18
%17 = OpLabel
%25 = OpLoad %int %i
%26 = OpLoad %int %i
%27 = OpIMul %int %25 %26
%28 = OpLoad %int %sum
%29 = OpIAdd %int %28 %27
OpStore %sum %29
if((i % y) == 4)
%30 = OpLoad %int %i
%31 = OpLoad %int %y
%32 = OpSMod %int %30 %31
%34 = OpIEqual %bool %32 %int_4
merge block = %36
OpSelectionMerge %36 None
if(true) branch %35, which branches to %19, the continue block
if(false) branch to %36, which branches to %19, the continue block
However the true block may not visit the merge block #36.
OpBranchConditional %34 %35 %36
%35 = OpLabel
OpBranch %19
%36 = OpLabel
OpBranch %19
%19 = OpLabel
%38 = OpLoad %int %i
%40 = OpIAdd %int %38 %int_1
OpStore %i %40
OpBranch %16
%18 = OpLabel
%42 = OpLoad %int %sum
%43 = OpSDiv %int %42 %int_2
OpStore %sum %43
%44 = OpLoad %int %sum
OpReturnValue %44
OpFunctionEnd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment