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");
}
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:
function_names
, so the function definitely did exist.Writing the exact same data to disk and using
new_library_with_file
instead works perfectly fine.Minimal reproducer that produces the failed assert inside the Metal driver with _with_data but not when using _with_file