rusticl/mem: cache the pipe_format

This moves the expensive to_pipe_format call to image creation time.

Signed-off-by: Karol Herbst <git@karolherbst.de>
Reviewed-by: Dave Airlie <airlied@redhat.com>
Reviewed-by: Nora Allen <blackcatgames@protonmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23714>
This commit is contained in:
Karol Herbst 2023-06-18 17:21:27 +02:00
parent ff95349285
commit 73f86c9b9d
3 changed files with 11 additions and 8 deletions

View file

@ -1,12 +1,12 @@
use crate::api::icd::*;
use crate::core::device::*;
use crate::core::format::*;
use crate::core::memory::*;
use crate::core::util::*;
use crate::impl_cl_type_trait;
use mesa_rust::pipe::resource::*;
use mesa_rust::pipe::screen::ResourceType;
use mesa_rust_gen::*;
use mesa_rust_util::properties::Properties;
use rusticl_opencl_gen::*;
@ -84,7 +84,7 @@ impl Context {
pub fn create_texture(
&self,
desc: &cl_image_desc,
format: &cl_image_format,
format: pipe_format,
user_ptr: *mut c_void,
copy: bool,
res_type: ResourceType,
@ -106,7 +106,6 @@ impl Context {
.try_into()
.map_err(|_| CL_OUT_OF_HOST_MEMORY)?;
let target = cl_mem_type_to_texture_target(desc.image_type);
let format = format.to_pipe_format().unwrap();
let mut res = HashMap::new();
for dev in &self.devs {

View file

@ -1,7 +1,6 @@
use crate::api::icd::*;
use crate::core::device::*;
use crate::core::event::*;
use crate::core::format::*;
use crate::core::memory::*;
use crate::core::program::*;
use crate::core::queue::*;
@ -936,7 +935,7 @@ impl Kernel {
}
resource_info.push((res.clone(), arg.offset));
} else {
let format = mem.image_format.to_pipe_format().unwrap();
let format = mem.pipe_format;
let (formats, orders) = if arg.kind == KernelArgType::Image {
iviews.push(res.pipe_image_view(format, false, app_img_info.as_ref()));
(&mut img_formats, &mut img_orders)

View file

@ -111,6 +111,7 @@ pub struct Mem {
pub offset: usize,
pub host_ptr: *mut c_void,
pub image_format: cl_image_format,
pub pipe_format: pipe_format,
pub image_desc: cl_image_desc,
pub image_elem_size: u8,
pub props: Vec<cl_mem_properties>,
@ -299,6 +300,7 @@ impl Mem {
offset: 0,
host_ptr: host_ptr,
image_format: cl_image_format::default(),
pipe_format: pipe_format::PIPE_FORMAT_NONE,
image_desc: cl_image_desc::default(),
image_elem_size: 0,
props: props,
@ -330,6 +332,7 @@ impl Mem {
offset: offset,
host_ptr: host_ptr,
image_format: cl_image_format::default(),
pipe_format: pipe_format::PIPE_FORMAT_NONE,
image_desc: cl_image_desc::default(),
image_elem_size: 0,
props: Vec::new(),
@ -370,10 +373,11 @@ impl Mem {
ResourceType::Normal
};
let pipe_format = image_format.to_pipe_format().unwrap();
let texture = if parent.is_none() {
Some(context.create_texture(
&image_desc,
image_format,
pipe_format,
host_ptr,
bit_check(flags, CL_MEM_COPY_HOST_PTR),
res_type,
@ -398,6 +402,7 @@ impl Mem {
offset: 0,
host_ptr: host_ptr,
image_format: *image_format,
pipe_format: pipe_format,
image_desc: api_image_desc,
image_elem_size: image_elem_size,
props: props,
@ -529,7 +534,7 @@ impl Mem {
r.depth(),
r.array_size(),
cl_mem_type_to_texture_target(self.image_desc.image_type),
self.image_format.to_pipe_format().unwrap(),
self.pipe_format,
ResourceType::Staging,
)
.ok_or(CL_OUT_OF_RESOURCES)?;
@ -805,7 +810,7 @@ impl Mem {
// CL_DEPTH where it's just one value.
unsafe {
util_format_pack_rgba(
self.image_format.to_pipe_format().unwrap(),
self.pipe_format,
new_pattern.as_mut_ptr().cast(),
pattern.as_ptr().cast(),
1,