rusticl/mem: set bind flags for gl imports

We have to tell the driver how we want to use the resource.

Fixes: 2645003bdc ("rusticl: Create CL mem objects from GL")
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/33325>
(cherry picked from commit 46454f01d3)
This commit is contained in:
Karol Herbst 2024-08-25 14:51:58 +02:00 committed by Eric Engestrom
parent f2f488ced5
commit 3aa3ec625d
4 changed files with 26 additions and 4 deletions

View file

@ -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

View file

@ -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<HashMap<&'static Device, Arc<PipeResource>>> {
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)?;

View file

@ -950,7 +950,7 @@ impl MemBase {
export_out.modifier,
mem_type,
export_in.target,
pipe_format,
image_format,
gl_mem_props.clone(),
)?;

View file

@ -249,6 +249,7 @@ impl PipeScreen {
height: u16,
depth: u16,
array_size: u16,
support_image: bool,
) -> Option<PipeResource> {
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()(