From 2cbe7c0baf7715d01a0565bebca5af2e565a0ab2 Mon Sep 17 00:00:00 2001 From: luboslenco Date: Thu, 12 Mar 2026 18:06:30 +0100 Subject: [PATCH] gpu: unify scissor handling --- base/sources/backends/direct3d12_gpu.c | 3 +++ base/sources/backends/metal_gpu.m | 9 +++++---- base/sources/backends/webgpu_gpu.c | 3 +++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/base/sources/backends/direct3d12_gpu.c b/base/sources/backends/direct3d12_gpu.c index 20fcb1ce..a55d3eb3 100644 --- a/base/sources/backends/direct3d12_gpu.c +++ b/base/sources/backends/direct3d12_gpu.c @@ -546,6 +546,9 @@ void gpu_viewport(int x, int y, int width, int height) { } void gpu_scissor(int x, int y, int width, int height) { + if (width < 0 || height < 0) { + return; + } current_scissor = (D3D12_RECT){ .left = x, .top = y, diff --git a/base/sources/backends/metal_gpu.m b/base/sources/backends/metal_gpu.m index b6fd905b..fddde4fc 100644 --- a/base/sources/backends/metal_gpu.m +++ b/base/sources/backends/metal_gpu.m @@ -309,12 +309,13 @@ void gpu_viewport(int x, int y, int width, int height) { } void gpu_scissor(int x, int y, int width, int height) { + if (width < 0 || height < 0) { + return; + } current_scissor.x = x; current_scissor.y = y; - int target_w = current_render_targets[0]->width; - int target_h = current_render_targets[0]->height; - current_scissor.width = (x + width <= target_w) ? width : target_w - x; - current_scissor.height = (y + height <= target_h) ? height : target_h - y; + current_scissor.width = width; + current_scissor.height = height; [command_encoder setScissorRect:current_scissor]; } diff --git a/base/sources/backends/webgpu_gpu.c b/base/sources/backends/webgpu_gpu.c index ecb90a79..2e7e61b6 100644 --- a/base/sources/backends/webgpu_gpu.c +++ b/base/sources/backends/webgpu_gpu.c @@ -414,6 +414,9 @@ void gpu_viewport(int x, int y, int width, int height) { } void gpu_scissor(int x, int y, int width, int height) { + if (width < 0 || height < 0) { + return; + } wgpuRenderPassEncoderSetScissorRect(render_pass_encoder, (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height); }