rusticl: proper PIPE_MAP flags for internal maps

Signed-off-by: Karol Herbst <kherbst@redhat.com>
Acked-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15439>
This commit is contained in:
Karol Herbst
2022-05-12 18:38:27 +02:00
committed by Marge Bot
parent 9a56920398
commit 6d8d30660a
4 changed files with 60 additions and 23 deletions
+2 -2
View File
@@ -91,11 +91,11 @@ impl<'a> HelperContextWrapper for HelperContext<'a> {
}
fn buffer_map_async(&self, res: &PipeResource, offset: i32, size: i32) -> PipeTransfer {
self.lock.buffer_map(res, offset, size, false)
self.lock.buffer_map(res, offset, size, false, RWFlags::RW)
}
fn texture_map_async(&self, res: &PipeResource, bx: &pipe_box) -> PipeTransfer {
self.lock.texture_map(res, bx, false)
self.lock.texture_map(res, bx, false, RWFlags::RW)
}
fn unmap(&self, tx: PipeTransfer) {
+2 -1
View File
@@ -10,6 +10,7 @@ use crate::impl_cl_type_trait;
use mesa_rust::compiler::clc::*;
use mesa_rust::compiler::nir::*;
use mesa_rust::pipe::context::RWFlags;
use mesa_rust_gen::*;
use mesa_rust_util::math::*;
use mesa_rust_util::serialize::*;
@@ -924,7 +925,7 @@ impl Kernel {
if let Some(printf_buf) = &printf_buf {
let tx = ctx
.buffer_map(printf_buf, 0, printf_size as i32, true)
.buffer_map(printf_buf, 0, printf_size as i32, true, RWFlags::RD)
.with_ctx(ctx);
let mut buf: &[u8] =
unsafe { slice::from_raw_parts(tx.ptr().cast(), printf_size as usize) };
+33 -17
View File
@@ -354,6 +354,7 @@ impl Mem {
ctx: Option<&PipeContext>,
mut offset: usize,
size: usize,
rw: RWFlags,
) -> CLResult<PipeTransfer> {
let b = self.to_parent(&mut offset);
let r = b.get_res()?.get(&q.device).unwrap();
@@ -366,6 +367,7 @@ impl Mem {
offset.try_into().map_err(|_| CL_OUT_OF_HOST_MEMORY)?,
size.try_into().map_err(|_| CL_OUT_OF_HOST_MEMORY)?,
true,
rw,
)
} else {
q.device.helper_ctx().buffer_map_async(
@@ -382,8 +384,9 @@ impl Mem {
ctx: &'a PipeContext,
offset: usize,
size: usize,
rw: RWFlags,
) -> CLResult<GuardedPipeTransfer<'a>> {
Ok(self.tx_raw(q, Some(ctx), offset, size)?.with_ctx(ctx))
Ok(self.tx_raw(q, Some(ctx), offset, size, rw)?.with_ctx(ctx))
}
fn tx_image_raw(
@@ -391,12 +394,13 @@ impl Mem {
q: &Arc<Queue>,
ctx: Option<&PipeContext>,
bx: &pipe_box,
rw: RWFlags,
) -> CLResult<PipeTransfer> {
assert!(!self.is_buffer());
let r = self.get_res()?.get(&q.device).unwrap();
Ok(if let Some(ctx) = ctx {
ctx.texture_map(r, bx, true)
ctx.texture_map(r, bx, true, rw)
} else {
q.device.helper_ctx().texture_map_async(r, bx)
})
@@ -407,8 +411,9 @@ impl Mem {
q: &Arc<Queue>,
ctx: &'a PipeContext,
bx: &pipe_box,
rw: RWFlags,
) -> CLResult<GuardedPipeTransfer<'a>> {
Ok(self.tx_image_raw(q, Some(ctx), bx)?.with_ctx(ctx))
Ok(self.tx_image_raw(q, Some(ctx), bx, rw)?.with_ctx(ctx))
}
pub fn has_same_parent(&self, other: &Self) -> bool {
@@ -454,7 +459,7 @@ impl Mem {
) -> CLResult<()> {
assert!(self.is_buffer());
let tx = self.tx(q, ctx, offset, size)?;
let tx = self.tx(q, ctx, offset, size, RWFlags::RD)?;
unsafe {
ptr::copy_nonoverlapping(tx.ptr(), ptr, size);
@@ -505,8 +510,13 @@ impl Mem {
if self.is_buffer() {
let bpp = dst.image_format.pixel_size().unwrap() as usize;
tx_src = self.tx(q, ctx, src_origin[0], region.pixels() * bpp)?;
tx_dst = dst.tx_image(q, ctx, &create_box(&dst_origin, region, dst.mem_type)?)?;
tx_src = self.tx(q, ctx, src_origin[0], region.pixels() * bpp, RWFlags::RD)?;
tx_dst = dst.tx_image(
q,
ctx,
&create_box(&dst_origin, region, dst.mem_type)?,
RWFlags::WR,
)?;
sw_copy(
tx_src.ptr(),
@@ -522,8 +532,13 @@ impl Mem {
)
} else {
let bpp = self.image_format.pixel_size().unwrap() as usize;
tx_src = self.tx_image(q, ctx, &create_box(&src_origin, region, self.mem_type)?)?;
tx_dst = dst.tx(q, ctx, dst_origin[0], region.pixels() * bpp)?;
tx_src = self.tx_image(
q,
ctx,
&create_box(&src_origin, region, self.mem_type)?,
RWFlags::RD,
)?;
tx_dst = dst.tx(q, ctx, dst_origin[0], region.pixels() * bpp, RWFlags::WR)?;
sw_copy(
tx_src.ptr(),
@@ -616,7 +631,7 @@ impl Mem {
if self.is_buffer() {
let (offset, size) =
buffer_offset_size(dst_origin, region, dst_row_pitch, dst_slice_pitch);
let tx = self.tx(q, ctx, offset, size)?;
let tx = self.tx(q, ctx, offset, size, RWFlags::WR)?;
sw_copy(
src,
@@ -676,13 +691,13 @@ impl Mem {
if self.is_buffer() {
let (offset, size) =
buffer_offset_size(src_origin, region, src_row_pitch, src_slice_pitch);
tx = self.tx(q, ctx, offset, size)?;
tx = self.tx(q, ctx, offset, size, RWFlags::RD)?;
pixel_size = 1;
} else {
assert!(dst_origin == &CLVec::default());
let bx = create_box(src_origin, region, self.mem_type)?;
tx = self.tx_image(q, ctx, &bx)?;
tx = self.tx_image(q, ctx, &bx, RWFlags::RD)?;
src_row_pitch = tx.row_pitch() as usize;
src_slice_pitch = tx.slice_pitch() as usize;
@@ -722,10 +737,10 @@ impl Mem {
assert!(dst.is_buffer());
let (offset, size) = buffer_offset_size(src_origin, region, src_row_pitch, src_slice_pitch);
let tx_src = self.tx(q, ctx, offset, size)?;
let tx_src = self.tx(q, ctx, offset, size, RWFlags::RD)?;
let (offset, size) = buffer_offset_size(dst_origin, region, dst_row_pitch, dst_slice_pitch);
let tx_dst = dst.tx(q, ctx, offset, size)?;
let tx_dst = dst.tx(q, ctx, offset, size, RWFlags::WR)?;
// TODO check to use hw accelerated paths (e.g. resource_copy_region or blits)
sw_copy(
@@ -797,13 +812,14 @@ impl Mem {
q: &Arc<Queue>,
ctx: Option<&PipeContext>,
lock: &'a mut MutexGuard<Mappings>,
rw: RWFlags,
) -> CLResult<&'a PipeTransfer> {
if !lock.tx.contains_key(&q.device) {
let tx = if self.is_buffer() {
self.tx_raw(q, ctx, 0, self.size)?
self.tx_raw(q, ctx, 0, self.size, rw)?
} else {
let bx = self.image_desc.bx()?;
self.tx_image_raw(q, ctx, &bx)?
self.tx_image_raw(q, ctx, &bx, rw)?
};
lock.tx.insert(q.device.clone(), (tx, 0));
@@ -833,7 +849,7 @@ impl Mem {
self.host_ptr
} else {
let tx = self.map(q, ctx, &mut lock)?;
let tx = self.map(q, ctx, &mut lock, RWFlags::RW)?;
tx.ptr()
};
@@ -873,7 +889,7 @@ impl Mem {
self.host_ptr
} else {
let tx = self.map(q, ctx, &mut lock)?;
let tx = self.map(q, ctx, &mut lock, RWFlags::RW)?;
if self.image_desc.dims() > 1 {
*row_pitch = tx.row_pitch() as usize;
@@ -19,6 +19,19 @@ pub struct PipeContext {
unsafe impl Send for PipeContext {}
unsafe impl Sync for PipeContext {}
#[repr(u32)]
pub enum RWFlags {
RD = pipe_map_flags::PIPE_MAP_READ.0,
WR = pipe_map_flags::PIPE_MAP_WRITE.0,
RW = pipe_map_flags::PIPE_MAP_READ_WRITE.0,
}
impl From<RWFlags> for pipe_map_flags {
fn from(rw: RWFlags) -> Self {
pipe_map_flags(rw as u32)
}
}
impl PipeContext {
pub(super) fn new(context: *mut pipe_context, screen: &Arc<PipeScreen>) -> Option<Self> {
let s = Self {
@@ -128,6 +141,7 @@ impl PipeContext {
offset: i32,
size: i32,
block: bool,
rw: RWFlags,
) -> PipeTransfer {
let mut b = pipe_box::default();
let mut out: *mut pipe_transfer = ptr::null_mut();
@@ -140,7 +154,7 @@ impl PipeContext {
let flags = match block {
false => pipe_map_flags::PIPE_MAP_UNSYNCHRONIZED,
true => pipe_map_flags(0),
} | pipe_map_flags::PIPE_MAP_READ_WRITE;
} | rw.into();
let ptr = unsafe {
self.pipe.as_ref().buffer_map.unwrap()(
@@ -160,13 +174,19 @@ impl PipeContext {
unsafe { self.pipe.as_ref().buffer_unmap.unwrap()(self.pipe.as_ptr(), tx) };
}
pub fn texture_map(&self, res: &PipeResource, bx: &pipe_box, block: bool) -> PipeTransfer {
pub fn texture_map(
&self,
res: &PipeResource,
bx: &pipe_box,
block: bool,
rw: RWFlags,
) -> PipeTransfer {
let mut out: *mut pipe_transfer = ptr::null_mut();
let flags = match block {
false => pipe_map_flags::PIPE_MAP_UNSYNCHRONIZED,
true => pipe_map_flags(0),
} | pipe_map_flags::PIPE_MAP_READ_WRITE;
} | rw.into();
let ptr = unsafe {
self.pipe.as_ref().texture_map.unwrap()(