mesa: fold most of check_valid_to_render into _mesa_update_valid_to_render_state
authorMarek Olšák <marek.olsak@amd.com>
Sat, 16 Jan 2021 16:30:44 +0000 (11:30 -0500)
committerMarge Bot <eric+marge@anholt.net>
Mon, 15 Feb 2021 19:29:09 +0000 (19:29 +0000)
Set the mask (ValidPrimMask) to 0 if draw calls should generate
GL_INVALID_OPERATION. The mask is updated when states are changed.

Reviewed-by: Zoltán Böszörményi <zboszor@gmail.com>
Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8798>

src/mesa/main/arrayobj.c
src/mesa/main/context.c
src/mesa/main/draw_validate.c
src/mesa/main/enable.c
src/mesa/main/fbobject.c
src/mesa/main/framebuffer.c

index 2d1b14b0b882f17517f653127a25d65ab82c70c7..b668fb762df8313be4a9d46cb9f0a23f494324b9 100644 (file)
@@ -47,6 +47,7 @@
 #include "context.h"
 #include "bufferobj.h"
 #include "arrayobj.h"
+#include "draw_validate.h"
 #include "macros.h"
 #include "mtypes.h"
 #include "state.h"
@@ -1010,6 +1011,13 @@ bind_vertex_array(struct gl_context *ctx, GLuint id, bool no_error)
    _mesa_set_draw_vao(ctx, ctx->Array._EmptyVAO, 0);
 
    _mesa_reference_vao(ctx, &ctx->Array.VAO, newObj);
+
+   /* Update the valid-to-render state if binding on unbinding default VAO
+    * if drawing with the default VAO is invalid.
+    */
+   if (ctx->API == API_OPENGL_CORE &&
+       (oldObj == ctx->Array.DefaultVAO) != (newObj == ctx->Array.DefaultVAO))
+      _mesa_update_valid_to_render_state(ctx);
 }
 
 
index c90a9d07561038870eb19beafb9ce46450c3d312..29653bd19a6d035f09e92fb14f90d8f0a865c605 100644 (file)
@@ -93,6 +93,7 @@
 #include "debug_output.h"
 #include "depth.h"
 #include "dlist.h"
+#include "draw_validate.h"
 #include "eval.h"
 #include "extensions.h"
 #include "fbobject.h"
@@ -1745,6 +1746,7 @@ _mesa_make_current( struct gl_context *newCtx,
              */
             _mesa_update_draw_buffers(newCtx);
             _mesa_update_allow_draw_out_of_order(newCtx);
+            _mesa_update_valid_to_render_state(newCtx);
          }
          if (!newCtx->ReadBuffer || _mesa_is_winsys_fbo(newCtx->ReadBuffer)) {
             _mesa_reference_framebuffer(&newCtx->ReadBuffer, readBuffer);
index 7a72508eefaabb19db173ce3919ced409f4f1295..022385a8f972d2fea8cefbc6de03868c9bdad676 100644 (file)
@@ -266,6 +266,32 @@ check_valid_to_render(struct gl_context *ctx, bool uses_vao,
       return false;
    }
 
+   return true;
+}
+
+/**
+ * Compute the bitmask of allowed primitive types (ValidPrimMask) depending
+ * on shaders and current states. This is used by draw validation.
+ *
+ * If some combinations of shaders and states are invalid, ValidPrimMask is
+ * set to 0, which will always set GL_INVALID_OPERATION in draw calls
+ * except for invalid enums, which will set GL_INVALID_ENUM, minimizing
+ * the number of gl_context variables that have to be read by draw calls.
+ */
+void
+_mesa_update_valid_to_render_state(struct gl_context *ctx)
+{
+   struct gl_pipeline_object *shader = ctx->_Shader;
+   unsigned mask = ctx->SupportedPrimMask;
+
+   if (_mesa_is_no_error_enabled(ctx)) {
+      ctx->ValidPrimMask = mask;
+      return;
+   }
+
+   /* Start with an empty mask and set this to the trimmed mask at the end. */
+   ctx->ValidPrimMask = 0;
+
    /* Section 11.2 (Tessellation) of the ES 3.2 spec says:
     *
     * "An INVALID_OPERATION error is generated by any command that
@@ -286,11 +312,9 @@ check_valid_to_render(struct gl_context *ctx, bool uses_vao,
     * Also, all vendors except one don't support a tess ctrl shader without
     * a tess eval shader anyway.
     */
-   if (ctx->TessCtrlProgram._Current && !ctx->TessEvalProgram._Current) {
-      _mesa_error(ctx, GL_INVALID_OPERATION,
-                  "%s(tess eval shader is missing)", function);
-      return false;
-   }
+   if (shader->CurrentProgram[MESA_SHADER_TESS_CTRL] &&
+       !shader->CurrentProgram[MESA_SHADER_TESS_EVAL])
+      return;
 
    switch (ctx->API) {
    case API_OPENGLES2:
@@ -302,11 +326,9 @@ check_valid_to_render(struct gl_context *ctx, bool uses_vao,
        *  evaluation shader."
        */
       if (_mesa_is_gles3(ctx) &&
-          ctx->TessEvalProgram._Current && !ctx->TessCtrlProgram._Current) {
-         _mesa_error(ctx, GL_INVALID_OPERATION,
-                     "%s(tess ctrl shader is missing)", function);
-         return false;
-      }
+          shader->CurrentProgram[MESA_SHADER_TESS_EVAL] &&
+          !shader->CurrentProgram[MESA_SHADER_TESS_CTRL])
+         return;
 
       /* From GL_EXT_color_buffer_float:
        *
@@ -321,11 +343,8 @@ check_valid_to_render(struct gl_context *ctx, bool uses_vao,
        * However GL_EXT_float_blend removes this text.
        */
       if (!ctx->Extensions.EXT_float_blend &&
-          (ctx->DrawBuffer->_FP32Buffers & ctx->Color.BlendEnabled)) {
-         _mesa_error(ctx, GL_INVALID_OPERATION,
-                     "%s(32-bit float output + blending)", function);
-         return false;
-      }
+          (ctx->DrawBuffer->_FP32Buffers & ctx->Color.BlendEnabled))
+         return;
       break;
 
    case API_OPENGL_CORE:
@@ -335,10 +354,8 @@ check_valid_to_render(struct gl_context *ctx, bool uses_vao,
        *     "An INVALID_OPERATION error is generated if no vertex array
        *     object is bound (see section 10.3.1)."
        */
-      if (ctx->Array.VAO == ctx->Array.DefaultVAO) {
-         _mesa_error(ctx, GL_INVALID_OPERATION, "%s(no VAO bound)", function);
-         return false;
-      }
+      if (ctx->Array.VAO == ctx->Array.DefaultVAO)
+         return;
       break;
 
    case API_OPENGLES:
@@ -346,35 +363,9 @@ check_valid_to_render(struct gl_context *ctx, bool uses_vao,
       break;
 
    default:
-      unreachable("Invalid API value in check_valid_to_render()");
+      unreachable("Invalid API value in _mesa_update_valid_to_render_state");
    }
 
-   return true;
-}
-
-/**
- * Compute the bitmask of allowed primitive types (ValidPrimMask) depending
- * on shaders and current states. This is used by draw validation.
- *
- * If some combinations of shaders and states are invalid, ValidPrimMask is
- * set to 0, which will always set GL_INVALID_OPERATION in draw calls
- * except for invalid enums, which will set GL_INVALID_ENUM, minimizing
- * the number of gl_context variables that have to be read by draw calls.
- */
-void
-_mesa_update_valid_to_render_state(struct gl_context *ctx)
-{
-   struct gl_pipeline_object *shader = ctx->_Shader;
-   unsigned mask = ctx->SupportedPrimMask;
-
-   if (_mesa_is_no_error_enabled(ctx)) {
-      ctx->ValidPrimMask = mask;
-      return;
-   }
-
-   /* Start with an empty mask and set this to the trimmed mask at the end. */
-   ctx->ValidPrimMask = 0;
-
    /* From GL_INTEL_conservative_rasterization spec:
     *
     * The conservative rasterization option applies only to polygons with
index fa0c86acd2ca6a5e5c89c50e02161ced0b5046d5..04831dd51250e6c92c22a682ed014dfebe63e948 100644 (file)
@@ -440,6 +440,7 @@ _mesa_set_enable(struct gl_context *ctx, GLenum cap, GLboolean state)
                ctx->PopAttribState |= GL_ENABLE_BIT;
                ctx->Color.BlendEnabled = newEnabled;
                _mesa_update_allow_draw_out_of_order(ctx);
+               _mesa_update_valid_to_render_state(ctx);
             }
          }
          break;
@@ -1403,6 +1404,7 @@ _mesa_set_enablei(struct gl_context *ctx, GLenum cap,
          ctx->PopAttribState |= GL_ENABLE_BIT;
          ctx->Color.BlendEnabled = enabled;
          _mesa_update_allow_draw_out_of_order(ctx);
+         _mesa_update_valid_to_render_state(ctx);
       }
       break;
    case GL_SCISSOR_TEST:
index a1a084d1f77b5b787f57f02598890ad8765fcd4b..1fb76e52f221253cd5cfb732524742981eaf101b 100644 (file)
@@ -36,6 +36,7 @@
 #include "buffers.h"
 #include "context.h"
 #include "debug_output.h"
+#include "draw_validate.h"
 #include "enums.h"
 #include "fbobject.h"
 #include "formats.h"
@@ -3137,6 +3138,7 @@ _mesa_bind_framebuffers(struct gl_context *ctx,
 
       _mesa_reference_framebuffer(&ctx->DrawBuffer, newDrawFb);
       _mesa_update_allow_draw_out_of_order(ctx);
+      _mesa_update_valid_to_render_state(ctx);
    }
 
    if ((bindDrawBuf || bindReadBuf) && ctx->Driver.BindFramebuffer) {
index 5311d117673878f50fc6471d66adaf951f4c74cc..a50d0febe7edead0b17ee31b3855292a2969f17d 100644 (file)
@@ -35,6 +35,7 @@
 #include "blend.h"
 #include "buffers.h"
 #include "context.h"
+#include "draw_validate.h"
 #include "enums.h"
 #include "formats.h"
 #include "macros.h"
@@ -504,6 +505,7 @@ _mesa_update_framebuffer_visual(struct gl_context *ctx,
 
    compute_depth_max(fb);
    _mesa_update_allow_draw_out_of_order(ctx);
+   _mesa_update_valid_to_render_state(ctx);
 }