Module: Mesa
Branch: main
Commit: 5e3b7bef1e1efa47530c35e86731085ff98dc2ec
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=5e3b7bef1e1efa47530c35e86731085ff98dc2ec

Author: Karol Herbst <kher...@redhat.com>
Date:   Fri Oct 27 18:03:05 2023 +0200

rusticl: handle failed maps gracefully

Signed-off-by: Karol Herbst <kher...@redhat.com>
Reviewed-by: @LingMan <18294-ling...@users.noreply.gitlab.freedesktop.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25937>

---

 src/gallium/frontends/rusticl/core/device.rs       | 18 ++++++++++++++----
 src/gallium/frontends/rusticl/core/kernel.rs       |  1 +
 src/gallium/frontends/rusticl/core/memory.rs       | 16 +++++++++++-----
 src/gallium/frontends/rusticl/mesa/pipe/context.rs |  8 ++++----
 4 files changed, 30 insertions(+), 13 deletions(-)

diff --git a/src/gallium/frontends/rusticl/core/device.rs 
b/src/gallium/frontends/rusticl/core/device.rs
index a0bb0652ee1..86596958ea7 100644
--- a/src/gallium/frontends/rusticl/core/device.rs
+++ b/src/gallium/frontends/rusticl/core/device.rs
@@ -68,7 +68,7 @@ pub trait HelperContextWrapper {
         offset: i32,
         size: i32,
         rw: RWFlags,
-    ) -> PipeTransfer;
+    ) -> Option<PipeTransfer>;
 
     fn texture_map_directly(
         &self,
@@ -77,7 +77,12 @@ pub trait HelperContextWrapper {
         rw: RWFlags,
     ) -> Option<PipeTransfer>;
 
-    fn texture_map_coherent(&self, res: &PipeResource, bx: &pipe_box, rw: 
RWFlags) -> PipeTransfer;
+    fn texture_map_coherent(
+        &self,
+        res: &PipeResource,
+        bx: &pipe_box,
+        rw: RWFlags,
+    ) -> Option<PipeTransfer>;
 
     fn create_compute_state(&self, nir: &NirShader, static_local_mem: u32) -> 
*mut c_void;
     fn delete_compute_state(&self, cso: *mut c_void);
@@ -140,7 +145,7 @@ impl<'a> HelperContextWrapper for HelperContext<'a> {
         offset: i32,
         size: i32,
         rw: RWFlags,
-    ) -> PipeTransfer {
+    ) -> Option<PipeTransfer> {
         self.lock
             .buffer_map(res, offset, size, rw, ResourceMapType::Coherent)
     }
@@ -154,7 +159,12 @@ impl<'a> HelperContextWrapper for HelperContext<'a> {
         self.lock.texture_map_directly(res, bx, rw)
     }
 
-    fn texture_map_coherent(&self, res: &PipeResource, bx: &pipe_box, rw: 
RWFlags) -> PipeTransfer {
+    fn texture_map_coherent(
+        &self,
+        res: &PipeResource,
+        bx: &pipe_box,
+        rw: RWFlags,
+    ) -> Option<PipeTransfer> {
         self.lock
             .texture_map(res, bx, rw, ResourceMapType::Coherent)
     }
diff --git a/src/gallium/frontends/rusticl/core/kernel.rs 
b/src/gallium/frontends/rusticl/core/kernel.rs
index 21a604c7192..3d5b724efea 100644
--- a/src/gallium/frontends/rusticl/core/kernel.rs
+++ b/src/gallium/frontends/rusticl/core/kernel.rs
@@ -1103,6 +1103,7 @@ impl Kernel {
                         RWFlags::RD,
                         ResourceMapType::Normal,
                     )
+                    .ok_or(CL_OUT_OF_RESOURCES)?
                     .with_ctx(ctx);
                 let mut buf: &[u8] =
                     unsafe { slice::from_raw_parts(tx.ptr().cast(), 
printf_size as usize) };
diff --git a/src/gallium/frontends/rusticl/core/memory.rs 
b/src/gallium/frontends/rusticl/core/memory.rs
index 55cf3747f4a..ec7f3bb96a3 100644
--- a/src/gallium/frontends/rusticl/core/memory.rs
+++ b/src/gallium/frontends/rusticl/core/memory.rs
@@ -451,13 +451,14 @@ impl Mem {
         let b = self.to_parent(&mut offset);
         let r = b.get_res()?.get(&q.device).unwrap();
 
-        Ok(ctx.buffer_map(
+        ctx.buffer_map(
             r,
             offset.try_into().map_err(|_| CL_OUT_OF_HOST_MEMORY)?,
             size.try_into().map_err(|_| CL_OUT_OF_HOST_MEMORY)?,
             rw,
             ResourceMapType::Normal,
-        ))
+        )
+        .ok_or(CL_OUT_OF_RESOURCES)
     }
 
     fn tx_raw_async(
@@ -492,7 +493,9 @@ impl Mem {
                 .screen()
                 .resource_create_buffer(size as u32, ResourceType::Staging)
                 .ok_or(CL_OUT_OF_RESOURCES)?;
-            let tx = ctx.buffer_map_coherent(&shadow, 0, size, rw);
+            let tx = ctx
+                .buffer_map_coherent(&shadow, 0, size, rw)
+                .ok_or(CL_OUT_OF_RESOURCES)?;
             Ok((tx, Some(shadow)))
         }
     }
@@ -518,7 +521,8 @@ impl Mem {
         assert!(!self.is_buffer());
 
         let r = self.get_res()?.get(&q.device).unwrap();
-        Ok(ctx.texture_map(r, bx, rw, ResourceMapType::Normal))
+        ctx.texture_map(r, bx, rw, ResourceMapType::Normal)
+            .ok_or(CL_OUT_OF_RESOURCES)
     }
 
     fn tx_image_raw_async(
@@ -555,7 +559,9 @@ impl Mem {
                     false,
                 )
                 .ok_or(CL_OUT_OF_RESOURCES)?;
-            let tx = ctx.texture_map_coherent(&shadow, bx, rw);
+            let tx = ctx
+                .texture_map_coherent(&shadow, bx, rw)
+                .ok_or(CL_OUT_OF_RESOURCES)?;
             Ok((tx, Some(shadow)))
         }
     }
diff --git a/src/gallium/frontends/rusticl/mesa/pipe/context.rs 
b/src/gallium/frontends/rusticl/mesa/pipe/context.rs
index abf9655af42..11472aa4891 100644
--- a/src/gallium/frontends/rusticl/mesa/pipe/context.rs
+++ b/src/gallium/frontends/rusticl/mesa/pipe/context.rs
@@ -248,10 +248,10 @@ impl PipeContext {
         size: i32,
         rw: RWFlags,
         map_type: ResourceMapType,
-    ) -> PipeTransfer {
+    ) -> Option<PipeTransfer> {
         let mut flags: pipe_map_flags = map_type.into();
         flags |= rw.into();
-        self._buffer_map(res, offset, size, flags).unwrap()
+        self._buffer_map(res, offset, size, flags)
     }
 
     pub fn buffer_map_directly(
@@ -285,10 +285,10 @@ impl PipeContext {
         bx: &pipe_box,
         rw: RWFlags,
         map_type: ResourceMapType,
-    ) -> PipeTransfer {
+    ) -> Option<PipeTransfer> {
         let mut flags: pipe_map_flags = map_type.into();
         flags |= rw.into();
-        self._texture_map(res, bx, flags).unwrap()
+        self._texture_map(res, bx, flags)
     }
 
     pub fn texture_map_directly(

Reply via email to