rusticl/memory: only specify PIPE_BIND_SHADER_IMAGE where supported
authorKarol Herbst <git@karolherbst.de>
Tue, 29 Aug 2023 19:59:31 +0000 (21:59 +0200)
committerMarge Bot <emma+marge@anholt.net>
Sat, 2 Sep 2023 10:11:24 +0000 (10:11 +0000)
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24982>

src/gallium/frontends/rusticl/core/context.rs
src/gallium/frontends/rusticl/core/memory.rs
src/gallium/frontends/rusticl/mesa/pipe/screen.rs

index 858ec2d..623ec06 100644 (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,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<HashMap<&'static Device, Arc<PipeResource>>> {
+        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,
                 )
             }
 
index 5f4c0c1..a2f96f8 100644 (file)
@@ -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);
index 7e5f621..0937e93 100644 (file)
@@ -176,6 +176,7 @@ impl PipeScreen {
         target: pipe_texture_target,
         format: pipe_format,
         res_type: ResourceType,
+        support_image: bool,
     ) -> Option<PipeResource> {
         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<PipeResource> {
         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)
     }