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) ...@@ -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 // 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 // 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." // INVALID_OPERATION if the provided name identifies an object that is not the expected type."
if (context->getProgram(id) != NULL) Program *validProgram = context->getProgram(id);
{
return true; if (!validProgram)
}
else if (context->getShader(id) != NULL)
{ {
// ID is the wrong type if (context->getShader(id))
context->recordError(Error(GL_INVALID_OPERATION)); {
return false; 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 if (context->getProgram(id))
context->recordError(Error(GL_INVALID_VALUE)); {
return false; 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) bool ValidateAttachmentTarget(gl::Context *context, GLenum attachment)
...@@ -1880,13 +1902,12 @@ bool ValidateGetUniformBase(Context *context, GLuint program, GLint location) ...@@ -1880,13 +1902,12 @@ bool ValidateGetUniformBase(Context *context, GLuint program, GLint location)
return false; return false;
} }
if (!ValidProgram(context, program)) gl::Program *programObject = GetValidProgram(context, program);
if (!programObject)
{ {
return false; return false;
} }
gl::Program *programObject = context->getProgram(program);
if (!programObject || !programObject->isLinked()) if (!programObject || !programObject->isLinked())
{ {
context->recordError(Error(GL_INVALID_OPERATION)); context->recordError(Error(GL_INVALID_OPERATION));
......
...@@ -24,6 +24,8 @@ namespace gl ...@@ -24,6 +24,8 @@ namespace gl
{ {
class Context; class Context;
class Program;
class Shader;
bool ValidCap(const Context *context, GLenum cap); bool ValidCap(const Context *context, GLenum cap);
bool ValidTextureTarget(const Context *context, GLenum target); bool ValidTextureTarget(const Context *context, GLenum target);
...@@ -35,7 +37,16 @@ bool ValidMipLevel(const Context *context, GLenum target, GLint level); ...@@ -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 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 ValidCompressedImageSize(const Context *context, GLenum internalFormat, GLsizei width, GLsizei height);
bool ValidQueryType(const Context *context, GLenum queryType); 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 ValidateAttachmentTarget(Context *context, GLenum attachment);
bool ValidateRenderbufferStorageParametersBase(Context *context, GLenum target, GLsizei samples, bool ValidateRenderbufferStorageParametersBase(Context *context, GLenum target, GLsizei samples,
......
...@@ -1247,14 +1247,12 @@ void GL_APIENTRY TransformFeedbackVaryings(GLuint program, GLsizei count, const ...@@ -1247,14 +1247,12 @@ void GL_APIENTRY TransformFeedbackVaryings(GLuint program, GLsizei count, const
return; return;
} }
if (!ValidProgram(context, program)) Program *programObject = GetValidProgram(context, program);
if (!programObject)
{ {
return; return;
} }
Program *programObject = context->getProgram(program);
ASSERT(programObject);
programObject->setTransformFeedbackVaryings(count, varyings, bufferMode); programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
} }
} }
...@@ -1280,14 +1278,12 @@ void GL_APIENTRY GetTransformFeedbackVarying(GLuint program, GLuint index, GLsiz ...@@ -1280,14 +1278,12 @@ void GL_APIENTRY GetTransformFeedbackVarying(GLuint program, GLuint index, GLsiz
return; return;
} }
if (!ValidProgram(context, program)) Program *programObject = GetValidProgram(context, program);
if (!programObject)
{ {
return; return;
} }
Program *programObject = context->getProgram(program);
ASSERT(programObject);
if (index >= static_cast<GLuint>(programObject->getTransformFeedbackVaryingCount())) if (index >= static_cast<GLuint>(programObject->getTransformFeedbackVaryingCount()))
{ {
context->recordError(Error(GL_INVALID_VALUE)); context->recordError(Error(GL_INVALID_VALUE));
...@@ -1991,20 +1987,11 @@ void GL_APIENTRY GetUniformIndices(GLuint program, GLsizei uniformCount, const G ...@@ -1991,20 +1987,11 @@ void GL_APIENTRY GetUniformIndices(GLuint program, GLsizei uniformCount, const G
return; return;
} }
Program *programObject = context->getProgram(program); Program *programObject = GetValidProgram(context, program);
if (!programObject) if (!programObject)
{ {
if (context->getShader(program)) return;
{
context->recordError(Error(GL_INVALID_OPERATION));
return;
}
else
{
context->recordError(Error(GL_INVALID_VALUE));
return;
}
} }
if (!programObject->isLinked()) if (!programObject->isLinked())
...@@ -2044,20 +2031,11 @@ void GL_APIENTRY GetActiveUniformsiv(GLuint program, GLsizei uniformCount, const ...@@ -2044,20 +2031,11 @@ void GL_APIENTRY GetActiveUniformsiv(GLuint program, GLsizei uniformCount, const
return; return;
} }
Program *programObject = context->getProgram(program); Program *programObject = GetValidProgram(context, program);
if (!programObject) if (!programObject)
{ {
if (context->getShader(program)) return;
{
context->recordError(Error(GL_INVALID_OPERATION));
return;
}
else
{
context->recordError(Error(GL_INVALID_VALUE));
return;
}
} }
switch (pname) switch (pname)
...@@ -2115,20 +2093,10 @@ GLuint GL_APIENTRY GetUniformBlockIndex(GLuint program, const GLchar* uniformBlo ...@@ -2115,20 +2093,10 @@ GLuint GL_APIENTRY GetUniformBlockIndex(GLuint program, const GLchar* uniformBlo
return GL_INVALID_INDEX; return GL_INVALID_INDEX;
} }
Program *programObject = context->getProgram(program); Program *programObject = GetValidProgram(context, program);
if (!programObject) if (!programObject)
{ {
if (context->getShader(program)) return GL_INVALID_INDEX;
{
context->recordError(Error(GL_INVALID_OPERATION));
return GL_INVALID_INDEX;
}
else
{
context->recordError(Error(GL_INVALID_VALUE));
return GL_INVALID_INDEX;
}
} }
return programObject->getUniformBlockIndex(uniformBlockName); return programObject->getUniformBlockIndex(uniformBlockName);
...@@ -2150,20 +2118,11 @@ void GL_APIENTRY GetActiveUniformBlockiv(GLuint program, GLuint uniformBlockInde ...@@ -2150,20 +2118,11 @@ void GL_APIENTRY GetActiveUniformBlockiv(GLuint program, GLuint uniformBlockInde
context->recordError(Error(GL_INVALID_OPERATION)); context->recordError(Error(GL_INVALID_OPERATION));
return; return;
} }
Program *programObject = context->getProgram(program); Program *programObject = GetValidProgram(context, program);
if (!programObject) if (!programObject)
{ {
if (context->getShader(program)) return;
{
context->recordError(Error(GL_INVALID_OPERATION));
return;
}
else
{
context->recordError(Error(GL_INVALID_VALUE));
return;
}
} }
if (uniformBlockIndex >= programObject->getActiveUniformBlockCount()) if (uniformBlockIndex >= programObject->getActiveUniformBlockCount())
...@@ -2208,20 +2167,11 @@ void GL_APIENTRY GetActiveUniformBlockName(GLuint program, GLuint uniformBlockIn ...@@ -2208,20 +2167,11 @@ void GL_APIENTRY GetActiveUniformBlockName(GLuint program, GLuint uniformBlockIn
return; return;
} }
Program *programObject = context->getProgram(program); Program *programObject = GetValidProgram(context, program);
if (!programObject) if (!programObject)
{ {
if (context->getShader(program)) return;
{
context->recordError(Error(GL_INVALID_OPERATION));
return;
}
else
{
context->recordError(Error(GL_INVALID_VALUE));
return;
}
} }
if (uniformBlockIndex >= programObject->getActiveUniformBlockCount()) if (uniformBlockIndex >= programObject->getActiveUniformBlockCount())
...@@ -2254,20 +2204,11 @@ void GL_APIENTRY UniformBlockBinding(GLuint program, GLuint uniformBlockIndex, G ...@@ -2254,20 +2204,11 @@ void GL_APIENTRY UniformBlockBinding(GLuint program, GLuint uniformBlockIndex, G
return; return;
} }
Program *programObject = context->getProgram(program); Program *programObject = GetValidProgram(context, program);
if (!programObject) if (!programObject)
{ {
if (context->getShader(program)) return;
{
context->recordError(Error(GL_INVALID_OPERATION));
return;
}
else
{
context->recordError(Error(GL_INVALID_VALUE));
return;
}
} }
// if never linked, there won't be any uniform blocks // if never linked, there won't be any uniform blocks
......
...@@ -244,11 +244,6 @@ ...@@ -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_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.depth_component_unsigned_int = FAIL
1028 WIN LINUX : dEQP-GLES2.functional.fbo.completeness.renderable.texture.depth.srgb8 = 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_tex2d = FAIL
1029 WIN LINUX : dEQP-GLES2.functional.negative_api.texture.compressedteximage_2d_invalid_format_cube = 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 1128 WIN LINUX : dEQP-GLES2.functional.negative_api.texture.compressedtexsubimage2d_invalid_size = FAIL
......
...@@ -1149,11 +1149,6 @@ ...@@ -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 = 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_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.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_buffer_pointerv = FAIL
1101 WIN : dEQP-GLES3.functional.negative_api.state.get_framebuffer_attachment_parameteriv = 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 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