mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-05 05:18:08 +02:00
rusticl: rework resource mappings a little
The _async variants will be removed later. Signed-off-by: Karol Herbst <kherbst@redhat.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18793>
This commit is contained in:
parent
6b235361f7
commit
ea5b23c75b
4 changed files with 116 additions and 49 deletions
|
|
@ -91,11 +91,13 @@ 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, RWFlags::RW)
|
||||
self.lock
|
||||
.buffer_map(res, offset, size, RWFlags::RW, ResourceMapType::Async)
|
||||
}
|
||||
|
||||
fn texture_map_async(&self, res: &PipeResource, bx: &pipe_box) -> PipeTransfer {
|
||||
self.lock.texture_map(res, bx, false, RWFlags::RW)
|
||||
self.lock
|
||||
.texture_map(res, bx, RWFlags::RW, ResourceMapType::Async)
|
||||
}
|
||||
|
||||
fn unmap(&self, tx: PipeTransfer) {
|
||||
|
|
|
|||
|
|
@ -11,6 +11,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::pipe::context::ResourceMapType;
|
||||
use mesa_rust::pipe::screen::ResourceType;
|
||||
use mesa_rust_gen::*;
|
||||
use mesa_rust_util::math::*;
|
||||
|
|
@ -943,7 +944,13 @@ impl Kernel {
|
|||
|
||||
if let Some(printf_buf) = &printf_buf {
|
||||
let tx = ctx
|
||||
.buffer_map(printf_buf, 0, printf_size as i32, true, RWFlags::RD)
|
||||
.buffer_map(
|
||||
printf_buf,
|
||||
0,
|
||||
printf_size as i32,
|
||||
RWFlags::RD,
|
||||
ResourceMapType::Normal,
|
||||
)
|
||||
.with_ctx(ctx);
|
||||
let mut buf: &[u8] =
|
||||
unsafe { slice::from_raw_parts(tx.ptr().cast(), printf_size as usize) };
|
||||
|
|
|
|||
|
|
@ -380,8 +380,8 @@ impl Mem {
|
|||
r,
|
||||
offset.try_into().map_err(|_| CL_OUT_OF_HOST_MEMORY)?,
|
||||
size.try_into().map_err(|_| CL_OUT_OF_HOST_MEMORY)?,
|
||||
true,
|
||||
rw,
|
||||
ResourceMapType::Normal,
|
||||
)
|
||||
} else {
|
||||
q.device.helper_ctx().buffer_map_async(
|
||||
|
|
@ -414,7 +414,7 @@ impl Mem {
|
|||
|
||||
let r = self.get_res()?.get(&q.device).unwrap();
|
||||
Ok(if let Some(ctx) = ctx {
|
||||
ctx.texture_map(r, bx, true, rw)
|
||||
ctx.texture_map(r, bx, rw, ResourceMapType::Normal)
|
||||
} else {
|
||||
q.device.helper_ctx().texture_map_async(r, bx)
|
||||
})
|
||||
|
|
|
|||
|
|
@ -32,6 +32,26 @@ impl From<RWFlags> for pipe_map_flags {
|
|||
}
|
||||
}
|
||||
|
||||
pub enum ResourceMapType {
|
||||
Normal,
|
||||
Async,
|
||||
Coherent,
|
||||
}
|
||||
|
||||
impl From<ResourceMapType> for pipe_map_flags {
|
||||
fn from(map_type: ResourceMapType) -> Self {
|
||||
match map_type {
|
||||
ResourceMapType::Normal => pipe_map_flags(0),
|
||||
ResourceMapType::Async => pipe_map_flags::PIPE_MAP_UNSYNCHRONIZED,
|
||||
ResourceMapType::Coherent => {
|
||||
pipe_map_flags::PIPE_MAP_COHERENT
|
||||
| pipe_map_flags::PIPE_MAP_PERSISTENT
|
||||
| pipe_map_flags::PIPE_MAP_UNSYNCHRONIZED
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl PipeContext {
|
||||
pub(super) fn new(context: *mut pipe_context, screen: &Arc<PipeScreen>) -> Option<Self> {
|
||||
let s = Self {
|
||||
|
|
@ -135,71 +155,109 @@ impl PipeContext {
|
|||
}
|
||||
}
|
||||
|
||||
fn resource_map(
|
||||
&self,
|
||||
res: &PipeResource,
|
||||
bx: &pipe_box,
|
||||
flags: pipe_map_flags,
|
||||
is_buffer: bool,
|
||||
) -> Option<PipeTransfer> {
|
||||
let mut out: *mut pipe_transfer = ptr::null_mut();
|
||||
|
||||
let ptr = unsafe {
|
||||
let func = if is_buffer {
|
||||
self.pipe.as_ref().buffer_map
|
||||
} else {
|
||||
self.pipe.as_ref().texture_map
|
||||
};
|
||||
|
||||
func.unwrap()(self.pipe.as_ptr(), res.pipe(), 0, flags.0, bx, &mut out)
|
||||
};
|
||||
|
||||
if ptr.is_null() {
|
||||
None
|
||||
} else {
|
||||
Some(PipeTransfer::new(is_buffer, out, ptr))
|
||||
}
|
||||
}
|
||||
|
||||
fn _buffer_map(
|
||||
&self,
|
||||
res: &PipeResource,
|
||||
offset: i32,
|
||||
size: i32,
|
||||
flags: pipe_map_flags,
|
||||
) -> Option<PipeTransfer> {
|
||||
let b = pipe_box {
|
||||
x: offset,
|
||||
width: size,
|
||||
height: 1,
|
||||
depth: 1,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
self.resource_map(res, &b, flags, true)
|
||||
}
|
||||
|
||||
pub fn buffer_map(
|
||||
&self,
|
||||
res: &PipeResource,
|
||||
offset: i32,
|
||||
size: i32,
|
||||
block: bool,
|
||||
rw: RWFlags,
|
||||
map_type: ResourceMapType,
|
||||
) -> PipeTransfer {
|
||||
let mut b = pipe_box::default();
|
||||
let mut out: *mut pipe_transfer = ptr::null_mut();
|
||||
let mut flags: pipe_map_flags = map_type.into();
|
||||
flags |= rw.into();
|
||||
self._buffer_map(res, offset, size, flags).unwrap()
|
||||
}
|
||||
|
||||
b.x = offset;
|
||||
b.width = size;
|
||||
b.height = 1;
|
||||
b.depth = 1;
|
||||
|
||||
let flags = match block {
|
||||
false => pipe_map_flags::PIPE_MAP_UNSYNCHRONIZED,
|
||||
true => pipe_map_flags(0),
|
||||
} | rw.into();
|
||||
|
||||
let ptr = unsafe {
|
||||
self.pipe.as_ref().buffer_map.unwrap()(
|
||||
self.pipe.as_ptr(),
|
||||
res.pipe(),
|
||||
0,
|
||||
flags.0,
|
||||
&b,
|
||||
&mut out,
|
||||
)
|
||||
};
|
||||
|
||||
PipeTransfer::new(true, out, ptr)
|
||||
pub fn buffer_map_directly(
|
||||
&self,
|
||||
res: &PipeResource,
|
||||
offset: i32,
|
||||
size: i32,
|
||||
rw: RWFlags,
|
||||
) -> Option<PipeTransfer> {
|
||||
let flags =
|
||||
pipe_map_flags::PIPE_MAP_DIRECTLY | pipe_map_flags::PIPE_MAP_UNSYNCHRONIZED | rw.into();
|
||||
self._buffer_map(res, offset, size, flags)
|
||||
}
|
||||
|
||||
pub(super) fn buffer_unmap(&self, tx: *mut pipe_transfer) {
|
||||
unsafe { self.pipe.as_ref().buffer_unmap.unwrap()(self.pipe.as_ptr(), tx) };
|
||||
}
|
||||
|
||||
pub fn _texture_map(
|
||||
&self,
|
||||
res: &PipeResource,
|
||||
bx: &pipe_box,
|
||||
flags: pipe_map_flags,
|
||||
) -> Option<PipeTransfer> {
|
||||
self.resource_map(res, bx, flags, false)
|
||||
}
|
||||
|
||||
pub fn texture_map(
|
||||
&self,
|
||||
res: &PipeResource,
|
||||
bx: &pipe_box,
|
||||
block: bool,
|
||||
rw: RWFlags,
|
||||
map_type: ResourceMapType,
|
||||
) -> PipeTransfer {
|
||||
let mut out: *mut pipe_transfer = ptr::null_mut();
|
||||
let mut flags: pipe_map_flags = map_type.into();
|
||||
flags |= rw.into();
|
||||
self._texture_map(res, bx, flags).unwrap()
|
||||
}
|
||||
|
||||
let flags = match block {
|
||||
false => pipe_map_flags::PIPE_MAP_UNSYNCHRONIZED,
|
||||
true => pipe_map_flags(0),
|
||||
} | rw.into();
|
||||
|
||||
let ptr = unsafe {
|
||||
self.pipe.as_ref().texture_map.unwrap()(
|
||||
self.pipe.as_ptr(),
|
||||
res.pipe(),
|
||||
0,
|
||||
flags.0,
|
||||
bx,
|
||||
&mut out,
|
||||
)
|
||||
};
|
||||
|
||||
PipeTransfer::new(false, out, ptr)
|
||||
pub fn texture_map_directly(
|
||||
&self,
|
||||
res: &PipeResource,
|
||||
bx: &pipe_box,
|
||||
rw: RWFlags,
|
||||
) -> Option<PipeTransfer> {
|
||||
let flags =
|
||||
pipe_map_flags::PIPE_MAP_DIRECTLY | pipe_map_flags::PIPE_MAP_UNSYNCHRONIZED | rw.into();
|
||||
self.resource_map(res, bx, flags, false)
|
||||
}
|
||||
|
||||
pub(super) fn texture_unmap(&self, tx: *mut pipe_transfer) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue