From 7a8771f7b540f807fddf8751037ff7ca59afa6d0 Mon Sep 17 00:00:00 2001 From: Mary Strodl Date: Wed, 20 Mar 2024 17:09:39 -0400 Subject: [PATCH] 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: --- src/gallium/frontends/rusticl/mesa/compiler/nir.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/gallium/frontends/rusticl/mesa/compiler/nir.rs b/src/gallium/frontends/rusticl/mesa/compiler/nir.rs index 5fadf1810c5..ca140ae6f27 100644 --- a/src/gallium/frontends/rusticl/mesa/compiler/nir.rs +++ b/src/gallium/frontends/rusticl/mesa/compiler/nir.rs @@ -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) + } } }