Rust-GPU / rust-gpu

🐉 Making Rust a first-class language and ecosystem for GPU shaders 🚧
https://rust-gpu.github.io
Apache License 2.0
934 stars 26 forks source link

Regression on master when allocating arrays of arrays #46

Open LegNeato opened 2 weeks ago

LegNeato commented 2 weeks ago

Minimal repro that fails to compile:

use spirv_std::spirv;

#[spirv(fragment)]
pub fn main() {
    let x = [[1; 2]; 1];
}

Bisects to https://github.com/Rust-GPU/rust-gpu/commit/02cd3248ad13df8e0b4fa2962ceb57ac089e2d49

It was found in https://github.com/Rust-GPU/rust-gpu/pull/21#issuecomment-2381578892 (assuming it is the same issue, but at least that is what I started with to get a repro)

LegNeato commented 2 weeks ago

@eddyb not sure if this will be fixed by your qptr stuff.

eddyb commented 2 weeks ago

Is this the error you're seeing?

error: cannot cast between pointer types
       from `*i32`
         to `*[i32; 2]`

With my various changes I also get:

error: error:0:0 - OpStore Pointer <id> '32[%32]' is not a logical pointer.
         OpStore %32 %33

And with a full move to qptr, something goes wrong with qptr.copy:

error: error:0:0 - Opcode CopyMemorySized requires one of these capabilities: Addresses 
         OpCopyMemorySized %29 %30 %uint_8

(and I'm not getting the kind of SPIR-T errors I would expect, either).

02cd3248ad13df8e0b4fa2962ceb57ac089e2d49 shouldn't have broken anything like this, but that code is subtle and I am not exactly surprised.

My best guess is that something is being ambiguous about wanting access to the whole inner [_; 2] array, and instead it gets just the leaf field.

LegNeato commented 2 weeks ago

Yep, that's the error:

error: cannot cast between pointer types
       from `*i32`
         to `*[i32; 2]`