From 3aa3ec625d76eb131bb59b366bbf7e58982e7520 Mon Sep 17 00:00:00 2001 From: Karol Herbst Date: Sun, 25 Aug 2024 14:51:58 +0200 Subject: [PATCH] rusticl/mem: set bind flags for gl imports We have to tell the driver how we want to use the resource. Fixes: 2645003bdc5 ("rusticl: Create CL mem objects from GL") Part-of: (cherry picked from commit 46454f01d390d89e2dc62b3e93892137440a05ef) --- .pick_status.json | 2 +- src/gallium/frontends/rusticl/core/context.rs | 16 ++++++++++++++-- src/gallium/frontends/rusticl/core/memory.rs | 2 +- .../frontends/rusticl/mesa/pipe/screen.rs | 10 ++++++++++ 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index 7a277e5670b..7d1e630e614 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -644,7 +644,7 @@ "description": "rusticl/mem: set bind flags for gl imports", "nominated": true, "nomination_type": 2, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": "2645003bdc527b5dc046366fce5e65b44b27334f", "notes": null diff --git a/src/gallium/frontends/rusticl/core/context.rs b/src/gallium/frontends/rusticl/core/context.rs index 09d68bb6813..e03fba84a6b 100644 --- a/src/gallium/frontends/rusticl/core/context.rs +++ b/src/gallium/frontends/rusticl/core/context.rs @@ -200,25 +200,37 @@ impl Context { modifier: u64, image_type: cl_mem_object_type, gl_target: cl_GLenum, - format: pipe_format, + format: cl_image_format, gl_props: GLMemProps, ) -> CLResult>> { let mut res = HashMap::new(); let target = cl_mem_type_to_texture_target_gl(image_type, gl_target); + let pipe_format = if image_type == CL_MEM_OBJECT_BUFFER { + pipe_format::PIPE_FORMAT_NONE + } else { + format.to_pipe_format().unwrap() + }; for dev in &self.devs { + let enable_bind_as_image = if target != pipe_texture_target::PIPE_BUFFER { + dev.formats[&format][&image_type] as u32 & CL_MEM_WRITE_ONLY != 0 + } else { + false + }; + let resource = dev .screen() .resource_import_dmabuf( handle, modifier, target, - format, + pipe_format, gl_props.stride, gl_props.width, gl_props.height, gl_props.depth, gl_props.array_size, + enable_bind_as_image, ) .ok_or(CL_OUT_OF_RESOURCES)?; diff --git a/src/gallium/frontends/rusticl/core/memory.rs b/src/gallium/frontends/rusticl/core/memory.rs index 2a966761d3e..e8602611d19 100644 --- a/src/gallium/frontends/rusticl/core/memory.rs +++ b/src/gallium/frontends/rusticl/core/memory.rs @@ -950,7 +950,7 @@ impl MemBase { export_out.modifier, mem_type, export_in.target, - pipe_format, + image_format, gl_mem_props.clone(), )?; diff --git a/src/gallium/frontends/rusticl/mesa/pipe/screen.rs b/src/gallium/frontends/rusticl/mesa/pipe/screen.rs index 39206267e75..d20955be9b4 100644 --- a/src/gallium/frontends/rusticl/mesa/pipe/screen.rs +++ b/src/gallium/frontends/rusticl/mesa/pipe/screen.rs @@ -249,6 +249,7 @@ impl PipeScreen { height: u16, depth: u16, array_size: u16, + support_image: bool, ) -> Option { let mut tmpl = pipe_resource::default(); let mut handle = winsys_handle { @@ -267,6 +268,15 @@ impl PipeScreen { tmpl.depth0 = depth; tmpl.array_size = array_size; + if target == pipe_texture_target::PIPE_BUFFER { + tmpl.bind = PIPE_BIND_GLOBAL + } else { + tmpl.bind = PIPE_BIND_SAMPLER_VIEW; + if support_image { + tmpl.bind |= PIPE_BIND_SHADER_IMAGE; + } + } + unsafe { PipeResource::new( self.screen().resource_from_handle.unwrap()(