[Mesa-dev] [PATCH 11/18] mesa: Share code between _mesa_validate_DrawArrays[_Instanced].
Kenneth Graunke
kenneth at whitecape.org
Mon Aug 1 17:29:38 UTC 2016
Mostly, I want to share the GLES 3 transform feedback handling,
though most of the rest of the code is identical as well.
Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
---
src/mesa/main/api_validate.c | 89 +++++++++++++-------------------------------
1 file changed, 25 insertions(+), 64 deletions(-)
diff --git a/src/mesa/main/api_validate.c b/src/mesa/main/api_validate.c
index 038b5a9..2ee2cd8 100644
--- a/src/mesa/main/api_validate.c
+++ b/src/mesa/main/api_validate.c
@@ -515,30 +515,24 @@ _mesa_validate_DrawRangeElements(struct gl_context *ctx, GLenum mode,
"glDrawRangeElements");
}
-
-/**
- * Called from the tnl module to error check the function parameters and
- * verify that we really can draw something.
- * \return GL_TRUE if OK to render, GL_FALSE if error found
- */
-GLboolean
-_mesa_validate_DrawArrays(struct gl_context *ctx, GLenum mode, GLsizei count)
+static bool
+validate_draw_arrays(struct gl_context *ctx, const char *func,
+ GLenum mode, GLsizei count, GLsizei numInstances)
{
struct gl_transform_feedback_object *xfb_obj
= ctx->TransformFeedback.CurrentObject;
FLUSH_CURRENT(ctx, 0);
if (count < 0) {
- _mesa_error(ctx, GL_INVALID_VALUE, "glDrawArrays(count)" );
- return GL_FALSE;
+ _mesa_error(ctx, GL_INVALID_VALUE, "%s(count)", func);
+ return false;
}
- if (!_mesa_valid_prim_mode(ctx, mode, "glDrawArrays")) {
- return GL_FALSE;
- }
+ if (!_mesa_valid_prim_mode(ctx, mode, func))
+ return false;
- if (!check_valid_to_render(ctx, "glDrawArrays"))
- return GL_FALSE;
+ if (!check_valid_to_render(ctx, func))
+ return false;
/* From the GLES3 specification, section 2.14.2 (Transform Feedback
* Primitive Capture):
@@ -557,16 +551,27 @@ _mesa_validate_DrawArrays(struct gl_context *ctx, GLenum mode, GLsizei count)
size_t prim_count = vbo_count_tessellated_primitives(mode, count, 1);
if (xfb_obj->GlesRemainingPrims < prim_count) {
_mesa_error(ctx, GL_INVALID_OPERATION,
- "glDrawArrays(exceeds transform feedback size)");
- return GL_FALSE;
+ "%s(exceeds transform feedback size)", func);
+ return false;
}
xfb_obj->GlesRemainingPrims -= prim_count;
}
if (count == 0)
- return GL_FALSE;
+ return false;
- return GL_TRUE;
+ return true;
+}
+
+/**
+ * Called from the tnl module to error check the function parameters and
+ * verify that we really can draw something.
+ * \return GL_TRUE if OK to render, GL_FALSE if error found
+ */
+GLboolean
+_mesa_validate_DrawArrays(struct gl_context *ctx, GLenum mode, GLsizei count)
+{
+ return validate_draw_arrays(ctx, "glDrawArrays", mode, count, 1);
}
@@ -574,26 +579,12 @@ GLboolean
_mesa_validate_DrawArraysInstanced(struct gl_context *ctx, GLenum mode, GLint first,
GLsizei count, GLsizei numInstances)
{
- struct gl_transform_feedback_object *xfb_obj
- = ctx->TransformFeedback.CurrentObject;
- FLUSH_CURRENT(ctx, 0);
-
- if (count < 0) {
- _mesa_error(ctx, GL_INVALID_VALUE,
- "glDrawArraysInstanced(count=%d)", count);
- return GL_FALSE;
- }
-
if (first < 0) {
_mesa_error(ctx, GL_INVALID_VALUE,
"glDrawArraysInstanced(start=%d)", first);
return GL_FALSE;
}
- if (!_mesa_valid_prim_mode(ctx, mode, "glDrawArraysInstanced")) {
- return GL_FALSE;
- }
-
if (numInstances <= 0) {
if (numInstances < 0)
_mesa_error(ctx, GL_INVALID_VALUE,
@@ -601,37 +592,7 @@ _mesa_validate_DrawArraysInstanced(struct gl_context *ctx, GLenum mode, GLint fi
return GL_FALSE;
}
- if (!check_valid_to_render(ctx, "glDrawArraysInstanced(invalid to render)"))
- return GL_FALSE;
-
- /* From the GLES3 specification, section 2.14.2 (Transform Feedback
- * Primitive Capture):
- *
- * The error INVALID_OPERATION is generated by DrawArrays and
- * DrawArraysInstanced if recording the vertices of a primitive to the
- * buffer objects being used for transform feedback purposes would result
- * in either exceeding the limits of any buffer object’s size, or in
- * exceeding the end position offset + size − 1, as set by
- * BindBufferRange.
- *
- * This is in contrast to the behaviour of desktop GL, where the extra
- * primitives are silently dropped from the transform feedback buffer.
- */
- if (_mesa_is_gles3(ctx) && _mesa_is_xfb_active_and_unpaused(ctx)) {
- size_t prim_count
- = vbo_count_tessellated_primitives(mode, count, numInstances);
- if (xfb_obj->GlesRemainingPrims < prim_count) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glDrawArraysInstanced(exceeds transform feedback size)");
- return GL_FALSE;
- }
- xfb_obj->GlesRemainingPrims -= prim_count;
- }
-
- if (count == 0)
- return GL_FALSE;
-
- return GL_TRUE;
+ return validate_draw_arrays(ctx, "glDrawArraysInstanced", mode, count, 1);
}
--
2.9.2
More information about the mesa-dev
mailing list