[naga msl-out] Add padding to end of structs if required

This commit is contained in:
Jamie Nicol 2025-06-13 11:56:16 +01:00 committed by Jamie Nicol
parent 5f8d408fb8
commit d811258424
20 changed files with 36 additions and 3 deletions

View File

@ -4470,6 +4470,16 @@ impl<W: Write> Writer<W> {
} }
} }
} }
if last_offset < span {
let pad = span - last_offset;
writeln!(
self.out,
"{}char _pad{}[{}];",
back::INDENT,
members.len(),
pad
)?;
}
writeln!(self.out, "}};")?; writeln!(self.out, "}};")?;
} }
_ => { _ => {

View File

@ -12,6 +12,7 @@ struct gl_PerVertex {
float gl_PointSize; float gl_PointSize;
type_3 gl_ClipDistance; type_3 gl_ClipDistance;
type_3 gl_CullDistance; type_3 gl_CullDistance;
char _pad4[4];
}; };
struct VertexOutput { struct VertexOutput {
metal::float2 member; metal::float2 member;

View File

@ -12,6 +12,7 @@ struct type_4 {
float member_1; float member_1;
type_3 member_2; type_3 member_2;
type_3 member_3; type_3 member_3;
char _pad4[4];
}; };
void function( void function(

View File

@ -7,6 +7,7 @@ using metal::uint;
struct OurVertexShaderOutput { struct OurVertexShaderOutput {
metal::float4 position; metal::float4 position;
metal::float2 texcoord; metal::float2 texcoord;
char _pad2[8];
}; };
struct vsInput { struct vsInput {

View File

@ -16,6 +16,7 @@ struct GlobalConst {
}; };
struct AlignedWrapper { struct AlignedWrapper {
int value; int value;
char _pad1[4];
}; };
struct type_6 { struct type_6 {
metal::float2x2 inner[2]; metal::float2x2 inner[2];
@ -35,6 +36,7 @@ struct Bar {
char _pad4[4]; char _pad4[4];
type_10 arr; type_10 arr;
type_11 data; type_11 data;
char _pad6[8];
}; };
struct Baz { struct Baz {
metal::float3x2 m; metal::float3x2 m;

View File

@ -13,10 +13,12 @@ struct type_4 {
struct _atomic_compare_exchange_resultSint4_ { struct _atomic_compare_exchange_resultSint4_ {
int old_value; int old_value;
bool exchanged; bool exchanged;
char _pad2[3];
}; };
struct _atomic_compare_exchange_resultUint4_ { struct _atomic_compare_exchange_resultUint4_ {
uint old_value; uint old_value;
bool exchanged; bool exchanged;
char _pad2[3];
}; };
template <typename A> template <typename A>

View File

@ -14,10 +14,12 @@ struct Struct {
struct _atomic_compare_exchange_resultUint4_ { struct _atomic_compare_exchange_resultUint4_ {
uint old_value; uint old_value;
bool exchanged; bool exchanged;
char _pad2[3];
}; };
struct _atomic_compare_exchange_resultSint4_ { struct _atomic_compare_exchange_resultSint4_ {
int old_value; int old_value;
bool exchanged; bool exchanged;
char _pad2[3];
}; };
template <typename A> template <typename A>

View File

@ -18,6 +18,7 @@ struct Globals {
metal::float4 v; metal::float4 v;
metal::float3x4 m; metal::float3x4 m;
type_4 d; type_4 d;
char _pad4[12];
}; };
float index_array( float index_array(

View File

@ -24,6 +24,7 @@ struct Globals {
metal::float4 v; metal::float4 v;
metal::float3x4 m; metal::float3x4 m;
type_4 d; type_4 d;
char _pad4[12];
}; };
float index_array( float index_array(

View File

@ -7,6 +7,7 @@ using metal::uint;
struct Foo { struct Foo {
metal::float4 a; metal::float4 a;
int b; int b;
char _pad2[12];
}; };
struct type_6 { struct type_6 {
metal::float2x2 inner[1]; metal::float2x2 inner[1];

View File

@ -12,6 +12,7 @@ struct PushConstants {
struct FragmentIn { struct FragmentIn {
metal::float4 color; metal::float4 color;
uint primitive_index; uint primitive_index;
char _pad2[12];
}; };
struct main_Input { struct main_Input {

View File

@ -19,6 +19,7 @@ struct FragmentOutputVec2Scalar {
float scalarf; float scalarf;
int scalari; int scalari;
uint scalaru; uint scalaru;
char _pad6[4];
}; };
struct main_vec4vec3_Output { struct main_vec4vec3_Output {

View File

@ -21,6 +21,7 @@ struct UniformCompatible {
metal::long3 val_i64_3_; metal::long3 val_i64_3_;
metal::long4 val_i64_4_; metal::long4 val_i64_4_;
ulong final_value; ulong final_value;
char _pad12[24];
}; };
struct type_11 { struct type_11 {
ulong inner[2]; ulong inner[2];

View File

@ -7,6 +7,7 @@ using metal::uint;
struct VertexOutput { struct VertexOutput {
metal::float4 position; metal::float4 position;
float _varying; float _varying;
char _pad2[12];
}; };
struct FragmentOutput { struct FragmentOutput {
float depth; float depth;

View File

@ -18,6 +18,7 @@ struct FragmentInput {
float perspective_centroid; float perspective_centroid;
float perspective_sample; float perspective_sample;
float perspective_center; float perspective_center;
char _pad12[4];
}; };
struct vert_mainOutput { struct vert_mainOutput {

View File

@ -18,6 +18,7 @@ struct FragmentInput {
float perspective_centroid; float perspective_centroid;
float perspective_sample; float perspective_sample;
float perspective_center; float perspective_center;
char _pad11[4];
}; };
struct vert_mainOutput { struct vert_mainOutput {

View File

@ -13,11 +13,13 @@ struct VertexOutput {
metal::float4 position; metal::float4 position;
metal::float4 color; metal::float4 color;
metal::float2 texcoord; metal::float2 texcoord;
char _pad3[8];
}; };
struct VertexInput { struct VertexInput {
metal::float4 position; metal::float4 position;
metal::float3 normal; metal::float3 normal;
metal::float2 texcoord; metal::float2 texcoord;
char _pad3[8];
}; };
float unpackFloat32_(uint b0, uint b1, uint b2, uint b3) { float unpackFloat32_(uint b0, uint b1, uint b2, uint b3) {
return as_type<float>(b3 << 24 | b2 << 16 | b1 << 8 | b0); return as_type<float>(b3 << 24 | b2 << 16 | b1 << 8 | b0);

View File

@ -7,6 +7,7 @@ using metal::uint;
struct _atomic_compare_exchange_resultUint4_ { struct _atomic_compare_exchange_resultUint4_ {
uint old_value; uint old_value;
bool exchanged; bool exchanged;
char _pad2[3];
}; };
template <typename A> template <typename A>

View File

@ -10,6 +10,7 @@ struct S {
struct Test { struct Test {
S a; S a;
float b; float b;
char _pad2[12];
}; };
struct type_2 { struct type_2 {
metal::float3 inner[2]; metal::float3 inner[2];
@ -17,10 +18,12 @@ struct type_2 {
struct Test2_ { struct Test2_ {
type_2 a; type_2 a;
float b; float b;
char _pad2[12];
}; };
struct Test3_ { struct Test3_ {
metal::float4x3 a; metal::float4x3 a;
float b; float b;
char _pad2[12];
}; };
struct vertex_Output { struct vertex_Output {

View File

@ -211,7 +211,7 @@ fn create_struct_layout_tests(storage_type: InputStorageType) -> Vec<ShaderTest>
// Test for https://github.com/gfx-rs/wgpu/issues/5262. // Test for https://github.com/gfx-rs/wgpu/issues/5262.
// //
// The struct is supposed to have a size of 32 and alignment of 16, but on metal, it has size 24. // The struct is supposed to have a size of 32 and alignment of 16.
for ty in ["f32", "u32", "i32"] { for ty in ["f32", "u32", "i32"] {
let header = format!("struct Inner {{ vec: vec3<{ty}>, scalar1: u32, scalar2: u32 }}"); let header = format!("struct Inner {{ vec: vec3<{ty}>, scalar1: u32, scalar2: u32 }}");
let members = String::from("arr: array<Inner, 2>"); let members = String::from("arr: array<Inner, 2>");
@ -238,8 +238,7 @@ fn create_struct_layout_tests(storage_type: InputStorageType) -> Vec<ShaderTest>
&input_values, &input_values,
&[0, 1, 2, 3, 4, 8, 9, 10, 11, 12], &[0, 1, 2, 3, 4, 8, 9, 10, 11, 12],
) )
.header(header) .header(header),
.failures(Backends::METAL),
); );
} }