From dfd1080f9db7502b05c3f5841ebad1c9eea2a857 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Sat, 16 Jan 2021 11:30:44 -0500 Subject: [PATCH] mesa: fold most of check_valid_to_render into _mesa_update_valid_to_render_state MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Pierre-Eric Pelloux-Prayer Part-of: --- src/mesa/main/arrayobj.c | 8 ++++ src/mesa/main/context.c | 2 + src/mesa/main/draw_validate.c | 83 ++++++++++++++++------------------- src/mesa/main/enable.c | 2 + src/mesa/main/fbobject.c | 2 + src/mesa/main/framebuffer.c | 2 + 6 files changed, 53 insertions(+), 46 deletions(-) diff --git a/src/mesa/main/arrayobj.c b/src/mesa/main/arrayobj.c index 2d1b14b0b88..b668fb762df 100644 --- a/src/mesa/main/arrayobj.c +++ b/src/mesa/main/arrayobj.c @@ -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); } diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c index c90a9d07561..29653bd19a6 100644 --- a/src/mesa/main/context.c +++ b/src/mesa/main/context.c @@ -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); diff --git a/src/mesa/main/draw_validate.c b/src/mesa/main/draw_validate.c index 7a72508eefa..022385a8f97 100644 --- a/src/mesa/main/draw_validate.c +++ b/src/mesa/main/draw_validate.c @@ -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 diff --git a/src/mesa/main/enable.c b/src/mesa/main/enable.c index fa0c86acd2c..04831dd5125 100644 --- a/src/mesa/main/enable.c +++ b/src/mesa/main/enable.c @@ -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: diff --git a/src/mesa/main/fbobject.c b/src/mesa/main/fbobject.c index a1a084d1f77..1fb76e52f22 100644 --- a/src/mesa/main/fbobject.c +++ b/src/mesa/main/fbobject.c @@ -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) { diff --git a/src/mesa/main/framebuffer.c b/src/mesa/main/framebuffer.c index 5311d117673..a50d0febe7e 100644 --- a/src/mesa/main/framebuffer.c +++ b/src/mesa/main/framebuffer.c @@ -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); } -- 2.34.1