Skip to content
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-out] Handle struct padding in global variable initialiser #1974

Closed
hasali19 opened this issue Jun 6, 2022 · 1 comment · Fixed by #1988
Closed

[msl-out] Handle struct padding in global variable initialiser #1974

hasali19 opened this issue Jun 6, 2022 · 1 comment · Fixed by #1988
Labels
area: back-end Outputs of shader conversion kind: bug Something isn't working lang: Metal Metal Shading Language

Comments

@hasali19
Copy link
Contributor

hasali19 commented Jun 6, 2022

WGSL:

struct Struct_1 {
    a: u32,
    b: vec3<u32>,
    c: i32,
}

var<private> x: Struct_1 = Struct_1(0u, vec3<u32>(0u, 0u, 0u), 0);

MSL:

// language: metal2.0
#include <metal_stdlib>
#include <simd/simd.h>

using metal::uint;

struct Struct_1_ {
    uint a;
    char _pad1[12];
    metal::packed_uint3 b;
    int c;
};
constant metal::uint3 const_type_1_ = {0u, 0u, 0u};
constant Struct_1_ const_Struct_1_ = {0u, const_type_1_, 0};

The initialiser for const_Struct_1_ ignores the padding bytes of Struct_1_.

The metal compiler complains with

naga.metal:14:43: error: cannot initialize an array element of type 'const constant char' with an lvalue of type 'const constant metal::uint3' (aka 'const constant uint3')
constant Struct_1_ const_Struct_1_ = {0u, const_type_1_, 0};
                                          ^~~~~~~~~~~~~
@teoxoy teoxoy added kind: bug Something isn't working lang: Metal Metal Shading Language area: back-end Outputs of shader conversion labels Jun 13, 2022
@teoxoy teoxoy added this to the WGSL Specification V1 milestone Jun 13, 2022
@teoxoy
Copy link
Member

teoxoy commented Jun 16, 2022

This actually looks like a duplicate of #870. Looks like the fix in #1215 didn't cover global constants.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: back-end Outputs of shader conversion kind: bug Something isn't working lang: Metal Metal Shading Language
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants