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_) : order(order_), type(type_)
133 {
134 }
135
TextureFormat(void)136 TextureFormat(void) : order(CHANNELORDER_LAST), type(CHANNELTYPE_LAST)
137 {
138 }
139
140 int getPixelSize(void) const; //!< Deprecated, use tcu::getPixelSize(fmt)
141
operator ==(const TextureFormat & other) const142 bool operator==(const TextureFormat &other) const
143 {
144 return !(*this != other);
145 }
operator !=(const TextureFormat & other) const146 bool operator!=(const TextureFormat &other) const
147 {
148 return (order != other.order || type != other.type);
149 }
150 } DE_WARN_UNUSED_TYPE;
151
152 bool isValid(TextureFormat format);
153 int getPixelSize(TextureFormat format);
154 int getNumUsedChannels(TextureFormat::ChannelOrder order);
155 bool hasAlphaChannel(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_, WrapMode wrapT_, WrapMode wrapR_, FilterMode minFilter_, FilterMode magFilter_,
288 float lodThreshold_ = 0.0f, bool normalizedCoords_ = true, CompareMode compare_ = COMPAREMODE_NONE,
289 int compareChannel_ = 0, const Vec4 &borderColor_ = Vec4(0.0f, 0.0f, 0.0f, 0.0f),
290 bool seamlessCubeMap_ = false, DepthStencilMode depthStencilMode_ = MODE_DEPTH,
291 ReductionMode reductionMode_ = WEIGHTED_AVERAGE)
292 : wrapS(wrapS_)
293 , wrapT(wrapT_)
294 , wrapR(wrapR_)
295 , minFilter(minFilter_)
296 , magFilter(magFilter_)
297 , reductionMode(reductionMode_)
298 , lodThreshold(lodThreshold_)
299 , normalizedCoords(normalizedCoords_)
300 , compare(compare_)
301 , compareChannel(compareChannel_)
302 , borderColor(borderColor_)
303 , seamlessCubeMap(seamlessCubeMap_)
304 , depthStencilMode(depthStencilMode_)
305 {
306 }
307
Sampler(void)308 Sampler(void)
309 : wrapS(WRAPMODE_LAST)
310 , wrapT(WRAPMODE_LAST)
311 , wrapR(WRAPMODE_LAST)
312 , minFilter(FILTERMODE_LAST)
313 , magFilter(FILTERMODE_LAST)
314 , reductionMode(REDUCTIONMODE_LAST)
315 , lodThreshold(0.0f)
316 , normalizedCoords(true)
317 , compare(COMPAREMODE_NONE)
318 , compareChannel(0)
319 , borderColor(Vec4(0.0f, 0.0f, 0.0f, 0.0f))
320 , seamlessCubeMap(false)
321 , depthStencilMode(MODE_DEPTH)
322 {
323 }
324 } DE_WARN_UNUSED_TYPE;
325
326 // Calculate pitches for pixel data with no padding.
327 IVec3 calculatePackedPitch(const TextureFormat &format, const IVec3 &size);
328
329 bool isSamplerMipmapModeLinear(tcu::Sampler::FilterMode filterMode);
330
331 class TextureLevel;
332
333 /*--------------------------------------------------------------------*//*!
334 * \brief Read-only pixel data access
335 *
336 * ConstPixelBufferAccess encapsulates pixel data pointer along with
337 * format and layout information. It can be used for read-only access
338 * to arbitrary pixel buffers.
339 *
340 * Access objects are like iterators or pointers. They can be passed around
341 * as values and are valid as long as the storage doesn't change.
342 *//*--------------------------------------------------------------------*/
343 class ConstPixelBufferAccess
344 {
345 public:
346 ConstPixelBufferAccess(void);
347 ConstPixelBufferAccess(const TextureLevel &level);
348 ConstPixelBufferAccess(const TextureFormat &format, int width, int height, int depth, const void *data);
349 ConstPixelBufferAccess(const TextureFormat &format, const IVec3 &size, const void *data);
350 ConstPixelBufferAccess(const TextureFormat &format, int width, int height, int depth, int rowPitch, int slicePitch,
351 const void *data);
352 ConstPixelBufferAccess(const TextureFormat &format, const IVec3 &size, const IVec3 &pitch, const void *data);
353 ConstPixelBufferAccess(const TextureFormat &format, const IVec3 &size, const IVec3 &pitch, const IVec3 ÷r,
354 const void *data);
355
getFormat(void) const356 const TextureFormat &getFormat(void) const
357 {
358 return m_format;
359 }
getSize(void) const360 const IVec3 &getSize(void) const
361 {
362 return m_size;
363 }
getWidth(void) const364 int getWidth(void) const
365 {
366 return m_size.x();
367 }
getHeight(void) const368 int getHeight(void) const
369 {
370 return m_size.y();
371 }
getDepth(void) const372 int getDepth(void) const
373 {
374 return m_size.z();
375 }
getPixelPitch(void) const376 int getPixelPitch(void) const
377 {
378 return m_pitch.x();
379 }
getRowPitch(void) const380 int getRowPitch(void) const
381 {
382 return m_pitch.y();
383 }
getSlicePitch(void) const384 int getSlicePitch(void) const
385 {
386 return m_pitch.z();
387 }
getPitch(void) const388 const IVec3 &getPitch(void) const
389 {
390 return m_pitch;
391 }
getDivider(void) const392 const IVec3 &getDivider(void) const
393 {
394 return m_divider;
395 }
396
getDataPtr(void) const397 const void *getDataPtr(void) const
398 {
399 return m_data;
400 }
getPixelPtr(int x,int y,int z=0) const401 const void *getPixelPtr(int x, int y, int z = 0) const
402 {
403 return (const uint8_t *)m_data + (x / m_divider.x()) * m_pitch.x() + (y / m_divider.y()) * m_pitch.y() +
404 (z / m_divider.z()) * m_pitch.z();
405 }
406
407 Vec4 getPixel(int x, int y, int z = 0) const;
408 IVec4 getPixelInt(int x, int y, int z = 0) const;
getPixelUint(int x,int y,int z=0) const409 UVec4 getPixelUint(int x, int y, int z = 0) const
410 {
411 return getPixelInt(x, y, z).cast<uint32_t>();
412 }
413 I64Vec4 getPixelInt64(int x, int y, int z = 0) const;
getPixelUint64(int x,int y,int z=0) const414 U64Vec4 getPixelUint64(int x, int y, int z = 0) const
415 {
416 return getPixelInt64(x, y, z).cast<uint64_t>();
417 }
418 U64Vec4 getPixelBitsAsUint64(int x, int y, int z = 0) const;
419
420 template <typename T>
421 Vector<T, 4> getPixelT(int x, int y, int z = 0) const;
422
423 float getPixDepth(int x, int y, int z = 0) const;
424 int getPixStencil(int x, int y, int z = 0) const;
425
426 Vec4 sample1D(const Sampler &sampler, Sampler::FilterMode filter, float s, int level) const;
427 Vec4 sample2D(const Sampler &sampler, Sampler::FilterMode filter, float s, float t, int depth) const;
428 Vec4 sample3D(const Sampler &sampler, Sampler::FilterMode filter, float s, float t, float r) const;
429
430 Vec4 sample1DOffset(const Sampler &sampler, Sampler::FilterMode filter, float s, const IVec2 &offset) const;
431 Vec4 sample2DOffset(const Sampler &sampler, Sampler::FilterMode filter, float s, float t,
432 const IVec3 &offset) const;
433 Vec4 sample3DOffset(const Sampler &sampler, Sampler::FilterMode filter, float s, float t, float r,
434 const IVec3 &offset) const;
435
436 float sample1DCompare(const Sampler &sampler, Sampler::FilterMode filter, float ref, float s,
437 const IVec2 &offset) const;
438 float sample2DCompare(const Sampler &sampler, Sampler::FilterMode filter, float ref, float s, float t,
439 const IVec3 &offset) const;
440
441 protected:
442 TextureFormat m_format;
443 IVec3 m_size;
444 IVec3 m_pitch; //!< (pixelPitch, rowPitch, slicePitch)
445 IVec3 m_divider;
446 mutable void *m_data;
447 } DE_WARN_UNUSED_TYPE;
448
449 /*--------------------------------------------------------------------*//*!
450 * \brief Read-write pixel data access
451 *
452 * This class extends read-only access object by providing write functionality.
453 *
454 * \note PixelBufferAccess may not have any data members nor add any
455 * virtual functions. It must be possible to reinterpret_cast<>
456 * PixelBufferAccess to ConstPixelBufferAccess.
457 *//*--------------------------------------------------------------------*/
458 class PixelBufferAccess : public ConstPixelBufferAccess
459 {
460 public:
PixelBufferAccess(void)461 PixelBufferAccess(void)
462 {
463 }
464 PixelBufferAccess(TextureLevel &level);
465 PixelBufferAccess(const TextureFormat &format, int width, int height, int depth, void *data);
466 PixelBufferAccess(const TextureFormat &format, const IVec3 &size, void *data);
467 PixelBufferAccess(const TextureFormat &format, int width, int height, int depth, int rowPitch, int slicePitch,
468 void *data);
469 PixelBufferAccess(const TextureFormat &format, const IVec3 &size, const IVec3 &pitch, void *data);
470 PixelBufferAccess(const TextureFormat &format, const IVec3 &size, const IVec3 &pitch, const IVec3 &block,
471 void *data);
472
getDataPtr(void) const473 void *getDataPtr(void) const
474 {
475 return m_data;
476 }
getPixelPtr(int x,int y,int z=0) const477 void *getPixelPtr(int x, int y, int z = 0) const
478 {
479 return (uint8_t *)m_data + (x / m_divider.x()) * m_pitch.x() + (y / m_divider.y()) * m_pitch.y() +
480 (z / m_divider.z()) * m_pitch.z();
481 }
482
483 void setPixel(const tcu::Vec4 &color, int x, int y, int z = 0) const;
484 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) const485 void setPixel(const tcu::UVec4 &color, int x, int y, int z = 0) const
486 {
487 setPixel(color.cast<int>(), x, y, z);
488 }
489
490 void setPixDepth(float depth, int x, int y, int z = 0) const;
491 void setPixStencil(int stencil, int x, int y, int z = 0) const;
492 } DE_WARN_UNUSED_TYPE;
493
494 /*--------------------------------------------------------------------*//*!
495 * \brief Generic pixel data container
496 *
497 * This container supports all valid TextureFormat combinations and
498 * both 2D and 3D textures. To read or manipulate data access object must
499 * be queried using getAccess().
500 *//*--------------------------------------------------------------------*/
501 class TextureLevel
502 {
503 public:
504 TextureLevel(void);
505 TextureLevel(const TextureFormat &format);
506 TextureLevel(const TextureFormat &format, int width, int height, int depth = 1);
507 ~TextureLevel(void);
508
getSize(void) const509 const IVec3 &getSize(void) const
510 {
511 return m_size;
512 }
getWidth(void) const513 int getWidth(void) const
514 {
515 return m_size.x();
516 }
getHeight(void) const517 int getHeight(void) const
518 {
519 return m_size.y();
520 }
getDepth(void) const521 int getDepth(void) const
522 {
523 return m_size.z();
524 }
isEmpty(void) const525 bool isEmpty(void) const
526 {
527 return m_size.x() * m_size.y() * m_size.z() == 0;
528 }
getFormat(void) const529 const TextureFormat getFormat(void) const
530 {
531 return m_format;
532 }
533
534 void setStorage(const TextureFormat &format, int width, int heigth, int depth = 1);
535 void setSize(int width, int height, int depth = 1);
536
getAccess(void)537 PixelBufferAccess getAccess(void)
538 {
539 return isEmpty() ? PixelBufferAccess() :
540 PixelBufferAccess(m_format, m_size, calculatePackedPitch(m_format, m_size), getPtr());
541 }
getAccess(void) const542 ConstPixelBufferAccess getAccess(void) const
543 {
544 return isEmpty() ? ConstPixelBufferAccess() :
545 ConstPixelBufferAccess(m_format, m_size, calculatePackedPitch(m_format, m_size), getPtr());
546 }
547
548 private:
getPtr(void)549 void *getPtr(void)
550 {
551 return m_data.getPtr();
552 }
getPtr(void) const553 const void *getPtr(void) const
554 {
555 return m_data.getPtr();
556 }
557
558 TextureFormat m_format;
559 IVec3 m_size;
560 de::ArrayBuffer<uint8_t> m_data;
561
562 friend class ConstPixelBufferAccess;
563 } DE_WARN_UNUSED_TYPE;
564
565 /*--------------------------------------------------------------------*//*!
566 * \brief VK_EXT_image_view_min_lod
567 *//*--------------------------------------------------------------------*/
568 enum ImageViewMinLodMode
569 {
570 IMAGEVIEWMINLODMODE_PREFERRED, //!< use image view min lod as-is
571 IMAGEVIEWMINLODMODE_ALTERNATIVE, //!< use floor of image view min lod, as in 'Image Level(s) Selection' in VK spec (v 1.3.206)
572 };
573
574 struct ImageViewMinLod
575 {
576 float value;
577 ImageViewMinLodMode mode;
578 };
579
580 struct ImageViewMinLodParams
581 {
582 int baseLevel;
583 ImageViewMinLod minLod;
584 bool intTexCoord;
585 };
586
587 Vec4 sampleLevelArray1D(const ConstPixelBufferAccess *levels, int numLevels, const Sampler &sampler, float s, int level,
588 float lod);
589 Vec4 sampleLevelArray2D(const ConstPixelBufferAccess *levels, int numLevels, const Sampler &sampler, float s, float t,
590 int depth, float lod, bool es2 = false, ImageViewMinLodParams *minLodParams = DE_NULL);
591 Vec4 sampleLevelArray3D(const ConstPixelBufferAccess *levels, int numLevels, const Sampler &sampler, float s, float t,
592 float r, float lod, ImageViewMinLodParams *minLodParams = DE_NULL);
593
594 Vec4 sampleLevelArray1DOffset(const ConstPixelBufferAccess *levels, int numLevels, const Sampler &sampler, float s,
595 float lod, const IVec2 &offset);
596 Vec4 sampleLevelArray2DOffset(const ConstPixelBufferAccess *levels, int numLevels, const Sampler &sampler, float s,
597 float t, float lod, const IVec3 &offset, bool es2 = false,
598 ImageViewMinLodParams *minLodParams = DE_NULL);
599 Vec4 sampleLevelArray3DOffset(const ConstPixelBufferAccess *levels, int numLevels, const Sampler &sampler, float s,
600 float t, float r, float lod, const IVec3 &offset,
601 ImageViewMinLodParams *minLodParams = DE_NULL);
602
603 float sampleLevelArray1DCompare(const ConstPixelBufferAccess *levels, int numLevels, const Sampler &sampler, float ref,
604 float s, float lod, const IVec2 &offset);
605 float sampleLevelArray2DCompare(const ConstPixelBufferAccess *levels, int numLevels, const Sampler &sampler, float ref,
606 float s, float t, float lod, const IVec3 &offset);
607
608 Vec4 gatherArray2DOffsets(const ConstPixelBufferAccess &src, const Sampler &sampler, float s, float t, int depth,
609 int componentNdx, const IVec2 (&offsets)[4]);
610 Vec4 gatherArray2DOffsetsCompare(const ConstPixelBufferAccess &src, const Sampler &sampler, float ref, float s, float t,
611 int depth, const IVec2 (&offsets)[4]);
612
613 enum CubeFace
614 {
615 CUBEFACE_NEGATIVE_X = 0,
616 CUBEFACE_POSITIVE_X,
617 CUBEFACE_NEGATIVE_Y,
618 CUBEFACE_POSITIVE_Y,
619 CUBEFACE_NEGATIVE_Z,
620 CUBEFACE_POSITIVE_Z,
621
622 CUBEFACE_LAST
623 };
624
625 /*--------------------------------------------------------------------*//*!
626 * \brief Coordinates projected onto cube face.
627 *//*--------------------------------------------------------------------*/
628 template <typename T>
629 struct CubeFaceCoords
630 {
631 CubeFace face;
632 T s;
633 T t;
634
CubeFaceCoordstcu::CubeFaceCoords635 CubeFaceCoords(CubeFace face_, T s_, T t_) : face(face_), s(s_), t(t_)
636 {
637 }
CubeFaceCoordstcu::CubeFaceCoords638 CubeFaceCoords(CubeFace face_, const Vector<T, 2> &c) : face(face_), s(c.x()), t(c.y())
639 {
640 }
641 } DE_WARN_UNUSED_TYPE;
642
643 typedef CubeFaceCoords<float> CubeFaceFloatCoords;
644 typedef CubeFaceCoords<int> CubeFaceIntCoords;
645
646 CubeFace selectCubeFace(const Vec3 &coords);
647 Vec2 projectToFace(CubeFace face, const Vec3 &coords);
648 CubeFaceFloatCoords getCubeFaceCoords(const Vec3 &coords);
649 CubeFaceIntCoords remapCubeEdgeCoords(const CubeFaceIntCoords &coords, int size);
650
651 /*--------------------------------------------------------------------*//*!
652 * \brief 2D Texture View
653 *//*--------------------------------------------------------------------*/
654 class Texture2DView
655 {
656 public:
657 Texture2DView(int numLevels, const ConstPixelBufferAccess *levels, bool es2 = false,
658 ImageViewMinLodParams *minLodParams = DE_NULL);
659
getNumLevels(void) const660 int getNumLevels(void) const
661 {
662 return m_numLevels;
663 }
getWidth(void) const664 int getWidth(void) const
665 {
666 return m_numLevels > 0 ? m_levels[0].getWidth() : 0;
667 }
getHeight(void) const668 int getHeight(void) const
669 {
670 return m_numLevels > 0 ? m_levels[0].getHeight() : 0;
671 }
getLevel(int ndx) const672 const ConstPixelBufferAccess &getLevel(int ndx) const
673 {
674 DE_ASSERT(de::inBounds(ndx, 0, m_numLevels));
675 return m_levels[ndx];
676 }
getLevels(void) const677 const ConstPixelBufferAccess *getLevels(void) const
678 {
679 return m_levels;
680 }
isES2(void) const681 bool isES2(void) const
682 {
683 return m_es2;
684 }
685
686 Vec4 sample(const Sampler &sampler, float s, float t, float lod) const;
687 Vec4 sampleOffset(const Sampler &sampler, float s, float t, float lod, const IVec2 &offset) const;
688 float sampleCompare(const Sampler &sampler, float ref, float s, float t, float lod) const;
689 float sampleCompareOffset(const Sampler &sampler, float ref, float s, float t, float lod,
690 const IVec2 &offset) const;
691
692 Vec4 gatherOffsets(const Sampler &sampler, float s, float t, int componentNdx, const IVec2 (&offsets)[4]) const;
693 Vec4 gatherOffsetsCompare(const Sampler &sampler, float ref, float s, float t, const IVec2 (&offsets)[4]) const;
694
getImageViewMinLodParams(void) const695 ImageViewMinLodParams *getImageViewMinLodParams(void) const
696 {
697 return m_minLodParams;
698 }
699
700 protected:
701 int m_numLevels;
702 const ConstPixelBufferAccess *m_levels;
703 bool m_es2;
704 struct ImageViewMinLodParams *m_minLodParams;
705 } DE_WARN_UNUSED_TYPE;
706
Texture2DView(int numLevels,const ConstPixelBufferAccess * levels,bool es2,ImageViewMinLodParams * minLodParams)707 inline Texture2DView::Texture2DView(int numLevels, const ConstPixelBufferAccess *levels, bool es2,
708 ImageViewMinLodParams *minLodParams)
709 : m_numLevels(numLevels)
710 , m_levels(levels)
711 , m_es2(es2)
712 , m_minLodParams(minLodParams)
713 {
714 DE_ASSERT(m_numLevels >= 0 && ((m_numLevels == 0) == !m_levels));
715 }
716
sample(const Sampler & sampler,float s,float t,float lod) const717 inline Vec4 Texture2DView::sample(const Sampler &sampler, float s, float t, float lod) const
718 {
719 return sampleLevelArray2D(m_levels, m_numLevels, sampler, s, t, 0 /* depth */, lod, m_es2, m_minLodParams);
720 }
721
sampleOffset(const Sampler & sampler,float s,float t,float lod,const IVec2 & offset) const722 inline Vec4 Texture2DView::sampleOffset(const Sampler &sampler, float s, float t, float lod, const IVec2 &offset) const
723 {
724 return sampleLevelArray2DOffset(m_levels, m_numLevels, sampler, s, t, lod, IVec3(offset.x(), offset.y(), 0));
725 }
726
sampleCompare(const Sampler & sampler,float ref,float s,float t,float lod) const727 inline float Texture2DView::sampleCompare(const Sampler &sampler, float ref, float s, float t, float lod) const
728 {
729 return sampleLevelArray2DCompare(m_levels, m_numLevels, sampler, ref, s, t, lod, IVec3(0, 0, 0));
730 }
731
sampleCompareOffset(const Sampler & sampler,float ref,float s,float t,float lod,const IVec2 & offset) const732 inline float Texture2DView::sampleCompareOffset(const Sampler &sampler, float ref, float s, float t, float lod,
733 const IVec2 &offset) const
734 {
735 return sampleLevelArray2DCompare(m_levels, m_numLevels, sampler, ref, s, t, lod, IVec3(offset.x(), offset.y(), 0));
736 }
737
gatherOffsets(const Sampler & sampler,float s,float t,int componentNdx,const IVec2 (& offsets)[4]) const738 inline Vec4 Texture2DView::gatherOffsets(const Sampler &sampler, float s, float t, int componentNdx,
739 const IVec2 (&offsets)[4]) const
740 {
741 return gatherArray2DOffsets(m_levels[0], sampler, s, t, 0, componentNdx, offsets);
742 }
743
gatherOffsetsCompare(const Sampler & sampler,float ref,float s,float t,const IVec2 (& offsets)[4]) const744 inline Vec4 Texture2DView::gatherOffsetsCompare(const Sampler &sampler, float ref, float s, float t,
745 const IVec2 (&offsets)[4]) const
746 {
747 return gatherArray2DOffsetsCompare(m_levels[0], sampler, ref, s, t, 0, offsets);
748 }
749
750 /*--------------------------------------------------------------------*//*!
751 * \brief Base class for textures that have single mip-map pyramid
752 *//*--------------------------------------------------------------------*/
753 class TextureLevelPyramid
754 {
755 public:
756 TextureLevelPyramid(const TextureFormat &format, int numLevels);
757 TextureLevelPyramid(const TextureLevelPyramid &other);
758 ~TextureLevelPyramid(void);
759
getFormat(void) const760 const TextureFormat &getFormat(void) const
761 {
762 return m_format;
763 }
getNumLevels(void) const764 int getNumLevels(void) const
765 {
766 return (int)m_access.size();
767 }
768
isLevelEmpty(int levelNdx) const769 bool isLevelEmpty(int levelNdx) const
770 {
771 DE_ASSERT(de::inBounds(levelNdx, 0, getNumLevels()));
772 return m_data[(size_t)levelNdx].empty();
773 }
getLevel(int levelNdx) const774 const ConstPixelBufferAccess &getLevel(int levelNdx) const
775 {
776 DE_ASSERT(de::inBounds(levelNdx, 0, getNumLevels()));
777 return m_access[(size_t)levelNdx];
778 }
getLevel(int levelNdx)779 const PixelBufferAccess &getLevel(int levelNdx)
780 {
781 DE_ASSERT(de::inBounds(levelNdx, 0, getNumLevels()));
782 return m_access[(size_t)levelNdx];
783 }
784
getLevels(void) const785 const ConstPixelBufferAccess *getLevels(void) const
786 {
787 return &m_access[0];
788 }
getLevels(void)789 const PixelBufferAccess *getLevels(void)
790 {
791 return &m_access[0];
792 }
793
794 void allocLevel(int levelNdx, int width, int height, int depth);
795 void clearLevel(int levelNdx);
796
797 TextureLevelPyramid &operator=(const TextureLevelPyramid &other);
798
799 private:
800 typedef de::ArrayBuffer<uint8_t> LevelData;
801
802 TextureFormat m_format;
803 std::vector<LevelData> m_data;
804 std::vector<PixelBufferAccess> m_access;
805 } DE_WARN_UNUSED_TYPE;
806
807 /*--------------------------------------------------------------------*//*!
808 * \brief 2D Texture reference implementation
809 *//*--------------------------------------------------------------------*/
810 class Texture2D : private TextureLevelPyramid
811 {
812 public:
813 Texture2D(const TextureFormat &format, int width, int height, bool es2 = false);
814 Texture2D(const TextureFormat &format, int width, int height, int mipmaps);
815 Texture2D(const Texture2D &other);
816 ~Texture2D(void);
817
getWidth(void) const818 int getWidth(void) const
819 {
820 return m_width;
821 }
getHeight(void) const822 int getHeight(void) const
823 {
824 return m_height;
825 }
getView(void) const826 const Texture2DView &getView(void) const
827 {
828 return m_view;
829 }
isYUVTextureUsed(void) const830 bool isYUVTextureUsed(void) const
831 {
832 return m_yuvTextureUsed;
833 }
834 void allocLevel(int levelNdx);
835
836 // Sampling
837 Vec4 sample(const Sampler &sampler, float s, float t, float lod) const;
838 Vec4 sampleOffset(const Sampler &sampler, float s, float t, float lod, const IVec2 &offset) const;
839 float sampleCompare(const Sampler &sampler, float ref, float s, float t, float lod) const;
840 float sampleCompareOffset(const Sampler &sampler, float ref, float s, float t, float lod,
841 const IVec2 &offset) const;
842
843 Vec4 gatherOffsets(const Sampler &sampler, float s, float t, int componentNdx, const IVec2 (&offsets)[4]) const;
844 Vec4 gatherOffsetsCompare(const Sampler &sampler, float ref, float s, float t, const IVec2 (&offsets)[4]) const;
845
846 using TextureLevelPyramid::clearLevel;
847 using TextureLevelPyramid::getFormat;
848 using TextureLevelPyramid::getLevel;
849 using TextureLevelPyramid::getNumLevels;
850 using TextureLevelPyramid::isLevelEmpty;
851
852 Texture2D &operator=(const Texture2D &other);
853 //whether this is a yuv format texture tests
854 bool m_yuvTextureUsed;
operator Texture2DView(void) const855 operator Texture2DView(void) const
856 {
857 return m_view;
858 }
859
860 private:
861 int m_width;
862 int m_height;
863 Texture2DView m_view;
864 } DE_WARN_UNUSED_TYPE;
865
sample(const Sampler & sampler,float s,float t,float lod) const866 inline Vec4 Texture2D::sample(const Sampler &sampler, float s, float t, float lod) const
867 {
868 return m_view.sample(sampler, s, t, lod);
869 }
870
sampleOffset(const Sampler & sampler,float s,float t,float lod,const IVec2 & offset) const871 inline Vec4 Texture2D::sampleOffset(const Sampler &sampler, float s, float t, float lod, const IVec2 &offset) const
872 {
873 return m_view.sampleOffset(sampler, s, t, lod, offset);
874 }
875
sampleCompare(const Sampler & sampler,float ref,float s,float t,float lod) const876 inline float Texture2D::sampleCompare(const Sampler &sampler, float ref, float s, float t, float lod) const
877 {
878 return m_view.sampleCompare(sampler, ref, s, t, lod);
879 }
880
sampleCompareOffset(const Sampler & sampler,float ref,float s,float t,float lod,const IVec2 & offset) const881 inline float Texture2D::sampleCompareOffset(const Sampler &sampler, float ref, float s, float t, float lod,
882 const IVec2 &offset) const
883 {
884 return m_view.sampleCompareOffset(sampler, ref, s, t, lod, offset);
885 }
886
gatherOffsets(const Sampler & sampler,float s,float t,int componentNdx,const IVec2 (& offsets)[4]) const887 inline Vec4 Texture2D::gatherOffsets(const Sampler &sampler, float s, float t, int componentNdx,
888 const IVec2 (&offsets)[4]) const
889 {
890 return m_view.gatherOffsets(sampler, s, t, componentNdx, offsets);
891 }
892
gatherOffsetsCompare(const Sampler & sampler,float ref,float s,float t,const IVec2 (& offsets)[4]) const893 inline Vec4 Texture2D::gatherOffsetsCompare(const Sampler &sampler, float ref, float s, float t,
894 const IVec2 (&offsets)[4]) const
895 {
896 return m_view.gatherOffsetsCompare(sampler, ref, s, t, offsets);
897 }
898
899 /*--------------------------------------------------------------------*//*!
900 * \brief Cube Map Texture View
901 *//*--------------------------------------------------------------------*/
902 class TextureCubeView
903 {
904 public:
905 TextureCubeView(void);
906 TextureCubeView(int numLevels, const ConstPixelBufferAccess *const (&levels)[CUBEFACE_LAST], bool es2 = false,
907 ImageViewMinLodParams *minLodParams = DE_NULL);
908
getNumLevels(void) const909 int getNumLevels(void) const
910 {
911 return m_numLevels;
912 }
isES2(void) const913 bool isES2(void) const
914 {
915 return m_es2;
916 }
getSize(void) const917 int getSize(void) const
918 {
919 return m_numLevels > 0 ? m_levels[0][0].getWidth() : 0;
920 }
getLevelFace(int ndx,CubeFace face) const921 const ConstPixelBufferAccess &getLevelFace(int ndx, CubeFace face) const
922 {
923 DE_ASSERT(de::inBounds(ndx, 0, m_numLevels));
924 return m_levels[face][ndx];
925 }
getFaceLevels(CubeFace face) const926 const ConstPixelBufferAccess *getFaceLevels(CubeFace face) const
927 {
928 return m_levels[face];
929 }
930
931 Vec4 sample(const Sampler &sampler, float s, float t, float p, float lod) const;
932 float sampleCompare(const Sampler &sampler, float ref, float s, float t, float r, float lod) const;
933
934 Vec4 gather(const Sampler &sampler, float s, float t, float r, int componentNdx) const;
935 Vec4 gatherCompare(const Sampler &sampler, float ref, float s, float t, float r) const;
936
getImageViewMinLodParams(void) const937 ImageViewMinLodParams *getImageViewMinLodParams(void) const
938 {
939 return m_minLodParams;
940 }
941
942 protected:
943 int m_numLevels;
944 const ConstPixelBufferAccess *m_levels[CUBEFACE_LAST];
945 bool m_es2;
946 ImageViewMinLodParams *m_minLodParams;
947 } DE_WARN_UNUSED_TYPE;
948
949 /*--------------------------------------------------------------------*//*!
950 * \brief Cube Map Texture reference implementation
951 *//*--------------------------------------------------------------------*/
952 class TextureCube
953 {
954 public:
955 TextureCube(const TextureFormat &format, int size, bool es2 = false);
956 TextureCube(const TextureCube &other);
957 ~TextureCube(void);
958
getFormat(void) const959 const TextureFormat &getFormat(void) const
960 {
961 return m_format;
962 }
getSize(void) const963 int getSize(void) const
964 {
965 return m_size;
966 }
getView(void) const967 const TextureCubeView &getView(void) const
968 {
969 return m_view;
970 }
971
getNumLevels(void) const972 int getNumLevels(void) const
973 {
974 return (int)m_access[0].size();
975 }
getLevelFace(int ndx,CubeFace face) const976 const ConstPixelBufferAccess &getLevelFace(int ndx, CubeFace face) const
977 {
978 DE_ASSERT(de::inBounds(ndx, 0, getNumLevels()));
979 return m_access[face][(size_t)ndx];
980 }
getLevelFace(int ndx,CubeFace face)981 const PixelBufferAccess &getLevelFace(int ndx, CubeFace face)
982 {
983 DE_ASSERT(de::inBounds(ndx, 0, getNumLevels()));
984 return m_access[face][(size_t)ndx];
985 }
986
987 void allocLevel(CubeFace face, int levelNdx);
988 void clearLevel(CubeFace face, int levelNdx);
isLevelEmpty(CubeFace face,int levelNdx) const989 bool isLevelEmpty(CubeFace face, int levelNdx) const
990 {
991 DE_ASSERT(de::inBounds(levelNdx, 0, getNumLevels()));
992 return m_data[face][(size_t)levelNdx].empty();
993 }
994
995 Vec4 sample(const Sampler &sampler, float s, float t, float p, float lod) const;
996 float sampleCompare(const Sampler &sampler, float ref, float s, float t, float r, float lod) const;
997
998 Vec4 gather(const Sampler &sampler, float s, float t, float r, int componentNdx) const;
999 Vec4 gatherCompare(const Sampler &sampler, float ref, float s, float t, float r) const;
1000
1001 TextureCube &operator=(const TextureCube &other);
1002
operator TextureCubeView(void) const1003 operator TextureCubeView(void) const
1004 {
1005 return m_view;
1006 }
1007
1008 private:
1009 typedef de::ArrayBuffer<uint8_t> LevelData;
1010
1011 TextureFormat m_format;
1012 int m_size;
1013 std::vector<LevelData> m_data[CUBEFACE_LAST];
1014 std::vector<PixelBufferAccess> m_access[CUBEFACE_LAST];
1015 TextureCubeView m_view;
1016 } DE_WARN_UNUSED_TYPE;
1017
sample(const Sampler & sampler,float s,float t,float p,float lod) const1018 inline Vec4 TextureCube::sample(const Sampler &sampler, float s, float t, float p, float lod) const
1019 {
1020 return m_view.sample(sampler, s, t, p, lod);
1021 }
1022
sampleCompare(const Sampler & sampler,float ref,float s,float t,float r,float lod) const1023 inline float TextureCube::sampleCompare(const Sampler &sampler, float ref, float s, float t, float r, float lod) const
1024 {
1025 return m_view.sampleCompare(sampler, ref, s, t, r, lod);
1026 }
1027
gather(const Sampler & sampler,float s,float t,float r,int componentNdx) const1028 inline Vec4 TextureCube::gather(const Sampler &sampler, float s, float t, float r, int componentNdx) const
1029 {
1030 return m_view.gather(sampler, s, t, r, componentNdx);
1031 }
1032
gatherCompare(const Sampler & sampler,float ref,float s,float t,float r) const1033 inline Vec4 TextureCube::gatherCompare(const Sampler &sampler, float ref, float s, float t, float r) const
1034 {
1035 return m_view.gatherCompare(sampler, ref, s, t, r);
1036 }
1037
1038 /*--------------------------------------------------------------------*//*!
1039 * \brief 1D Texture View
1040 *//*--------------------------------------------------------------------*/
1041 class Texture1DView
1042 {
1043 public:
1044 Texture1DView(int numLevels, const ConstPixelBufferAccess *levels, bool es2, ImageViewMinLodParams *minLodParams);
1045
getNumLevels(void) const1046 int getNumLevels(void) const
1047 {
1048 return m_numLevels;
1049 }
getWidth(void) const1050 int getWidth(void) const
1051 {
1052 return m_numLevels > 0 ? m_levels[0].getWidth() : 0;
1053 }
getLevel(int ndx) const1054 const ConstPixelBufferAccess &getLevel(int ndx) const
1055 {
1056 DE_ASSERT(de::inBounds(ndx, 0, m_numLevels));
1057 return m_levels[ndx];
1058 }
getLevels(void) const1059 const ConstPixelBufferAccess *getLevels(void) const
1060 {
1061 return m_levels;
1062 }
isES2(void) const1063 bool isES2(void) const
1064 {
1065 return false;
1066 }
1067
1068 Vec4 sample(const Sampler &sampler, float s, float lod) const;
1069 Vec4 sampleOffset(const Sampler &sampler, float s, float lod, int32_t offset) const;
1070 float sampleCompare(const Sampler &sampler, float ref, float s, float lod) const;
1071 float sampleCompareOffset(const Sampler &sampler, float ref, float s, float lod, int32_t offset) const;
1072
getImageViewMinLodParams(void) const1073 ImageViewMinLodParams *getImageViewMinLodParams(void) const
1074 {
1075 return DE_NULL;
1076 }
1077
1078 protected:
1079 int m_numLevels;
1080 const ConstPixelBufferAccess *m_levels;
1081 } DE_WARN_UNUSED_TYPE;
1082
Texture1DView(int numLevels,const ConstPixelBufferAccess * levels,bool es2 DE_UNUSED_ATTR=false,ImageViewMinLodParams * minLodParams DE_UNUSED_ATTR=DE_NULL)1083 inline Texture1DView::Texture1DView(int numLevels, const ConstPixelBufferAccess *levels,
1084 bool es2 DE_UNUSED_ATTR = false,
1085 ImageViewMinLodParams *minLodParams DE_UNUSED_ATTR = DE_NULL)
1086 : m_numLevels(numLevels)
1087 , m_levels(levels)
1088 {
1089 DE_ASSERT(m_numLevels >= 0 && ((m_numLevels == 0) == !m_levels));
1090 }
1091
sample(const Sampler & sampler,float s,float lod) const1092 inline Vec4 Texture1DView::sample(const Sampler &sampler, float s, float lod) const
1093 {
1094 return sampleLevelArray1D(m_levels, m_numLevels, sampler, s, 0 /* depth */, lod);
1095 }
1096
sampleOffset(const Sampler & sampler,float s,float lod,int32_t offset) const1097 inline Vec4 Texture1DView::sampleOffset(const Sampler &sampler, float s, float lod, int32_t offset) const
1098 {
1099 return sampleLevelArray1DOffset(m_levels, m_numLevels, sampler, s, lod, IVec2(offset, 0));
1100 }
1101
sampleCompare(const Sampler & sampler,float ref,float s,float lod) const1102 inline float Texture1DView::sampleCompare(const Sampler &sampler, float ref, float s, float lod) const
1103 {
1104 return sampleLevelArray1DCompare(m_levels, m_numLevels, sampler, ref, s, lod, IVec2(0, 0));
1105 }
1106
sampleCompareOffset(const Sampler & sampler,float ref,float s,float lod,int32_t offset) const1107 inline float Texture1DView::sampleCompareOffset(const Sampler &sampler, float ref, float s, float lod,
1108 int32_t offset) const
1109 {
1110 return sampleLevelArray1DCompare(m_levels, m_numLevels, sampler, ref, s, lod, IVec2(offset, 0));
1111 }
1112
1113 /*--------------------------------------------------------------------*//*!
1114 * \brief 1D Texture reference implementation
1115 *//*--------------------------------------------------------------------*/
1116 class Texture1D : private TextureLevelPyramid
1117 {
1118 public:
1119 Texture1D(const TextureFormat &format, int width);
1120 Texture1D(const Texture1D &other);
1121 ~Texture1D(void);
1122
getWidth(void) const1123 int getWidth(void) const
1124 {
1125 return m_width;
1126 }
getView(void) const1127 const Texture1DView &getView(void) const
1128 {
1129 return m_view;
1130 }
1131
1132 void allocLevel(int levelNdx);
1133
1134 // Sampling
1135 Vec4 sample(const Sampler &sampler, float s, float lod) const;
1136 Vec4 sampleOffset(const Sampler &sampler, float s, float lod, int32_t offset) const;
1137 float sampleCompare(const Sampler &sampler, float ref, float s, float lod) const;
1138 float sampleCompareOffset(const Sampler &sampler, float ref, float s, float lod, int32_t offset) const;
1139
1140 using TextureLevelPyramid::clearLevel;
1141 using TextureLevelPyramid::getFormat;
1142 using TextureLevelPyramid::getLevel;
1143 using TextureLevelPyramid::getNumLevels;
1144 using TextureLevelPyramid::isLevelEmpty;
1145
1146 Texture1D &operator=(const Texture1D &other);
1147
operator Texture1DView(void) const1148 operator Texture1DView(void) const
1149 {
1150 return m_view;
1151 }
1152
1153 private:
1154 int m_width;
1155 Texture1DView m_view;
1156 } DE_WARN_UNUSED_TYPE;
1157
sample(const Sampler & sampler,float s,float lod) const1158 inline Vec4 Texture1D::sample(const Sampler &sampler, float s, float lod) const
1159 {
1160 return m_view.sample(sampler, s, lod);
1161 }
1162
sampleOffset(const Sampler & sampler,float s,float lod,int32_t offset) const1163 inline Vec4 Texture1D::sampleOffset(const Sampler &sampler, float s, float lod, int32_t offset) const
1164 {
1165 return m_view.sampleOffset(sampler, s, lod, offset);
1166 }
1167
sampleCompare(const Sampler & sampler,float ref,float s,float lod) const1168 inline float Texture1D::sampleCompare(const Sampler &sampler, float ref, float s, float lod) const
1169 {
1170 return m_view.sampleCompare(sampler, ref, s, lod);
1171 }
1172
sampleCompareOffset(const Sampler & sampler,float ref,float s,float lod,int32_t offset) const1173 inline float Texture1D::sampleCompareOffset(const Sampler &sampler, float ref, float s, float lod, int32_t offset) const
1174 {
1175 return m_view.sampleCompareOffset(sampler, ref, s, lod, offset);
1176 }
1177
1178 /*--------------------------------------------------------------------*//*!
1179 * \brief 1D Array Texture View
1180 *//*--------------------------------------------------------------------*/
1181 class Texture1DArrayView
1182 {
1183 public:
1184 Texture1DArrayView(int numLevels, const ConstPixelBufferAccess *levels, bool es2 = false,
1185 ImageViewMinLodParams *minLodParams = DE_NULL);
1186
getWidth(void) const1187 int getWidth(void) const
1188 {
1189 return m_numLevels > 0 ? m_levels[0].getWidth() : 0;
1190 }
getNumLayers(void) const1191 int getNumLayers(void) const
1192 {
1193 return m_numLevels > 0 ? m_levels[0].getHeight() : 0;
1194 }
getNumLevels(void) const1195 int getNumLevels(void) const
1196 {
1197 return m_numLevels;
1198 }
getLevel(int ndx) const1199 const ConstPixelBufferAccess &getLevel(int ndx) const
1200 {
1201 DE_ASSERT(de::inBounds(ndx, 0, m_numLevels));
1202 return m_levels[ndx];
1203 }
getLevels(void) const1204 const ConstPixelBufferAccess *getLevels(void) const
1205 {
1206 return m_levels;
1207 }
isES2(void) const1208 bool isES2(void) const
1209 {
1210 return false;
1211 }
1212
1213 Vec4 sample(const Sampler &sampler, float s, float t, float lod) const;
1214 Vec4 sampleOffset(const Sampler &sampler, float s, float t, float lod, int32_t offset) const;
1215 float sampleCompare(const Sampler &sampler, float ref, float s, float t, float lod) const;
1216 float sampleCompareOffset(const Sampler &sampler, float ref, float s, float t, float lod, int32_t offset) const;
1217
getImageViewMinLodParams(void) const1218 ImageViewMinLodParams *getImageViewMinLodParams(void) const
1219 {
1220 return DE_NULL;
1221 }
1222
1223 protected:
1224 int selectLayer(float r) const;
1225
1226 int m_numLevels;
1227 const ConstPixelBufferAccess *m_levels;
1228 } DE_WARN_UNUSED_TYPE;
1229
1230 /*--------------------------------------------------------------------*//*!
1231 * \brief 1D Array Texture reference implementation
1232 *//*--------------------------------------------------------------------*/
1233 class Texture1DArray : private TextureLevelPyramid
1234 {
1235 public:
1236 Texture1DArray(const TextureFormat &format, int width, int numLayers);
1237 Texture1DArray(const Texture1DArray &other);
1238 ~Texture1DArray(void);
1239
getWidth(void) const1240 int getWidth(void) const
1241 {
1242 return m_width;
1243 }
getNumLayers(void) const1244 int getNumLayers(void) const
1245 {
1246 return m_numLayers;
1247 }
1248
1249 void allocLevel(int levelNdx);
1250
1251 using TextureLevelPyramid::clearLevel;
1252 using TextureLevelPyramid::getFormat;
1253 using TextureLevelPyramid::getLevel;
1254 using TextureLevelPyramid::getNumLevels;
1255 using TextureLevelPyramid::isLevelEmpty;
1256
1257 Vec4 sample(const Sampler &sampler, float s, float t, float lod) const;
1258 Vec4 sampleOffset(const Sampler &sampler, float s, float t, float lod, int32_t offset) const;
1259 float sampleCompare(const Sampler &sampler, float ref, float s, float t, float lod) const;
1260 float sampleCompareOffset(const Sampler &sampler, float ref, float s, float t, float lod, int32_t offset) const;
1261
1262 Texture1DArray &operator=(const Texture1DArray &other);
1263
operator Texture1DArrayView(void) const1264 operator Texture1DArrayView(void) const
1265 {
1266 return m_view;
1267 }
1268
1269 private:
1270 int m_width;
1271 int m_numLayers;
1272 Texture1DArrayView m_view;
1273 } DE_WARN_UNUSED_TYPE;
1274
sample(const Sampler & sampler,float s,float t,float lod) const1275 inline Vec4 Texture1DArray::sample(const Sampler &sampler, float s, float t, float lod) const
1276 {
1277 return m_view.sample(sampler, s, t, lod);
1278 }
1279
sampleOffset(const Sampler & sampler,float s,float t,float lod,int32_t offset) const1280 inline Vec4 Texture1DArray::sampleOffset(const Sampler &sampler, float s, float t, float lod, int32_t offset) const
1281 {
1282 return m_view.sampleOffset(sampler, s, t, lod, offset);
1283 }
1284
sampleCompare(const Sampler & sampler,float ref,float s,float t,float lod) const1285 inline float Texture1DArray::sampleCompare(const Sampler &sampler, float ref, float s, float t, float lod) const
1286 {
1287 return m_view.sampleCompare(sampler, ref, s, t, lod);
1288 }
1289
sampleCompareOffset(const Sampler & sampler,float ref,float s,float t,float lod,int32_t offset) const1290 inline float Texture1DArray::sampleCompareOffset(const Sampler &sampler, float ref, float s, float t, float lod,
1291 int32_t offset) const
1292 {
1293 return m_view.sampleCompareOffset(sampler, ref, s, t, lod, offset);
1294 }
1295
1296 /*--------------------------------------------------------------------*//*!
1297 * \brief 2D Array Texture View
1298 *//*--------------------------------------------------------------------*/
1299 class Texture2DArrayView
1300 {
1301 public:
1302 Texture2DArrayView(int numLevels, const ConstPixelBufferAccess *levels, bool es2 = false,
1303 ImageViewMinLodParams *minLodParams = DE_NULL);
1304
getWidth(void) const1305 int getWidth(void) const
1306 {
1307 return m_numLevels > 0 ? m_levels[0].getWidth() : 0;
1308 }
getHeight(void) const1309 int getHeight(void) const
1310 {
1311 return m_numLevels > 0 ? m_levels[0].getHeight() : 0;
1312 }
getNumLayers(void) const1313 int getNumLayers(void) const
1314 {
1315 return m_numLevels > 0 ? m_levels[0].getDepth() : 0;
1316 }
getNumLevels(void) const1317 int getNumLevels(void) const
1318 {
1319 return m_numLevels;
1320 }
getLevel(int ndx) const1321 const ConstPixelBufferAccess &getLevel(int ndx) const
1322 {
1323 DE_ASSERT(de::inBounds(ndx, 0, m_numLevels));
1324 return m_levels[ndx];
1325 }
getLevels(void) const1326 const ConstPixelBufferAccess *getLevels(void) const
1327 {
1328 return m_levels;
1329 }
isES2(void) const1330 bool isES2(void) const
1331 {
1332 return false;
1333 }
1334
1335 Vec4 sample(const Sampler &sampler, float s, float t, float r, float lod) const;
1336 Vec4 sampleOffset(const Sampler &sampler, float s, float t, float r, float lod, const IVec2 &offset) const;
1337 float sampleCompare(const Sampler &sampler, float ref, float s, float t, float r, float lod) const;
1338 float sampleCompareOffset(const Sampler &sampler, float ref, float s, float t, float r, float lod,
1339 const IVec2 &offset) const;
1340
1341 Vec4 gatherOffsets(const Sampler &sampler, float s, float t, float r, int componentNdx,
1342 const IVec2 (&offsets)[4]) const;
1343 Vec4 gatherOffsetsCompare(const Sampler &sampler, float ref, float s, float t, float r,
1344 const IVec2 (&offsets)[4]) const;
1345
getImageViewMinLodParams(void) const1346 ImageViewMinLodParams *getImageViewMinLodParams(void) const
1347 {
1348 return DE_NULL;
1349 }
1350
1351 protected:
1352 int selectLayer(float r) const;
1353
1354 int m_numLevels;
1355 const ConstPixelBufferAccess *m_levels;
1356 } DE_WARN_UNUSED_TYPE;
1357
1358 /*--------------------------------------------------------------------*//*!
1359 * \brief 2D Array Texture reference implementation
1360 *//*--------------------------------------------------------------------*/
1361 class Texture2DArray : private TextureLevelPyramid
1362 {
1363 public:
1364 Texture2DArray(const TextureFormat &format, int width, int height, int numLayers);
1365 Texture2DArray(const Texture2DArray &other);
1366 ~Texture2DArray(void);
1367
getWidth(void) const1368 int getWidth(void) const
1369 {
1370 return m_width;
1371 }
getHeight(void) const1372 int getHeight(void) const
1373 {
1374 return m_height;
1375 }
getNumLayers(void) const1376 int getNumLayers(void) const
1377 {
1378 return m_numLayers;
1379 }
1380
1381 void allocLevel(int levelNdx);
1382
1383 using TextureLevelPyramid::clearLevel;
1384 using TextureLevelPyramid::getFormat;
1385 using TextureLevelPyramid::getLevel;
1386 using TextureLevelPyramid::getNumLevels;
1387 using TextureLevelPyramid::isLevelEmpty;
1388
1389 Vec4 sample(const Sampler &sampler, float s, float t, float r, float lod) const;
1390 Vec4 sampleOffset(const Sampler &sampler, float s, float t, float r, float lod, const IVec2 &offset) const;
1391 float sampleCompare(const Sampler &sampler, float ref, float s, float t, float r, float lod) const;
1392 float sampleCompareOffset(const Sampler &sampler, float ref, float s, float t, float r, float lod,
1393 const IVec2 &offset) const;
1394
1395 Vec4 gatherOffsets(const Sampler &sampler, float s, float t, float r, int componentNdx,
1396 const IVec2 (&offsets)[4]) const;
1397 Vec4 gatherOffsetsCompare(const Sampler &sampler, float ref, float s, float t, float r,
1398 const IVec2 (&offsets)[4]) const;
1399
1400 Texture2DArray &operator=(const Texture2DArray &other);
1401
operator Texture2DArrayView(void) const1402 operator Texture2DArrayView(void) const
1403 {
1404 return m_view;
1405 }
1406
1407 private:
1408 int m_width;
1409 int m_height;
1410 int m_numLayers;
1411 Texture2DArrayView m_view;
1412 } DE_WARN_UNUSED_TYPE;
1413
sample(const Sampler & sampler,float s,float t,float r,float lod) const1414 inline Vec4 Texture2DArray::sample(const Sampler &sampler, float s, float t, float r, float lod) const
1415 {
1416 return m_view.sample(sampler, s, t, r, lod);
1417 }
1418
sampleOffset(const Sampler & sampler,float s,float t,float r,float lod,const IVec2 & offset) const1419 inline Vec4 Texture2DArray::sampleOffset(const Sampler &sampler, float s, float t, float r, float lod,
1420 const IVec2 &offset) const
1421 {
1422 return m_view.sampleOffset(sampler, s, t, r, lod, offset);
1423 }
1424
sampleCompare(const Sampler & sampler,float ref,float s,float t,float r,float lod) const1425 inline float Texture2DArray::sampleCompare(const Sampler &sampler, float ref, float s, float t, float r,
1426 float lod) const
1427 {
1428 return m_view.sampleCompare(sampler, ref, s, t, r, lod);
1429 }
1430
sampleCompareOffset(const Sampler & sampler,float ref,float s,float t,float r,float lod,const IVec2 & offset) const1431 inline float Texture2DArray::sampleCompareOffset(const Sampler &sampler, float ref, float s, float t, float r,
1432 float lod, const IVec2 &offset) const
1433 {
1434 return m_view.sampleCompareOffset(sampler, ref, s, t, r, lod, offset);
1435 }
1436
gatherOffsets(const Sampler & sampler,float s,float t,float r,int componentNdx,const IVec2 (& offsets)[4]) const1437 inline Vec4 Texture2DArray::gatherOffsets(const Sampler &sampler, float s, float t, float r, int componentNdx,
1438 const IVec2 (&offsets)[4]) const
1439 {
1440 return m_view.gatherOffsets(sampler, s, t, r, componentNdx, offsets);
1441 }
1442
gatherOffsetsCompare(const Sampler & sampler,float ref,float s,float t,float r,const IVec2 (& offsets)[4]) const1443 inline Vec4 Texture2DArray::gatherOffsetsCompare(const Sampler &sampler, float ref, float s, float t, float r,
1444 const IVec2 (&offsets)[4]) const
1445 {
1446 return m_view.gatherOffsetsCompare(sampler, ref, s, t, r, offsets);
1447 }
1448
1449 /*--------------------------------------------------------------------*//*!
1450 * \brief 3D Texture View
1451 *//*--------------------------------------------------------------------*/
1452 class Texture3DView
1453 {
1454 public:
1455 Texture3DView(int numLevels, const ConstPixelBufferAccess *levels, bool es2 = false,
1456 ImageViewMinLodParams *minLodParams = DE_NULL);
1457
getWidth(void) const1458 int getWidth(void) const
1459 {
1460 return m_numLevels > 0 ? m_levels[0].getWidth() : 0;
1461 }
getHeight(void) const1462 int getHeight(void) const
1463 {
1464 return m_numLevels > 0 ? m_levels[0].getHeight() : 0;
1465 }
getDepth(void) const1466 int getDepth(void) const
1467 {
1468 return m_numLevels > 0 ? m_levels[0].getDepth() : 0;
1469 }
getNumLevels(void) const1470 int getNumLevels(void) const
1471 {
1472 return m_numLevels;
1473 }
getLevel(int ndx) const1474 const ConstPixelBufferAccess &getLevel(int ndx) const
1475 {
1476 DE_ASSERT(de::inBounds(ndx, 0, m_numLevels));
1477 return m_levels[ndx];
1478 }
getLevels(void) const1479 const ConstPixelBufferAccess *getLevels(void) const
1480 {
1481 return m_levels;
1482 }
isES2(void) const1483 bool isES2(void) const
1484 {
1485 return m_es2;
1486 }
1487
1488 Vec4 sample(const Sampler &sampler, float s, float t, float r, float lod) const;
1489 Vec4 sampleOffset(const Sampler &sampler, float s, float t, float r, float lod, const IVec3 &offset) const;
1490
getImageViewMinLodParams(void) const1491 ImageViewMinLodParams *getImageViewMinLodParams(void) const
1492 {
1493 return m_minLodParams;
1494 }
1495
1496 protected:
1497 int m_numLevels;
1498 const ConstPixelBufferAccess *m_levels;
1499 bool m_es2;
1500 ImageViewMinLodParams *m_minLodParams;
1501
1502 } DE_WARN_UNUSED_TYPE;
1503
sample(const Sampler & sampler,float s,float t,float r,float lod) const1504 inline Vec4 Texture3DView::sample(const Sampler &sampler, float s, float t, float r, float lod) const
1505 {
1506 return sampleLevelArray3D(m_levels, m_numLevels, sampler, s, t, r, lod, m_minLodParams);
1507 }
1508
sampleOffset(const Sampler & sampler,float s,float t,float r,float lod,const IVec3 & offset) const1509 inline Vec4 Texture3DView::sampleOffset(const Sampler &sampler, float s, float t, float r, float lod,
1510 const IVec3 &offset) const
1511 {
1512 return sampleLevelArray3DOffset(m_levels, m_numLevels, sampler, s, t, r, lod, offset, m_minLodParams);
1513 }
1514
1515 /*--------------------------------------------------------------------*//*!
1516 * \brief 3D Texture reference implementation
1517 *//*--------------------------------------------------------------------*/
1518 class Texture3D : private TextureLevelPyramid
1519 {
1520 public:
1521 Texture3D(const TextureFormat &format, int width, int height, int depth);
1522 Texture3D(const Texture3D &other);
1523 ~Texture3D(void);
1524
getWidth(void) const1525 int getWidth(void) const
1526 {
1527 return m_width;
1528 }
getHeight(void) const1529 int getHeight(void) const
1530 {
1531 return m_height;
1532 }
getDepth(void) const1533 int getDepth(void) const
1534 {
1535 return m_depth;
1536 }
1537
1538 void allocLevel(int levelNdx);
1539
1540 using TextureLevelPyramid::clearLevel;
1541 using TextureLevelPyramid::getFormat;
1542 using TextureLevelPyramid::getLevel;
1543 using TextureLevelPyramid::getNumLevels;
1544 using TextureLevelPyramid::isLevelEmpty;
1545
1546 Vec4 sample(const Sampler &sampler, float s, float t, float r, float lod) const;
1547 Vec4 sampleOffset(const Sampler &sampler, float s, float t, float r, float lod, const IVec3 &offset) const;
1548
1549 Texture3D &operator=(const Texture3D &other);
1550
operator Texture3DView(void) const1551 operator Texture3DView(void) const
1552 {
1553 return m_view;
1554 }
1555
1556 private:
1557 int m_width;
1558 int m_height;
1559 int m_depth;
1560 Texture3DView m_view;
1561 } DE_WARN_UNUSED_TYPE;
1562
sample(const Sampler & sampler,float s,float t,float r,float lod) const1563 inline Vec4 Texture3D::sample(const Sampler &sampler, float s, float t, float r, float lod) const
1564 {
1565 return m_view.sample(sampler, s, t, r, lod);
1566 }
1567
sampleOffset(const Sampler & sampler,float s,float t,float r,float lod,const IVec3 & offset) const1568 inline Vec4 Texture3D::sampleOffset(const Sampler &sampler, float s, float t, float r, float lod,
1569 const IVec3 &offset) const
1570 {
1571 return m_view.sampleOffset(sampler, s, t, r, lod, offset);
1572 }
1573
1574 /*--------------------------------------------------------------------*//*!
1575 * \brief Cube Map Array Texture View
1576 *//*--------------------------------------------------------------------*/
1577 class TextureCubeArrayView
1578 {
1579 public:
1580 TextureCubeArrayView(int numLevels, const ConstPixelBufferAccess *levels, bool es2 = false,
1581 ImageViewMinLodParams *minLodParams = DE_NULL);
1582
getSize(void) const1583 int getSize(void) const
1584 {
1585 return m_numLevels > 0 ? m_levels[0].getWidth() : 0;
1586 }
getDepth(void) const1587 int getDepth(void) const
1588 {
1589 return m_numLevels > 0 ? m_levels[0].getDepth() : 0;
1590 }
getNumLayers(void) const1591 int getNumLayers(void) const
1592 {
1593 return getDepth() / 6;
1594 }
getNumLevels(void) const1595 int getNumLevels(void) const
1596 {
1597 return m_numLevels;
1598 }
getLevel(int ndx) const1599 const ConstPixelBufferAccess &getLevel(int ndx) const
1600 {
1601 DE_ASSERT(de::inBounds(ndx, 0, m_numLevels));
1602 return m_levels[ndx];
1603 }
getLevels(void) const1604 const ConstPixelBufferAccess *getLevels(void) const
1605 {
1606 return m_levels;
1607 }
isES2(void) const1608 bool isES2(void) const
1609 {
1610 return false;
1611 }
1612
1613 Vec4 sample(const Sampler &sampler, float s, float t, float r, float q, float lod) const;
1614 Vec4 sampleOffset(const Sampler &sampler, float s, float t, float r, float q, float lod, const IVec2 &offset) const;
1615 float sampleCompare(const Sampler &sampler, float ref, float s, float t, float r, float q, float lod) const;
1616 float sampleCompareOffset(const Sampler &sampler, float ref, float s, float t, float r, float q, float lod,
1617 const IVec2 &offset) const;
1618
getImageViewMinLodParams(void) const1619 ImageViewMinLodParams *getImageViewMinLodParams(void) const
1620 {
1621 return DE_NULL;
1622 }
1623
1624 protected:
1625 int selectLayer(float q) const;
1626
1627 int m_numLevels;
1628 const ConstPixelBufferAccess *m_levels;
1629 } DE_WARN_UNUSED_TYPE;
1630
1631 /*--------------------------------------------------------------------*//*!
1632 * \brief Cube Map Array Texture reference implementation
1633 *//*--------------------------------------------------------------------*/
1634 class TextureCubeArray : private TextureLevelPyramid
1635 {
1636 public:
1637 TextureCubeArray(const TextureFormat &format, int size, int depth);
1638 TextureCubeArray(const TextureCubeArray &other);
1639 ~TextureCubeArray(void);
1640
getSize(void) const1641 int getSize(void) const
1642 {
1643 return m_size;
1644 }
getDepth(void) const1645 int getDepth(void) const
1646 {
1647 return m_depth;
1648 }
1649
1650 void allocLevel(int levelNdx);
1651
1652 using TextureLevelPyramid::clearLevel;
1653 using TextureLevelPyramid::getFormat;
1654 using TextureLevelPyramid::getLevel;
1655 using TextureLevelPyramid::getNumLevels;
1656 using TextureLevelPyramid::isLevelEmpty;
1657
1658 Vec4 sample(const Sampler &sampler, float s, float t, float r, float q, float lod) const;
1659 Vec4 sampleOffset(const Sampler &sampler, float s, float t, float r, float q, float lod, const IVec2 &offset) const;
1660 float sampleCompare(const Sampler &sampler, float ref, float s, float t, float r, float q, float lod) const;
1661 float sampleCompareOffset(const Sampler &sampler, float ref, float s, float t, float r, float q, float lod,
1662 const IVec2 &offset) const;
1663
1664 TextureCubeArray &operator=(const TextureCubeArray &other);
1665
operator TextureCubeArrayView(void) const1666 operator TextureCubeArrayView(void) const
1667 {
1668 return m_view;
1669 }
1670
1671 private:
1672 int m_size;
1673 int m_depth;
1674 TextureCubeArrayView m_view;
1675 } DE_WARN_UNUSED_TYPE;
1676
sample(const Sampler & sampler,float s,float t,float r,float q,float lod) const1677 inline Vec4 TextureCubeArray::sample(const Sampler &sampler, float s, float t, float r, float q, float lod) const
1678 {
1679 return m_view.sample(sampler, s, t, r, q, lod);
1680 }
1681
sampleOffset(const Sampler & sampler,float s,float t,float r,float q,float lod,const IVec2 & offset) const1682 inline Vec4 TextureCubeArray::sampleOffset(const Sampler &sampler, float s, float t, float r, float q, float lod,
1683 const IVec2 &offset) const
1684 {
1685 return m_view.sampleOffset(sampler, s, t, r, q, lod, offset);
1686 }
1687
sampleCompare(const Sampler & sampler,float ref,float s,float t,float r,float q,float lod) const1688 inline float TextureCubeArray::sampleCompare(const Sampler &sampler, float ref, float s, float t, float r, float q,
1689 float lod) const
1690 {
1691 return m_view.sampleCompare(sampler, ref, s, t, r, q, lod);
1692 }
1693
sampleCompareOffset(const Sampler & sampler,float ref,float s,float t,float r,float q,float lod,const IVec2 & offset) const1694 inline float TextureCubeArray::sampleCompareOffset(const Sampler &sampler, float ref, float s, float t, float r,
1695 float q, float lod, const IVec2 &offset) const
1696 {
1697 return m_view.sampleCompareOffset(sampler, ref, s, t, r, q, lod, offset);
1698 }
1699
1700 // Stream operators.
1701 std::ostream &operator<<(std::ostream &str, TextureFormat::ChannelOrder order);
1702 std::ostream &operator<<(std::ostream &str, TextureFormat::ChannelType type);
1703 std::ostream &operator<<(std::ostream &str, TextureFormat format);
1704 std::ostream &operator<<(std::ostream &str, CubeFace face);
1705 std::ostream &operator<<(std::ostream &str, const ConstPixelBufferAccess &access);
1706
1707 } // namespace tcu
1708
1709 #endif // _TCUTEXTURE_HPP
1710