1 #ifndef _TCUTEXTURE_HPP
2 #define _TCUTEXTURE_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 Reference Texture Implementation.
24 *//*--------------------------------------------------------------------*/
25
26 #include "tcuDefs.hpp"
27 #include "tcuVector.hpp"
28 #include "rrGenericVector.hpp"
29 #include "deArrayBuffer.hpp"
30
31 #include <vector>
32 #include <ostream>
33
34 namespace tcu
35 {
36
37 /*--------------------------------------------------------------------*//*!
38 * \brief Texture format
39 *//*--------------------------------------------------------------------*/
40 class TextureFormat
41 {
42 public:
43 enum ChannelOrder
44 {
45 R = 0,
46 A,
47 I,
48 L,
49 LA,
50 RG,
51 RA,
52 RGB,
53 RGBA,
54 ARGB,
55 ABGR,
56 BGR,
57 BGRA,
58
59 sR,
60 sRG,
61 sRGB,
62 sRGBA,
63 sBGR,
64 sBGRA,
65
66 D,
67 S,
68 DS,
69
70 CHANNELORDER_LAST
71 };
72
73 enum ChannelType
74 {
75 SNORM_INT8 = 0,
76 SNORM_INT16,
77 SNORM_INT32,
78 UNORM_INT8,
79 UNORM_INT16,
80 UNORM_INT24,
81 UNORM_INT32,
82 UNORM_BYTE_44,
83 UNORM_SHORT_565,
84 UNORM_SHORT_555,
85 UNORM_SHORT_4444,
86 UNORM_SHORT_5551,
87 UNORM_SHORT_1555,
88 UNORM_INT_101010,
89 SNORM_INT_1010102_REV,
90 UNORM_INT_1010102_REV,
91 UNSIGNED_BYTE_44,
92 UNSIGNED_SHORT_565,
93 UNSIGNED_SHORT_4444,
94 UNSIGNED_SHORT_5551,
95 SIGNED_INT_1010102_REV,
96 UNSIGNED_INT_1010102_REV,
97 UNSIGNED_INT_11F_11F_10F_REV,
98 UNSIGNED_INT_999_E5_REV,
99 UNSIGNED_INT_16_8_8,
100 UNSIGNED_INT_24_8,
101 UNSIGNED_INT_24_8_REV,
102 SIGNED_INT8,
103 SIGNED_INT16,
104 SIGNED_INT32,
105 SIGNED_INT64,
106 UNSIGNED_INT8,
107 UNSIGNED_INT16,
108 UNSIGNED_INT24,
109 UNSIGNED_INT32,
110 UNSIGNED_INT64,
111 HALF_FLOAT,
112 FLOAT,
113 FLOAT64,
114 FLOAT_UNSIGNED_INT_24_8_REV,
115
116 UNORM_SHORT_10,
117 UNORM_SHORT_12,
118
119 USCALED_INT8,
120 USCALED_INT16,
121 SSCALED_INT8,
122 SSCALED_INT16,
123 USCALED_INT_1010102_REV,
124 SSCALED_INT_1010102_REV,
125
126 CHANNELTYPE_LAST
127 };
128
129 ChannelOrder order;
130 ChannelType type;
131
TextureFormat(ChannelOrder order_,ChannelType type_)132 TextureFormat (ChannelOrder order_, ChannelType type_)
133 : order (order_)
134 , type (type_)
135 {
136 }
137
TextureFormat(void)138 TextureFormat (void)
139 : order (CHANNELORDER_LAST)
140 , type (CHANNELTYPE_LAST)
141 {
142 }
143
144 int getPixelSize (void) const; //!< Deprecated, use tcu::getPixelSize(fmt)
145
operator ==(const TextureFormat & other) const146 bool operator== (const TextureFormat& other) const { return !(*this != other); }
operator !=(const TextureFormat & other) const147 bool operator!= (const TextureFormat& other) const
148 {
149 return (order != other.order || type != other.type);
150 }
151 } DE_WARN_UNUSED_TYPE;
152
153 bool isValid (TextureFormat format);
154 int getPixelSize (TextureFormat format);
155 int getNumUsedChannels (TextureFormat::ChannelOrder order);
156 int getChannelSize (TextureFormat::ChannelType type);
157
158 /*--------------------------------------------------------------------*//*!
159 * \brief Texture swizzle
160 *//*--------------------------------------------------------------------*/
161 struct TextureSwizzle
162 {
163 enum Channel
164 {
165 // \note CHANNEL_N must equal int N
166 CHANNEL_0 = 0,
167 CHANNEL_1,
168 CHANNEL_2,
169 CHANNEL_3,
170
171 CHANNEL_ZERO,
172 CHANNEL_ONE,
173
174 CHANNEL_LAST
175 };
176
177 Channel components[4];
178 };
179
180 //! get the swizzle used to expand texture data with a given channel order to RGBA form
181 const TextureSwizzle& getChannelReadSwizzle (TextureFormat::ChannelOrder order);
182
183 //! get the swizzle used to narrow RGBA form data to native texture data with a given channel order
184 const TextureSwizzle& getChannelWriteSwizzle (TextureFormat::ChannelOrder order);
185
186 /*--------------------------------------------------------------------*//*!
187 * \brief Sampling parameters
188 *//*--------------------------------------------------------------------*/
189 class Sampler
190 {
191 public:
192 enum WrapMode
193 {
194 CLAMP_TO_EDGE = 0, //! Clamp to edge
195 CLAMP_TO_BORDER, //! Use border color at edge
196 REPEAT_GL, //! Repeat with OpenGL semantics
197 REPEAT_CL, //! Repeat with OpenCL semantics
198 MIRRORED_REPEAT_GL, //! Mirrored repeat with OpenGL semantics
199 MIRRORED_REPEAT_CL, //! Mirrored repeat with OpenCL semantics
200 MIRRORED_ONCE, //! Mirrored once in negative directions
201
202 WRAPMODE_LAST
203 };
204
205 enum FilterMode
206 {
207 NEAREST = 0,
208 LINEAR,
209 CUBIC,
210
211 NEAREST_MIPMAP_NEAREST,
212 NEAREST_MIPMAP_LINEAR,
213 LINEAR_MIPMAP_NEAREST,
214 LINEAR_MIPMAP_LINEAR,
215 CUBIC_MIPMAP_NEAREST,
216 CUBIC_MIPMAP_LINEAR,
217
218 FILTERMODE_LAST
219 };
220
221 enum ReductionMode
222 {
223 WEIGHTED_AVERAGE = 0,
224 MIN,
225 MAX,
226
227 REDUCTIONMODE_LAST
228 };
229
230 enum CompareMode
231 {
232 COMPAREMODE_NONE = 0,
233 COMPAREMODE_LESS,
234 COMPAREMODE_LESS_OR_EQUAL,
235 COMPAREMODE_GREATER,
236 COMPAREMODE_GREATER_OR_EQUAL,
237 COMPAREMODE_EQUAL,
238 COMPAREMODE_NOT_EQUAL,
239 COMPAREMODE_ALWAYS,
240 COMPAREMODE_NEVER,
241
242 COMPAREMODE_LAST
243 };
244
245 enum DepthStencilMode
246 {
247 MODE_DEPTH = 0,
248 MODE_STENCIL,
249
250 MODE_LAST
251 };
252
253 // Wrap control
254 WrapMode wrapS;
255 WrapMode wrapT;
256 WrapMode wrapR;
257
258 // Minifcation & magnification
259 FilterMode minFilter;
260 FilterMode magFilter;
261
262 // min/max filtering reduction
263 ReductionMode reductionMode;
264
265 float lodThreshold; // lod <= lodThreshold ? magnified : minified
266
267 // Coordinate normalization
268 bool normalizedCoords;
269
270 // Shadow comparison
271 CompareMode compare;
272 int compareChannel;
273
274 // Border color.
275 // \note It is setter's responsibility to guarantee that the values are representable
276 // in sampled texture's internal format.
277 // \note It is setter's responsibility to guarantee that the format is compatible with the
278 // sampled texture's internal format. Otherwise results are undefined.
279 rr::GenericVec4 borderColor;
280
281 // Seamless cube map filtering
282 bool seamlessCubeMap;
283
284 // Depth stencil mode
285 DepthStencilMode depthStencilMode;
286
Sampler(WrapMode wrapS_,WrapMode wrapT_,WrapMode wrapR_,FilterMode minFilter_,FilterMode magFilter_,float lodThreshold_=0.0f,bool normalizedCoords_=true,CompareMode compare_=COMPAREMODE_NONE,int compareChannel_=0,const Vec4 & borderColor_=Vec4 (0.0f,0.0f,0.0f,0.0f),bool seamlessCubeMap_=false,DepthStencilMode depthStencilMode_=MODE_DEPTH,ReductionMode reductionMode_=WEIGHTED_AVERAGE)287 Sampler (WrapMode wrapS_,
288 WrapMode wrapT_,
289 WrapMode wrapR_,
290 FilterMode minFilter_,
291 FilterMode magFilter_,
292 float lodThreshold_ = 0.0f,
293 bool normalizedCoords_ = true,
294 CompareMode compare_ = COMPAREMODE_NONE,
295 int compareChannel_ = 0,
296 const Vec4& borderColor_ = Vec4(0.0f, 0.0f, 0.0f, 0.0f),
297 bool seamlessCubeMap_ = false,
298 DepthStencilMode depthStencilMode_ = MODE_DEPTH,
299 ReductionMode reductionMode_ = WEIGHTED_AVERAGE)
300 : wrapS (wrapS_)
301 , wrapT (wrapT_)
302 , wrapR (wrapR_)
303 , minFilter (minFilter_)
304 , magFilter (magFilter_)
305 , reductionMode (reductionMode_)
306 , lodThreshold (lodThreshold_)
307 , normalizedCoords (normalizedCoords_)
308 , compare (compare_)
309 , compareChannel (compareChannel_)
310 , borderColor (borderColor_)
311 , seamlessCubeMap (seamlessCubeMap_)
312 , depthStencilMode (depthStencilMode_)
313 {
314 }
315
Sampler(void)316 Sampler (void)
317 : wrapS (WRAPMODE_LAST)
318 , wrapT (WRAPMODE_LAST)
319 , wrapR (WRAPMODE_LAST)
320 , minFilter (FILTERMODE_LAST)
321 , magFilter (FILTERMODE_LAST)
322 , reductionMode (REDUCTIONMODE_LAST)
323 , lodThreshold (0.0f)
324 , normalizedCoords (true)
325 , compare (COMPAREMODE_NONE)
326 , compareChannel (0)
327 , borderColor (Vec4(0.0f, 0.0f, 0.0f, 0.0f))
328 , seamlessCubeMap (false)
329 , depthStencilMode (MODE_DEPTH)
330 {
331 }
332 } DE_WARN_UNUSED_TYPE;
333
334 // Calculate pitches for pixel data with no padding.
335 IVec3 calculatePackedPitch (const TextureFormat& format, const IVec3& size);
336
337 deBool isSamplerMipmapModeLinear (tcu::Sampler::FilterMode filterMode);
338
339 class TextureLevel;
340
341 /*--------------------------------------------------------------------*//*!
342 * \brief Read-only pixel data access
343 *
344 * ConstPixelBufferAccess encapsulates pixel data pointer along with
345 * format and layout information. It can be used for read-only access
346 * to arbitrary pixel buffers.
347 *
348 * Access objects are like iterators or pointers. They can be passed around
349 * as values and are valid as long as the storage doesn't change.
350 *//*--------------------------------------------------------------------*/
351 class ConstPixelBufferAccess
352 {
353 public:
354 ConstPixelBufferAccess (void);
355 ConstPixelBufferAccess (const TextureLevel& level);
356 ConstPixelBufferAccess (const TextureFormat& format, int width, int height, int depth, const void* data);
357 ConstPixelBufferAccess (const TextureFormat& format, const IVec3& size, const void* data);
358 ConstPixelBufferAccess (const TextureFormat& format, int width, int height, int depth, int rowPitch, int slicePitch, const void* data);
359 ConstPixelBufferAccess (const TextureFormat& format, const IVec3& size, const IVec3& pitch, const void* data);
360 ConstPixelBufferAccess (const TextureFormat& format, const IVec3& size, const IVec3& pitch, const IVec3& divider, const void* data);
361
getFormat(void) const362 const TextureFormat& getFormat (void) const { return m_format; }
getSize(void) const363 const IVec3& getSize (void) const { return m_size; }
getWidth(void) const364 int getWidth (void) const { return m_size.x(); }
getHeight(void) const365 int getHeight (void) const { return m_size.y(); }
getDepth(void) const366 int getDepth (void) const { return m_size.z(); }
getPixelPitch(void) const367 int getPixelPitch (void) const { return m_pitch.x(); }
getRowPitch(void) const368 int getRowPitch (void) const { return m_pitch.y(); }
getSlicePitch(void) const369 int getSlicePitch (void) const { return m_pitch.z(); }
getPitch(void) const370 const IVec3& getPitch (void) const { return m_pitch; }
getDivider(void) const371 const IVec3& getDivider (void) const { return m_divider; }
372
getDataPtr(void) const373 const void* getDataPtr (void) const { return m_data; }
getPixelPtr(int x,int y,int z=0) const374 const void* getPixelPtr (int x, int y, int z = 0) const { return (const deUint8*)m_data + (x/m_divider.x()) * m_pitch.x() + (y/m_divider.y()) * m_pitch.y() + (z/m_divider.z()) * m_pitch.z(); }
375
376 Vec4 getPixel (int x, int y, int z = 0) const;
377 IVec4 getPixelInt (int x, int y, int z = 0) const;
getPixelUint(int x,int y,int z=0) const378 UVec4 getPixelUint (int x, int y, int z = 0) const { return getPixelInt(x, y, z).cast<deUint32>(); }
379 I64Vec4 getPixelInt64 (int x, int y, int z = 0) const;
getPixelUint64(int x,int y,int z=0) const380 U64Vec4 getPixelUint64 (int x, int y, int z = 0) const { return getPixelInt64(x, y, z).cast<deUint64>(); }
381 U64Vec4 getPixelBitsAsUint64 (int x, int y, int z = 0) const;
382
383 template<typename T>
384 Vector<T, 4> getPixelT (int x, int y, int z = 0) const;
385
386 float getPixDepth (int x, int y, int z = 0) const;
387 int getPixStencil (int x, int y, int z = 0) const;
388
389 Vec4 sample1D (const Sampler& sampler, Sampler::FilterMode filter, float s, int level) const;
390 Vec4 sample2D (const Sampler& sampler, Sampler::FilterMode filter, float s, float t, int depth) const;
391 Vec4 sample3D (const Sampler& sampler, Sampler::FilterMode filter, float s, float t, float r) const;
392
393 Vec4 sample1DOffset (const Sampler& sampler, Sampler::FilterMode filter, float s, const IVec2& offset) const;
394 Vec4 sample2DOffset (const Sampler& sampler, Sampler::FilterMode filter, float s, float t, const IVec3& offset) const;
395 Vec4 sample3DOffset (const Sampler& sampler, Sampler::FilterMode filter, float s, float t, float r, const IVec3& offset) const;
396
397 float sample1DCompare (const Sampler& sampler, Sampler::FilterMode filter, float ref, float s, const IVec2& offset) const;
398 float sample2DCompare (const Sampler& sampler, Sampler::FilterMode filter, float ref, float s, float t, const IVec3& offset) const;
399
400 protected:
401 TextureFormat m_format;
402 IVec3 m_size;
403 IVec3 m_pitch; //!< (pixelPitch, rowPitch, slicePitch)
404 IVec3 m_divider;
405 mutable void* m_data;
406 } DE_WARN_UNUSED_TYPE;
407
408 /*--------------------------------------------------------------------*//*!
409 * \brief Read-write pixel data access
410 *
411 * This class extends read-only access object by providing write functionality.
412 *
413 * \note PixelBufferAccess may not have any data members nor add any
414 * virtual functions. It must be possible to reinterpret_cast<>
415 * PixelBufferAccess to ConstPixelBufferAccess.
416 *//*--------------------------------------------------------------------*/
417 class PixelBufferAccess : public ConstPixelBufferAccess
418 {
419 public:
PixelBufferAccess(void)420 PixelBufferAccess (void) {}
421 PixelBufferAccess (TextureLevel& level);
422 PixelBufferAccess (const TextureFormat& format, int width, int height, int depth, void* data);
423 PixelBufferAccess (const TextureFormat& format, const IVec3& size, void* data);
424 PixelBufferAccess (const TextureFormat& format, int width, int height, int depth, int rowPitch, int slicePitch, void* data);
425 PixelBufferAccess (const TextureFormat& format, const IVec3& size, const IVec3& pitch, void* data);
426 PixelBufferAccess (const TextureFormat& format, const IVec3& size, const IVec3& pitch, const IVec3& block, void* data);
427
getDataPtr(void) const428 void* getDataPtr (void) const { return m_data; }
getPixelPtr(int x,int y,int z=0) const429 void* getPixelPtr (int x, int y, int z = 0) const { return (deUint8*)m_data + (x/m_divider.x()) * m_pitch.x() + (y/m_divider.y()) * m_pitch.y() + (z/m_divider.z()) * m_pitch.z(); }
430
431 void setPixel (const tcu::Vec4& color, int x, int y, int z = 0) const;
432 void setPixel (const tcu::IVec4& color, int x, int y, int z = 0) const;
setPixel(const tcu::UVec4 & color,int x,int y,int z=0) const433 void setPixel (const tcu::UVec4& color, int x, int y, int z = 0) const { setPixel(color.cast<int>(), x, y, z); }
434
435 void setPixDepth (float depth, int x, int y, int z = 0) const;
436 void setPixStencil (int stencil, int x, int y, int z = 0) const;
437 } DE_WARN_UNUSED_TYPE;
438
439 /*--------------------------------------------------------------------*//*!
440 * \brief Generic pixel data container
441 *
442 * This container supports all valid TextureFormat combinations and
443 * both 2D and 3D textures. To read or manipulate data access object must
444 * be queried using getAccess().
445 *//*--------------------------------------------------------------------*/
446 class TextureLevel
447 {
448 public:
449 TextureLevel (void);
450 TextureLevel (const TextureFormat& format);
451 TextureLevel (const TextureFormat& format, int width, int height, int depth = 1);
452 ~TextureLevel (void);
453
getSize(void) const454 const IVec3& getSize (void) const { return m_size; }
getWidth(void) const455 int getWidth (void) const { return m_size.x(); }
getHeight(void) const456 int getHeight (void) const { return m_size.y(); }
getDepth(void) const457 int getDepth (void) const { return m_size.z(); }
isEmpty(void) const458 bool isEmpty (void) const { return m_size.x() * m_size.y() * m_size.z() == 0; }
getFormat(void) const459 const TextureFormat getFormat (void) const { return m_format; }
460
461 void setStorage (const TextureFormat& format, int width, int heigth, int depth = 1);
462 void setSize (int width, int height, int depth = 1);
463
getAccess(void)464 PixelBufferAccess getAccess (void) { return isEmpty() ? PixelBufferAccess() : PixelBufferAccess(m_format, m_size, calculatePackedPitch(m_format, m_size), getPtr()); }
getAccess(void) const465 ConstPixelBufferAccess getAccess (void) const { return isEmpty() ? ConstPixelBufferAccess() : ConstPixelBufferAccess(m_format, m_size, calculatePackedPitch(m_format, m_size), getPtr()); }
466
467 private:
getPtr(void)468 void* getPtr (void) { return m_data.getPtr(); }
getPtr(void) const469 const void* getPtr (void) const { return m_data.getPtr(); }
470
471 TextureFormat m_format;
472 IVec3 m_size;
473 de::ArrayBuffer<deUint8> m_data;
474
475 friend class ConstPixelBufferAccess;
476 } DE_WARN_UNUSED_TYPE;
477
478 /*--------------------------------------------------------------------*//*!
479 * \brief VK_EXT_image_view_min_lod
480 *//*--------------------------------------------------------------------*/
481 enum ImageViewMinLodMode
482 {
483 IMAGEVIEWMINLODMODE_PREFERRED, //!< use image view min lod as-is
484 IMAGEVIEWMINLODMODE_ALTERNATIVE, //!< use floor of image view min lod, as in 'Image Level(s) Selection' in VK spec (v 1.3.206)
485 };
486
487 struct ImageViewMinLod
488 {
489 float value;
490 ImageViewMinLodMode mode;
491 };
492
493 struct ImageViewMinLodParams
494 {
495 int baseLevel;
496 ImageViewMinLod minLod;
497 bool intTexCoord;
498 };
499
500 Vec4 sampleLevelArray1D (const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, int level, float lod);
501 Vec4 sampleLevelArray2D (const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, float t, int depth, float lod, bool es2 = false, ImageViewMinLodParams *minLodParams = DE_NULL);
502 Vec4 sampleLevelArray3D (const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, float t, float r, float lod, ImageViewMinLodParams *minLodParams = DE_NULL);
503
504 Vec4 sampleLevelArray1DOffset (const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, float lod, const IVec2& offset);
505 Vec4 sampleLevelArray2DOffset (const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, float t, float lod, const IVec3& offset, bool es2 = false, ImageViewMinLodParams *minLodParams = DE_NULL);
506 Vec4 sampleLevelArray3DOffset (const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float s, float t, float r, float lod, const IVec3& offset, ImageViewMinLodParams *minLodParams = DE_NULL);
507
508 float sampleLevelArray1DCompare (const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float ref, float s, float lod, const IVec2& offset);
509 float sampleLevelArray2DCompare (const ConstPixelBufferAccess* levels, int numLevels, const Sampler& sampler, float ref, float s, float t, float lod, const IVec3& offset);
510
511 Vec4 gatherArray2DOffsets (const ConstPixelBufferAccess& src, const Sampler& sampler, float s, float t, int depth, int componentNdx, const IVec2 (&offsets)[4]);
512 Vec4 gatherArray2DOffsetsCompare (const ConstPixelBufferAccess& src, const Sampler& sampler, float ref, float s, float t, int depth, const IVec2 (&offsets)[4]);
513
514 enum CubeFace
515 {
516 CUBEFACE_NEGATIVE_X = 0,
517 CUBEFACE_POSITIVE_X,
518 CUBEFACE_NEGATIVE_Y,
519 CUBEFACE_POSITIVE_Y,
520 CUBEFACE_NEGATIVE_Z,
521 CUBEFACE_POSITIVE_Z,
522
523 CUBEFACE_LAST
524 };
525
526 /*--------------------------------------------------------------------*//*!
527 * \brief Coordinates projected onto cube face.
528 *//*--------------------------------------------------------------------*/
529 template<typename T>
530 struct CubeFaceCoords
531 {
532 CubeFace face;
533 T s;
534 T t;
535
CubeFaceCoordstcu::CubeFaceCoords536 CubeFaceCoords (CubeFace face_, T s_, T t_) : face(face_), s(s_), t(t_) {}
CubeFaceCoordstcu::CubeFaceCoords537 CubeFaceCoords (CubeFace face_, const Vector<T, 2>& c) : face(face_), s(c.x()), t(c.y()) {}
538 } DE_WARN_UNUSED_TYPE;
539
540 typedef CubeFaceCoords<float> CubeFaceFloatCoords;
541 typedef CubeFaceCoords<int> CubeFaceIntCoords;
542
543 CubeFace selectCubeFace (const Vec3& coords);
544 Vec2 projectToFace (CubeFace face, const Vec3& coords);
545 CubeFaceFloatCoords getCubeFaceCoords (const Vec3& coords);
546 CubeFaceIntCoords remapCubeEdgeCoords (const CubeFaceIntCoords& coords, int size);
547
548 /*--------------------------------------------------------------------*//*!
549 * \brief 2D Texture View
550 *//*--------------------------------------------------------------------*/
551 class Texture2DView
552 {
553 public:
554 Texture2DView (int numLevels, const ConstPixelBufferAccess* levels, bool es2 = false, ImageViewMinLodParams* minLodParams = DE_NULL);
555
getNumLevels(void) const556 int getNumLevels (void) const { return m_numLevels; }
getWidth(void) const557 int getWidth (void) const { return m_numLevels > 0 ? m_levels[0].getWidth() : 0; }
getHeight(void) const558 int getHeight (void) const { return m_numLevels > 0 ? m_levels[0].getHeight() : 0; }
getLevel(int ndx) const559 const ConstPixelBufferAccess& getLevel (int ndx) const { DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx]; }
getLevels(void) const560 const ConstPixelBufferAccess* getLevels (void) const { return m_levels; }
isES2(void) const561 bool isES2 (void) const { return m_es2; }
562
563 Vec4 sample (const Sampler& sampler, float s, float t, float lod) const;
564 Vec4 sampleOffset (const Sampler& sampler, float s, float t, float lod, const IVec2& offset) const;
565 float sampleCompare (const Sampler& sampler, float ref, float s, float t, float lod) const;
566 float sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float lod, const IVec2& offset) const;
567
568 Vec4 gatherOffsets (const Sampler& sampler, float s, float t, int componentNdx, const IVec2 (&offsets)[4]) const;
569 Vec4 gatherOffsetsCompare(const Sampler& sampler, float ref, float s, float t, const IVec2 (&offsets)[4]) const;
570
getImageViewMinLodParams(void) const571 ImageViewMinLodParams* getImageViewMinLodParams (void) const { return m_minLodParams; }
572
573 protected:
574 int m_numLevels;
575 const ConstPixelBufferAccess* m_levels;
576 bool m_es2;
577 struct ImageViewMinLodParams* m_minLodParams;
578 } DE_WARN_UNUSED_TYPE;
579
Texture2DView(int numLevels,const ConstPixelBufferAccess * levels,bool es2,ImageViewMinLodParams * minLodParams)580 inline Texture2DView::Texture2DView (int numLevels, const ConstPixelBufferAccess* levels, bool es2, ImageViewMinLodParams* minLodParams)
581 : m_numLevels (numLevels)
582 , m_levels (levels)
583 , m_es2 (es2)
584 , m_minLodParams (minLodParams)
585 {
586 DE_ASSERT(m_numLevels >= 0 && ((m_numLevels == 0) == !m_levels));
587 }
588
sample(const Sampler & sampler,float s,float t,float lod) const589 inline Vec4 Texture2DView::sample (const Sampler& sampler, float s, float t, float lod) const
590 {
591 return sampleLevelArray2D(m_levels, m_numLevels, sampler, s, t, 0 /* depth */, lod, m_es2, m_minLodParams);
592 }
593
sampleOffset(const Sampler & sampler,float s,float t,float lod,const IVec2 & offset) const594 inline Vec4 Texture2DView::sampleOffset (const Sampler& sampler, float s, float t, float lod, const IVec2& offset) const
595 {
596 return sampleLevelArray2DOffset(m_levels, m_numLevels, sampler, s, t, lod, IVec3(offset.x(), offset.y(), 0));
597 }
598
sampleCompare(const Sampler & sampler,float ref,float s,float t,float lod) const599 inline float Texture2DView::sampleCompare (const Sampler& sampler, float ref, float s, float t, float lod) const
600 {
601 return sampleLevelArray2DCompare(m_levels, m_numLevels, sampler, ref, s, t, lod, IVec3(0, 0, 0));
602 }
603
sampleCompareOffset(const Sampler & sampler,float ref,float s,float t,float lod,const IVec2 & offset) const604 inline float Texture2DView::sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float lod, const IVec2& offset) const
605 {
606 return sampleLevelArray2DCompare(m_levels, m_numLevels, sampler, ref, s, t, lod, IVec3(offset.x(), offset.y(), 0));
607 }
608
gatherOffsets(const Sampler & sampler,float s,float t,int componentNdx,const IVec2 (& offsets)[4]) const609 inline Vec4 Texture2DView::gatherOffsets (const Sampler& sampler, float s, float t, int componentNdx, const IVec2 (&offsets)[4]) const
610 {
611 return gatherArray2DOffsets(m_levels[0], sampler, s, t, 0, componentNdx, offsets);
612 }
613
gatherOffsetsCompare(const Sampler & sampler,float ref,float s,float t,const IVec2 (& offsets)[4]) const614 inline Vec4 Texture2DView::gatherOffsetsCompare (const Sampler& sampler, float ref, float s, float t, const IVec2 (&offsets)[4]) const
615 {
616 return gatherArray2DOffsetsCompare(m_levels[0], sampler, ref, s, t, 0, offsets);
617 }
618
619 /*--------------------------------------------------------------------*//*!
620 * \brief Base class for textures that have single mip-map pyramid
621 *//*--------------------------------------------------------------------*/
622 class TextureLevelPyramid
623 {
624 public:
625 TextureLevelPyramid (const TextureFormat& format, int numLevels);
626 TextureLevelPyramid (const TextureLevelPyramid& other);
627 ~TextureLevelPyramid(void);
628
getFormat(void) const629 const TextureFormat& getFormat (void) const { return m_format; }
getNumLevels(void) const630 int getNumLevels (void) const { return (int)m_access.size(); }
631
isLevelEmpty(int levelNdx) const632 bool isLevelEmpty (int levelNdx) const { DE_ASSERT(de::inBounds(levelNdx, 0, getNumLevels())); return m_data[(size_t)levelNdx].empty(); }
getLevel(int levelNdx) const633 const ConstPixelBufferAccess& getLevel (int levelNdx) const { DE_ASSERT(de::inBounds(levelNdx, 0, getNumLevels())); return m_access[(size_t)levelNdx]; }
getLevel(int levelNdx)634 const PixelBufferAccess& getLevel (int levelNdx) { DE_ASSERT(de::inBounds(levelNdx, 0, getNumLevels())); return m_access[(size_t)levelNdx]; }
635
getLevels(void) const636 const ConstPixelBufferAccess* getLevels (void) const { return &m_access[0]; }
getLevels(void)637 const PixelBufferAccess* getLevels (void) { return &m_access[0]; }
638
639 void allocLevel (int levelNdx, int width, int height, int depth);
640 void clearLevel (int levelNdx);
641
642 TextureLevelPyramid& operator= (const TextureLevelPyramid& other);
643
644 private:
645 typedef de::ArrayBuffer<deUint8> LevelData;
646
647 TextureFormat m_format;
648 std::vector<LevelData> m_data;
649 std::vector<PixelBufferAccess> m_access;
650 } DE_WARN_UNUSED_TYPE;
651
652 /*--------------------------------------------------------------------*//*!
653 * \brief 2D Texture reference implementation
654 *//*--------------------------------------------------------------------*/
655 class Texture2D : private TextureLevelPyramid
656 {
657 public:
658 Texture2D (const TextureFormat& format, int width, int height, bool es2 = false);
659 Texture2D (const TextureFormat& format, int width, int height, int mipmaps);
660 Texture2D (const Texture2D& other);
661 ~Texture2D (void);
662
getWidth(void) const663 int getWidth (void) const { return m_width; }
getHeight(void) const664 int getHeight (void) const { return m_height; }
getView(void) const665 const Texture2DView& getView (void) const { return m_view; }
isYUVTextureUsed(void) const666 bool isYUVTextureUsed (void) const { return m_yuvTextureUsed;}
667 void allocLevel (int levelNdx);
668
669 // Sampling
670 Vec4 sample (const Sampler& sampler, float s, float t, float lod) const;
671 Vec4 sampleOffset (const Sampler& sampler, float s, float t, float lod, const IVec2& offset) const;
672 float sampleCompare (const Sampler& sampler, float ref, float s, float t, float lod) const;
673 float sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float lod, const IVec2& offset) const;
674
675 Vec4 gatherOffsets (const Sampler& sampler, float s, float t, int componentNdx, const IVec2 (&offsets)[4]) const;
676 Vec4 gatherOffsetsCompare (const Sampler& sampler, float ref, float s, float t, const IVec2 (&offsets)[4]) const;
677
678 using TextureLevelPyramid::getFormat;
679 using TextureLevelPyramid::getNumLevels;
680 using TextureLevelPyramid::getLevel;
681 using TextureLevelPyramid::clearLevel;
682 using TextureLevelPyramid::isLevelEmpty;
683
684 Texture2D& operator= (const Texture2D& other);
685 //whether this is a yuv format texture tests
686 bool m_yuvTextureUsed;
operator Texture2DView(void) const687 operator Texture2DView (void) const { return m_view; }
688
689 private:
690 int m_width;
691 int m_height;
692 Texture2DView m_view;
693 } DE_WARN_UNUSED_TYPE;
694
sample(const Sampler & sampler,float s,float t,float lod) const695 inline Vec4 Texture2D::sample (const Sampler& sampler, float s, float t, float lod) const
696 {
697 return m_view.sample(sampler, s, t, lod);
698 }
699
sampleOffset(const Sampler & sampler,float s,float t,float lod,const IVec2 & offset) const700 inline Vec4 Texture2D::sampleOffset (const Sampler& sampler, float s, float t, float lod, const IVec2& offset) const
701 {
702 return m_view.sampleOffset(sampler, s, t, lod, offset);
703 }
704
sampleCompare(const Sampler & sampler,float ref,float s,float t,float lod) const705 inline float Texture2D::sampleCompare (const Sampler& sampler, float ref, float s, float t, float lod) const
706 {
707 return m_view.sampleCompare(sampler, ref, s, t, lod);
708 }
709
sampleCompareOffset(const Sampler & sampler,float ref,float s,float t,float lod,const IVec2 & offset) const710 inline float Texture2D::sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float lod, const IVec2& offset) const
711 {
712 return m_view.sampleCompareOffset(sampler, ref, s, t, lod, offset);
713 }
714
gatherOffsets(const Sampler & sampler,float s,float t,int componentNdx,const IVec2 (& offsets)[4]) const715 inline Vec4 Texture2D::gatherOffsets (const Sampler& sampler, float s, float t, int componentNdx, const IVec2 (&offsets)[4]) const
716 {
717 return m_view.gatherOffsets(sampler, s, t, componentNdx, offsets);
718 }
719
gatherOffsetsCompare(const Sampler & sampler,float ref,float s,float t,const IVec2 (& offsets)[4]) const720 inline Vec4 Texture2D::gatherOffsetsCompare (const Sampler& sampler, float ref, float s, float t, const IVec2 (&offsets)[4]) const
721 {
722 return m_view.gatherOffsetsCompare(sampler, ref, s, t, offsets);
723 }
724
725 /*--------------------------------------------------------------------*//*!
726 * \brief Cube Map Texture View
727 *//*--------------------------------------------------------------------*/
728 class TextureCubeView
729 {
730 public:
731 TextureCubeView (void);
732 TextureCubeView (int numLevels, const ConstPixelBufferAccess* const (&levels)[CUBEFACE_LAST], bool es2 = false, ImageViewMinLodParams* minLodParams = DE_NULL);
733
getNumLevels(void) const734 int getNumLevels (void) const { return m_numLevels; }
isES2(void) const735 bool isES2 (void) const { return m_es2; }
getSize(void) const736 int getSize (void) const { return m_numLevels > 0 ? m_levels[0][0].getWidth() : 0; }
getLevelFace(int ndx,CubeFace face) const737 const ConstPixelBufferAccess& getLevelFace (int ndx, CubeFace face) const { DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[face][ndx]; }
getFaceLevels(CubeFace face) const738 const ConstPixelBufferAccess* getFaceLevels (CubeFace face) const { return m_levels[face]; }
739
740 Vec4 sample (const Sampler& sampler, float s, float t, float p, float lod) const;
741 float sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float lod) const;
742
743 Vec4 gather (const Sampler& sampler, float s, float t, float r, int componentNdx) const;
744 Vec4 gatherCompare (const Sampler& sampler, float ref, float s, float t, float r) const;
745
getImageViewMinLodParams(void) const746 ImageViewMinLodParams* getImageViewMinLodParams (void) const { return m_minLodParams; }
747
748 protected:
749 int m_numLevels;
750 const ConstPixelBufferAccess* m_levels[CUBEFACE_LAST];
751 bool m_es2;
752 ImageViewMinLodParams* m_minLodParams;
753 } DE_WARN_UNUSED_TYPE;
754
755 /*--------------------------------------------------------------------*//*!
756 * \brief Cube Map Texture reference implementation
757 *//*--------------------------------------------------------------------*/
758 class TextureCube
759 {
760 public:
761 TextureCube (const TextureFormat& format, int size, bool es2 = false);
762 TextureCube (const TextureCube& other);
763 ~TextureCube (void);
764
getFormat(void) const765 const TextureFormat& getFormat (void) const { return m_format; }
getSize(void) const766 int getSize (void) const { return m_size; }
getView(void) const767 const TextureCubeView& getView (void) const { return m_view; }
768
getNumLevels(void) const769 int getNumLevels (void) const { return (int)m_access[0].size(); }
getLevelFace(int ndx,CubeFace face) const770 const ConstPixelBufferAccess& getLevelFace (int ndx, CubeFace face) const { DE_ASSERT(de::inBounds(ndx, 0, getNumLevels())); return m_access[face][(size_t)ndx]; }
getLevelFace(int ndx,CubeFace face)771 const PixelBufferAccess& getLevelFace (int ndx, CubeFace face) { DE_ASSERT(de::inBounds(ndx, 0, getNumLevels())); return m_access[face][(size_t)ndx]; }
772
773 void allocLevel (CubeFace face, int levelNdx);
774 void clearLevel (CubeFace face, int levelNdx);
isLevelEmpty(CubeFace face,int levelNdx) const775 bool isLevelEmpty (CubeFace face, int levelNdx) const { DE_ASSERT(de::inBounds(levelNdx, 0, getNumLevels())); return m_data[face][(size_t)levelNdx].empty(); }
776
777 Vec4 sample (const Sampler& sampler, float s, float t, float p, float lod) const;
778 float sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float lod) const;
779
780 Vec4 gather (const Sampler& sampler, float s, float t, float r, int componentNdx) const;
781 Vec4 gatherCompare (const Sampler& sampler, float ref, float s, float t, float r) const;
782
783 TextureCube& operator= (const TextureCube& other);
784
operator TextureCubeView(void) const785 operator TextureCubeView (void) const { return m_view; }
786
787 private:
788 typedef de::ArrayBuffer<deUint8> LevelData;
789
790 TextureFormat m_format;
791 int m_size;
792 std::vector<LevelData> m_data[CUBEFACE_LAST];
793 std::vector<PixelBufferAccess> m_access[CUBEFACE_LAST];
794 TextureCubeView m_view;
795 } DE_WARN_UNUSED_TYPE;
796
sample(const Sampler & sampler,float s,float t,float p,float lod) const797 inline Vec4 TextureCube::sample (const Sampler& sampler, float s, float t, float p, float lod) const
798 {
799 return m_view.sample(sampler, s, t, p, lod);
800 }
801
sampleCompare(const Sampler & sampler,float ref,float s,float t,float r,float lod) const802 inline float TextureCube::sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float lod) const
803 {
804 return m_view.sampleCompare(sampler, ref, s, t, r, lod);
805 }
806
gather(const Sampler & sampler,float s,float t,float r,int componentNdx) const807 inline Vec4 TextureCube::gather (const Sampler& sampler, float s, float t, float r, int componentNdx) const
808 {
809 return m_view.gather(sampler, s, t, r, componentNdx);
810 }
811
gatherCompare(const Sampler & sampler,float ref,float s,float t,float r) const812 inline Vec4 TextureCube::gatherCompare (const Sampler& sampler, float ref, float s, float t, float r) const
813 {
814 return m_view.gatherCompare(sampler, ref, s, t, r);
815 }
816
817 /*--------------------------------------------------------------------*//*!
818 * \brief 1D Texture View
819 *//*--------------------------------------------------------------------*/
820 class Texture1DView
821 {
822 public:
823 Texture1DView (int numLevels, const ConstPixelBufferAccess* levels, bool es2, ImageViewMinLodParams* minLodParams);
824
getNumLevels(void) const825 int getNumLevels (void) const { return m_numLevels; }
getWidth(void) const826 int getWidth (void) const { return m_numLevels > 0 ? m_levels[0].getWidth() : 0; }
getLevel(int ndx) const827 const ConstPixelBufferAccess& getLevel (int ndx) const { DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx]; }
getLevels(void) const828 const ConstPixelBufferAccess* getLevels (void) const { return m_levels; }
isES2(void) const829 bool isES2 (void) const { return false; }
830
831 Vec4 sample (const Sampler& sampler, float s, float lod) const;
832 Vec4 sampleOffset (const Sampler& sampler, float s, float lod, deInt32 offset) const;
833 float sampleCompare (const Sampler& sampler, float ref, float s, float lod) const;
834 float sampleCompareOffset (const Sampler& sampler, float ref, float s, float lod, deInt32 offset) const;
835
getImageViewMinLodParams(void) const836 ImageViewMinLodParams* getImageViewMinLodParams (void) const { return DE_NULL; }
837
838 protected:
839 int m_numLevels;
840 const ConstPixelBufferAccess* m_levels;
841 } DE_WARN_UNUSED_TYPE;
842
Texture1DView(int numLevels,const ConstPixelBufferAccess * levels,bool es2 DE_UNUSED_ATTR=false,ImageViewMinLodParams * minLodParams DE_UNUSED_ATTR=DE_NULL)843 inline Texture1DView::Texture1DView (int numLevels, const ConstPixelBufferAccess* levels, bool es2 DE_UNUSED_ATTR = false, ImageViewMinLodParams* minLodParams DE_UNUSED_ATTR = DE_NULL)
844 : m_numLevels (numLevels)
845 , m_levels (levels)
846 {
847 DE_ASSERT(m_numLevels >= 0 && ((m_numLevels == 0) == !m_levels));
848 }
849
sample(const Sampler & sampler,float s,float lod) const850 inline Vec4 Texture1DView::sample (const Sampler& sampler, float s, float lod) const
851 {
852 return sampleLevelArray1D(m_levels, m_numLevels, sampler, s, 0 /* depth */, lod);
853 }
854
sampleOffset(const Sampler & sampler,float s,float lod,deInt32 offset) const855 inline Vec4 Texture1DView::sampleOffset (const Sampler& sampler, float s, float lod, deInt32 offset) const
856 {
857 return sampleLevelArray1DOffset(m_levels, m_numLevels, sampler, s, lod, IVec2(offset, 0));
858 }
859
sampleCompare(const Sampler & sampler,float ref,float s,float lod) const860 inline float Texture1DView::sampleCompare (const Sampler& sampler, float ref, float s, float lod) const
861 {
862 return sampleLevelArray1DCompare(m_levels, m_numLevels, sampler, ref, s, lod, IVec2(0, 0));
863 }
864
sampleCompareOffset(const Sampler & sampler,float ref,float s,float lod,deInt32 offset) const865 inline float Texture1DView::sampleCompareOffset (const Sampler& sampler, float ref, float s, float lod, deInt32 offset) const
866 {
867 return sampleLevelArray1DCompare(m_levels, m_numLevels, sampler, ref, s, lod, IVec2(offset, 0));
868 }
869
870 /*--------------------------------------------------------------------*//*!
871 * \brief 1D Texture reference implementation
872 *//*--------------------------------------------------------------------*/
873 class Texture1D : private TextureLevelPyramid
874 {
875 public:
876 Texture1D (const TextureFormat& format, int width);
877 Texture1D (const Texture1D& other);
878 ~Texture1D (void);
879
getWidth(void) const880 int getWidth (void) const { return m_width; }
getView(void) const881 const Texture1DView& getView (void) const { return m_view; }
882
883 void allocLevel (int levelNdx);
884
885 // Sampling
886 Vec4 sample (const Sampler& sampler, float s, float lod) const;
887 Vec4 sampleOffset (const Sampler& sampler, float s, float lod, deInt32 offset) const;
888 float sampleCompare (const Sampler& sampler, float ref, float s, float lod) const;
889 float sampleCompareOffset (const Sampler& sampler, float ref, float s, float lod, deInt32 offset) const;
890
891 using TextureLevelPyramid::getFormat;
892 using TextureLevelPyramid::getNumLevels;
893 using TextureLevelPyramid::getLevel;
894 using TextureLevelPyramid::clearLevel;
895 using TextureLevelPyramid::isLevelEmpty;
896
897 Texture1D& operator= (const Texture1D& other);
898
operator Texture1DView(void) const899 operator Texture1DView (void) const { return m_view; }
900
901 private:
902 int m_width;
903 Texture1DView m_view;
904 } DE_WARN_UNUSED_TYPE;
905
sample(const Sampler & sampler,float s,float lod) const906 inline Vec4 Texture1D::sample (const Sampler& sampler, float s, float lod) const
907 {
908 return m_view.sample(sampler, s, lod);
909 }
910
sampleOffset(const Sampler & sampler,float s,float lod,deInt32 offset) const911 inline Vec4 Texture1D::sampleOffset (const Sampler& sampler, float s, float lod, deInt32 offset) const
912 {
913 return m_view.sampleOffset(sampler, s, lod, offset);
914 }
915
sampleCompare(const Sampler & sampler,float ref,float s,float lod) const916 inline float Texture1D::sampleCompare (const Sampler& sampler, float ref, float s, float lod) const
917 {
918 return m_view.sampleCompare(sampler, ref, s, lod);
919 }
920
sampleCompareOffset(const Sampler & sampler,float ref,float s,float lod,deInt32 offset) const921 inline float Texture1D::sampleCompareOffset (const Sampler& sampler, float ref, float s, float lod, deInt32 offset) const
922 {
923 return m_view.sampleCompareOffset(sampler, ref, s, lod, offset);
924 }
925
926 /*--------------------------------------------------------------------*//*!
927 * \brief 1D Array Texture View
928 *//*--------------------------------------------------------------------*/
929 class Texture1DArrayView
930 {
931 public:
932 Texture1DArrayView (int numLevels, const ConstPixelBufferAccess* levels, bool es2 = false, ImageViewMinLodParams* minLodParams = DE_NULL);
933
getWidth(void) const934 int getWidth (void) const { return m_numLevels > 0 ? m_levels[0].getWidth() : 0; }
getNumLayers(void) const935 int getNumLayers (void) const { return m_numLevels > 0 ? m_levels[0].getHeight() : 0; }
getNumLevels(void) const936 int getNumLevels (void) const { return m_numLevels; }
getLevel(int ndx) const937 const ConstPixelBufferAccess& getLevel (int ndx) const { DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx]; }
getLevels(void) const938 const ConstPixelBufferAccess* getLevels (void) const { return m_levels; }
isES2(void) const939 bool isES2 (void) const { return false; }
940
941 Vec4 sample (const Sampler& sampler, float s, float t, float lod) const;
942 Vec4 sampleOffset (const Sampler& sampler, float s, float t, float lod, deInt32 offset) const;
943 float sampleCompare (const Sampler& sampler, float ref, float s, float t, float lod) const;
944 float sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float lod, deInt32 offset) const;
945
getImageViewMinLodParams(void) const946 ImageViewMinLodParams* getImageViewMinLodParams (void) const { return DE_NULL; }
947
948 protected:
949 int selectLayer (float r) const;
950
951 int m_numLevels;
952 const ConstPixelBufferAccess* m_levels;
953 } DE_WARN_UNUSED_TYPE;
954
955 /*--------------------------------------------------------------------*//*!
956 * \brief 1D Array Texture reference implementation
957 *//*--------------------------------------------------------------------*/
958 class Texture1DArray : private TextureLevelPyramid
959 {
960 public:
961 Texture1DArray (const TextureFormat& format, int width, int numLayers);
962 Texture1DArray (const Texture1DArray& other);
963 ~Texture1DArray (void);
964
getWidth(void) const965 int getWidth (void) const { return m_width; }
getNumLayers(void) const966 int getNumLayers (void) const { return m_numLayers; }
967
968 void allocLevel (int levelNdx);
969
970 using TextureLevelPyramid::getFormat;
971 using TextureLevelPyramid::getNumLevels;
972 using TextureLevelPyramid::getLevel;
973 using TextureLevelPyramid::clearLevel;
974 using TextureLevelPyramid::isLevelEmpty;
975
976 Vec4 sample (const Sampler& sampler, float s, float t, float lod) const;
977 Vec4 sampleOffset (const Sampler& sampler, float s, float t, float lod, deInt32 offset) const;
978 float sampleCompare (const Sampler& sampler, float ref, float s, float t, float lod) const;
979 float sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float lod, deInt32 offset) const;
980
981 Texture1DArray& operator= (const Texture1DArray& other);
982
operator Texture1DArrayView(void) const983 operator Texture1DArrayView (void) const { return m_view; }
984
985 private:
986 int m_width;
987 int m_numLayers;
988 Texture1DArrayView m_view;
989 } DE_WARN_UNUSED_TYPE;
990
sample(const Sampler & sampler,float s,float t,float lod) const991 inline Vec4 Texture1DArray::sample (const Sampler& sampler, float s, float t, float lod) const
992 {
993 return m_view.sample(sampler, s, t, lod);
994 }
995
sampleOffset(const Sampler & sampler,float s,float t,float lod,deInt32 offset) const996 inline Vec4 Texture1DArray::sampleOffset (const Sampler& sampler, float s, float t, float lod, deInt32 offset) const
997 {
998 return m_view.sampleOffset(sampler, s, t, lod, offset);
999 }
1000
sampleCompare(const Sampler & sampler,float ref,float s,float t,float lod) const1001 inline float Texture1DArray::sampleCompare (const Sampler& sampler, float ref, float s, float t, float lod) const
1002 {
1003 return m_view.sampleCompare(sampler, ref, s, t, lod);
1004 }
1005
sampleCompareOffset(const Sampler & sampler,float ref,float s,float t,float lod,deInt32 offset) const1006 inline float Texture1DArray::sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float lod, deInt32 offset) const
1007 {
1008 return m_view.sampleCompareOffset(sampler, ref, s, t, lod, offset);
1009 }
1010
1011 /*--------------------------------------------------------------------*//*!
1012 * \brief 2D Array Texture View
1013 *//*--------------------------------------------------------------------*/
1014 class Texture2DArrayView
1015 {
1016 public:
1017 Texture2DArrayView (int numLevels, const ConstPixelBufferAccess* levels, bool es2 = false, ImageViewMinLodParams* minLodParams = DE_NULL);
1018
getWidth(void) const1019 int getWidth (void) const { return m_numLevels > 0 ? m_levels[0].getWidth() : 0; }
getHeight(void) const1020 int getHeight (void) const { return m_numLevels > 0 ? m_levels[0].getHeight() : 0; }
getNumLayers(void) const1021 int getNumLayers (void) const { return m_numLevels > 0 ? m_levels[0].getDepth() : 0; }
getNumLevels(void) const1022 int getNumLevels (void) const { return m_numLevels; }
getLevel(int ndx) const1023 const ConstPixelBufferAccess& getLevel (int ndx) const { DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx]; }
getLevels(void) const1024 const ConstPixelBufferAccess* getLevels (void) const { return m_levels; }
isES2(void) const1025 bool isES2 (void) const { return false; }
1026
1027 Vec4 sample (const Sampler& sampler, float s, float t, float r, float lod) const;
1028 Vec4 sampleOffset (const Sampler& sampler, float s, float t, float r, float lod, const IVec2& offset) const;
1029 float sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float lod) const;
1030 float sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float r, float lod, const IVec2& offset) const;
1031
1032 Vec4 gatherOffsets (const Sampler& sampler, float s, float t, float r, int componentNdx, const IVec2 (&offsets)[4]) const;
1033 Vec4 gatherOffsetsCompare(const Sampler& sampler, float ref, float s, float t, float r, const IVec2 (&offsets)[4]) const;
1034
getImageViewMinLodParams(void) const1035 ImageViewMinLodParams* getImageViewMinLodParams (void) const { return DE_NULL; }
1036
1037 protected:
1038 int selectLayer (float r) const;
1039
1040 int m_numLevels;
1041 const ConstPixelBufferAccess* m_levels;
1042 } DE_WARN_UNUSED_TYPE;
1043
1044 /*--------------------------------------------------------------------*//*!
1045 * \brief 2D Array Texture reference implementation
1046 *//*--------------------------------------------------------------------*/
1047 class Texture2DArray : private TextureLevelPyramid
1048 {
1049 public:
1050 Texture2DArray (const TextureFormat& format, int width, int height, int numLayers);
1051 Texture2DArray (const Texture2DArray& other);
1052 ~Texture2DArray (void);
1053
getWidth(void) const1054 int getWidth (void) const { return m_width; }
getHeight(void) const1055 int getHeight (void) const { return m_height; }
getNumLayers(void) const1056 int getNumLayers (void) const { return m_numLayers; }
1057
1058 void allocLevel (int levelNdx);
1059
1060 using TextureLevelPyramid::getFormat;
1061 using TextureLevelPyramid::getNumLevels;
1062 using TextureLevelPyramid::getLevel;
1063 using TextureLevelPyramid::clearLevel;
1064 using TextureLevelPyramid::isLevelEmpty;
1065
1066 Vec4 sample (const Sampler& sampler, float s, float t, float r, float lod) const;
1067 Vec4 sampleOffset (const Sampler& sampler, float s, float t, float r, float lod, const IVec2& offset) const;
1068 float sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float lod) const;
1069 float sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float r, float lod, const IVec2& offset) const;
1070
1071 Vec4 gatherOffsets (const Sampler& sampler, float s, float t, float r, int componentNdx, const IVec2 (&offsets)[4]) const;
1072 Vec4 gatherOffsetsCompare(const Sampler& sampler, float ref, float s, float t, float r, const IVec2 (&offsets)[4]) const;
1073
1074 Texture2DArray& operator= (const Texture2DArray& other);
1075
operator Texture2DArrayView(void) const1076 operator Texture2DArrayView (void) const { return m_view; }
1077
1078 private:
1079 int m_width;
1080 int m_height;
1081 int m_numLayers;
1082 Texture2DArrayView m_view;
1083 } DE_WARN_UNUSED_TYPE;
1084
sample(const Sampler & sampler,float s,float t,float r,float lod) const1085 inline Vec4 Texture2DArray::sample (const Sampler& sampler, float s, float t, float r, float lod) const
1086 {
1087 return m_view.sample(sampler, s, t, r, lod);
1088 }
1089
sampleOffset(const Sampler & sampler,float s,float t,float r,float lod,const IVec2 & offset) const1090 inline Vec4 Texture2DArray::sampleOffset (const Sampler& sampler, float s, float t, float r, float lod, const IVec2& offset) const
1091 {
1092 return m_view.sampleOffset(sampler, s, t, r, lod, offset);
1093 }
1094
sampleCompare(const Sampler & sampler,float ref,float s,float t,float r,float lod) const1095 inline float Texture2DArray::sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float lod) const
1096 {
1097 return m_view.sampleCompare(sampler, ref, s, t, r, lod);
1098 }
1099
sampleCompareOffset(const Sampler & sampler,float ref,float s,float t,float r,float lod,const IVec2 & offset) const1100 inline float Texture2DArray::sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float r, float lod, const IVec2& offset) const
1101 {
1102 return m_view.sampleCompareOffset(sampler, ref, s, t, r, lod, offset);
1103 }
1104
gatherOffsets(const Sampler & sampler,float s,float t,float r,int componentNdx,const IVec2 (& offsets)[4]) const1105 inline Vec4 Texture2DArray::gatherOffsets (const Sampler& sampler, float s, float t, float r, int componentNdx, const IVec2 (&offsets)[4]) const
1106 {
1107 return m_view.gatherOffsets(sampler, s, t, r, componentNdx, offsets);
1108 }
1109
gatherOffsetsCompare(const Sampler & sampler,float ref,float s,float t,float r,const IVec2 (& offsets)[4]) const1110 inline Vec4 Texture2DArray::gatherOffsetsCompare (const Sampler& sampler, float ref, float s, float t, float r, const IVec2 (&offsets)[4]) const
1111 {
1112 return m_view.gatherOffsetsCompare(sampler, ref, s, t, r, offsets);
1113 }
1114
1115 /*--------------------------------------------------------------------*//*!
1116 * \brief 3D Texture View
1117 *//*--------------------------------------------------------------------*/
1118 class Texture3DView
1119 {
1120 public:
1121 Texture3DView (int numLevels, const ConstPixelBufferAccess* levels, bool es2 = false, ImageViewMinLodParams* minLodParams = DE_NULL);
1122
getWidth(void) const1123 int getWidth (void) const { return m_numLevels > 0 ? m_levels[0].getWidth() : 0; }
getHeight(void) const1124 int getHeight (void) const { return m_numLevels > 0 ? m_levels[0].getHeight() : 0; }
getDepth(void) const1125 int getDepth (void) const { return m_numLevels > 0 ? m_levels[0].getDepth() : 0; }
getNumLevels(void) const1126 int getNumLevels (void) const { return m_numLevels; }
getLevel(int ndx) const1127 const ConstPixelBufferAccess& getLevel (int ndx) const { DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx]; }
getLevels(void) const1128 const ConstPixelBufferAccess* getLevels (void) const { return m_levels; }
isES2(void) const1129 bool isES2 (void) const { return m_es2; }
1130
1131 Vec4 sample (const Sampler& sampler, float s, float t, float r, float lod) const;
1132 Vec4 sampleOffset (const Sampler& sampler, float s, float t, float r, float lod, const IVec3& offset) const;
1133
getImageViewMinLodParams(void) const1134 ImageViewMinLodParams* getImageViewMinLodParams (void) const { return m_minLodParams; }
1135
1136 protected:
1137 int m_numLevels;
1138 const ConstPixelBufferAccess* m_levels;
1139 bool m_es2;
1140 ImageViewMinLodParams* m_minLodParams;
1141
1142 } DE_WARN_UNUSED_TYPE;
1143
sample(const Sampler & sampler,float s,float t,float r,float lod) const1144 inline Vec4 Texture3DView::sample (const Sampler& sampler, float s, float t, float r, float lod) const
1145 {
1146 return sampleLevelArray3D(m_levels, m_numLevels, sampler, s, t, r, lod, m_minLodParams);
1147 }
1148
sampleOffset(const Sampler & sampler,float s,float t,float r,float lod,const IVec3 & offset) const1149 inline Vec4 Texture3DView::sampleOffset (const Sampler& sampler, float s, float t, float r, float lod, const IVec3& offset) const
1150 {
1151 return sampleLevelArray3DOffset(m_levels, m_numLevels, sampler, s, t, r, lod, offset, m_minLodParams);
1152 }
1153
1154 /*--------------------------------------------------------------------*//*!
1155 * \brief 3D Texture reference implementation
1156 *//*--------------------------------------------------------------------*/
1157 class Texture3D : private TextureLevelPyramid
1158 {
1159 public:
1160 Texture3D (const TextureFormat& format, int width, int height, int depth);
1161 Texture3D (const Texture3D& other);
1162 ~Texture3D (void);
1163
getWidth(void) const1164 int getWidth (void) const { return m_width; }
getHeight(void) const1165 int getHeight (void) const { return m_height; }
getDepth(void) const1166 int getDepth (void) const { return m_depth; }
1167
1168 void allocLevel (int levelNdx);
1169
1170 using TextureLevelPyramid::getFormat;
1171 using TextureLevelPyramid::getNumLevels;
1172 using TextureLevelPyramid::getLevel;
1173 using TextureLevelPyramid::clearLevel;
1174 using TextureLevelPyramid::isLevelEmpty;
1175
1176 Vec4 sample (const Sampler& sampler, float s, float t, float r, float lod) const;
1177 Vec4 sampleOffset (const Sampler& sampler, float s, float t, float r, float lod, const IVec3& offset) const;
1178
1179 Texture3D& operator= (const Texture3D& other);
1180
operator Texture3DView(void) const1181 operator Texture3DView (void) const { return m_view; }
1182
1183 private:
1184 int m_width;
1185 int m_height;
1186 int m_depth;
1187 Texture3DView m_view;
1188 } DE_WARN_UNUSED_TYPE;
1189
sample(const Sampler & sampler,float s,float t,float r,float lod) const1190 inline Vec4 Texture3D::sample (const Sampler& sampler, float s, float t, float r, float lod) const
1191 {
1192 return m_view.sample(sampler, s, t, r, lod);
1193 }
1194
sampleOffset(const Sampler & sampler,float s,float t,float r,float lod,const IVec3 & offset) const1195 inline Vec4 Texture3D::sampleOffset (const Sampler& sampler, float s, float t, float r, float lod, const IVec3& offset) const
1196 {
1197 return m_view.sampleOffset(sampler, s, t, r, lod, offset);
1198 }
1199
1200 /*--------------------------------------------------------------------*//*!
1201 * \brief Cube Map Array Texture View
1202 *//*--------------------------------------------------------------------*/
1203 class TextureCubeArrayView
1204 {
1205 public:
1206 TextureCubeArrayView (int numLevels, const ConstPixelBufferAccess* levels, bool es2 = false, ImageViewMinLodParams* minLodParams = DE_NULL);
1207
getSize(void) const1208 int getSize (void) const { return m_numLevels > 0 ? m_levels[0].getWidth() : 0; }
getDepth(void) const1209 int getDepth (void) const { return m_numLevels > 0 ? m_levels[0].getDepth() : 0; }
getNumLayers(void) const1210 int getNumLayers (void) const { return getDepth() / 6; }
getNumLevels(void) const1211 int getNumLevels (void) const { return m_numLevels; }
getLevel(int ndx) const1212 const ConstPixelBufferAccess& getLevel (int ndx) const { DE_ASSERT(de::inBounds(ndx, 0, m_numLevels)); return m_levels[ndx]; }
getLevels(void) const1213 const ConstPixelBufferAccess* getLevels (void) const { return m_levels; }
isES2(void) const1214 bool isES2 (void) const { return false; }
1215
1216 Vec4 sample (const Sampler& sampler, float s, float t, float r, float q, float lod) const;
1217 Vec4 sampleOffset (const Sampler& sampler, float s, float t, float r, float q, float lod, const IVec2& offset) const;
1218 float sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float q, float lod) const;
1219 float sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float r, float q, float lod, const IVec2& offset) const;
1220
getImageViewMinLodParams(void) const1221 ImageViewMinLodParams* getImageViewMinLodParams (void) const { return DE_NULL; }
1222
1223
1224 protected:
1225 int selectLayer (float q) const;
1226
1227 int m_numLevels;
1228 const ConstPixelBufferAccess* m_levels;
1229 } DE_WARN_UNUSED_TYPE;
1230
1231 /*--------------------------------------------------------------------*//*!
1232 * \brief Cube Map Array Texture reference implementation
1233 *//*--------------------------------------------------------------------*/
1234 class TextureCubeArray : private TextureLevelPyramid
1235 {
1236 public:
1237 TextureCubeArray (const TextureFormat& format, int size, int depth);
1238 TextureCubeArray (const TextureCubeArray& other);
1239 ~TextureCubeArray (void);
1240
getSize(void) const1241 int getSize (void) const { return m_size; }
getDepth(void) const1242 int getDepth (void) const { return m_depth; }
1243
1244 void allocLevel (int levelNdx);
1245
1246 using TextureLevelPyramid::getFormat;
1247 using TextureLevelPyramid::getNumLevels;
1248 using TextureLevelPyramid::getLevel;
1249 using TextureLevelPyramid::clearLevel;
1250 using TextureLevelPyramid::isLevelEmpty;
1251
1252 Vec4 sample (const Sampler& sampler, float s, float t, float r, float q, float lod) const;
1253 Vec4 sampleOffset (const Sampler& sampler, float s, float t, float r, float q, float lod, const IVec2& offset) const;
1254 float sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float q, float lod) const;
1255 float sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float r, float q, float lod, const IVec2& offset) const;
1256
1257 TextureCubeArray& operator= (const TextureCubeArray& other);
1258
operator TextureCubeArrayView(void) const1259 operator TextureCubeArrayView (void) const { return m_view; }
1260
1261 private:
1262 int m_size;
1263 int m_depth;
1264 TextureCubeArrayView m_view;
1265 } DE_WARN_UNUSED_TYPE;
1266
sample(const Sampler & sampler,float s,float t,float r,float q,float lod) const1267 inline Vec4 TextureCubeArray::sample (const Sampler& sampler, float s, float t, float r, float q, float lod) const
1268 {
1269 return m_view.sample(sampler, s, t, r, q, lod);
1270 }
1271
sampleOffset(const Sampler & sampler,float s,float t,float r,float q,float lod,const IVec2 & offset) const1272 inline Vec4 TextureCubeArray::sampleOffset (const Sampler& sampler, float s, float t, float r, float q, float lod, const IVec2& offset) const
1273 {
1274 return m_view.sampleOffset(sampler, s, t, r, q, lod, offset);
1275 }
1276
sampleCompare(const Sampler & sampler,float ref,float s,float t,float r,float q,float lod) const1277 inline float TextureCubeArray::sampleCompare (const Sampler& sampler, float ref, float s, float t, float r, float q, float lod) const
1278 {
1279 return m_view.sampleCompare(sampler, ref, s, t, r, q, lod);
1280 }
1281
sampleCompareOffset(const Sampler & sampler,float ref,float s,float t,float r,float q,float lod,const IVec2 & offset) const1282 inline float TextureCubeArray::sampleCompareOffset (const Sampler& sampler, float ref, float s, float t, float r, float q, float lod, const IVec2& offset) const
1283 {
1284 return m_view.sampleCompareOffset(sampler, ref, s, t, r, q, lod, offset);
1285 }
1286
1287 // Stream operators.
1288 std::ostream& operator<< (std::ostream& str, TextureFormat::ChannelOrder order);
1289 std::ostream& operator<< (std::ostream& str, TextureFormat::ChannelType type);
1290 std::ostream& operator<< (std::ostream& str, TextureFormat format);
1291 std::ostream& operator<< (std::ostream& str, CubeFace face);
1292 std::ostream& operator<< (std::ostream& str, const ConstPixelBufferAccess& access);
1293
1294 } // tcu
1295
1296 #endif // _TCUTEXTURE_HPP
1297