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:
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user