From 1485a3ff7b52eed21cdc199aaa76ee1692dfa3c8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Sat, 21 Mar 2020 02:58:51 -0400 Subject: [PATCH] glthread: handle gl{Push,Pop}ClientAttrib{DefaultEXT} for glthread states Part-of: --- src/mapi/glapi/gen/EXT_direct_state_access.xml | 6 +- src/mapi/glapi/gen/gl_API.xml | 6 +- src/mesa/main/glthread.h | 19 ++++++ src/mesa/main/glthread_varray.c | 86 ++++++++++++++++++++++++++ 4 files changed, 113 insertions(+), 4 deletions(-) diff --git a/src/mapi/glapi/gen/EXT_direct_state_access.xml b/src/mapi/glapi/gen/EXT_direct_state_access.xml index d570f68..4314973 100644 --- a/src/mapi/glapi/gen/EXT_direct_state_access.xml +++ b/src/mapi/glapi/gen/EXT_direct_state_access.xml @@ -102,11 +102,13 @@ - + - + diff --git a/src/mapi/glapi/gen/gl_API.xml b/src/mapi/glapi/gen/gl_API.xml index 2ee1c7f..42857e4 100644 --- a/src/mapi/glapi/gen/gl_API.xml +++ b/src/mapi/glapi/gen/gl_API.xml @@ -3388,11 +3388,13 @@ - + - + diff --git a/src/mesa/main/glthread.h b/src/mesa/main/glthread.h index 35b5f19..db73372 100644 --- a/src/mesa/main/glthread.h +++ b/src/mesa/main/glthread.h @@ -51,6 +51,7 @@ #include "util/u_queue.h" #include "GL/gl.h" #include "compiler/shader_enums.h" +#include "main/config.h" struct gl_context; struct gl_buffer_object; @@ -99,6 +100,18 @@ struct glthread_batch uint8_t buffer[MARSHAL_MAX_CMD_SIZE]; }; +struct glthread_client_attrib { + struct glthread_vao VAO; + GLuint CurrentArrayBufferName; + int ClientActiveTexture; + GLuint RestartIndex; + bool PrimitiveRestart; + bool PrimitiveRestartFixedIndex; + + /** Whether this element of the client attrib stack contains saved state. */ + bool Valid; +}; + struct glthread_state { /** Multithreaded queue. */ @@ -143,6 +156,8 @@ struct glthread_state struct glthread_vao *CurrentVAO; struct glthread_vao *LastLookedUpVAO; struct glthread_vao DefaultVAO; + struct glthread_client_attrib ClientAttribStack[MAX_CLIENT_ATTRIB_STACK_DEPTH]; + int ClientAttribStackTop; int ClientActiveTexture; /** Currently-bound buffer object IDs. */ @@ -188,5 +203,9 @@ void _mesa_glthread_DSAAttribPointer(struct gl_context *ctx, GLuint vao, GLuint buffer, gl_vert_attrib attrib, GLint size, GLenum type, GLsizei stride, GLintptr offset); +void _mesa_glthread_PushClientAttrib(struct gl_context *ctx, GLbitfield mask, + bool set_default); +void _mesa_glthread_PopClientAttrib(struct gl_context *ctx); +void _mesa_glthread_ClientAttribDefault(struct gl_context *ctx, GLbitfield mask); #endif /* _GLTHREAD_H*/ diff --git a/src/mesa/main/glthread_varray.c b/src/mesa/main/glthread_varray.c index ff333af..8fae4af 100644 --- a/src/mesa/main/glthread_varray.c +++ b/src/mesa/main/glthread_varray.c @@ -308,3 +308,89 @@ _mesa_glthread_DSAAttribPointer(struct gl_context *ctx, GLuint vaobj, attrib_pointer(glthread, vao, buffer, attrib, size, type, stride, (const void*)offset); } + +void +_mesa_glthread_PushClientAttrib(struct gl_context *ctx, GLbitfield mask, + bool set_default) +{ + struct glthread_state *glthread = &ctx->GLThread; + + if (glthread->ClientAttribStackTop >= MAX_CLIENT_ATTRIB_STACK_DEPTH) + return; + + struct glthread_client_attrib *top = + &glthread->ClientAttribStack[glthread->ClientAttribStackTop]; + + if (mask & GL_CLIENT_VERTEX_ARRAY_BIT) { + top->VAO = *glthread->CurrentVAO; + top->CurrentArrayBufferName = glthread->CurrentArrayBufferName; + top->ClientActiveTexture = glthread->ClientActiveTexture; + top->RestartIndex = glthread->RestartIndex; + top->PrimitiveRestart = glthread->PrimitiveRestart; + top->PrimitiveRestartFixedIndex = glthread->PrimitiveRestartFixedIndex; + top->Valid = true; + } else { + top->Valid = false; + } + + glthread->ClientAttribStackTop++; + + if (set_default) + _mesa_glthread_ClientAttribDefault(ctx, mask); +} + +void +_mesa_glthread_PopClientAttrib(struct gl_context *ctx) +{ + struct glthread_state *glthread = &ctx->GLThread; + + if (glthread->ClientAttribStackTop == 0) + return; + + glthread->ClientAttribStackTop--; + + struct glthread_client_attrib *top = + &glthread->ClientAttribStack[glthread->ClientAttribStackTop]; + + if (!top->Valid) + return; + + /* Popping a delete VAO is an error. */ + struct glthread_vao *vao = NULL; + if (top->VAO.Name) { + vao = lookup_vao(ctx, top->VAO.Name); + if (!vao) + return; + } + + /* Restore states. */ + glthread->CurrentArrayBufferName = top->CurrentArrayBufferName; + glthread->ClientActiveTexture = top->ClientActiveTexture; + glthread->RestartIndex = top->RestartIndex; + glthread->PrimitiveRestart = top->PrimitiveRestart; + glthread->PrimitiveRestartFixedIndex = top->PrimitiveRestartFixedIndex; + + if (!vao) + vao = &glthread->DefaultVAO; + + assert(top->VAO.Name == vao->Name); + *vao = top->VAO; /* Copy all fields. */ + glthread->CurrentVAO = vao; +} + +void +_mesa_glthread_ClientAttribDefault(struct gl_context *ctx, GLbitfield mask) +{ + struct glthread_state *glthread = &ctx->GLThread; + + if (!(mask & GL_CLIENT_VERTEX_ARRAY_BIT)) + return; + + glthread->CurrentArrayBufferName = 0; + glthread->ClientActiveTexture = 0; + glthread->RestartIndex = 0; + glthread->PrimitiveRestart = false; + glthread->PrimitiveRestartFixedIndex = false; + glthread->CurrentVAO = &glthread->DefaultVAO; + _mesa_glthread_reset_vao(glthread->CurrentVAO); +} -- 2.7.4