Commit 33b1e31e by Alexey Knyazev Committed by Commit Bot

Fix compressed formats validation with TEXTURE_3D

Bug: angleproject:4385 Change-Id: Ibc1b482ec851d8076aacad84ab67fe20a745c122 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2045512 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarJonah Ryan-Davis <jonahr@google.com>
parent cf03c7ae
...@@ -159,6 +159,9 @@ MSG kInsufficientParams = "More parameters are required than were provided."; ...@@ -159,6 +159,9 @@ MSG kInsufficientParams = "More parameters are required than were provided.";
MSG kInsufficientVertexBufferSize = "Vertex buffer is not big enough for the draw call"; MSG kInsufficientVertexBufferSize = "Vertex buffer is not big enough for the draw call";
MSG kIntegerOverflow = "Integer overflow."; MSG kIntegerOverflow = "Integer overflow.";
MSG kInternalFormatRequiresTexture2DArray = "internalformat is an ETC2/EAC format and target is not GL_TEXTURE_2D_ARRAY."; MSG kInternalFormatRequiresTexture2DArray = "internalformat is an ETC2/EAC format and target is not GL_TEXTURE_2D_ARRAY.";
MSG kInternalFormatRequiresTexture2DArrayS3TC = "internalformat is an S3TC format and target is not GL_TEXTURE_2D_ARRAY.";
MSG kInternalFormatRequiresTexture2DArrayRGTC = "internalformat is an RGTC format and target is not GL_TEXTURE_2D_ARRAY.";
MSG kInternalFormatRequiresTexture2DArrayASTC = "internalformat is an ASTC format and target is not GL_TEXTURE_2D_ARRAY.";
MSG kInvalidAccessBits = "Invalid access bits."; MSG kInvalidAccessBits = "Invalid access bits.";
MSG kInvalidAccessBitsFlush = "The explicit flushing bit may only be set if the buffer is mapped for writing."; MSG kInvalidAccessBitsFlush = "The explicit flushing bit may only be set if the buffer is mapped for writing.";
MSG kInvalidAccessBitsRead = "Invalid access bits when mapping buffer for reading"; MSG kInvalidAccessBitsRead = "Invalid access bits when mapping buffer for reading";
......
...@@ -324,6 +324,74 @@ angle::FormatID GetCurrentValueFormatID(VertexAttribType currentValueType); ...@@ -324,6 +324,74 @@ angle::FormatID GetCurrentValueFormatID(VertexAttribType currentValueType);
const VertexFormat &GetVertexFormatFromID(angle::FormatID vertexFormatID); const VertexFormat &GetVertexFormatFromID(angle::FormatID vertexFormatID);
size_t GetVertexFormatSize(angle::FormatID vertexFormatID); size_t GetVertexFormatSize(angle::FormatID vertexFormatID);
ANGLE_INLINE bool IsS3TCFormat(const GLenum format)
{
switch (format)
{
case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT:
case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT:
case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT:
case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT:
return true;
default:
return false;
}
}
ANGLE_INLINE bool IsRGTCFormat(const GLenum format)
{
switch (format)
{
case GL_COMPRESSED_RED_RGTC1_EXT:
case GL_COMPRESSED_SIGNED_RED_RGTC1_EXT:
case GL_COMPRESSED_RED_GREEN_RGTC2_EXT:
case GL_COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT:
return true;
default:
return false;
}
}
ANGLE_INLINE bool IsASTC2DFormat(const GLenum format)
{
if ((format >= GL_COMPRESSED_RGBA_ASTC_4x4_KHR &&
format <= GL_COMPRESSED_RGBA_ASTC_12x12_KHR) ||
(format >= GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR &&
format <= GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR))
{
return true;
}
return false;
}
ANGLE_INLINE bool IsETC2EACFormat(const GLenum format)
{
// ES 3.1, Table 8.19
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:
return true;
default:
return false;
}
}
// Check if an internal format is ever valid in ES3. Makes no checks about support for a specific // Check if an internal format is ever valid in ES3. Makes no checks about support for a specific
// context. // context.
bool ValidES3InternalFormat(GLenum internalFormat); bool ValidES3InternalFormat(GLenum internalFormat);
......
...@@ -477,28 +477,6 @@ void SetRobustLengthParam(GLsizei *length, GLsizei value) ...@@ -477,28 +477,6 @@ void SetRobustLengthParam(GLsizei *length, GLsizei value)
} }
} }
bool IsETC2EACFormat(const GLenum format)
{
// ES 3.1, Table 8.19
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:
return true;
default:
return false;
}
}
bool ValidTextureTarget(const Context *context, TextureType type) bool ValidTextureTarget(const Context *context, TextureType type)
{ {
switch (type) switch (type)
......
...@@ -37,7 +37,6 @@ class Program; ...@@ -37,7 +37,6 @@ class Program;
class Shader; class Shader;
void SetRobustLengthParam(GLsizei *length, GLsizei value); void SetRobustLengthParam(GLsizei *length, GLsizei value);
bool IsETC2EACFormat(const GLenum format);
bool ValidTextureTarget(const Context *context, TextureType type); bool ValidTextureTarget(const Context *context, TextureType type);
bool ValidTexture2DTarget(const Context *context, TextureType type); bool ValidTexture2DTarget(const Context *context, TextureType type);
bool ValidTexture3DTarget(const Context *context, TextureType target); bool ValidTexture3DTarget(const Context *context, TextureType target);
......
...@@ -346,6 +346,38 @@ static bool ValidateTexImageFormatCombination(gl::Context *context, ...@@ -346,6 +346,38 @@ static bool ValidateTexImageFormatCombination(gl::Context *context,
return true; return true;
} }
static bool ValidateES3CompressedFormatForTexture3D(Context *context, GLenum format)
{
if (IsETC2EACFormat(format))
{
// ES 3.1, Section 8.7, page 169.
context->validationError(GL_INVALID_OPERATION, kInternalFormatRequiresTexture2DArray);
return false;
}
if (IsASTC2DFormat(format) && !context->getExtensions().textureCompressionASTCHDRKHR)
{
// GL_KHR_texture_compression_astc_hdr, TEXTURE_3D is not supported without HDR profile
context->validationError(GL_INVALID_OPERATION, kInternalFormatRequiresTexture2DArrayASTC);
return false;
}
if (IsS3TCFormat(format))
{
// GL_EXT_texture_compression_s3tc
context->validationError(GL_INVALID_OPERATION, kInternalFormatRequiresTexture2DArrayS3TC);
return false;
}
if (IsRGTCFormat(format))
{
// GL_EXT_texture_compression_rgtc
context->validationError(GL_INVALID_OPERATION, kInternalFormatRequiresTexture2DArrayRGTC);
return false;
}
return true;
}
bool ValidateES3TexImageParametersBase(Context *context, bool ValidateES3TexImageParametersBase(Context *context,
TextureTarget target, TextureTarget target,
GLint level, GLint level,
...@@ -477,10 +509,9 @@ bool ValidateES3TexImageParametersBase(Context *context, ...@@ -477,10 +509,9 @@ bool ValidateES3TexImageParametersBase(Context *context,
if (isCompressed && texType == TextureType::_3D) if (isCompressed && texType == TextureType::_3D)
{ {
GLenum compressedDataFormat = isSubImage ? format : internalformat; GLenum compressedDataFormat = isSubImage ? format : internalformat;
if (IsETC2EACFormat(compressedDataFormat)) if (!ValidateES3CompressedFormatForTexture3D(context, compressedDataFormat))
{ {
// ES 3.1, Section 8.7, page 169. // Error already generated.
context->validationError(GL_INVALID_OPERATION, kInternalFormatRequiresTexture2DArray);
return false; return false;
} }
} }
...@@ -1209,8 +1240,11 @@ bool ValidateES3TexStorageParametersBase(Context *context, ...@@ -1209,8 +1240,11 @@ bool ValidateES3TexStorageParametersBase(Context *context,
if (formatInfo.compressed && target == TextureType::_3D) if (formatInfo.compressed && target == TextureType::_3D)
{ {
context->validationError(GL_INVALID_OPERATION, kInvalidTextureTarget); if (!ValidateES3CompressedFormatForTexture3D(context, formatInfo.internalFormat))
return false; {
// Error already generated.
return false;
}
} }
return true; 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