Merge pull request #483 from KhronosGroup/fix-466

Overhaul type_alias for MSL.
This commit is contained in:
Hans-Kristian Arntzen 2018-03-06 16:41:04 +01:00 committed by GitHub
commit b0a2de5b63
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
35 changed files with 739 additions and 225 deletions

View File

@ -0,0 +1,19 @@
#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
struct TestStruct
{
float4x4 transforms[6];
};
struct CB0
{
TestStruct CB0[16];
};
vertex void main0()
{
}

View File

@ -0,0 +1,34 @@
#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
constant uint3 gl_WorkGroupSize = uint3(32u, 1u, 1u);
struct T1
{
float3 a;
float b;
};
struct T1_1
{
packed_float3 a;
float b;
};
struct Buffer0
{
T1_1 buf0[1];
};
struct Buffer1
{
float buf1[1];
};
kernel void main0(device Buffer0& _15 [[buffer(0)]], device Buffer1& _34 [[buffer(1)]], uint3 gl_GlobalInvocationID [[thread_position_in_grid]])
{
_34.buf1[gl_GlobalInvocationID.x] = _15.buf0[0].b;
}

View File

@ -0,0 +1,28 @@
#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
constant uint3 gl_WorkGroupSize = uint3(32u, 1u, 1u);
struct T1
{
packed_float3 a;
float b;
};
struct Buffer0
{
T1 buf0[1];
};
struct Buffer1
{
float buf1[1];
};
kernel void main0(device Buffer0& _14 [[buffer(0)]], device Buffer1& _24 [[buffer(1)]], uint3 gl_GlobalInvocationID [[thread_position_in_grid]])
{
_24.buf1[gl_GlobalInvocationID.x] = _14.buf0[0].b;
}

View File

@ -13,9 +13,19 @@ struct s2
s1 b;
};
struct s1_1
{
int a;
};
struct s2_1
{
s1_1 b;
};
struct dstbuffer
{
s2 test[1];
s2_1 test[1];
};
constant s2 _31 = {};

View File

@ -67,11 +67,54 @@ struct SSBO1
float array[1];
};
struct S0_1
{
float2 a[1];
float b;
};
struct S1_1
{
packed_float3 a;
float b;
};
struct S2_1
{
float3 a[1];
float b;
};
struct S3_1
{
float2 a;
float b;
};
struct S4_1
{
float2 c;
};
struct Content_1
{
S0_1 m0s[1];
S1_1 m1s[1];
S2_1 m2s[1];
S0_1 m0;
S1_1 m1;
S2_1 m2;
S3_1 m3;
char pad7[4];
float m4;
S4_1 m3s[8];
};
struct SSBO0
{
Content content;
Content content1[2];
Content content2;
Content_1 content;
Content_1 content1[2];
Content_1 content2;
float array[1];
};

View File

@ -13,14 +13,24 @@ struct S1
float4 a;
};
struct S0_1
{
float4 a;
};
struct SSBO0
{
S0 s0s[1];
S0_1 s0s[1];
};
struct S1_1
{
float4 a;
};
struct SSBO1
{
S1 s1s[1];
S1_1 s1s[1];
};
struct SSBO2

View File

@ -0,0 +1,39 @@
#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
struct VertexOutput
{
float4 HPosition;
};
struct TestStruct
{
float3 position;
float radius;
};
struct TestStruct_1
{
packed_float3 position;
float radius;
};
struct CB0
{
TestStruct_1 CB0[16];
};
struct main0_out
{
float4 _entryPointOutput [[color(0)]];
};
fragment main0_out main0(constant CB0& _26 [[buffer(0)]], float4 gl_FragCoord [[position]])
{
main0_out out = {};
out._entryPointOutput = float4(_26.CB0[1].position, _26.CB0[1].radius);
return out;
}

View File

@ -13,9 +13,14 @@ struct UBO1
Str foo;
};
struct Str_1
{
float4x4 foo;
};
struct UBO2
{
Str foo;
Str_1 foo;
};
struct main0_out

View File

@ -16,6 +16,13 @@ struct UBO
Light lights[4];
};
struct Light_1
{
float3 Position;
float Radius;
float4 Color;
};
struct main0_in
{
float3 aNormal [[attribute(1)]];

View File

@ -1,37 +0,0 @@
#version 310 es
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
struct alias
{
vec3 alias[100];
};
struct alias_1
{
vec4 alias;
vec2 alias_1[10];
alias alias_2[2];
};
struct alias_2
{
vec4 alias;
alias_1 alias_1;
};
layout(binding = 0, std430) buffer alias_3
{
alias_2 alias;
} alias_4;
layout(binding = 1, std140) buffer alias_5
{
alias_2 alias;
} alias_6;
void main()
{
alias_2 alias_7 = alias_4.alias;
alias_6.alias = alias_7;
}

View File

@ -43,6 +43,48 @@ struct Content
S4 m3s[8];
};
struct S0_1
{
vec2 a[1];
float b;
};
struct S1_1
{
vec3 a;
float b;
};
struct S2_1
{
vec3 a[1];
float b;
};
struct S3_1
{
vec2 a;
float b;
};
struct S4_1
{
vec2 c;
};
struct Content_1
{
S0_1 m0s[1];
S1_1 m1s[1];
S2_1 m2s[1];
S0_1 m0;
S1_1 m1;
S2_1 m2;
S3_1 m3;
float m4;
S4_1 m3s[8];
};
layout(binding = 1, std430) buffer SSBO1
{
Content content;
@ -61,9 +103,9 @@ layout(binding = 1, std430) buffer SSBO1
layout(binding = 0, std140) buffer SSBO0
{
Content content;
Content content1[2];
Content content2;
Content_1 content;
Content_1 content1[2];
Content_1 content2;
mat2 m0;
mat2 m1;
mat2x3 m2[4];

View File

@ -8,6 +8,13 @@ struct Foo
int c;
};
struct Foo_1
{
int a;
int b;
int c;
};
layout(binding = 1, std140) buffer SSBO1
{
layout(offset = 4) int a;
@ -20,7 +27,7 @@ layout(binding = 2, std430) buffer SSBO2
{
layout(offset = 4) int a;
layout(offset = 8) int b;
layout(offset = 16) Foo foo;
layout(offset = 16) Foo_1 foo;
layout(offset = 48) int c[8];
} ssbo2;

View File

@ -7,6 +7,11 @@ struct Str
mat4 foo;
};
struct Str_1
{
mat4 foo;
};
layout(binding = 0, std140) uniform UBO1
{
layout(row_major) Str foo;
@ -14,7 +19,7 @@ layout(binding = 0, std140) uniform UBO1
layout(binding = 1, std140) uniform UBO2
{
Str foo;
Str_1 foo;
} ubo0;
layout(location = 0) out vec4 FragColor;

View File

@ -0,0 +1,19 @@
#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
struct TestStruct
{
float4x4 transforms[6];
};
struct CB0
{
TestStruct CB0[16];
};
vertex void main0()
{
}

View File

@ -0,0 +1,38 @@
#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
constant uint3 gl_WorkGroupSize = uint3(32u, 1u, 1u);
struct T1
{
float3 a;
float b;
};
struct T1_1
{
packed_float3 a;
float b;
};
struct Buffer0
{
T1_1 buf0[1];
};
struct Buffer1
{
float buf1[1];
};
kernel void main0(device Buffer0& _15 [[buffer(0)]], device Buffer1& _34 [[buffer(1)]], uint3 gl_GlobalInvocationID [[thread_position_in_grid]])
{
T1 v;
v.a = _15.buf0[0].a;
v.b = _15.buf0[0].b;
float x = v.b;
_34.buf1[gl_GlobalInvocationID.x] = x;
}

View File

@ -0,0 +1,29 @@
#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
constant uint3 gl_WorkGroupSize = uint3(32u, 1u, 1u);
struct T1
{
packed_float3 a;
float b;
};
struct Buffer0
{
T1 buf0[1];
};
struct Buffer1
{
float buf1[1];
};
kernel void main0(device Buffer0& _14 [[buffer(0)]], device Buffer1& _24 [[buffer(1)]], uint3 gl_GlobalInvocationID [[thread_position_in_grid]])
{
float x = _14.buf0[0].b;
_24.buf1[gl_GlobalInvocationID.x] = x;
}

View File

@ -13,9 +13,19 @@ struct s2
s1 b;
};
struct s1_1
{
int a;
};
struct s2_1
{
s1_1 b;
};
struct dstbuffer
{
s2 test[1];
s2_1 test[1];
};
kernel void main0(device dstbuffer& _19 [[buffer(0)]])

View File

@ -67,11 +67,54 @@ struct SSBO1
float array[1];
};
struct S0_1
{
float2 a[1];
float b;
};
struct S1_1
{
packed_float3 a;
float b;
};
struct S2_1
{
float3 a[1];
float b;
};
struct S3_1
{
float2 a;
float b;
};
struct S4_1
{
float2 c;
};
struct Content_1
{
S0_1 m0s[1];
S1_1 m1s[1];
S2_1 m2s[1];
S0_1 m0;
S1_1 m1;
S2_1 m2;
S3_1 m3;
char pad7[4];
float m4;
S4_1 m3s[8];
};
struct SSBO0
{
Content content;
Content content1[2];
Content content2;
Content_1 content;
Content_1 content1[2];
Content_1 content2;
float array[1];
};

View File

@ -15,14 +15,24 @@ struct S1
float4 a;
};
struct S0_1
{
float4 a;
};
struct SSBO0
{
S0 s0s[1];
S0_1 s0s[1];
};
struct S1_1
{
float4 a;
};
struct SSBO1
{
S1 s1s[1];
S1_1 s1s[1];
};
struct SSBO2

View File

@ -0,0 +1,54 @@
#pragma clang diagnostic ignored "-Wmissing-prototypes"
#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
struct VertexOutput
{
float4 HPosition;
};
struct TestStruct
{
float3 position;
float radius;
};
struct TestStruct_1
{
packed_float3 position;
float radius;
};
struct CB0
{
TestStruct_1 CB0[16];
};
struct main0_out
{
float4 _entryPointOutput [[color(0)]];
};
float4 _main(thread const VertexOutput& IN, constant CB0& v_26)
{
TestStruct st;
st.position = v_26.CB0[1].position;
st.radius = v_26.CB0[1].radius;
float4 col = float4(st.position, st.radius);
return col;
}
fragment main0_out main0(constant CB0& v_26 [[buffer(0)]], float4 gl_FragCoord [[position]])
{
main0_out out = {};
VertexOutput IN;
IN.HPosition = gl_FragCoord;
VertexOutput param = IN;
VertexOutput param_1 = param;
out._entryPointOutput = _main(param_1, v_26);
return out;
}

View File

@ -13,9 +13,14 @@ struct UBO1
Str foo;
};
struct Str_1
{
float4x4 foo;
};
struct UBO2
{
Str foo;
Str_1 foo;
};
struct main0_out

View File

@ -16,6 +16,13 @@ struct UBO
Light lights[4];
};
struct Light_1
{
float3 Position;
float Radius;
float4 Color;
};
struct main0_in
{
float3 aNormal [[attribute(1)]];
@ -35,7 +42,7 @@ vertex main0_out main0(main0_in in [[stage_in]], constant UBO& _21 [[buffer(0)]]
out.vColor = float4(0.0);
for (int i = 0; i < 4; i++)
{
Light light;
Light_1 light;
light.Position = _21.lights[i].Position;
light.Radius = _21.lights[i].Radius;
light.Color = _21.lights[i].Color;

View File

@ -1,37 +0,0 @@
#version 310 es
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
struct alias
{
vec3 alias[100];
};
struct alias_1
{
vec4 alias;
vec2 alias_1[10];
alias alias_2[2];
};
struct alias_2
{
vec4 alias;
alias_1 alias_1;
};
layout(binding = 0, std430) buffer alias_3
{
alias_2 alias;
} alias_4;
layout(binding = 1, std140) buffer alias_5
{
alias_2 alias;
} alias_6;
void main()
{
alias_2 alias_7 = alias_4.alias;
alias_6.alias = alias_7;
}

View File

@ -43,6 +43,48 @@ struct Content
S4 m3s[8];
};
struct S0_1
{
vec2 a[1];
float b;
};
struct S1_1
{
vec3 a;
float b;
};
struct S2_1
{
vec3 a[1];
float b;
};
struct S3_1
{
vec2 a;
float b;
};
struct S4_1
{
vec2 c;
};
struct Content_1
{
S0_1 m0s[1];
S1_1 m1s[1];
S2_1 m2s[1];
S0_1 m0;
S1_1 m1;
S2_1 m2;
S3_1 m3;
float m4;
S4_1 m3s[8];
};
layout(binding = 1, std430) buffer SSBO1
{
Content content;
@ -61,9 +103,9 @@ layout(binding = 1, std430) buffer SSBO1
layout(binding = 0, std140) buffer SSBO0
{
Content content;
Content content1[2];
Content content2;
Content_1 content;
Content_1 content1[2];
Content_1 content2;
mat2 m0;
mat2 m1;
mat2x3 m2[4];

View File

@ -8,6 +8,13 @@ struct Foo
int c;
};
struct Foo_1
{
int a;
int b;
int c;
};
layout(binding = 1, std140) buffer SSBO1
{
layout(offset = 4) int a;
@ -20,7 +27,7 @@ layout(binding = 2, std430) buffer SSBO2
{
layout(offset = 4) int a;
layout(offset = 8) int b;
layout(offset = 16) Foo foo;
layout(offset = 16) Foo_1 foo;
layout(offset = 48) int c[8];
} ssbo2;

View File

@ -7,6 +7,11 @@ struct Str
mat4 foo;
};
struct Str_1
{
mat4 foo;
};
layout(binding = 0, std140) uniform UBO1
{
layout(row_major) Str foo;
@ -14,7 +19,7 @@ layout(binding = 0, std140) uniform UBO1
layout(binding = 1, std140) uniform UBO2
{
Str foo;
Str_1 foo;
} ubo0;
layout(location = 0) out vec4 FragColor;

View File

@ -0,0 +1,43 @@
; SPIR-V
; Version: 1.0
; Generator: Khronos Glslang Reference Front End; 3
; Bound: 18
; Schema: 0
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Vertex %main "main"
OpSource HLSL 500
OpName %main "main"
OpName %TestStruct "TestStruct"
OpMemberName %TestStruct 0 "transforms"
OpName %CB0 "CB0"
OpMemberName %CB0 0 "CB0"
OpName %_ ""
OpDecorate %_arr_mat4v4float_uint_6 ArrayStride 64
OpMemberDecorate %TestStruct 0 RowMajor
OpMemberDecorate %TestStruct 0 Offset 0
OpMemberDecorate %TestStruct 0 MatrixStride 16
OpDecorate %_arr_TestStruct_uint_16 ArrayStride 384
OpMemberDecorate %CB0 0 Offset 0
OpDecorate %CB0 Block
OpDecorate %_ DescriptorSet 0
OpDecorate %_ Binding 0
%void = OpTypeVoid
%3 = OpTypeFunction %void
%float = OpTypeFloat 32
%v4float = OpTypeVector %float 4
%mat4v4float = OpTypeMatrix %v4float 4
%uint = OpTypeInt 32 0
%uint_6 = OpConstant %uint 6
%_arr_mat4v4float_uint_6 = OpTypeArray %mat4v4float %uint_6
%TestStruct = OpTypeStruct %_arr_mat4v4float_uint_6
%uint_16 = OpConstant %uint 16
%_arr_TestStruct_uint_16 = OpTypeArray %TestStruct %uint_16
%CB0 = OpTypeStruct %_arr_TestStruct_uint_16
%_ptr_Uniform_CB0 = OpTypePointer Uniform %CB0
%_ = OpVariable %_ptr_Uniform_CB0 Uniform
%main = OpFunction %void None %3
%5 = OpLabel
OpReturn
OpFunctionEnd

View File

@ -0,0 +1,18 @@
#version 450
struct T1
{
vec3 a;
float b;
};
layout(std430, binding = 1) buffer Buffer0 { T1 buf0[]; };
layout(std430, binding = 2) buffer Buffer1 { float buf1[]; };
layout(local_size_x = 32, local_size_y = 1, local_size_z = 1) in;
void main()
{
// broken case in Metal!
T1 v = buf0[0];
float x = v.b;
buf1[gl_GlobalInvocationID.x] = x;
}

View File

@ -0,0 +1,16 @@
#version 450
struct T1
{
vec3 a;
float b;
};
layout(std430, binding = 1) buffer Buffer0 { T1 buf0[]; };
layout(std430, binding = 2) buffer Buffer1 { float buf1[]; };
layout(local_size_x = 32, local_size_y = 1, local_size_z = 1) in;
void main()
{
float x = buf0[0].b;
buf1[gl_GlobalInvocationID.x] = x;
}

View File

@ -0,0 +1,36 @@
#version 450
struct VertexOutput
{
vec4 HPosition;
};
struct TestStruct
{
vec3 position;
float radius;
};
layout(binding = 0, std140) uniform CB0
{
TestStruct CB0[16];
} _24;
layout(location = 0) out vec4 _entryPointOutput;
vec4 _main(VertexOutput IN)
{
TestStruct st;
st.position = _24.CB0[1].position;
st.radius = _24.CB0[1].radius;
vec4 col = vec4(st.position, st.radius);
return col;
}
void main()
{
VertexOutput IN;
IN.HPosition = gl_FragCoord;
VertexOutput param = IN;
_entryPointOutput = _main(param);
}

View File

@ -1,124 +0,0 @@
; SPIR-V
; Version: 1.0
; Generator: Khronos Glslang Reference Front End; 1
; Bound: 48
; Schema: 0
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %4 "main"
OpExecutionMode %4 LocalSize 1 1 1
OpSource ESSL 310
OpName %4 "alias"
OpName %15 "alias"
OpMemberName %15 0 "alias"
OpName %18 "alias"
OpMemberName %18 0 "alias"
OpMemberName %18 1 "alias"
OpMemberName %18 2 "alias"
OpName %19 "alias"
OpMemberName %19 0 "alias"
OpMemberName %19 1 "alias"
OpName %21 "alias"
OpName %24 "alias"
OpMemberName %24 0 "alias"
OpName %26 "alias"
OpMemberName %26 0 "alias"
OpMemberName %26 1 "alias"
OpMemberName %26 2 "alias"
OpName %27 "alias"
OpMemberName %27 0 "alias"
OpMemberName %27 1 "alias"
OpName %28 "alias"
OpMemberName %28 0 "alias"
OpName %30 "alias"
OpName %38 "alias"
OpMemberName %38 0 "alias"
OpName %40 "alias"
OpMemberName %40 0 "alias"
OpMemberName %40 1 "alias"
OpMemberName %40 2 "alias"
OpName %41 "alias"
OpMemberName %41 0 "alias"
OpMemberName %41 1 "alias"
OpName %42 "alias"
OpMemberName %42 0 "alias"
OpName %44 "alias"
OpDecorate %22 ArrayStride 8
OpDecorate %23 ArrayStride 16
OpMemberDecorate %24 0 Offset 0
OpDecorate %25 ArrayStride 1600
OpMemberDecorate %26 0 Offset 0
OpMemberDecorate %26 1 Offset 16
OpMemberDecorate %26 2 Offset 96
OpMemberDecorate %27 0 Offset 0
OpMemberDecorate %27 1 Offset 16
OpMemberDecorate %28 0 Offset 0
OpDecorate %28 BufferBlock
OpDecorate %30 DescriptorSet 0
OpDecorate %30 Binding 0
OpDecorate %36 ArrayStride 16
OpDecorate %37 ArrayStride 16
OpMemberDecorate %38 0 Offset 0
OpDecorate %39 ArrayStride 1600
OpMemberDecorate %40 0 Offset 0
OpMemberDecorate %40 1 Offset 16
OpMemberDecorate %40 2 Offset 176
OpMemberDecorate %41 0 Offset 0
OpMemberDecorate %41 1 Offset 16
OpMemberDecorate %42 0 Offset 0
OpDecorate %42 BufferBlock
OpDecorate %44 DescriptorSet 0
OpDecorate %44 Binding 1
%2 = OpTypeVoid
%3 = OpTypeFunction %2
%6 = OpTypeFloat 32
%7 = OpTypeVector %6 4
%8 = OpTypeVector %6 2
%9 = OpTypeInt 32 0
%10 = OpConstant %9 10
%11 = OpTypeArray %8 %10
%12 = OpTypeVector %6 3
%13 = OpConstant %9 100
%14 = OpTypeArray %12 %13
%15 = OpTypeStruct %14
%16 = OpConstant %9 2
%17 = OpTypeArray %15 %16
%18 = OpTypeStruct %7 %11 %17
%19 = OpTypeStruct %7 %18
%20 = OpTypePointer Function %19
%22 = OpTypeArray %8 %10
%23 = OpTypeArray %12 %13
%24 = OpTypeStruct %23
%25 = OpTypeArray %24 %16
%26 = OpTypeStruct %7 %22 %25
%27 = OpTypeStruct %7 %26
%28 = OpTypeStruct %27
%29 = OpTypePointer Uniform %28
%30 = OpVariable %29 Uniform
%31 = OpTypeInt 32 1
%32 = OpConstant %31 0
%33 = OpTypePointer Uniform %27
%36 = OpTypeArray %8 %10
%37 = OpTypeArray %12 %13
%38 = OpTypeStruct %37
%39 = OpTypeArray %38 %16
%40 = OpTypeStruct %7 %36 %39
%41 = OpTypeStruct %7 %40
%42 = OpTypeStruct %41
%43 = OpTypePointer Uniform %42
%44 = OpVariable %43 Uniform
%46 = OpTypePointer Uniform %41
%4 = OpFunction %2 None %3
%5 = OpLabel
%21 = OpVariable %20 Function
%34 = OpAccessChain %33 %30 %32
%35 = OpLoad %27 %34
; This shader has an illegal aliased store for testing purposes. spirv-val is not run for this shader.
OpStore %21 %35
%45 = OpLoad %19 %21
%47 = OpAccessChain %46 %44 %32
; This shader has an illegal aliased store for testing purposes. spirv-val is not run for this shader.
OpStore %47 %45
OpReturn
OpFunctionEnd

View File

@ -188,7 +188,12 @@ string Compiler::to_name(uint32_t id, bool allow_alias) const
// as that can be overridden by the reflection APIs after parse.
auto &type = get<SPIRType>(id);
if (type.type_alias)
return to_name(type.type_alias);
{
// If the alias master has been specially packed, we will have emitted a clean variant as well,
// so skip the name aliasing here.
if (!has_decoration(type.type_alias, DecorationCPacked))
return to_name(type.type_alias);
}
}
if (meta[id].decoration.alias.empty())
@ -802,6 +807,71 @@ static bool is_valid_spirv_version(uint32_t version)
}
}
bool Compiler::type_is_block_like(const SPIRType &type) const
{
if (type.basetype != SPIRType::Struct)
return false;
if (has_decoration(type.self, DecorationBlock) ||
has_decoration(type.self, DecorationBufferBlock))
{
return true;
}
// Block-like types may have Offset decorations.
for (uint32_t i = 0; i < uint32_t(type.member_types.size()); i++)
if (has_member_decoration(type.self, i, DecorationOffset))
return true;
return false;
}
void Compiler::fixup_type_alias()
{
// Due to how some backends work, the "master" type of type_alias must be a block-like type if it exists.
// FIXME: Multiple alias types which are both block-like will be awkward, for now, it's best to just drop the type
// alias if the slave type is a block type.
for (auto &id : ids)
{
if (id.get_type() != TypeType)
continue;
auto &type = id.get<SPIRType>();
if (type.type_alias && type_is_block_like(type))
{
// Become the master.
for (auto &other_id : ids)
{
if (other_id.get_type() != TypeType)
continue;
if (other_id.get_id() == type.self)
continue;
auto &other_type = other_id.get<SPIRType>();
if (other_type.type_alias == type.type_alias)
other_type.type_alias = type.self;
}
get<SPIRType>(type.type_alias).type_alias = id.get_id();
type.type_alias = 0;
}
}
for (auto &id : ids)
{
if (id.get_type() != TypeType)
continue;
auto &type = id.get<SPIRType>();
if (type.type_alias && type_is_block_like(type))
{
// This is not allowed, drop the type_alias.
type.type_alias = 0;
}
}
}
void Compiler::parse()
{
auto len = spirv.size();
@ -853,6 +923,8 @@ void Compiler::parse()
}
}
}
fixup_type_alias();
}
void Compiler::flatten_interface_block(uint32_t id)

View File

@ -824,6 +824,9 @@ private:
// Used only to implement the old deprecated get_entry_point() interface.
const SPIREntryPoint &get_first_entry_point(const std::string &name) const;
SPIREntryPoint &get_first_entry_point(const std::string &name);
void fixup_type_alias();
bool type_is_block_like(const SPIRType &type) const;
};
}

View File

@ -612,7 +612,8 @@ void CompilerGLSL::emit_struct(SPIRType &type)
// with just different offsets, matrix layouts, etc ...
// Type-punning with these types is legal, which complicates things
// when we are storing struct and array types in an SSBO for example.
if (type.type_alias != 0)
// If the type master is packed however, we can no longer assume that the struct declaration will be redundant.
if (type.type_alias != 0 && !has_decoration(type.type_alias, DecorationCPacked))
return;
// Don't declare empty structs in GLSL, this is not allowed.

View File

@ -438,6 +438,11 @@ void CompilerMSL::mark_as_packable(SPIRType &type)
uint32_t mbr_type_id = type.member_types[mbr_idx];
auto &mbr_type = get<SPIRType>(mbr_type_id);
mark_as_packable(mbr_type);
if (mbr_type.type_alias)
{
auto &mbr_type_alias = get<SPIRType>(mbr_type.type_alias);
mark_as_packable(mbr_type_alias);
}
}
}
}