xref: /aosp_15_r20/external/deqp/framework/common/tcuCompressedTexture.hpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1 #ifndef _TCUCOMPRESSEDTEXTURE_HPP
2 #define _TCUCOMPRESSEDTEXTURE_HPP
3 /*-------------------------------------------------------------------------
4  * drawElements Quality Program Tester Core
5  * ----------------------------------------
6  *
7  * Copyright 2014 The Android Open Source Project
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  *//*!
22  * \file
23  * \brief Compressed Texture Utilities.
24  *//*--------------------------------------------------------------------*/
25 
26 #include "tcuDefs.hpp"
27 #include "tcuTexture.hpp"
28 
29 #include <vector>
30 
31 namespace tcu
32 {
33 
34 enum CompressedTexFormat
35 {
36     COMPRESSEDTEXFORMAT_ETC1_RGB8 = 0,
37     COMPRESSEDTEXFORMAT_EAC_R11,
38     COMPRESSEDTEXFORMAT_EAC_SIGNED_R11,
39     COMPRESSEDTEXFORMAT_EAC_RG11,
40     COMPRESSEDTEXFORMAT_EAC_SIGNED_RG11,
41     COMPRESSEDTEXFORMAT_ETC2_RGB8,
42     COMPRESSEDTEXFORMAT_ETC2_SRGB8,
43     COMPRESSEDTEXFORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1,
44     COMPRESSEDTEXFORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1,
45     COMPRESSEDTEXFORMAT_ETC2_EAC_RGBA8,
46     COMPRESSEDTEXFORMAT_ETC2_EAC_SRGB8_ALPHA8,
47 
48     COMPRESSEDTEXFORMAT_ASTC_4x4_RGBA,
49     COMPRESSEDTEXFORMAT_ASTC_5x4_RGBA,
50     COMPRESSEDTEXFORMAT_ASTC_5x5_RGBA,
51     COMPRESSEDTEXFORMAT_ASTC_6x5_RGBA,
52     COMPRESSEDTEXFORMAT_ASTC_6x6_RGBA,
53     COMPRESSEDTEXFORMAT_ASTC_8x5_RGBA,
54     COMPRESSEDTEXFORMAT_ASTC_8x6_RGBA,
55     COMPRESSEDTEXFORMAT_ASTC_8x8_RGBA,
56     COMPRESSEDTEXFORMAT_ASTC_10x5_RGBA,
57     COMPRESSEDTEXFORMAT_ASTC_10x6_RGBA,
58     COMPRESSEDTEXFORMAT_ASTC_10x8_RGBA,
59     COMPRESSEDTEXFORMAT_ASTC_10x10_RGBA,
60     COMPRESSEDTEXFORMAT_ASTC_12x10_RGBA,
61     COMPRESSEDTEXFORMAT_ASTC_12x12_RGBA,
62     COMPRESSEDTEXFORMAT_ASTC_4x4_SRGB8_ALPHA8,
63     COMPRESSEDTEXFORMAT_ASTC_5x4_SRGB8_ALPHA8,
64     COMPRESSEDTEXFORMAT_ASTC_5x5_SRGB8_ALPHA8,
65     COMPRESSEDTEXFORMAT_ASTC_6x5_SRGB8_ALPHA8,
66     COMPRESSEDTEXFORMAT_ASTC_6x6_SRGB8_ALPHA8,
67     COMPRESSEDTEXFORMAT_ASTC_8x5_SRGB8_ALPHA8,
68     COMPRESSEDTEXFORMAT_ASTC_8x6_SRGB8_ALPHA8,
69     COMPRESSEDTEXFORMAT_ASTC_8x8_SRGB8_ALPHA8,
70     COMPRESSEDTEXFORMAT_ASTC_10x5_SRGB8_ALPHA8,
71     COMPRESSEDTEXFORMAT_ASTC_10x6_SRGB8_ALPHA8,
72     COMPRESSEDTEXFORMAT_ASTC_10x8_SRGB8_ALPHA8,
73     COMPRESSEDTEXFORMAT_ASTC_10x10_SRGB8_ALPHA8,
74     COMPRESSEDTEXFORMAT_ASTC_12x10_SRGB8_ALPHA8,
75     COMPRESSEDTEXFORMAT_ASTC_12x12_SRGB8_ALPHA8,
76 
77     COMPRESSEDTEXFORMAT_BC1_RGB_UNORM_BLOCK,
78     COMPRESSEDTEXFORMAT_BC1_RGB_SRGB_BLOCK,
79     COMPRESSEDTEXFORMAT_BC1_RGBA_UNORM_BLOCK,
80     COMPRESSEDTEXFORMAT_BC1_RGBA_SRGB_BLOCK,
81     COMPRESSEDTEXFORMAT_BC2_UNORM_BLOCK,
82     COMPRESSEDTEXFORMAT_BC2_SRGB_BLOCK,
83     COMPRESSEDTEXFORMAT_BC3_UNORM_BLOCK,
84     COMPRESSEDTEXFORMAT_BC3_SRGB_BLOCK,
85     COMPRESSEDTEXFORMAT_BC4_UNORM_BLOCK,
86     COMPRESSEDTEXFORMAT_BC4_SNORM_BLOCK,
87     COMPRESSEDTEXFORMAT_BC5_UNORM_BLOCK,
88     COMPRESSEDTEXFORMAT_BC5_SNORM_BLOCK,
89     COMPRESSEDTEXFORMAT_BC6H_UFLOAT_BLOCK,
90     COMPRESSEDTEXFORMAT_BC6H_SFLOAT_BLOCK,
91     COMPRESSEDTEXFORMAT_BC7_UNORM_BLOCK,
92     COMPRESSEDTEXFORMAT_BC7_SRGB_BLOCK,
93 
94     COMPRESSEDTEXFORMAT_AHB_RAW10,
95     COMPRESSEDTEXFORMAT_AHB_RAW12,
96 
97     COMPRESSEDTEXFORMAT_LAST
98 };
99 
100 int getBlockSize(CompressedTexFormat format);
101 IVec3 getBlockPixelSize(CompressedTexFormat format);
102 
103 bool isEtcFormat(CompressedTexFormat format);
104 bool isAstcFormat(CompressedTexFormat format);
105 bool isAstcSRGBFormat(CompressedTexFormat format);
106 bool isBcFormat(CompressedTexFormat format);
107 bool isBcBitExactFormat(CompressedTexFormat format);
108 bool isBcSRGBFormat(CompressedTexFormat format);
109 bool isAhbRawFormat(CompressedTexFormat format);
110 
111 TextureFormat getUncompressedFormat(CompressedTexFormat format);
112 CompressedTexFormat getAstcFormatByBlockSize(const IVec3 &size, bool isSRGB);
113 
114 struct TexDecompressionParams
115 {
116     enum AstcMode
117     {
118         ASTCMODE_LDR = 0,
119         ASTCMODE_HDR,
120         ASTCMODE_LAST
121     };
122 
TexDecompressionParamstcu::TexDecompressionParams123     TexDecompressionParams(AstcMode astcMode_ = ASTCMODE_LAST) : astcMode(astcMode_)
124     {
125     }
126 
127     AstcMode astcMode;
128 };
129 
130 /*--------------------------------------------------------------------*//*!
131  * \brief Compressed texture
132  *
133  * This class implements container for common compressed texture formats.
134  * Reference decoding to uncompressed formats is supported.
135  *//*--------------------------------------------------------------------*/
136 class CompressedTexture
137 {
138 public:
139     CompressedTexture(CompressedTexFormat format, int width, int height, int depth = 1);
140     CompressedTexture(void);
141     ~CompressedTexture(void);
142 
143     void setStorage(CompressedTexFormat format, int width, int height, int depth = 1);
144 
getWidth(void) const145     int getWidth(void) const
146     {
147         return m_width;
148     }
getHeight(void) const149     int getHeight(void) const
150     {
151         return m_height;
152     }
getDepth(void) const153     int getDepth(void) const
154     {
155         return m_depth;
156     }
getFormat(void) const157     CompressedTexFormat getFormat(void) const
158     {
159         return m_format;
160     }
getDataSize(void) const161     int getDataSize(void) const
162     {
163         return (int)m_data.size();
164     }
getData(void) const165     const void *getData(void) const
166     {
167         return &m_data[0];
168     }
getData(void)169     void *getData(void)
170     {
171         return &m_data[0];
172     }
173 
174     void decompress(const PixelBufferAccess &dst,
175                     const TexDecompressionParams &params = TexDecompressionParams()) const;
176 
177 private:
178     CompressedTexFormat m_format;
179     int m_width;
180     int m_height;
181     int m_depth;
182     std::vector<uint8_t> m_data;
183 } DE_WARN_UNUSED_TYPE;
184 
185 void decompress(const PixelBufferAccess &dst, CompressedTexFormat fmt, const uint8_t *src,
186                 const TexDecompressionParams &params = TexDecompressionParams());
187 
188 } // namespace tcu
189 
190 #endif // _TCUCOMPRESSEDTEXTURE_HPP
191