nak: Return VK_ERROR_UNKNOWN on assertion failure

Previously, unwinding would abort the process when it reached the FFI
boundary. Instead, catch panics and report them to the client. The
default panic handler still runs and prints the assertion failure to
stderr.

Reviewed-by: Faith Ekstrand <faith.ekstrand@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/33247>
This commit is contained in:
Mel Henning 2024-12-12 18:24:50 -05:00 committed by Marge Bot
parent 2b6437a3f4
commit b6b1021303
2 changed files with 20 additions and 2 deletions

View file

@ -15,6 +15,7 @@ use std::env;
use std::ffi::{CStr, CString};
use std::fmt::Write;
use std::os::raw::c_void;
use std::panic;
use std::sync::OnceLock;
#[repr(u8)]
@ -376,8 +377,7 @@ macro_rules! pass {
};
}
#[no_mangle]
pub extern "C" fn nak_compile_shader(
fn nak_compile_shader_internal(
nir: *mut nir_shader,
dump_asm: bool,
nak: *const nak_compiler,
@ -441,3 +441,17 @@ pub extern "C" fn nak_compile_shader(
Box::new(ShaderBin::new(sm.as_ref(), &s.info, fs_key, code, &asm));
Box::into_raw(bin) as *mut nak_shader_bin
}
#[no_mangle]
pub extern "C" fn nak_compile_shader(
nir: *mut nir_shader,
dump_asm: bool,
nak: *const nak_compiler,
robust2_modes: nir_variable_mode,
fs_key: *const nak_fs_key,
) -> *mut nak_shader_bin {
panic::catch_unwind(|| {
nak_compile_shader_internal(nir, dump_asm, nak, robust2_modes, fs_key)
})
.unwrap_or(std::ptr::null_mut())
}

View file

@ -557,6 +557,10 @@ nvk_compile_nir_with_nak(struct nvk_physical_device *pdev,
robust2_modes |= nir_var_mem_ssbo;
shader->nak = nak_compile_shader(nir, dump_asm, pdev->nak, robust2_modes, fs_key);
if (!shader->nak)
return vk_errorf(pdev, VK_ERROR_UNKNOWN, "Internal compiler error in NAK");
shader->info = shader->nak->info;
shader->code_ptr = shader->nak->code;
shader->code_size = shader->nak->code_size;