Skip to content

Commit

Permalink
debug_printf: glsl-out
Browse files Browse the repository at this point in the history
  • Loading branch information
exrook committed Oct 16, 2023
1 parent 54f02a5 commit bd404ff
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
22 changes: 22 additions & 0 deletions src/back/glsl/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ bitflags::bitflags! {
const IMAGE_SIZE = 1 << 20;
/// Dual source blending
const DUAL_SOURCE_BLENDING = 1 << 21;
/// Debug Printf
const DEBUG_PRINTF = 1 << 22;
}
}

Expand Down Expand Up @@ -235,6 +237,10 @@ impl FeaturesManager {
// https://registry.khronos.org/OpenGL/extensions/EXT/EXT_blend_func_extended.txt
writeln!(out, "#extension GL_EXT_blend_func_extended : require")?;
}
if self.0.contains(Features::DEBUG_PRINTF) {
// https://github.com/KhronosGroup/GLSL/blob/master/extensions/ext/GLSL_EXT_debug_printf.txt
writeln!(out, "#extension GL_EXT_debug_printf : enable")?;
}

Ok(())
}
Expand Down Expand Up @@ -407,6 +413,22 @@ impl<'a, W> Writer<'a, W> {
..
} = self;

for block in module
.functions
.iter()
.map(|(_, f)| &f.body)
.chain(std::iter::once(&entry_point.function.body))
{
for statement in block.iter() {
match *statement {
crate::Statement::DebugPrintf { .. } => {
features.request(Features::DEBUG_PRINTF)
}
_ => {}
}
}
}

// Loop trough all expressions in both functions and the entry point
// to check for needed features
for (expressions, info) in module
Expand Down
10 changes: 8 additions & 2 deletions src/back/glsl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2238,8 +2238,14 @@ impl<'a, W: Write> Writer<'a, W> {
writeln!(self.out, ");")?;
}
Statement::RayQuery { .. } => unreachable!(),
Statement::DebugPrintf { .. } => {
return Err(Error::Custom("debugPrintf is not implemented".to_string()));
Statement::DebugPrintf {
ref format,
ref arguments,
} => {
write!(self.out, "{level}")?;
write!(self.out, "debugPrintfEXT(\"{format}\",")?;
self.write_slice(arguments, |this, _, arg| this.write_expr(*arg, ctx))?;
writeln!(self.out, ");")?
}
}

Expand Down

0 comments on commit bd404ff

Please sign in to comment.