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