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

Malformed SPIRV after assignment to mutable reference #178

Open
FractalFir opened this issue Dec 13, 2024 · 1 comment
Open

Malformed SPIRV after assignment to mutable reference #178

FractalFir opened this issue Dec 13, 2024 · 1 comment
Labels
bug Something isn't working rustlantis

Comments

@FractalFir
Copy link
Contributor

Issue originally found by rustlantis.

This reduced example:

#![no_std]
use spirv_std::spirv;
#[spirv(compute(threads(1)))]
pub fn fn1(#[spirv(storage_buffer, descriptor_set = 0, binding = 0)] mut addr: &mut f32) {
    addr = addr;
    (*addr) = 0.0;
}

Results in invalid SPIR-V:

error: malformed SPIR-V (in OpStore: undefined ID %33)
  |
  = note: while lowering SPIR-V module to SPIR-T (spirt::spv::lower)
  = note: input SPIR-V module was saved to /home/michal/rust-gpu/target/spirv-builder/spirv-unknown-vulkan1.1/release/deps/sky_shader.spirt-lower-from-spv-input.spv

@FractalFir FractalFir added the bug Something isn't working label Dec 13, 2024
@LegNeato LegNeato changed the title Malformed SPIRV after assigement to mutable reference Malformed SPIRV after assignment to mutable reference Dec 13, 2024
@eddyb
Copy link
Collaborator

eddyb commented Dec 17, 2024

This was my minimal repro:

#[spirv(fragment)]
pub fn self_assignment(mut x: f32, y: &mut f32) {
    x = x;
    *y = x;
}

Crucially, the type of the self-assignment doesn't actually matter, the legacy mem2reg pass (which replaces variables with their contents, just like the LLVM mem2reg pass) is just buggy for this.

(My qptr replacement doesn't have this bug so I might be able to find what is wrong with the legacy mem2reg)

Also, I could've sworn I've seen this bug before, but maybe in the context of loops? (which made me assume it was a much more complicated issue)


Yupp this is the bug report I was thinking of:

Can't believe none of us tried x = x; to see if it worked...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working rustlantis
Projects
None yet
Development

No branches or pull requests

3 participants