diff --git a/src/mapi/glapi/gen/gl_marshal.py b/src/mapi/glapi/gen/gl_marshal.py index 233a60d5db0..afde88e61dc 100644 --- a/src/mapi/glapi/gen/gl_marshal.py +++ b/src/mapi/glapi/gen/gl_marshal.py @@ -154,12 +154,10 @@ class PrintCode(gl_XML.gl_print_base): self.print_call(func, unmarshal=1) if variable_params: - out('return cmd->cmd_base.cmd_size;') + out('return cmd->num_slots;') else: struct = 'struct marshal_cmd_{0}'.format(func.name) - out('const unsigned cmd_size = (align(sizeof({0}), 8) / 8);'.format(struct)) - out('assert(cmd_size == cmd->cmd_base.cmd_size);') - out('return cmd_size;') + out('return align(sizeof({0}), 8) / 8;'.format(struct)) out('}') out('{0}{1} GLAPIENTRY'.format('static ' if func.marshal_is_static() else '', func.return_type)) @@ -218,6 +216,8 @@ class PrintCode(gl_XML.gl_print_base): # Add the call into the batch. out('cmd = _mesa_glthread_allocate_command(ctx, ' 'DISPATCH_CMD_{0}, cmd_size);'.format(func.name)) + if variable_params: + out('cmd->num_slots = align(cmd_size, 8) / 8;') for p in fixed_params: type = marshal_XML.get_marshal_type(func.name, p) diff --git a/src/mapi/glapi/gen/marshal_XML.py b/src/mapi/glapi/gen/marshal_XML.py index ffaeb1498a9..41c411cbfdf 100644 --- a/src/mapi/glapi/gen/marshal_XML.py +++ b/src/mapi/glapi/gen/marshal_XML.py @@ -174,6 +174,8 @@ class marshal_function(gl_XML.gl_function): print('struct marshal_cmd_{0}'.format(self.name)) print('{') print(' struct marshal_cmd_base cmd_base;') + if variable_params: + print(' uint16_t num_slots;') # Sort the parameters according to their size to pack the structure optimally for p in sorted(fixed_params, key=lambda p: get_type_size(self.name, p)): diff --git a/src/mesa/main/glthread_bufferobj.c b/src/mesa/main/glthread_bufferobj.c index 100e810c3f4..07a9285ad7f 100644 --- a/src/mesa/main/glthread_bufferobj.c +++ b/src/mesa/main/glthread_bufferobj.c @@ -240,9 +240,7 @@ _mesa_unmarshal_BindBuffer(struct gl_context *ctx, if (cmd->target[1]) CALL_BindBuffer(ctx->Dispatch.Current, (cmd->target[1], cmd->buffer[1])); - const unsigned cmd_size = (align(sizeof(struct marshal_cmd_BindBuffer), 8) / 8); - assert (cmd_size == cmd->cmd_base.cmd_size); - return cmd_size; + return align(sizeof(struct marshal_cmd_BindBuffer), 8) / 8; } void GLAPIENTRY @@ -251,11 +249,13 @@ _mesa_marshal_BindBuffer(GLenum target, GLuint buffer) GET_CURRENT_CONTEXT(ctx); struct glthread_state *glthread = &ctx->GLThread; struct marshal_cmd_BindBuffer *last = glthread->LastBindBuffer; + int cmd_size = sizeof(struct marshal_cmd_BindBuffer); _mesa_glthread_BindBuffer(ctx, target, buffer); /* If the last call is BindBuffer... */ - if (_mesa_glthread_call_is_last(glthread, &last->cmd_base)) { + if (_mesa_glthread_call_is_last(glthread, &last->cmd_base, + align(cmd_size, 8) / 8)) { /* If the target is in the last call and unbinding the buffer, overwrite * the buffer ID there. * @@ -279,7 +279,6 @@ _mesa_marshal_BindBuffer(GLenum target, GLuint buffer) } } - int cmd_size = sizeof(struct marshal_cmd_BindBuffer); struct marshal_cmd_BindBuffer *cmd = _mesa_glthread_allocate_command(ctx, DISPATCH_CMD_BindBuffer, cmd_size); @@ -319,6 +318,7 @@ _mesa_glthread_DeleteBuffers(struct gl_context *ctx, GLsizei n, struct marshal_cmd_BufferData { struct marshal_cmd_base cmd_base; + uint16_t num_slots; GLuint target_or_name; GLsizeiptr size; GLenum usage; @@ -355,7 +355,7 @@ _mesa_unmarshal_BufferData(struct gl_context *ctx, CALL_BufferData(ctx->Dispatch.Current, (target_or_name, size, data, usage)); } - return cmd->cmd_base.cmd_size; + return cmd->num_slots; } uint32_t @@ -401,7 +401,7 @@ _mesa_marshal_BufferData_merged(GLuint target_or_name, GLsizeiptr size, struct marshal_cmd_BufferData *cmd = _mesa_glthread_allocate_command(ctx, DISPATCH_CMD_BufferData, cmd_size); - + cmd->num_slots = align(cmd_size, 8) / 8; cmd->target_or_name = target_or_name; cmd->size = size; cmd->usage = usage; @@ -445,6 +445,7 @@ _mesa_marshal_NamedBufferDataEXT(GLuint buffer, GLsizeiptr size, struct marshal_cmd_BufferSubData { struct marshal_cmd_base cmd_base; + uint16_t num_slots; GLenum target_or_name; GLintptr offset; GLsizeiptr size; @@ -472,7 +473,7 @@ _mesa_unmarshal_BufferSubData(struct gl_context *ctx, CALL_BufferSubData(ctx->Dispatch.Current, (target_or_name, offset, size, data)); } - return cmd->cmd_base.cmd_size; + return cmd->num_slots; } uint32_t @@ -542,6 +543,7 @@ _mesa_marshal_BufferSubData_merged(GLuint target_or_name, GLintptr offset, struct marshal_cmd_BufferSubData *cmd = _mesa_glthread_allocate_command(ctx, DISPATCH_CMD_BufferSubData, cmd_size); + cmd->num_slots = align(cmd_size, 8) / 8; cmd->target_or_name = target_or_name; cmd->offset = offset; cmd->size = size; diff --git a/src/mesa/main/glthread_draw.c b/src/mesa/main/glthread_draw.c index 8c48aef859d..cde43be7b35 100644 --- a/src/mesa/main/glthread_draw.c +++ b/src/mesa/main/glthread_draw.c @@ -291,9 +291,7 @@ _mesa_unmarshal_DrawArrays(struct gl_context *ctx, const GLsizei count = cmd->count; CALL_DrawArrays(ctx->Dispatch.Current, (mode, first, count)); - const unsigned cmd_size = align(sizeof(*cmd), 8) / 8; - assert(cmd_size == cmd->cmd_base.cmd_size); - return cmd_size; + return align(sizeof(*cmd), 8) / 8; } /* DrawArraysInstancedBaseInstance without user buffers. */ @@ -310,9 +308,7 @@ _mesa_unmarshal_DrawArraysInstancedBaseInstance(struct gl_context *ctx, CALL_DrawArraysInstancedBaseInstance(ctx->Dispatch.Current, (mode, first, count, instance_count, baseinstance)); - const unsigned cmd_size = align(sizeof(*cmd), 8) / 8; - assert(cmd_size == cmd->cmd_base.cmd_size); - return cmd_size; + return align(sizeof(*cmd), 8) / 8; } struct marshal_cmd_DrawArraysInstancedBaseInstanceDrawID @@ -341,16 +337,14 @@ _mesa_unmarshal_DrawArraysInstancedBaseInstanceDrawID(struct gl_context *ctx, (mode, first, count, instance_count, baseinstance)); ctx->DrawID = 0; - - const unsigned cmd_size = align(sizeof(*cmd), 8) / 8; - assert(cmd_size == cmd->cmd_base.cmd_size); - return cmd_size; + return align(sizeof(*cmd), 8) / 8; } /* DrawArraysInstancedBaseInstance with user buffers. */ struct marshal_cmd_DrawArraysUserBuf { struct marshal_cmd_base cmd_base; + uint16_t num_slots; GLenum mode; GLint first; GLsizei count; @@ -383,7 +377,7 @@ _mesa_unmarshal_DrawArraysUserBuf(struct gl_context *ctx, (mode, first, count, instance_count, baseinstance)); ctx->DrawID = 0; - return cmd->cmd_base.cmd_size; + return cmd->num_slots; } static inline unsigned @@ -484,6 +478,7 @@ draw_arrays(GLuint drawid, GLenum mode, GLint first, GLsizei count, cmd = _mesa_glthread_allocate_command(ctx, DISPATCH_CMD_DrawArraysUserBuf, cmd_size); + cmd->num_slots = align(cmd_size, 8) / 8; cmd->mode = mode; cmd->first = first; cmd->count = count; @@ -500,6 +495,7 @@ draw_arrays(GLuint drawid, GLenum mode, GLint first, GLsizei count, struct marshal_cmd_MultiDrawArraysUserBuf { struct marshal_cmd_base cmd_base; + uint16_t num_slots; GLenum mode; GLsizei draw_count; GLuint user_buffer_mask; @@ -527,7 +523,7 @@ _mesa_unmarshal_MultiDrawArraysUserBuf(struct gl_context *ctx, CALL_MultiDrawArrays(ctx->Dispatch.Current, (mode, first, count, draw_count)); - return cmd->cmd_base.cmd_size; + return cmd->num_slots; } void GLAPIENTRY @@ -594,6 +590,7 @@ _mesa_marshal_MultiDrawArrays(GLenum mode, const GLint *first, if (cmd_size <= MARSHAL_MAX_CMD_SIZE) { cmd = _mesa_glthread_allocate_command(ctx, DISPATCH_CMD_MultiDrawArraysUserBuf, cmd_size); + cmd->num_slots = align(cmd_size, 8) / 8; cmd->mode = mode; cmd->draw_count = draw_count; cmd->user_buffer_mask = user_buffer_mask; @@ -632,9 +629,7 @@ _mesa_unmarshal_DrawElementsInstanced(struct gl_context *ctx, CALL_DrawElementsInstanced(ctx->Dispatch.Current, (mode, count, type, indices, instance_count)); - const unsigned cmd_size = align(sizeof(*cmd), 8) / 8; - assert(cmd_size == cmd->cmd_base.cmd_size); - return cmd_size; + return align(sizeof(*cmd), 8) / 8; } /* DrawElementsBaseVertex without user buffers. */ @@ -650,9 +645,7 @@ _mesa_unmarshal_DrawElementsBaseVertex(struct gl_context *ctx, CALL_DrawElementsBaseVertex(ctx->Dispatch.Current, (mode, count, type, indices, basevertex)); - const unsigned cmd_size = align(sizeof(*cmd), 8) / 8; - assert(cmd_size == cmd->cmd_base.cmd_size); - return cmd_size; + return align(sizeof(*cmd), 8) / 8; } /* DrawElementsInstancedBaseVertexBaseInstance without user buffers. */ @@ -672,9 +665,7 @@ _mesa_unmarshal_DrawElementsInstancedBaseVertexBaseInstance(struct gl_context *c (mode, count, type, indices, instance_count, basevertex, baseinstance)); - const unsigned cmd_size = align(sizeof(*cmd), 8) / 8; - assert(cmd_size == cmd->cmd_base.cmd_size); - return cmd_size; + return align(sizeof(*cmd), 8) / 8; } struct marshal_cmd_DrawElementsInstancedBaseVertexBaseInstanceDrawID @@ -709,9 +700,7 @@ _mesa_unmarshal_DrawElementsInstancedBaseVertexBaseInstanceDrawID(struct gl_cont baseinstance)); ctx->DrawID = 0; - const unsigned cmd_size = align(sizeof(*cmd), 8) / 8; - assert(cmd_size == cmd->cmd_base.cmd_size); - return cmd_size; + return align(sizeof(*cmd), 8) / 8; } uint32_t @@ -731,7 +720,7 @@ _mesa_unmarshal_DrawElementsUserBuf(struct gl_context *ctx, struct gl_buffer_object *index_buffer = cmd->index_buffer; _mesa_reference_buffer_object(ctx, &index_buffer, NULL); - return cmd->cmd_base.cmd_size; + return cmd->num_slots; } static inline bool @@ -920,6 +909,7 @@ draw_elements(GLuint drawid, GLenum mode, GLsizei count, GLenum type, struct marshal_cmd_DrawElementsUserBuf *cmd; cmd = _mesa_glthread_allocate_command(ctx, DISPATCH_CMD_DrawElementsUserBuf, cmd_size); + cmd->num_slots = align(cmd_size, 8) / 8; cmd->mode = MIN2(mode, 0xffff); cmd->type = MIN2(type, 0xffff); cmd->count = count; @@ -938,6 +928,7 @@ draw_elements(GLuint drawid, GLenum mode, GLsizei count, GLenum type, struct marshal_cmd_MultiDrawElementsUserBuf { struct marshal_cmd_base cmd_base; + uint16_t num_slots; bool has_base_vertex; GLenum8 mode; GLenum16 type; @@ -980,7 +971,7 @@ _mesa_unmarshal_MultiDrawElementsUserBuf(struct gl_context *ctx, ((GLintptr)index_buffer, mode, count, type, indices, draw_count, basevertex)); _mesa_reference_buffer_object(ctx, &index_buffer, NULL); - return cmd->cmd_base.cmd_size; + return cmd->num_slots; } static void @@ -1004,6 +995,7 @@ multi_draw_elements_async(struct gl_context *ctx, GLenum mode, /* Make sure cmd can fit the queue buffer */ if (cmd_size <= MARSHAL_MAX_CMD_SIZE) { cmd = _mesa_glthread_allocate_command(ctx, DISPATCH_CMD_MultiDrawElementsUserBuf, cmd_size); + cmd->num_slots = align(cmd_size, 8) / 8; cmd->mode = MIN2(mode, 0xff); /* primitive types go from 0 to 14 */ cmd->type = MIN2(type, 0xffff); cmd->draw_count = draw_count; @@ -1330,10 +1322,7 @@ _mesa_unmarshal_DrawArraysIndirect(struct gl_context *ctx, CALL_DrawArraysIndirect(ctx->Dispatch.Current, (mode, indirect)); - const unsigned cmd_size = - (align(sizeof(struct marshal_cmd_DrawArraysIndirect), 8) / 8); - assert(cmd_size == cmd->cmd_base.cmd_size); - return cmd_size; + return align(sizeof(struct marshal_cmd_DrawArraysIndirect), 8) / 8; } void GLAPIENTRY @@ -1367,11 +1356,7 @@ _mesa_unmarshal_DrawElementsIndirect(struct gl_context *ctx, const GLvoid * indirect = cmd->indirect; CALL_DrawElementsIndirect(ctx->Dispatch.Current, (mode, type, indirect)); - - const unsigned cmd_size = - (align(sizeof(struct marshal_cmd_DrawElementsIndirect), 8) / 8); - assert(cmd_size == cmd->cmd_base.cmd_size); - return cmd_size; + return align(sizeof(struct marshal_cmd_DrawElementsIndirect), 8) / 8; } void GLAPIENTRY @@ -1409,11 +1394,7 @@ _mesa_unmarshal_MultiDrawArraysIndirect(struct gl_context *ctx, CALL_MultiDrawArraysIndirect(ctx->Dispatch.Current, (mode, indirect, primcount, stride)); - - const unsigned cmd_size = - (align(sizeof(struct marshal_cmd_MultiDrawArraysIndirect), 8) / 8); - assert(cmd_size == cmd->cmd_base.cmd_size); - return cmd_size; + return align(sizeof(struct marshal_cmd_MultiDrawArraysIndirect), 8) / 8; } void GLAPIENTRY @@ -1456,11 +1437,7 @@ _mesa_unmarshal_MultiDrawElementsIndirect(struct gl_context *ctx, CALL_MultiDrawElementsIndirect(ctx->Dispatch.Current, (mode, type, indirect, primcount, stride)); - - const unsigned cmd_size = - (align(sizeof(struct marshal_cmd_MultiDrawElementsIndirect), 8) / 8); - assert(cmd_size == cmd->cmd_base.cmd_size); - return cmd_size; + return align(sizeof(struct marshal_cmd_MultiDrawElementsIndirect), 8) / 8; } void GLAPIENTRY @@ -1508,11 +1485,7 @@ _mesa_unmarshal_MultiDrawArraysIndirectCountARB(struct gl_context *ctx, CALL_MultiDrawArraysIndirectCountARB(ctx->Dispatch.Current, (mode, indirect, drawcount, maxdrawcount, stride)); - - const unsigned cmd_size = - (align(sizeof(struct marshal_cmd_MultiDrawArraysIndirectCountARB), 8) / 8); - assert(cmd_size == cmd->cmd_base.cmd_size); - return cmd_size; + return align(sizeof(struct marshal_cmd_MultiDrawArraysIndirectCountARB), 8) / 8; } void GLAPIENTRY @@ -1563,9 +1536,7 @@ _mesa_unmarshal_MultiDrawElementsIndirectCountARB(struct gl_context *ctx, CALL_MultiDrawElementsIndirectCountARB(ctx->Dispatch.Current, (mode, type, indirect, drawcount, maxdrawcount, stride)); - const unsigned cmd_size = (align(sizeof(struct marshal_cmd_MultiDrawElementsIndirectCountARB), 8) / 8); - assert(cmd_size == cmd->cmd_base.cmd_size); - return cmd_size; + return align(sizeof(struct marshal_cmd_MultiDrawElementsIndirectCountARB), 8) / 8; } void GLAPIENTRY @@ -1975,8 +1946,6 @@ _mesa_unmarshal_PushMatrix(struct gl_context *ctx, next2 = _mesa_glthread_next_cmd(next1, draw_elements_size); if (_mesa_glthread_get_cmd(next2)->cmd_id == DISPATCH_CMD_PopMatrix) { - assert(_mesa_glthread_get_cmd(next2)->cmd_size == pop_matrix_size); - /* The beauty of this is that this is inlined. */ _mesa_unmarshal_DrawElementsBaseVertex(ctx, (void*)next1); return push_matrix_size + draw_elements_size + pop_matrix_size; @@ -1991,10 +1960,8 @@ _mesa_unmarshal_PushMatrix(struct gl_context *ctx, */ next2 = _mesa_glthread_next_cmd(next1, mult_matrixf_size); - if (_mesa_glthread_get_cmd(next2)->cmd_id == DISPATCH_CMD_PopMatrix) { - assert(_mesa_glthread_get_cmd(next2)->cmd_size == pop_matrix_size); + if (_mesa_glthread_get_cmd(next2)->cmd_id == DISPATCH_CMD_PopMatrix) return push_matrix_size + mult_matrixf_size + pop_matrix_size; - } break; } diff --git a/src/mesa/main/glthread_list.c b/src/mesa/main/glthread_list.c index b27671859c4..46d8ee46079 100644 --- a/src/mesa/main/glthread_list.c +++ b/src/mesa/main/glthread_list.c @@ -29,6 +29,7 @@ struct marshal_cmd_CallList { struct marshal_cmd_base cmd_base; + uint16_t num_slots; GLuint num; GLuint list[]; }; @@ -39,13 +40,13 @@ _mesa_unmarshal_CallList(struct gl_context *ctx, { const GLuint num = cmd->num; - if (cmd->cmd_base.cmd_size == sizeof(*cmd) / 8) { + if (cmd->num_slots == sizeof(*cmd) / 8) { CALL_CallList(ctx->Dispatch.Current, (num)); } else { CALL_CallLists(ctx->Dispatch.Current, (num, GL_UNSIGNED_INT, cmd->list)); } - return cmd->cmd_base.cmd_size; + return cmd->num_slots; } void GLAPIENTRY @@ -58,15 +59,16 @@ _mesa_marshal_CallList(GLuint list) _mesa_glthread_CallList(ctx, list); /* If the last call is CallList and there is enough space to append another list... */ - if (_mesa_glthread_call_is_last(glthread, &last->cmd_base) && + if (last && + _mesa_glthread_call_is_last(glthread, &last->cmd_base, last->num_slots) && glthread->used + 1 <= MARSHAL_MAX_CMD_SIZE / 8) { STATIC_ASSERT(sizeof(*last) == 8); /* Add the list to the last call. */ - if (last->cmd_base.cmd_size > sizeof(*last) / 8) { + if (last->num_slots > sizeof(*last) / 8) { last->list[last->num++] = list; if (last->num % 2 == 1) { - last->cmd_base.cmd_size++; + last->num_slots++; glthread->used++; } } else { @@ -76,16 +78,17 @@ _mesa_marshal_CallList(GLuint list) last->list[0] = last->num; last->list[1] = list; last->num = 2; - last->cmd_base.cmd_size++; + last->num_slots++; glthread->used++; } - assert(align(sizeof(*last) + last->num * 4, 8) / 8 == last->cmd_base.cmd_size); + assert(align(sizeof(*last) + last->num * 4, 8) / 8 == last->num_slots); return; } int cmd_size = sizeof(struct marshal_cmd_CallList); struct marshal_cmd_CallList *cmd; cmd = _mesa_glthread_allocate_command(ctx, DISPATCH_CMD_CallList, cmd_size); + cmd->num_slots = align(cmd_size, 8) / 8; cmd->num = list; glthread->LastCallList = cmd; diff --git a/src/mesa/main/glthread_marshal.h b/src/mesa/main/glthread_marshal.h index 09a65640f00..cf199de2867 100644 --- a/src/mesa/main/glthread_marshal.h +++ b/src/mesa/main/glthread_marshal.h @@ -41,11 +41,6 @@ struct marshal_cmd_base * Type of command. See enum marshal_dispatch_cmd_id. */ uint16_t cmd_id; - - /** - * Number of uint64_t elements used by the command. - */ - uint16_t cmd_size; }; /* This must be included after "struct marshal_cmd_base" because it uses it. */ @@ -59,6 +54,7 @@ extern const char *_mesa_unmarshal_func_name[NUM_DISPATCH_CMD]; struct marshal_cmd_DrawElementsUserBuf { struct marshal_cmd_base cmd_base; + uint16_t num_slots; GLenum16 mode; GLenum16 type; GLsizei count; @@ -89,7 +85,6 @@ _mesa_glthread_allocate_command(struct gl_context *ctx, (struct marshal_cmd_base *)&next->buffer[glthread->used]; glthread->used += num_elements; cmd_base->cmd_id = cmd_id; - cmd_base->cmd_size = num_elements; return cmd_base; } @@ -102,16 +97,15 @@ _mesa_glthread_get_cmd(uint64_t *opaque_cmd) static inline uint64_t * _mesa_glthread_next_cmd(uint64_t *opaque_cmd, unsigned cmd_size) { - assert(_mesa_glthread_get_cmd(opaque_cmd)->cmd_size == cmd_size); return opaque_cmd + cmd_size; } static inline bool _mesa_glthread_call_is_last(struct glthread_state *glthread, - struct marshal_cmd_base *last) + struct marshal_cmd_base *last, uint16_t num_slots) { return last && - (uint64_t*)last + last->cmd_size == + (uint64_t*)last + num_slots == &glthread->next_batch->buffer[glthread->used]; }