nak: Add a NAK_DEBUG=panic option

This tells it to actually panic instead of unwinding and returning NULL.
I find myself commenting out the unwind code pretty frequently so I can
get GDB to break at the panic.  This should help avoid that extra debug
step.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/34435>
This commit is contained in:
Faith Ekstrand 2025-04-09 10:36:43 -05:00 committed by Marge Bot
parent 0750c4c5f1
commit 18b2bef45a

View file

@ -20,6 +20,7 @@ use std::sync::OnceLock;
#[repr(u8)]
enum DebugFlags {
Panic,
Print,
Serial,
Spill,
@ -45,6 +46,7 @@ impl Debug {
let mut flags = 0;
for flag in debug_str.split(',') {
match flag.trim() {
"panic" => flags |= 1 << DebugFlags::Panic as u8,
"print" => flags |= 1 << DebugFlags::Print as u8,
"serial" => flags |= 1 << DebugFlags::Serial as u8,
"spill" => flags |= 1 << DebugFlags::Spill as u8,
@ -61,6 +63,10 @@ impl Debug {
pub trait GetDebugFlags {
fn debug_flags(&self) -> u32;
fn panic(&self) -> bool {
self.debug_flags() & (1 << DebugFlags::Panic as u8) != 0
}
fn print(&self) -> bool {
self.debug_flags() & (1 << DebugFlags::Print as u8) != 0
}
@ -469,8 +475,12 @@ pub extern "C" fn nak_compile_shader(
robust2_modes: nir_variable_mode,
fs_key: *const nak_fs_key,
) -> *mut nak_shader_bin {
panic::catch_unwind(|| {
let compile = || {
nak_compile_shader_internal(nir, dump_asm, nak, robust2_modes, fs_key)
})
.unwrap_or(std::ptr::null_mut())
};
if DEBUG.panic() {
compile()
} else {
panic::catch_unwind(compile).unwrap_or(std::ptr::null_mut())
}
}