mesa: remove redudant check
[mesa.git] / src / mesa / main / compute.c
index e881d4f5a393a81f1da337cd67bf58670343b2ed..013d6a68567f65ce4a0b7cd52447b4fdfa3f20f0 100644 (file)
@@ -54,8 +54,6 @@ check_valid_to_compute(struct gl_context *ctx, const char *function)
 static bool
 validate_DispatchCompute(struct gl_context *ctx, const GLuint *num_groups)
 {
-   FLUSH_CURRENT(ctx, 0);
-
    if (!check_valid_to_compute(ctx, "glDispatchCompute"))
       return GL_FALSE;
 
@@ -105,10 +103,6 @@ validate_DispatchComputeGroupSizeARB(struct gl_context *ctx,
                                      const GLuint *num_groups,
                                      const GLuint *group_size)
 {
-   GLuint total_invocations = 1;
-
-   FLUSH_CURRENT(ctx, 0);
-
    if (!check_valid_to_compute(ctx, "glDispatchComputeGroupSizeARB"))
       return GL_FALSE;
 
@@ -157,8 +151,6 @@ validate_DispatchComputeGroupSizeARB(struct gl_context *ctx,
                      "glDispatchComputeGroupSizeARB(group_size_%c)", 'x' + i);
          return GL_FALSE;
       }
-
-      total_invocations *= group_size[i];
    }
 
    /* The ARB_compute_variable_group_size spec says:
@@ -169,11 +161,19 @@ validate_DispatchComputeGroupSizeARB(struct gl_context *ctx,
     *  for compute shaders with variable group size
     *  (MAX_COMPUTE_VARIABLE_GROUP_INVOCATIONS_ARB)."
     */
+   uint64_t total_invocations = group_size[0] * group_size[1];
+   if (total_invocations <= UINT32_MAX) {
+      /* Only bother multiplying the third value if total still fits in
+       * 32-bit, since MaxComputeVariableGroupInvocations is also 32-bit.
+       */
+      total_invocations *= group_size[2];
+   }
    if (total_invocations > ctx->Const.MaxComputeVariableGroupInvocations) {
       _mesa_error(ctx, GL_INVALID_VALUE,
                   "glDispatchComputeGroupSizeARB(product of local_sizes "
                   "exceeds MAX_COMPUTE_VARIABLE_GROUP_INVOCATIONS_ARB "
-                  "(%d > %d))", total_invocations,
+                  "(%u * %u * %u > %u))",
+                  group_size[0], group_size[1], group_size[2],
                   ctx->Const.MaxComputeVariableGroupInvocations);
       return GL_FALSE;
    }
@@ -184,8 +184,6 @@ validate_DispatchComputeGroupSizeARB(struct gl_context *ctx,
 static bool
 valid_dispatch_indirect(struct gl_context *ctx,  GLintptr indirect)
 {
-   FLUSH_CURRENT(ctx, 0);
-
    GLsizei size = 3 * sizeof(GLuint);
    const uint64_t end = (uint64_t) indirect + size;
    const char *name = "glDispatchComputeIndirect";
@@ -216,7 +214,7 @@ valid_dispatch_indirect(struct gl_context *ctx,  GLintptr indirect)
     *  DRAW_INDIRECT_BUFFER binding, or if the command would source data
     *  beyond the end of the buffer object."
     */
-   if (!_mesa_is_bufferobj(ctx->DispatchIndirectBuffer)) {
+   if (!ctx->DispatchIndirectBuffer) {
       _mesa_error(ctx, GL_INVALID_OPERATION,
                   "%s: no buffer bound to DISPATCH_INDIRECT_BUFFER", name);
       return GL_FALSE;
@@ -249,19 +247,20 @@ valid_dispatch_indirect(struct gl_context *ctx,  GLintptr indirect)
    return GL_TRUE;
 }
 
-void GLAPIENTRY
-_mesa_DispatchCompute(GLuint num_groups_x,
-                      GLuint num_groups_y,
-                      GLuint num_groups_z)
+static ALWAYS_INLINE void
+dispatch_compute(GLuint num_groups_x, GLuint num_groups_y,
+                 GLuint num_groups_z, bool no_error)
 {
    GET_CURRENT_CONTEXT(ctx);
    const GLuint num_groups[3] = { num_groups_x, num_groups_y, num_groups_z };
 
+   FLUSH_VERTICES(ctx, 0);
+
    if (MESA_VERBOSE & VERBOSE_API)
       _mesa_debug(ctx, "glDispatchCompute(%d, %d, %d)\n",
                   num_groups_x, num_groups_y, num_groups_z);
 
-   if (!validate_DispatchCompute(ctx, num_groups))
+   if (!no_error && !validate_DispatchCompute(ctx, num_groups))
       return;
 
    if (num_groups_x == 0u || num_groups_y == 0u || num_groups_z == 0u)
@@ -270,36 +269,69 @@ _mesa_DispatchCompute(GLuint num_groups_x,
    ctx->Driver.DispatchCompute(ctx, num_groups);
 }
 
-extern void GLAPIENTRY
-_mesa_DispatchComputeIndirect(GLintptr indirect)
+void GLAPIENTRY
+_mesa_DispatchCompute_no_error(GLuint num_groups_x, GLuint num_groups_y,
+                               GLuint num_groups_z)
+{
+   dispatch_compute(num_groups_x, num_groups_y, num_groups_z, true);
+}
+
+void GLAPIENTRY
+_mesa_DispatchCompute(GLuint num_groups_x,
+                      GLuint num_groups_y,
+                      GLuint num_groups_z)
+{
+   dispatch_compute(num_groups_x, num_groups_y, num_groups_z, false);
+}
+
+static ALWAYS_INLINE void
+dispatch_compute_indirect(GLintptr indirect, bool no_error)
 {
    GET_CURRENT_CONTEXT(ctx);
 
+   FLUSH_VERTICES(ctx, 0);
+
    if (MESA_VERBOSE & VERBOSE_API)
       _mesa_debug(ctx, "glDispatchComputeIndirect(%ld)\n", (long) indirect);
 
-   if (!valid_dispatch_indirect(ctx, indirect))
+   if (!no_error && !valid_dispatch_indirect(ctx, indirect))
       return;
 
    ctx->Driver.DispatchComputeIndirect(ctx, indirect);
 }
 
-void GLAPIENTRY
-_mesa_DispatchComputeGroupSizeARB(GLuint num_groups_x, GLuint num_groups_y,
-                                  GLuint num_groups_z, GLuint group_size_x,
-                                  GLuint group_size_y, GLuint group_size_z)
+extern void GLAPIENTRY
+_mesa_DispatchComputeIndirect_no_error(GLintptr indirect)
+{
+   dispatch_compute_indirect(indirect, true);
+}
+
+extern void GLAPIENTRY
+_mesa_DispatchComputeIndirect(GLintptr indirect)
+{
+   dispatch_compute_indirect(indirect, false);
+}
+
+static ALWAYS_INLINE void
+dispatch_compute_group_size(GLuint num_groups_x, GLuint num_groups_y,
+                            GLuint num_groups_z, GLuint group_size_x,
+                            GLuint group_size_y, GLuint group_size_z,
+                            bool no_error)
 {
    GET_CURRENT_CONTEXT(ctx);
    const GLuint num_groups[3] = { num_groups_x, num_groups_y, num_groups_z };
    const GLuint group_size[3] = { group_size_x, group_size_y, group_size_z };
 
+   FLUSH_VERTICES(ctx, 0);
+
    if (MESA_VERBOSE & VERBOSE_API)
       _mesa_debug(ctx,
                   "glDispatchComputeGroupSizeARB(%d, %d, %d, %d, %d, %d)\n",
                   num_groups_x, num_groups_y, num_groups_z,
                   group_size_x, group_size_y, group_size_z);
 
-   if (!validate_DispatchComputeGroupSizeARB(ctx, num_groups, group_size))
+   if (!no_error &&
+       !validate_DispatchComputeGroupSizeARB(ctx, num_groups, group_size))
       return;
 
    if (num_groups_x == 0u || num_groups_y == 0u || num_groups_z == 0u)
@@ -307,3 +339,26 @@ _mesa_DispatchComputeGroupSizeARB(GLuint num_groups_x, GLuint num_groups_y,
 
    ctx->Driver.DispatchComputeGroupSize(ctx, num_groups, group_size);
 }
+
+void GLAPIENTRY
+_mesa_DispatchComputeGroupSizeARB_no_error(GLuint num_groups_x,
+                                           GLuint num_groups_y,
+                                           GLuint num_groups_z,
+                                           GLuint group_size_x,
+                                           GLuint group_size_y,
+                                           GLuint group_size_z)
+{
+   dispatch_compute_group_size(num_groups_x, num_groups_y, num_groups_z,
+                               group_size_x, group_size_y, group_size_z,
+                               true);
+}
+
+void GLAPIENTRY
+_mesa_DispatchComputeGroupSizeARB(GLuint num_groups_x, GLuint num_groups_y,
+                                  GLuint num_groups_z, GLuint group_size_x,
+                                  GLuint group_size_y, GLuint group_size_z)
+{
+   dispatch_compute_group_size(num_groups_x, num_groups_y, num_groups_z,
+                               group_size_x, group_size_y, group_size_z,
+                               false);
+}