rusticl/kernel: mark can_remove_var as unsafe and document it

Signed-off-by: Karol Herbst <git@karolherbst.de>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24470>
This commit is contained in:
Karol Herbst
2023-08-03 15:17:41 +02:00
committed by Marge Bot
parent 66c6061491
commit e331245541
+11 -5
View File
@@ -377,12 +377,18 @@ fn opt_nir(nir: &mut NirShader, dev: &Device) {
} {}
}
extern "C" fn can_remove_var(var: *mut nir_variable, _: *mut c_void) -> bool {
/// # Safety
///
/// Only safe to call when `var` is a valid pointer to a valid [`nir_variable`]
unsafe extern "C" fn can_remove_var(var: *mut nir_variable, _: *mut c_void) -> bool {
// SAFETY: It is the caller's responsibility to provide a valid and aligned pointer
let var_type = unsafe { (*var).type_ };
// SAFETY: `nir_variable`'s type invariant guarantees that the `type_` field is valid and
// properly aligned.
unsafe {
let var = var.as_ref().unwrap();
!glsl_type_is_image(var.type_)
&& !glsl_type_is_texture(var.type_)
&& !glsl_type_is_sampler(var.type_)
!glsl_type_is_image(var_type)
&& !glsl_type_is_texture(var_type)
&& !glsl_type_is_sampler(var_type)
}
}