forked from KhronosGroup/SPIRV-Cross
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MSL: Workaround Metal 3.1 regression bug on recursive input structs.
Metal 3.1 introduced a Metal regression bug which causes an infinite recursion crash during Metal's analysis of an entry point input structure that itself contains internal recursion. This patch works around this by replacing the recursive input declaration with a alternate variable of type void*, and then casting to the correct type at the top of the entry point function. - Add CompilerMSL::Options::replace_recursive_inputs to enable replacing recursive input. - Add Compiler::type_contains_recursion() to determine if a struct contains internal recursion, and add custom Decorations to mark such structs, to short-cut future similar checks. - Replace recursive input struct declarations with void*, and emit a recast to correct type at top of entry function. - Add unit test. - Compiler::type_is_top_level_block() remove hardcode reference to spirv_cross namespace, as it interferes with configurable namespaces (unrelated).
- Loading branch information
1 parent
724433d
commit 16fbf88
Showing
10 changed files
with
161 additions
and
10 deletions.
There are no files selected for viewing
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
33 changes: 33 additions & 0 deletions
33
reference/opt/shaders-msl/comp/metal3_1_regression_patch.replace-recursive-inputs.msl3.comp
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,33 @@ | ||
#include <metal_stdlib> | ||
#include <simd/simd.h> | ||
|
||
using namespace metal; | ||
|
||
struct recurs_1; | ||
|
||
struct recurs | ||
{ | ||
int m1; | ||
device recurs_1* m2; | ||
}; | ||
|
||
struct recurs_1 | ||
{ | ||
int m1; | ||
device recurs_1* m2; | ||
}; | ||
|
||
constant uint3 gl_WorkGroupSize [[maybe_unused]] = uint3(1u); | ||
|
||
kernel void main0(device void* nums_vp [[buffer(0)]], texture2d<uint, access::write> tex [[texture(0)]], uint3 gl_GlobalInvocationID [[thread_position_in_grid]]) | ||
{ | ||
device auto& nums = *(device recurs*)nums_vp; | ||
int rslt = 0; | ||
rslt = nums.m1; | ||
int _28 = nums.m1 + nums.m2->m1; | ||
rslt = _28; | ||
int _37 = _28 + nums.m2->m2->m1; | ||
rslt = _37; | ||
tex.write(uint4(uint(_37), 0u, 0u, 1u), uint2(int2(gl_GlobalInvocationID.xy))); | ||
} | ||
|
31 changes: 31 additions & 0 deletions
31
reference/shaders-msl/comp/metal3_1_regression_patch.replace-recursive-inputs.msl3.comp
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,31 @@ | ||
#include <metal_stdlib> | ||
#include <simd/simd.h> | ||
|
||
using namespace metal; | ||
|
||
struct recurs; | ||
|
||
struct recurs | ||
{ | ||
int m1; | ||
device recurs* m2; | ||
}; | ||
|
||
struct recurs_1 | ||
{ | ||
int m1; | ||
device recurs_1* m2; | ||
}; | ||
|
||
constant uint3 gl_WorkGroupSize [[maybe_unused]] = uint3(1u); | ||
|
||
kernel void main0(device void* nums_vp [[buffer(0)]], texture2d<uint, access::write> tex [[texture(0)]], uint3 gl_GlobalInvocationID [[thread_position_in_grid]]) | ||
{ | ||
device auto& nums = *(device recurs*)nums_vp; | ||
int rslt = 0; | ||
rslt += nums.m1; | ||
rslt += nums.m2->m1; | ||
rslt += nums.m2->m2->m1; | ||
tex.write(uint4(uint(rslt), 0u, 0u, 1u), uint2(int2(gl_GlobalInvocationID.xy))); | ||
} | ||
|
21 changes: 21 additions & 0 deletions
21
shaders-msl/comp/metal3_1_regression_patch.replace-recursive-inputs.msl3.comp
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,21 @@ | ||
#version 450 | ||
#extension GL_EXT_buffer_reference2 : require | ||
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in; | ||
|
||
layout(buffer_reference) buffer recurs; | ||
layout(buffer_reference, buffer_reference_align = 16, set = 0, binding = 1, std140) buffer recurs | ||
{ | ||
int m1; | ||
recurs m2; | ||
} nums; | ||
|
||
layout(set = 0, binding = 0, r32ui) uniform writeonly uimage2D tex; | ||
|
||
void main() | ||
{ | ||
int rslt = 0; | ||
rslt += nums.m1; | ||
rslt += nums.m2.m1; | ||
rslt += nums.m2.m2.m1; | ||
imageStore(tex, ivec2(gl_GlobalInvocationID.xy), uvec4(rslt, 0u, 0u, 1u)); | ||
} |
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
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
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