glthread: add nop dispatch
authorMarek Olšák <marek.olsak@amd.com>
Mon, 29 Nov 2021 11:11:35 +0000 (06:11 -0500)
committerMarek Olšák <marek.olsak@amd.com>
Tue, 14 Dec 2021 17:00:40 +0000 (12:00 -0500)
so that glthread behaves the same as the main dispatch.

Also fix the SetError function for GLES 1.0.

Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14000>

src/mapi/glapi/gen/gl_API.xml
src/mapi/glapi/gen/gl_marshal.py
src/mesa/main/context.c
src/mesa/main/context.h

index e1f22a3..dc7b729 100644 (file)
     </function>
 
     <!-- Set a GL error. Used by glthread to set errors without syncing. -->
-    <function name="InternalSetError" es2="2.0">
+    <function name="InternalSetError" es1="1.0" es2="2.0">
         <param name="error" type="GLenum"/>
     </function>
 </category>
index 8705b4e..3dbfa6c 100644 (file)
@@ -383,7 +383,7 @@ class PrintCode(gl_XML.gl_print_base):
         with indent():
             out('struct _glapi_table *table;')
             out('')
-            out('table = _mesa_alloc_dispatch_table();')
+            out('table = _mesa_alloc_dispatch_table(true);')
             out('if (table == NULL)')
             with indent():
                 out('return NULL;')
index 0b62f08..a6e58b2 100644 (file)
@@ -916,6 +916,17 @@ generic_nop(void)
 #endif
 
 
+static int
+glthread_nop(void)
+{
+   /* This writes the error into the glthread command buffer if glthread is
+    * enabled.
+    */
+   CALL_InternalSetError(GET_DISPATCH(), (GL_INVALID_OPERATION));
+   return 0;
+}
+
+
 /**
  * Create a new API dispatch table in which all entries point to the
  * generic_nop() function.  This will not work on Windows because of
@@ -923,7 +934,7 @@ generic_nop(void)
  * call stack.  That's impossible with one generic no-op function.
  */
 struct _glapi_table *
-_mesa_new_nop_table(unsigned numEntries)
+_mesa_new_nop_table(unsigned numEntries, bool glthread)
 {
    struct _glapi_table *table;
 
@@ -939,6 +950,13 @@ _mesa_new_nop_table(unsigned numEntries)
 #else
    table = _glapi_new_nop_table(numEntries);
 #endif
+
+   if (glthread) {
+      _glapi_proc *entry = (_glapi_proc *) table;
+      for (unsigned i = 0; i < numEntries; i++)
+         entry[i] = (_glapi_proc)glthread_nop;
+   }
+
    return table;
 }
 
@@ -949,7 +967,7 @@ _mesa_new_nop_table(unsigned numEntries)
  * functions will call nop_handler() above.
  */
 struct _glapi_table *
-_mesa_alloc_dispatch_table(void)
+_mesa_alloc_dispatch_table(bool glthread)
 {
    /* Find the larger of Mesa's dispatch table and libGL's dispatch table.
     * In practice, this'll be the same for stand-alone Mesa.  But for DRI
@@ -958,7 +976,7 @@ _mesa_alloc_dispatch_table(void)
     */
    int numEntries = MAX2(_glapi_get_dispatch_table_size(), _gloffset_COUNT);
 
-   struct _glapi_table *table = _mesa_new_nop_table(numEntries);
+   struct _glapi_table *table = _mesa_new_nop_table(numEntries, glthread);
 
 #if defined(_WIN32)
    if (table) {
@@ -1021,7 +1039,7 @@ create_beginend_table(const struct gl_context *ctx)
 {
    struct _glapi_table *table;
 
-   table = _mesa_alloc_dispatch_table();
+   table = _mesa_alloc_dispatch_table(false);
    if (!table)
       return NULL;
 
@@ -1170,7 +1188,7 @@ _mesa_initialize_context(struct gl_context *ctx,
    }
 
    /* setup the API dispatch tables with all nop functions */
-   ctx->OutsideBeginEnd = _mesa_alloc_dispatch_table();
+   ctx->OutsideBeginEnd = _mesa_alloc_dispatch_table(false);
    if (!ctx->OutsideBeginEnd)
       goto fail;
    ctx->Exec = ctx->OutsideBeginEnd;
@@ -1198,7 +1216,7 @@ _mesa_initialize_context(struct gl_context *ctx,
    switch (ctx->API) {
    case API_OPENGL_COMPAT:
       ctx->BeginEnd = create_beginend_table(ctx);
-      ctx->Save = _mesa_alloc_dispatch_table();
+      ctx->Save = _mesa_alloc_dispatch_table(false);
       if (!ctx->BeginEnd || !ctx->Save)
          goto fail;
 
index 0933427..42e4094 100644 (file)
@@ -100,7 +100,7 @@ _mesa_initialize_context( struct gl_context *ctx,
                           const struct dd_function_table *driverFunctions);
 
 extern struct _glapi_table *
-_mesa_alloc_dispatch_table(void);
+_mesa_alloc_dispatch_table(bool glthread);
 
 extern void
 _mesa_initialize_exec_table(struct gl_context *ctx);
@@ -109,7 +109,7 @@ extern void
 _mesa_initialize_dispatch_tables(struct gl_context *ctx);
 
 extern struct _glapi_table *
-_mesa_new_nop_table(unsigned numEntries);
+_mesa_new_nop_table(unsigned numEntries, bool glthread);
 
 extern void
 _mesa_free_context_data(struct gl_context *ctx, bool destroy_debug_output);