Skip to content

Commit

Permalink
Include shader source into debug info
Browse files Browse the repository at this point in the history
  • Loading branch information
kvark committed Sep 5, 2024
1 parent bf40d4f commit b0ece3c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
1 change: 1 addition & 0 deletions blade-graphics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,7 @@ pub struct AccelerationStructureSizes {
pub struct Shader {
module: naga::Module,
info: naga::valid::ModuleInfo,
source: String,
}

#[derive(Clone, Copy)]
Expand Down
6 changes: 5 additions & 1 deletion blade-graphics/src/shader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ impl super::Context {
"validation failed"
})?;

Ok(super::Shader { module, info })
Ok(super::Shader {
module,
info,
source: desc.source.to_owned(),
})
}

pub fn create_shader(&self, desc: super::ShaderDesc) -> super::Shader {
Expand Down
2 changes: 1 addition & 1 deletion blade-graphics/src/vulkan/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ impl super::Context {
});

let mut naga_flags = spv::WriterFlags::FORCE_POINT_SIZE;
if desc.validation {
if desc.validation || desc.capture {
naga_flags |= spv::WriterFlags::DEBUG;
}

Expand Down
15 changes: 13 additions & 2 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, str};
use std::{ffi, mem, path::Path, str};

const DUMP_PREFIX: Option<&str> = None;

Expand Down Expand Up @@ -55,7 +55,7 @@ impl super::Context {
fn load_shader(
&self,
sf: crate::ShaderFunction,
naga_options: &spv::Options,
naga_options_base: &spv::Options,
group_layouts: &[&crate::ShaderDataLayout],
group_infos: &mut [crate::ShaderDataInfo],
vertex_fetch_states: &[crate::VertexFetchState],
Expand All @@ -79,6 +79,17 @@ impl super::Context {
shader_stage: ep.stage,
entry_point: sf.entry_point.to_string(),
};
let mut naga_options_debug;
let naga_options = if self.naga_flags.contains(spv::WriterFlags::DEBUG) {
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(""),
});
&naga_options_debug
} else {
naga_options_base
};

let spv = spv::write_vec(
&module,
Expand Down

0 comments on commit b0ece3c

Please sign in to comment.