Handle OpUnreachable in code-gen.

Forgot to add it to emit_block_chain. It should just be a noop.
This commit is contained in:
Hans-Kristian Arntzen 2018-01-15 09:35:09 +01:00
parent 17f9026248
commit 0f4adaa09d
4 changed files with 123 additions and 0 deletions

View File

@ -0,0 +1,28 @@
#version 450
layout(location = 0) flat in int counter;
layout(location = 0) out vec4 FragColor;
vec4 _21;
void main()
{
vec4 _15;
vec4 _17;
vec4 _33;
do
{
if (counter == 10)
{
_33 = vec4(10.0);
break;
}
else
{
_33 = vec4(30.0);
break;
}
} while (false);
FragColor = _33;
}

View File

@ -0,0 +1,30 @@
#version 450
layout(location = 0) flat in int counter;
layout(location = 0) out vec4 FragColor;
vec4 _21;
void main()
{
vec4 _15;
vec4 _17;
vec4 _24;
vec4 _33;
_24 = _21;
for (;;)
{
if (counter == 10)
{
_33 = vec4(10.0);
break;
}
else
{
_33 = vec4(30.0);
break;
}
}
FragColor = _33;
}

View File

@ -0,0 +1,61 @@
; SPIR-V
; Version: 1.0
; Generator: Khronos Glslang Reference Front End; 3
; Bound: 47
; Schema: 0
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %main "main" %counter %FragColor
OpExecutionMode %main OriginUpperLeft
OpSource GLSL 450
OpName %main "main"
OpName %counter "counter"
OpName %FragColor "FragColor"
OpDecorate %counter Flat
OpDecorate %counter Location 0
OpDecorate %FragColor Location 0
%void = OpTypeVoid
%3 = OpTypeFunction %void
%float = OpTypeFloat 32
%v4float = OpTypeVector %float 4
%8 = OpTypeFunction %v4float
%int = OpTypeInt 32 1
%_ptr_Input_int = OpTypePointer Input %int
%counter = OpVariable %_ptr_Input_int Input
%int_10 = OpConstant %int 10
%bool = OpTypeBool
%float_10 = OpConstant %float 10
%21 = OpConstantComposite %v4float %float_10 %float_10 %float_10 %float_10
%float_30 = OpConstant %float 30
%25 = OpConstantComposite %v4float %float_30 %float_30 %float_30 %float_30
%_ptr_Output_v4float = OpTypePointer Output %v4float
%FragColor = OpVariable %_ptr_Output_v4float Output
%_ptr_Function_v4float = OpTypePointer Function %v4float
%false = OpConstantFalse %bool
%44 = OpUndef %v4float
%main = OpFunction %void None %3
%5 = OpLabel
OpBranch %33
%33 = OpLabel
%45 = OpPhi %v4float %44 %5 %44 %35
OpLoopMerge %34 %35 None
OpBranch %36
%36 = OpLabel
%37 = OpLoad %int %counter
%38 = OpIEqual %bool %37 %int_10
OpSelectionMerge %39 None
OpBranchConditional %38 %40 %41
%40 = OpLabel
OpBranch %34
%41 = OpLabel
OpBranch %34
%39 = OpLabel
OpUnreachable
%35 = OpLabel
OpBranchConditional %false %33 %34
%34 = OpLabel
%46 = OpPhi %v4float %21 %40 %25 %41 %44 %35
OpStore %FragColor %46
OpReturn
OpFunctionEnd

View File

@ -8357,6 +8357,10 @@ void CompilerGLSL::emit_block_chain(SPIRBlock &block)
statement(backend.discard_literal, ";");
break;
case SPIRBlock::Unreachable:
emit_next_block = false;
break;
default:
SPIRV_CROSS_THROW("Unimplemented block terminator.");
}