From 20c316718c4968fc7db7c329ff33f180512ef808 Mon Sep 17 00:00:00 2001 From: Rhys Perry Date: Fri, 16 May 2025 17:25:34 +0100 Subject: [PATCH] rusticl: support NIR_DEBUG=invalidate_metadata/extended_validation Signed-off-by: Rhys Perry Reviewed-by: @LingMan Part-of: --- .../frontends/rusticl/mesa/compiler/nir.rs | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/gallium/frontends/rusticl/mesa/compiler/nir.rs b/src/gallium/frontends/rusticl/mesa/compiler/nir.rs index 544d2d54857..302f650f383 100644 --- a/src/gallium/frontends/rusticl/mesa/compiler/nir.rs +++ b/src/gallium/frontends/rusticl/mesa/compiler/nir.rs @@ -48,12 +48,20 @@ impl<'a, T: 'a> Iterator for ExecListIter<'a, T> { macro_rules! nir_pass_impl { ($nir:ident, $pass:ident, $func:ident $(,$arg:expr)* $(,)?) => { { + // SAFETY: mutable static can't be read safely, but this value isn't going to change + let debug_opts = unsafe { nir_debug }; + let func_str = ::std::stringify!($func); let func_cstr = ::std::ffi::CString::new(func_str).unwrap(); let res = if unsafe { should_skip_nir(func_cstr.as_ptr()) } { println!("skipping {}", func_str); false } else { + if debug_opts & NIR_DEBUG_INVALIDATE_METADATA != 0 { + $nir.metadata_invalidate(); + } else if debug_opts & NIR_DEBUG_EXTENDED_VALIDATION != 0 { + $nir.metadata_require_most(); + } $nir.metadata_set_validation_flag(); if $nir.should_print() { println!("{}", func_str); @@ -66,17 +74,18 @@ macro_rules! nir_pass_impl { $nir.metadata_check_validation_flag(); true } else { + if debug_opts & NIR_DEBUG_EXTENDED_VALIDATION != 0 { + $nir.validate(&format!("after {} in {}:{}", func_str, file!(), line!())); + } false } }; - // SAFETY: mutable static can't be read safely, but this value isn't going to change - let ndebug = unsafe { nir_debug }; - if ndebug & NIR_DEBUG_CLONE != 0 { + if debug_opts & NIR_DEBUG_CLONE != 0 { $nir.validate_clone(); } - if ndebug & NIR_DEBUG_SERIALIZE != 0 { + if debug_opts & NIR_DEBUG_SERIALIZE != 0 { $nir.validate_serialize_deserialize(); } @@ -230,6 +239,16 @@ impl NirShader { unsafe { nir_metadata_set_validation_flag(self.nir.as_ptr()) } } + #[cfg(debug_assertions)] + pub fn metadata_invalidate(&self) { + unsafe { nir_metadata_invalidate(self.nir.as_ptr()) } + } + + #[cfg(debug_assertions)] + pub fn metadata_require_most(&self) { + unsafe { nir_metadata_require_most(self.nir.as_ptr()) } + } + #[cfg(debug_assertions)] pub fn validate(&self, when: &str) { let cstr = std::ffi::CString::new(when).unwrap();