From b0ece3c79047cb2af9f81ddd8ed745b6b9888d37 Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Sun, 25 Aug 2024 23:34:13 -0700 Subject: [PATCH] Include shader source into debug info --- blade-graphics/src/lib.rs | 1 + blade-graphics/src/shader.rs | 6 +++++- blade-graphics/src/vulkan/init.rs | 2 +- blade-graphics/src/vulkan/pipeline.rs | 15 +++++++++++++-- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/blade-graphics/src/lib.rs b/blade-graphics/src/lib.rs index a717305a..02e973f2 100644 --- a/blade-graphics/src/lib.rs +++ b/blade-graphics/src/lib.rs @@ -556,6 +556,7 @@ pub struct AccelerationStructureSizes { pub struct Shader { module: naga::Module, info: naga::valid::ModuleInfo, + source: String, } #[derive(Clone, Copy)] diff --git a/blade-graphics/src/shader.rs b/blade-graphics/src/shader.rs index 6cc9f6b2..c98a94a6 100644 --- a/blade-graphics/src/shader.rs +++ b/blade-graphics/src/shader.rs @@ -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 { diff --git a/blade-graphics/src/vulkan/init.rs b/blade-graphics/src/vulkan/init.rs index 0895ec85..f55a001c 100644 --- a/blade-graphics/src/vulkan/init.rs +++ b/blade-graphics/src/vulkan/init.rs @@ -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; } diff --git a/blade-graphics/src/vulkan/pipeline.rs b/blade-graphics/src/vulkan/pipeline.rs index 3ea7ab40..aa98cd76 100644 --- a/blade-graphics/src/vulkan/pipeline.rs +++ b/blade-graphics/src/vulkan/pipeline.rs @@ -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; @@ -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], @@ -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,