Commit 769769a7 by Dian Xiang

Adding in checks for program and shader names to return INVALID_OPERATION

When a valid program is given instead of a shader, an INVALID_OPERATION is returned rather than INVALID_VALUE when a shader related function is called. The reverse happens when a program related function is called and a valid shader program is given to it. This commit also refactors other places that requires a similar check to use the same validation function and error message. BUG=angleproject:1029 dEQP-GLES2.functional.negative_api.state.get_shader_info_log dEQP-GLES2.functional.negative_api.state.get_shader_source dEQP-GLES2.functional.negative_api.state.get_programiv dEQP-GLES2.functional.negative_api.state.get_program_info_log BUG=angleproject:1101 dEQP-GLES3.functional.negative_api.state.get_shader_info_log dEQP-GLES3.functional.negative_api.state.get_shader_source dEQP-GLES3.functional.negative_api.state.get_programiv dEQP-GLES3.functional.negative_api.state.get_program_info_log Change-Id: I707b6ba10da0288128af185ce8dfb906fca0f766 Reviewed-on: https://chromium-review.googlesource.com/298604Reviewed-by: 's avatarZhenyao Mo <zmo@chromium.org> Tryjob-Request: Dian Xiang <dianx@google.com> Tested-by: 's avatarDian Xiang <dianx@google.com>
parent e8f47137
......@@ -326,28 +326,50 @@ bool ValidQueryType(const Context *context, GLenum queryType)
}
}
bool ValidProgram(Context *context, GLuint id)
Program *GetValidProgram(Context *context, GLuint id)
{
// ES3 spec (section 2.11.1) -- "Commands that accept shader or program object names will generate the
// error INVALID_VALUE if the provided name is not the name of either a shader or program object and
// INVALID_OPERATION if the provided name identifies an object that is not the expected type."
if (context->getProgram(id) != NULL)
{
return true;
}
else if (context->getShader(id) != NULL)
Program *validProgram = context->getProgram(id);
if (!validProgram)
{
// ID is the wrong type
context->recordError(Error(GL_INVALID_OPERATION));
return false;
if (context->getShader(id))
{
context->recordError(
Error(GL_INVALID_OPERATION, "Expected a program name, but found a shader name"));
}
else
{
context->recordError(Error(GL_INVALID_VALUE, "Program name is not valid"));
}
}
else
return validProgram;
}
Shader *GetValidShader(Context *context, GLuint id)
{
// See ValidProgram for spec details.
Shader *validShader = context->getShader(id);
if (!validShader)
{
// No shader/program object has this ID
context->recordError(Error(GL_INVALID_VALUE));
return false;
if (context->getProgram(id))
{
context->recordError(
Error(GL_INVALID_OPERATION, "Expected a shader name, but found a program name"));
}
else
{
context->recordError(Error(GL_INVALID_VALUE, "Shader name is invalid"));
}
}
return validShader;
}
bool ValidateAttachmentTarget(gl::Context *context, GLenum attachment)
......@@ -1880,13 +1902,12 @@ bool ValidateGetUniformBase(Context *context, GLuint program, GLint location)
return false;
}
if (!ValidProgram(context, program))
gl::Program *programObject = GetValidProgram(context, program);
if (!programObject)
{
return false;
}
gl::Program *programObject = context->getProgram(program);
if (!programObject || !programObject->isLinked())
{
context->recordError(Error(GL_INVALID_OPERATION));
......
......@@ -24,6 +24,8 @@ namespace gl
{
class Context;
class Program;
class Shader;
bool ValidCap(const Context *context, GLenum cap);
bool ValidTextureTarget(const Context *context, GLenum target);
......@@ -35,7 +37,16 @@ bool ValidMipLevel(const Context *context, GLenum target, GLint level);
bool ValidImageSize(const Context *context, GLenum target, GLint level, GLsizei width, GLsizei height, GLsizei depth);
bool ValidCompressedImageSize(const Context *context, GLenum internalFormat, GLsizei width, GLsizei height);
bool ValidQueryType(const Context *context, GLenum queryType);
bool ValidProgram(Context *context, GLuint id);
// 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
Program *GetValidProgram(Context *context, GLuint id);
// Returns valid shader if id is a valid shader name
// Errors INVALID_OPERATION if valid program is given and returns NULL
// Errors INVALID_VALUE otherwise and returns NULL
Shader *GetValidShader(Context *context, GLuint id);
bool ValidateAttachmentTarget(Context *context, GLenum attachment);
bool ValidateRenderbufferStorageParametersBase(Context *context, GLenum target, GLsizei samples,
......
......@@ -59,35 +59,16 @@ void GL_APIENTRY AttachShader(GLuint program, GLuint shader)
Context *context = GetValidGlobalContext();
if (context)
{
Program *programObject = context->getProgram(program);
Shader *shaderObject = context->getShader(shader);
Program *programObject = GetValidProgram(context, program);
if (!programObject)
{
if (context->getShader(program))
{
context->recordError(Error(GL_INVALID_OPERATION));
return;
}
else
{
context->recordError(Error(GL_INVALID_VALUE));
return;
}
return;
}
Shader *shaderObject = GetValidShader(context, shader);
if (!shaderObject)
{
if (context->getProgram(shader))
{
context->recordError(Error(GL_INVALID_OPERATION));
return;
}
else
{
context->recordError(Error(GL_INVALID_VALUE));
return;
}
return;
}
if (!programObject->attachShader(shaderObject))
......@@ -111,20 +92,11 @@ void GL_APIENTRY BindAttribLocation(GLuint program, GLuint index, const GLchar*
return;
}
Program *programObject = context->getProgram(program);
Program *programObject = GetValidProgram(context, program);
if (!programObject)
{
if (context->getShader(program))
{
context->recordError(Error(GL_INVALID_OPERATION));
return;
}
else
{
context->recordError(Error(GL_INVALID_VALUE));
return;
}
return;
}
if (strncmp(name, "gl_", 3) == 0)
......@@ -698,22 +670,11 @@ void GL_APIENTRY CompileShader(GLuint shader)
Context *context = GetValidGlobalContext();
if (context)
{
Shader *shaderObject = context->getShader(shader);
Shader *shaderObject = GetValidShader(context, shader);
if (!shaderObject)
{
if (context->getProgram(shader))
{
context->recordError(Error(GL_INVALID_OPERATION));
return;
}
else
{
context->recordError(Error(GL_INVALID_VALUE));
return;
}
return;
}
shaderObject->compile(context->getCompiler());
}
}
......@@ -1140,38 +1101,16 @@ void GL_APIENTRY DetachShader(GLuint program, GLuint shader)
Context *context = GetValidGlobalContext();
if (context)
{
Program *programObject = context->getProgram(program);
Shader *shaderObject = context->getShader(shader);
Program *programObject = GetValidProgram(context, program);
if (!programObject)
{
Shader *shaderByProgramHandle;
shaderByProgramHandle = context->getShader(program);
if (!shaderByProgramHandle)
{
context->recordError(Error(GL_INVALID_VALUE));
return;
}
else
{
context->recordError(Error(GL_INVALID_OPERATION));
return;
}
return;
}
Shader *shaderObject = GetValidShader(context, shader);
if (!shaderObject)
{
Program *programByShaderHandle = context->getProgram(shader);
if (!programByShaderHandle)
{
context->recordError(Error(GL_INVALID_VALUE));
return;
}
else
{
context->recordError(Error(GL_INVALID_OPERATION));
return;
}
return;
}
if (!programObject->detachShader(shaderObject))
......@@ -1608,20 +1547,11 @@ void GL_APIENTRY GetActiveAttrib(GLuint program, GLuint index, GLsizei bufsize,
return;
}
Program *programObject = context->getProgram(program);
Program *programObject = GetValidProgram(context, program);
if (!programObject)
{
if (context->getShader(program))
{
context->recordError(Error(GL_INVALID_OPERATION));
return;
}
else
{
context->recordError(Error(GL_INVALID_VALUE));
return;
}
return;
}
if (index >= (GLuint)programObject->getActiveAttributeCount())
......@@ -1650,20 +1580,11 @@ void GL_APIENTRY GetActiveUniform(GLuint program, GLuint index, GLsizei bufsize,
return;
}
Program *programObject = context->getProgram(program);
Program *programObject = GetValidProgram(context, program);
if (!programObject)
{
if (context->getShader(program))
{
context->recordError(Error(GL_INVALID_OPERATION));
return;
}
else
{
context->recordError(Error(GL_INVALID_VALUE));
return;
}
return;
}
if (index >= (GLuint)programObject->getActiveUniformCount())
......@@ -1690,20 +1611,11 @@ void GL_APIENTRY GetAttachedShaders(GLuint program, GLsizei maxcount, GLsizei* c
return;
}
Program *programObject = context->getProgram(program);
Program *programObject = GetValidProgram(context, program);
if (!programObject)
{
if (context->getShader(program))
{
context->recordError(Error(GL_INVALID_OPERATION));
return;
}
else
{
context->recordError(Error(GL_INVALID_VALUE));
return;
}
return;
}
return programObject->getAttachedShaders(maxcount, count, shaders);
......@@ -1717,20 +1629,11 @@ GLint GL_APIENTRY GetAttribLocation(GLuint program, const GLchar* name)
Context *context = GetValidGlobalContext();
if (context)
{
Program *programObject = context->getProgram(program);
Program *programObject = GetValidProgram(context, program);
if (!programObject)
{
if (context->getShader(program))
{
context->recordError(Error(GL_INVALID_OPERATION));
return -1;
}
else
{
context->recordError(Error(GL_INVALID_VALUE));
return -1;
}
return -1;
}
if (!programObject->isLinked())
......@@ -2163,11 +2066,10 @@ void GL_APIENTRY GetProgramiv(GLuint program, GLenum pname, GLint* params)
Context *context = GetValidGlobalContext();
if (context)
{
Program *programObject = context->getProgram(program);
Program *programObject = GetValidProgram(context, program);
if (!programObject)
{
context->recordError(Error(GL_INVALID_VALUE));
return;
}
......@@ -2254,11 +2156,9 @@ void GL_APIENTRY GetProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei* len
return;
}
Program *programObject = context->getProgram(program);
Program *programObject = GetValidProgram(context, program);
if (!programObject)
{
context->recordError(Error(GL_INVALID_VALUE));
return;
}
......@@ -2322,21 +2222,9 @@ void GL_APIENTRY GetShaderiv(GLuint shader, GLenum pname, GLint* params)
Context *context = GetValidGlobalContext();
if (context)
{
Shader *shaderObject = context->getShader(shader);
Shader *shaderObject = GetValidShader(context, shader);
if (!shaderObject)
{
Program *programObject = context->getProgram(shader);
if (programObject)
{
context->recordError(Error(GL_INVALID_OPERATION,
"Expected a shader name, but found a program name"));
}
else
{
context->recordError(Error(GL_INVALID_VALUE, "Shader name is invalid"));
}
return;
}
......@@ -2382,11 +2270,9 @@ void GL_APIENTRY GetShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei* lengt
return;
}
Shader *shaderObject = context->getShader(shader);
Shader *shaderObject = GetValidShader(context, shader);
if (!shaderObject)
{
context->recordError(Error(GL_INVALID_VALUE));
return;
}
......@@ -2482,11 +2368,9 @@ void GL_APIENTRY GetShaderSource(GLuint shader, GLsizei bufsize, GLsizei* length
return;
}
Shader *shaderObject = context->getShader(shader);
Shader *shaderObject = GetValidShader(context, shader);
if (!shaderObject)
{
context->recordError(Error(GL_INVALID_OPERATION));
return;
}
......@@ -2872,20 +2756,11 @@ GLint GL_APIENTRY GetUniformLocation(GLuint program, const GLchar* name)
return -1;
}
Program *programObject = context->getProgram(program);
Program *programObject = GetValidProgram(context, program);
if (!programObject)
{
if (context->getShader(program))
{
context->recordError(Error(GL_INVALID_OPERATION));
return -1;
}
else
{
context->recordError(Error(GL_INVALID_VALUE));
return -1;
}
return -1;
}
if (!programObject->isLinked())
......@@ -3179,20 +3054,10 @@ void GL_APIENTRY LinkProgram(GLuint program)
Context *context = GetValidGlobalContext();
if (context)
{
Program *programObject = context->getProgram(program);
Program *programObject = GetValidProgram(context, program);
if (!programObject)
{
if (context->getShader(program))
{
context->recordError(Error(GL_INVALID_OPERATION));
return;
}
else
{
context->recordError(Error(GL_INVALID_VALUE));
return;
}
return;
}
Error error = programObject->link(context->getData());
......@@ -3461,22 +3326,11 @@ void GL_APIENTRY ShaderSource(GLuint shader, GLsizei count, const GLchar* const*
return;
}
Shader *shaderObject = context->getShader(shader);
Shader *shaderObject = GetValidShader(context, shader);
if (!shaderObject)
{
if (context->getProgram(shader))
{
context->recordError(Error(GL_INVALID_OPERATION));
return;
}
else
{
context->recordError(Error(GL_INVALID_VALUE));
return;
}
return;
}
shaderObject->setSource(count, string, length);
}
}
......@@ -4129,20 +3983,11 @@ void GL_APIENTRY ValidateProgram(GLuint program)
Context *context = GetValidGlobalContext();
if (context)
{
Program *programObject = context->getProgram(program);
Program *programObject = GetValidProgram(context, program);
if (!programObject)
{
if (context->getShader(program))
{
context->recordError(Error(GL_INVALID_OPERATION));
return;
}
else
{
context->recordError(Error(GL_INVALID_VALUE));
return;
}
return;
}
programObject->validate(context->getCaps());
......
......@@ -1247,14 +1247,12 @@ void GL_APIENTRY TransformFeedbackVaryings(GLuint program, GLsizei count, const
return;
}
if (!ValidProgram(context, program))
Program *programObject = GetValidProgram(context, program);
if (!programObject)
{
return;
}
Program *programObject = context->getProgram(program);
ASSERT(programObject);
programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
}
}
......@@ -1280,14 +1278,12 @@ void GL_APIENTRY GetTransformFeedbackVarying(GLuint program, GLuint index, GLsiz
return;
}
if (!ValidProgram(context, program))
Program *programObject = GetValidProgram(context, program);
if (!programObject)
{
return;
}
Program *programObject = context->getProgram(program);
ASSERT(programObject);
if (index >= static_cast<GLuint>(programObject->getTransformFeedbackVaryingCount()))
{
context->recordError(Error(GL_INVALID_VALUE));
......@@ -1991,20 +1987,11 @@ void GL_APIENTRY GetUniformIndices(GLuint program, GLsizei uniformCount, const G
return;
}
Program *programObject = context->getProgram(program);
Program *programObject = GetValidProgram(context, program);
if (!programObject)
{
if (context->getShader(program))
{
context->recordError(Error(GL_INVALID_OPERATION));
return;
}
else
{
context->recordError(Error(GL_INVALID_VALUE));
return;
}
return;
}
if (!programObject->isLinked())
......@@ -2044,20 +2031,11 @@ void GL_APIENTRY GetActiveUniformsiv(GLuint program, GLsizei uniformCount, const
return;
}
Program *programObject = context->getProgram(program);
Program *programObject = GetValidProgram(context, program);
if (!programObject)
{
if (context->getShader(program))
{
context->recordError(Error(GL_INVALID_OPERATION));
return;
}
else
{
context->recordError(Error(GL_INVALID_VALUE));
return;
}
return;
}
switch (pname)
......@@ -2115,20 +2093,10 @@ GLuint GL_APIENTRY GetUniformBlockIndex(GLuint program, const GLchar* uniformBlo
return GL_INVALID_INDEX;
}
Program *programObject = context->getProgram(program);
Program *programObject = GetValidProgram(context, program);
if (!programObject)
{
if (context->getShader(program))
{
context->recordError(Error(GL_INVALID_OPERATION));
return GL_INVALID_INDEX;
}
else
{
context->recordError(Error(GL_INVALID_VALUE));
return GL_INVALID_INDEX;
}
return GL_INVALID_INDEX;
}
return programObject->getUniformBlockIndex(uniformBlockName);
......@@ -2150,20 +2118,11 @@ void GL_APIENTRY GetActiveUniformBlockiv(GLuint program, GLuint uniformBlockInde
context->recordError(Error(GL_INVALID_OPERATION));
return;
}
Program *programObject = context->getProgram(program);
Program *programObject = GetValidProgram(context, program);
if (!programObject)
{
if (context->getShader(program))
{
context->recordError(Error(GL_INVALID_OPERATION));
return;
}
else
{
context->recordError(Error(GL_INVALID_VALUE));
return;
}
return;
}
if (uniformBlockIndex >= programObject->getActiveUniformBlockCount())
......@@ -2208,20 +2167,11 @@ void GL_APIENTRY GetActiveUniformBlockName(GLuint program, GLuint uniformBlockIn
return;
}
Program *programObject = context->getProgram(program);
Program *programObject = GetValidProgram(context, program);
if (!programObject)
{
if (context->getShader(program))
{
context->recordError(Error(GL_INVALID_OPERATION));
return;
}
else
{
context->recordError(Error(GL_INVALID_VALUE));
return;
}
return;
}
if (uniformBlockIndex >= programObject->getActiveUniformBlockCount())
......@@ -2254,20 +2204,11 @@ void GL_APIENTRY UniformBlockBinding(GLuint program, GLuint uniformBlockIndex, G
return;
}
Program *programObject = context->getProgram(program);
Program *programObject = GetValidProgram(context, program);
if (!programObject)
{
if (context->getShader(program))
{
context->recordError(Error(GL_INVALID_OPERATION));
return;
}
else
{
context->recordError(Error(GL_INVALID_VALUE));
return;
}
return;
}
// if never linked, there won't be any uniform blocks
......
......@@ -244,11 +244,6 @@
1028 WIN LINUX : dEQP-GLES2.functional.fbo.completeness.renderable.texture.depth.depth_component_unsigned_short = FAIL
1028 WIN LINUX : dEQP-GLES2.functional.fbo.completeness.renderable.texture.depth.depth_component_unsigned_int = FAIL
1028 WIN LINUX : dEQP-GLES2.functional.fbo.completeness.renderable.texture.depth.srgb8 = FAIL
1029 WIN LINUX : dEQP-GLES2.functional.negative_api.state.get_shaderiv = FAIL
1029 WIN LINUX : dEQP-GLES2.functional.negative_api.state.get_shader_info_log = FAIL
1029 WIN LINUX : dEQP-GLES2.functional.negative_api.state.get_shader_source = FAIL
1029 WIN LINUX : dEQP-GLES2.functional.negative_api.state.get_programiv = FAIL
1029 WIN LINUX : dEQP-GLES2.functional.negative_api.state.get_program_info_log = FAIL
1029 WIN LINUX : dEQP-GLES2.functional.negative_api.texture.compressedteximage_2d_invalid_format_tex2d = FAIL
1029 WIN LINUX : dEQP-GLES2.functional.negative_api.texture.compressedteximage_2d_invalid_format_cube = FAIL
1128 WIN LINUX : dEQP-GLES2.functional.negative_api.texture.compressedtexsubimage2d_invalid_size = FAIL
......
......@@ -1149,11 +1149,6 @@
1101 WIN : dEQP-GLES3.functional.negative_api.vertex_array.draw_range_elements = FAIL
1101 WIN : dEQP-GLES3.functional.negative_api.vertex_array.draw_range_elements_invalid_program = FAIL
1101 WIN : dEQP-GLES3.functional.negative_api.vertex_array.draw_range_elements_incomplete_primitive = FAIL
1101 WIN : dEQP-GLES3.functional.negative_api.state.get_shaderiv = FAIL
1101 WIN : dEQP-GLES3.functional.negative_api.state.get_shader_info_log = FAIL
1101 WIN : dEQP-GLES3.functional.negative_api.state.get_shader_source = FAIL
1101 WIN : dEQP-GLES3.functional.negative_api.state.get_programiv = FAIL
1101 WIN : dEQP-GLES3.functional.negative_api.state.get_program_info_log = FAIL
1101 WIN : dEQP-GLES3.functional.negative_api.state.get_buffer_pointerv = FAIL
1101 WIN : dEQP-GLES3.functional.negative_api.state.get_framebuffer_attachment_parameteriv = FAIL
1101 WIN : dEQP-GLES3.functional.negative_api.state.is_transform_feedback = FAIL
......
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