From fa2c39df0fd25d7c57dfbe20c9e8189093046b6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Sat, 23 Oct 2021 16:14:25 -0400 Subject: [PATCH] mesa: remove PADDING_64BIT by adding the dlist header into vbo_save_vertex_list Now we can put useful data where the padding was. Reviewed-by: Pierre-Eric Pelloux-Prayer Part-of: --- src/mesa/main/dlist.c | 65 +++++++------------------------------ src/mesa/main/dlist.h | 33 +++++++++++++++++++ src/mesa/vbo/vbo_save.h | 3 ++ src/mesa/vbo/vbo_save_api.c | 1 - 4 files changed, 47 insertions(+), 55 deletions(-) diff --git a/src/mesa/main/dlist.c b/src/mesa/main/dlist.c index 6085c6d961a..86b7e3fa77f 100644 --- a/src/mesa/main/dlist.c +++ b/src/mesa/main/dlist.c @@ -643,51 +643,6 @@ typedef enum OPCODE_END_OF_LIST } OpCode; -/* We want the vertex list payload to start at offset 8 on x86_64 because it - * contains pointers. The header node has 4 bytes, so add 1 more node to get - * 8 bytes. - */ -#define PADDING_64BIT (sizeof(void*) == 8 ? 1 : 0) - - -/** - * Display list node. - * - * Display list instructions are stored as sequences of "nodes". Nodes - * are allocated in blocks. Each block has BLOCK_SIZE nodes. Blocks - * are linked together with a pointer. - * - * Each instruction in the display list is stored as a sequence of - * contiguous nodes in memory. - * Each node is the union of a variety of data types. - * - * Note, all of these members should be 4 bytes in size or less for the - * sake of compact display lists. We store 8-byte pointers in a pair of - * these nodes using the save/get_pointer() functions below. - */ -union gl_dlist_node -{ - struct { -#if !DETECT_OS_WINDOWS - OpCode opcode:16; -#else - /* sizeof(Node) is 8 with MSVC/mingw, so use an explicit 16 bits type. */ - uint16_t opcode; -#endif - uint16_t InstSize; - }; - GLboolean b; - GLbitfield bf; - GLubyte ub; - GLshort s; - GLushort us; - GLint i; - GLuint ui; - GLenum e; - GLfloat f; - GLsizei si; -}; - typedef union gl_dlist_node Node; @@ -1387,7 +1342,7 @@ _mesa_delete_list(struct gl_context *ctx, struct gl_display_list *dlist) case OPCODE_VERTEX_LIST: case OPCODE_VERTEX_LIST_LOOPBACK: case OPCODE_VERTEX_LIST_COPY_CURRENT: - vbo_destroy_vertex_list(ctx, (struct vbo_save_vertex_list *) &n[1 + PADDING_64BIT]); + vbo_destroy_vertex_list(ctx, (struct vbo_save_vertex_list *) &n[0]); break; case OPCODE_CONTINUE: n = (Node *) get_pointer(&n[1]); @@ -1615,12 +1570,14 @@ _mesa_dlist_alloc_vertex_list(struct gl_context *ctx, bool copy_to_current) Node *n = dlist_alloc(ctx, copy_to_current ? OPCODE_VERTEX_LIST_COPY_CURRENT : OPCODE_VERTEX_LIST, - PADDING_64BIT * 4 + sizeof(struct vbo_save_vertex_list), + sizeof(struct vbo_save_vertex_list) - sizeof(Node), true); - if (n) - return n + 1 + PADDING_64BIT; /* return pointer to payload area, after opcode */ - else + if (!n) return NULL; + + /* Clear all nodes except the header */ + memset(n + 1, 0, sizeof(struct vbo_save_vertex_list) - sizeof(Node)); + return n; } @@ -13385,15 +13342,15 @@ execute_list(struct gl_context *ctx, GLuint list) n[5].f, n[6].f, n[7].f, n[8].f)); break; case OPCODE_VERTEX_LIST: - vbo_save_playback_vertex_list(ctx, &n[1 + PADDING_64BIT], false); + vbo_save_playback_vertex_list(ctx, &n[0], false); break; case OPCODE_VERTEX_LIST_COPY_CURRENT: - vbo_save_playback_vertex_list(ctx, &n[1 + PADDING_64BIT], true); + vbo_save_playback_vertex_list(ctx, &n[0], true); break; case OPCODE_VERTEX_LIST_LOOPBACK: - vbo_save_playback_vertex_list_loopback(ctx, &n[1 + PADDING_64BIT]); + vbo_save_playback_vertex_list_loopback(ctx, &n[0]); break; case OPCODE_CONTINUE: @@ -14976,7 +14933,7 @@ print_list(struct gl_context *ctx, GLuint list, const char *fname) case OPCODE_VERTEX_LIST: case OPCODE_VERTEX_LIST_LOOPBACK: case OPCODE_VERTEX_LIST_COPY_CURRENT: - vbo_print_vertex_list(ctx, (struct vbo_save_vertex_list *) &n[1 + PADDING_64BIT], opcode, f); + vbo_print_vertex_list(ctx, (struct vbo_save_vertex_list *) &n[0], opcode, f); break; default: if (opcode < 0 || opcode > OPCODE_END_OF_LIST) { diff --git a/src/mesa/main/dlist.h b/src/mesa/main/dlist.h index 6a7d418b4ca..a319124fd35 100644 --- a/src/mesa/main/dlist.h +++ b/src/mesa/main/dlist.h @@ -36,6 +36,39 @@ struct gl_context; +/** + * Display list node. + * + * Display list instructions are stored as sequences of "nodes". Nodes + * are allocated in blocks. Each block has BLOCK_SIZE nodes. Blocks + * are linked together with a pointer. + * + * Each instruction in the display list is stored as a sequence of + * contiguous nodes in memory. + * Each node is the union of a variety of data types. + * + * Note, all of these members should be 4 bytes in size or less for the + * sake of compact display lists. We store 8-byte pointers in a pair of + * these nodes using the save/get_pointer() functions below. + */ +union gl_dlist_node +{ + struct { + uint16_t opcode; /* dlist.c : enum Opcode */ + uint16_t InstSize; + }; + GLboolean b; + GLbitfield bf; + GLubyte ub; + GLshort s; + GLushort us; + GLint i; + GLuint ui; + GLenum e; + GLfloat f; + GLsizei si; +}; + /** * Describes the location and size of a glBitmap image in a texture atlas. */ diff --git a/src/mesa/vbo/vbo_save.h b/src/mesa/vbo/vbo_save.h index 96ed597781d..eb9b0e392ab 100644 --- a/src/mesa/vbo/vbo_save.h +++ b/src/mesa/vbo/vbo_save.h @@ -34,6 +34,7 @@ USE OR OTHER DEALINGS IN THE SOFTWARE. #ifndef VBO_SAVE_H #define VBO_SAVE_H +#include "dlist.h" #include "vbo.h" #include "vbo_attrib.h" @@ -53,6 +54,8 @@ USE OR OTHER DEALINGS IN THE SOFTWARE. * compiled using the fallback opcode mechanism provided by dlist.c. */ struct vbo_save_vertex_list { + union gl_dlist_node header; + /* Data used in vbo_save_playback_vertex_list */ struct gl_vertex_array_object *VAO[VP_MODE_MAX]; diff --git a/src/mesa/vbo/vbo_save_api.c b/src/mesa/vbo/vbo_save_api.c index dbfe1650888..f0f5b827b47 100644 --- a/src/mesa/vbo/vbo_save_api.c +++ b/src/mesa/vbo/vbo_save_api.c @@ -526,7 +526,6 @@ compile_vertex_list(struct gl_context *ctx) if (!node) return; - memset(node, 0, sizeof(struct vbo_save_vertex_list)); node->cold = calloc(1, sizeof(*node->cold)); /* Make sure the pointer is aligned to the size of a pointer */