Module: Mesa Branch: main Commit: c824104ce9f9817f835a82af64b235eabba1d477 URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=c824104ce9f9817f835a82af64b235eabba1d477
Author: Patrick Lerda <[email protected]> Date: Mon May 9 16:22:43 2022 +0200 panfrost: Fix unwanted valgrind message related to restart_index As a reminder primitive_restart should always be checked before any access to restart_index. It seems that restart_index is only initialized when primitive_restart is set to a non-zero value. This patch is equivalent to the previous code but written in a way that the compiler will test primitive_restart first before trying to read restart_index. With commit ad864a7c150a15221fb9c85d3214d4bcb6db7518: Conditional jump or move depends on uninitialised value(s) at 0xD33F1EC: panfrost_is_implicit_prim_restart (pan_cmdstream.c:2907) by 0xD33F1EC: panfrost_emit_primitive (pan_cmdstream.c:3073) by 0xD33F1EC: panfrost_draw_emit_tiler (pan_cmdstream.c:3440) by 0xD33F1EC: panfrost_direct_draw (pan_cmdstream.c:3595) by 0xD340467: panfrost_draw_vbo (pan_cmdstream.c:3889) by 0xD219119: u_vbuf_draw_vbo (u_vbuf.c:1498) by 0xD1C81F9: cso_multi_draw (cso_context.c:1644) by 0xCFBA19B: _mesa_draw_arrays.part.11 (draw.c:1324) by 0xCFBADA1: _mesa_draw_arrays (draw.c:1295) by 0xCFBADA1: _mesa_DrawArrays (draw.c:1533) by 0xD32EB: gl_vao_draw_data (in /usr/local/bin/mpv) Uninitialised value was created by a stack allocation at 0xCFBA14E: _mesa_draw_arrays.part.11 (draw.c:1289) With mesa-22.1.0-rc4: Conditional jump or move depends on uninitialised value(s) at 0xD36369C: panfrost_is_implicit_prim_restart (pan_cmdstream.c:2895) by 0xD36369C: panfrost_draw_emit_tiler (pan_cmdstream.c:3023) by 0xD36369C: panfrost_direct_draw (pan_cmdstream.c:3215) by 0xD3649BF: panfrost_draw_vbo (pan_cmdstream.c:3494) by 0xD23DE7D: u_vbuf_draw_vbo (u_vbuf.c:1498) by 0xD1ECBD1: cso_multi_draw (cso_context.c:1644) by 0xCFD60FF: _mesa_draw_arrays.part.11 (draw.c:1324) by 0xCFD6D11: _mesa_draw_arrays (draw.c:1295) by 0xCFD6D11: _mesa_DrawArrays (draw.c:1533) by 0xD32EB: gl_vao_draw_data (in /usr/local/bin/mpv) Uninitialised value was created by a stack allocation at 0xCFD60B2: _mesa_draw_arrays.part.11 (draw.c:1289) Signed-off-by: Patrick Lerda <[email protected]> Reviewed-by: Alyssa Rosenzweig [email protected] Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16389> --- src/gallium/drivers/panfrost/pan_cmdstream.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/gallium/drivers/panfrost/pan_cmdstream.c b/src/gallium/drivers/panfrost/pan_cmdstream.c index 1ef8d09bd2b..3f8b803e995 100644 --- a/src/gallium/drivers/panfrost/pan_cmdstream.c +++ b/src/gallium/drivers/panfrost/pan_cmdstream.c @@ -2902,9 +2902,10 @@ panfrost_emit_primitive_size(struct panfrost_context *ctx, static bool panfrost_is_implicit_prim_restart(const struct pipe_draw_info *info) { - unsigned implicit_index = BITFIELD_MASK(info->index_size * 8); - bool implicit = info->restart_index == implicit_index; - return info->primitive_restart && implicit; + /* As a reminder primitive_restart should always be checked before any + access to restart_index. */ + return info->primitive_restart && + info->restart_index == (unsigned)BITFIELD_MASK(info->index_size * 8); } /* On Bifrost and older, the Renderer State Descriptor aggregates many pieces of
