From eb904cd51cafc5dd79bbf70df6e00db49ce6451e Mon Sep 17 00:00:00 2001 From: Karol Herbst Date: Fri, 18 Jul 2025 22:42:16 +0200 Subject: [PATCH] rusticl/kernel: stop clearing sampler views on kernel launches Instead we just unbind on the next launch by using the unbind_num_trailing_slots parameter. Part-of: --- src/gallium/frontends/rusticl/core/kernel.rs | 4 +--- src/gallium/frontends/rusticl/core/queue.rs | 11 +++++++++++ src/gallium/frontends/rusticl/mesa/pipe/context.rs | 4 ++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/gallium/frontends/rusticl/core/kernel.rs b/src/gallium/frontends/rusticl/core/kernel.rs index 7a092be9b15..47c51ab0fad 100644 --- a/src/gallium/frontends/rusticl/core/kernel.rs +++ b/src/gallium/frontends/rusticl/core/kernel.rs @@ -1653,10 +1653,9 @@ impl Kernel { globals.push(unsafe { input.as_mut_ptr().byte_add(offset) }.cast()); } - let sviews_len = sviews.len(); ctx.bind_kernel(&nir_kernel_builds, variant)?; ctx.bind_sampler_states(&samplers); - ctx.set_sampler_views(sviews); + ctx.bind_sampler_views(sviews); ctx.set_shader_images(&iviews); ctx.set_global_binding(resources.as_slice(), &mut globals); @@ -1701,7 +1700,6 @@ impl Kernel { } ctx.clear_global_binding(globals.len() as u32); - ctx.clear_sampler_views(sviews_len as u32); ctx.clear_sampler_states(samplers.len() as u32); ctx.memory_barrier(PIPE_BARRIER_GLOBAL_BUFFER); diff --git a/src/gallium/frontends/rusticl/core/queue.rs b/src/gallium/frontends/rusticl/core/queue.rs index f23711224e6..ca000f7e232 100644 --- a/src/gallium/frontends/rusticl/core/queue.rs +++ b/src/gallium/frontends/rusticl/core/queue.rs @@ -10,6 +10,7 @@ use mesa_rust::compiler::nir::NirShader; use mesa_rust::pipe::context::PipeContext; use mesa_rust::pipe::context::PipeContextPrio; use mesa_rust::pipe::fence::PipeFence; +use mesa_rust::pipe::resource::PipeSamplerView; use mesa_rust_gen::*; use mesa_rust_util::properties::*; use rusticl_opencl_gen::*; @@ -70,6 +71,7 @@ impl<'a> QueueContext<'a> { variant: NirKernelVariant::Default, cso: None, use_stream: self.dev.prefers_real_buffer_in_cb0(), + bound_sampler_views: 0, } } } @@ -83,6 +85,7 @@ pub struct QueueContextWithState<'a> { builds: Option>, variant: NirKernelVariant, cso: Option>, + bound_sampler_views: u32, } impl QueueContextWithState<'_> { @@ -123,6 +126,13 @@ impl QueueContextWithState<'_> { Ok(()) } + pub fn bind_sampler_views(&mut self, views: Vec) { + let cnt = views.len() as u32; + let unbind_cnt = self.bound_sampler_views.saturating_sub(cnt); + self.ctx.set_sampler_views(views, unbind_cnt); + self.bound_sampler_views = cnt; + } + pub fn update_cb0(&self, data: &[u8]) -> CLResult<()> { // only update if we actually bind data if !data.is_empty() { @@ -149,6 +159,7 @@ impl<'a> Deref for QueueContextWithState<'a> { impl Drop for QueueContextWithState<'_> { fn drop(&mut self) { self.set_constant_buffer(0, &[]); + self.ctx.clear_sampler_views(self.bound_sampler_views); self.ctx.clear_shader_images(self.dev.caps.max_write_images); if self.builds.is_some() { // SAFETY: We simply unbind here. The bound cso will only be dropped at the end of this diff --git a/src/gallium/frontends/rusticl/mesa/pipe/context.rs b/src/gallium/frontends/rusticl/mesa/pipe/context.rs index 0528b4a7fde..dadaac4577f 100644 --- a/src/gallium/frontends/rusticl/mesa/pipe/context.rs +++ b/src/gallium/frontends/rusticl/mesa/pipe/context.rs @@ -541,14 +541,14 @@ impl PipeContext { } } - pub fn set_sampler_views(&self, mut views: Vec) { + pub fn set_sampler_views(&self, mut views: Vec, unbind_trailing: u32) { unsafe { self.pipe.as_ref().set_sampler_views.unwrap()( self.pipe.as_ptr(), pipe_shader_type::PIPE_SHADER_COMPUTE, 0, views.len() as u32, - 0, + unbind_trailing, PipeSamplerView::as_pipe(views.as_mut_slice()), ); }