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 SPIR-V when compiling a simple loop #1076

Open
Patryk27 opened this issue Jun 16, 2023 · 3 comments
Open

Malformed SPIR-V when compiling a simple loop #1076

Patryk27 opened this issue Jun 16, 2023 · 3 comments
Labels
t: bug Something isn't working

Comments

@Patryk27
Copy link

Patryk27 commented Jun 16, 2023

Hi,

Compiling this code:

#[spirv(compute(threads(8, 8)))]
pub fn main(#[spirv(descriptor_set = 0, binding = 0)] out: TexRgba32f) {
    let mut value = vec3(0.1, 0.2, 0.3);
    let mut i = 0;

    loop {
        if i >= 32 {
            break;
        }

        i += 1;
    }

    unsafe {
        out.write(uvec2(0, 0), value.extend(1.0));
    }
}

... will work, but adding a seemingly no-op value = value into that loop:

loop {
    value = value;

    if i >= 32 {
        break;
    }

    i += 1;
}

... will panic the compiler, saying:

error: malformed SPIR-V (in OpCompositeExtract: undefined ID %4547)

Meta:

rustc 1.71.0-nightly (1a5f8bce7 2023-05-26)
SPIRV-Tools v2023.2 unknown hash, 1980-01-01T00:00:00
@Patryk27 Patryk27 added the t: bug Something isn't working label Jun 16, 2023
@Patryk27
Copy link
Author

Patryk27 commented Jun 17, 2023

fwiw, an assignment after (or before) the loop triggers this error as well:

#[spirv(compute(threads(8, 8)))]
pub fn main(#[spirv(descriptor_set = 0, binding = 0)] out: TexRgba32f) {
    let mut val = vec3(0.1, 0.2, 0.3);
    let mut i = 0;

    while i < 10 {
        i += 1;
    }

    val = val;

    unsafe {
        out.write(uvec2(0, 0), val.extend(1.0));
    }
}

@schell
Copy link

schell commented Jul 29, 2023

@Patryk27 I think there's something up with while loops and loops with loop { if ... { break; } } because I have a number of shaders that work with for i in range that won't work with any other looping mechanism.

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

No branches or pull requests

3 participants
@schell @Patryk27 and others