-
Notifications
You must be signed in to change notification settings - Fork 575
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MSL: Terminate function with return value using return if ending in unreachable. #2436
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
reference/shaders-msl/asm/frag/unreachable-return.msl23.spv14.asm.frag
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#include <metal_stdlib> | ||
#include <simd/simd.h> | ||
|
||
using namespace metal; | ||
|
||
struct buff_t | ||
{ | ||
int m0[1024]; | ||
}; | ||
|
||
struct main0_out | ||
{ | ||
float4 frag_clr [[color(0)]]; | ||
}; | ||
|
||
fragment main0_out main0(device buff_t& buff [[buffer(0)]], float4 gl_FragCoord [[position]]) | ||
{ | ||
main0_out out = {}; | ||
int2 frag_coord = int4(gl_FragCoord).xy; | ||
int buff_idx = (frag_coord.y * 32) + frag_coord.x; | ||
out.frag_clr = float4(0.0, 0.0, 1.0, 1.0); | ||
buff.m0[buff_idx] = 1; | ||
discard_fragment(); | ||
return out; | ||
} | ||
|
78 changes: 78 additions & 0 deletions
78
shaders-msl/asm/frag/unreachable-return.msl23.spv14.asm.frag
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
; SPIR-V | ||
; Version: 1.5 | ||
; Generator: Khronos Glslang Reference Front End; 11 | ||
; Bound: 46 | ||
; Schema: 0 | ||
OpCapability Shader | ||
OpCapability DemoteToHelperInvocation | ||
OpExtension "SPV_EXT_demote_to_helper_invocation" | ||
%1 = OpExtInstImport "GLSL.std.450" | ||
OpMemoryModel Logical GLSL450 | ||
OpEntryPoint Fragment %main "main" %gl_FragCoord %frag_clr %buff | ||
OpExecutionMode %main OriginUpperLeft | ||
OpSource GLSL 450 | ||
OpName %main "main" | ||
OpName %frag_coord "frag_coord" | ||
OpName %gl_FragCoord "gl_FragCoord" | ||
OpName %buff_idx "buff_idx" | ||
OpName %frag_clr "frag_clr" | ||
OpName %buff_t "buff_t" | ||
OpMemberName %buff_t 0 "m0" | ||
OpName %buff "buff" | ||
OpDecorate %gl_FragCoord BuiltIn FragCoord | ||
OpDecorate %frag_clr Location 0 | ||
OpDecorate %_arr_int_uint_1024 ArrayStride 4 | ||
OpDecorate %buff_t Block | ||
OpMemberDecorate %buff_t 0 Offset 0 | ||
OpDecorate %buff Binding 0 | ||
OpDecorate %buff DescriptorSet 0 | ||
%void = OpTypeVoid | ||
%3 = OpTypeFunction %void | ||
%int = OpTypeInt 32 1 | ||
%v2int = OpTypeVector %int 2 | ||
%_ptr_Function_v2int = OpTypePointer Function %v2int | ||
%float = OpTypeFloat 32 | ||
%v4float = OpTypeVector %float 4 | ||
%_ptr_Input_v4float = OpTypePointer Input %v4float | ||
%gl_FragCoord = OpVariable %_ptr_Input_v4float Input | ||
%v4int = OpTypeVector %int 4 | ||
%_ptr_Function_int = OpTypePointer Function %int | ||
%uint = OpTypeInt 32 0 | ||
%uint_1 = OpConstant %uint 1 | ||
%int_32 = OpConstant %int 32 | ||
%uint_0 = OpConstant %uint 0 | ||
%_ptr_Output_v4float = OpTypePointer Output %v4float | ||
%frag_clr = OpVariable %_ptr_Output_v4float Output | ||
%float_0 = OpConstant %float 0 | ||
%float_1 = OpConstant %float 1 | ||
%34 = OpConstantComposite %v4float %float_0 %float_0 %float_1 %float_1 | ||
%uint_1024 = OpConstant %uint 1024 | ||
%_arr_int_uint_1024 = OpTypeArray %int %uint_1024 | ||
%buff_t = OpTypeStruct %_arr_int_uint_1024 | ||
%_ptr_StorageBuffer_buff_t = OpTypePointer StorageBuffer %buff_t | ||
%buff = OpVariable %_ptr_StorageBuffer_buff_t StorageBuffer | ||
%int_0 = OpConstant %int 0 | ||
%int_1 = OpConstant %int 1 | ||
%_ptr_StorageBuffer_int = OpTypePointer StorageBuffer %int | ||
%main = OpFunction %void None %3 | ||
%5 = OpLabel | ||
%frag_coord = OpVariable %_ptr_Function_v2int Function | ||
%buff_idx = OpVariable %_ptr_Function_int Function | ||
%14 = OpLoad %v4float %gl_FragCoord | ||
%16 = OpConvertFToS %v4int %14 | ||
%17 = OpVectorShuffle %v2int %16 %16 0 1 | ||
OpStore %frag_coord %17 | ||
%22 = OpAccessChain %_ptr_Function_int %frag_coord %uint_1 | ||
%23 = OpLoad %int %22 | ||
%25 = OpIMul %int %23 %int_32 | ||
%27 = OpAccessChain %_ptr_Function_int %frag_coord %uint_0 | ||
%28 = OpLoad %int %27 | ||
%29 = OpIAdd %int %25 %28 | ||
OpStore %buff_idx %29 | ||
OpStore %frag_clr %34 | ||
%41 = OpLoad %int %buff_idx | ||
%44 = OpAccessChain %_ptr_StorageBuffer_int %buff %int_0 %41 | ||
OpStore %44 %int_1 | ||
OpDemoteToHelperInvocation | ||
OpUnreachable | ||
OpFunctionEnd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This OpUnreachable is completely bogus fwiw. Having Unreachable post-dominate the entry block means that the entire shader is UB to execute, but ... whatever.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I had the same suspicion and will probably have to visit the generation that results in this in my use case. But it seems to function elsewhere (I think just because discarding eliminates potential side effects?) and I figured also that, while the spec says that executing OpUnreachable is UB, there is no indication that it should fail to compile.