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

new_library_with_data is broken #308

Closed
K0bin opened this issue Apr 22, 2024 · 1 comment · Fixed by #309
Closed

new_library_with_data is broken #308

K0bin opened this issue Apr 22, 2024 · 1 comment · Fixed by #309

Comments

@K0bin
Copy link

K0bin commented Apr 22, 2024

There appears to be a memory corruption bug with new_library_with_data.

Calling it results in all kinds of weird errors. Here are a few I've run into today while trying to figure out my problem:

  • "readFunctionPublicOrPrivateMetadata:4956: failed assertion `Invalid library file/data (unexpected end of file)'"
  • "Compiler encountered an internal error"
  • "Function main0 does not exist" when trying to get a function from the library. And main0 does get listed when calling function_names, so the function definitely did exist.
  • "assertion failed: !ptr.is_null()" (in metal-0.27.0/src/pipeline/render.rs:675:1)

Writing the exact same data to disk and using new_library_with_file instead works perfectly fine.

use metal;

const BROKEN: bool = true;

fn main() {
    println!("Hello, world!");

    let device = metal::Device::system_default().unwrap();
    let data = std::fs::read("test.metallib").unwrap();
    let data_box = data.into_boxed_slice();
    let lib = if BROKEN {
        device.new_library_with_data(&data_box).unwrap()
    } else {
        device.new_library_with_file("test.metallib").unwrap()
    };
    std::mem::drop(data_box);
    let function = lib.get_function("main0", None).unwrap();
    let _pipeline = device.new_compute_pipeline_state_with_function(&function).unwrap();
    println!("Done");
}

Minimal reproducer that produces the failed assert inside the Metal driver with _with_data but not when using _with_file

@madsmtm
Copy link
Contributor

madsmtm commented Apr 22, 2024

Thanks for the reproducer, have posted #309 to fix this.

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

Successfully merging a pull request may close this issue.

2 participants