diff --git a/src/gallium/frontends/rusticl/api/memory.rs b/src/gallium/frontends/rusticl/api/memory.rs index 7010c706eed..3267d5011c8 100644 --- a/src/gallium/frontends/rusticl/api/memory.rs +++ b/src/gallium/frontends/rusticl/api/memory.rs @@ -1671,7 +1671,7 @@ fn enqueue_map_buffer( evs, event, block, - Box::new(move |q, ctx| b.sync_shadow_buffer(q, ctx, ptr)), + Box::new(move |q, ctx| b.sync_shadow(q, ctx, ptr)), )?; Ok(ptr) @@ -2156,7 +2156,7 @@ fn enqueue_map_image( evs, event, block, - Box::new(move |q, ctx| i.sync_shadow_image(q, ctx, ptr)), + Box::new(move |q, ctx| i.sync_shadow(q, ctx, ptr)), )?; Ok(ptr) diff --git a/src/gallium/frontends/rusticl/core/memory.rs b/src/gallium/frontends/rusticl/core/memory.rs index 5843758b78a..4bae0b1bf1a 100644 --- a/src/gallium/frontends/rusticl/core/memory.rs +++ b/src/gallium/frontends/rusticl/core/memory.rs @@ -1121,71 +1121,6 @@ impl MemBase { Ok(()) } - // TODO: only sync on map when the memory is not mapped with discard - pub fn sync_shadow_buffer( - &self, - q: &Queue, - ctx: &PipeContext, - ptr: *mut c_void, - ) -> CLResult<()> { - let mut lock = self.maps.lock().unwrap(); - if !lock.increase_ref(q.device, ptr) { - return Ok(()); - } - - if self.has_user_shadow_buffer(q.device)? { - self.read_to_user(q, ctx, 0, self.host_ptr, self.size) - } else { - if let Some(shadow) = lock.tx.get(&q.device).and_then(|tx| tx.shadow.as_ref()) { - let mut offset = 0; - let b = self.to_parent(&mut offset); - let res = b.get_res_of_dev(q.device)?; - let bx = create_pipe_box( - [offset, 0, 0].into(), - [self.size, 1, 1].into(), - CL_MEM_OBJECT_BUFFER, - )?; - ctx.resource_copy_region(res, shadow, &[0; 3], &bx); - } - Ok(()) - } - } - - // TODO: only sync on map when the memory is not mapped with discard - pub fn sync_shadow_image( - &self, - q: &Queue, - ctx: &PipeContext, - ptr: *mut c_void, - ) -> CLResult<()> { - let mut lock = self.maps.lock().unwrap(); - if !lock.increase_ref(q.device, ptr) { - return Ok(()); - } - - if self.has_user_shadow_buffer(q.device)? { - self.read_to_user_rect( - self.host_ptr, - q, - ctx, - &self.image_desc.size(), - &CLVec::default(), - 0, - 0, - &CLVec::default(), - self.image_desc.image_row_pitch, - self.image_desc.image_slice_pitch, - ) - } else { - if let Some(shadow) = lock.tx.get(q.device).and_then(|tx| tx.shadow.as_ref()) { - let res = self.get_res_of_dev(q.device)?; - let bx = self.image_desc.bx()?; - ctx.resource_copy_region(res, shadow, &[0, 0, 0], &bx); - } - Ok(()) - } - } - /// Maps the queue associated device's resource. /// /// Mapping resources could have been quite straightforward if OpenCL wouldn't allow for so @@ -1350,6 +1285,29 @@ impl Buffer { let ptr = unsafe { ptr.add(offset) }; Ok(ptr) } + + // TODO: only sync on map when the memory is not mapped with discard + pub fn sync_shadow(&self, q: &Queue, ctx: &PipeContext, ptr: *mut c_void) -> CLResult<()> { + let mut lock = self.maps.lock().unwrap(); + if !lock.increase_ref(q.device, ptr) { + return Ok(()); + } + + if self.has_user_shadow_buffer(q.device)? { + self.read_to_user(q, ctx, 0, self.host_ptr, self.size) + } else { + if let Some(shadow) = lock.tx.get(&q.device).and_then(|tx| tx.shadow.as_ref()) { + let res = self.get_res_of_dev(q.device)?; + let bx = create_pipe_box( + [self.offset, 0, 0].into(), + [self.size, 1, 1].into(), + CL_MEM_OBJECT_BUFFER, + )?; + ctx.resource_copy_region(res, shadow, &[0; 3], &bx); + } + Ok(()) + } + } } impl Image { @@ -1451,6 +1409,36 @@ impl Image { Ok(ptr) } + + // TODO: only sync on map when the memory is not mapped with discard + pub fn sync_shadow(&self, q: &Queue, ctx: &PipeContext, ptr: *mut c_void) -> CLResult<()> { + let mut lock = self.maps.lock().unwrap(); + if !lock.increase_ref(q.device, ptr) { + return Ok(()); + } + + if self.has_user_shadow_buffer(q.device)? { + self.read_to_user_rect( + self.host_ptr, + q, + ctx, + &self.image_desc.size(), + &CLVec::default(), + 0, + 0, + &CLVec::default(), + self.image_desc.image_row_pitch, + self.image_desc.image_slice_pitch, + ) + } else { + if let Some(shadow) = lock.tx.get(q.device).and_then(|tx| tx.shadow.as_ref()) { + let res = self.get_res_of_dev(q.device)?; + let bx = self.image_desc.bx()?; + ctx.resource_copy_region(res, shadow, &[0, 0, 0], &bx); + } + Ok(()) + } + } } pub struct Sampler {