From f7fcd7ed5dd075bd679c3cb285370715c61f98fc Mon Sep 17 00:00:00 2001 From: Karol Herbst Date: Sun, 14 Sep 2025 21:33:54 +0200 Subject: [PATCH] rusticl/mesa: rework Context creation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewed-by: Seán de Búrca Part-of: --- src/gallium/frontends/rusticl/core/device.rs | 4 ++-- .../frontends/rusticl/mesa/pipe/context.rs | 7 ++----- .../frontends/rusticl/mesa/pipe/screen.rs | 20 ++++++++----------- 3 files changed, 12 insertions(+), 19 deletions(-) diff --git a/src/gallium/frontends/rusticl/core/device.rs b/src/gallium/frontends/rusticl/core/device.rs index 6e9283b8b70..f6d7d58866d 100644 --- a/src/gallium/frontends/rusticl/core/device.rs +++ b/src/gallium/frontends/rusticl/core/device.rs @@ -1141,7 +1141,7 @@ impl DeviceBase { let res = (prio == PipeContextPrio::Med) .then(|| self.reusable_ctx().pop()) .flatten() - .or_else(|| self.screen.create_context(prio))?; + .or_else(|| PipeContext::new(prio, &self.screen))?; debug_assert_eq!(res.prio, prio); @@ -1281,7 +1281,7 @@ impl Device { let screen = Arc::new(screen); // Create before loading libclc as llvmpipe only creates the shader cache with the first // context being created. - let helper_ctx = screen.create_context(PipeContextPrio::Med)?; + let helper_ctx = PipeContext::new(PipeContextPrio::Med, &screen)?; let mut dev_base = DeviceBase { caps: DeviceCaps::new(&screen, &helper_ctx), helper_ctx: Mutex::new(helper_ctx), diff --git a/src/gallium/frontends/rusticl/mesa/pipe/context.rs b/src/gallium/frontends/rusticl/mesa/pipe/context.rs index e230a49b4d3..e19a6f6f5a1 100644 --- a/src/gallium/frontends/rusticl/mesa/pipe/context.rs +++ b/src/gallium/frontends/rusticl/mesa/pipe/context.rs @@ -52,11 +52,8 @@ impl From for pipe_map_flags { } impl PipeContext { - pub(super) fn new( - context: *mut pipe_context, - prio: PipeContextPrio, - screen: &Arc, - ) -> Option { + pub fn new(prio: PipeContextPrio, screen: &Arc) -> Option { + let context = screen.create_context(prio); let s = Self { pipe: NonNull::new(context)?, screen: Arc::clone(screen), diff --git a/src/gallium/frontends/rusticl/mesa/pipe/screen.rs b/src/gallium/frontends/rusticl/mesa/pipe/screen.rs index 92828c9becc..3d504f5b296 100644 --- a/src/gallium/frontends/rusticl/mesa/pipe/screen.rs +++ b/src/gallium/frontends/rusticl/mesa/pipe/screen.rs @@ -98,19 +98,15 @@ impl PipeScreen { &self.screen().caps } - pub fn create_context(self: &Arc, prio: PipeContextPrio) -> Option { + pub(super) fn create_context(&self, prio: PipeContextPrio) -> *mut pipe_context { let flags: u32 = prio.into(); - PipeContext::new( - unsafe { - self.screen().context_create.unwrap()( - self.screen.as_ptr(), - ptr::null_mut(), - flags | PIPE_CONTEXT_COMPUTE_ONLY | PIPE_CONTEXT_NO_LOD_BIAS, - ) - }, - prio, - self, - ) + unsafe { + self.screen().context_create.unwrap()( + self.pipe(), + ptr::null_mut(), + flags | PIPE_CONTEXT_COMPUTE_ONLY | PIPE_CONTEXT_NO_LOD_BIAS, + ) + } } pub fn alloc_vm(&self, start: NonZeroU64, size: NonZeroU64) -> Option> {