From 1ac4439d6278e6c5f9da5499bbc50362f0c6759b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Mathias=20Fr=C3=B6hlich?= Date: Fri, 1 Jun 2018 19:10:08 +0200 Subject: [PATCH] mesa: Make sure that imm draws are flushed before other draws execute. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The recent patch mesa: Remove FLUSH_VERTICES from VAO state changes. Pending draw calls on immediate mode or display list calls do not depend on changes of the VAO state. So, remove calls to FLUSH_VERTICES and flag _NEW_ARRAY as appropriate. uncovered a problem that non immediate mode draw calls do only flush outstanding immediate mode draws if FLUSH_UPDATE_CURRENT is set in ctx->Driver.NeedFlush. In that case, due to the sequence of _mesa_set_draw_vao commands we could end up with the VAO from the FLUSH_VERTICES call set into gl_context::Array._DrawVAO when the array draw is executed. So the change pulls FLUSH_CURRENT out of _mesa_validate_* calls into the array draw calls being validated. The change introduces a new macro FLUSH_FOR_DRAW beside FLUSH_VERTICES and FLUSH_CURRENT that flushes on changed current attributes as well as on outstanding immediate mode draw calls. Use FLUSH_FOR_DRAW in the non immediate mode draw code paths. Reviewed-by: Marek Olšák Tested-by: Kai Wasserbäch Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=106594 Signed-off-by: Mathias Fröhlich --- src/mesa/main/context.h | 16 ++++++++ src/mesa/main/draw_validate.c | 26 ------------ src/mesa/vbo/vbo_exec_array.c | 77 ++++++++++++++++++----------------- src/mesa/vbo/vbo_save_draw.c | 2 +- 4 files changed, 56 insertions(+), 65 deletions(-) diff --git a/src/mesa/main/context.h b/src/mesa/main/context.h index 77520f678ff..d50438fd7f9 100644 --- a/src/mesa/main/context.h +++ b/src/mesa/main/context.h @@ -232,6 +232,22 @@ do { \ ctx->NewState |= newstate; \ } while (0) +/** + * Flush vertices. + * + * \param ctx GL context. + * + * Checks if dd_function_table::NeedFlush is marked to flush stored vertices + * or current state and calls dd_function_table::FlushVertices if so. + */ +#define FLUSH_FOR_DRAW(ctx) \ +do { \ + if (MESA_VERBOSE & VERBOSE_STATE) \ + _mesa_debug(ctx, "FLUSH_FOR_DRAW in %s\n", __func__); \ + if (ctx->Driver.NeedFlush) \ + vbo_exec_FlushVertices(ctx, ctx->Driver.NeedFlush); \ +} while (0) + /** * Macro to assert that the API call was made outside the * glBegin()/glEnd() pair, with return value. diff --git a/src/mesa/main/draw_validate.c b/src/mesa/main/draw_validate.c index bcb2d91306e..352263c5c78 100644 --- a/src/mesa/main/draw_validate.c +++ b/src/mesa/main/draw_validate.c @@ -696,8 +696,6 @@ _mesa_validate_DrawElements(struct gl_context *ctx, GLenum mode, GLsizei count, GLenum type, const GLvoid *indices) { - FLUSH_CURRENT(ctx, 0); - return validate_DrawElements_common(ctx, mode, count, type, indices, "glDrawElements"); } @@ -716,8 +714,6 @@ _mesa_validate_MultiDrawElements(struct gl_context *ctx, { GLsizei i; - FLUSH_CURRENT(ctx, 0); - /* * Section 2.3.1 (Errors) of the OpenGL 4.5 (Core Profile) spec says: * @@ -780,8 +776,6 @@ _mesa_validate_DrawRangeElements(struct gl_context *ctx, GLenum mode, GLsizei count, GLenum type, const GLvoid *indices) { - FLUSH_CURRENT(ctx, 0); - if (end < start) { _mesa_error(ctx, GL_INVALID_VALUE, "glDrawRangeElements(endArray.VAO, enabled_filter(ctx)); if (ctx->NewState) @@ -568,10 +568,9 @@ vbo_exec_DrawArraysInstanced(GLenum mode, GLint start, GLsizei count, _mesa_debug(ctx, "glDrawArraysInstanced(%s, %d, %d, %d)\n", _mesa_enum_to_string(mode), start, count, numInstances); + FLUSH_FOR_DRAW(ctx); if (_mesa_is_no_error_enabled(ctx)) { - FLUSH_CURRENT(ctx, 0); - _mesa_set_draw_vao(ctx, ctx->Array.VAO, enabled_filter(ctx)); if (ctx->NewState) @@ -610,9 +609,9 @@ vbo_exec_DrawArraysInstancedBaseInstance(GLenum mode, GLint first, _mesa_enum_to_string(mode), first, count, numInstances, baseInstance); - if (_mesa_is_no_error_enabled(ctx)) { - FLUSH_CURRENT(ctx, 0); + FLUSH_FOR_DRAW(ctx); + if (_mesa_is_no_error_enabled(ctx)) { _mesa_set_draw_vao(ctx, ctx->Array.VAO, enabled_filter(ctx)); if (ctx->NewState) @@ -650,9 +649,9 @@ vbo_exec_MultiDrawArrays(GLenum mode, const GLint *first, "glMultiDrawArrays(%s, %p, %p, %d)\n", _mesa_enum_to_string(mode), first, count, primcount); - if (_mesa_is_no_error_enabled(ctx)) { - FLUSH_CURRENT(ctx, 0); + FLUSH_FOR_DRAW(ctx); + if (_mesa_is_no_error_enabled(ctx)) { _mesa_set_draw_vao(ctx, ctx->Array.VAO, enabled_filter(ctx)); if (ctx->NewState) @@ -873,9 +872,9 @@ vbo_exec_DrawRangeElementsBaseVertex(GLenum mode, GLuint start, GLuint end, _mesa_enum_to_string(mode), start, end, count, _mesa_enum_to_string(type), indices, basevertex); - if (_mesa_is_no_error_enabled(ctx)) { - FLUSH_CURRENT(ctx, 0); + FLUSH_FOR_DRAW(ctx); + if (_mesa_is_no_error_enabled(ctx)) { _mesa_set_draw_vao(ctx, ctx->Array.VAO, enabled_filter(ctx)); if (ctx->NewState) @@ -984,9 +983,9 @@ vbo_exec_DrawElements(GLenum mode, GLsizei count, GLenum type, _mesa_enum_to_string(mode), count, _mesa_enum_to_string(type), indices); - if (_mesa_is_no_error_enabled(ctx)) { - FLUSH_CURRENT(ctx, 0); + FLUSH_FOR_DRAW(ctx); + if (_mesa_is_no_error_enabled(ctx)) { _mesa_set_draw_vao(ctx, ctx->Array.VAO, enabled_filter(ctx)); if (ctx->NewState) @@ -1017,9 +1016,9 @@ vbo_exec_DrawElementsBaseVertex(GLenum mode, GLsizei count, GLenum type, _mesa_enum_to_string(mode), count, _mesa_enum_to_string(type), indices); - if (_mesa_is_no_error_enabled(ctx)) { - FLUSH_CURRENT(ctx, 0); + FLUSH_FOR_DRAW(ctx); + if (_mesa_is_no_error_enabled(ctx)) { _mesa_set_draw_vao(ctx, ctx->Array.VAO, enabled_filter(ctx)); if (ctx->NewState) @@ -1050,9 +1049,9 @@ vbo_exec_DrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, _mesa_enum_to_string(mode), count, _mesa_enum_to_string(type), indices); - if (_mesa_is_no_error_enabled(ctx)) { - FLUSH_CURRENT(ctx, 0); + FLUSH_FOR_DRAW(ctx); + if (_mesa_is_no_error_enabled(ctx)) { _mesa_set_draw_vao(ctx, ctx->Array.VAO, enabled_filter(ctx)); if (ctx->NewState) @@ -1089,9 +1088,9 @@ vbo_exec_DrawElementsInstancedBaseVertex(GLenum mode, GLsizei count, _mesa_enum_to_string(type), indices, numInstances, basevertex); - if (_mesa_is_no_error_enabled(ctx)) { - FLUSH_CURRENT(ctx, 0); + FLUSH_FOR_DRAW(ctx); + if (_mesa_is_no_error_enabled(ctx)) { _mesa_set_draw_vao(ctx, ctx->Array.VAO, enabled_filter(ctx)); if (ctx->NewState) @@ -1130,9 +1129,9 @@ vbo_exec_DrawElementsInstancedBaseInstance(GLenum mode, GLsizei count, _mesa_enum_to_string(type), indices, numInstances, baseInstance); - if (_mesa_is_no_error_enabled(ctx)) { - FLUSH_CURRENT(ctx, 0); + FLUSH_FOR_DRAW(ctx); + if (_mesa_is_no_error_enabled(ctx)) { _mesa_set_draw_vao(ctx, ctx->Array.VAO, enabled_filter(ctx)); if (ctx->NewState) @@ -1173,9 +1172,9 @@ vbo_exec_DrawElementsInstancedBaseVertexBaseInstance(GLenum mode, _mesa_enum_to_string(type), indices, numInstances, basevertex, baseInstance); - if (_mesa_is_no_error_enabled(ctx)) { - FLUSH_CURRENT(ctx, 0); + FLUSH_FOR_DRAW(ctx); + if (_mesa_is_no_error_enabled(ctx)) { _mesa_set_draw_vao(ctx, ctx->Array.VAO, enabled_filter(ctx)); if (ctx->NewState) @@ -1337,6 +1336,8 @@ vbo_exec_MultiDrawElements(GLenum mode, { GET_CURRENT_CONTEXT(ctx); + FLUSH_FOR_DRAW(ctx); + _mesa_set_draw_vao(ctx, ctx->Array.VAO, enabled_filter(ctx)); if (!_mesa_validate_MultiDrawElements(ctx, mode, count, type, indices, @@ -1360,9 +1361,9 @@ vbo_exec_MultiDrawElementsBaseVertex(GLenum mode, { GET_CURRENT_CONTEXT(ctx); - if (_mesa_is_no_error_enabled(ctx)) { - FLUSH_CURRENT(ctx, 0); + FLUSH_FOR_DRAW(ctx); + if (_mesa_is_no_error_enabled(ctx)) { _mesa_set_draw_vao(ctx, ctx->Array.VAO, enabled_filter(ctx)); if (ctx->NewState) @@ -1398,9 +1399,9 @@ vbo_draw_transform_feedback(struct gl_context *ctx, GLenum mode, { struct _mesa_prim prim; - if (_mesa_is_no_error_enabled(ctx)) { - FLUSH_CURRENT(ctx, 0); + FLUSH_FOR_DRAW(ctx); + if (_mesa_is_no_error_enabled(ctx)) { _mesa_set_draw_vao(ctx, ctx->Array.VAO, enabled_filter(ctx)); if (ctx->NewState) @@ -1615,9 +1616,9 @@ vbo_exec_DrawArraysIndirect(GLenum mode, const GLvoid *indirect) _mesa_debug(ctx, "glDrawArraysIndirect(%s, %p)\n", _mesa_enum_to_string(mode), indirect); - if (_mesa_is_no_error_enabled(ctx)) { - FLUSH_CURRENT(ctx, 0); + FLUSH_FOR_DRAW(ctx); + if (_mesa_is_no_error_enabled(ctx)) { _mesa_set_draw_vao(ctx, ctx->Array.VAO, enabled_filter(ctx)); if (ctx->NewState) @@ -1646,9 +1647,9 @@ vbo_exec_DrawElementsIndirect(GLenum mode, GLenum type, const GLvoid *indirect) _mesa_enum_to_string(mode), _mesa_enum_to_string(type), indirect); - if (_mesa_is_no_error_enabled(ctx)) { - FLUSH_CURRENT(ctx, 0); + FLUSH_FOR_DRAW(ctx); + if (_mesa_is_no_error_enabled(ctx)) { _mesa_set_draw_vao(ctx, ctx->Array.VAO, enabled_filter(ctx)); if (ctx->NewState) @@ -1681,9 +1682,9 @@ vbo_exec_MultiDrawArraysIndirect(GLenum mode, const GLvoid *indirect, if (stride == 0) stride = 4 * sizeof(GLuint); /* sizeof(DrawArraysIndirectCommand) */ - if (_mesa_is_no_error_enabled(ctx)) { - FLUSH_CURRENT(ctx, 0); + FLUSH_FOR_DRAW(ctx); + if (_mesa_is_no_error_enabled(ctx)) { _mesa_set_draw_vao(ctx, ctx->Array.VAO, enabled_filter(ctx)); if (ctx->NewState) @@ -1720,9 +1721,9 @@ vbo_exec_MultiDrawElementsIndirect(GLenum mode, GLenum type, if (stride == 0) stride = 5 * sizeof(GLuint); /* sizeof(DrawElementsIndirectCommand) */ - if (_mesa_is_no_error_enabled(ctx)) { - FLUSH_CURRENT(ctx, 0); + FLUSH_FOR_DRAW(ctx); + if (_mesa_is_no_error_enabled(ctx)) { _mesa_set_draw_vao(ctx, ctx->Array.VAO, enabled_filter(ctx)); if (ctx->NewState) @@ -1815,9 +1816,9 @@ vbo_exec_MultiDrawArraysIndirectCount(GLenum mode, GLintptr indirect, if (stride == 0) stride = 4 * sizeof(GLuint); /* sizeof(DrawArraysIndirectCommand) */ - if (_mesa_is_no_error_enabled(ctx)) { - FLUSH_CURRENT(ctx, 0); + FLUSH_FOR_DRAW(ctx); + if (_mesa_is_no_error_enabled(ctx)) { _mesa_set_draw_vao(ctx, ctx->Array.VAO, enabled_filter(ctx)); if (ctx->NewState) @@ -1860,9 +1861,9 @@ vbo_exec_MultiDrawElementsIndirectCount(GLenum mode, GLenum type, if (stride == 0) stride = 5 * sizeof(GLuint); /* sizeof(DrawElementsIndirectCommand) */ - if (_mesa_is_no_error_enabled(ctx)) { - FLUSH_CURRENT(ctx, 0); + FLUSH_FOR_DRAW(ctx); + if (_mesa_is_no_error_enabled(ctx)) { _mesa_set_draw_vao(ctx, ctx->Array.VAO, enabled_filter(ctx)); if (ctx->NewState) diff --git a/src/mesa/vbo/vbo_save_draw.c b/src/mesa/vbo/vbo_save_draw.c index f4b2c807480..71620e9a3cd 100644 --- a/src/mesa/vbo/vbo_save_draw.c +++ b/src/mesa/vbo/vbo_save_draw.c @@ -168,7 +168,7 @@ vbo_save_playback_vertex_list(struct gl_context *ctx, void *data) remap_vertex_store = GL_TRUE; } - FLUSH_CURRENT(ctx, 0); + FLUSH_FOR_DRAW(ctx); if (node->prim_count > 0) { -- 2.30.2