From b94d4f90f249e135ff4539d8f9e625e10dbe69b2 Mon Sep 17 00:00:00 2001 From: Karol Herbst Date: Mon, 6 Jan 2025 01:10:26 +0100 Subject: [PATCH] rusticl/mesa: set take_ownership to true for set_sampler_views This simplifies sampler view tracking a bit for us. Also, drivers will automatically free the pipe_sampler_view as well. It was wrong to call into sampler_view_destroy directly anyway, because pipe_sampler_view is a refcounted object and pipe_sampler_view_reference should be used instead. Reviewed-by: @LingMan Part-of: --- src/gallium/frontends/rusticl/core/kernel.rs | 8 ++++---- src/gallium/frontends/rusticl/mesa/pipe/context.rs | 11 ++++------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/gallium/frontends/rusticl/core/kernel.rs b/src/gallium/frontends/rusticl/core/kernel.rs index fe47df53905..9ca4b1c080c 100644 --- a/src/gallium/frontends/rusticl/core/kernel.rs +++ b/src/gallium/frontends/rusticl/core/kernel.rs @@ -1522,7 +1522,7 @@ impl Kernel { // subtract the shader local_size as we only request something on top of that. variable_local_size -= static_local_size; - let mut sviews: Vec<_> = sviews + let sviews: Vec<_> = sviews .iter() .map(|(s, f, size, aii)| ctx.create_sampler_view(s, *f, *size, aii.as_ref())) .collect(); @@ -1547,9 +1547,10 @@ impl Kernel { } }; + let sviews_len = sviews.len(); ctx.bind_compute_state(cso.cso_ptr); ctx.bind_sampler_states(&samplers); - ctx.set_sampler_views(&mut sviews); + ctx.set_sampler_views(sviews); ctx.set_shader_images(&iviews); ctx.set_global_binding(resources.as_slice(), &mut globals); @@ -1589,7 +1590,7 @@ impl Kernel { ctx.clear_global_binding(globals.len() as u32); ctx.clear_shader_images(iviews.len() as u32); - ctx.clear_sampler_views(sviews.len() as u32); + ctx.clear_sampler_views(sviews_len as u32); ctx.clear_sampler_states(samplers.len() as u32); ctx.bind_compute_state(ptr::null_mut()); @@ -1597,7 +1598,6 @@ impl Kernel { ctx.memory_barrier(PIPE_BARRIER_GLOBAL_BUFFER); samplers.iter().for_each(|s| ctx.delete_sampler_state(*s)); - sviews.iter().for_each(|v| ctx.sampler_view_destroy(*v)); if let Some(printf_buf) = &printf_buf { let tx = ctx diff --git a/src/gallium/frontends/rusticl/mesa/pipe/context.rs b/src/gallium/frontends/rusticl/mesa/pipe/context.rs index 0bd1f24de9a..e5201bf19f8 100644 --- a/src/gallium/frontends/rusticl/mesa/pipe/context.rs +++ b/src/gallium/frontends/rusticl/mesa/pipe/context.rs @@ -451,7 +451,7 @@ impl PipeContext { } } - pub fn set_sampler_views(&self, views: &mut [*mut pipe_sampler_view]) { + pub fn set_sampler_views(&self, mut views: Vec<*mut pipe_sampler_view>) { unsafe { self.pipe.as_ref().set_sampler_views.unwrap()( self.pipe.as_ptr(), @@ -459,7 +459,7 @@ impl PipeContext { 0, views.len() as u32, 0, - false, + true, views.as_mut_ptr(), ) } @@ -474,16 +474,12 @@ impl PipeContext { 0, count, 0, - false, + true, samplers.as_mut_ptr(), ) } } - pub fn sampler_view_destroy(&self, view: *mut pipe_sampler_view) { - unsafe { self.pipe.as_ref().sampler_view_destroy.unwrap()(self.pipe.as_ptr(), view) } - } - pub fn set_shader_images(&self, images: &[PipeImageView]) { let images = PipeImageView::slice_to_pipe(images); unsafe { @@ -618,6 +614,7 @@ fn has_required_cbs(context: &pipe_context) -> bool { & has_required_feature!(context, launch_grid) & has_required_feature!(context, memory_barrier) & has_required_feature!(context, resource_copy_region) + // implicitly used through pipe_sampler_view_reference & has_required_feature!(context, sampler_view_destroy) & has_required_feature!(context, set_constant_buffer) & has_required_feature!(context, set_global_binding)