xref: /aosp_15_r20/external/deqp/framework/common/tcuTextureUtil.hpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1 #ifndef _TCUTEXTUREUTIL_HPP
2 #define _TCUTEXTUREUTIL_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 Texture utilities.
24  *//*--------------------------------------------------------------------*/
25 
26 #include "tcuDefs.hpp"
27 #include "tcuTexture.hpp"
28 
29 namespace tcu
30 {
31 
32 // PixelBufferAccess utilities.
33 PixelBufferAccess getSubregion(const PixelBufferAccess &access, int x, int y, int z, int width, int height, int depth);
34 ConstPixelBufferAccess getSubregion(const ConstPixelBufferAccess &access, int x, int y, int z, int width, int height,
35                                     int depth);
36 
37 PixelBufferAccess getSubregion(const PixelBufferAccess &access, int x, int y, int width, int height);
38 ConstPixelBufferAccess getSubregion(const ConstPixelBufferAccess &access, int x, int y, int width, int height);
39 
40 PixelBufferAccess flipYAccess(const PixelBufferAccess &access);
41 ConstPixelBufferAccess flipYAccess(const ConstPixelBufferAccess &access);
42 
43 bool isCombinedDepthStencilType(TextureFormat::ChannelType type);
44 bool hasStencilComponent(TextureFormat::ChannelOrder order);
45 bool hasDepthComponent(TextureFormat::ChannelOrder order);
46 
47 // sRGB - linear conversion.
48 float linearChannelToSRGB(float cl);
49 float sRGBChannelToLinear(float cl);
50 Vec4 sRGBToLinear(const Vec4 &cs);
51 Vec4 sRGB8ToLinear(const UVec4 &cs);
52 Vec4 sRGBA8ToLinear(const UVec4 &cs);
53 Vec4 linearToSRGB(const Vec4 &cl);
54 bool isSRGB(TextureFormat format);
55 
56 /*--------------------------------------------------------------------*//*!
57  * \brief Color channel storage type
58  *//*--------------------------------------------------------------------*/
59 enum TextureChannelClass
60 {
61     TEXTURECHANNELCLASS_SIGNED_FIXED_POINT = 0,
62     TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT,
63     TEXTURECHANNELCLASS_SIGNED_INTEGER,
64     TEXTURECHANNELCLASS_UNSIGNED_INTEGER,
65     TEXTURECHANNELCLASS_FLOATING_POINT,
66 
67     TEXTURECHANNELCLASS_LAST
68 };
69 
70 TextureChannelClass getTextureChannelClass(TextureFormat::ChannelType channelType);
71 
72 /*--------------------------------------------------------------------*//*!
73  * \brief Texture access type
74  *//*--------------------------------------------------------------------*/
75 enum TextureAccessType
76 {
77     TEXTUREACCESSTYPE_FLOAT = 0,    //!< Read (getPixel) or write as floating-point data
78     TEXTUREACCESSTYPE_SIGNED_INT,   //!< Read (getPixelInt) or write as signed integer data
79     TEXTUREACCESSTYPE_UNSIGNED_INT, //!< Read (getPixelUint) or write as unsigned integer data
80 
81     TEXTUREACCESSTYPE_LAST
82 };
83 
84 bool isAccessValid(TextureFormat format, TextureAccessType type);
85 
86 /*--------------------------------------------------------------------*//*!
87  * \brief Standard parameters for texture format testing
88  *//*--------------------------------------------------------------------*/
89 struct TextureFormatInfo
90 {
91     Vec4 valueMin;
92     Vec4 valueMax;
93     Vec4 lookupScale;
94     Vec4 lookupBias;
95 
TextureFormatInfotcu::TextureFormatInfo96     TextureFormatInfo(const Vec4 &valueMin_, const Vec4 &valueMax_, const Vec4 &lookupScale_, const Vec4 &lookupBias_)
97         : valueMin(valueMin_)
98         , valueMax(valueMax_)
99         , lookupScale(lookupScale_)
100         , lookupBias(lookupBias_)
101     {
102     }
103 } DE_WARN_UNUSED_TYPE;
104 
105 TextureFormatInfo getTextureFormatInfo(const TextureFormat &format);
106 IVec4 getTextureFormatBitDepth(const TextureFormat &format);
107 IVec4 getTextureFormatMantissaBitDepth(const TextureFormat &format);
108 BVec4 getTextureFormatChannelMask(const TextureFormat &format);
109 
110 IVec4 getFormatMinIntValue(const TextureFormat &format);
111 IVec4 getFormatMaxIntValue(const TextureFormat &format);
112 
113 UVec4 getFormatMaxUintValue(const TextureFormat &format);
114 
115 // Texture fill.
116 void clear(const PixelBufferAccess &access, const Vec4 &color);
117 void clear(const PixelBufferAccess &access, const IVec4 &color);
118 void clear(const PixelBufferAccess &access, const UVec4 &color);
119 void clearDepth(const PixelBufferAccess &access, float depth);
120 void clearStencil(const PixelBufferAccess &access, int stencil);
121 void fillWithComponentGradients(const PixelBufferAccess &access, const Vec4 &minVal, const Vec4 &maxVal);
122 void fillWithComponentGradients2(const PixelBufferAccess &access, const Vec4 &minVal, const Vec4 &maxVal);
123 void fillWithComponentGradients3(const PixelBufferAccess &access, const Vec4 &minVal, const Vec4 &maxVal);
124 void fillWithGrid(const PixelBufferAccess &access, int cellSize, const Vec4 &colorA, const Vec4 &colorB);
125 void fillWithRepeatableGradient(const PixelBufferAccess &access, const Vec4 &colorA, const Vec4 &colorB);
126 void fillWithMetaballs(const PixelBufferAccess &access, int numMetaballs, uint32_t seed);
127 void fillWithRGBAQuads(const PixelBufferAccess &access);
128 
129 //! Copies contents of src to dst. If formats of dst and src are equal, a bit-exact copy is made.
130 void copy(const PixelBufferAccess &dst, const ConstPixelBufferAccess &src, const bool clearUnused = true);
131 
132 void scale(const PixelBufferAccess &dst, const ConstPixelBufferAccess &src, Sampler::FilterMode filter);
133 
134 void estimatePixelValueRange(const ConstPixelBufferAccess &access, Vec4 &minVal, Vec4 &maxVal);
135 void computePixelScaleBias(const ConstPixelBufferAccess &access, Vec4 &scale, Vec4 &bias);
136 
137 int getCubeArrayFaceIndex(CubeFace face);
138 
139 //! FP32->U8 with RTE rounding (extremely fast, always accurate).
floatToU8(float fv)140 inline uint8_t floatToU8(float fv)
141 {
142     union
143     {
144         float fv;
145         uint32_t uv;
146         int32_t iv;
147     } v;
148     v.fv = fv;
149 
150     const uint32_t e = (uint32_t)(126 - (v.iv >> 23));
151     uint32_t m       = v.uv;
152 
153     m &= 0x00ffffffu;
154     m |= 0x00800000u;
155     m = (m << 8) - m;
156     m = (e > 8) ? e : (0x00800000u + (m >> e));
157 
158     return (uint8_t)(m >> 24);
159 }
160 
161 uint32_t packRGB999E5(const tcu::Vec4 &color);
162 
163 /*--------------------------------------------------------------------*//*!
164  * \brief Depth-stencil utilities
165  *//*--------------------------------------------------------------------*/
166 
167 TextureFormat getEffectiveDepthStencilTextureFormat(const TextureFormat &baseFormat, Sampler::DepthStencilMode mode);
168 
169 //! returns the currently effective access to an access with a given sampler mode, e.g.
170 //! for combined depth stencil accesses and for sampler set to sample stencil returns
171 //! stencil access. Identity for non-combined formats.
172 PixelBufferAccess getEffectiveDepthStencilAccess(const PixelBufferAccess &baseAccess, Sampler::DepthStencilMode mode);
173 ConstPixelBufferAccess getEffectiveDepthStencilAccess(const ConstPixelBufferAccess &baseAccess,
174                                                       Sampler::DepthStencilMode mode);
175 
176 //! returns the currently effective view to an texture with a given sampler mode. Uses
177 //! storage for access storage storage
178 
179 tcu::Texture1DView getEffectiveTextureView(const tcu::Texture1DView &src,
180                                            std::vector<tcu::ConstPixelBufferAccess> &storage,
181                                            const tcu::Sampler &sampler);
182 tcu::Texture2DView getEffectiveTextureView(const tcu::Texture2DView &src,
183                                            std::vector<tcu::ConstPixelBufferAccess> &storage,
184                                            const tcu::Sampler &sampler);
185 tcu::Texture3DView getEffectiveTextureView(const tcu::Texture3DView &src,
186                                            std::vector<tcu::ConstPixelBufferAccess> &storage,
187                                            const tcu::Sampler &sampler);
188 tcu::Texture1DArrayView getEffectiveTextureView(const tcu::Texture1DArrayView &src,
189                                                 std::vector<tcu::ConstPixelBufferAccess> &storage,
190                                                 const tcu::Sampler &sampler);
191 tcu::Texture2DArrayView getEffectiveTextureView(const tcu::Texture2DArrayView &src,
192                                                 std::vector<tcu::ConstPixelBufferAccess> &storage,
193                                                 const tcu::Sampler &sampler);
194 tcu::TextureCubeView getEffectiveTextureView(const tcu::TextureCubeView &src,
195                                              std::vector<tcu::ConstPixelBufferAccess> &storage,
196                                              const tcu::Sampler &sampler);
197 tcu::TextureCubeArrayView getEffectiveTextureView(const tcu::TextureCubeArrayView &src,
198                                                   std::vector<tcu::ConstPixelBufferAccess> &storage,
199                                                   const tcu::Sampler &sampler);
200 
201 template <typename ScalarType>
202 tcu::Vector<ScalarType, 4> sampleTextureBorder(const TextureFormat &format, const Sampler &sampler);
203 
204 } // namespace tcu
205 
206 #endif // _TCUTEXTUREUTIL_HPP
207