Commit 9efa581d by Jamie Madill

Move more draw call validation to the API.

The GL expects us to reject invalid draw calls before we start doing any work, so we can prevent internal unnecessary state changes. BUG=angle:571 Change-Id: Ic71218b3c2d5dc310280d3738bb1387753a10e03 Reviewed-on: https://chromium-review.googlesource.com/203770Tested-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarShannon Woods <shannonwoods@chromium.org>
parent ac528015
...@@ -1348,6 +1348,11 @@ void Context::setProgramBinary(GLuint program, const void *binary, GLint length) ...@@ -1348,6 +1348,11 @@ void Context::setProgramBinary(GLuint program, const void *binary, GLint length)
} }
GLuint Context::getCurrentProgram() const
{
return mState.currentProgram;
}
void Context::bindTransformFeedback(GLuint transformFeedback) void Context::bindTransformFeedback(GLuint transformFeedback)
{ {
TransformFeedback *transformFeedbackObject = getTransformFeedback(transformFeedback); TransformFeedback *transformFeedbackObject = getTransformFeedback(transformFeedback);
...@@ -1491,7 +1496,7 @@ Buffer *Context::getElementArrayBuffer() const ...@@ -1491,7 +1496,7 @@ Buffer *Context::getElementArrayBuffer() const
return getCurrentVertexArray()->getElementArrayBuffer(); return getCurrentVertexArray()->getElementArrayBuffer();
} }
ProgramBinary *Context::getCurrentProgramBinary() ProgramBinary *Context::getCurrentProgramBinary() const
{ {
return mCurrentProgramBinary.get(); return mCurrentProgramBinary.get();
} }
...@@ -2846,10 +2851,7 @@ void Context::readPixels(GLint x, GLint y, GLsizei width, GLsizei height, ...@@ -2846,10 +2851,7 @@ void Context::readPixels(GLint x, GLint y, GLsizei width, GLsizei height,
void Context::drawArrays(GLenum mode, GLint first, GLsizei count, GLsizei instances) void Context::drawArrays(GLenum mode, GLint first, GLsizei count, GLsizei instances)
{ {
if (!mState.currentProgram) ASSERT(mState.currentProgram);
{
return gl::error(GL_INVALID_OPERATION);
}
ProgramBinary *programBinary = getCurrentProgramBinary(); ProgramBinary *programBinary = getCurrentProgramBinary();
programBinary->applyUniforms(); programBinary->applyUniforms();
...@@ -2900,11 +2902,6 @@ void Context::drawArrays(GLenum mode, GLint first, GLsizei count, GLsizei instan ...@@ -2900,11 +2902,6 @@ void Context::drawArrays(GLenum mode, GLint first, GLsizei count, GLsizei instan
return; return;
} }
if (!programBinary->validateSamplers(NULL))
{
return gl::error(GL_INVALID_OPERATION);
}
if (!skipDraw(mode)) if (!skipDraw(mode))
{ {
mRenderer->drawArrays(mode, count, instances, transformFeedbackActive); mRenderer->drawArrays(mode, count, instances, transformFeedbackActive);
...@@ -2918,16 +2915,7 @@ void Context::drawArrays(GLenum mode, GLint first, GLsizei count, GLsizei instan ...@@ -2918,16 +2915,7 @@ void Context::drawArrays(GLenum mode, GLint first, GLsizei count, GLsizei instan
void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei instances) void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei instances)
{ {
if (!mState.currentProgram) ASSERT(mState.currentProgram);
{
return gl::error(GL_INVALID_OPERATION);
}
VertexArray *vao = getCurrentVertexArray();
if (!indices && !vao->getElementArrayBuffer())
{
return gl::error(GL_INVALID_OPERATION);
}
ProgramBinary *programBinary = getCurrentProgramBinary(); ProgramBinary *programBinary = getCurrentProgramBinary();
programBinary->applyUniforms(); programBinary->applyUniforms();
...@@ -2957,6 +2945,7 @@ void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid ...@@ -2957,6 +2945,7 @@ void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid
applyState(mode); applyState(mode);
VertexArray *vao = getCurrentVertexArray();
rx::TranslatedIndexData indexInfo; rx::TranslatedIndexData indexInfo;
GLenum err = mRenderer->applyIndexBuffer(indices, vao->getElementArrayBuffer(), count, mode, type, &indexInfo); GLenum err = mRenderer->applyIndexBuffer(indices, vao->getElementArrayBuffer(), count, mode, type, &indexInfo);
if (err != GL_NO_ERROR) if (err != GL_NO_ERROR)
...@@ -2989,11 +2978,6 @@ void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid ...@@ -2989,11 +2978,6 @@ void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid
return; return;
} }
if (!programBinary->validateSamplers(NULL))
{
return gl::error(GL_INVALID_OPERATION);
}
if (!skipDraw(mode)) if (!skipDraw(mode))
{ {
mRenderer->drawElements(mode, count, type, indices, vao->getElementArrayBuffer(), indexInfo, instances); mRenderer->drawElements(mode, count, type, indices, vao->getElementArrayBuffer(), indexInfo, instances);
......
...@@ -309,6 +309,7 @@ class Context ...@@ -309,6 +309,7 @@ class Context
void useProgram(GLuint program); void useProgram(GLuint program);
void linkProgram(GLuint program); void linkProgram(GLuint program);
void setProgramBinary(GLuint program, const void *binary, GLint length); void setProgramBinary(GLuint program, const void *binary, GLint length);
GLuint getCurrentProgram() const;
void bindTransformFeedback(GLuint transformFeedback); void bindTransformFeedback(GLuint transformFeedback);
void beginQuery(GLenum target, GLuint query); void beginQuery(GLenum target, GLuint query);
...@@ -344,7 +345,7 @@ class Context ...@@ -344,7 +345,7 @@ class Context
Buffer *getTargetBuffer(GLenum target) const; Buffer *getTargetBuffer(GLenum target) const;
Buffer *getArrayBuffer(); Buffer *getArrayBuffer();
Buffer *getElementArrayBuffer() const; Buffer *getElementArrayBuffer() const;
ProgramBinary *getCurrentProgramBinary(); ProgramBinary *getCurrentProgramBinary() const;
Texture *getTargetTexture(GLenum target) const; Texture *getTargetTexture(GLenum target) const;
Texture2D *getTexture2D() const; Texture2D *getTexture2D() const;
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "libGLESv2/Query.h" #include "libGLESv2/Query.h"
#include "libGLESv2/ProgramBinary.h" #include "libGLESv2/ProgramBinary.h"
#include "libGLESv2/TransformFeedback.h" #include "libGLESv2/TransformFeedback.h"
#include "libGLESv2/VertexArray.h"
#include "common/mathutil.h" #include "common/mathutil.h"
#include "common/utilities.h" #include "common/utilities.h"
...@@ -1314,6 +1315,17 @@ static bool ValidateDrawBase(const gl::Context *context, GLsizei count) ...@@ -1314,6 +1315,17 @@ static bool ValidateDrawBase(const gl::Context *context, GLsizei count)
return gl::error(GL_INVALID_OPERATION, false); return gl::error(GL_INVALID_OPERATION, false);
} }
if (!context->getCurrentProgram())
{
return gl::error(GL_INVALID_OPERATION, false);
}
gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
if (!programBinary->validateSamplers(NULL))
{
return gl::error(GL_INVALID_OPERATION, false);
}
// No-op if zero count // No-op if zero count
return (count > 0); return (count > 0);
} }
...@@ -1390,6 +1402,12 @@ bool ValidateDrawElements(const gl::Context *context, GLenum mode, GLsizei count ...@@ -1390,6 +1402,12 @@ bool ValidateDrawElements(const gl::Context *context, GLenum mode, GLsizei count
return gl::error(GL_INVALID_OPERATION, false); return gl::error(GL_INVALID_OPERATION, false);
} }
gl::VertexArray *vao = context->getCurrentVertexArray();
if (!indices && !vao->getElementArrayBuffer())
{
return gl::error(GL_INVALID_OPERATION, false);
}
if (!ValidateDrawBase(context, count)) if (!ValidateDrawBase(context, count))
{ {
return false; return false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment