rusticl/memory: only specify PIPE_BIND_SHADER_IMAGE where supported

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24982>
This commit is contained in:
Karol Herbst 2023-08-29 21:59:31 +02:00 committed by Marge Bot
parent 3a715cc9d2
commit f90f68aa1c
3 changed files with 37 additions and 8 deletions

View file

@ -1,12 +1,12 @@
use crate::api::icd::*; use crate::api::icd::*;
use crate::core::device::*; use crate::core::device::*;
use crate::core::format::*;
use crate::core::memory::*; use crate::core::memory::*;
use crate::core::util::*; use crate::core::util::*;
use crate::impl_cl_type_trait; use crate::impl_cl_type_trait;
use mesa_rust::pipe::resource::*; use mesa_rust::pipe::resource::*;
use mesa_rust::pipe::screen::ResourceType; use mesa_rust::pipe::screen::ResourceType;
use mesa_rust_gen::*;
use mesa_rust_util::properties::Properties; use mesa_rust_util::properties::Properties;
use rusticl_opencl_gen::*; use rusticl_opencl_gen::*;
@ -84,11 +84,13 @@ impl Context {
pub fn create_texture( pub fn create_texture(
&self, &self,
desc: &cl_image_desc, desc: &cl_image_desc,
format: pipe_format, format: &cl_image_format,
user_ptr: *mut c_void, user_ptr: *mut c_void,
copy: bool, copy: bool,
res_type: ResourceType, res_type: ResourceType,
) -> CLResult<HashMap<&'static Device, Arc<PipeResource>>> { ) -> CLResult<HashMap<&'static Device, Arc<PipeResource>>> {
let pipe_format = format.to_pipe_format().unwrap();
let width = desc let width = desc
.image_width .image_width
.try_into() .try_into()
@ -110,17 +112,33 @@ impl Context {
let mut res = HashMap::new(); let mut res = HashMap::new();
for &dev in &self.devs { for &dev in &self.devs {
let mut resource = None; let mut resource = None;
let enable_bind_as_image =
(dev.formats[format][&desc.image_type] as u32 & CL_MEM_WRITE_ONLY) != 0;
// we can't specify custom pitches/slices, so this won't work for non 1D images // we can't specify custom pitches/slices, so this won't work for non 1D images
if !user_ptr.is_null() && !copy && desc.image_type == CL_MEM_OBJECT_IMAGE1D { if !user_ptr.is_null() && !copy && desc.image_type == CL_MEM_OBJECT_IMAGE1D {
resource = dev.screen().resource_create_texture_from_user( resource = dev.screen().resource_create_texture_from_user(
width, height, depth, array_size, target, format, user_ptr, width,
height,
depth,
array_size,
target,
pipe_format,
user_ptr,
enable_bind_as_image,
) )
} }
if resource.is_none() { if resource.is_none() {
resource = dev.screen().resource_create_texture( resource = dev.screen().resource_create_texture(
width, height, depth, array_size, target, format, res_type, width,
height,
depth,
array_size,
target,
pipe_format,
res_type,
enable_bind_as_image,
) )
} }

View file

@ -374,11 +374,10 @@ impl Mem {
ResourceType::Normal ResourceType::Normal
}; };
let pipe_format = image_format.to_pipe_format().unwrap();
let texture = if parent.is_none() { let texture = if parent.is_none() {
Some(context.create_texture( Some(context.create_texture(
&image_desc, &image_desc,
pipe_format, image_format,
host_ptr, host_ptr,
bit_check(flags, CL_MEM_COPY_HOST_PTR), bit_check(flags, CL_MEM_COPY_HOST_PTR),
res_type, res_type,
@ -393,6 +392,7 @@ impl Mem {
ptr::null_mut() ptr::null_mut()
}; };
let pipe_format = image_format.to_pipe_format().unwrap();
Ok(Arc::new(Self { Ok(Arc::new(Self {
base: CLObjectBase::new(), base: CLObjectBase::new(),
context: context, context: context,
@ -537,6 +537,7 @@ impl Mem {
cl_mem_type_to_texture_target(self.image_desc.image_type), cl_mem_type_to_texture_target(self.image_desc.image_type),
self.pipe_format, self.pipe_format,
ResourceType::Staging, ResourceType::Staging,
false,
) )
.ok_or(CL_OUT_OF_RESOURCES)?; .ok_or(CL_OUT_OF_RESOURCES)?;
let tx = ctx.texture_map_coherent(&shadow, bx, rw); let tx = ctx.texture_map_coherent(&shadow, bx, rw);

View file

@ -176,6 +176,7 @@ impl PipeScreen {
target: pipe_texture_target, target: pipe_texture_target,
format: pipe_format, format: pipe_format,
res_type: ResourceType, res_type: ResourceType,
support_image: bool,
) -> Option<PipeResource> { ) -> Option<PipeResource> {
let mut tmpl = pipe_resource::default(); let mut tmpl = pipe_resource::default();
@ -185,7 +186,11 @@ impl PipeScreen {
tmpl.height0 = height; tmpl.height0 = height;
tmpl.depth0 = depth; tmpl.depth0 = depth;
tmpl.array_size = array_size; tmpl.array_size = array_size;
tmpl.bind = PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_SHADER_IMAGE; tmpl.bind = PIPE_BIND_SAMPLER_VIEW;
if support_image {
tmpl.bind |= PIPE_BIND_SHADER_IMAGE;
}
res_type.apply(&mut tmpl); res_type.apply(&mut tmpl);
@ -201,6 +206,7 @@ impl PipeScreen {
target: pipe_texture_target, target: pipe_texture_target,
format: pipe_format, format: pipe_format,
mem: *mut c_void, mem: *mut c_void,
support_image: bool,
) -> Option<PipeResource> { ) -> Option<PipeResource> {
let mut tmpl = pipe_resource::default(); let mut tmpl = pipe_resource::default();
@ -210,7 +216,11 @@ impl PipeScreen {
tmpl.height0 = height; tmpl.height0 = height;
tmpl.depth0 = depth; tmpl.depth0 = depth;
tmpl.array_size = array_size; tmpl.array_size = array_size;
tmpl.bind = PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_SHADER_IMAGE; tmpl.bind = PIPE_BIND_SAMPLER_VIEW;
if support_image {
tmpl.bind |= PIPE_BIND_SHADER_IMAGE;
}
self.resource_create_from_user(&tmpl, mem) self.resource_create_from_user(&tmpl, mem)
} }