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(iter_array_chunks)]
#![feature(portable_simd)]
#![feature(mpmc_channel)]
@@ -493,23 +492,17 @@ impl App {
.unwrap();
let trace_spv_code = include_bytes!("../shaders_out/trace.recompiled.spv");
let trace_spv_code_u32 = trace_spv_code
.as_chunks::<4>()
.0
.into_iter()
.map(|u| u32::from_le_bytes(*u))
.collect::<Vec<_>>();
let trace_spv_code_u32 = vulkano::shader::spirv::bytes_to_words(trace_spv_code)
.unwrap()
.into_owned();
let mut loader = rspirv::dr::Loader::new();
rspirv::binary::parse_words(trace_spv_code_u32, &mut loader).unwrap();
let trace_module = loader.module();
let normals_spv_code = include_bytes!("../shaders_out/normals.recompiled.spv");
let normals_spv_code_u32 = normals_spv_code
.as_chunks::<4>()
.0
.into_iter()
.map(|u| u32::from_le_bytes(*u))
.collect::<Vec<_>>();
let normals_spv_code_u32 = vulkano::shader::spirv::bytes_to_words(normals_spv_code)
.unwrap()
.into_owned();
let mut loader = rspirv::dr::Loader::new();
rspirv::binary::parse_words(normals_spv_code_u32, &mut loader).unwrap();
let normals_module = loader.module();
@@ -1409,35 +1402,35 @@ impl App {
}
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() {
error!("Could not read trace frag file");
return;
}
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() {
error!("Could not read trace vert file");
return;
}
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() {
error!("Could not read normals frag file");
return;
}
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() {
error!("Could not read fullscreen vert file");
return;
}
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() {
error!("Could not read lighting frag file");
return;
@@ -2276,15 +2269,12 @@ fn relpath(path: &str) -> PathBuf {
Path::new(env!("CARGO_MANIFEST_DIR")).join(path)
}
fn load_spv_from_file(name: &str) -> std::io::Result<Vec<u32>> {
let mut spv_file = std::fs::File::open(format!("shaders_out/{name}"))?;
let mut buf = vec![];
spv_file.read_to_end(&mut buf)?;
let spv_code_u32 = buf
.as_chunks::<4>()
.0
.into_iter()
.map(|u| u32::from_le_bytes(*u))
.collect::<Vec<_>>();
Ok(spv_code_u32)
fn read_spirv_words_from_file(name: &str) -> std::io::Result<Vec<u32>> {
let mut file = std::fs::File::open(format!("shaders_out/{name}"))?;
let mut bytes = vec![];
file.read_to_end(&mut bytes).unwrap();
vulkano::shader::spirv::bytes_to_words(&bytes)
.map_err(|err| std::io::Error::new(std::io::ErrorKind::InvalidData, err))
.map(|cow| cow.into_owned())
}