Merge pull request #393 from KhronosGroup/fix-391

Handle OpUnreachable in code-gen.
This commit is contained in:
Hans-Kristian Arntzen 2018-01-16 09:46:34 +01:00 committed by GitHub
commit 779ad0412f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 417 additions and 0 deletions

View File

@ -0,0 +1,44 @@
static int counter;
static float4 FragColor;
struct SPIRV_Cross_Input
{
nointerpolation int counter : TEXCOORD0;
};
struct SPIRV_Cross_Output
{
float4 FragColor : SV_Target0;
};
float4 _21;
void frag_main()
{
float4 _15;
float4 _17;
float4 _33;
do
{
if (counter == 10)
{
_33 = 10.0f.xxxx;
break;
}
else
{
_33 = 30.0f.xxxx;
break;
}
} while (false);
FragColor = _33;
}
SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)
{
counter = stage_input.counter;
frag_main();
SPIRV_Cross_Output stage_output;
stage_output.FragColor = FragColor;
return stage_output;
}

View File

@ -0,0 +1,40 @@
#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
constant float4 _21 = {};
struct main0_in
{
int counter [[user(locn0)]];
};
struct main0_out
{
float4 FragColor [[color(0)]];
};
fragment main0_out main0(main0_in in [[stage_in]])
{
main0_out out = {};
float4 _15;
float4 _17;
float4 _33;
do
{
if (in.counter == 10)
{
_33 = float4(10.0);
break;
}
else
{
_33 = float4(30.0);
break;
}
} while (false);
out.FragColor = _33;
return out;
}

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,46 @@
static int counter;
static float4 FragColor;
struct SPIRV_Cross_Input
{
nointerpolation int counter : TEXCOORD0;
};
struct SPIRV_Cross_Output
{
float4 FragColor : SV_Target0;
};
float4 _21;
void frag_main()
{
float4 _15;
float4 _17;
float4 _24;
float4 _33;
_24 = _21;
for (;;)
{
if (counter == 10)
{
_33 = 10.0f.xxxx;
break;
}
else
{
_33 = 30.0f.xxxx;
break;
}
}
FragColor = _33;
}
SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)
{
counter = stage_input.counter;
frag_main();
SPIRV_Cross_Output stage_output;
stage_output.FragColor = FragColor;
return stage_output;
}

View File

@ -0,0 +1,42 @@
#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
constant float4 _21 = {};
struct main0_in
{
int counter [[user(locn0)]];
};
struct main0_out
{
float4 FragColor [[color(0)]];
};
fragment main0_out main0(main0_in in [[stage_in]])
{
main0_out out = {};
float4 _15;
float4 _17;
float4 _24;
float4 _33;
_24 = _21;
for (;;)
{
if (in.counter == 10)
{
_33 = float4(10.0);
break;
}
else
{
_33 = float4(30.0);
break;
}
}
out.FragColor = _33;
return out;
}

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

@ -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

@ -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.");
}