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 <kenneth@whitecape.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17749>
This commit is contained in:
Mark Janes 2022-07-25 15:10:19 -07:00 committed by Marge Bot
parent b15d0a11a4
commit e6f6142c9b
1 changed files with 20 additions and 4 deletions

View File

@ -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;