OSDN Git Service

glCompressedTexSub* validation fixes
authorAlexis Hetu <sugoi@google.com>
Tue, 21 Nov 2017 17:39:41 +0000 (12:39 -0500)
committerAlexis Hétu <sugoi@google.com>
Wed, 22 Nov 2017 14:51:00 +0000 (14:51 +0000)
- Added imageSize validation checks
- Added ETC2/EAC specific validations

Change-Id: I8671b08caecb7aaff0b42d6843d31738b54d0f5a
Reviewed-on: https://swiftshader-review.googlesource.com/14088
Tested-by: Alexis Hétu <sugoi@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
src/OpenGL/libGLESv2/libGLESv2.cpp
src/OpenGL/libGLESv2/libGLESv3.cpp

index 2ba9176..2ad5717 100644 (file)
@@ -947,9 +947,9 @@ void CompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yo
                return error(validationError);
        }
 
-       if(width == 0 || height == 0)
+       if(imageSize != egl::ComputeCompressedSize(width, height, format))
        {
-               return;
+               return error(GL_INVALID_VALUE);
        }
 
        es2::Context *context = es2::getContext();
@@ -6578,9 +6578,9 @@ void CompressedTexSubImage3DOES(GLenum target, GLint level, GLint xoffset, GLint
                return error(validationError);
        }
 
-       if(width == 0 || height == 0 || depth == 0)
+       if(imageSize != egl::ComputeCompressedSize(width, height, format) * depth)
        {
-               return;
+               return error(GL_INVALID_VALUE);
        }
 
        es2::Context *context = es2::getContext();
index ce5872a..92813e2 100644 (file)
@@ -912,9 +912,39 @@ GL_APICALL void GL_APIENTRY glCompressedTexSubImage3D(GLenum target, GLint level
                return error(validationError);
        }
 
-       if(width == 0 || height == 0 || depth == 0)
+       if(imageSize != egl::ComputeCompressedSize(width, height, format) * depth)
        {
-               return;
+               return error(GL_INVALID_VALUE);
+       }
+
+       bool is_ETC2_EAC = false;
+       switch(format)
+       {
+       case GL_COMPRESSED_R11_EAC:
+       case GL_COMPRESSED_SIGNED_R11_EAC:
+       case GL_COMPRESSED_RG11_EAC:
+       case GL_COMPRESSED_SIGNED_RG11_EAC:
+       case GL_COMPRESSED_RGB8_ETC2:
+       case GL_COMPRESSED_SRGB8_ETC2:
+       case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2:
+       case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:
+       case GL_COMPRESSED_RGBA8_ETC2_EAC:
+       case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:
+               if(target != GL_TEXTURE_2D_ARRAY)
+               {
+                       return error(GL_INVALID_OPERATION);
+               }
+
+               if(((width  % 4) != 0) || ((height % 4) != 0) ||
+                  ((xoffset % 4) != 0) || ((yoffset % 4) != 0))
+               {
+                       return error(GL_INVALID_OPERATION);
+               }
+
+               is_ETC2_EAC = true;
+               break;
+       default:
+               break;
        }
 
        es2::Context *context = es2::getContext();
@@ -934,6 +964,15 @@ GL_APICALL void GL_APIENTRY glCompressedTexSubImage3D(GLenum target, GLint level
                        return error(validationError);
                }
 
+               if(is_ETC2_EAC)
+               {
+                       if(((width + xoffset) != texture->getWidth(target, level)) ||
+                          ((height + yoffset) != texture->getHeight(target, level)))
+                       {
+                               return error(GL_INVALID_OPERATION);
+                       }
+               }
+
                texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data);
        }
 }