Make compressed texture helpers more accessible * Moved 2D array and 3D format-specific functions to shared validation code. * Moved error generation to call sites. * Drive-by: disallowed cubemap arrays for formats that do not support 2D arrays. Bug: angleproject:518266751 Change-Id: I98d0b6f35e1f14dd034f8063fce43495c0e5586d Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/7967806 Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Alexey Knyazev <lexa.knyazev@gmail.com> Reviewed-by: Alexey Knyazev <lexa.knyazev@gmail.com>
diff --git a/src/libANGLE/validationES.cpp b/src/libANGLE/validationES.cpp index 743f8a7..7c35699 100644 --- a/src/libANGLE/validationES.cpp +++ b/src/libANGLE/validationES.cpp
@@ -1156,6 +1156,36 @@ return true; } +bool ValidCompressedFormatForTexture2DArray(GLenum format, const Extensions &extensions) +{ + if ((IsETC1Format(format) && !extensions.compressedETC1RGB8SubTextureEXT) || + IsPVRTC1Format(format)) + { + return false; + } + + return true; +} + +bool ValidCompressedFormatForTexture3D(GLenum format, const Extensions &extensions) +{ + if (IsASTC2DFormat(format)) + { + return extensions.textureCompressionAstcHdrKHR || + extensions.textureCompressionAstcSliced3dKHR; + } + + if (IsASTC3DFormat(format) || IsBPTCFormat(format)) + { + return true; + } + + // All other compressed formats are specified to not support 3D textures. + ASSERT((IsS3TCFormat(format) || IsRGTCFormat(format)) || + (IsETC1Format(format) || IsETC2EACFormat(format)) || IsPVRTC1Format(format)); + return false; +} + bool ValidCompressedImageSize(const Context *context, GLenum internalFormat, GLint level,
diff --git a/src/libANGLE/validationES.h b/src/libANGLE/validationES.h index c4d5c4d..d3cda8e 100644 --- a/src/libANGLE/validationES.h +++ b/src/libANGLE/validationES.h
@@ -59,6 +59,8 @@ GLsizei height, GLsizei depth, bool isSubImage); +bool ValidCompressedFormatForTexture2DArray(GLenum format, const Extensions &extensions); +bool ValidCompressedFormatForTexture3D(GLenum format, const Extensions &extensions); bool ValidCompressedImageSize(const Context *context, GLenum internalFormat, GLint level,
diff --git a/src/libANGLE/validationES3.cpp b/src/libANGLE/validationES3.cpp index 994a3e3..0901e5c 100644 --- a/src/libANGLE/validationES3.cpp +++ b/src/libANGLE/validationES3.cpp
@@ -354,39 +354,6 @@ return true; } -static bool ValidateES3CompressedFormatForTexture2DArray(const Context *context, - angle::EntryPoint entryPoint, - GLenum format) -{ - if ((IsETC1Format(format) && !context->getExtensions().compressedETC1RGB8SubTextureEXT) || - IsPVRTC1Format(format)) - { - ANGLE_VALIDATION_ERROR(GL_INVALID_OPERATION, kInternalFormatRequiresTexture2D); - return false; - } - - return true; -} - -static bool ValidCompressedFormatForTexture3D(GLenum format, const Extensions &extensions) -{ - if (IsASTC2DFormat(format)) - { - return extensions.textureCompressionAstcHdrKHR || - extensions.textureCompressionAstcSliced3dKHR; - } - - if (IsASTC3DFormat(format) || IsBPTCFormat(format)) - { - return true; - } - - // All other compressed formats are specified to not support 3D textures. - ASSERT((IsS3TCFormat(format) || IsRGTCFormat(format)) || - (IsETC1Format(format) || IsETC2EACFormat(format)) || IsPVRTC1Format(format)); - return false; -} - bool ValidateES3TexImageParametersBase(const Context *context, angle::EntryPoint entryPoint, TextureTarget target, @@ -615,13 +582,13 @@ } } - if (texType == TextureType::_2DArray) + if (texType == TextureType::_2DArray || texType == TextureType::CubeMapArray) { GLenum compressedDataFormat = isSubImage ? format : internalformat; - if (!ValidateES3CompressedFormatForTexture2DArray(context, entryPoint, - compressedDataFormat)) + if (!ValidCompressedFormatForTexture2DArray(compressedDataFormat, + context->getExtensions())) { - // Error already generated. + ANGLE_VALIDATION_ERROR(GL_INVALID_OPERATION, kInternalFormatRequiresTexture2D); return false; } } @@ -1519,12 +1486,12 @@ return false; } - if (target == TextureType::_2DArray) + if (target == TextureType::_2DArray || target == TextureType::CubeMapArray) { - if (!ValidateES3CompressedFormatForTexture2DArray(context, entryPoint, - formatInfo.internalFormat)) + if (!ValidCompressedFormatForTexture2DArray(formatInfo.internalFormat, + context->getExtensions())) { - // Error already generated. + ANGLE_VALIDATION_ERROR(GL_INVALID_OPERATION, kInternalFormatRequiresTexture2D); return false; } }