rusticl/kernel: handle nir shader compilation failures gracefully

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41475>
This commit is contained in:
Karol Herbst 2026-05-10 17:06:00 +02:00 committed by Marge Bot
parent b8fa4fd258
commit b618cbb5e9
2 changed files with 24 additions and 8 deletions

View file

@ -1227,7 +1227,7 @@ pub(super) fn convert_spirv_to_nir(
args: &[spirv::SPIRVKernelArg],
spec_constants: &mut HashMap<u32, Vec<u8>>,
dev: &'static Device,
) -> SPIRVToNirResult {
) -> Option<SPIRVToNirResult> {
let cache = dev.screen().shader_cache();
let key = build.hash_key(cache.as_ref(), name, spec_constants);
let spirv_info = build.kernel_info(name).unwrap();
@ -1236,8 +1236,8 @@ pub(super) fn convert_spirv_to_nir(
.as_ref()
.and_then(|cache| cache.get(&mut key?))
.and_then(|entry| SPIRVToNirResult::deserialize(&entry, dev, spirv_info))
.unwrap_or_else(|| {
let nir = build.to_nir(name, dev, spec_constants);
.or_else(|| {
let nir = build.to_nir(name, dev, spec_constants)?;
if Platform::dbg().nir {
eprintln!("=== Printing nir for '{name}' after spirv_to_nir");
@ -1270,7 +1270,13 @@ pub(super) fn convert_spirv_to_nir(
}
}
SPIRVToNirResult::new(dev, spirv_info, args, default_build, optimized)
Some(SPIRVToNirResult::new(
dev,
spirv_info,
args,
default_build,
optimized,
))
})
}

View file

@ -137,8 +137,13 @@ impl ProgramBuild {
continue;
}
let build_result =
convert_spirv_to_nir(build, kernel_name, &args, &mut self.spec_constants, dev);
let Some(build_result) =
convert_spirv_to_nir(build, kernel_name, &args, &mut self.spec_constants, dev)
else {
build.status = CL_BUILD_ERROR;
build.log = "Internal compilation error".to_owned();
return;
};
kernel_info_set.insert(build_result.kernel_info);
self.builds_by_device.get_mut(dev).unwrap().kernels.insert(
@ -147,6 +152,11 @@ impl ProgramBuild {
);
}
// If all devices failed to rebuilt their kernels we simply return here.
if kernel_info_set.is_empty() {
return;
}
// we want the same (internal) args for every compiled kernel, for now
assert_eq!(kernel_info_set.len(), 1);
let mut kernel_info = kernel_info_set.into_iter().next().unwrap();
@ -223,7 +233,7 @@ impl DeviceProgramBuild {
kernel: &str,
device: &Device,
spec_constants: &mut HashMap<u32, Vec<u8>>,
) -> NirShader {
) -> Option<NirShader> {
assert_eq!(self.status, CL_BUILD_SUCCESS as cl_build_status);
let mut spec_constants: Vec<_> = spec_constants
@ -260,7 +270,7 @@ impl DeviceProgramBuild {
}
};
nir.unwrap()
nir
}
fn is_success(&self) -> bool {