hadronized/luminance-rs

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

Opened this issue · 2 comments

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.

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

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