From 54cba7d297aadb6a088ef91bff860f40e201e8c6 Mon Sep 17 00:00:00 2001 From: "Juan A. Suarez Romero" Date: Wed, 22 Sep 2021 09:10:53 +0200 Subject: [PATCH] v3d: clamp clear color On clearing a color buffer, clamp the passed color values to the allowed ones. Hardware do clamping for TLB values, but not for clear values. v2 (Iago) - Add comment about hardware-based clamping on clear values. v3 (Iago): - Use format utils to simplify clamping - Move clamp color function as utility Reviewed-by: Iago Toral Quiroga Signed-off-by: Juan A. Suarez Romero Part-of: --- src/gallium/drivers/v3d/v3dx_draw.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/gallium/drivers/v3d/v3dx_draw.c b/src/gallium/drivers/v3d/v3dx_draw.c index 25ef97f888e..e9e8f1889af 100644 --- a/src/gallium/drivers/v3d/v3dx_draw.c +++ b/src/gallium/drivers/v3d/v3dx_draw.c @@ -25,6 +25,7 @@ #include "util/u_draw.h" #include "util/u_prim.h" #include "util/format/u_format.h" +#include "util/u_helpers.h" #include "util/u_pack_color.h" #include "util/u_prim_restart.h" #include "util/u_upload_mgr.h" @@ -1564,6 +1565,17 @@ v3d_tlb_clear(struct v3d_job *job, unsigned buffers, color = &swapped_color; } + /* While hardware supports clamping, this is not applied on + * the clear values, so we need to do it manually. + * + * "Clamping is performed on color values immediately as they + * enter the TLB and after blending. Clamping is not + * performed on the clear color." + */ + union pipe_color_union clamped_color = + util_clamp_color(psurf->format, color); + color = &clamped_color; + switch (surf->internal_type) { case V3D_INTERNAL_TYPE_8: util_pack_color(color->f, PIPE_FORMAT_R8G8B8A8_UNORM,