diff --git a/src/gallium/frontends/rusticl/core/context.rs b/src/gallium/frontends/rusticl/core/context.rs index 858ec2d3267..623ec065a88 100644 --- a/src/gallium/frontends/rusticl/core/context.rs +++ b/src/gallium/frontends/rusticl/core/context.rs @@ -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,11 +84,13 @@ impl Context { pub fn create_texture( &self, desc: &cl_image_desc, - format: pipe_format, + format: &cl_image_format, user_ptr: *mut c_void, copy: bool, res_type: ResourceType, ) -> CLResult>> { + let pipe_format = format.to_pipe_format().unwrap(); + let width = desc .image_width .try_into() @@ -110,17 +112,33 @@ impl Context { let mut res = HashMap::new(); for &dev in &self.devs { 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 if !user_ptr.is_null() && !copy && desc.image_type == CL_MEM_OBJECT_IMAGE1D { 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() { 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, ) } diff --git a/src/gallium/frontends/rusticl/core/memory.rs b/src/gallium/frontends/rusticl/core/memory.rs index 5f4c0c1dc0b..a2f96f821e5 100644 --- a/src/gallium/frontends/rusticl/core/memory.rs +++ b/src/gallium/frontends/rusticl/core/memory.rs @@ -374,11 +374,10 @@ 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, - pipe_format, + image_format, host_ptr, bit_check(flags, CL_MEM_COPY_HOST_PTR), res_type, @@ -393,6 +392,7 @@ impl Mem { ptr::null_mut() }; + let pipe_format = image_format.to_pipe_format().unwrap(); Ok(Arc::new(Self { base: CLObjectBase::new(), context: context, @@ -537,6 +537,7 @@ impl Mem { cl_mem_type_to_texture_target(self.image_desc.image_type), self.pipe_format, ResourceType::Staging, + false, ) .ok_or(CL_OUT_OF_RESOURCES)?; let tx = ctx.texture_map_coherent(&shadow, bx, rw); diff --git a/src/gallium/frontends/rusticl/mesa/pipe/screen.rs b/src/gallium/frontends/rusticl/mesa/pipe/screen.rs index 7e5f621f450..0937e93db82 100644 --- a/src/gallium/frontends/rusticl/mesa/pipe/screen.rs +++ b/src/gallium/frontends/rusticl/mesa/pipe/screen.rs @@ -176,6 +176,7 @@ impl PipeScreen { target: pipe_texture_target, format: pipe_format, res_type: ResourceType, + support_image: bool, ) -> Option { let mut tmpl = pipe_resource::default(); @@ -185,7 +186,11 @@ impl PipeScreen { tmpl.height0 = height; tmpl.depth0 = depth; 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); @@ -201,6 +206,7 @@ impl PipeScreen { target: pipe_texture_target, format: pipe_format, mem: *mut c_void, + support_image: bool, ) -> Option { let mut tmpl = pipe_resource::default(); @@ -210,7 +216,11 @@ impl PipeScreen { tmpl.height0 = height; tmpl.depth0 = depth; 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) }