Skip to content

Commit

Permalink
Include shader path in the debug info
Browse files Browse the repository at this point in the history
  • Loading branch information
kvark committed Sep 5, 2024
1 parent b0ece3c commit a14ad93
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
11 changes: 9 additions & 2 deletions blade-graphics/src/vulkan/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -695,9 +695,15 @@ impl super::Context {
});

let mut naga_flags = spv::WriterFlags::FORCE_POINT_SIZE;
if desc.validation || desc.capture {
let shader_debug_path = if desc.validation || desc.capture {
use std::{env, fs};
naga_flags |= spv::WriterFlags::DEBUG;
}
let dir = env::temp_dir().join("blade");
let _ = fs::create_dir(&dir);
Some(dir)
} else {
None
};

Ok(super::Context {
memory: Mutex::new(memory_manager),
Expand All @@ -712,6 +718,7 @@ impl super::Context {
surface,
physical_device,
naga_flags,
shader_debug_path,
instance,
_entry: entry,
})
Expand Down
3 changes: 2 additions & 1 deletion blade-graphics/src/vulkan/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use ash::{khr, vk};
use std::{num::NonZeroU32, ptr, sync::Mutex};
use std::{num::NonZeroU32, path::PathBuf, ptr, sync::Mutex};

mod command;
mod descriptor;
Expand Down Expand Up @@ -107,6 +107,7 @@ pub struct Context {
surface: Option<Mutex<Surface>>,
physical_device: vk::PhysicalDevice,
naga_flags: naga::back::spv::WriterFlags,
shader_debug_path: Option<PathBuf>,
instance: Instance,
_entry: ash::Entry,
}
Expand Down
17 changes: 14 additions & 3 deletions blade-graphics/src/vulkan/pipeline.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use ash::vk;
use naga::back::spv;
use std::{ffi, mem, path::Path, str};
use std::{ffi, mem, str};

const DUMP_PREFIX: Option<&str> = None;

Expand Down Expand Up @@ -79,12 +79,23 @@ impl super::Context {
shader_stage: ep.stage,
entry_point: sf.entry_point.to_string(),
};
let file_path;
let mut naga_options_debug;
let naga_options = if self.naga_flags.contains(spv::WriterFlags::DEBUG) {
let naga_options = if let Some(ref temp_dir) = self.shader_debug_path {
use std::{
fs,
hash::{DefaultHasher, Hash as _, Hasher as _},
};
let mut hasher = DefaultHasher::new();
sf.shader.source.hash(&mut hasher);
file_path = temp_dir.join(format!("{}-{:x}.wgsl", sf.entry_point, hasher.finish()));
log::debug!("Dumping processed shader code to: {}", file_path.display());
let _ = fs::write(&file_path, &sf.shader.source);

naga_options_debug = naga_options_base.clone();
naga_options_debug.debug_info = Some(naga::back::spv::DebugInfo {
source_code: &sf.shader.source,
file_name: Path::new(""),
file_name: &file_path,
});
&naga_options_debug
} else {
Expand Down

0 comments on commit a14ad93

Please sign in to comment.