use vulkano spriv loading

This commit is contained in:
2025-12-03 00:42:38 +00:00
parent 336eb0203f
commit c477afaa98
+19 -29
View File
@@ -1,5 +1,4 @@
#![feature(variant_count)] #![feature(variant_count)]
#![feature(iter_array_chunks)]
#![feature(portable_simd)] #![feature(portable_simd)]
#![feature(mpmc_channel)] #![feature(mpmc_channel)]
@@ -493,23 +492,17 @@ impl App {
.unwrap(); .unwrap();
let trace_spv_code = include_bytes!("../shaders_out/trace.recompiled.spv"); let trace_spv_code = include_bytes!("../shaders_out/trace.recompiled.spv");
let trace_spv_code_u32 = trace_spv_code let trace_spv_code_u32 = vulkano::shader::spirv::bytes_to_words(trace_spv_code)
.as_chunks::<4>() .unwrap()
.0 .into_owned();
.into_iter()
.map(|u| u32::from_le_bytes(*u))
.collect::<Vec<_>>();
let mut loader = rspirv::dr::Loader::new(); let mut loader = rspirv::dr::Loader::new();
rspirv::binary::parse_words(trace_spv_code_u32, &mut loader).unwrap(); rspirv::binary::parse_words(trace_spv_code_u32, &mut loader).unwrap();
let trace_module = loader.module(); let trace_module = loader.module();
let normals_spv_code = include_bytes!("../shaders_out/normals.recompiled.spv"); let normals_spv_code = include_bytes!("../shaders_out/normals.recompiled.spv");
let normals_spv_code_u32 = normals_spv_code let normals_spv_code_u32 = vulkano::shader::spirv::bytes_to_words(normals_spv_code)
.as_chunks::<4>() .unwrap()
.0 .into_owned();
.into_iter()
.map(|u| u32::from_le_bytes(*u))
.collect::<Vec<_>>();
let mut loader = rspirv::dr::Loader::new(); let mut loader = rspirv::dr::Loader::new();
rspirv::binary::parse_words(normals_spv_code_u32, &mut loader).unwrap(); rspirv::binary::parse_words(normals_spv_code_u32, &mut loader).unwrap();
let normals_module = loader.module(); let normals_module = loader.module();
@@ -1409,35 +1402,35 @@ impl App {
} }
fn load_all_spv_from_file(&mut self, rcx: &mut RenderContext) { fn load_all_spv_from_file(&mut self, rcx: &mut RenderContext) {
let trace_frag = load_spv_from_file("trace.recompiled.spv"); let trace_frag = read_spirv_words_from_file("trace.recompiled.spv");
if trace_frag.is_err() { if trace_frag.is_err() {
error!("Could not read trace frag file"); error!("Could not read trace frag file");
return; return;
} }
let trace_frag = trace_frag.unwrap(); let trace_frag = trace_frag.unwrap();
let trace_vert = load_spv_from_file("trace.vert.spv"); let trace_vert = read_spirv_words_from_file("trace.vert.spv");
if trace_vert.is_err() { if trace_vert.is_err() {
error!("Could not read trace vert file"); error!("Could not read trace vert file");
return; return;
} }
let trace_vert = trace_vert.unwrap(); let trace_vert = trace_vert.unwrap();
let normals_frag = load_spv_from_file("normals.recompiled.spv"); let normals_frag = read_spirv_words_from_file("normals.recompiled.spv");
if normals_frag.is_err() { if normals_frag.is_err() {
error!("Could not read normals frag file"); error!("Could not read normals frag file");
return; return;
} }
let normals_frag = normals_frag.unwrap(); let normals_frag = normals_frag.unwrap();
let fullscreen_vert = load_spv_from_file("fullscreen.vert.spv"); let fullscreen_vert = read_spirv_words_from_file("fullscreen.vert.spv");
if fullscreen_vert.is_err() { if fullscreen_vert.is_err() {
error!("Could not read fullscreen vert file"); error!("Could not read fullscreen vert file");
return; return;
} }
let fullscreen_vert = fullscreen_vert.unwrap(); let fullscreen_vert = fullscreen_vert.unwrap();
let lighting_frag = load_spv_from_file("lighting.frag.spv"); let lighting_frag = read_spirv_words_from_file("lighting.frag.spv");
if lighting_frag.is_err() { if lighting_frag.is_err() {
error!("Could not read lighting frag file"); error!("Could not read lighting frag file");
return; return;
@@ -2276,15 +2269,12 @@ fn relpath(path: &str) -> PathBuf {
Path::new(env!("CARGO_MANIFEST_DIR")).join(path) Path::new(env!("CARGO_MANIFEST_DIR")).join(path)
} }
fn load_spv_from_file(name: &str) -> std::io::Result<Vec<u32>> { fn read_spirv_words_from_file(name: &str) -> std::io::Result<Vec<u32>> {
let mut spv_file = std::fs::File::open(format!("shaders_out/{name}"))?; let mut file = std::fs::File::open(format!("shaders_out/{name}"))?;
let mut buf = vec![]; let mut bytes = vec![];
spv_file.read_to_end(&mut buf)?; file.read_to_end(&mut bytes).unwrap();
let spv_code_u32 = buf
.as_chunks::<4>() vulkano::shader::spirv::bytes_to_words(&bytes)
.0 .map_err(|err| std::io::Error::new(std::io::ErrorKind::InvalidData, err))
.into_iter() .map(|cow| cow.into_owned())
.map(|u| u32::from_le_bytes(*u))
.collect::<Vec<_>>();
Ok(spv_code_u32)
} }