glthread: generate errors for glGet functions between glBegin/End
authorMarek Olšák <marek.olsak@amd.com>
Tue, 23 Aug 2022 19:40:01 +0000 (15:40 -0400)
committerMarge Bot <emma+marge@anholt.net>
Wed, 21 Sep 2022 14:54:49 +0000 (14:54 +0000)
Acked-by: Adam Jackson <ajax@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18223>

src/mapi/glapi/gen/gl_API.xml
src/mesa/main/glthread.h
src/mesa/main/glthread_get.c
src/mesa/main/glthread_marshal.h
src/mesa/main/glthread_shaderobj.c

index bffb072..ce73745 100644 (file)
         <glx rop="3"/>
     </function>
 
-    <function name="Begin" deprecated="3.1" exec="vtxfmt">
+    <function name="Begin" deprecated="3.1" exec="vtxfmt"
+              marshal_call_after="ctx->GLThread.inside_begin_end = true;">
         <param name="mode" type="GLenum"/>
         <glx rop="4"/>
     </function>
         <glx rop="22"/>
     </function>
 
-    <function name="End" deprecated="3.1" exec="vtxfmt">
+    <function name="End" deprecated="3.1" exec="vtxfmt"
+              marshal_call_after="ctx->GLThread.inside_begin_end = false;">
         <glx rop="23"/>
     </function>
 
index de97834..6ed17a3 100644 (file)
@@ -154,6 +154,7 @@ struct glthread_state
 
    /** Whether GLThread is enabled. */
    bool enabled;
+   bool inside_begin_end;
 
    /** Display lists. */
    GLenum ListMode; /**< Zero if not inside display list, else list mode. */
index 2c85d60..916f9b3 100644 (file)
@@ -38,6 +38,10 @@ _mesa_marshal_GetIntegerv(GLenum pname, GLint *p)
 {
    GET_CURRENT_CONTEXT(ctx);
 
+   /* This will generate GL_INVALID_OPERATION, as it should. */
+   if (ctx->GLThread.inside_begin_end)
+      goto sync;
+
    /* TODO: Use get_hash_params.py to return values for items containing:
     * - CONST(
     * - CONTEXT_[A-Z]*(Const
@@ -127,6 +131,7 @@ _mesa_marshal_GetIntegerv(GLenum pname, GLint *p)
       return;
    }
 
+sync:
    _mesa_glthread_finish_before(ctx, "GetIntegerv");
    CALL_GetIntegerv(ctx->CurrentServerDispatch, (pname, p));
 }
index 2db4be1..9c56e57 100644 (file)
@@ -487,6 +487,10 @@ _mesa_glthread_Disable(struct gl_context *ctx, GLenum cap)
 static inline int
 _mesa_glthread_IsEnabled(struct gl_context *ctx, GLenum cap)
 {
+   /* This will generate GL_INVALID_OPERATION, as it should. */
+   if (ctx->GLThread.inside_begin_end)
+      return -1;
+
    switch (cap) {
    case GL_CULL_FACE:
       return ctx->GLThread.CullFace;
index 3fd5bbd..617f10f 100644 (file)
@@ -155,6 +155,15 @@ _mesa_marshal_GetActiveUniform(GLuint program, GLuint index, GLsizei bufSize,
 {
    GET_CURRENT_CONTEXT(ctx);
 
+   /* This will generate GL_INVALID_OPERATION, as it should. */
+   if (ctx->GLThread.inside_begin_end) {
+      _mesa_glthread_finish_before(ctx, "GetActiveUniform");
+      CALL_GetActiveUniform(ctx->CurrentServerDispatch,
+                            (program, index, bufSize, length, size, type,
+                             name));
+      return;
+   }
+
    wait_for_glLinkProgram(ctx);
 
    /* We can execute glGetActiveUniform without syncing if we are sync'd to
@@ -182,6 +191,12 @@ _mesa_marshal_GetUniformLocation(GLuint program, const GLchar *name)
 {
    GET_CURRENT_CONTEXT(ctx);
 
+   /* This will generate GL_INVALID_OPERATION, as it should. */
+   if (ctx->GLThread.inside_begin_end) {
+      _mesa_glthread_finish_before(ctx, "GetUniformLocation");
+      return CALL_GetUniformLocation(ctx->CurrentServerDispatch, (program, name));
+   }
+
    wait_for_glLinkProgram(ctx);
 
    /* This is thread-safe. See the comment in _mesa_marshal_GetActiveUniform. */