From a54faaa3218ea599cb21967dbb8aea0f73cd7fa0 Mon Sep 17 00:00:00 2001 From: Jacob Hughes Date: Mon, 16 Oct 2023 09:51:19 -0400 Subject: [PATCH] debug_printf: glsl-out --- src/back/glsl/features.rs | 22 ++++++++++++++++++++++ src/back/glsl/mod.rs | 10 ++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/back/glsl/features.rs b/src/back/glsl/features.rs index 4aac9b2e67..ec9f2e8485 100644 --- a/src/back/glsl/features.rs +++ b/src/back/glsl/features.rs @@ -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; } } @@ -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(()) } @@ -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 diff --git a/src/back/glsl/mod.rs b/src/back/glsl/mod.rs index 7fe7b11135..af77ffef95 100644 --- a/src/back/glsl/mod.rs +++ b/src/back/glsl/mod.rs @@ -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, ");")? } }