[Mesa-dev] [PATCH 1/4] mesa/cs: Add _mesa_validate_DispatchCompute
Tapani Pälli
tapani.palli at intel.com
Sun Sep 20 22:23:36 PDT 2015
Reviewed-by: Tapani Pälli <tapani.palli at intel.com>
On 09/20/2015 01:50 AM, Jordan Justen wrote:
> Move API validation to _mesa_validate_DispatchCompute in
> api_validate.c.
>
> Signed-off-by: Jordan Justen <jordan.l.justen at intel.com>
> ---
> src/mesa/main/api_validate.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
> src/mesa/main/api_validate.h | 4 ++++
> src/mesa/main/compute.c | 28 +++++-----------------------
> 3 files changed, 53 insertions(+), 23 deletions(-)
>
> diff --git a/src/mesa/main/api_validate.c b/src/mesa/main/api_validate.c
> index 53c8fb8..b46226a 100644
> --- a/src/mesa/main/api_validate.c
> +++ b/src/mesa/main/api_validate.c
> @@ -882,3 +882,47 @@ _mesa_validate_MultiDrawElementsIndirect(struct gl_context *ctx,
>
> return GL_TRUE;
> }
> +
> +static bool
> +check_valid_to_compute(struct gl_context *ctx, const char *function)
> +{
> + struct gl_shader_program *prog;
> +
> + if (!_mesa_has_compute_shaders(ctx)) {
> + _mesa_error(ctx, GL_INVALID_OPERATION,
> + "unsupported function (%s) called",
> + function);
> + return false;
> + }
> +
> + prog = ctx->Shader.CurrentProgram[MESA_SHADER_COMPUTE];
> + if (prog == NULL || prog->_LinkedShaders[MESA_SHADER_COMPUTE] == NULL) {
> + _mesa_error(ctx, GL_INVALID_OPERATION,
> + "%s(no active compute shader)",
> + function);
> + return false;
> + }
> +
> + return true;
> +}
> +
> +GLboolean
> +_mesa_validate_DispatchCompute(struct gl_context *ctx,
> + const GLuint *num_groups)
> +{
> + int i;
> + FLUSH_CURRENT(ctx, 0);
> +
> + if (!check_valid_to_compute(ctx, "glDispatchCompute"))
> + return GL_FALSE;
> +
> + for (i = 0; i < 3; i++) {
> + if (num_groups[i] > ctx->Const.MaxComputeWorkGroupCount[i]) {
> + _mesa_error(ctx, GL_INVALID_VALUE,
> + "glDispatchCompute(num_groups_%c)", 'x' + i);
> + return GL_FALSE;
> + }
> + }
> +
> + return GL_TRUE;
> +}
> diff --git a/src/mesa/main/api_validate.h b/src/mesa/main/api_validate.h
> index 0ce7b69..ef2c794 100644
> --- a/src/mesa/main/api_validate.h
> +++ b/src/mesa/main/api_validate.h
> @@ -105,5 +105,9 @@ _mesa_validate_MultiDrawElementsIndirect(struct gl_context *ctx,
> GLsizei primcount,
> GLsizei stride);
>
> +extern GLboolean
> +_mesa_validate_DispatchCompute(struct gl_context *ctx,
> + const GLuint *num_groups);
> +
>
> #endif
> diff --git a/src/mesa/main/compute.c b/src/mesa/main/compute.c
> index 37a4ba7..f67ffbb 100644
> --- a/src/mesa/main/compute.c
> +++ b/src/mesa/main/compute.c
> @@ -24,6 +24,7 @@
> #include "glheader.h"
> #include "compute.h"
> #include "context.h"
> +#include "api_validate.h"
>
> void GLAPIENTRY
> _mesa_DispatchCompute(GLuint num_groups_x,
> @@ -31,31 +32,12 @@ _mesa_DispatchCompute(GLuint num_groups_x,
> GLuint num_groups_z)
> {
> GET_CURRENT_CONTEXT(ctx);
> - int i;
> - struct gl_shader_program *prog;
> const GLuint num_groups[3] = { num_groups_x, num_groups_y, num_groups_z };
>
> - if (ctx->Extensions.ARB_compute_shader) {
> - for (i = 0; i < 3; i++) {
> - if (num_groups[i] > ctx->Const.MaxComputeWorkGroupCount[i]) {
> - _mesa_error(ctx, GL_INVALID_VALUE,
> - "glDispatchCompute(num_groups_%c)", 'x' + i);
> - return;
> - }
> - }
> - if (!_mesa_valid_to_render(ctx, "glDispatchCompute"))
> - return;
> - prog = ctx->Shader.CurrentProgram[MESA_SHADER_COMPUTE];
> - if (prog == NULL || prog->_LinkedShaders[MESA_SHADER_COMPUTE] == NULL) {
> - _mesa_error(ctx, GL_INVALID_OPERATION,
> - "glDispatchCompute(no active compute shader)");
> - return;
> - }
> - ctx->Driver.DispatchCompute(ctx, num_groups);
> - } else {
> - _mesa_error(ctx, GL_INVALID_OPERATION,
> - "unsupported function (glDispatchCompute) called");
> - }
> + if (!_mesa_validate_DispatchCompute(ctx, num_groups))
> + return;
> +
> + ctx->Driver.DispatchCompute(ctx, num_groups);
> }
>
> extern void GLAPIENTRY
>
More information about the mesa-dev
mailing list