Commit 2d62ab72 by Geoff Lang Committed by Commit Bot

Apply WebGL validation to glVertexAttribIPointer.

TEST=deqp/functional/gles3/shaderstatequery.html BUG=angleproject:1523 BUG=chromium:668223 Change-Id: I24230144f8529d84cdbde3d5a8ad9178481550a9 Reviewed-on: https://chromium-review.googlesource.com/458680 Commit-Queue: Geoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org>
parent 80957d99
......@@ -1867,6 +1867,53 @@ bool ValidQueryType(const Context *context, GLenum queryType)
}
}
bool ValidateWebGLVertexAttribPointer(ValidationContext *context,
GLenum type,
GLboolean normalized,
GLsizei stride,
const GLvoid *ptr,
bool pureInteger)
{
ASSERT(context->getExtensions().webglCompatibility);
// WebGL 1.0 [Section 6.11] Vertex Attribute Data Stride
// The WebGL API supports vertex attribute data strides up to 255 bytes. A call to
// vertexAttribPointer will generate an INVALID_VALUE error if the value for the stride
// parameter exceeds 255.
constexpr GLsizei kMaxWebGLStride = 255;
if (stride > kMaxWebGLStride)
{
context->handleError(
Error(GL_INVALID_VALUE, "Stride is over the maximum stride allowed by WebGL."));
return false;
}
// WebGL 1.0 [Section 6.4] Buffer Offset and Stride Requirements
// The offset arguments to drawElements and vertexAttribPointer, and the stride argument to
// vertexAttribPointer, must be a multiple of the size of the data type passed to the call,
// or an INVALID_OPERATION error is generated.
VertexFormatType internalType = GetVertexFormatType(type, normalized, 1, pureInteger);
size_t typeSize = GetVertexFormatTypeSize(internalType);
ASSERT(isPow2(typeSize) && typeSize > 0);
size_t sizeMask = (typeSize - 1);
if ((reinterpret_cast<intptr_t>(ptr) & sizeMask) != 0)
{
context->handleError(
Error(GL_INVALID_OPERATION, "Offset is not a multiple of the type size."));
return false;
}
if ((stride & sizeMask) != 0)
{
context->handleError(
Error(GL_INVALID_OPERATION, "Stride is not a multiple of the type size."));
return false;
}
return true;
}
Program *GetValidProgram(ValidationContext *context, GLuint id)
{
// ES3 spec (section 2.11.1) -- "Commands that accept shader or program object names will
......
......@@ -65,6 +65,13 @@ bool ValidImageDataSize(ValidationContext *context,
bool ValidQueryType(const Context *context, GLenum queryType);
bool ValidateWebGLVertexAttribPointer(ValidationContext *context,
GLenum type,
GLboolean normalized,
GLsizei stride,
const GLvoid *ptr,
bool pureInteger);
// Returns valid program if id is a valid program name
// Errors INVALID_OPERATION if valid shader is given and returns NULL
// Errors INVALID_VALUE otherwise and returns NULL
......
......@@ -3988,38 +3988,8 @@ bool ValidateVertexAttribPointer(ValidationContext *context,
return false;
}
// WebGL 1.0 [Section 6.11] Vertex Attribute Data Stride
// The WebGL API supports vertex attribute data strides up to 255 bytes. A call to
// vertexAttribPointer will generate an INVALID_VALUE error if the value for the stride
// parameter exceeds 255.
constexpr GLsizei kMaxWebGLStride = 255;
if (stride > kMaxWebGLStride)
if (!ValidateWebGLVertexAttribPointer(context, type, normalized, stride, ptr, false))
{
context->handleError(
Error(GL_INVALID_VALUE, "Stride is over the maximum stride allowed by WebGL."));
return false;
}
// WebGL 1.0 [Section 6.4] Buffer Offset and Stride Requirements
// The offset arguments to drawElements and vertexAttribPointer, and the stride argument to
// vertexAttribPointer, must be a multiple of the size of the data type passed to the call,
// or an INVALID_OPERATION error is generated.
VertexFormatType internalType = GetVertexFormatType(type, normalized, 1, false);
size_t typeSize = GetVertexFormatTypeSize(internalType);
ASSERT(isPow2(typeSize) && typeSize > 0);
size_t sizeMask = (typeSize - 1);
if ((reinterpret_cast<intptr_t>(ptr) & sizeMask) != 0)
{
context->handleError(
Error(GL_INVALID_OPERATION, "Offset is not a multiple of the type size."));
return false;
}
if ((stride & sizeMask) != 0)
{
context->handleError(
Error(GL_INVALID_OPERATION, "Stride is not a multiple of the type size."));
return false;
}
}
......
......@@ -2364,6 +2364,14 @@ bool ValidateVertexAttribIPointer(ValidationContext *context,
return false;
}
if (context->getExtensions().webglCompatibility)
{
if (!ValidateWebGLVertexAttribPointer(context, type, false, stride, pointer, true))
{
return 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