Commit 3639892d by Jamie Madill

Move all uniform validation from ProgramBinary to API layer.

This will have the contract of having a successful API call once we call into the ANGLE internals, having successfully passed valiation. BUG=angle:571 Change-Id: Ia8d6eccc1e42bdf9e9cc5c10094a08729b42778a Reviewed-on: https://chromium-review.googlesource.com/200075Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarShannon Woods <shannonwoods@chromium.org> Tested-by: 's avatarJamie Madill <jmadill@chromium.org>
parent aa981bd7
......@@ -100,27 +100,27 @@ class ProgramBinary : public RefCountObject
GLint getUniformLocation(std::string name);
GLuint getUniformIndex(std::string name);
GLuint getUniformBlockIndex(std::string name);
bool setUniform1fv(GLint location, GLsizei count, const GLfloat *v);
bool setUniform2fv(GLint location, GLsizei count, const GLfloat *v);
bool setUniform3fv(GLint location, GLsizei count, const GLfloat *v);
bool setUniform4fv(GLint location, GLsizei count, const GLfloat *v);
bool setUniform1iv(GLint location, GLsizei count, const GLint *v);
bool setUniform2iv(GLint location, GLsizei count, const GLint *v);
bool setUniform3iv(GLint location, GLsizei count, const GLint *v);
bool setUniform4iv(GLint location, GLsizei count, const GLint *v);
bool setUniform1uiv(GLint location, GLsizei count, const GLuint *v);
bool setUniform2uiv(GLint location, GLsizei count, const GLuint *v);
bool setUniform3uiv(GLint location, GLsizei count, const GLuint *v);
bool setUniform4uiv(GLint location, GLsizei count, const GLuint *v);
bool setUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
bool setUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
bool setUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
bool setUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
bool setUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
bool setUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
bool setUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
bool setUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
bool setUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
void setUniform1fv(GLint location, GLsizei count, const GLfloat *v);
void setUniform2fv(GLint location, GLsizei count, const GLfloat *v);
void setUniform3fv(GLint location, GLsizei count, const GLfloat *v);
void setUniform4fv(GLint location, GLsizei count, const GLfloat *v);
void setUniform1iv(GLint location, GLsizei count, const GLint *v);
void setUniform2iv(GLint location, GLsizei count, const GLint *v);
void setUniform3iv(GLint location, GLsizei count, const GLint *v);
void setUniform4iv(GLint location, GLsizei count, const GLint *v);
void setUniform1uiv(GLint location, GLsizei count, const GLuint *v);
void setUniform2uiv(GLint location, GLsizei count, const GLuint *v);
void setUniform3uiv(GLint location, GLsizei count, const GLuint *v);
void setUniform4uiv(GLint location, GLsizei count, const GLuint *v);
void setUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
void setUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
void setUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
void setUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
void setUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
void setUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
void setUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
void setUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
void setUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
bool getUniformfv(GLint location, GLsizei *bufSize, GLfloat *params);
bool getUniformiv(GLint location, GLsizei *bufSize, GLint *params);
......@@ -146,6 +146,8 @@ class ProgramBinary : public RefCountObject
GLint getActiveUniformCount() const;
GLint getActiveUniformMaxLength() const;
GLint getActiveUniformi(GLuint index, GLenum pname) const;
bool isValidUniformLocation(GLint location) const;
LinkedUniform *getUniformByLocation(GLint location) const;
void getActiveUniformBlockName(GLuint uniformBlockIndex, GLsizei bufSize, GLsizei *length, GLchar *uniformBlockName) const;
void getActiveUniformBlockiv(GLuint uniformBlockIndex, GLenum pname, GLint *params) const;
......@@ -203,10 +205,10 @@ class ProgramBinary : public RefCountObject
void initializeUniformStorage();
template <typename T>
bool setUniform(GLint location, GLsizei count, const T* v, GLenum targetUniformType);
void setUniform(GLint location, GLsizei count, const T* v, GLenum targetUniformType);
template <int cols, int rows>
bool setUniformMatrixfv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value, GLenum targetUniformType);
void setUniformMatrixfv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value, GLenum targetUniformType);
template <typename T>
bool getUniformv(GLint location, GLsizei *bufSize, T *params, GLenum uniformType);
......
......@@ -5238,10 +5238,7 @@ void __stdcall glUniform1fv(GLint location, GLsizei count, const GLfloat* v)
}
gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
if (!programBinary->setUniform1fv(location, count, v))
{
return gl::error(GL_INVALID_OPERATION);
}
programBinary->setUniform1fv(location, count, v);
}
}
catch (...)
......@@ -5271,10 +5268,7 @@ void __stdcall glUniform1iv(GLint location, GLsizei count, const GLint* v)
}
gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
if (!programBinary->setUniform1iv(location, count, v))
{
return gl::error(GL_INVALID_OPERATION);
}
programBinary->setUniform1iv(location, count, v);
}
}
catch (...)
......@@ -5306,10 +5300,7 @@ void __stdcall glUniform2fv(GLint location, GLsizei count, const GLfloat* v)
}
gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
if (!programBinary->setUniform2fv(location, count, v))
{
return gl::error(GL_INVALID_OPERATION);
}
programBinary->setUniform2fv(location, count, v);
}
}
catch (...)
......@@ -5341,10 +5332,7 @@ void __stdcall glUniform2iv(GLint location, GLsizei count, const GLint* v)
}
gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
if (!programBinary->setUniform2iv(location, count, v))
{
return gl::error(GL_INVALID_OPERATION);
}
programBinary->setUniform2iv(location, count, v);
}
}
catch (...)
......@@ -5376,10 +5364,7 @@ void __stdcall glUniform3fv(GLint location, GLsizei count, const GLfloat* v)
}
gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
if (!programBinary->setUniform3fv(location, count, v))
{
return gl::error(GL_INVALID_OPERATION);
}
programBinary->setUniform3fv(location, count, v);
}
}
catch (...)
......@@ -5411,10 +5396,7 @@ void __stdcall glUniform3iv(GLint location, GLsizei count, const GLint* v)
}
gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
if (!programBinary->setUniform3iv(location, count, v))
{
return gl::error(GL_INVALID_OPERATION);
}
programBinary->setUniform3iv(location, count, v);
}
}
catch (...)
......@@ -5446,10 +5428,7 @@ void __stdcall glUniform4fv(GLint location, GLsizei count, const GLfloat* v)
}
gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
if (!programBinary->setUniform4fv(location, count, v))
{
return gl::error(GL_INVALID_OPERATION);
}
programBinary->setUniform4fv(location, count, v);
}
}
catch (...)
......@@ -5481,10 +5460,7 @@ void __stdcall glUniform4iv(GLint location, GLsizei count, const GLint* v)
}
gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
if (!programBinary->setUniform4iv(location, count, v))
{
return gl::error(GL_INVALID_OPERATION);
}
programBinary->setUniform4iv(location, count, v);
}
}
catch (...)
......@@ -5510,10 +5486,7 @@ void __stdcall glUniformMatrix2fv(GLint location, GLsizei count, GLboolean trans
}
gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
if (!programBinary->setUniformMatrix2fv(location, count, transpose, value))
{
return gl::error(GL_INVALID_OPERATION);
}
programBinary->setUniformMatrix2fv(location, count, transpose, value);
}
}
catch (...)
......@@ -5539,10 +5512,7 @@ void __stdcall glUniformMatrix3fv(GLint location, GLsizei count, GLboolean trans
}
gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
if (!programBinary->setUniformMatrix3fv(location, count, transpose, value))
{
return gl::error(GL_INVALID_OPERATION);
}
programBinary->setUniformMatrix3fv(location, count, transpose, value);
}
}
catch (...)
......@@ -5568,10 +5538,7 @@ void __stdcall glUniformMatrix4fv(GLint location, GLsizei count, GLboolean trans
}
gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
if (!programBinary->setUniformMatrix4fv(location, count, transpose, value))
{
return gl::error(GL_INVALID_OPERATION);
}
programBinary->setUniformMatrix4fv(location, count, transpose, value);
}
}
catch (...)
......@@ -6639,10 +6606,7 @@ void __stdcall glUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean tra
}
gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
if (!programBinary->setUniformMatrix2x3fv(location, count, transpose, value))
{
return gl::error(GL_INVALID_OPERATION);
}
programBinary->setUniformMatrix2x3fv(location, count, transpose, value);
}
}
catch (...)
......@@ -6668,10 +6632,7 @@ void __stdcall glUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean tra
}
gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
if (!programBinary->setUniformMatrix3x2fv(location, count, transpose, value))
{
return gl::error(GL_INVALID_OPERATION);
}
programBinary->setUniformMatrix3x2fv(location, count, transpose, value);
}
}
catch (...)
......@@ -6697,10 +6658,7 @@ void __stdcall glUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean tra
}
gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
if (!programBinary->setUniformMatrix2x4fv(location, count, transpose, value))
{
return gl::error(GL_INVALID_OPERATION);
}
programBinary->setUniformMatrix2x4fv(location, count, transpose, value);
}
}
catch (...)
......@@ -6726,10 +6684,7 @@ void __stdcall glUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean tra
}
gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
if (!programBinary->setUniformMatrix4x2fv(location, count, transpose, value))
{
return gl::error(GL_INVALID_OPERATION);
}
programBinary->setUniformMatrix4x2fv(location, count, transpose, value);
}
}
catch (...)
......@@ -6755,10 +6710,7 @@ void __stdcall glUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean tra
}
gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
if (!programBinary->setUniformMatrix3x4fv(location, count, transpose, value))
{
return gl::error(GL_INVALID_OPERATION);
}
programBinary->setUniformMatrix3x4fv(location, count, transpose, value);
}
}
catch (...)
......@@ -6784,10 +6736,7 @@ void __stdcall glUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean tra
}
gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
if (!programBinary->setUniformMatrix4x3fv(location, count, transpose, value))
{
return gl::error(GL_INVALID_OPERATION);
}
programBinary->setUniformMatrix4x3fv(location, count, transpose, value);
}
}
catch (...)
......@@ -7900,10 +7849,7 @@ void __stdcall glUniform1uiv(GLint location, GLsizei count, const GLuint* value)
}
gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
if (!programBinary->setUniform1uiv(location, count, value))
{
return gl::error(GL_INVALID_OPERATION);
}
programBinary->setUniform1uiv(location, count, value);
}
}
catch (...)
......@@ -7929,10 +7875,7 @@ void __stdcall glUniform2uiv(GLint location, GLsizei count, const GLuint* value)
}
gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
if (!programBinary->setUniform2uiv(location, count, value))
{
return gl::error(GL_INVALID_OPERATION);
}
programBinary->setUniform2uiv(location, count, value);
}
}
catch (...)
......@@ -7958,10 +7901,7 @@ void __stdcall glUniform3uiv(GLint location, GLsizei count, const GLuint* value)
}
gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
if (!programBinary->setUniform3uiv(location, count, value))
{
return gl::error(GL_INVALID_OPERATION);
}
programBinary->setUniform3uiv(location, count, value);
}
}
catch (...)
......@@ -7987,10 +7927,7 @@ void __stdcall glUniform4uiv(GLint location, GLsizei count, const GLuint* value)
}
gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
if (!programBinary->setUniform4uiv(location, count, value))
{
return gl::error(GL_INVALID_OPERATION);
}
programBinary->setUniform4uiv(location, count, value);
}
}
catch (...)
......
......@@ -17,6 +17,7 @@
#include "libGLESv2/formatutils.h"
#include "libGLESv2/main.h"
#include "libGLESv2/Query.h"
#include "libGLESv2/ProgramBinary.h"
#include "common/mathutil.h"
#include "common/utilities.h"
......@@ -946,7 +947,8 @@ bool ValidateEndQuery(gl::Context *context, GLenum target)
return true;
}
static bool ValidateUniformCommonBase(gl::Context *context, GLint location, GLsizei count)
static bool ValidateUniformCommonBase(gl::Context *context, GLenum targetUniformType,
GLint location, GLsizei count, LinkedUniform **uniformOut)
{
if (count < 0)
{
......@@ -965,6 +967,20 @@ static bool ValidateUniformCommonBase(gl::Context *context, GLint location, GLsi
return false;
}
if (!programBinary->isValidUniformLocation(location))
{
return gl::error(GL_INVALID_OPERATION, false);
}
LinkedUniform *uniform = programBinary->getUniformByLocation(location);
// attempting to write an array to a non-array uniform is an INVALID_OPERATION
if (uniform->elementCount() == 1 && count > 1)
{
return gl::error(GL_INVALID_OPERATION, false);
}
*uniformOut = uniform;
return true;
}
......@@ -976,7 +992,20 @@ bool ValidateUniform(gl::Context *context, GLenum uniformType, GLint location, G
return gl::error(GL_INVALID_OPERATION, false);
}
return ValidateUniformCommonBase(context, location, count);
LinkedUniform *uniform = NULL;
if (!ValidateUniformCommonBase(context, uniformType, location, count, &uniform))
{
return false;
}
GLenum targetBoolType = UniformBoolVectorType(uniformType);
bool samplerUniformCheck = (IsSampler(uniform->type) && uniformType == GL_INT);
if (!samplerUniformCheck && uniformType != uniform->type && targetBoolType != uniform->type)
{
return gl::error(GL_INVALID_OPERATION, false);
}
return true;
}
bool ValidateUniformMatrix(gl::Context *context, GLenum matrixType, GLint location, GLsizei count,
......@@ -995,7 +1024,18 @@ bool ValidateUniformMatrix(gl::Context *context, GLenum matrixType, GLint locati
return gl::error(GL_INVALID_VALUE, false);
}
return ValidateUniformCommonBase(context, location, count);
LinkedUniform *uniform = NULL;
if (!ValidateUniformCommonBase(context, matrixType, location, count, &uniform))
{
return false;
}
if (uniform->type != matrixType)
{
return gl::error(GL_INVALID_OPERATION, false);
}
return true;
}
}
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