Skip to content

Commit

Permalink
Enable debug image in debug builds automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
kvark committed Sep 21, 2024
1 parent 655f986 commit af520dc
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
4 changes: 3 additions & 1 deletion blade-render/code/gbuf.inc.wgsl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#use DEBUG_MODE

const MOTION_SCALE: f32 = 0.02;
const USE_MOTION_VECTORS: bool = true;
const WRITE_DEBUG_IMAGE: bool = false;
const WRITE_DEBUG_IMAGE: bool = DEBUG_MODE;
2 changes: 1 addition & 1 deletion blade-render/code/ray-trace.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ fn main(@builtin(global_invocation_id) global_id: vec3<u32>) {
var rng = random_init(global_index, parameters.frame_index);

let surface = read_surface(vec2<i32>(global_id.xy));
let enable_debug = all(global_id.xy == debug.mouse_pos);
let enable_debug = DEBUG_MODE && all(global_id.xy == debug.mouse_pos);
let enable_restir_debug = (debug.draw_flags & DebugDrawFlags_RESTIR) != 0u && enable_debug;
let ro = compute_restir(surface, vec2<i32>(global_id.xy), &rng, enable_restir_debug);
let color = ro.radiance;
Expand Down
1 change: 1 addition & 0 deletions blade-render/src/asset_hub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ impl AssetHub {
);

let mut sh_baker = crate::shader::Baker::new(gpu_context);
sh_baker.register_bool("DEBUG_MODE", cfg!(debug_assertions));
sh_baker.register_enum::<crate::render::DebugMode>();
sh_baker.register_bitflags::<crate::render::DebugDrawFlags>();
sh_baker.register_bitflags::<crate::render::DebugTextureFlags>();
Expand Down
26 changes: 21 additions & 5 deletions blade-render/src/shader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,20 @@ pub struct Shader {
pub raw: Result<blade_graphics::Shader, &'static str>,
}

pub struct Expansion(HashMap<String, u32>);
pub enum Expansion {
Values(HashMap<String, u32>),
Bool(bool),
}
impl Expansion {
pub fn from_enum<E: strum::IntoEnumIterator + fmt::Debug + Into<u32>>() -> Self {
Self(
Self::Values(
E::iter()
.map(|variant| (format!("{variant:?}"), variant.into()))
.collect(),
)
}
pub fn from_bitflags<F: bitflags::Flags<Bits = u32>>() -> Self {
Self(
Self::Values(
F::FLAGS
.iter()
.map(|flag| (flag.name().to_string(), flag.value().bits()))
Expand Down Expand Up @@ -64,6 +67,11 @@ impl Baker {
pub fn register_bitflags<F: bitflags::Flags<Bits = u32>>(&mut self) {
self.register::<F>(Expansion::from_bitflags::<F>());
}

pub fn register_bool(&mut self, name: &str, value: bool) {
self.expansions
.insert(name.to_string(), Expansion::Bool(value));
}
}

fn parse_impl(
Expand Down Expand Up @@ -93,8 +101,16 @@ fn parse_impl(
);
} else if line.starts_with("#use") {
let type_name = line.split_whitespace().last().unwrap();
for (key, value) in expansions[type_name].0.iter() {
writeln!(text_out, "const {}_{}: u32 = {}u;", type_name, key, value).unwrap();
match expansions[type_name] {
Expansion::Values(ref map) => {
for (key, value) in map.iter() {
writeln!(text_out, "const {}_{}: u32 = {}u;", type_name, key, value)
.unwrap();
}
}
Expansion::Bool(value) => {
writeln!(text_out, "const {}: bool = {};", type_name, value).unwrap();
}
}
} else {
*text_out += line;
Expand Down

0 comments on commit af520dc

Please sign in to comment.