From patchwork Wed Nov 18 09:57:30 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 28985 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 841E0BDE17 for ; Wed, 18 Nov 2026 09:58:33 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E60046A90F; Wed, 18 Nov 2026 10:58:32 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="kC4M/bY9"; dkim-atps=neutral Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4540D6A8E7 for ; Wed, 18 Nov 2026 10:58:13 +0100 (CET) Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-4a358881793so339700f8f.0 for ; Wed, 18 Nov 2026 01:58:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1794995893; x=1795600693; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=O9T9MF8rCVzXbohesTp8C4DzVCwKDTj4cLX4G4awFQg=; b=kC4M/bY9CUz07Qc1hU8IOPxg2TjmOz/XRbFtjtIGA0sRemsGvZy8xy2eTm6s7BpE+C XZ+vpHdC7gdYrCLqhq0rU0pZl6lEfcE7gKoo+MrbwBS7218CdnODqFQW/cIPRcCr7bkm XdHygniAYD/ZTVDB9JNs3xJ5rqqWi9WF4C+e0i7ScDZhIjqOr/hGcjdn5QfzQvLKnlsx knYCcK7Ttzzb5FpMonx90SqwsWWgh4JfhlpNvZZx1iai/wg3UYbyOt94ei4X+O5zBNUV dKh7wJ2Fhk9jlsJa97qZqExWevJl0BCUPqfZci/Q3KjsJ5QamZ+jlF8XpvpF+0BqGwQ9 2DgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794995893; x=1795600693; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=O9T9MF8rCVzXbohesTp8C4DzVCwKDTj4cLX4G4awFQg=; b=LDDt0ZWM6Jg0GdksSY5JJmEjW5lbo32egAa1JF1x2dW4IROrnwRBWXnMN/3/09K6F5 ycXbYEbY1eRgpf6VuZtko9oVT3AY1CJ6zLMxV/kFJVuNjIncBLa+E/DgPfxvfeQX1+5/ 240i7bKRI02HPj0J25yuTpepK1cdxoZEWsIEC85kkKoPei/s63bP/s8nHJojDGD0Edxy hqk6K6c2OloP+pWCRllUccFifkc6VgkCA8WyXn4dlNETIwaE7E5yxgVkzNNbAOCAiRBv vR7vrSHY9nji3hGmv43R1ebPs5OPV9kaCD0GlBaT5e0Elql8cmmHS70ZuXgDtzGXr/ol HYLw== X-Gm-Message-State: APuU4Z+fELhTNAEftevK/VFMO3Kab/oFroV2H3n88nC6cm+iSq2Zxvh4 2DkGhquXnA63hebF8FcTCXyXPBTiII2hn/d8Q2uCKx54NAB/steXV9Po7w1kauFfzrqB/30UtFQ MpzkMI9M= X-Gm-Gg: AZFdTZe5Ps+gzKx+K9qhoQCWV/DcYsT807iD8/x1i4uKIzsrVFbTWai3Id/VYXW92RT YigtTqBd1mFGT59Z/p7oj3f3agx8QK1rHcUvoRATR0RuzisskZ8o1Px8UUfsuWenN3CXdXHGabk A2rTi17p8K7coNO+B9xH6YCiGFMGEi3yq8H7o6Noili/CsCSQ/BPQxqgRzw0Zw2uojcipmZme08 9cr4sUDH7Gl7Ztubcg9iVkUNXbRHl3qF8iLU9RQDfbISxCqM0KIMcGkwe+HeMVXkN3CudMkglJK ZEpLZYziDaaw1MzHiYdbY8SNG4TMfXIm9BT3zFlzCgQnf5mxICXPfSlOQf5MxRMAjQDLwwF11Qp ocyEqqZDlvnMZu/iy6Egl4+XSkqT3MQ8neuEs05418+xKSD3WZjN2JUdEFIbfN68RrsX/3zXbMM Jr35guoB196jzDibjAUyzygbTky1QW3l16jEfCWHG+H5UpbwxMV3zehEnA3xSGYiALZSrG0kG6A 9DAhepwzZiTig5amymjoaHD3KT3eabWM+kVttY+qCNw/hvZkhqPEwveDC3LWSIwca5rit/9wr0K ZnzMEdu7upkc6zyPl6ZuvySnAzG27L1e4nJyBxjcgcKLJA== X-Received: by 2002:a05:6000:3c4:b0:48b:1a0:5630 with SMTP id ffacd0b85a97d-4a63d985408mr4289734f8f.41.1794995892668; Wed, 18 Nov 2026 01:58:12 -0800 (PST) Received: from inspiron14p-linux ([109.76.187.112]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4a655f9f4a7sm3940871f8f.34.2026.11.18.01.58.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2026 01:58:12 -0800 (PST) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: rstrode@redhat.com, robert.mader@collabora.com, barnabas.pocze@ideasonboard.com, Bryan O'Donoghue Subject: [RFC PATCH v2 23/26] libcamera: shaders: bayer_1x_packed_to_blc_glr16f.frag: Sample inputs at the texel centers Date: Wed, 18 Nov 2026 10:57:30 +0100 Message-ID: <20261118095735.170587-24-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20261118095735.170587-1-bryan.odonoghue@linaro.org> References: <20261118095735.170587-1-bryan.odonoghue@linaro.org> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" texture2D() takes inputs in the range 0.0f..1.0f for any x/y coordinate. This means a byte index has to be scaled into the range 0.0f..1.0f. When we mean to sample byte where x = 5.0 we calculate 4.964. This is very much dependent on how an individual implementation does GL_NEAREST filtering. For example on a reference Qualcomm system I see no error however using SwiftShader, whose textured unit works in steps of 1/65536 we can easily elicit an invalid read. Change the logic of where to sample by forcing the "asked" for co-ordinate into the middle of the texel not the periphery. We do this by adding 0.5f to each x/y before multiplying by tex_step. The outcome looks like this: pixel 4 of row 7 in a 2410-byte, 1088-row RAW10 frame is byte 5 of row 7: byte 4 byte 5 +-------------+-------------+ row 6 | | | | x | | x before: read (4.96, 6.99) +-------------X-------------+ X before: asked (5.0, 7.0) row 7 | | | | | o | o after: asked (5.5, 7.5), | | | read (5.48, 7.49) +-------------+-------------+ before: byte 4 of row 6, the low bits of pixels 0-3 on the row above after: byte 5 of row 7 This is easy to reproduce on SwitfShader because its texture unit is coarser than most real hardware. For any implementation we have an upper limit on what can be supported by frame-based floating point sampling. Later patches will interrogate shader precision and reject resolutions we can't support. For now implement the immediate sampling fix as given above. Signed-off-by: Bryan O'Donoghue --- src/libcamera/shaders/bayer_1x_packed_to_glr16f.frag | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcamera/shaders/bayer_1x_packed_to_glr16f.frag b/src/libcamera/shaders/bayer_1x_packed_to_glr16f.frag index 418a9e063..22eb74444 100644 --- a/src/libcamera/shaders/bayer_1x_packed_to_glr16f.frag +++ b/src/libcamera/shaders/bayer_1x_packed_to_glr16f.frag @@ -87,7 +87,7 @@ void main(void) */ center_bytes.x = BPP * center_pixel.x + 0.02; center_bytes.x = floor(center_bytes.x); - center_bytes *= tex_step; + center_bytes = (center_bytes + 0.5) * tex_step; float C = texture2D(tex_y, center_bytes).r;