mesa: consolidate setting no error state and checking suid.
authorDave Airlie <airlied@redhat.com>
Tue, 25 Jan 2022 06:01:00 +0000 (16:01 +1000)
committerDave Airlie <airlied@redhat.com>
Tue, 25 Jan 2022 19:30:35 +0000 (05:30 +1000)
This makes MESA_NO_ERROR and mesa_no_error via drirc do the same thing.

Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14701>

src/gallium/frontends/dri/dri_context.c
src/mesa/main/context.c
src/mesa/main/context.h
src/mesa/state_tracker/st_context.c

index 55bfa22..1b0dd9f 100644 (file)
@@ -41,6 +41,7 @@
 #include "state_tracker/st_context.h"
 
 #include "util/u_memory.h"
+#include "util/debug.h"
 
 GLboolean
 dri_create_context(gl_api api, const struct gl_config * visual,
@@ -155,8 +156,15 @@ dri_create_context(gl_api api, const struct gl_config * visual,
    ctx->cPriv = cPriv;
    ctx->sPriv = sPriv;
 
-   if (driQueryOptionb(&screen->dev->option_cache, "mesa_no_error"))
-      attribs.flags |= ST_CONTEXT_FLAG_NO_ERROR;
+   /* KHR_no_error is likely to crash, overflow memory, etc if an application
+    * has errors so don't enable it for setuid processes.
+    */
+   if (env_var_as_boolean("MESA_NO_ERROR", false) ||
+       driQueryOptionb(&screen->dev->option_cache, "mesa_no_error"))
+#if !defined(_WIN32)
+      if (geteuid() == getuid())
+#endif
+         attribs.flags |= ST_CONTEXT_FLAG_NO_ERROR;
 
    attribs.options = screen->options;
    dri_fill_st_visual(&attribs.visual, screen, visual);
index baaa2a2..7ad1a9f 100644 (file)
@@ -978,6 +978,7 @@ _mesa_initialize_dispatch_tables(struct gl_context *ctx)
 GLboolean
 _mesa_initialize_context(struct gl_context *ctx,
                          gl_api api,
+                         bool no_error,
                          const struct gl_config *visual,
                          struct gl_context *share_list,
                          const struct dd_function_table *driverFunctions)
@@ -1031,15 +1032,8 @@ _mesa_initialize_context(struct gl_context *ctx,
    if (!init_attrib_groups( ctx ))
       goto fail;
 
-   /* KHR_no_error is likely to crash, overflow memory, etc if an application
-    * has errors so don't enable it for setuid processes.
-    */
-   if (env_var_as_boolean("MESA_NO_ERROR", false)) {
-#if !defined(_WIN32)
-      if (geteuid() == getuid())
-#endif
-         ctx->Const.ContextFlags |= GL_CONTEXT_FLAG_NO_ERROR_BIT_KHR;
-   }
+   if (no_error)
+      ctx->Const.ContextFlags |= GL_CONTEXT_FLAG_NO_ERROR_BIT_KHR;
 
    /* setup the API dispatch tables with all nop functions */
    ctx->OutsideBeginEnd = _mesa_alloc_dispatch_table(false);
index f6bbb62..6e068f9 100644 (file)
@@ -73,6 +73,7 @@ _mesa_initialize(const char *extensions_override);
 extern GLboolean
 _mesa_initialize_context( struct gl_context *ctx,
                           gl_api api,
+                          bool no_error,
                           const struct gl_config *visual,
                           struct gl_context *share_list,
                           const struct dd_function_table *driverFunctions);
index 524e1f8..a71837a 100644 (file)
@@ -475,7 +475,7 @@ st_have_perfquery(struct st_context *ctx)
 
 static struct st_context *
 st_create_context_priv(struct gl_context *ctx, struct pipe_context *pipe,
-                       const struct st_config_options *options, bool no_error)
+                       const struct st_config_options *options)
 {
    struct pipe_screen *screen = pipe->screen;
    uint i;
@@ -551,9 +551,6 @@ st_create_context_priv(struct gl_context *ctx, struct pipe_context *pipe,
       st->util_velems.velems[2].src_format = PIPE_FORMAT_R32G32_FLOAT;
    }
 
-   if (no_error)
-      ctx->Const.ContextFlags |= GL_CONTEXT_FLAG_NO_ERROR_BIT_KHR;
-
    ctx->Const.PackedDriverUniformStorage =
       screen->get_param(screen, PIPE_CAP_PACKED_UNIFORMS);
 
@@ -870,7 +867,7 @@ st_create_context(gl_api api, struct pipe_context *pipe,
    ctx->pipe = pipe;
    ctx->screen = pipe->screen;
 
-   if (!_mesa_initialize_context(ctx, api, visual, shareCtx, &funcs)) {
+   if (!_mesa_initialize_context(ctx, api, no_error, visual, shareCtx, &funcs)) {
       align_free(ctx);
       return NULL;
    }
@@ -889,7 +886,7 @@ st_create_context(gl_api api, struct pipe_context *pipe,
    if (pipe->screen->get_param(pipe->screen, PIPE_CAP_INVALIDATE_BUFFER))
       ctx->has_invalidate_buffer = true;
 
-   st = st_create_context_priv(ctx, pipe, options, no_error);
+   st = st_create_context_priv(ctx, pipe, options);
    if (!st) {
       _mesa_free_context_data(ctx, true);
       align_free(ctx);