From e6f6142c9ba1705660c52236a1469058270c87f9 Mon Sep 17 00:00:00 2001 From: Mark Janes Date: Mon, 25 Jul 2022 15:10:19 -0700 Subject: [PATCH] iris: pad all structures used in a shader key When the compiler pads a data structure, the padded bytes will not be initialized. Shader keys are compared with memcmp and unitialized bytes within the structure breaks this mechanism. Explicitly pad the structures with members, so the compiler is forced to initialize them. Add a warning to indicate if a change to alignment in any of the data structures requires additional padding. Reviewed-by: Kenneth Graunke Part-of: --- src/gallium/drivers/iris/iris_context.h | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/gallium/drivers/iris/iris_context.h b/src/gallium/drivers/iris/iris_context.h index 05bbd177488..9652f84b971 100644 --- a/src/gallium/drivers/iris/iris_context.h +++ b/src/gallium/drivers/iris/iris_context.h @@ -29,6 +29,7 @@ #include "util/set.h" #include "util/slab.h" #include "util/u_debug.h" +#include "util/macros.h" #include "util/u_threaded_context.h" #include "intel/blorp/blorp.h" #include "intel/dev/intel_debug.h" @@ -206,15 +207,23 @@ enum iris_nos_dep { * Program cache keys for state based recompiles. */ -struct iris_base_prog_key { - unsigned program_string_id; - bool limit_trig_input_range; -}; +/* Provide explicit padding for each member, to ensure that the compiler + * initializes every bit in the shader cache keys. The keys will be compared + * with memcmp. + */ +PRAGMA_DIAGNOSTIC_PUSH +PRAGMA_DIAGNOSTIC_ERROR(-Wpadded) /** * Note, we need to take care to have padding explicitly declared * for key since we will directly memcmp the whole struct. */ +struct iris_base_prog_key { + unsigned program_string_id; + bool limit_trig_input_range; + unsigned padding:24; +}; + struct iris_vue_prog_key { struct iris_base_prog_key base; @@ -234,6 +243,7 @@ struct iris_tcs_prog_key { uint8_t input_vertices; bool quads_workaround; + unsigned padding:16; /** A bitfield of per-patch outputs written. */ uint32_t patch_outputs_written; @@ -268,8 +278,11 @@ struct iris_fs_prog_key { bool multisample_fbo:1; bool force_dual_color_blend:1; bool coherent_fb_fetch:1; + unsigned padding_1:3; uint8_t color_outputs_valid; + uint64_t padding_2:40; + uint64_t input_slots_valid; }; @@ -288,6 +301,9 @@ union iris_any_prog_key { struct iris_cs_prog_key cs; }; +/* Restore the pack alignment to default. */ +PRAGMA_DIAGNOSTIC_POP + /** @} */ struct iris_depth_stencil_alpha_state;