From becd5d53015521acf7536ba754de326d8b1da2f3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Mika=20Isoj=C3=A4rvi?= Date: Tue, 4 Nov 2014 17:30:50 +0200 Subject: [PATCH] Add support for compressed 3D/2D array textures. Add support for 3D and 2D array textures to tcu::CompressedTexture. Also cleaned up the tcuCompressedTexture.hpp/.cpp. Change-Id: I407e04f72d4dbc4e705d26600fbf03607a6c4ea2 --- framework/common/tcuCompressedTexture.cpp | 1071 ++++++++++---------- framework/common/tcuCompressedTexture.hpp | 142 +-- framework/common/tcuImageIO.cpp | 2 +- framework/common/tcuTexture.hpp | 64 +- framework/common/tcuTextureUtil.cpp | 49 +- framework/common/tcuTextureUtil.hpp | 3 + framework/opengl/gluTexture.cpp | 68 +- framework/opengl/gluTexture.hpp | 15 +- framework/opengl/gluTextureUtil.cpp | 82 +- framework/opengl/gluTextureUtil.hpp | 2 +- .../functional/es3fASTCDecompressionCases.cpp | 95 +- .../functional/es3fASTCDecompressionCases.hpp | 22 +- .../functional/es3fCompressedTextureTests.cpp | 23 +- .../gles3/functional/es3fTextureFormatTests.cpp | 103 +- modules/gles3/functional/es3fTextureWrapTests.cpp | 55 +- 15 files changed, 952 insertions(+), 844 deletions(-) diff --git a/framework/common/tcuCompressedTexture.cpp b/framework/common/tcuCompressedTexture.cpp index 4767436..9bbf55c 100644 --- a/framework/common/tcuCompressedTexture.cpp +++ b/framework/common/tcuCompressedTexture.cpp @@ -23,6 +23,7 @@ #include "tcuCompressedTexture.hpp" #include "tcuTextureUtil.hpp" + #include "deStringUtil.hpp" #include "deFloat16.h" @@ -31,6 +32,9 @@ namespace tcu { +namespace +{ + enum { ASTC_BLOCK_SIZE_BYTES = 128/8 }; template @@ -38,47 +42,108 @@ struct isSameType { enum { V = 0 }; }; template struct isSameType { enum { V = 1 }; }; -CompressedTexture::CompressedTexture (void) - : m_format (FORMAT_LAST) - , m_width (0) - , m_height (0) - , m_depth (0) -{ -} +} // anonymous -CompressedTexture::CompressedTexture (Format format, int width, int height, int depth) - : m_format (FORMAT_LAST) - , m_width (0) - , m_height (0) - , m_depth (0) +int getBlockSize (CompressedTexFormat format) { - setStorage(format, width, height, depth); -} + if (isAstcFormat(format)) + { + return ASTC_BLOCK_SIZE_BYTES; + } + else if (isEtcFormat(format)) + { + switch (format) + { + case COMPRESSEDTEXFORMAT_ETC1_RGB8: return 8; + case COMPRESSEDTEXFORMAT_EAC_R11: return 8; + case COMPRESSEDTEXFORMAT_EAC_SIGNED_R11: return 8; + case COMPRESSEDTEXFORMAT_EAC_RG11: return 16; + case COMPRESSEDTEXFORMAT_EAC_SIGNED_RG11: return 16; + case COMPRESSEDTEXFORMAT_ETC2_RGB8: return 8; + case COMPRESSEDTEXFORMAT_ETC2_SRGB8: return 8; + case COMPRESSEDTEXFORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1: return 8; + case COMPRESSEDTEXFORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1: return 8; + case COMPRESSEDTEXFORMAT_ETC2_EAC_RGBA8: return 16; + case COMPRESSEDTEXFORMAT_ETC2_EAC_SRGB8_ALPHA8: return 16; -CompressedTexture::~CompressedTexture (void) -{ + default: + DE_ASSERT(false); + return -1; + } + } + else + { + DE_ASSERT(false); + return -1; + } } -static inline int divRoundUp (int a, int b) +IVec3 getBlockPixelSize (CompressedTexFormat format) { - return a/b + ((a%b) ? 1 : 0); + if (isEtcFormat(format)) + { + return IVec3(4, 4, 1); + } + else if (isAstcFormat(format)) + { + switch (format) + { + case COMPRESSEDTEXFORMAT_ASTC_4x4_RGBA: return IVec3(4, 4, 1); + case COMPRESSEDTEXFORMAT_ASTC_5x4_RGBA: return IVec3(5, 4, 1); + case COMPRESSEDTEXFORMAT_ASTC_5x5_RGBA: return IVec3(5, 5, 1); + case COMPRESSEDTEXFORMAT_ASTC_6x5_RGBA: return IVec3(6, 5, 1); + case COMPRESSEDTEXFORMAT_ASTC_6x6_RGBA: return IVec3(6, 6, 1); + case COMPRESSEDTEXFORMAT_ASTC_8x5_RGBA: return IVec3(8, 5, 1); + case COMPRESSEDTEXFORMAT_ASTC_8x6_RGBA: return IVec3(8, 6, 1); + case COMPRESSEDTEXFORMAT_ASTC_8x8_RGBA: return IVec3(8, 8, 1); + case COMPRESSEDTEXFORMAT_ASTC_10x5_RGBA: return IVec3(10, 5, 1); + case COMPRESSEDTEXFORMAT_ASTC_10x6_RGBA: return IVec3(10, 6, 1); + case COMPRESSEDTEXFORMAT_ASTC_10x8_RGBA: return IVec3(10, 8, 1); + case COMPRESSEDTEXFORMAT_ASTC_10x10_RGBA: return IVec3(10, 10, 1); + case COMPRESSEDTEXFORMAT_ASTC_12x10_RGBA: return IVec3(12, 10, 1); + case COMPRESSEDTEXFORMAT_ASTC_12x12_RGBA: return IVec3(12, 12, 1); + case COMPRESSEDTEXFORMAT_ASTC_4x4_SRGB8_ALPHA8: return IVec3(4, 4, 1); + case COMPRESSEDTEXFORMAT_ASTC_5x4_SRGB8_ALPHA8: return IVec3(5, 4, 1); + case COMPRESSEDTEXFORMAT_ASTC_5x5_SRGB8_ALPHA8: return IVec3(5, 5, 1); + case COMPRESSEDTEXFORMAT_ASTC_6x5_SRGB8_ALPHA8: return IVec3(6, 5, 1); + case COMPRESSEDTEXFORMAT_ASTC_6x6_SRGB8_ALPHA8: return IVec3(6, 6, 1); + case COMPRESSEDTEXFORMAT_ASTC_8x5_SRGB8_ALPHA8: return IVec3(8, 5, 1); + case COMPRESSEDTEXFORMAT_ASTC_8x6_SRGB8_ALPHA8: return IVec3(8, 6, 1); + case COMPRESSEDTEXFORMAT_ASTC_8x8_SRGB8_ALPHA8: return IVec3(8, 8, 1); + case COMPRESSEDTEXFORMAT_ASTC_10x5_SRGB8_ALPHA8: return IVec3(10, 5, 1); + case COMPRESSEDTEXFORMAT_ASTC_10x6_SRGB8_ALPHA8: return IVec3(10, 6, 1); + case COMPRESSEDTEXFORMAT_ASTC_10x8_SRGB8_ALPHA8: return IVec3(10, 8, 1); + case COMPRESSEDTEXFORMAT_ASTC_10x10_SRGB8_ALPHA8: return IVec3(10, 10, 1); + case COMPRESSEDTEXFORMAT_ASTC_12x10_SRGB8_ALPHA8: return IVec3(12, 10, 1); + case COMPRESSEDTEXFORMAT_ASTC_12x12_SRGB8_ALPHA8: return IVec3(12, 12, 1); + + default: + DE_ASSERT(false); + return IVec3(); + } + } + else + { + DE_ASSERT(false); + return IVec3(-1); + } } -bool isEtcFormat (CompressedTexture::Format fmt) +bool isEtcFormat (CompressedTexFormat format) { - switch (fmt) + switch (format) { - case CompressedTexture::ETC1_RGB8: - case CompressedTexture::EAC_R11: - case CompressedTexture::EAC_SIGNED_R11: - case CompressedTexture::EAC_RG11: - case CompressedTexture::EAC_SIGNED_RG11: - case CompressedTexture::ETC2_RGB8: - case CompressedTexture::ETC2_SRGB8: - case CompressedTexture::ETC2_RGB8_PUNCHTHROUGH_ALPHA1: - case CompressedTexture::ETC2_SRGB8_PUNCHTHROUGH_ALPHA1: - case CompressedTexture::ETC2_EAC_RGBA8: - case CompressedTexture::ETC2_EAC_SRGB8_ALPHA8: + case COMPRESSEDTEXFORMAT_ETC1_RGB8: + case COMPRESSEDTEXFORMAT_EAC_R11: + case COMPRESSEDTEXFORMAT_EAC_SIGNED_R11: + case COMPRESSEDTEXFORMAT_EAC_RG11: + case COMPRESSEDTEXFORMAT_EAC_SIGNED_RG11: + case COMPRESSEDTEXFORMAT_ETC2_RGB8: + case COMPRESSEDTEXFORMAT_ETC2_SRGB8: + case COMPRESSEDTEXFORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1: + case COMPRESSEDTEXFORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1: + case COMPRESSEDTEXFORMAT_ETC2_EAC_RGBA8: + case COMPRESSEDTEXFORMAT_ETC2_EAC_SRGB8_ALPHA8: return true; default: @@ -86,38 +151,38 @@ bool isEtcFormat (CompressedTexture::Format fmt) } } -bool isASTCFormat (CompressedTexture::Format fmt) -{ - switch (fmt) - { - case CompressedTexture::ASTC_4x4_RGBA: - case CompressedTexture::ASTC_5x4_RGBA: - case CompressedTexture::ASTC_5x5_RGBA: - case CompressedTexture::ASTC_6x5_RGBA: - case CompressedTexture::ASTC_6x6_RGBA: - case CompressedTexture::ASTC_8x5_RGBA: - case CompressedTexture::ASTC_8x6_RGBA: - case CompressedTexture::ASTC_8x8_RGBA: - case CompressedTexture::ASTC_10x5_RGBA: - case CompressedTexture::ASTC_10x6_RGBA: - case CompressedTexture::ASTC_10x8_RGBA: - case CompressedTexture::ASTC_10x10_RGBA: - case CompressedTexture::ASTC_12x10_RGBA: - case CompressedTexture::ASTC_12x12_RGBA: - case CompressedTexture::ASTC_4x4_SRGB8_ALPHA8: - case CompressedTexture::ASTC_5x4_SRGB8_ALPHA8: - case CompressedTexture::ASTC_5x5_SRGB8_ALPHA8: - case CompressedTexture::ASTC_6x5_SRGB8_ALPHA8: - case CompressedTexture::ASTC_6x6_SRGB8_ALPHA8: - case CompressedTexture::ASTC_8x5_SRGB8_ALPHA8: - case CompressedTexture::ASTC_8x6_SRGB8_ALPHA8: - case CompressedTexture::ASTC_8x8_SRGB8_ALPHA8: - case CompressedTexture::ASTC_10x5_SRGB8_ALPHA8: - case CompressedTexture::ASTC_10x6_SRGB8_ALPHA8: - case CompressedTexture::ASTC_10x8_SRGB8_ALPHA8: - case CompressedTexture::ASTC_10x10_SRGB8_ALPHA8: - case CompressedTexture::ASTC_12x10_SRGB8_ALPHA8: - case CompressedTexture::ASTC_12x12_SRGB8_ALPHA8: +bool isAstcFormat (CompressedTexFormat format) +{ + switch (format) + { + case COMPRESSEDTEXFORMAT_ASTC_4x4_RGBA: + case COMPRESSEDTEXFORMAT_ASTC_5x4_RGBA: + case COMPRESSEDTEXFORMAT_ASTC_5x5_RGBA: + case COMPRESSEDTEXFORMAT_ASTC_6x5_RGBA: + case COMPRESSEDTEXFORMAT_ASTC_6x6_RGBA: + case COMPRESSEDTEXFORMAT_ASTC_8x5_RGBA: + case COMPRESSEDTEXFORMAT_ASTC_8x6_RGBA: + case COMPRESSEDTEXFORMAT_ASTC_8x8_RGBA: + case COMPRESSEDTEXFORMAT_ASTC_10x5_RGBA: + case COMPRESSEDTEXFORMAT_ASTC_10x6_RGBA: + case COMPRESSEDTEXFORMAT_ASTC_10x8_RGBA: + case COMPRESSEDTEXFORMAT_ASTC_10x10_RGBA: + case COMPRESSEDTEXFORMAT_ASTC_12x10_RGBA: + case COMPRESSEDTEXFORMAT_ASTC_12x12_RGBA: + case COMPRESSEDTEXFORMAT_ASTC_4x4_SRGB8_ALPHA8: + case COMPRESSEDTEXFORMAT_ASTC_5x4_SRGB8_ALPHA8: + case COMPRESSEDTEXFORMAT_ASTC_5x5_SRGB8_ALPHA8: + case COMPRESSEDTEXFORMAT_ASTC_6x5_SRGB8_ALPHA8: + case COMPRESSEDTEXFORMAT_ASTC_6x6_SRGB8_ALPHA8: + case COMPRESSEDTEXFORMAT_ASTC_8x5_SRGB8_ALPHA8: + case COMPRESSEDTEXFORMAT_ASTC_8x6_SRGB8_ALPHA8: + case COMPRESSEDTEXFORMAT_ASTC_8x8_SRGB8_ALPHA8: + case COMPRESSEDTEXFORMAT_ASTC_10x5_SRGB8_ALPHA8: + case COMPRESSEDTEXFORMAT_ASTC_10x6_SRGB8_ALPHA8: + case COMPRESSEDTEXFORMAT_ASTC_10x8_SRGB8_ALPHA8: + case COMPRESSEDTEXFORMAT_ASTC_10x10_SRGB8_ALPHA8: + case COMPRESSEDTEXFORMAT_ASTC_12x10_SRGB8_ALPHA8: + case COMPRESSEDTEXFORMAT_ASTC_12x12_SRGB8_ALPHA8: return true; default: @@ -125,24 +190,24 @@ bool isASTCFormat (CompressedTexture::Format fmt) } } -bool isASTCSRGBFormat (CompressedTexture::Format fmt) +bool isAstcSRGBFormat (CompressedTexFormat format) { - switch (fmt) + switch (format) { - case CompressedTexture::ASTC_4x4_SRGB8_ALPHA8: - case CompressedTexture::ASTC_5x4_SRGB8_ALPHA8: - case CompressedTexture::ASTC_5x5_SRGB8_ALPHA8: - case CompressedTexture::ASTC_6x5_SRGB8_ALPHA8: - case CompressedTexture::ASTC_6x6_SRGB8_ALPHA8: - case CompressedTexture::ASTC_8x5_SRGB8_ALPHA8: - case CompressedTexture::ASTC_8x6_SRGB8_ALPHA8: - case CompressedTexture::ASTC_8x8_SRGB8_ALPHA8: - case CompressedTexture::ASTC_10x5_SRGB8_ALPHA8: - case CompressedTexture::ASTC_10x6_SRGB8_ALPHA8: - case CompressedTexture::ASTC_10x8_SRGB8_ALPHA8: - case CompressedTexture::ASTC_10x10_SRGB8_ALPHA8: - case CompressedTexture::ASTC_12x10_SRGB8_ALPHA8: - case CompressedTexture::ASTC_12x12_SRGB8_ALPHA8: + case COMPRESSEDTEXFORMAT_ASTC_4x4_SRGB8_ALPHA8: + case COMPRESSEDTEXFORMAT_ASTC_5x4_SRGB8_ALPHA8: + case COMPRESSEDTEXFORMAT_ASTC_5x5_SRGB8_ALPHA8: + case COMPRESSEDTEXFORMAT_ASTC_6x5_SRGB8_ALPHA8: + case COMPRESSEDTEXFORMAT_ASTC_6x6_SRGB8_ALPHA8: + case COMPRESSEDTEXFORMAT_ASTC_8x5_SRGB8_ALPHA8: + case COMPRESSEDTEXFORMAT_ASTC_8x6_SRGB8_ALPHA8: + case COMPRESSEDTEXFORMAT_ASTC_8x8_SRGB8_ALPHA8: + case COMPRESSEDTEXFORMAT_ASTC_10x5_SRGB8_ALPHA8: + case COMPRESSEDTEXFORMAT_ASTC_10x6_SRGB8_ALPHA8: + case COMPRESSEDTEXFORMAT_ASTC_10x8_SRGB8_ALPHA8: + case COMPRESSEDTEXFORMAT_ASTC_10x10_SRGB8_ALPHA8: + case COMPRESSEDTEXFORMAT_ASTC_12x10_SRGB8_ALPHA8: + case COMPRESSEDTEXFORMAT_ASTC_12x12_SRGB8_ALPHA8: return true; default: @@ -150,141 +215,32 @@ bool isASTCSRGBFormat (CompressedTexture::Format fmt) } } -IVec3 getASTCBlockSize (CompressedTexture::Format fmt) -{ - switch (fmt) - { - case CompressedTexture::ASTC_4x4_RGBA: return IVec3(4, 4, 1); - case CompressedTexture::ASTC_5x4_RGBA: return IVec3(5, 4, 1); - case CompressedTexture::ASTC_5x5_RGBA: return IVec3(5, 5, 1); - case CompressedTexture::ASTC_6x5_RGBA: return IVec3(6, 5, 1); - case CompressedTexture::ASTC_6x6_RGBA: return IVec3(6, 6, 1); - case CompressedTexture::ASTC_8x5_RGBA: return IVec3(8, 5, 1); - case CompressedTexture::ASTC_8x6_RGBA: return IVec3(8, 6, 1); - case CompressedTexture::ASTC_8x8_RGBA: return IVec3(8, 8, 1); - case CompressedTexture::ASTC_10x5_RGBA: return IVec3(10, 5, 1); - case CompressedTexture::ASTC_10x6_RGBA: return IVec3(10, 6, 1); - case CompressedTexture::ASTC_10x8_RGBA: return IVec3(10, 8, 1); - case CompressedTexture::ASTC_10x10_RGBA: return IVec3(10, 10, 1); - case CompressedTexture::ASTC_12x10_RGBA: return IVec3(12, 10, 1); - case CompressedTexture::ASTC_12x12_RGBA: return IVec3(12, 12, 1); - case CompressedTexture::ASTC_4x4_SRGB8_ALPHA8: return IVec3(4, 4, 1); - case CompressedTexture::ASTC_5x4_SRGB8_ALPHA8: return IVec3(5, 4, 1); - case CompressedTexture::ASTC_5x5_SRGB8_ALPHA8: return IVec3(5, 5, 1); - case CompressedTexture::ASTC_6x5_SRGB8_ALPHA8: return IVec3(6, 5, 1); - case CompressedTexture::ASTC_6x6_SRGB8_ALPHA8: return IVec3(6, 6, 1); - case CompressedTexture::ASTC_8x5_SRGB8_ALPHA8: return IVec3(8, 5, 1); - case CompressedTexture::ASTC_8x6_SRGB8_ALPHA8: return IVec3(8, 6, 1); - case CompressedTexture::ASTC_8x8_SRGB8_ALPHA8: return IVec3(8, 8, 1); - case CompressedTexture::ASTC_10x5_SRGB8_ALPHA8: return IVec3(10, 5, 1); - case CompressedTexture::ASTC_10x6_SRGB8_ALPHA8: return IVec3(10, 6, 1); - case CompressedTexture::ASTC_10x8_SRGB8_ALPHA8: return IVec3(10, 8, 1); - case CompressedTexture::ASTC_10x10_SRGB8_ALPHA8: return IVec3(10, 10, 1); - case CompressedTexture::ASTC_12x10_SRGB8_ALPHA8: return IVec3(12, 10, 1); - case CompressedTexture::ASTC_12x12_SRGB8_ALPHA8: return IVec3(12, 12, 1); - - default: - DE_ASSERT(false); - return IVec3(); - } -} - -CompressedTexture::Format getASTCFormatByBlockSize (int width, int height, int depth, bool isSRGB) +TextureFormat getUncompressedFormat (CompressedTexFormat format) { - if (depth > 1) - throw tcu::InternalError("3D ASTC textures not currently supported"); - - const tcu::IVec3 size(width, height, depth); - - for (int fmtI = 0; fmtI < CompressedTexture::FORMAT_LAST; fmtI++) - { - const CompressedTexture::Format fmt = (CompressedTexture::Format)fmtI; - - if (isASTCFormat(fmt) && getASTCBlockSize(fmt) == size && isASTCSRGBFormat(fmt) == isSRGB) - return fmt; - } - - throw tcu::InternalError("Invalid ASTC block size " + de::toString(width) + "x" + de::toString(height) + "x" + de::toString(depth)); -} - -void CompressedTexture::setStorage (Format format, int width, int height, int depth) -{ - m_format = format; - m_width = width; - m_height = height; - m_depth = depth; - - if (isEtcFormat(m_format)) + if (isEtcFormat(format)) { - DE_ASSERT(m_depth == 1); - - int blockSizeMultiplier = 0; // How many 64-bit parts each compressed block contains. - - switch (m_format) + switch (format) { - case ETC1_RGB8: blockSizeMultiplier = 1; break; - case EAC_R11: blockSizeMultiplier = 1; break; - case EAC_SIGNED_R11: blockSizeMultiplier = 1; break; - case EAC_RG11: blockSizeMultiplier = 2; break; - case EAC_SIGNED_RG11: blockSizeMultiplier = 2; break; - case ETC2_RGB8: blockSizeMultiplier = 1; break; - case ETC2_SRGB8: blockSizeMultiplier = 1; break; - case ETC2_RGB8_PUNCHTHROUGH_ALPHA1: blockSizeMultiplier = 1; break; - case ETC2_SRGB8_PUNCHTHROUGH_ALPHA1: blockSizeMultiplier = 1; break; - case ETC2_EAC_RGBA8: blockSizeMultiplier = 2; break; - case ETC2_EAC_SRGB8_ALPHA8: blockSizeMultiplier = 2; break; + case COMPRESSEDTEXFORMAT_ETC1_RGB8: return TextureFormat(TextureFormat::RGB, TextureFormat::UNORM_INT8); + case COMPRESSEDTEXFORMAT_EAC_R11: return TextureFormat(TextureFormat::R, TextureFormat::UNORM_INT16); + case COMPRESSEDTEXFORMAT_EAC_SIGNED_R11: return TextureFormat(TextureFormat::R, TextureFormat::SNORM_INT16); + case COMPRESSEDTEXFORMAT_EAC_RG11: return TextureFormat(TextureFormat::RG, TextureFormat::UNORM_INT16); + case COMPRESSEDTEXFORMAT_EAC_SIGNED_RG11: return TextureFormat(TextureFormat::RG, TextureFormat::SNORM_INT16); + case COMPRESSEDTEXFORMAT_ETC2_RGB8: return TextureFormat(TextureFormat::RGB, TextureFormat::UNORM_INT8); + case COMPRESSEDTEXFORMAT_ETC2_SRGB8: return TextureFormat(TextureFormat::sRGB, TextureFormat::UNORM_INT8); + case COMPRESSEDTEXFORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1: return TextureFormat(TextureFormat::RGBA, TextureFormat::UNORM_INT8); + case COMPRESSEDTEXFORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1: return TextureFormat(TextureFormat::sRGBA, TextureFormat::UNORM_INT8); + case COMPRESSEDTEXFORMAT_ETC2_EAC_RGBA8: return TextureFormat(TextureFormat::RGBA, TextureFormat::UNORM_INT8); + case COMPRESSEDTEXFORMAT_ETC2_EAC_SRGB8_ALPHA8: return TextureFormat(TextureFormat::sRGBA, TextureFormat::UNORM_INT8); default: DE_ASSERT(false); - break; - } - - m_data.resize(blockSizeMultiplier * sizeof(deUint64) * divRoundUp(m_width, 4) * divRoundUp(m_height, 4)); - } - else if (isASTCFormat(m_format)) - { - if (m_depth > 1) - throw tcu::InternalError("3D ASTC textures not currently supported"); - - const IVec3 blockSize = getASTCBlockSize(m_format); - m_data.resize(ASTC_BLOCK_SIZE_BYTES * divRoundUp(m_width, blockSize.x()) * divRoundUp(m_height, blockSize.y()) * divRoundUp(m_depth, blockSize.z())); - } - else - { - DE_ASSERT(m_format == FORMAT_LAST); - DE_ASSERT(m_width == 0 && m_height == 0 && m_depth == 0); - m_data.resize(0); - } -} - -/*--------------------------------------------------------------------*//*! - * \brief Get uncompressed texture format - *//*--------------------------------------------------------------------*/ -TextureFormat CompressedTexture::getUncompressedFormat (void) const -{ - if (isEtcFormat(m_format)) - { - switch (m_format) - { - case ETC1_RGB8: return TextureFormat(TextureFormat::RGB, TextureFormat::UNORM_INT8); - case EAC_R11: return TextureFormat(TextureFormat::R, TextureFormat::UNORM_INT16); - case EAC_SIGNED_R11: return TextureFormat(TextureFormat::R, TextureFormat::SNORM_INT16); - case EAC_RG11: return TextureFormat(TextureFormat::RG, TextureFormat::UNORM_INT16); - case EAC_SIGNED_RG11: return TextureFormat(TextureFormat::RG, TextureFormat::SNORM_INT16); - case ETC2_RGB8: return TextureFormat(TextureFormat::RGB, TextureFormat::UNORM_INT8); - case ETC2_SRGB8: return TextureFormat(TextureFormat::sRGB, TextureFormat::UNORM_INT8); - case ETC2_RGB8_PUNCHTHROUGH_ALPHA1: return TextureFormat(TextureFormat::RGBA, TextureFormat::UNORM_INT8); - case ETC2_SRGB8_PUNCHTHROUGH_ALPHA1: return TextureFormat(TextureFormat::sRGBA, TextureFormat::UNORM_INT8); - case ETC2_EAC_RGBA8: return TextureFormat(TextureFormat::RGBA, TextureFormat::UNORM_INT8); - case ETC2_EAC_SRGB8_ALPHA8: return TextureFormat(TextureFormat::sRGBA, TextureFormat::UNORM_INT8); - default: - DE_ASSERT(false); return TextureFormat(); } } - else if (isASTCFormat(m_format)) + else if (isAstcFormat(format)) { - if (isASTCSRGBFormat(m_format)) + if (isAstcSRGBFormat(format)) return TextureFormat(TextureFormat::sRGBA, TextureFormat::UNORM_INT8); else return TextureFormat(TextureFormat::RGBA, TextureFormat::HALF_FLOAT); @@ -296,6 +252,30 @@ TextureFormat CompressedTexture::getUncompressedFormat (void) const } } +CompressedTexFormat getAstcFormatByBlockSize (const IVec3& size, bool isSRGB) +{ + if (size.z() > 1) + throw InternalError("3D ASTC textures not currently supported"); + + for (int fmtI = 0; fmtI < COMPRESSEDTEXFORMAT_LAST; fmtI++) + { + const CompressedTexFormat fmt = (CompressedTexFormat)fmtI; + + if (isAstcFormat(fmt) && getBlockPixelSize(fmt) == size && isAstcSRGBFormat(fmt) == isSRGB) + return fmt; + } + + throw InternalError("Invalid ASTC block size " + de::toString(size.x()) + "x" + de::toString(size.y()) + "x" + de::toString(size.z())); +} + +namespace +{ + +inline int divRoundUp (int a, int b) +{ + return a/b + ((a%b) ? 1 : 0); +} + // \todo [2013-08-06 nuutti] ETC and ASTC decompression codes are rather unrelated, and are already in their own "private" namespaces - should this be split to multiple files? namespace EtcDecompressInternal @@ -317,82 +297,84 @@ enum ETC2_UNCOMPRESSED_BLOCK_SIZE_RGBA8 = ETC2_BLOCK_WIDTH*ETC2_BLOCK_HEIGHT*ETC2_UNCOMPRESSED_PIXEL_SIZE_RGBA8 }; -static inline deUint64 get64BitBlock (const deUint8* src, int blockNdx) +inline deUint64 get64BitBlock (const deUint8* src, int blockNdx) { // Stored in big-endian form. deUint64 block = 0; + for (int i = 0; i < 8; i++) block = (block << 8ull) | (deUint64)(src[blockNdx*8+i]); + return block; } // Return the first 64 bits of a 128 bit block. -static inline deUint64 get128BitBlockStart (const deUint8* src, int blockNdx) +inline deUint64 get128BitBlockStart (const deUint8* src, int blockNdx) { return get64BitBlock(src, 2*blockNdx); } // Return the last 64 bits of a 128 bit block. -static inline deUint64 get128BitBlockEnd (const deUint8* src, int blockNdx) +inline deUint64 get128BitBlockEnd (const deUint8* src, int blockNdx) { return get64BitBlock(src, 2*blockNdx + 1); } -static inline deUint32 getBit (deUint64 src, int bit) +inline deUint32 getBit (deUint64 src, int bit) { return (src >> bit) & 1; } -static inline deUint32 getBits (deUint64 src, int low, int high) +inline deUint32 getBits (deUint64 src, int low, int high) { const int numBits = (high-low) + 1; DE_ASSERT(de::inRange(numBits, 1, 32)); return (src >> low) & ((1<> 2); } -static inline deUint8 extend6To8 (deUint8 src) +inline deUint8 extend6To8 (deUint8 src) { DE_ASSERT((src & ~((1<<6)-1)) == 0); return (src << 2) | (src >> 4); } -static inline deUint8 extend7To8 (deUint8 src) +inline deUint8 extend7To8 (deUint8 src) { DE_ASSERT((src & ~((1<<7)-1)) == 0); return (src << 1) | (src >> 6); } -static inline deInt8 extendSigned3To8 (deUint8 src) +inline deInt8 extendSigned3To8 (deUint8 src) { const bool isNeg = (src & (1<<2)) != 0; return (deInt8)((isNeg ? ~((1<<3)-1) : 0) | src); } -static inline deUint8 extend5Delta3To8 (deUint8 base5, deUint8 delta3) +inline deUint8 extend5Delta3To8 (deUint8 base5, deUint8 delta3) { const deUint8 t = (deUint8)((deInt8)base5 + extendSigned3To8(delta3)); return extend5To8(t); } -static inline deUint16 extend11To16 (deUint16 src) +inline deUint16 extend11To16 (deUint16 src) { DE_ASSERT((src & ~((1<<11)-1)) == 0); return (src << 5) | (src >> 6); } -static inline deInt16 extend11To16WithSign (deInt16 src) +inline deInt16 extend11To16WithSign (deInt16 src) { if (src < 0) return -(deInt16)extend11To16(-src); @@ -400,7 +382,7 @@ static inline deInt16 extend11To16WithSign (deInt16 src) return (deInt16)extend11To16(src); } -static void decompressETC1Block (deUint8 dst[ETC2_UNCOMPRESSED_BLOCK_SIZE_RGB8], deUint64 src) +void decompressETC1Block (deUint8 dst[ETC2_UNCOMPRESSED_BLOCK_SIZE_RGB8], deUint64 src) { const int diffBit = (int)getBit(src, 33); const int flipBit = (int)getBit(src, 32); @@ -469,7 +451,7 @@ static void decompressETC1Block (deUint8 dst[ETC2_UNCOMPRESSED_BLOCK_SIZE_RGB8], } // if alphaMode is true, do PUNCHTHROUGH and store alpha to alphaDst; otherwise do ordinary ETC2 RGB8. -static void decompressETC2Block (deUint8 dst[ETC2_UNCOMPRESSED_BLOCK_SIZE_RGB8], deUint64 src, deUint8 alphaDst[ETC2_UNCOMPRESSED_BLOCK_SIZE_A8], bool alphaMode) +void decompressETC2Block (deUint8 dst[ETC2_UNCOMPRESSED_BLOCK_SIZE_RGB8], deUint64 src, deUint8 alphaDst[ETC2_UNCOMPRESSED_BLOCK_SIZE_A8], bool alphaMode) { enum Etc2Mode { @@ -731,7 +713,7 @@ static void decompressETC2Block (deUint8 dst[ETC2_UNCOMPRESSED_BLOCK_SIZE_RGB8], } } -static void decompressEAC8Block (deUint8 dst[ETC2_UNCOMPRESSED_BLOCK_SIZE_A8], deUint64 src) +void decompressEAC8Block (deUint8 dst[ETC2_UNCOMPRESSED_BLOCK_SIZE_A8], deUint64 src) { static const int modifierTable[16][8] = { @@ -770,7 +752,7 @@ static void decompressEAC8Block (deUint8 dst[ETC2_UNCOMPRESSED_BLOCK_SIZE_A8], d } } -static void decompressEAC11Block (deUint8 dst[ETC2_UNCOMPRESSED_BLOCK_SIZE_R11], deUint64 src, bool signedMode) +void decompressEAC11Block (deUint8 dst[ETC2_UNCOMPRESSED_BLOCK_SIZE_R11], deUint64 src, bool signedMode) { static const int modifierTable[16][8] = { @@ -815,294 +797,199 @@ static void decompressEAC11Block (deUint8 dst[ETC2_UNCOMPRESSED_BLOCK_SIZE_R11], if (signedMode) { + deInt16 value; + if (multiplier != 0) - *(deInt16*)&dst[dstOffset] = (deInt16)deClamp32(baseCodeword*8 + multiplier*modifier*8, -1023, 1023); + value = (deInt16)deClamp32(baseCodeword*8 + multiplier*modifier*8, -1023, 1023); else - *(deInt16*)&dst[dstOffset] = (deInt16)deClamp32(baseCodeword*8 + modifier, -1023, 1023); + value = (deInt16)deClamp32(baseCodeword*8 + modifier, -1023, 1023); + + *((deInt16*)(dst + dstOffset)) = value; } else { + deUint16 value; + if (multiplier != 0) - *(deUint16*)&dst[dstOffset] = (deUint16)deClamp32(baseCodeword*8 + 4 + multiplier*modifier*8, 0, 2047); + value = (deUint16)deClamp32(baseCodeword*8 + 4 + multiplier*modifier*8, 0, 2047); else - *(deUint16*)&dst[dstOffset] = (deUint16)deClamp32(baseCodeword*8 + 4 + modifier, 0, 2047); + value= (deUint16)deClamp32(baseCodeword*8 + 4 + modifier, 0, 2047); + + *((deUint16*)(dst + dstOffset)) = value; } } } } // EtcDecompressInternal -static void decompressETC1 (const tcu::PixelBufferAccess& dst, int width, int height, const deUint8* src) +void decompressETC1 (const PixelBufferAccess& dst, const deUint8* src) { using namespace EtcDecompressInternal; - DE_ASSERT(dst.getWidth() == width && dst.getHeight() == height && dst.getDepth() == 1); - DE_ASSERT(dst.getFormat() == TextureFormat(TextureFormat::RGB, TextureFormat::UNORM_INT8)); - - const int numBlocksX = divRoundUp(width, 4); - const int numBlocksY = divRoundUp(height, 4); deUint8* const dstPtr = (deUint8*)dst.getDataPtr(); - const int dstRowPitch = dst.getRowPitch(); - const int dstPixelSize = ETC2_UNCOMPRESSED_PIXEL_SIZE_RGB8; + const deUint64 compressedBlock = get64BitBlock(src, 0); - for (int blockY = 0; blockY < numBlocksY; blockY++) - { - for (int blockX = 0; blockX < numBlocksX; blockX++) - { - const deUint64 compressedBlock = get64BitBlock(src, blockY*numBlocksX + blockX); - deUint8 uncompressedBlock[ETC2_UNCOMPRESSED_BLOCK_SIZE_RGB8]; - - // Decompress. - decompressETC1Block(uncompressedBlock, compressedBlock); - - // Write to dst. - const int baseX = blockX*ETC2_BLOCK_WIDTH; - const int baseY = blockY*ETC2_BLOCK_HEIGHT; - for (int y = 0; y < de::min((int)ETC2_BLOCK_HEIGHT, height-baseY); y++) - { - for (int x = 0; x < de::min((int)ETC2_BLOCK_WIDTH, width-baseX); x++) - { - const deUint8* const srcPixel = &uncompressedBlock[(y*ETC2_BLOCK_WIDTH + x)*ETC2_UNCOMPRESSED_PIXEL_SIZE_RGB8]; - deUint8* const dstPixel = dstPtr + (baseY+y)*dstRowPitch + (baseX+x)*dstPixelSize; - - DE_STATIC_ASSERT(ETC2_UNCOMPRESSED_PIXEL_SIZE_RGB8 == 3); - dstPixel[0] = srcPixel[0]; - dstPixel[1] = srcPixel[1]; - dstPixel[2] = srcPixel[2]; - } - } - } - } + decompressETC1Block(dstPtr, compressedBlock); } -static void decompressETC2 (const tcu::PixelBufferAccess& dst, int width, int height, const deUint8* src) +void decompressETC2 (const PixelBufferAccess& dst, const deUint8* src) { using namespace EtcDecompressInternal; - const int numBlocksX = divRoundUp(width, 4); - const int numBlocksY = divRoundUp(height, 4); deUint8* const dstPtr = (deUint8*)dst.getDataPtr(); - const int dstRowPitch = dst.getRowPitch(); - const int dstPixelSize = ETC2_UNCOMPRESSED_PIXEL_SIZE_RGB8; - - for (int blockY = 0; blockY < numBlocksY; blockY++) - { - for (int blockX = 0; blockX < numBlocksX; blockX++) - { - const deUint64 compressedBlock = get64BitBlock(src, blockY*numBlocksX + blockX); - deUint8 uncompressedBlock[ETC2_UNCOMPRESSED_BLOCK_SIZE_RGB8]; + const deUint64 compressedBlock = get64BitBlock(src, 0); - // Decompress. - decompressETC2Block(uncompressedBlock, compressedBlock, NULL, false); - - // Write to dst. - const int baseX = blockX*ETC2_BLOCK_WIDTH; - const int baseY = blockY*ETC2_BLOCK_HEIGHT; - for (int y = 0; y < de::min((int)ETC2_BLOCK_HEIGHT, height-baseY); y++) - { - for (int x = 0; x < de::min((int)ETC2_BLOCK_WIDTH, width-baseX); x++) - { - const deUint8* const srcPixel = &uncompressedBlock[(y*ETC2_BLOCK_WIDTH + x)*ETC2_UNCOMPRESSED_PIXEL_SIZE_RGB8]; - deUint8* const dstPixel = dstPtr + (baseY+y)*dstRowPitch + (baseX+x)*dstPixelSize; - - DE_STATIC_ASSERT(ETC2_UNCOMPRESSED_PIXEL_SIZE_RGB8 == 3); - dstPixel[0] = srcPixel[0]; - dstPixel[1] = srcPixel[1]; - dstPixel[2] = srcPixel[2]; - } - } - } - } + decompressETC2Block(dstPtr, compressedBlock, NULL, false); } -static void decompressETC2_EAC_RGBA8 (const tcu::PixelBufferAccess& dst, int width, int height, const deUint8* src) +void decompressETC2_EAC_RGBA8 (const PixelBufferAccess& dst, const deUint8* src) { using namespace EtcDecompressInternal; - const int numBlocksX = divRoundUp(width, 4); - const int numBlocksY = divRoundUp(height, 4); deUint8* const dstPtr = (deUint8*)dst.getDataPtr(); const int dstRowPitch = dst.getRowPitch(); const int dstPixelSize = ETC2_UNCOMPRESSED_PIXEL_SIZE_RGBA8; - for (int blockY = 0; blockY < numBlocksY; blockY++) + const deUint64 compressedBlockAlpha = get128BitBlockStart(src, 0); + const deUint64 compressedBlockRGB = get128BitBlockEnd(src, 0); + deUint8 uncompressedBlockAlpha[ETC2_UNCOMPRESSED_BLOCK_SIZE_A8]; + deUint8 uncompressedBlockRGB[ETC2_UNCOMPRESSED_BLOCK_SIZE_RGB8]; + + // Decompress. + decompressETC2Block(uncompressedBlockRGB, compressedBlockRGB, NULL, false); + decompressEAC8Block(uncompressedBlockAlpha, compressedBlockAlpha); + + // Write to dst. + for (int y = 0; y < (int)ETC2_BLOCK_HEIGHT; y++) { - for (int blockX = 0; blockX < numBlocksX; blockX++) + for (int x = 0; x < (int)ETC2_BLOCK_WIDTH; x++) { - const deUint64 compressedBlockAlpha = get128BitBlockStart(src, blockY*numBlocksX + blockX); - const deUint64 compressedBlockRGB = get128BitBlockEnd(src, blockY*numBlocksX + blockX); - deUint8 uncompressedBlockAlpha[ETC2_UNCOMPRESSED_BLOCK_SIZE_A8]; - deUint8 uncompressedBlockRGB[ETC2_UNCOMPRESSED_BLOCK_SIZE_RGB8]; - - // Decompress. - decompressETC2Block(uncompressedBlockRGB, compressedBlockRGB, NULL, false); - decompressEAC8Block(uncompressedBlockAlpha, compressedBlockAlpha); - - // Write to dst. - const int baseX = blockX*ETC2_BLOCK_WIDTH; - const int baseY = blockY*ETC2_BLOCK_HEIGHT; - for (int y = 0; y < de::min((int)ETC2_BLOCK_HEIGHT, height-baseY); y++) - { - for (int x = 0; x < de::min((int)ETC2_BLOCK_WIDTH, width-baseX); x++) - { - const deUint8* const srcPixelRGB = &uncompressedBlockRGB[(y*ETC2_BLOCK_WIDTH + x)*ETC2_UNCOMPRESSED_PIXEL_SIZE_RGB8]; - const deUint8* const srcPixelAlpha = &uncompressedBlockAlpha[(y*ETC2_BLOCK_WIDTH + x)*ETC2_UNCOMPRESSED_PIXEL_SIZE_A8]; - deUint8* const dstPixel = dstPtr + (baseY+y)*dstRowPitch + (baseX+x)*dstPixelSize; - - DE_STATIC_ASSERT(ETC2_UNCOMPRESSED_PIXEL_SIZE_RGBA8 == 4); - dstPixel[0] = srcPixelRGB[0]; - dstPixel[1] = srcPixelRGB[1]; - dstPixel[2] = srcPixelRGB[2]; - dstPixel[3] = srcPixelAlpha[0]; - } - } + const deUint8* const srcPixelRGB = &uncompressedBlockRGB[(y*ETC2_BLOCK_WIDTH + x)*ETC2_UNCOMPRESSED_PIXEL_SIZE_RGB8]; + const deUint8* const srcPixelAlpha = &uncompressedBlockAlpha[(y*ETC2_BLOCK_WIDTH + x)*ETC2_UNCOMPRESSED_PIXEL_SIZE_A8]; + deUint8* const dstPixel = dstPtr + y*dstRowPitch + x*dstPixelSize; + + DE_STATIC_ASSERT(ETC2_UNCOMPRESSED_PIXEL_SIZE_RGBA8 == 4); + dstPixel[0] = srcPixelRGB[0]; + dstPixel[1] = srcPixelRGB[1]; + dstPixel[2] = srcPixelRGB[2]; + dstPixel[3] = srcPixelAlpha[0]; } } } -static void decompressETC2_RGB8_PUNCHTHROUGH_ALPHA1 (const tcu::PixelBufferAccess& dst, int width, int height, const deUint8* src) +void decompressETC2_RGB8_PUNCHTHROUGH_ALPHA1 (const PixelBufferAccess& dst, const deUint8* src) { using namespace EtcDecompressInternal; - const int numBlocksX = divRoundUp(width, 4); - const int numBlocksY = divRoundUp(height, 4); deUint8* const dstPtr = (deUint8*)dst.getDataPtr(); const int dstRowPitch = dst.getRowPitch(); const int dstPixelSize = ETC2_UNCOMPRESSED_PIXEL_SIZE_RGBA8; - for (int blockY = 0; blockY < numBlocksY; blockY++) - { - for (int blockX = 0; blockX < numBlocksX; blockX++) - { - const deUint64 compressedBlockRGBA = get64BitBlock(src, blockY*numBlocksX + blockX); - deUint8 uncompressedBlockRGB[ETC2_UNCOMPRESSED_BLOCK_SIZE_RGB8]; - deUint8 uncompressedBlockAlpha[ETC2_UNCOMPRESSED_BLOCK_SIZE_A8]; + const deUint64 compressedBlockRGBA = get64BitBlock(src, 0); + deUint8 uncompressedBlockRGB[ETC2_UNCOMPRESSED_BLOCK_SIZE_RGB8]; + deUint8 uncompressedBlockAlpha[ETC2_UNCOMPRESSED_BLOCK_SIZE_A8]; - // Decompress. - decompressETC2Block(uncompressedBlockRGB, compressedBlockRGBA, uncompressedBlockAlpha, DE_TRUE); + // Decompress. + decompressETC2Block(uncompressedBlockRGB, compressedBlockRGBA, uncompressedBlockAlpha, DE_TRUE); - // Write to dst. - const int baseX = blockX*ETC2_BLOCK_WIDTH; - const int baseY = blockY*ETC2_BLOCK_HEIGHT; - for (int y = 0; y < de::min((int)ETC2_BLOCK_HEIGHT, height-baseY); y++) - { - for (int x = 0; x < de::min((int)ETC2_BLOCK_WIDTH, width-baseX); x++) - { - const deUint8* const srcPixel = &uncompressedBlockRGB[(y*ETC2_BLOCK_WIDTH + x)*ETC2_UNCOMPRESSED_PIXEL_SIZE_RGB8]; - const deUint8* const srcPixelAlpha = &uncompressedBlockAlpha[(y*ETC2_BLOCK_WIDTH + x)*ETC2_UNCOMPRESSED_PIXEL_SIZE_A8]; - deUint8* const dstPixel = dstPtr + (baseY+y)*dstRowPitch + (baseX+x)*dstPixelSize; - - DE_STATIC_ASSERT(ETC2_UNCOMPRESSED_PIXEL_SIZE_RGBA8 == 4); - dstPixel[0] = srcPixel[0]; - dstPixel[1] = srcPixel[1]; - dstPixel[2] = srcPixel[2]; - dstPixel[3] = srcPixelAlpha[0]; - } - } + // Write to dst. + for (int y = 0; y < (int)ETC2_BLOCK_HEIGHT; y++) + { + for (int x = 0; x < (int)ETC2_BLOCK_WIDTH; x++) + { + const deUint8* const srcPixel = &uncompressedBlockRGB[(y*ETC2_BLOCK_WIDTH + x)*ETC2_UNCOMPRESSED_PIXEL_SIZE_RGB8]; + const deUint8* const srcPixelAlpha = &uncompressedBlockAlpha[(y*ETC2_BLOCK_WIDTH + x)*ETC2_UNCOMPRESSED_PIXEL_SIZE_A8]; + deUint8* const dstPixel = dstPtr + y*dstRowPitch + x*dstPixelSize; + + DE_STATIC_ASSERT(ETC2_UNCOMPRESSED_PIXEL_SIZE_RGBA8 == 4); + dstPixel[0] = srcPixel[0]; + dstPixel[1] = srcPixel[1]; + dstPixel[2] = srcPixel[2]; + dstPixel[3] = srcPixelAlpha[0]; } } } -static void decompressEAC_R11 (const tcu::PixelBufferAccess& dst, int width, int height, const deUint8* src, bool signedMode) +void decompressEAC_R11 (const PixelBufferAccess& dst, const deUint8* src, bool signedMode) { using namespace EtcDecompressInternal; - const int numBlocksX = divRoundUp(width, 4); - const int numBlocksY = divRoundUp(height, 4); deUint8* const dstPtr = (deUint8*)dst.getDataPtr(); const int dstRowPitch = dst.getRowPitch(); const int dstPixelSize = ETC2_UNCOMPRESSED_PIXEL_SIZE_R11; - for (int blockY = 0; blockY < numBlocksY; blockY++) + const deUint64 compressedBlock = get64BitBlock(src, 0); + deUint8 uncompressedBlock[ETC2_UNCOMPRESSED_BLOCK_SIZE_R11]; + + // Decompress. + decompressEAC11Block(uncompressedBlock, compressedBlock, signedMode); + + // Write to dst. + for (int y = 0; y < (int)ETC2_BLOCK_HEIGHT; y++) { - for (int blockX = 0; blockX < numBlocksX; blockX++) + for (int x = 0; x < (int)ETC2_BLOCK_WIDTH; x++) { - const deUint64 compressedBlock = get64BitBlock(src, blockY*numBlocksX + blockX); - deUint8 uncompressedBlock[ETC2_UNCOMPRESSED_BLOCK_SIZE_R11]; + DE_STATIC_ASSERT(ETC2_UNCOMPRESSED_PIXEL_SIZE_R11 == 2); - // Decompress. - decompressEAC11Block(uncompressedBlock, compressedBlock, signedMode); - - // Write to dst. - const int baseX = blockX*ETC2_BLOCK_WIDTH; - const int baseY = blockY*ETC2_BLOCK_HEIGHT; - for (int y = 0; y < de::min((int)ETC2_BLOCK_HEIGHT, height-baseY); y++) + if (signedMode) { - for (int x = 0; x < de::min((int)ETC2_BLOCK_WIDTH, width-baseX); x++) - { - DE_STATIC_ASSERT(ETC2_UNCOMPRESSED_PIXEL_SIZE_R11 == 2); + const deInt16* const srcPixel = (deInt16*)&uncompressedBlock[(y*ETC2_BLOCK_WIDTH + x)*ETC2_UNCOMPRESSED_PIXEL_SIZE_R11]; + deInt16* const dstPixel = (deInt16*)(dstPtr + y*dstRowPitch + x*dstPixelSize); - if (signedMode) - { - const deInt16* const srcPixel = (deInt16*)&uncompressedBlock[(y*ETC2_BLOCK_WIDTH + x)*ETC2_UNCOMPRESSED_PIXEL_SIZE_R11]; - deInt16* const dstPixel = (deInt16*)(dstPtr + (baseY+y)*dstRowPitch + (baseX+x)*dstPixelSize); - - dstPixel[0] = extend11To16WithSign(srcPixel[0]); - } - else - { - const deUint16* const srcPixel = (deUint16*)&uncompressedBlock[(y*ETC2_BLOCK_WIDTH + x)*ETC2_UNCOMPRESSED_PIXEL_SIZE_R11]; - deUint16* const dstPixel = (deUint16*)(dstPtr + (baseY+y)*dstRowPitch + (baseX+x)*dstPixelSize); + dstPixel[0] = extend11To16WithSign(srcPixel[0]); + } + else + { + const deUint16* const srcPixel = (deUint16*)&uncompressedBlock[(y*ETC2_BLOCK_WIDTH + x)*ETC2_UNCOMPRESSED_PIXEL_SIZE_R11]; + deUint16* const dstPixel = (deUint16*)(dstPtr + y*dstRowPitch + x*dstPixelSize); - dstPixel[0] = extend11To16(srcPixel[0]); - } - } + dstPixel[0] = extend11To16(srcPixel[0]); } } } } -static void decompressEAC_RG11 (const tcu::PixelBufferAccess& dst, int width, int height, const deUint8* src, bool signedMode) +void decompressEAC_RG11 (const PixelBufferAccess& dst, const deUint8* src, bool signedMode) { using namespace EtcDecompressInternal; - const int numBlocksX = divRoundUp(width, 4); - const int numBlocksY = divRoundUp(height, 4); deUint8* const dstPtr = (deUint8*)dst.getDataPtr(); const int dstRowPitch = dst.getRowPitch(); const int dstPixelSize = ETC2_UNCOMPRESSED_PIXEL_SIZE_RG11; - for (int blockY = 0; blockY < numBlocksY; blockY++) + const deUint64 compressedBlockR = get128BitBlockStart(src, 0); + const deUint64 compressedBlockG = get128BitBlockEnd(src, 0); + deUint8 uncompressedBlockR[ETC2_UNCOMPRESSED_BLOCK_SIZE_R11]; + deUint8 uncompressedBlockG[ETC2_UNCOMPRESSED_BLOCK_SIZE_R11]; + + // Decompress. + decompressEAC11Block(uncompressedBlockR, compressedBlockR, signedMode); + decompressEAC11Block(uncompressedBlockG, compressedBlockG, signedMode); + + // Write to dst. + for (int y = 0; y < (int)ETC2_BLOCK_HEIGHT; y++) { - for (int blockX = 0; blockX < numBlocksX; blockX++) + for (int x = 0; x < (int)ETC2_BLOCK_WIDTH; x++) { - const deUint64 compressedBlockR = get128BitBlockStart(src, blockY*numBlocksX + blockX); - const deUint64 compressedBlockG = get128BitBlockEnd(src, blockY*numBlocksX + blockX); - deUint8 uncompressedBlockR[ETC2_UNCOMPRESSED_BLOCK_SIZE_R11]; - deUint8 uncompressedBlockG[ETC2_UNCOMPRESSED_BLOCK_SIZE_R11]; - - // Decompress. - decompressEAC11Block(uncompressedBlockR, compressedBlockR, signedMode); - decompressEAC11Block(uncompressedBlockG, compressedBlockG, signedMode); - - // Write to dst. - const int baseX = blockX*ETC2_BLOCK_WIDTH; - const int baseY = blockY*ETC2_BLOCK_HEIGHT; - for (int y = 0; y < de::min((int)ETC2_BLOCK_HEIGHT, height-baseY); y++) + DE_STATIC_ASSERT(ETC2_UNCOMPRESSED_PIXEL_SIZE_RG11 == 4); + + if (signedMode) { - for (int x = 0; x < de::min((int)ETC2_BLOCK_WIDTH, width-baseX); x++) - { - DE_STATIC_ASSERT(ETC2_UNCOMPRESSED_PIXEL_SIZE_RG11 == 4); + const deInt16* const srcPixelR = (deInt16*)&uncompressedBlockR[(y*ETC2_BLOCK_WIDTH + x)*ETC2_UNCOMPRESSED_PIXEL_SIZE_R11]; + const deInt16* const srcPixelG = (deInt16*)&uncompressedBlockG[(y*ETC2_BLOCK_WIDTH + x)*ETC2_UNCOMPRESSED_PIXEL_SIZE_R11]; + deInt16* const dstPixel = (deInt16*)(dstPtr + y*dstRowPitch + x*dstPixelSize); - if (signedMode) - { - const deInt16* const srcPixelR = (deInt16*)&uncompressedBlockR[(y*ETC2_BLOCK_WIDTH + x)*ETC2_UNCOMPRESSED_PIXEL_SIZE_R11]; - const deInt16* const srcPixelG = (deInt16*)&uncompressedBlockG[(y*ETC2_BLOCK_WIDTH + x)*ETC2_UNCOMPRESSED_PIXEL_SIZE_R11]; - deInt16* const dstPixel = (deInt16*)(dstPtr + (baseY+y)*dstRowPitch + (baseX+x)*dstPixelSize); + dstPixel[0] = extend11To16WithSign(srcPixelR[0]); + dstPixel[1] = extend11To16WithSign(srcPixelG[0]); + } + else + { + const deUint16* const srcPixelR = (deUint16*)&uncompressedBlockR[(y*ETC2_BLOCK_WIDTH + x)*ETC2_UNCOMPRESSED_PIXEL_SIZE_R11]; + const deUint16* const srcPixelG = (deUint16*)&uncompressedBlockG[(y*ETC2_BLOCK_WIDTH + x)*ETC2_UNCOMPRESSED_PIXEL_SIZE_R11]; + deUint16* const dstPixel = (deUint16*)(dstPtr + y*dstRowPitch + x*dstPixelSize); - dstPixel[0] = extend11To16WithSign(srcPixelR[0]); - dstPixel[1] = extend11To16WithSign(srcPixelG[0]); - } - else - { - const deUint16* const srcPixelR = (deUint16*)&uncompressedBlockR[(y*ETC2_BLOCK_WIDTH + x)*ETC2_UNCOMPRESSED_PIXEL_SIZE_R11]; - const deUint16* const srcPixelG = (deUint16*)&uncompressedBlockG[(y*ETC2_BLOCK_WIDTH + x)*ETC2_UNCOMPRESSED_PIXEL_SIZE_R11]; - deUint16* const dstPixel = (deUint16*)(dstPtr + (baseY+y)*dstRowPitch + (baseX+x)*dstPixelSize); - - dstPixel[0] = extend11To16(srcPixelR[0]); - dstPixel[1] = extend11To16(srcPixelG[0]); - } - } + dstPixel[0] = extend11To16(srcPixelR[0]); + dstPixel[1] = extend11To16(srcPixelG[0]); } } } @@ -1117,25 +1004,25 @@ enum ASTC_MAX_BLOCK_HEIGHT = 12 }; -static inline deUint32 getBit (deUint32 src, int ndx) +inline deUint32 getBit (deUint32 src, int ndx) { DE_ASSERT(de::inBounds(ndx, 0, 32)); return (src >> ndx) & 1; } -static inline deUint32 getBits (deUint32 src, int low, int high) +inline deUint32 getBits (deUint32 src, int low, int high) { const int numBits = (high-low) + 1; DE_ASSERT(de::inRange(numBits, 1, 32)); return (src >> low) & ((1u<>= 1; b |= a & 0x80; @@ -1829,7 +1716,7 @@ static inline void bitTransferSigned (deInt32& a, deInt32& b) a -= 0x40; } -static inline UVec4 clampedRGBA (const tcu::IVec4& rgba) +inline UVec4 clampedRGBA (const IVec4& rgba) { return UVec4(de::clamp(rgba.x(), 0, 0xff), de::clamp(rgba.y(), 0, 0xff), @@ -1837,12 +1724,12 @@ static inline UVec4 clampedRGBA (const tcu::IVec4& rgba) de::clamp(rgba.w(), 0, 0xff)); } -static inline tcu::IVec4 blueContract (int r, int g, int b, int a) +inline IVec4 blueContract (int r, int g, int b, int a) { - return tcu::IVec4((r+b)>>1, (g+b)>>1, b, a); + return IVec4((r+b)>>1, (g+b)>>1, b, a); } -static inline bool isColorEndpointModeHDR (deUint32 mode) +inline bool isColorEndpointModeHDR (deUint32 mode) { return mode == 2 || mode == 3 || @@ -1852,7 +1739,7 @@ static inline bool isColorEndpointModeHDR (deUint32 mode) mode == 15; } -static void decodeHDREndpointMode7 (UVec4& e0, UVec4& e1, deUint32 v0, deUint32 v1, deUint32 v2, deUint32 v3) +void decodeHDREndpointMode7 (UVec4& e0, UVec4& e1, deUint32 v0, deUint32 v1, deUint32 v2, deUint32 v3) { const deUint32 m10 = getBit(v1, 7) | (getBit(v2, 7) << 1); const deUint32 m23 = getBits(v0, 6, 7); @@ -1931,7 +1818,7 @@ static void decodeHDREndpointMode7 (UVec4& e0, UVec4& e1, deUint32 v0, deUint32 0x780); } -static void decodeHDREndpointMode11 (UVec4& e0, UVec4& e1, deUint32 v0, deUint32 v1, deUint32 v2, deUint32 v3, deUint32 v4, deUint32 v5) +void decodeHDREndpointMode11 (UVec4& e0, UVec4& e1, deUint32 v0, deUint32 v1, deUint32 v2, deUint32 v3, deUint32 v4, deUint32 v5) { const deUint32 major = (getBit(v5, 7) << 1) | getBit(v4, 7); @@ -2017,7 +1904,7 @@ static void decodeHDREndpointMode11 (UVec4& e0, UVec4& e1, deUint32 v0, deUint32 } } -static void decodeHDREndpointMode15(UVec4& e0, UVec4& e1, deUint32 v0, deUint32 v1, deUint32 v2, deUint32 v3, deUint32 v4, deUint32 v5, deUint32 v6In, deUint32 v7In) +void decodeHDREndpointMode15(UVec4& e0, UVec4& e1, deUint32 v0, deUint32 v1, deUint32 v2, deUint32 v3, deUint32 v4, deUint32 v5, deUint32 v6In, deUint32 v7In) { decodeHDREndpointMode11(e0, e1, v0, v1, v2, v3, v4, v5); @@ -2046,7 +1933,7 @@ static void decodeHDREndpointMode15(UVec4& e0, UVec4& e1, deUint32 v0, deUint32 } } -static void decodeColorEndpoints (ColorEndpointPair* dst, const deUint32* unquantizedEndpoints, const deUint32* endpointModes, int numPartitions) +void decodeColorEndpoints (ColorEndpointPair* dst, const deUint32* unquantizedEndpoints, const deUint32* endpointModes, int numPartitions) { int unquantizedNdx = 0; @@ -2114,8 +2001,8 @@ static void decodeColorEndpoints (ColorEndpointPair* dst, const deUint32* unquan bitTransferSigned(v1, v0); bitTransferSigned(v3, v2); - e0 = clampedRGBA(tcu::IVec4(v0, v0, v0, v2)); - e1 = clampedRGBA(tcu::IVec4(v0+v1, v0+v1, v0+v1, v2+v3)); + e0 = clampedRGBA(IVec4(v0, v0, v0, v2)); + e1 = clampedRGBA(IVec4(v0+v1, v0+v1, v0+v1, v2+v3)); break; } @@ -2155,8 +2042,8 @@ static void decodeColorEndpoints (ColorEndpointPair* dst, const deUint32* unquan if (v1+v3+v5 >= 0) { - e0 = clampedRGBA(tcu::IVec4(v0, v2, v4, 0xff)); - e1 = clampedRGBA(tcu::IVec4(v0+v1, v2+v3, v4+v5, 0xff)); + e0 = clampedRGBA(IVec4(v0, v2, v4, 0xff)); + e1 = clampedRGBA(IVec4(v0+v1, v2+v3, v4+v5, 0xff)); } else { @@ -2205,8 +2092,8 @@ static void decodeColorEndpoints (ColorEndpointPair* dst, const deUint32* unquan if (v1+v3+v5 >= 0) { - e0 = clampedRGBA(tcu::IVec4(v0, v2, v4, v6)); - e1 = clampedRGBA(tcu::IVec4(v0+v1, v2+v3, v4+v5, v6+v7)); + e0 = clampedRGBA(IVec4(v0, v2, v4, v6)); + e1 = clampedRGBA(IVec4(v0+v1, v2+v3, v4+v5, v6+v7)); } else { @@ -2233,7 +2120,7 @@ static void decodeColorEndpoints (ColorEndpointPair* dst, const deUint32* unquan } } -static void computeColorEndpoints (ColorEndpointPair* dst, const Block128& blockData, const deUint32* endpointModes, int numPartitions, int numColorEndpointValues, const ISEParams& iseParams, int numBitsAvailable) +void computeColorEndpoints (ColorEndpointPair* dst, const Block128& blockData, const deUint32* endpointModes, int numPartitions, int numColorEndpointValues, const ISEParams& iseParams, int numBitsAvailable) { const int colorEndpointDataStart = numPartitions == 1 ? 17 : 29; ISEDecodedResult colorEndpointData[18]; @@ -2250,7 +2137,7 @@ static void computeColorEndpoints (ColorEndpointPair* dst, const Block128& block } } -static void unquantizeWeights (deUint32* dst, const ISEDecodedResult* weightGrid, const ASTCBlockMode& blockMode) +void unquantizeWeights (deUint32* dst, const ISEDecodedResult* weightGrid, const ASTCBlockMode& blockMode) { const int numWeights = computeNumWeights(blockMode); const ISEParams& iseParams = blockMode.weightISEParams; @@ -2306,7 +2193,7 @@ static void unquantizeWeights (deUint32* dst, const ISEDecodedResult* weightGrid dst[weightNdx] += dst[weightNdx] > 32 ? 1 : 0; } -static void interpolateWeights (TexelWeightPair* dst, const deUint32* unquantizedWeights, int blockWidth, int blockHeight, const ASTCBlockMode& blockMode) +void interpolateWeights (TexelWeightPair* dst, const deUint32* unquantizedWeights, int blockWidth, int blockHeight, const ASTCBlockMode& blockMode) { const int numWeightsPerTexel = blockMode.isDualPlane ? 2 : 1; const deUint32 scaleX = (1024 + blockWidth/2) / (blockWidth-1); @@ -2341,7 +2228,7 @@ static void interpolateWeights (TexelWeightPair* dst, const deUint32* unquantize } } -static void computeTexelWeights (TexelWeightPair* dst, const Block128& blockData, int blockWidth, int blockHeight, const ASTCBlockMode& blockMode) +void computeTexelWeights (TexelWeightPair* dst, const Block128& blockData, int blockWidth, int blockHeight, const ASTCBlockMode& blockMode) { ISEDecodedResult weightGrid[64]; @@ -2357,7 +2244,7 @@ static void computeTexelWeights (TexelWeightPair* dst, const Block128& blockData } } -static inline deUint32 hash52 (deUint32 v) +inline deUint32 hash52 (deUint32 v) { deUint32 p = v; p ^= p >> 15; p -= p << 17; p += p << 7; p += p << 4; @@ -2366,7 +2253,7 @@ static inline deUint32 hash52 (deUint32 v) return p; } -static int computeTexelPartition (deUint32 seedIn, deUint32 xIn, deUint32 yIn, deUint32 zIn, int numPartitions, bool smallBlock) +int computeTexelPartition (deUint32 seedIn, deUint32 xIn, deUint32 yIn, deUint32 zIn, int numPartitions, bool smallBlock) { DE_ASSERT(zIn == 0); const deUint32 x = smallBlock ? xIn << 1 : xIn; @@ -2413,7 +2300,7 @@ static int computeTexelPartition (deUint32 seedIn, deUint32 xIn, deUint32 yIn, d : 3; } -static void setTexelColors (void* dst, ColorEndpointPair* colorEndpoints, TexelWeightPair* texelWeights, int ccs, deUint32 partitionIndexSeed, +void setTexelColors (void* dst, ColorEndpointPair* colorEndpoints, TexelWeightPair* texelWeights, int ccs, deUint32 partitionIndexSeed, int numPartitions, int blockWidth, int blockHeight, bool isSRGB, bool isLDRMode, const deUint32* colorEndpointModes) { const bool smallBlock = blockWidth*blockHeight < 31; @@ -2486,7 +2373,7 @@ static void setTexelColors (void* dst, ColorEndpointPair* colorEndpoints, TexelW } } -static void decompressASTCBlock (void* dst, const Block128& blockData, int blockWidth, int blockHeight, bool isSRGB, bool isLDR) +void decompressASTCBlock (void* dst, const Block128& blockData, int blockWidth, int blockHeight, bool isSRGB, bool isLDR) { DE_ASSERT(isLDR || !isSRGB); @@ -2576,105 +2463,205 @@ static void decompressASTCBlock (void* dst, const Block128& blockData, int block } // ASTCDecompressInternal -static void decompressASTC (const tcu::PixelBufferAccess& dst, int width, int height, const deUint8* data, int blockWidth, int blockHeight, bool isSRGB, bool isLDR) +void decompressASTC (const PixelBufferAccess& dst, const deUint8* data, bool isSRGB, bool isLDR) { using namespace ASTCDecompressInternal; DE_ASSERT(isLDR || !isSRGB); - const int numBlocksX = divRoundUp(width, blockWidth); - const int numBlocksY = divRoundUp(height, blockHeight); + const int blockWidth = dst.getWidth(); + const int blockHeight = dst.getHeight(); + union { deUint8 sRGB[ASTC_MAX_BLOCK_WIDTH*ASTC_MAX_BLOCK_HEIGHT*4]; float linear[ASTC_MAX_BLOCK_WIDTH*ASTC_MAX_BLOCK_HEIGHT*4]; } decompressedBuffer; - for (int blockY = 0; blockY < numBlocksY; blockY++) - for (int blockX = 0; blockX < numBlocksX; blockX++) - { - const int baseX = blockX * blockWidth; - const int baseY = blockY * blockHeight; - - const Block128 blockData(&data[(blockY*numBlocksX + blockX) * ASTC_BLOCK_SIZE_BYTES]); - decompressASTCBlock(isSRGB ? (void*)&decompressedBuffer.sRGB[0] : (void*)&decompressedBuffer.linear[0], - blockData, blockWidth, blockHeight, isSRGB, isLDR); + const Block128 blockData(data); + decompressASTCBlock(isSRGB ? (void*)&decompressedBuffer.sRGB[0] : (void*)&decompressedBuffer.linear[0], + blockData, dst.getWidth(), dst.getHeight(), isSRGB, isLDR); - if (isSRGB) + if (isSRGB) + { + for (int i = 0; i < blockHeight; i++) + for (int j = 0; j < blockWidth; j++) { - for (int i = 0; i < blockHeight; i++) - for (int j = 0; j < blockWidth; j++) - { - if (baseX + j < dst.getWidth() && baseY + i < dst.getHeight()) - dst.setPixel(tcu::IVec4(decompressedBuffer.sRGB[(i*blockWidth + j) * 4 + 0], - decompressedBuffer.sRGB[(i*blockWidth + j) * 4 + 1], - decompressedBuffer.sRGB[(i*blockWidth + j) * 4 + 2], - decompressedBuffer.sRGB[(i*blockWidth + j) * 4 + 3]), - baseX + j, - baseY + i); - } + dst.setPixel(IVec4(decompressedBuffer.sRGB[(i*blockWidth + j) * 4 + 0], + decompressedBuffer.sRGB[(i*blockWidth + j) * 4 + 1], + decompressedBuffer.sRGB[(i*blockWidth + j) * 4 + 2], + decompressedBuffer.sRGB[(i*blockWidth + j) * 4 + 3]), j, i); } - else + } + else + { + for (int i = 0; i < blockHeight; i++) + for (int j = 0; j < blockWidth; j++) { - for (int i = 0; i < blockHeight; i++) - for (int j = 0; j < blockWidth; j++) - { - if (baseX + j < dst.getWidth() && baseY + i < dst.getHeight()) - { - dst.setPixel(tcu::Vec4(decompressedBuffer.linear[(i*blockWidth + j) * 4 + 0], - decompressedBuffer.linear[(i*blockWidth + j) * 4 + 1], - decompressedBuffer.linear[(i*blockWidth + j) * 4 + 2], - decompressedBuffer.linear[(i*blockWidth + j) * 4 + 3]), - baseX + j, - baseY + i); - } - } + dst.setPixel(Vec4(decompressedBuffer.linear[(i*blockWidth + j) * 4 + 0], + decompressedBuffer.linear[(i*blockWidth + j) * 4 + 1], + decompressedBuffer.linear[(i*blockWidth + j) * 4 + 2], + decompressedBuffer.linear[(i*blockWidth + j) * 4 + 3]), j, i); } } } -/*--------------------------------------------------------------------*//*! - * \brief Decode to uncompressed pixel data - * \param dst Destination buffer - *//*--------------------------------------------------------------------*/ -void CompressedTexture::decompress (const tcu::PixelBufferAccess& dst, const DecompressionParams& params) const -{ - DE_ASSERT(dst.getWidth() == m_width && dst.getHeight() == m_height && dst.getDepth() == 1); - DE_ASSERT(dst.getFormat() == getUncompressedFormat()); - - if (isEtcFormat(m_format)) - { - switch (m_format) +void decompressBlock (CompressedTexFormat format, const PixelBufferAccess& dst, const deUint8* src, const TexDecompressionParams& params) +{ + // No 3D blocks supported right now + DE_ASSERT(dst.getDepth() == 1); + + switch (format) + { + case COMPRESSEDTEXFORMAT_ETC1_RGB8: decompressETC1 (dst, src); break; + case COMPRESSEDTEXFORMAT_EAC_R11: decompressEAC_R11 (dst, src, false); break; + case COMPRESSEDTEXFORMAT_EAC_SIGNED_R11: decompressEAC_R11 (dst, src, true); break; + case COMPRESSEDTEXFORMAT_EAC_RG11: decompressEAC_RG11 (dst, src, false); break; + case COMPRESSEDTEXFORMAT_EAC_SIGNED_RG11: decompressEAC_RG11 (dst, src, true); break; + case COMPRESSEDTEXFORMAT_ETC2_RGB8: decompressETC2 (dst, src); break; + case COMPRESSEDTEXFORMAT_ETC2_SRGB8: decompressETC2 (dst, src); break; + case COMPRESSEDTEXFORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1: decompressETC2_RGB8_PUNCHTHROUGH_ALPHA1 (dst, src); break; + case COMPRESSEDTEXFORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1: decompressETC2_RGB8_PUNCHTHROUGH_ALPHA1 (dst, src); break; + case COMPRESSEDTEXFORMAT_ETC2_EAC_RGBA8: decompressETC2_EAC_RGBA8 (dst, src); break; + case COMPRESSEDTEXFORMAT_ETC2_EAC_SRGB8_ALPHA8: decompressETC2_EAC_RGBA8 (dst, src); break; + + case COMPRESSEDTEXFORMAT_ASTC_4x4_RGBA: + case COMPRESSEDTEXFORMAT_ASTC_5x4_RGBA: + case COMPRESSEDTEXFORMAT_ASTC_5x5_RGBA: + case COMPRESSEDTEXFORMAT_ASTC_6x5_RGBA: + case COMPRESSEDTEXFORMAT_ASTC_6x6_RGBA: + case COMPRESSEDTEXFORMAT_ASTC_8x5_RGBA: + case COMPRESSEDTEXFORMAT_ASTC_8x6_RGBA: + case COMPRESSEDTEXFORMAT_ASTC_8x8_RGBA: + case COMPRESSEDTEXFORMAT_ASTC_10x5_RGBA: + case COMPRESSEDTEXFORMAT_ASTC_10x6_RGBA: + case COMPRESSEDTEXFORMAT_ASTC_10x8_RGBA: + case COMPRESSEDTEXFORMAT_ASTC_10x10_RGBA: + case COMPRESSEDTEXFORMAT_ASTC_12x10_RGBA: + case COMPRESSEDTEXFORMAT_ASTC_12x12_RGBA: + case COMPRESSEDTEXFORMAT_ASTC_4x4_SRGB8_ALPHA8: + case COMPRESSEDTEXFORMAT_ASTC_5x4_SRGB8_ALPHA8: + case COMPRESSEDTEXFORMAT_ASTC_5x5_SRGB8_ALPHA8: + case COMPRESSEDTEXFORMAT_ASTC_6x5_SRGB8_ALPHA8: + case COMPRESSEDTEXFORMAT_ASTC_6x6_SRGB8_ALPHA8: + case COMPRESSEDTEXFORMAT_ASTC_8x5_SRGB8_ALPHA8: + case COMPRESSEDTEXFORMAT_ASTC_8x6_SRGB8_ALPHA8: + case COMPRESSEDTEXFORMAT_ASTC_8x8_SRGB8_ALPHA8: + case COMPRESSEDTEXFORMAT_ASTC_10x5_SRGB8_ALPHA8: + case COMPRESSEDTEXFORMAT_ASTC_10x6_SRGB8_ALPHA8: + case COMPRESSEDTEXFORMAT_ASTC_10x8_SRGB8_ALPHA8: + case COMPRESSEDTEXFORMAT_ASTC_10x10_SRGB8_ALPHA8: + case COMPRESSEDTEXFORMAT_ASTC_12x10_SRGB8_ALPHA8: + case COMPRESSEDTEXFORMAT_ASTC_12x12_SRGB8_ALPHA8: { - case ETC1_RGB8: decompressETC1 (dst, m_width, m_height, &m_data[0]); break; - case EAC_R11: decompressEAC_R11 (dst, m_width, m_height, &m_data[0], false); break; - case EAC_SIGNED_R11: decompressEAC_R11 (dst, m_width, m_height, &m_data[0], true); break; - case EAC_RG11: decompressEAC_RG11 (dst, m_width, m_height, &m_data[0], false); break; - case EAC_SIGNED_RG11: decompressEAC_RG11 (dst, m_width, m_height, &m_data[0], true); break; - case ETC2_RGB8: decompressETC2 (dst, m_width, m_height, &m_data[0]); break; - case ETC2_SRGB8: decompressETC2 (dst, m_width, m_height, &m_data[0]); break; - case ETC2_RGB8_PUNCHTHROUGH_ALPHA1: decompressETC2_RGB8_PUNCHTHROUGH_ALPHA1 (dst, m_width, m_height, &m_data[0]); break; - case ETC2_SRGB8_PUNCHTHROUGH_ALPHA1: decompressETC2_RGB8_PUNCHTHROUGH_ALPHA1 (dst, m_width, m_height, &m_data[0]); break; - case ETC2_EAC_RGBA8: decompressETC2_EAC_RGBA8 (dst, m_width, m_height, &m_data[0]); break; - case ETC2_EAC_SRGB8_ALPHA8: decompressETC2_EAC_RGBA8 (dst, m_width, m_height, &m_data[0]); break; + DE_ASSERT(params.astcMode == TexDecompressionParams::ASTCMODE_LDR || params.astcMode == TexDecompressionParams::ASTCMODE_HDR); - default: - DE_ASSERT(false); - break; + const bool isSRGBFormat = isAstcSRGBFormat(format); + decompressASTC(dst, src, isSRGBFormat, isSRGBFormat || params.astcMode == TexDecompressionParams::ASTCMODE_LDR); + + break; } + + default: + DE_ASSERT(false); + break; } - else if (isASTCFormat(m_format)) +} + +int componentSum (const IVec3& vec) +{ + return vec.x() + vec.y() + vec.z(); +} + +} // anonymous + +void decompress (const PixelBufferAccess& dst, CompressedTexFormat fmt, const deUint8* src, const TexDecompressionParams& params) +{ + const size_t blockSize = getBlockSize(fmt); + const IVec3 blockPixelSize (getBlockPixelSize(fmt)); + const IVec3 blockCount (divRoundUp(dst.getWidth(), blockPixelSize.x()), + divRoundUp(dst.getHeight(), blockPixelSize.y()), + divRoundUp(dst.getDepth(), blockPixelSize.z())); + const IVec3 blockPitches (blockSize, blockSize * blockCount.x(), blockSize * blockCount.x() * blockCount.y()); + + std::vector uncompressedBlock (dst.getFormat().getPixelSize() * blockPixelSize.x() * blockPixelSize.y() * blockPixelSize.z()); + const PixelBufferAccess blockAccess (getUncompressedFormat(fmt), blockPixelSize.x(), blockPixelSize.y(), blockPixelSize.z(), &uncompressedBlock[0]); + + DE_ASSERT(dst.getFormat() == getUncompressedFormat(fmt)); + + for (int blockZ = 0; blockZ < blockCount.z(); blockZ++) + for (int blockY = 0; blockY < blockCount.y(); blockY++) + for (int blockX = 0; blockX < blockCount.x(); blockX++) { - const tcu::IVec3 blockSize = getASTCBlockSize(m_format); - const bool isSRGBFormat = isASTCSRGBFormat(m_format); + const IVec3 blockPos (blockX, blockY, blockZ); + const deUint8* const blockPtr = src + componentSum(blockPos * blockPitches); + const IVec3 copySize (de::min(blockPixelSize.x(), dst.getWidth() - blockPos.x() * blockPixelSize.x()), + de::min(blockPixelSize.y(), dst.getHeight() - blockPos.y() * blockPixelSize.y()), + de::min(blockPixelSize.z(), dst.getDepth() - blockPos.z() * blockPixelSize.z())); + const IVec3 dstPixelPos = blockPos * blockPixelSize; - if (blockSize.z() > 1) - throw tcu::InternalError("3D ASTC textures not currently supported"); + decompressBlock(fmt, blockAccess, blockPtr, params); - decompressASTC(dst, m_width, m_height, &m_data[0], blockSize.x(), blockSize.y(), isSRGBFormat, isSRGBFormat || params.isASTCModeLDR); + copyRawPixels(getSubregion(dst, dstPixelPos.x(), dstPixelPos.y(), dstPixelPos.z(), copySize.x(), copySize.y(), copySize.z()), getSubregion(blockAccess, 0, 0, 0, copySize.x(), copySize.y(), copySize.z())); + } +} + +CompressedTexture::CompressedTexture (void) + : m_format (COMPRESSEDTEXFORMAT_LAST) + , m_width (0) + , m_height (0) + , m_depth (0) +{ +} + +CompressedTexture::CompressedTexture (CompressedTexFormat format, int width, int height, int depth) + : m_format (COMPRESSEDTEXFORMAT_LAST) + , m_width (0) + , m_height (0) + , m_depth (0) +{ + setStorage(format, width, height, depth); +} + +CompressedTexture::~CompressedTexture (void) +{ +} + +void CompressedTexture::setStorage (CompressedTexFormat format, int width, int height, int depth) +{ + m_format = format; + m_width = width; + m_height = height; + m_depth = depth; + + if (isAstcFormat(m_format) && m_depth > 1) + throw InternalError("3D ASTC textures not currently supported"); + + if (m_format != COMPRESSEDTEXFORMAT_LAST) + { + const IVec3 blockPixelSize = getBlockPixelSize(m_format); + const int blockSize = getBlockSize(m_format); + + m_data.resize(divRoundUp(m_width, blockPixelSize.x()) * divRoundUp(m_height, blockPixelSize.y()) * divRoundUp(m_depth, blockPixelSize.z()) * blockSize); } else - DE_ASSERT(false); + { + DE_ASSERT(m_format == COMPRESSEDTEXFORMAT_LAST); + DE_ASSERT(m_width == 0 && m_height == 0 && m_depth == 0); + m_data.resize(0); + } +} + +/*--------------------------------------------------------------------*//*! + * \brief Decode to uncompressed pixel data + * \param dst Destination buffer + *//*--------------------------------------------------------------------*/ +void CompressedTexture::decompress (const PixelBufferAccess& dst, const TexDecompressionParams& params) const +{ + DE_ASSERT(dst.getWidth() == m_width && dst.getHeight() == m_height && dst.getDepth() == m_depth); + DE_ASSERT(dst.getFormat() == getUncompressedFormat(m_format)); + + tcu::decompress(dst, m_format, &m_data[0], params); } } // tcu diff --git a/framework/common/tcuCompressedTexture.hpp b/framework/common/tcuCompressedTexture.hpp index dfcd8bd..e32e431 100644 --- a/framework/common/tcuCompressedTexture.hpp +++ b/framework/common/tcuCompressedTexture.hpp @@ -31,6 +31,76 @@ namespace tcu { +enum CompressedTexFormat +{ + COMPRESSEDTEXFORMAT_ETC1_RGB8 = 0, + COMPRESSEDTEXFORMAT_EAC_R11, + COMPRESSEDTEXFORMAT_EAC_SIGNED_R11, + COMPRESSEDTEXFORMAT_EAC_RG11, + COMPRESSEDTEXFORMAT_EAC_SIGNED_RG11, + COMPRESSEDTEXFORMAT_ETC2_RGB8, + COMPRESSEDTEXFORMAT_ETC2_SRGB8, + COMPRESSEDTEXFORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1, + COMPRESSEDTEXFORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1, + COMPRESSEDTEXFORMAT_ETC2_EAC_RGBA8, + COMPRESSEDTEXFORMAT_ETC2_EAC_SRGB8_ALPHA8, + + COMPRESSEDTEXFORMAT_ASTC_4x4_RGBA, + COMPRESSEDTEXFORMAT_ASTC_5x4_RGBA, + COMPRESSEDTEXFORMAT_ASTC_5x5_RGBA, + COMPRESSEDTEXFORMAT_ASTC_6x5_RGBA, + COMPRESSEDTEXFORMAT_ASTC_6x6_RGBA, + COMPRESSEDTEXFORMAT_ASTC_8x5_RGBA, + COMPRESSEDTEXFORMAT_ASTC_8x6_RGBA, + COMPRESSEDTEXFORMAT_ASTC_8x8_RGBA, + COMPRESSEDTEXFORMAT_ASTC_10x5_RGBA, + COMPRESSEDTEXFORMAT_ASTC_10x6_RGBA, + COMPRESSEDTEXFORMAT_ASTC_10x8_RGBA, + COMPRESSEDTEXFORMAT_ASTC_10x10_RGBA, + COMPRESSEDTEXFORMAT_ASTC_12x10_RGBA, + COMPRESSEDTEXFORMAT_ASTC_12x12_RGBA, + COMPRESSEDTEXFORMAT_ASTC_4x4_SRGB8_ALPHA8, + COMPRESSEDTEXFORMAT_ASTC_5x4_SRGB8_ALPHA8, + COMPRESSEDTEXFORMAT_ASTC_5x5_SRGB8_ALPHA8, + COMPRESSEDTEXFORMAT_ASTC_6x5_SRGB8_ALPHA8, + COMPRESSEDTEXFORMAT_ASTC_6x6_SRGB8_ALPHA8, + COMPRESSEDTEXFORMAT_ASTC_8x5_SRGB8_ALPHA8, + COMPRESSEDTEXFORMAT_ASTC_8x6_SRGB8_ALPHA8, + COMPRESSEDTEXFORMAT_ASTC_8x8_SRGB8_ALPHA8, + COMPRESSEDTEXFORMAT_ASTC_10x5_SRGB8_ALPHA8, + COMPRESSEDTEXFORMAT_ASTC_10x6_SRGB8_ALPHA8, + COMPRESSEDTEXFORMAT_ASTC_10x8_SRGB8_ALPHA8, + COMPRESSEDTEXFORMAT_ASTC_10x10_SRGB8_ALPHA8, + COMPRESSEDTEXFORMAT_ASTC_12x10_SRGB8_ALPHA8, + COMPRESSEDTEXFORMAT_ASTC_12x12_SRGB8_ALPHA8, + + COMPRESSEDTEXFORMAT_LAST +}; + +int getBlockSize (CompressedTexFormat format); +IVec3 getBlockPixelSize (CompressedTexFormat format); + +bool isEtcFormat (CompressedTexFormat format); +bool isAstcFormat (CompressedTexFormat format); +bool isAstcSRGBFormat (CompressedTexFormat format); + +TextureFormat getUncompressedFormat (CompressedTexFormat format); +CompressedTexFormat getAstcFormatByBlockSize (const IVec3& size, bool isSRGB); + +struct TexDecompressionParams +{ + enum AstcMode + { + ASTCMODE_LDR = 0, + ASTCMODE_HDR, + ASTCMODE_LAST + }; + + TexDecompressionParams (AstcMode astcMode_ = ASTCMODE_LAST) : astcMode(astcMode_) {} + + AstcMode astcMode; +}; + /*--------------------------------------------------------------------*//*! * \brief Compressed texture * @@ -40,90 +110,32 @@ namespace tcu class CompressedTexture { public: - enum Format - { - ETC1_RGB8 = 0, - EAC_R11, - EAC_SIGNED_R11, - EAC_RG11, - EAC_SIGNED_RG11, - ETC2_RGB8, - ETC2_SRGB8, - ETC2_RGB8_PUNCHTHROUGH_ALPHA1, - ETC2_SRGB8_PUNCHTHROUGH_ALPHA1, - ETC2_EAC_RGBA8, - ETC2_EAC_SRGB8_ALPHA8, - - ASTC_4x4_RGBA, - ASTC_5x4_RGBA, - ASTC_5x5_RGBA, - ASTC_6x5_RGBA, - ASTC_6x6_RGBA, - ASTC_8x5_RGBA, - ASTC_8x6_RGBA, - ASTC_8x8_RGBA, - ASTC_10x5_RGBA, - ASTC_10x6_RGBA, - ASTC_10x8_RGBA, - ASTC_10x10_RGBA, - ASTC_12x10_RGBA, - ASTC_12x12_RGBA, - ASTC_4x4_SRGB8_ALPHA8, - ASTC_5x4_SRGB8_ALPHA8, - ASTC_5x5_SRGB8_ALPHA8, - ASTC_6x5_SRGB8_ALPHA8, - ASTC_6x6_SRGB8_ALPHA8, - ASTC_8x5_SRGB8_ALPHA8, - ASTC_8x6_SRGB8_ALPHA8, - ASTC_8x8_SRGB8_ALPHA8, - ASTC_10x5_SRGB8_ALPHA8, - ASTC_10x6_SRGB8_ALPHA8, - ASTC_10x8_SRGB8_ALPHA8, - ASTC_10x10_SRGB8_ALPHA8, - ASTC_12x10_SRGB8_ALPHA8, - ASTC_12x12_SRGB8_ALPHA8, - - FORMAT_LAST - }; - - struct DecompressionParams - { - bool isASTCModeLDR; //!< \note Ignored if not ASTC format. - - DecompressionParams (bool isASTCModeLDR_) : isASTCModeLDR(isASTCModeLDR_) {} - }; - - CompressedTexture (Format format, int width, int height, int depth = 1); + CompressedTexture (CompressedTexFormat format, int width, int height, int depth = 1); CompressedTexture (void); ~CompressedTexture (void); - void setStorage (Format format, int width, int height, int depth = 1); + void setStorage (CompressedTexFormat format, int width, int height, int depth = 1); int getWidth (void) const { return m_width; } int getHeight (void) const { return m_height; } - Format getFormat (void) const { return m_format; } + int getDepth (void) const { return m_depth; } + CompressedTexFormat getFormat (void) const { return m_format; } int getDataSize (void) const { return (int)m_data.size(); } const void* getData (void) const { return &m_data[0]; } void* getData (void) { return &m_data[0]; } - TextureFormat getUncompressedFormat (void) const; - void decompress (const PixelBufferAccess& dst, const DecompressionParams& params = DecompressionParams(false)) const; + void decompress (const PixelBufferAccess& dst, const TexDecompressionParams& params = TexDecompressionParams()) const; private: - Format m_format; + CompressedTexFormat m_format; int m_width; int m_height; int m_depth; std::vector m_data; }; -bool isEtcFormat (CompressedTexture::Format fmt); -bool isASTCFormat (CompressedTexture::Format fmt); -bool isASTCSRGBFormat (CompressedTexture::Format fmt); - -IVec3 getASTCBlockSize (CompressedTexture::Format fmt); -CompressedTexture::Format getASTCFormatByBlockSize (int width, int height, int depth, bool isSRGB); +void decompress (const PixelBufferAccess& dst, CompressedTexFormat fmt, const deUint8* src, const TexDecompressionParams& params); } // tcu diff --git a/framework/common/tcuImageIO.cpp b/framework/common/tcuImageIO.cpp index a7ea19b..e17443b 100644 --- a/framework/common/tcuImageIO.cpp +++ b/framework/common/tcuImageIO.cpp @@ -248,7 +248,7 @@ void loadPKM (CompressedTexture& dst, const tcu::Archive& archive, const char* f DE_UNREF(width && height); - dst.setStorage(CompressedTexture::ETC1_RGB8, (int)activeWidth, (int)activeHeight); + dst.setStorage(COMPRESSEDTEXFORMAT_ETC1_RGB8, (int)activeWidth, (int)activeHeight); resource->read((deUint8*)dst.getData(), dst.getDataSize()); } diff --git a/framework/common/tcuTexture.hpp b/framework/common/tcuTexture.hpp index 43aab89..c4b6e85 100644 --- a/framework/common/tcuTexture.hpp +++ b/framework/common/tcuTexture.hpp @@ -301,20 +301,20 @@ protected: class PixelBufferAccess : public ConstPixelBufferAccess { public: - PixelBufferAccess (void) {} - PixelBufferAccess (TextureLevel& level); - PixelBufferAccess (const TextureFormat& format, int width, int height, int depth, void* data); - PixelBufferAccess (const TextureFormat& format, int width, int height, int depth, int rowPitch, int slicePitch, void* data); + PixelBufferAccess (void) {} + PixelBufferAccess (TextureLevel& level); + PixelBufferAccess (const TextureFormat& format, int width, int height, int depth, void* data); + PixelBufferAccess (const TextureFormat& format, int width, int height, int depth, int rowPitch, int slicePitch, void* data); - void* getDataPtr (void) const { return m_data; } + void* getDataPtr (void) const { return m_data; } - void setPixels (const void* buf, int bufSize) const; - void setPixel (const tcu::Vec4& color, int x, int y, int z = 0) const; - void setPixel (const tcu::IVec4& color, int x, int y, int z = 0) const; - void setPixel (const tcu::UVec4& color, int x, int y, int z = 0) const { setPixel(color.cast(), x, y, z); } + void setPixels (const void* buf, int bufSize) const; + void setPixel (const tcu::Vec4& color, int x, int y, int z = 0) const; + void setPixel (const tcu::IVec4& color, int x, int y, int z = 0) const; + void setPixel (const tcu::UVec4& color, int x, int y, int z = 0) const { setPixel(color.cast(), x, y, z); } - void setPixDepth (float depth, int x, int y, int z = 0) const; - void setPixStencil (int stencil, int x, int y, int z = 0) const; + void setPixDepth (float depth, int x, int y, int z = 0) const; + void setPixStencil (int stencil, int x, int y, int z = 0) const; }; /*--------------------------------------------------------------------*//*! @@ -327,32 +327,32 @@ public: class TextureLevel { public: - TextureLevel (void); - TextureLevel (const TextureFormat& format); - TextureLevel (const TextureFormat& format, int width, int height, int depth = 1); - ~TextureLevel (void); + TextureLevel (void); + TextureLevel (const TextureFormat& format); + TextureLevel (const TextureFormat& format, int width, int height, int depth = 1); + ~TextureLevel (void); - int getWidth (void) const { return m_width; } - int getHeight (void) const { return m_height; } - int getDepth (void) const { return m_depth; } - bool isEmpty (void) const { return m_width == 0 || m_height == 0 || m_depth == 0; } - const TextureFormat getFormat (void) const { return m_format; } + int getWidth (void) const { return m_width; } + int getHeight (void) const { return m_height; } + int getDepth (void) const { return m_depth; } + bool isEmpty (void) const { return m_width == 0 || m_height == 0 || m_depth == 0; } + const TextureFormat getFormat (void) const { return m_format; } - void setStorage (const TextureFormat& format, int width, int heigth, int depth = 1); - void setSize (int width, int height, int depth = 1); + void setStorage (const TextureFormat& format, int width, int heigth, int depth = 1); + void setSize (int width, int height, int depth = 1); - PixelBufferAccess getAccess (void) { return PixelBufferAccess(m_format, m_width, m_height, m_depth, getPtr()); } - ConstPixelBufferAccess getAccess (void) const { return ConstPixelBufferAccess(m_format, m_width, m_height, m_depth, getPtr()); } + PixelBufferAccess getAccess (void) { return PixelBufferAccess(m_format, m_width, m_height, m_depth, getPtr()); } + ConstPixelBufferAccess getAccess (void) const { return ConstPixelBufferAccess(m_format, m_width, m_height, m_depth, getPtr()); } private: - void* getPtr (void) { return m_data.getPtr(); } - const void* getPtr (void) const { return m_data.getPtr(); } - - TextureFormat m_format; - int m_width; - int m_height; - int m_depth; - de::ArrayBuffer m_data; + void* getPtr (void) { return m_data.getPtr(); } + const void* getPtr (void) const { return m_data.getPtr(); } + + TextureFormat m_format; + int m_width; + int m_height; + int m_depth; + de::ArrayBuffer m_data; friend class ConstPixelBufferAccess; }; diff --git a/framework/common/tcuTextureUtil.cpp b/framework/common/tcuTextureUtil.cpp index c83d151..376ab66 100644 --- a/framework/common/tcuTextureUtil.cpp +++ b/framework/common/tcuTextureUtil.cpp @@ -113,9 +113,15 @@ TextureChannelClass getTextureChannelClass (TextureFormat::ChannelType channelTy *//*--------------------------------------------------------------------*/ ConstPixelBufferAccess getSubregion (const ConstPixelBufferAccess& access, int x, int y, int z, int width, int height, int depth) { - DE_ASSERT(de::inBounds(x, 0, access.getWidth()) && de::inRange(x+width, x, access.getWidth())); - DE_ASSERT(de::inBounds(y, 0, access.getHeight()) && de::inRange(y+height, y, access.getHeight())); - DE_ASSERT(de::inBounds(z, 0, access.getDepth()) && de::inRange(z+depth, z, access.getDepth())); + DE_ASSERT(de::inBounds(x, 0, access.getWidth())); + DE_ASSERT(de::inRange(x+width, x+1, access.getWidth())); + + DE_ASSERT(de::inBounds(y, 0, access.getHeight())); + DE_ASSERT(de::inRange(y+height, y+1, access.getHeight())); + + DE_ASSERT(de::inBounds(z, 0, access.getDepth())); + DE_ASSERT(de::inRange(z+depth, z+1, access.getDepth())); + return ConstPixelBufferAccess(access.getFormat(), width, height, depth, access.getRowPitch(), access.getSlicePitch(), (const deUint8*)access.getDataPtr() + access.getFormat().getPixelSize()*x + access.getRowPitch()*y + access.getSlicePitch()*z); } @@ -133,9 +139,15 @@ ConstPixelBufferAccess getSubregion (const ConstPixelBufferAccess& access, int x *//*--------------------------------------------------------------------*/ PixelBufferAccess getSubregion (const PixelBufferAccess& access, int x, int y, int z, int width, int height, int depth) { - DE_ASSERT(de::inBounds(x, 0, access.getWidth()) && de::inRange(x+width, x, access.getWidth())); - DE_ASSERT(de::inBounds(y, 0, access.getHeight()) && de::inRange(y+height, y, access.getHeight())); - DE_ASSERT(de::inBounds(z, 0, access.getDepth()) && de::inRange(z+depth, z, access.getDepth())); + DE_ASSERT(de::inBounds(x, 0, access.getWidth())); + DE_ASSERT(de::inRange(x+width, x+1, access.getWidth())); + + DE_ASSERT(de::inBounds(y, 0, access.getHeight())); + DE_ASSERT(de::inRange(y+height, y+1, access.getHeight())); + + DE_ASSERT(de::inBounds(z, 0, access.getDepth())); + DE_ASSERT(de::inRange(z+depth, z+1, access.getDepth())); + return PixelBufferAccess(access.getFormat(), width, height, depth, access.getRowPitch(), access.getSlicePitch(), (deUint8*)access.getDataPtr() + access.getFormat().getPixelSize()*x + access.getRowPitch()*y + access.getSlicePitch()*z); } @@ -932,4 +944,29 @@ int getCubeArrayFaceIndex (CubeFace face) } } +void copyRawPixels (const PixelBufferAccess& dst, const ConstPixelBufferAccess& src) +{ + DE_ASSERT(dst.getFormat().getPixelSize() == src.getFormat().getPixelSize()); + DE_ASSERT(dst.getWidth() == src.getWidth()); + DE_ASSERT(dst.getHeight() == src.getHeight()); + DE_ASSERT(dst.getDepth() == src.getDepth()); + + const int pixelSize = dst.getFormat().getPixelSize(); + + for (int z = 0; z < dst.getDepth(); z++) + for (int y = 0; y < dst.getHeight(); y++) + { + const deUint8* const srcPtr = (const deUint8*)src.getDataPtr() + + src.getRowPitch() * y + + src.getSlicePitch() * z; + + deUint8* const dstPtr = (deUint8*)dst.getDataPtr() + + dst.getRowPitch() * y + + dst.getSlicePitch() * z; + + deMemcpy(dstPtr, srcPtr, dst.getWidth() * pixelSize); + } +} + + } // tcu diff --git a/framework/common/tcuTextureUtil.hpp b/framework/common/tcuTextureUtil.hpp index 72d4bcb..73e685a 100644 --- a/framework/common/tcuTextureUtil.hpp +++ b/framework/common/tcuTextureUtil.hpp @@ -96,6 +96,9 @@ void fillWithRGBAQuads (const PixelBufferAccess& access); void copy (const PixelBufferAccess& dst, const ConstPixelBufferAccess& src); void scale (const PixelBufferAccess& dst, const ConstPixelBufferAccess& src, Sampler::FilterMode filter); +// Copy raw pixel data between buffers. Both buffers must have same pixel size. +void copyRawPixels (const PixelBufferAccess& dst, const ConstPixelBufferAccess& src); + void estimatePixelValueRange (const ConstPixelBufferAccess& access, Vec4& minVal, Vec4& maxVal); void computePixelScaleBias (const ConstPixelBufferAccess& access, Vec4& scale, Vec4& bias); diff --git a/framework/opengl/gluTexture.cpp b/framework/opengl/gluTexture.cpp index e0386b5..c402a50 100644 --- a/framework/opengl/gluTexture.cpp +++ b/framework/opengl/gluTexture.cpp @@ -126,11 +126,11 @@ Texture2D::Texture2D (const RenderContext& context, deUint32 sizedFormat, int wi GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures() failed"); } -Texture2D::Texture2D (const RenderContext& context, const ContextInfo& contextInfo, int numLevels, const tcu::CompressedTexture* levels, const tcu::CompressedTexture::DecompressionParams& decompressionParams) +Texture2D::Texture2D (const RenderContext& context, const ContextInfo& contextInfo, int numLevels, const tcu::CompressedTexture* levels, const tcu::TexDecompressionParams& decompressionParams) : m_context (context) , m_isCompressed (true) , m_format (getGLFormat(levels[0].getFormat())) - , m_refTexture (levels[0].getUncompressedFormat(), levels[0].getWidth(), levels[0].getHeight()) + , m_refTexture (getUncompressedFormat(levels[0].getFormat()), levels[0].getWidth(), levels[0].getHeight()) , m_glTexture (0) { const glw::Functions& gl = context.getFunctions(); @@ -184,7 +184,7 @@ void Texture2D::upload (void) GLU_EXPECT_NO_ERROR(gl.getError(), "Texture upload failed"); } -void Texture2D::loadCompressed (int numLevels, const tcu::CompressedTexture* levels, const tcu::CompressedTexture::DecompressionParams& decompressionParams) +void Texture2D::loadCompressed (int numLevels, const tcu::CompressedTexture* levels, const tcu::TexDecompressionParams& decompressionParams) { const glw::Functions& gl = m_context.getFunctions(); deUint32 compressedFormat = getGLFormat(levels[0].getFormat()); @@ -285,11 +285,11 @@ Texture2D* Texture2D::create (const RenderContext& context, const ContextInfo& c // TextureCube -TextureCube::TextureCube (const RenderContext& context, const ContextInfo& contextInfo, int numLevels, const tcu::CompressedTexture* levels, const tcu::CompressedTexture::DecompressionParams& decompressionParams) +TextureCube::TextureCube (const RenderContext& context, const ContextInfo& contextInfo, int numLevels, const tcu::CompressedTexture* levels, const tcu::TexDecompressionParams& decompressionParams) : m_context (context) , m_isCompressed (true) , m_format (getGLFormat(levels[0].getFormat())) - , m_refTexture (levels[0].getUncompressedFormat(), levels[0].getWidth()) + , m_refTexture (getUncompressedFormat(levels[0].getFormat()), levels[0].getWidth()) , m_glTexture (0) { const glw::Functions& gl = m_context.getFunctions(); @@ -388,7 +388,7 @@ void TextureCube::upload (void) GLU_EXPECT_NO_ERROR(gl.getError(), "Texture upload failed"); } -void TextureCube::loadCompressed (int numLevels, const tcu::CompressedTexture* levels, const tcu::CompressedTexture::DecompressionParams& decompressionParams) +void TextureCube::loadCompressed (int numLevels, const tcu::CompressedTexture* levels, const tcu::TexDecompressionParams& decompressionParams) { const glw::Functions& gl = m_context.getFunctions(); deUint32 compressedFormat = getGLFormat(levels[0].getFormat()); @@ -510,6 +510,7 @@ void Texture1DArray::upload (void) Texture2DArray::Texture2DArray (const RenderContext& context, deUint32 format, deUint32 dataType, int width, int height, int numLevels) : m_context (context) + , m_isCompressed (false) , m_format (format) , m_refTexture (mapGLTransferFormat(format, dataType), width, height, numLevels) , m_glTexture (0) @@ -522,6 +523,7 @@ Texture2DArray::Texture2DArray (const RenderContext& context, deUint32 format, d Texture2DArray::Texture2DArray (const RenderContext& context, deUint32 sizedFormat, int width, int height, int numLevels) : m_context (context) + , m_isCompressed (false) , m_format (sizedFormat) , m_refTexture (mapGLInternalFormat(sizedFormat), width, height, numLevels) , m_glTexture (0) @@ -532,6 +534,32 @@ Texture2DArray::Texture2DArray (const RenderContext& context, deUint32 sizedForm GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures() failed"); } +Texture2DArray::Texture2DArray (const RenderContext& context, const ContextInfo& contextInfo, int numLevels, const tcu::CompressedTexture* levels, const tcu::TexDecompressionParams& decompressionParams) + : m_context (context) + , m_isCompressed (true) + , m_format (getGLFormat(levels[0].getFormat())) + , m_refTexture (getUncompressedFormat(levels[0].getFormat()), levels[0].getWidth(), levels[0].getHeight(), levels[0].getDepth()) + , m_glTexture (0) +{ + const glw::Functions& gl = context.getFunctions(); + + if (!contextInfo.isCompressedTextureFormatSupported(m_format)) + throw tcu::NotSupportedError("Compressed texture format not supported", "", __FILE__, __LINE__); + + gl.genTextures(1, &m_glTexture); + GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures() failed"); + + try + { + loadCompressed(numLevels, levels, decompressionParams); + } + catch (const std::exception&) + { + gl.deleteTextures(1, &m_glTexture); + throw; + } +} + Texture2DArray::~Texture2DArray (void) { if (m_glTexture) @@ -566,6 +594,34 @@ void Texture2DArray::upload (void) GLU_EXPECT_NO_ERROR(gl.getError(), "Texture upload failed"); } +void Texture2DArray::loadCompressed (int numLevels, const tcu::CompressedTexture* levels, const tcu::TexDecompressionParams& decompressionParams) +{ + const glw::Functions& gl = m_context.getFunctions(); + deUint32 compressedFormat = getGLFormat(levels[0].getFormat()); + + TCU_CHECK(m_glTexture); + gl.bindTexture(GL_TEXTURE_2D_ARRAY, m_glTexture); + + for (int levelNdx = 0; levelNdx < numLevels; levelNdx++) + { + const tcu::CompressedTexture& level = levels[levelNdx]; + + // Decompress to reference texture. + m_refTexture.allocLevel(levelNdx); + tcu::PixelBufferAccess refLevelAccess = m_refTexture.getLevel(levelNdx); + TCU_CHECK(level.getWidth() == refLevelAccess.getWidth() && + level.getHeight() == refLevelAccess.getHeight() && + level.getDepth() == refLevelAccess.getDepth()); + level.decompress(refLevelAccess, decompressionParams); + + // Upload to GL texture in compressed form. + gl.compressedTexImage3D(GL_TEXTURE_2D_ARRAY, levelNdx, compressedFormat, + level.getWidth(), level.getHeight(), m_refTexture.getLevel(levelNdx).getDepth(), 0 /* border */, level.getDataSize(), level.getData()); + } + + GLU_EXPECT_NO_ERROR(gl.getError(), "Texture upload failed"); +} + // Texture3D Texture3D::Texture3D (const RenderContext& context, deUint32 format, deUint32 dataType, int width, int height, int depth) diff --git a/framework/opengl/gluTexture.hpp b/framework/opengl/gluTexture.hpp index a16172b..d2058a3 100644 --- a/framework/opengl/gluTexture.hpp +++ b/framework/opengl/gluTexture.hpp @@ -68,7 +68,7 @@ private: class Texture2D { public: - Texture2D (const RenderContext& context, const ContextInfo& contextInfo, int numLevels, const tcu::CompressedTexture* levels, const tcu::CompressedTexture::DecompressionParams& = tcu::CompressedTexture::DecompressionParams(false)); + Texture2D (const RenderContext& context, const ContextInfo& contextInfo, int numLevels, const tcu::CompressedTexture* levels, const tcu::TexDecompressionParams& decompressionParams = tcu::TexDecompressionParams()); Texture2D (const RenderContext& context, deUint32 format, deUint32 dataType, int width, int height); Texture2D (const RenderContext& context, deUint32 internalFormat, int width, int height); ~Texture2D (void); @@ -87,7 +87,7 @@ private: Texture2D (const Texture2D& other); // Not allowed! Texture2D& operator= (const Texture2D& other); // Not allowed! - void loadCompressed (int numLevels, const tcu::CompressedTexture* levels, const tcu::CompressedTexture::DecompressionParams&); + void loadCompressed (int numLevels, const tcu::CompressedTexture* levels, const tcu::TexDecompressionParams& decompressionParams); const RenderContext& m_context; @@ -108,7 +108,7 @@ public: // to laid out to array in following order: // { l0_neg_x, l0_pos_x, l0_neg_y, l0_pos_y, l0_neg_z, l0_pos_z, l1_neg_x, l1_pos_x, ... } - TextureCube (const RenderContext& context, const ContextInfo& contextInfo, int numLevels, const tcu::CompressedTexture* levels, const tcu::CompressedTexture::DecompressionParams& = tcu::CompressedTexture::DecompressionParams(false)); + TextureCube (const RenderContext& context, const ContextInfo& contextInfo, int numLevels, const tcu::CompressedTexture* levels, const tcu::TexDecompressionParams& decompressionParams = tcu::TexDecompressionParams()); TextureCube (const RenderContext& context, deUint32 format, deUint32 dataType, int size); TextureCube (const RenderContext& context, deUint32 internalFormat, int size); ~TextureCube (void); @@ -126,7 +126,7 @@ private: TextureCube (const TextureCube& other); // Not allowed! TextureCube& operator= (const TextureCube& other); // Not allowed! - void loadCompressed (int numLevels, const tcu::CompressedTexture* levels, const tcu::CompressedTexture::DecompressionParams&); + void loadCompressed (int numLevels, const tcu::CompressedTexture* levels, const tcu::TexDecompressionParams& decompressionParams); const RenderContext& m_context; @@ -146,6 +146,7 @@ class Texture2DArray public: Texture2DArray (const RenderContext& context, deUint32 format, deUint32 dataType, int width, int height, int numLayers); Texture2DArray (const RenderContext& context, deUint32 internalFormat, int width, int height, int numLayers); + Texture2DArray (const RenderContext& context, const ContextInfo& contextInfo, int numLevels, const tcu::CompressedTexture* levels, const tcu::TexDecompressionParams& decompressionParams = tcu::TexDecompressionParams()); ~Texture2DArray (void); void upload (void); @@ -158,8 +159,12 @@ private: Texture2DArray (const Texture2DArray& other); // Not allowed! Texture2DArray& operator= (const Texture2DArray& other); // Not allowed! + void loadCompressed (int numLevels, const tcu::CompressedTexture* levels, const tcu::TexDecompressionParams& decompressionParams); + + const RenderContext& m_context; + bool m_isCompressed; deUint32 m_format; //!< Internal format. tcu::Texture2DArray m_refTexture; @@ -233,6 +238,7 @@ class TextureCubeArray public: TextureCubeArray (const RenderContext& context, deUint32 format, deUint32 dataType, int size, int numLayers); TextureCubeArray (const RenderContext& context, deUint32 internalFormat, int size, int numLayers); + ~TextureCubeArray (void); void upload (void); @@ -247,6 +253,7 @@ private: const RenderContext& m_context; + bool m_isCompressed; deUint32 m_format; //!< Internal format. tcu::TextureCubeArray m_refTexture; diff --git a/framework/opengl/gluTextureUtil.cpp b/framework/opengl/gluTextureUtil.cpp index 41056c0..e26ab54 100644 --- a/framework/opengl/gluTextureUtil.cpp +++ b/framework/opengl/gluTextureUtil.cpp @@ -224,50 +224,50 @@ deUint32 getInternalFormat (tcu::TextureFormat texFormat) * \param format Generic compressed format. * \return GL compressed texture format. *//*--------------------------------------------------------------------*/ -deUint32 getGLFormat (tcu::CompressedTexture::Format format) +deUint32 getGLFormat (tcu::CompressedTexFormat format) { switch (format) { - case tcu::CompressedTexture::ETC1_RGB8: return GL_ETC1_RGB8_OES; - case tcu::CompressedTexture::EAC_R11: return GL_COMPRESSED_R11_EAC; - case tcu::CompressedTexture::EAC_SIGNED_R11: return GL_COMPRESSED_SIGNED_R11_EAC; - case tcu::CompressedTexture::EAC_RG11: return GL_COMPRESSED_RG11_EAC; - case tcu::CompressedTexture::EAC_SIGNED_RG11: return GL_COMPRESSED_SIGNED_RG11_EAC; - case tcu::CompressedTexture::ETC2_RGB8: return GL_COMPRESSED_RGB8_ETC2; - case tcu::CompressedTexture::ETC2_SRGB8: return GL_COMPRESSED_SRGB8_ETC2; - case tcu::CompressedTexture::ETC2_RGB8_PUNCHTHROUGH_ALPHA1: return GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2; - case tcu::CompressedTexture::ETC2_SRGB8_PUNCHTHROUGH_ALPHA1: return GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2; - case tcu::CompressedTexture::ETC2_EAC_RGBA8: return GL_COMPRESSED_RGBA8_ETC2_EAC; - case tcu::CompressedTexture::ETC2_EAC_SRGB8_ALPHA8: return GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC; - - case tcu::CompressedTexture::ASTC_4x4_RGBA: return GL_COMPRESSED_RGBA_ASTC_4x4_KHR; - case tcu::CompressedTexture::ASTC_5x4_RGBA: return GL_COMPRESSED_RGBA_ASTC_5x4_KHR; - case tcu::CompressedTexture::ASTC_5x5_RGBA: return GL_COMPRESSED_RGBA_ASTC_5x5_KHR; - case tcu::CompressedTexture::ASTC_6x5_RGBA: return GL_COMPRESSED_RGBA_ASTC_6x5_KHR; - case tcu::CompressedTexture::ASTC_6x6_RGBA: return GL_COMPRESSED_RGBA_ASTC_6x6_KHR; - case tcu::CompressedTexture::ASTC_8x5_RGBA: return GL_COMPRESSED_RGBA_ASTC_8x5_KHR; - case tcu::CompressedTexture::ASTC_8x6_RGBA: return GL_COMPRESSED_RGBA_ASTC_8x6_KHR; - case tcu::CompressedTexture::ASTC_8x8_RGBA: return GL_COMPRESSED_RGBA_ASTC_8x8_KHR; - case tcu::CompressedTexture::ASTC_10x5_RGBA: return GL_COMPRESSED_RGBA_ASTC_10x5_KHR; - case tcu::CompressedTexture::ASTC_10x6_RGBA: return GL_COMPRESSED_RGBA_ASTC_10x6_KHR; - case tcu::CompressedTexture::ASTC_10x8_RGBA: return GL_COMPRESSED_RGBA_ASTC_10x8_KHR; - case tcu::CompressedTexture::ASTC_10x10_RGBA: return GL_COMPRESSED_RGBA_ASTC_10x10_KHR; - case tcu::CompressedTexture::ASTC_12x10_RGBA: return GL_COMPRESSED_RGBA_ASTC_12x10_KHR; - case tcu::CompressedTexture::ASTC_12x12_RGBA: return GL_COMPRESSED_RGBA_ASTC_12x12_KHR; - case tcu::CompressedTexture::ASTC_4x4_SRGB8_ALPHA8: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR; - case tcu::CompressedTexture::ASTC_5x4_SRGB8_ALPHA8: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR; - case tcu::CompressedTexture::ASTC_5x5_SRGB8_ALPHA8: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR; - case tcu::CompressedTexture::ASTC_6x5_SRGB8_ALPHA8: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR; - case tcu::CompressedTexture::ASTC_6x6_SRGB8_ALPHA8: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR; - case tcu::CompressedTexture::ASTC_8x5_SRGB8_ALPHA8: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR; - case tcu::CompressedTexture::ASTC_8x6_SRGB8_ALPHA8: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR; - case tcu::CompressedTexture::ASTC_8x8_SRGB8_ALPHA8: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR; - case tcu::CompressedTexture::ASTC_10x5_SRGB8_ALPHA8: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR; - case tcu::CompressedTexture::ASTC_10x6_SRGB8_ALPHA8: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR; - case tcu::CompressedTexture::ASTC_10x8_SRGB8_ALPHA8: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR; - case tcu::CompressedTexture::ASTC_10x10_SRGB8_ALPHA8: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR; - case tcu::CompressedTexture::ASTC_12x10_SRGB8_ALPHA8: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR; - case tcu::CompressedTexture::ASTC_12x12_SRGB8_ALPHA8: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR; + case tcu::COMPRESSEDTEXFORMAT_ETC1_RGB8: return GL_ETC1_RGB8_OES; + case tcu::COMPRESSEDTEXFORMAT_EAC_R11: return GL_COMPRESSED_R11_EAC; + case tcu::COMPRESSEDTEXFORMAT_EAC_SIGNED_R11: return GL_COMPRESSED_SIGNED_R11_EAC; + case tcu::COMPRESSEDTEXFORMAT_EAC_RG11: return GL_COMPRESSED_RG11_EAC; + case tcu::COMPRESSEDTEXFORMAT_EAC_SIGNED_RG11: return GL_COMPRESSED_SIGNED_RG11_EAC; + case tcu::COMPRESSEDTEXFORMAT_ETC2_RGB8: return GL_COMPRESSED_RGB8_ETC2; + case tcu::COMPRESSEDTEXFORMAT_ETC2_SRGB8: return GL_COMPRESSED_SRGB8_ETC2; + case tcu::COMPRESSEDTEXFORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1: return GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2; + case tcu::COMPRESSEDTEXFORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1: return GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2; + case tcu::COMPRESSEDTEXFORMAT_ETC2_EAC_RGBA8: return GL_COMPRESSED_RGBA8_ETC2_EAC; + case tcu::COMPRESSEDTEXFORMAT_ETC2_EAC_SRGB8_ALPHA8: return GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC; + + case tcu::COMPRESSEDTEXFORMAT_ASTC_4x4_RGBA: return GL_COMPRESSED_RGBA_ASTC_4x4_KHR; + case tcu::COMPRESSEDTEXFORMAT_ASTC_5x4_RGBA: return GL_COMPRESSED_RGBA_ASTC_5x4_KHR; + case tcu::COMPRESSEDTEXFORMAT_ASTC_5x5_RGBA: return GL_COMPRESSED_RGBA_ASTC_5x5_KHR; + case tcu::COMPRESSEDTEXFORMAT_ASTC_6x5_RGBA: return GL_COMPRESSED_RGBA_ASTC_6x5_KHR; + case tcu::COMPRESSEDTEXFORMAT_ASTC_6x6_RGBA: return GL_COMPRESSED_RGBA_ASTC_6x6_KHR; + case tcu::COMPRESSEDTEXFORMAT_ASTC_8x5_RGBA: return GL_COMPRESSED_RGBA_ASTC_8x5_KHR; + case tcu::COMPRESSEDTEXFORMAT_ASTC_8x6_RGBA: return GL_COMPRESSED_RGBA_ASTC_8x6_KHR; + case tcu::COMPRESSEDTEXFORMAT_ASTC_8x8_RGBA: return GL_COMPRESSED_RGBA_ASTC_8x8_KHR; + case tcu::COMPRESSEDTEXFORMAT_ASTC_10x5_RGBA: return GL_COMPRESSED_RGBA_ASTC_10x5_KHR; + case tcu::COMPRESSEDTEXFORMAT_ASTC_10x6_RGBA: return GL_COMPRESSED_RGBA_ASTC_10x6_KHR; + case tcu::COMPRESSEDTEXFORMAT_ASTC_10x8_RGBA: return GL_COMPRESSED_RGBA_ASTC_10x8_KHR; + case tcu::COMPRESSEDTEXFORMAT_ASTC_10x10_RGBA: return GL_COMPRESSED_RGBA_ASTC_10x10_KHR; + case tcu::COMPRESSEDTEXFORMAT_ASTC_12x10_RGBA: return GL_COMPRESSED_RGBA_ASTC_12x10_KHR; + case tcu::COMPRESSEDTEXFORMAT_ASTC_12x12_RGBA: return GL_COMPRESSED_RGBA_ASTC_12x12_KHR; + case tcu::COMPRESSEDTEXFORMAT_ASTC_4x4_SRGB8_ALPHA8: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR; + case tcu::COMPRESSEDTEXFORMAT_ASTC_5x4_SRGB8_ALPHA8: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR; + case tcu::COMPRESSEDTEXFORMAT_ASTC_5x5_SRGB8_ALPHA8: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR; + case tcu::COMPRESSEDTEXFORMAT_ASTC_6x5_SRGB8_ALPHA8: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR; + case tcu::COMPRESSEDTEXFORMAT_ASTC_6x6_SRGB8_ALPHA8: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR; + case tcu::COMPRESSEDTEXFORMAT_ASTC_8x5_SRGB8_ALPHA8: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR; + case tcu::COMPRESSEDTEXFORMAT_ASTC_8x6_SRGB8_ALPHA8: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR; + case tcu::COMPRESSEDTEXFORMAT_ASTC_8x8_SRGB8_ALPHA8: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR; + case tcu::COMPRESSEDTEXFORMAT_ASTC_10x5_SRGB8_ALPHA8: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR; + case tcu::COMPRESSEDTEXFORMAT_ASTC_10x6_SRGB8_ALPHA8: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR; + case tcu::COMPRESSEDTEXFORMAT_ASTC_10x8_SRGB8_ALPHA8: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR; + case tcu::COMPRESSEDTEXFORMAT_ASTC_10x10_SRGB8_ALPHA8: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR; + case tcu::COMPRESSEDTEXFORMAT_ASTC_12x10_SRGB8_ALPHA8: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR; + case tcu::COMPRESSEDTEXFORMAT_ASTC_12x12_SRGB8_ALPHA8: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR; default: throw tcu::InternalError("Can't map compressed format to GL format"); diff --git a/framework/opengl/gluTextureUtil.hpp b/framework/opengl/gluTextureUtil.hpp index 4b4a7f9..6ba71df 100644 --- a/framework/opengl/gluTextureUtil.hpp +++ b/framework/opengl/gluTextureUtil.hpp @@ -66,7 +66,7 @@ tcu::Sampler::CompareMode mapGLCompareFunc (deUint32 mode); TransferFormat getTransferFormat (tcu::TextureFormat format); deUint32 getInternalFormat (tcu::TextureFormat format); -deUint32 getGLFormat (tcu::CompressedTexture::Format format); +deUint32 getGLFormat (tcu::CompressedTexFormat format); deUint32 getGLWrapMode (tcu::Sampler::WrapMode wrapMode); deUint32 getGLFilterMode (tcu::Sampler::FilterMode filterMode); diff --git a/modules/gles3/functional/es3fASTCDecompressionCases.cpp b/modules/gles3/functional/es3fASTCDecompressionCases.cpp index 299dcbd..2aa9001 100644 --- a/modules/gles3/functional/es3fASTCDecompressionCases.cpp +++ b/modules/gles3/functional/es3fASTCDecompressionCases.cpp @@ -60,6 +60,7 @@ using tcu::TestLog; using tcu::CompressedTexture; +using tcu::CompressedTexFormat; using tcu::IVec2; using tcu::IVec3; using tcu::IVec4; @@ -933,7 +934,7 @@ static Vec4 getBlockTestTypeColorBias (ASTCBlockTestType testType) } // Generate block data for a given ASTCBlockTestType and format. -static void generateBlockCaseTestData (vector& dst, CompressedTexture::Format format, ASTCBlockTestType testType) +static void generateBlockCaseTestData (vector& dst, CompressedTexFormat format, ASTCBlockTestType testType) { using namespace ASTCBlockGeneratorInternal; @@ -953,10 +954,10 @@ static void generateBlockCaseTestData (vector& dst, CompressedTexture:: ISEParams(ISEMODE_PLAIN_BIT, 5) }; - DE_ASSERT(tcu::isASTCFormat(format)); - DE_ASSERT(!(tcu::isASTCSRGBFormat(format) && isBlockTestTypeHDROnly(testType))); + DE_ASSERT(tcu::isAstcFormat(format)); + DE_ASSERT(!(tcu::isAstcSRGBFormat(format) && isBlockTestTypeHDROnly(testType))); - const IVec3 blockSize = getASTCBlockSize(format); + const IVec3 blockSize = getBlockPixelSize(format); DE_ASSERT(blockSize.z() == 1); switch (testType) @@ -1607,57 +1608,57 @@ static inline ASTCSupportLevel getASTCSupportLevel (const glu::ContextInfo& cont class ASTCRenderer2D { public: - ASTCRenderer2D (Context& context, - CompressedTexture::Format format, - deUint32 randomSeed); + ASTCRenderer2D (Context& context, + CompressedTexFormat format, + deUint32 randomSeed); - ~ASTCRenderer2D (void); + ~ASTCRenderer2D (void); - void initialize (int minRenderWidth, int minRenderHeight, const Vec4& colorScale, const Vec4& colorBias); - void clear (void); + void initialize (int minRenderWidth, int minRenderHeight, const Vec4& colorScale, const Vec4& colorBias); + void clear (void); - void render (Surface& referenceDst, - Surface& resultDst, - const glu::Texture2D& texture, - const tcu::TextureFormat& uncompressedFormat); + void render (Surface& referenceDst, + Surface& resultDst, + const glu::Texture2D& texture, + const tcu::TextureFormat& uncompressedFormat); - CompressedTexture::Format getFormat (void) const { return m_format; } - IVec2 getBlockSize (void) const { return m_blockSize; } - ASTCSupportLevel getASTCSupport (void) const { DE_ASSERT(m_initialized); return m_astcSupport; } + CompressedTexFormat getFormat (void) const { return m_format; } + IVec2 getBlockSize (void) const { return m_blockSize; } + ASTCSupportLevel getASTCSupport (void) const { DE_ASSERT(m_initialized); return m_astcSupport; } private: - Context& m_context; - TextureRenderer m_renderer; + Context& m_context; + TextureRenderer m_renderer; - const CompressedTexture::Format m_format; - const IVec2 m_blockSize; - ASTCSupportLevel m_astcSupport; - Vec4 m_colorScale; - Vec4 m_colorBias; + const CompressedTexFormat m_format; + const IVec2 m_blockSize; + ASTCSupportLevel m_astcSupport; + Vec4 m_colorScale; + Vec4 m_colorBias; - de::Random m_rnd; + de::Random m_rnd; - bool m_initialized; + bool m_initialized; }; } // ASTCDecompressionCaseInternal using namespace ASTCDecompressionCaseInternal; -ASTCRenderer2D::ASTCRenderer2D (Context& context, - CompressedTexture::Format format, - deUint32 randomSeed) +ASTCRenderer2D::ASTCRenderer2D (Context& context, + CompressedTexFormat format, + deUint32 randomSeed) : m_context (context) , m_renderer (context.getRenderContext(), context.getTestContext(), glu::GLSL_VERSION_300_ES, glu::PRECISION_HIGHP) , m_format (format) - , m_blockSize (tcu::getASTCBlockSize(format).xy()) + , m_blockSize (tcu::getBlockPixelSize(format).xy()) , m_astcSupport (ASTCSUPPORTLEVEL_NONE) , m_colorScale (-1.0f) , m_colorBias (-1.0f) , m_rnd (randomSeed) , m_initialized (false) { - DE_ASSERT(tcu::getASTCBlockSize(format).z() == 1); + DE_ASSERT(tcu::getBlockPixelSize(format).z() == 1); } ASTCRenderer2D::~ASTCRenderer2D (void) @@ -1743,11 +1744,11 @@ void ASTCRenderer2D::render (Surface& referenceDst, Surface& resultDst, const gl glu::readPixels(renderCtx, viewport.x, viewport.y, resultDst.getAccess()); } -ASTCBlockCase2D::ASTCBlockCase2D (Context& context, - const char* name, - const char* description, - ASTCBlockTestType testType, - CompressedTexture::Format format) +ASTCBlockCase2D::ASTCBlockCase2D (Context& context, + const char* name, + const char* description, + ASTCBlockTestType testType, + CompressedTexFormat format) : TestCase (context, name, description) , m_testType (testType) , m_format (format) @@ -1755,7 +1756,7 @@ ASTCBlockCase2D::ASTCBlockCase2D (Context& context, , m_currentIteration (0) , m_renderer (new ASTCRenderer2D(context, format, deStringHash(getName()))) { - DE_ASSERT(!(tcu::isASTCSRGBFormat(m_format) && isBlockTestTypeHDROnly(m_testType))); // \note There is no HDR sRGB mode, so these would be redundant. + DE_ASSERT(!(tcu::isAstcSRGBFormat(m_format) && isBlockTestTypeHDROnly(m_testType))); // \note There is no HDR sRGB mode, so these would be redundant. } ASTCBlockCase2D::~ASTCBlockCase2D (void) @@ -1803,7 +1804,7 @@ ASTCBlockCase2D::IterateResult ASTCBlockCase2D::iterate (void) const int curNumNonDummyBlocks = de::min(numBlocksPerImage, numBlocksRemaining); const int curNumDummyBlocks = numBlocksPerImage - curNumNonDummyBlocks; const glu::RenderContext& renderCtx = m_context.getRenderContext(); - const tcu::RGBA threshold = renderCtx.getRenderTarget().getPixelFormat().getColorThreshold() + (tcu::isASTCSRGBFormat(m_format) ? tcu::RGBA(2,2,2,2) : tcu::RGBA(1,1,1,1)); + const tcu::RGBA threshold = renderCtx.getRenderTarget().getPixelFormat().getColorThreshold() + (tcu::isAstcSRGBFormat(m_format) ? tcu::RGBA(2,2,2,2) : tcu::RGBA(1,1,1,1)); tcu::CompressedTexture compressed (m_format, imageWidth, imageHeight); if (m_currentIteration == 0) @@ -1822,11 +1823,11 @@ ASTCBlockCase2D::IterateResult ASTCBlockCase2D::iterate (void) // Create texture and render. - glu::Texture2D texture (renderCtx, m_context.getContextInfo(), 1, &compressed, tcu::CompressedTexture::DecompressionParams(m_renderer->getASTCSupport() == ASTCSUPPORTLEVEL_LDR)); + glu::Texture2D texture (renderCtx, m_context.getContextInfo(), 1, &compressed, tcu::TexDecompressionParams((m_renderer->getASTCSupport() == ASTCSUPPORTLEVEL_LDR ? tcu::TexDecompressionParams::ASTCMODE_LDR : tcu::TexDecompressionParams::ASTCMODE_HDR))); Surface renderedFrame (imageWidth, imageHeight); Surface referenceFrame (imageWidth, imageHeight); - m_renderer->render(referenceFrame, renderedFrame, texture, compressed.getUncompressedFormat()); + m_renderer->render(referenceFrame, renderedFrame, texture, getUncompressedFormat(compressed.getFormat())); // Compare and log. // \note Since a case can draw quite many images, only log the first iteration and failures. @@ -1903,10 +1904,10 @@ void ASTCBlockCase2D::generateDummyBlocks (deUint8* dst, int num) block.assignToMemory(&dst[i * ASTC_BLOCK_SIZE_BYTES]); } -ASTCBlockSizeRemainderCase2D::ASTCBlockSizeRemainderCase2D (Context& context, - const char* name, - const char* description, - CompressedTexture::Format format) +ASTCBlockSizeRemainderCase2D::ASTCBlockSizeRemainderCase2D (Context& context, + const char* name, + const char* description, + CompressedTexFormat format) : TestCase (context, name, description) , m_format (format) , m_currentIteration (0) @@ -1942,7 +1943,7 @@ ASTCBlockSizeRemainderCase2D::IterateResult ASTCBlockSizeRemainderCase2D::iterat const int numBlocksY = divRoundUp(imageHeight, blockSize.y()); const int totalNumBlocks = numBlocksX * numBlocksY; const glu::RenderContext& renderCtx = m_context.getRenderContext(); - const tcu::RGBA threshold = renderCtx.getRenderTarget().getPixelFormat().getColorThreshold() + (tcu::isASTCSRGBFormat(m_format) ? tcu::RGBA(2,2,2,2) : tcu::RGBA(1,1,1,1)); + const tcu::RGBA threshold = renderCtx.getRenderTarget().getPixelFormat().getColorThreshold() + (tcu::isAstcSRGBFormat(m_format) ? tcu::RGBA(2,2,2,2) : tcu::RGBA(1,1,1,1)); tcu::CompressedTexture compressed (m_format, imageWidth, imageHeight); DE_ASSERT(compressed.getDataSize() == totalNumBlocks*ASTC_BLOCK_SIZE_BYTES); @@ -1952,9 +1953,9 @@ ASTCBlockSizeRemainderCase2D::IterateResult ASTCBlockSizeRemainderCase2D::iterat Surface renderedFrame (imageWidth, imageHeight); Surface referenceFrame (imageWidth, imageHeight); - glu::Texture2D texture (renderCtx, m_context.getContextInfo(), 1, &compressed, tcu::CompressedTexture::DecompressionParams(m_renderer->getASTCSupport() == ASTCSUPPORTLEVEL_LDR)); + glu::Texture2D texture (renderCtx, m_context.getContextInfo(), 1, &compressed, tcu::TexDecompressionParams(m_renderer->getASTCSupport() == ASTCSUPPORTLEVEL_LDR ? tcu::TexDecompressionParams::ASTCMODE_LDR : tcu::TexDecompressionParams::ASTCMODE_HDR)); - m_renderer->render(referenceFrame, renderedFrame, texture, compressed.getUncompressedFormat()); + m_renderer->render(referenceFrame, renderedFrame, texture, getUncompressedFormat(compressed.getFormat())); { // Compare and log. diff --git a/modules/gles3/functional/es3fASTCDecompressionCases.hpp b/modules/gles3/functional/es3fASTCDecompressionCases.hpp index 115caff..9d7e480 100644 --- a/modules/gles3/functional/es3fASTCDecompressionCases.hpp +++ b/modules/gles3/functional/es3fASTCDecompressionCases.hpp @@ -66,11 +66,11 @@ enum ASTCBlockTestType class ASTCBlockCase2D : public TestCase { public: - ASTCBlockCase2D (Context& context, - const char* name, - const char* description, - ASTCBlockTestType testType, - tcu::CompressedTexture::Format format); + ASTCBlockCase2D (Context& context, + const char* name, + const char* description, + ASTCBlockTestType testType, + tcu::CompressedTexFormat format); ~ASTCBlockCase2D (void); void init (void); @@ -84,7 +84,7 @@ private: ASTCBlockCase2D& operator= (const ASTCBlockCase2D& other); const ASTCBlockTestType m_testType; - const tcu::CompressedTexture::Format m_format; + const tcu::CompressedTexFormat m_format; std::vector m_blockData; int m_numBlocksTested; @@ -97,10 +97,10 @@ private: class ASTCBlockSizeRemainderCase2D : public TestCase { public: - ASTCBlockSizeRemainderCase2D (Context& context, - const char* name, - const char* description, - tcu::CompressedTexture::Format format); + ASTCBlockSizeRemainderCase2D (Context& context, + const char* name, + const char* description, + tcu::CompressedTexFormat format); ~ASTCBlockSizeRemainderCase2D (void); void init (void); @@ -119,7 +119,7 @@ private: ASTCBlockSizeRemainderCase2D (const ASTCBlockSizeRemainderCase2D& other); ASTCBlockSizeRemainderCase2D& operator= (const ASTCBlockSizeRemainderCase2D& other); - const tcu::CompressedTexture::Format m_format; + const tcu::CompressedTexFormat m_format; int m_currentIteration; diff --git a/modules/gles3/functional/es3fCompressedTextureTests.cpp b/modules/gles3/functional/es3fCompressedTextureTests.cpp index 3dbdff7..648d8f4 100644 --- a/modules/gles3/functional/es3fCompressedTextureTests.cpp +++ b/modules/gles3/functional/es3fCompressedTextureTests.cpp @@ -34,6 +34,7 @@ using std::string; using tcu::IVec3; using tcu::CompressedTexture; +using tcu::CompressedTexFormat; namespace deqp { @@ -42,13 +43,13 @@ namespace gles3 namespace Functional { -static const string getASTCFormatShortName (CompressedTexture::Format format) +static const string getASTCFormatShortName (CompressedTexFormat format) { - DE_ASSERT(tcu::isASTCFormat(format)); - const IVec3 blockSize = tcu::getASTCBlockSize(format); + DE_ASSERT(tcu::isAstcFormat(format)); + const IVec3 blockSize = tcu::getBlockPixelSize(format); DE_ASSERT(blockSize.z() == 1); - return de::toString(blockSize.x()) + "x" + de::toString(blockSize.y()) + (tcu::isASTCSRGBFormat(format) ? "_srgb" : ""); + return de::toString(blockSize.x()) + "x" + de::toString(blockSize.y()) + (tcu::isAstcSRGBFormat(format) ? "_srgb" : ""); } CompressedTextureTests::CompressedTextureTests (Context& context) @@ -75,13 +76,13 @@ void CompressedTextureTests::init (void) TestCaseGroup* const testTypeGroup = new TestCaseGroup(m_context, getBlockTestTypeName(astcTestType), getBlockTestTypeDescription(astcTestType)); astcGroup->addChild(testTypeGroup); - for (int formatI = 0; formatI < CompressedTexture::FORMAT_LAST; formatI++) + for (int formatI = 0; formatI < tcu::COMPRESSEDTEXFORMAT_LAST; formatI++) { - const CompressedTexture::Format format = (CompressedTexture::Format)formatI; + const CompressedTexFormat format = (CompressedTexFormat)formatI; - if (!tcu::isASTCFormat(format)) + if (!tcu::isAstcFormat(format)) continue; - if (tcu::isASTCSRGBFormat(format) && isBlockTestTypeHDROnly(astcTestType)) + if (tcu::isAstcSRGBFormat(format) && isBlockTestTypeHDROnly(astcTestType)) continue; testTypeGroup->addChild(new ASTCBlockCase2D(m_context, getASTCFormatShortName(format).c_str(), glu::getCompressedTexFormatName(glu::getGLFormat(format)), astcTestType, format)); @@ -94,11 +95,11 @@ void CompressedTextureTests::init (void) TestCaseGroup* const blockSizeRemainderGroup = new TestCaseGroup(m_context, "block_size_remainder", "Test image size/block size remainders"); astcGroup->addChild(blockSizeRemainderGroup); - for (int formatI = 0; formatI < CompressedTexture::FORMAT_LAST; formatI++) + for (int formatI = 0; formatI < tcu::COMPRESSEDTEXFORMAT_LAST; formatI++) { - const CompressedTexture::Format format = (CompressedTexture::Format)formatI; + const CompressedTexFormat format = (CompressedTexFormat)formatI; - if (!tcu::isASTCFormat(format)) + if (!tcu::isAstcFormat(format)) continue; blockSizeRemainderGroup->addChild(new ASTCBlockSizeRemainderCase2D(m_context, getASTCFormatShortName(format).c_str(), glu::getCompressedTexFormatName(glu::getGLFormat(format)), format)); diff --git a/modules/gles3/functional/es3fTextureFormatTests.cpp b/modules/gles3/functional/es3fTextureFormatTests.cpp index 7b42a51..2ae60cc 100644 --- a/modules/gles3/functional/es3fTextureFormatTests.cpp +++ b/modules/gles3/functional/es3fTextureFormatTests.cpp @@ -721,15 +721,15 @@ Texture3DFormatCase::IterateResult Texture3DFormatCase::iterate (void) class Compressed2DFormatCase : public tcu::TestCase { public: - Compressed2DFormatCase (tcu::TestContext& testCtx, - glu::RenderContext& renderCtx, - const glu::ContextInfo& renderCtxInfo, - const char* name, - const char* description, - tcu::CompressedTexture::Format format, - deUint32 randomSeed, - int width, - int height); + Compressed2DFormatCase (tcu::TestContext& testCtx, + glu::RenderContext& renderCtx, + const glu::ContextInfo& renderCtxInfo, + const char* name, + const char* description, + tcu::CompressedTexFormat format, + deUint32 randomSeed, + int width, + int height); ~Compressed2DFormatCase (void); void init (void); @@ -743,7 +743,7 @@ private: glu::RenderContext& m_renderCtx; const glu::ContextInfo& m_renderCtxInfo; - tcu::CompressedTexture::Format m_format; + tcu::CompressedTexFormat m_format; deUint32 m_randomSeed; int m_width; @@ -753,15 +753,15 @@ private: TextureTestUtil::TextureRenderer m_renderer; }; -Compressed2DFormatCase::Compressed2DFormatCase (tcu::TestContext& testCtx, - glu::RenderContext& renderCtx, - const glu::ContextInfo& renderCtxInfo, - const char* name, - const char* description, - tcu::CompressedTexture::Format format, - deUint32 randomSeed, - int width, - int height) +Compressed2DFormatCase::Compressed2DFormatCase (tcu::TestContext& testCtx, + glu::RenderContext& renderCtx, + const glu::ContextInfo& renderCtxInfo, + const char* name, + const char* description, + tcu::CompressedTexFormat format, + deUint32 randomSeed, + int width, + int height) : TestCase (testCtx, name, description) , m_renderCtx (renderCtx) , m_renderCtxInfo (renderCtxInfo) @@ -856,15 +856,16 @@ Compressed2DFormatCase::IterateResult Compressed2DFormatCase::iterate (void) class CompressedCubeFormatCase : public tcu::TestCase { public: - CompressedCubeFormatCase (tcu::TestContext& testCtx, - glu::RenderContext& renderCtx, - const glu::ContextInfo& renderCtxInfo, - const char* name, - const char* description, - tcu::CompressedTexture::Format format, - deUint32 randomSeed, - int width, - int height); + CompressedCubeFormatCase (tcu::TestContext& testCtx, + glu::RenderContext& renderCtx, + const glu::ContextInfo& renderCtxInfo, + const char* name, + const char* description, + tcu::CompressedTexFormat format, + deUint32 randomSeed, + int width, + int height); + ~CompressedCubeFormatCase (void); void init (void); @@ -880,7 +881,7 @@ private: glu::RenderContext& m_renderCtx; const glu::ContextInfo& m_renderCtxInfo; - tcu::CompressedTexture::Format m_format; + tcu::CompressedTexFormat m_format; deUint32 m_randomSeed; int m_width; @@ -893,15 +894,15 @@ private: bool m_isOk; }; -CompressedCubeFormatCase::CompressedCubeFormatCase (tcu::TestContext& testCtx, - glu::RenderContext& renderCtx, - const glu::ContextInfo& renderCtxInfo, - const char* name, - const char* description, - tcu::CompressedTexture::Format format, - deUint32 randomSeed, - int width, - int height) +CompressedCubeFormatCase::CompressedCubeFormatCase (tcu::TestContext& testCtx, + glu::RenderContext& renderCtx, + const glu::ContextInfo& renderCtxInfo, + const char* name, + const char* description, + tcu::CompressedTexFormat format, + deUint32 randomSeed, + int width, + int height) : TestCase (testCtx, name, description) , m_renderCtx (renderCtx) , m_renderCtxInfo (renderCtxInfo) @@ -1456,21 +1457,21 @@ void TextureFormatTests::init (void) // ETC-2 and EAC compressed formats. struct { - const char* descriptionBase; - const char* nameBase; - tcu::CompressedTexture::Format format; + const char* descriptionBase; + const char* nameBase; + tcu::CompressedTexFormat format; } etc2Formats[] = { - { "GL_COMPRESSED_R11_EAC", "eac_r11", tcu::CompressedTexture::EAC_R11, }, - { "GL_COMPRESSED_SIGNED_R11_EAC", "eac_signed_r11", tcu::CompressedTexture::EAC_SIGNED_R11, }, - { "GL_COMPRESSED_RG11_EAC", "eac_rg11", tcu::CompressedTexture::EAC_RG11, }, - { "GL_COMPRESSED_SIGNED_RG11_EAC", "eac_signed_rg11", tcu::CompressedTexture::EAC_SIGNED_RG11, }, - { "GL_COMPRESSED_RGB8_ETC2", "etc2_rgb8", tcu::CompressedTexture::ETC2_RGB8, }, - { "GL_COMPRESSED_SRGB8_ETC2", "etc2_srgb8", tcu::CompressedTexture::ETC2_SRGB8, }, - { "GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2", "etc2_rgb8_punchthrough_alpha1", tcu::CompressedTexture::ETC2_RGB8_PUNCHTHROUGH_ALPHA1, }, - { "GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2", "etc2_srgb8_punchthrough_alpha1", tcu::CompressedTexture::ETC2_SRGB8_PUNCHTHROUGH_ALPHA1, }, - { "GL_COMPRESSED_RGBA8_ETC2_EAC", "etc2_eac_rgba8", tcu::CompressedTexture::ETC2_EAC_RGBA8, }, - { "GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC", "etc2_eac_srgb8_alpha8", tcu::CompressedTexture::ETC2_EAC_SRGB8_ALPHA8, } + { "GL_COMPRESSED_R11_EAC", "eac_r11", tcu::COMPRESSEDTEXFORMAT_EAC_R11, }, + { "GL_COMPRESSED_SIGNED_R11_EAC", "eac_signed_r11", tcu::COMPRESSEDTEXFORMAT_EAC_SIGNED_R11, }, + { "GL_COMPRESSED_RG11_EAC", "eac_rg11", tcu::COMPRESSEDTEXFORMAT_EAC_RG11, }, + { "GL_COMPRESSED_SIGNED_RG11_EAC", "eac_signed_rg11", tcu::COMPRESSEDTEXFORMAT_EAC_SIGNED_RG11, }, + { "GL_COMPRESSED_RGB8_ETC2", "etc2_rgb8", tcu::COMPRESSEDTEXFORMAT_ETC2_RGB8, }, + { "GL_COMPRESSED_SRGB8_ETC2", "etc2_srgb8", tcu::COMPRESSEDTEXFORMAT_ETC2_SRGB8, }, + { "GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2", "etc2_rgb8_punchthrough_alpha1", tcu::COMPRESSEDTEXFORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1, }, + { "GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2", "etc2_srgb8_punchthrough_alpha1", tcu::COMPRESSEDTEXFORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1, }, + { "GL_COMPRESSED_RGBA8_ETC2_EAC", "etc2_eac_rgba8", tcu::COMPRESSEDTEXFORMAT_ETC2_EAC_RGBA8, }, + { "GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC", "etc2_eac_srgb8_alpha8", tcu::COMPRESSEDTEXFORMAT_ETC2_EAC_SRGB8_ALPHA8, } }; for (int formatNdx = 0; formatNdx < DE_LENGTH_OF_ARRAY(etc2Formats); formatNdx++) diff --git a/modules/gles3/functional/es3fTextureWrapTests.cpp b/modules/gles3/functional/es3fTextureWrapTests.cpp index a472467..c20300d 100644 --- a/modules/gles3/functional/es3fTextureWrapTests.cpp +++ b/modules/gles3/functional/es3fTextureWrapTests.cpp @@ -48,6 +48,7 @@ namespace Functional using tcu::TestLog; using tcu::CompressedTexture; +using tcu::CompressedTexFormat; using std::vector; using std::string; using tcu::Sampler; @@ -83,7 +84,7 @@ class TextureWrapCase : public tcu::TestCase public: TextureWrapCase (tcu::TestContext& testCtx, glu::RenderContext& renderCtx, const glu::ContextInfo& ctxInfo, const char* name, const char* description, deUint32 format, deUint32 dataType, deUint32 wrapS, deUint32 wrapT, deUint32 minFilter, deUint32 magFilter, int width, int height); TextureWrapCase (tcu::TestContext& testCtx, glu::RenderContext& renderCtx, const glu::ContextInfo& ctxInfo, const char* name, const char* description, deUint32 wrapS, deUint32 wrapT, deUint32 minFilter, deUint32 magFilter, const std::vector& filenames); - TextureWrapCase (tcu::TestContext& testCtx, glu::RenderContext& renderCtx, const glu::ContextInfo& ctxInfo, const char* name, const char* description, CompressedTexture::Format compressedFormat, deUint32 wrapS, deUint32 wrapT, deUint32 minFilter, deUint32 magFilter, int width, int height); + TextureWrapCase (tcu::TestContext& testCtx, glu::RenderContext& renderCtx, const glu::ContextInfo& ctxInfo, const char* name, const char* description, CompressedTexFormat compressedFormat, deUint32 wrapS, deUint32 wrapT, deUint32 minFilter, deUint32 magFilter, int width, int height); ~TextureWrapCase (void); void init (void); @@ -108,7 +109,7 @@ private: const deUint32 m_format; const deUint32 m_dataType; - const CompressedTexture::Format m_compressedFormat; + const CompressedTexFormat m_compressedFormat; const deUint32 m_wrapS; const deUint32 m_wrapT; const deUint32 m_minFilter; @@ -131,7 +132,7 @@ TextureWrapCase::TextureWrapCase (tcu::TestContext& testCtx, glu::RenderContext& , m_renderCtxInfo (ctxInfo) , m_format (format) , m_dataType (dataType) - , m_compressedFormat (CompressedTexture::FORMAT_LAST) + , m_compressedFormat (tcu::COMPRESSEDTEXFORMAT_LAST) , m_wrapS (wrapS) , m_wrapT (wrapT) , m_minFilter (minFilter) @@ -150,7 +151,7 @@ TextureWrapCase::TextureWrapCase (tcu::TestContext& testCtx, glu::RenderContext& , m_renderCtxInfo (ctxInfo) , m_format (GL_NONE) , m_dataType (GL_NONE) - , m_compressedFormat (CompressedTexture::FORMAT_LAST) + , m_compressedFormat (tcu::COMPRESSEDTEXFORMAT_LAST) , m_wrapS (wrapS) , m_wrapT (wrapT) , m_minFilter (minFilter) @@ -164,7 +165,7 @@ TextureWrapCase::TextureWrapCase (tcu::TestContext& testCtx, glu::RenderContext& { } -TextureWrapCase::TextureWrapCase (tcu::TestContext& testCtx, glu::RenderContext& renderCtx, const glu::ContextInfo& ctxInfo, const char* name, const char* description, CompressedTexture::Format compressedFormat, deUint32 wrapS, deUint32 wrapT, deUint32 minFilter, deUint32 magFilter, int width, int height) +TextureWrapCase::TextureWrapCase (tcu::TestContext& testCtx, glu::RenderContext& renderCtx, const glu::ContextInfo& ctxInfo, const char* name, const char* description, CompressedTexFormat compressedFormat, deUint32 wrapS, deUint32 wrapT, deUint32 minFilter, deUint32 magFilter, int width, int height) : TestCase (testCtx, name, description) , m_renderCtx (renderCtx) , m_renderCtxInfo (ctxInfo) @@ -203,7 +204,7 @@ void TextureWrapCase::init (void) m_width = m_texture->getRefTexture().getWidth(); m_height = m_texture->getRefTexture().getHeight(); } - else if (m_compressedFormat != CompressedTexture::FORMAT_LAST) + else if (m_compressedFormat != tcu::COMPRESSEDTEXFORMAT_LAST) { // Generate compressed texture. @@ -223,7 +224,7 @@ void TextureWrapCase::init (void) m_texture = new glu::Texture2D(m_renderCtx, m_renderCtxInfo, 1, &compressedTexture); } - else if (tcu::isASTCFormat(m_compressedFormat)) + else if (tcu::isAstcFormat(m_compressedFormat)) { // Create ASTC texture by picking from a set of pre-generated blocks. @@ -253,7 +254,8 @@ void TextureWrapCase::init (void) for (int i = 0; i < dataSize/BLOCK_SIZE; i++) deMemcpy(&data[i*BLOCK_SIZE], &blocks[rnd.getInt(0, DE_LENGTH_OF_ARRAY(blocks)-1)][0], BLOCK_SIZE); - m_texture = new glu::Texture2D(m_renderCtx, m_renderCtxInfo, 1, &compressedTexture); + // \note All blocks are valid LDR blocks so ASTCMODE_* doesn't change anything + m_texture = new glu::Texture2D(m_renderCtx, m_renderCtxInfo, 1, &compressedTexture, tcu::TexDecompressionParams(tcu::TexDecompressionParams::ASTCMODE_LDR)); } else DE_ASSERT(false); @@ -300,7 +302,7 @@ TextureWrapCase::IterateResult TextureWrapCase::iterate (void) vector texCoord; const tcu::TextureFormatInfo texFormatInfo = tcu::getTextureFormatInfo(texFormat); // \note For non-sRGB ASTC formats, the values are fp16 in range [0..1], not the range assumed given by tcu::getTextureFormatInfo(). - const bool useDefaultColorScaleAndBias = !tcu::isASTCFormat(m_compressedFormat) || tcu::isASTCSRGBFormat(m_compressedFormat); + const bool useDefaultColorScaleAndBias = !tcu::isAstcFormat(m_compressedFormat) || tcu::isAstcSRGBFormat(m_compressedFormat); // Bind to unit 0. gl.activeTexture(GL_TEXTURE0); @@ -468,20 +470,20 @@ void TextureWrapTests::init (void) { static const struct { - const char* name; - CompressedTexture::Format format; + const char* name; + CompressedTexFormat format; } etc2Formats[] = { - { "eac_r11", CompressedTexture::EAC_R11, }, - { "eac_signed_r11", CompressedTexture::EAC_SIGNED_R11, }, - { "eac_rg11", CompressedTexture::EAC_RG11, }, - { "eac_signed_rg11", CompressedTexture::EAC_SIGNED_RG11, }, - { "etc2_rgb8", CompressedTexture::ETC2_RGB8, }, - { "etc2_srgb8", CompressedTexture::ETC2_SRGB8, }, - { "etc2_rgb8_punchthrough_alpha1", CompressedTexture::ETC2_RGB8_PUNCHTHROUGH_ALPHA1, }, - { "etc2_srgb8_punchthrough_alpha1", CompressedTexture::ETC2_SRGB8_PUNCHTHROUGH_ALPHA1, }, - { "etc2_eac_rgba8", CompressedTexture::ETC2_EAC_RGBA8, }, - { "etc2_eac_srgb8_alpha8", CompressedTexture::ETC2_EAC_SRGB8_ALPHA8, } + { "eac_r11", tcu::COMPRESSEDTEXFORMAT_EAC_R11, }, + { "eac_signed_r11", tcu::COMPRESSEDTEXFORMAT_EAC_SIGNED_R11, }, + { "eac_rg11", tcu::COMPRESSEDTEXFORMAT_EAC_RG11, }, + { "eac_signed_rg11", tcu::COMPRESSEDTEXFORMAT_EAC_SIGNED_RG11, }, + { "etc2_rgb8", tcu::COMPRESSEDTEXFORMAT_ETC2_RGB8, }, + { "etc2_srgb8", tcu::COMPRESSEDTEXFORMAT_ETC2_SRGB8, }, + { "etc2_rgb8_punchthrough_alpha1", tcu::COMPRESSEDTEXFORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1, }, + { "etc2_srgb8_punchthrough_alpha1", tcu::COMPRESSEDTEXFORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1, }, + { "etc2_eac_rgba8", tcu::COMPRESSEDTEXFORMAT_ETC2_EAC_RGBA8, }, + { "etc2_eac_srgb8_alpha8", tcu::COMPRESSEDTEXFORMAT_ETC2_EAC_SRGB8_ALPHA8, } }; static const struct @@ -518,15 +520,16 @@ void TextureWrapTests::init (void) // ASTC cases. { - for (int formatI = 0; formatI < CompressedTexture::FORMAT_LAST; formatI++) + for (int formatI = 0; formatI < tcu::COMPRESSEDTEXFORMAT_LAST; formatI++) { - const CompressedTexture::Format format = (CompressedTexture::Format)formatI; - if (!tcu::isASTCFormat(format)) + const CompressedTexFormat format = (CompressedTexFormat)formatI; + + if (!tcu::isAstcFormat(format)) continue; { - const tcu::IVec3 blockSize = tcu::getASTCBlockSize(format); - const string formatName = "astc_" + de::toString(blockSize.x()) + "x" + de::toString(blockSize.y()) + (tcu::isASTCSRGBFormat(format) ? "_srgb" : ""); + const tcu::IVec3 blockSize = tcu::getBlockPixelSize(format); + const string formatName = "astc_" + de::toString(blockSize.x()) + "x" + de::toString(blockSize.y()) + (tcu::isAstcSRGBFormat(format) ? "_srgb" : ""); TestCaseGroup* const formatGroup = new TestCaseGroup(m_context, formatName.c_str(), ""); addChild(formatGroup); -- 2.7.4