rusticl/mesa/nir: Mark NirShader and NirPrintfInfo as Send and Sync
authorKarol Herbst <kherbst@redhat.com>
Wed, 4 Oct 2023 17:29:35 +0000 (19:29 +0200)
committerMarge Bot <emma+marge@anholt.net>
Sat, 14 Oct 2023 09:34:56 +0000 (09:34 +0000)
Signed-off-by: Karol Herbst <kherbst@redhat.com>
Reviewed-by: @LingMan <18294-LingMan@users.noreply.gitlab.freedesktop.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24062>

src/gallium/frontends/rusticl/mesa/compiler/nir.rs

index 1e05135..eb563ca 100644 (file)
@@ -114,6 +114,10 @@ pub struct NirPrintfInfo {
     printf_info: *mut u_printf_info,
 }
 
+// SAFETY: `u_printf_info` is considered immutable
+unsafe impl Send for NirPrintfInfo {}
+unsafe impl Sync for NirPrintfInfo {}
+
 impl NirPrintfInfo {
     pub fn u_printf(&self, buf: &[u8]) {
         unsafe {
@@ -140,6 +144,12 @@ pub struct NirShader {
     nir: NonNull<nir_shader>,
 }
 
+// SAFETY: It's safe to share a nir_shader between threads.
+unsafe impl Send for NirShader {}
+
+// SAFETY: We do not allow interior mutability with &NirShader
+unsafe impl Sync for NirShader {}
+
 impl NirShader {
     pub fn new(nir: *mut nir_shader) -> Option<Self> {
         NonNull::new(nir).map(|nir| Self { nir: nir })