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

Fields of Vertex struct being reordered on new rust version results in incorrect render #616

Open
nbvdkamp opened this issue Jan 16, 2023 · 2 comments

Comments

@nbvdkamp
Copy link

After updating my nightly rust install my luminance application started rendering my models completely incorrectly, as if the attribute data is being garbled. On the 2022-11-11 nightly build it still works as expected so I'm quite sure rust-lang/rust#102750 being merged is what caused things to break, though I haven't bisected yet.

This is my vertex struct:

#[derive(Copy, Clone, Debug, Semantics)]
pub enum VertexSemantics {
    #[sem(name = "position", repr = "[f32; 3]", wrapper = "VertexPosition")]
    Position,
    #[sem(name = "normal", repr = "[f32; 3]", wrapper = "VertexNormal")]
    Normal,
    #[sem(name = "uv", repr = "[f32; 2]", wrapper = "VertexUV")]
    TextureCoords,
}

#[derive(Copy, Clone, Vertex)]
#[vertex(sem = "VertexSemantics")]
pub struct Vertex {
    pub position: VertexPosition,
    pub normal: VertexNormal,
    pub uv: VertexUV,
}

Adding #[repr(C)] to Vertex fixes the issue so presumably luminance makes a bad assumption somewhere about vertex struct layout being not being reordered.

@nbvdkamp nbvdkamp changed the title Fields of Vertex struct being reordered on new rust version results in incorrect render result Fields of Vertex struct being reordered on new rust version results in incorrect render Jan 16, 2023
@hadronized
Copy link
Owner

Yes, they must be #[repr(C)]. I’ll add something to check that in the proc-macro.

@ColonelThirtyTwo
Copy link
Contributor

Luminance should use memoffset::offset_of, field_offset::offset_of, or equivalent to find the offsets in a way that works with #[repr(Rust)].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants