Mesa (main): gallium: use a packed enum to make pipe_prim_mode 1-byte large with __GNUC__
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Tue Aug 24 15:23:06 UTC 2021
Module: Mesa
Branch: main
Commit: 8886bf9a47cf4223e53aea5cef8dc5ffeb71978e
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=8886bf9a47cf4223e53aea5cef8dc5ffeb71978e
Author: Marek Olšák <marek.olsak at amd.com>
Date: Fri Aug 20 10:46:54 2021 -0400
gallium: use a packed enum to make pipe_prim_mode 1-byte large with __GNUC__
Reviewed-By: Mike Blumenkrantz <michael.blumenkrantz at gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12480>
---
src/gallium/auxiliary/util/u_prim.c | 5 +++++
src/gallium/include/pipe/p_defines.h | 2 +-
src/util/macros.h | 7 +++++++
3 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/src/gallium/auxiliary/util/u_prim.c b/src/gallium/auxiliary/util/u_prim.c
index cbd48e26ab6..707757eb27b 100644
--- a/src/gallium/auxiliary/util/u_prim.c
+++ b/src/gallium/auxiliary/util/u_prim.c
@@ -27,6 +27,11 @@
const char *
u_prim_name(enum pipe_prim_type prim)
{
+#if defined(__GNUC__)
+ /* Check that the enum is packed: */
+ STATIC_ASSERT(sizeof(enum pipe_prim_type) == 1);
+#endif
+
static const struct debug_named_value names[] = {
DEBUG_NAMED_VALUE(PIPE_PRIM_POINTS),
DEBUG_NAMED_VALUE(PIPE_PRIM_LINES),
diff --git a/src/gallium/include/pipe/p_defines.h b/src/gallium/include/pipe/p_defines.h
index 488a3968082..6f4fd7e7e06 100644
--- a/src/gallium/include/pipe/p_defines.h
+++ b/src/gallium/include/pipe/p_defines.h
@@ -575,7 +575,7 @@ enum pipe_prim_type {
PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY,
PIPE_PRIM_PATCHES,
PIPE_PRIM_MAX,
-};
+} ENUM_PACKED;
/**
* Tessellator spacing types
diff --git a/src/util/macros.h b/src/util/macros.h
index 4bd18f55ec0..e179479fa20 100644
--- a/src/util/macros.h
+++ b/src/util/macros.h
@@ -327,6 +327,13 @@ do { \
#define ATTRIBUTE_NOINLINE
#endif
+/* Use as: enum name { X, Y } ENUM_PACKED; */
+#if defined(__GNUC__)
+#define ENUM_PACKED __attribute__((packed))
+#else
+#define ENUM_PACKED
+#endif
+
/**
* Check that STRUCT::FIELD can hold MAXVAL. We use a lot of bitfields
More information about the mesa-commit
mailing list