From a79ac34b150fe602037dbc7ec4625159e7208beb Mon Sep 17 00:00:00 2001 From: teoxoy <28601907+teoxoy@users.noreply.github.com> Date: Tue, 25 Jun 2024 16:16:22 +0200 Subject: [PATCH] extract `set_scissor` from `render_pass_end_impl` --- wgpu-core/src/command/render.rs | 44 +++++++++++++++++---------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/wgpu-core/src/command/render.rs b/wgpu-core/src/command/render.rs index 9bccceeeee..fe5328df51 100644 --- a/wgpu-core/src/command/render.rs +++ b/wgpu-core/src/command/render.rs @@ -1587,28 +1587,9 @@ impl Global { ) .map_pass_err(scope)?; } - ArcRenderCommand::SetScissor(ref rect) => { - api_log!("RenderPass::set_scissor_rect {rect:?}"); - + ArcRenderCommand::SetScissor(rect) => { let scope = PassErrorScope::SetScissorRect; - if rect.x + rect.w > state.info.extent.width - || rect.y + rect.h > state.info.extent.height - { - return Err(RenderCommandError::InvalidScissorRect( - *rect, - state.info.extent, - )) - .map_pass_err(scope); - } - let r = hal::Rect { - x: rect.x, - y: rect.y, - w: rect.w, - h: rect.h, - }; - unsafe { - state.raw_encoder.set_scissor_rect(&r); - } + set_scissor(&mut state, rect).map_pass_err(scope)?; } ArcRenderCommand::Draw { vertex_count, @@ -2586,6 +2567,27 @@ fn set_push_constant( Ok(()) } +fn set_scissor( + state: &mut State, + rect: Rect, +) -> Result<(), RenderPassErrorInner> { + api_log!("RenderPass::set_scissor_rect {rect:?}"); + + if rect.x + rect.w > state.info.extent.width || rect.y + rect.h > state.info.extent.height { + return Err(RenderCommandError::InvalidScissorRect(rect, state.info.extent).into()); + } + let r = hal::Rect { + x: rect.x, + y: rect.y, + w: rect.w, + h: rect.h, + }; + unsafe { + state.raw_encoder.set_scissor_rect(&r); + } + Ok(()) +} + impl Global { pub fn render_pass_set_bind_group( &self,