NirShader: don't fail on null constant_buffer

On iris (and probably other platforms too), an empty buffer could be a
null pointer. This is problematic, because even empty slices can't have
a null pointer. When we encounter an empty buffer, send an empty
static slice instead.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/28309>
This commit is contained in:
Mary Strodl 2024-03-20 17:09:39 -04:00 committed by Marge Bot
parent f9b3e32440
commit 7a8771f7b5

View file

@ -440,7 +440,12 @@ impl NirShader {
pub fn get_constant_buffer(&self) -> &[u8] {
unsafe {
let nir = self.nir.as_ref();
slice::from_raw_parts(nir.constant_data.cast(), nir.constant_data_size as usize)
// Sometimes, constant_data can be a null pointer if the size is 0
if nir.constant_data_size == 0 {
&[]
} else {
slice::from_raw_parts(nir.constant_data.cast(), nir.constant_data_size as usize)
}
}
}