1 #ifndef _SGLRREFERENCECONTEXT_HPP
2 #define _SGLRREFERENCECONTEXT_HPP
3 /*-------------------------------------------------------------------------
4 * drawElements Quality Program OpenGL ES Utilities
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 Rendering Context.
24 *//*--------------------------------------------------------------------*/
25
26 #include "tcuDefs.hpp"
27 #include "sglrContext.hpp"
28 #include "tcuPixelFormat.hpp"
29 #include "tcuSurface.hpp"
30 #include "tcuTexture.hpp"
31 #include "tcuVector.hpp"
32 #include "rrFragmentOperations.hpp"
33 #include "rrRenderState.hpp"
34 #include "rrRenderer.hpp"
35 #include "rrMultisamplePixelBufferAccess.hpp"
36 #include "gluRenderContext.hpp"
37 #include "gluShaderUtil.hpp"
38 #include "deArrayBuffer.hpp"
39
40 #include <map>
41 #include <vector>
42
43 namespace sglr
44 {
45 namespace rc
46 {
47
48 enum
49 {
50 MAX_TEXTURE_SIZE_LOG2 = 14,
51 MAX_TEXTURE_SIZE = 1 << MAX_TEXTURE_SIZE_LOG2
52 };
53
54 class NamedObject
55 {
56 public:
~NamedObject(void)57 virtual ~NamedObject(void)
58 {
59 }
60
getName(void) const61 uint32_t getName(void) const
62 {
63 return m_name;
64 }
65
getRefCount(void) const66 int getRefCount(void) const
67 {
68 return m_refCount;
69 }
incRefCount(void)70 void incRefCount(void)
71 {
72 m_refCount += 1;
73 }
decRefCount(void)74 void decRefCount(void)
75 {
76 DE_ASSERT(m_refCount > 0);
77 m_refCount -= 1;
78 }
79
80 protected:
NamedObject(uint32_t name)81 NamedObject(uint32_t name) : m_name(name), m_refCount(1)
82 {
83 }
84
85 private:
86 uint32_t m_name;
87 int m_refCount;
88 };
89
90 class Texture : public NamedObject
91 {
92 public:
93 enum Type
94 {
95 TYPE_1D,
96 TYPE_2D,
97 TYPE_CUBE_MAP,
98 TYPE_2D_ARRAY,
99 TYPE_3D,
100 TYPE_CUBE_MAP_ARRAY,
101
102 TYPE_LAST
103 };
104
105 Texture(uint32_t name, Type type, bool seamless = true);
~Texture(void)106 virtual ~Texture(void)
107 {
108 }
109
getType(void) const110 Type getType(void) const
111 {
112 return m_type;
113 }
114
getBaseLevel(void) const115 int getBaseLevel(void) const
116 {
117 return m_baseLevel;
118 }
getMaxLevel(void) const119 int getMaxLevel(void) const
120 {
121 return m_maxLevel;
122 }
isImmutable(void) const123 bool isImmutable(void) const
124 {
125 return m_immutable;
126 }
127
setBaseLevel(int baseLevel)128 void setBaseLevel(int baseLevel)
129 {
130 m_baseLevel = baseLevel;
131 }
setMaxLevel(int maxLevel)132 void setMaxLevel(int maxLevel)
133 {
134 m_maxLevel = maxLevel;
135 }
setImmutable(void)136 void setImmutable(void)
137 {
138 m_immutable = true;
139 }
140
getSampler(void) const141 const tcu::Sampler &getSampler(void) const
142 {
143 return m_sampler;
144 }
getSampler(void)145 tcu::Sampler &getSampler(void)
146 {
147 return m_sampler;
148 }
149
150 private:
151 Type m_type;
152
153 bool m_immutable;
154
155 tcu::Sampler m_sampler;
156 int m_baseLevel;
157 int m_maxLevel;
158 };
159
160 //! Class for managing list of texture levels.
161 class TextureLevelArray
162 {
163 public:
164 TextureLevelArray(void);
165 ~TextureLevelArray(void);
166
hasLevel(int level) const167 bool hasLevel(int level) const
168 {
169 return deInBounds32(level, 0, DE_LENGTH_OF_ARRAY(m_data)) && !m_data[level].empty();
170 }
getLevel(int level)171 const tcu::PixelBufferAccess &getLevel(int level)
172 {
173 DE_ASSERT(hasLevel(level));
174 return m_access[level];
175 }
getLevel(int level) const176 const tcu::ConstPixelBufferAccess &getLevel(int level) const
177 {
178 DE_ASSERT(hasLevel(level));
179 return m_access[level];
180 }
181
getLevels(void) const182 const tcu::ConstPixelBufferAccess *getLevels(void) const
183 {
184 return &m_access[0];
185 }
getEffectiveLevels(void) const186 const tcu::ConstPixelBufferAccess *getEffectiveLevels(void) const
187 {
188 return &m_effectiveAccess[0];
189 }
190
191 void allocLevel(int level, const tcu::TextureFormat &format, int width, int height, int depth);
192 void clearLevel(int level);
193
194 void clear(void);
195
196 void updateSamplerMode(tcu::Sampler::DepthStencilMode);
197
198 private:
199 de::ArrayBuffer<uint8_t> m_data[MAX_TEXTURE_SIZE_LOG2];
200 tcu::PixelBufferAccess m_access[MAX_TEXTURE_SIZE_LOG2];
201 tcu::ConstPixelBufferAccess m_effectiveAccess
202 [MAX_TEXTURE_SIZE_LOG2]; //!< the currently effective sampling mode. For Depth-stencil texture always either Depth or stencil.
203 };
204
205 class Texture1D : public Texture
206 {
207 public:
208 Texture1D(uint32_t name = 0);
209 virtual ~Texture1D(void);
210
clearLevels(void)211 void clearLevels(void)
212 {
213 m_levels.clear();
214 }
215
hasLevel(int level) const216 bool hasLevel(int level) const
217 {
218 return m_levels.hasLevel(level);
219 }
getLevel(int level) const220 const tcu::ConstPixelBufferAccess &getLevel(int level) const
221 {
222 return m_levels.getLevel(level);
223 }
getLevel(int level)224 const tcu::PixelBufferAccess &getLevel(int level)
225 {
226 return m_levels.getLevel(level);
227 }
228
229 void allocLevel(int level, const tcu::TextureFormat &format, int width);
230
231 bool isComplete(void) const;
232
233 void updateView(
234 tcu::Sampler::DepthStencilMode
235 mode); // \note View must be refreshed after texture parameter/size changes, before calling sample*()
236
237 tcu::Vec4 sample(float s, float lod) const;
238 void sample4(tcu::Vec4 output[4], const float packetTexcoords[4], float lodBias = 0.0f) const;
239
240 private:
241 TextureLevelArray m_levels;
242 tcu::Texture2DView m_view;
243 };
244
245 class Texture2D : public Texture
246 {
247 public:
248 Texture2D(uint32_t name = 0, bool es2 = false);
249 virtual ~Texture2D(void);
250
clearLevels(void)251 void clearLevels(void)
252 {
253 m_levels.clear();
254 }
255
hasLevel(int level) const256 bool hasLevel(int level) const
257 {
258 return m_levels.hasLevel(level);
259 }
getLevel(int level) const260 const tcu::ConstPixelBufferAccess &getLevel(int level) const
261 {
262 return m_levels.getLevel(level);
263 }
getLevel(int level)264 const tcu::PixelBufferAccess &getLevel(int level)
265 {
266 return m_levels.getLevel(level);
267 }
268
269 void allocLevel(int level, const tcu::TextureFormat &format, int width, int height);
270
271 bool isComplete(void) const;
272
273 void updateView(
274 tcu::Sampler::DepthStencilMode
275 mode); // \note View must be refreshed after texture parameter/size changes, before calling sample*()
276
277 tcu::Vec4 sample(float s, float t, float lod) const;
278 void sample4(tcu::Vec4 output[4], const tcu::Vec2 packetTexcoords[4], float lodBias = 0.0f) const;
279
280 private:
281 TextureLevelArray m_levels;
282 tcu::Texture2DView m_view;
283 };
284
285 class TextureCube : public Texture
286 {
287 public:
288 TextureCube(uint32_t name = 0, bool seamless = true);
289 virtual ~TextureCube(void);
290
291 void clearLevels(void);
292
hasFace(int level,tcu::CubeFace face) const293 bool hasFace(int level, tcu::CubeFace face) const
294 {
295 return m_levels[face].hasLevel(level);
296 }
getFace(int level,tcu::CubeFace face)297 const tcu::PixelBufferAccess &getFace(int level, tcu::CubeFace face)
298 {
299 return m_levels[face].getLevel(level);
300 }
getFace(int level,tcu::CubeFace face) const301 const tcu::ConstPixelBufferAccess &getFace(int level, tcu::CubeFace face) const
302 {
303 return m_levels[face].getLevel(level);
304 }
305
306 void allocFace(int level, tcu::CubeFace face, const tcu::TextureFormat &format, int width, int height);
307
308 bool isComplete(void) const;
309 void updateView(
310 tcu::Sampler::DepthStencilMode
311 mode); // \note View must be refreshed after texture parameter/size changes, before calling sample*()
312
313 tcu::Vec4 sample(float s, float t, float p, float lod) const;
314 void sample4(tcu::Vec4 output[4], const tcu::Vec3 packetTexcoords[4], float lodBias = 0.0f) const;
315
316 private:
317 TextureLevelArray m_levels[tcu::CUBEFACE_LAST];
318 tcu::TextureCubeView m_view;
319 };
320
321 class Texture2DArray : public Texture
322 {
323 public:
324 Texture2DArray(uint32_t name = 0);
325 virtual ~Texture2DArray(void);
326
clearLevels(void)327 void clearLevels(void)
328 {
329 m_levels.clear();
330 }
331
hasLevel(int level) const332 bool hasLevel(int level) const
333 {
334 return m_levels.hasLevel(level);
335 }
getLevel(int level) const336 const tcu::ConstPixelBufferAccess &getLevel(int level) const
337 {
338 return m_levels.getLevel(level);
339 }
getLevel(int level)340 const tcu::PixelBufferAccess &getLevel(int level)
341 {
342 return m_levels.getLevel(level);
343 }
344
345 void allocLevel(int level, const tcu::TextureFormat &format, int width, int height, int numLayers);
346
347 bool isComplete(void) const;
348
349 void updateView(
350 tcu::Sampler::DepthStencilMode
351 mode); // \note View must be refreshed after texture parameter/size changes, before calling sample*()
352
353 tcu::Vec4 sample(float s, float t, float r, float lod) const;
354 void sample4(tcu::Vec4 output[4], const tcu::Vec3 packetTexcoords[4], float lodBias = 0.0f) const;
355
356 private:
357 TextureLevelArray m_levels;
358 tcu::Texture2DArrayView m_view;
359 };
360
361 class Texture3D : public Texture
362 {
363 public:
364 Texture3D(uint32_t name = 0);
365 virtual ~Texture3D(void);
366
clearLevels(void)367 void clearLevels(void)
368 {
369 m_levels.clear();
370 }
371
hasLevel(int level) const372 bool hasLevel(int level) const
373 {
374 return m_levels.hasLevel(level);
375 }
getLevel(int level) const376 const tcu::ConstPixelBufferAccess &getLevel(int level) const
377 {
378 return m_levels.getLevel(level);
379 }
getLevel(int level)380 const tcu::PixelBufferAccess &getLevel(int level)
381 {
382 return m_levels.getLevel(level);
383 }
384
385 void allocLevel(int level, const tcu::TextureFormat &format, int width, int height, int numLayers);
386
387 bool isComplete(void) const;
388
389 void updateView(
390 tcu::Sampler::DepthStencilMode
391 mode); // \note View must be refreshed after texture parameter/size changes, before calling sample*()
392
393 tcu::Vec4 sample(float s, float t, float r, float lod) const;
394 void sample4(tcu::Vec4 output[4], const tcu::Vec3 packetTexcoords[4], float lodBias = 0.0f) const;
395
396 private:
397 TextureLevelArray m_levels;
398 tcu::Texture3DView m_view;
399 };
400
401 class TextureCubeArray : public Texture
402 {
403 public:
404 TextureCubeArray(uint32_t name = 0);
405 virtual ~TextureCubeArray(void);
406
clearLevels(void)407 void clearLevels(void)
408 {
409 m_levels.clear();
410 }
411
hasLevel(int level) const412 bool hasLevel(int level) const
413 {
414 return m_levels.hasLevel(level);
415 }
getLevel(int level) const416 const tcu::ConstPixelBufferAccess &getLevel(int level) const
417 {
418 return m_levels.getLevel(level);
419 }
getLevel(int level)420 const tcu::PixelBufferAccess &getLevel(int level)
421 {
422 return m_levels.getLevel(level);
423 }
424
425 void allocLevel(int level, const tcu::TextureFormat &format, int width, int height, int numLayers);
426
427 bool isComplete(void) const;
428
429 void updateView(
430 tcu::Sampler::DepthStencilMode
431 mode); // \note View must be refreshed after texture parameter/size changes, before calling sample*()
432
433 tcu::Vec4 sample(float s, float t, float r, float q, float lod) const;
434 void sample4(tcu::Vec4 output[4], const tcu::Vec4 packetTexcoords[4], float lodBias = 0.0f) const;
435
436 private:
437 TextureLevelArray m_levels;
438 tcu::TextureCubeArrayView m_view;
439 };
440
441 class Renderbuffer : public NamedObject
442 {
443 public:
444 enum Format
445 {
446 FORMAT_DEPTH_COMPONENT16,
447 FORMAT_RGBA4,
448 FORMAT_RGB5_A1,
449 FORMAT_RGB565,
450 FORMAT_STENCIL_INDEX8,
451
452 FORMAT_LAST
453 };
454
455 Renderbuffer(uint32_t name);
456 virtual ~Renderbuffer(void);
457
458 void setStorage(const tcu::TextureFormat &format, int width, int height);
459
getWidth(void) const460 int getWidth(void) const
461 {
462 return m_data.getWidth();
463 }
getHeight(void) const464 int getHeight(void) const
465 {
466 return m_data.getHeight();
467 }
getFormat(void) const468 tcu::TextureFormat getFormat(void) const
469 {
470 return m_data.getFormat();
471 }
472
getAccess(void)473 tcu::PixelBufferAccess getAccess(void)
474 {
475 return m_data.getAccess();
476 }
getAccess(void) const477 tcu::ConstPixelBufferAccess getAccess(void) const
478 {
479 return m_data.getAccess();
480 }
481
482 private:
483 tcu::TextureLevel m_data;
484 };
485
486 class Framebuffer : public NamedObject
487 {
488 public:
489 enum AttachmentPoint
490 {
491 ATTACHMENTPOINT_COLOR0,
492 ATTACHMENTPOINT_DEPTH,
493 ATTACHMENTPOINT_STENCIL,
494
495 ATTACHMENTPOINT_LAST
496 };
497
498 enum AttachmentType
499 {
500 ATTACHMENTTYPE_RENDERBUFFER,
501 ATTACHMENTTYPE_TEXTURE,
502
503 ATTACHMENTTYPE_LAST
504 };
505
506 enum TexTarget
507 {
508 TEXTARGET_2D,
509 TEXTARGET_CUBE_MAP_POSITIVE_X,
510 TEXTARGET_CUBE_MAP_POSITIVE_Y,
511 TEXTARGET_CUBE_MAP_POSITIVE_Z,
512 TEXTARGET_CUBE_MAP_NEGATIVE_X,
513 TEXTARGET_CUBE_MAP_NEGATIVE_Y,
514 TEXTARGET_CUBE_MAP_NEGATIVE_Z,
515 TEXTARGET_2D_ARRAY,
516 TEXTARGET_3D,
517 TEXTARGET_CUBE_MAP_ARRAY,
518
519 TEXTARGET_LAST
520 };
521
522 struct Attachment
523 {
524 AttachmentType type;
525 uint32_t name;
526 TexTarget texTarget;
527 int level;
528 int layer;
529
Attachmentsglr::rc::Framebuffer::Attachment530 Attachment(void) : type(ATTACHMENTTYPE_LAST), name(0), texTarget(TEXTARGET_LAST), level(0), layer(0)
531 {
532 }
533 };
534
535 Framebuffer(uint32_t name);
536 virtual ~Framebuffer(void);
537
getAttachment(AttachmentPoint point)538 Attachment &getAttachment(AttachmentPoint point)
539 {
540 return m_attachments[point];
541 }
getAttachment(AttachmentPoint point) const542 const Attachment &getAttachment(AttachmentPoint point) const
543 {
544 return m_attachments[point];
545 }
546
547 private:
548 Attachment m_attachments[ATTACHMENTPOINT_LAST];
549 };
550
551 class DataBuffer : public NamedObject
552 {
553 public:
DataBuffer(uint32_t name)554 DataBuffer(uint32_t name) : NamedObject(name)
555 {
556 }
~DataBuffer(void)557 ~DataBuffer(void)
558 {
559 }
560
setStorage(int size)561 void setStorage(int size)
562 {
563 m_data.resize(size);
564 }
565
getSize(void) const566 int getSize(void) const
567 {
568 return (int)m_data.size();
569 }
getData(void) const570 const uint8_t *getData(void) const
571 {
572 return m_data.empty() ? DE_NULL : &m_data[0];
573 }
getData(void)574 uint8_t *getData(void)
575 {
576 return m_data.empty() ? DE_NULL : &m_data[0];
577 }
578
579 private:
580 std::vector<uint8_t> m_data;
581 };
582
583 class VertexArray : public NamedObject
584 {
585 public:
586 struct VertexAttribArray
587 {
588 bool enabled;
589 int size;
590 int stride;
591 uint32_t type;
592
593 bool normalized;
594 bool integer;
595 int divisor;
596
597 /**
598 ! These three variables define the state. bufferDeleted is needed to distinguish
599 ! drawing from user pointer and offset to a deleted buffer from each other.
600 !
601 ! Only these three combinations are possible:
602 ! 1) bufferDeleted = false, bufferBinding = NULL, pointer = user_ptr. < render from a user ptr
603 ! 2) bufferDeleted = false, bufferBinding = ptr, pointer = offset. < render from a buffer with offset
604 ! 3) bufferDeleted = true, bufferBinding = NULL, pointer = offset < render from a deleted buffer. Don't do anything
605 !
606 ! (bufferFreed = true) implies (bufferBinding = NULL)
607 */
608 bool bufferDeleted;
609 rc::DataBuffer *bufferBinding;
610 const void *pointer;
611 };
612
613 VertexArray(uint32_t name, int maxVertexAttribs);
~VertexArray(void)614 ~VertexArray(void)
615 {
616 }
617
618 rc::DataBuffer *m_elementArrayBufferBinding;
619 std::vector<VertexAttribArray> m_arrays;
620 };
621
622 class ShaderProgramObjectContainer : public NamedObject
623 {
624 public:
625 ShaderProgramObjectContainer(uint32_t name, ShaderProgram *program);
626 ~ShaderProgramObjectContainer(void);
627
628 ShaderProgram *m_program;
629 bool m_deleteFlag;
630 };
631
632 template <typename T>
633 class ObjectManager
634 {
635 public:
636 ObjectManager(void);
637 ~ObjectManager(void);
638
639 uint32_t allocateName(void);
640 void insert(T *object);
641 T *find(uint32_t name);
642
643 void acquireReference(T *object);
644 void releaseReference(T *object);
645
getCount(void) const646 int getCount(void) const
647 {
648 return (int)m_objects.size();
649 }
650 void getAll(typename std::vector<T *> &objects) const;
651
652 private:
653 ObjectManager(const ObjectManager<T> &other);
654 ObjectManager &operator=(const ObjectManager<T> &other);
655
656 uint32_t m_lastName;
657 std::map<uint32_t, T *> m_objects;
658 };
659
660 template <typename T>
ObjectManager(void)661 ObjectManager<T>::ObjectManager(void) : m_lastName(0)
662 {
663 }
664
665 template <typename T>
~ObjectManager(void)666 ObjectManager<T>::~ObjectManager(void)
667 {
668 DE_ASSERT(m_objects.size() == 0);
669 }
670
671 template <typename T>
allocateName(void)672 uint32_t ObjectManager<T>::allocateName(void)
673 {
674 TCU_CHECK(m_lastName != 0xffffffff);
675 return ++m_lastName;
676 }
677
678 template <typename T>
insert(T * object)679 void ObjectManager<T>::insert(T *object)
680 {
681 uint32_t name = object->getName();
682 DE_ASSERT(object->getName() != 0);
683
684 if (name > m_lastName)
685 m_lastName = name;
686
687 m_objects.insert(std::pair<uint32_t, T *>(name, object));
688 }
689
690 template <typename T>
find(uint32_t name)691 T *ObjectManager<T>::find(uint32_t name)
692 {
693 typename std::map<uint32_t, T *>::iterator it = m_objects.find(name);
694 if (it != m_objects.end())
695 return it->second;
696 else
697 return DE_NULL;
698 }
699
700 template <typename T>
acquireReference(T * object)701 void ObjectManager<T>::acquireReference(T *object)
702 {
703 DE_ASSERT(find(object->getName()) == object);
704 object->incRefCount();
705 }
706
707 template <typename T>
releaseReference(T * object)708 void ObjectManager<T>::releaseReference(T *object)
709 {
710 DE_ASSERT(find(object->getName()) == object);
711 object->decRefCount();
712
713 if (object->getRefCount() == 0)
714 {
715 m_objects.erase(object->getName());
716 delete object;
717 }
718 }
719
720 template <typename T>
getAll(typename std::vector<T * > & objects) const721 void ObjectManager<T>::getAll(typename std::vector<T *> &objects) const
722 {
723 objects.resize(m_objects.size());
724 typename std::vector<T *>::iterator dst = objects.begin();
725
726 for (typename std::map<uint32_t, T *>::const_iterator i = m_objects.begin(); i != m_objects.end(); i++)
727 {
728 *dst++ = i->second;
729 }
730 }
731
732 } // namespace rc
733
734 struct ReferenceContextLimits
735 {
ReferenceContextLimitssglr::ReferenceContextLimits736 ReferenceContextLimits(void)
737 : contextType(glu::ApiType::es(3, 0))
738 , maxTextureImageUnits(16)
739 , maxTexture2DSize(2048)
740 , maxTextureCubeSize(2048)
741 , maxTexture2DArrayLayers(256)
742 , maxTexture3DSize(256)
743 , maxRenderbufferSize(2048)
744 , maxVertexAttribs(16)
745 , subpixelBits(rr::RenderState::DEFAULT_SUBPIXEL_BITS)
746 {
747 }
748
749 ReferenceContextLimits(const glu::RenderContext &renderCtx);
750
751 void addExtension(const char *extension);
752
753 glu::ContextType contextType;
754
755 int maxTextureImageUnits;
756 int maxTexture2DSize;
757 int maxTextureCubeSize;
758 int maxTexture2DArrayLayers;
759 int maxTexture3DSize;
760 int maxRenderbufferSize;
761 int maxVertexAttribs;
762 int subpixelBits;
763
764 // Both variants are needed since there are glGetString() and glGetStringi()
765 std::vector<std::string> extensionList;
766 std::string extensionStr;
767 };
768
769 class ReferenceContextBuffers
770 {
771 public:
772 ReferenceContextBuffers(const tcu::PixelFormat &colorBits, int depthBits, int stencilBits, int width, int height,
773 int samples = 1);
774
getColorbuffer(void)775 rr::MultisamplePixelBufferAccess getColorbuffer(void)
776 {
777 return rr::MultisamplePixelBufferAccess::fromMultisampleAccess(m_colorbuffer.getAccess());
778 }
getDepthbuffer(void)779 rr::MultisamplePixelBufferAccess getDepthbuffer(void)
780 {
781 return rr::MultisamplePixelBufferAccess::fromMultisampleAccess(m_depthbuffer.getAccess());
782 }
getStencilbuffer(void)783 rr::MultisamplePixelBufferAccess getStencilbuffer(void)
784 {
785 return rr::MultisamplePixelBufferAccess::fromMultisampleAccess(m_stencilbuffer.getAccess());
786 }
787
788 private:
789 tcu::TextureLevel m_colorbuffer;
790 tcu::TextureLevel m_depthbuffer;
791 tcu::TextureLevel m_stencilbuffer;
792 };
793
794 class ReferenceContext : public Context
795 {
796 public:
797 ReferenceContext(const ReferenceContextLimits &limits, const rr::MultisamplePixelBufferAccess &colorbuffer,
798 const rr::MultisamplePixelBufferAccess &depthbuffer,
799 const rr::MultisamplePixelBufferAccess &stencilbuffer);
800 virtual ~ReferenceContext(void);
801
getWidth(void) const802 virtual int getWidth(void) const
803 {
804 return m_defaultColorbuffer.raw().getHeight();
805 }
getHeight(void) const806 virtual int getHeight(void) const
807 {
808 return m_defaultColorbuffer.raw().getDepth();
809 }
810
viewport(int x,int y,int width,int height)811 virtual void viewport(int x, int y, int width, int height)
812 {
813 m_viewport = tcu::IVec4(x, y, width, height);
814 }
815 virtual void activeTexture(uint32_t texture);
816
817 virtual void bindTexture(uint32_t target, uint32_t texture);
818 virtual void genTextures(int numTextures, uint32_t *textures);
819 virtual void deleteTextures(int numTextures, const uint32_t *textures);
820
821 virtual void bindFramebuffer(uint32_t target, uint32_t framebuffer);
822 virtual void genFramebuffers(int numFramebuffers, uint32_t *framebuffers);
823 virtual void deleteFramebuffers(int numFramebuffers, const uint32_t *framebuffers);
824
825 virtual void bindRenderbuffer(uint32_t target, uint32_t renderbuffer);
826 virtual void genRenderbuffers(int numRenderbuffers, uint32_t *renderbuffers);
827 virtual void deleteRenderbuffers(int numRenderbuffers, const uint32_t *renderbuffers);
828
829 virtual void pixelStorei(uint32_t pname, int param);
830 virtual void texImage1D(uint32_t target, int level, uint32_t internalFormat, int width, int border, uint32_t format,
831 uint32_t type, const void *data);
832 virtual void texImage2D(uint32_t target, int level, uint32_t internalFormat, int width, int height, int border,
833 uint32_t format, uint32_t type, const void *data);
834 virtual void texImage3D(uint32_t target, int level, uint32_t internalFormat, int width, int height, int depth,
835 int border, uint32_t format, uint32_t type, const void *data);
836 virtual void texSubImage1D(uint32_t target, int level, int xoffset, int width, uint32_t format, uint32_t type,
837 const void *data);
838 virtual void texSubImage2D(uint32_t target, int level, int xoffset, int yoffset, int width, int height,
839 uint32_t format, uint32_t type, const void *data);
840 virtual void texSubImage3D(uint32_t target, int level, int xoffset, int yoffset, int zoffset, int width, int height,
841 int depth, uint32_t format, uint32_t type, const void *data);
842 virtual void copyTexImage1D(uint32_t target, int level, uint32_t internalFormat, int x, int y, int width,
843 int border);
844 virtual void copyTexImage2D(uint32_t target, int level, uint32_t internalFormat, int x, int y, int width,
845 int height, int border);
846 virtual void copyTexSubImage1D(uint32_t target, int level, int xoffset, int x, int y, int width);
847 virtual void copyTexSubImage2D(uint32_t target, int level, int xoffset, int yoffset, int x, int y, int width,
848 int height);
849 virtual void copyTexSubImage3D(uint32_t target, int level, int xoffset, int yoffset, int zoffset, int x, int y,
850 int width, int height);
851
852 virtual void texStorage2D(uint32_t target, int levels, uint32_t internalFormat, int width, int height);
853 virtual void texStorage3D(uint32_t target, int levels, uint32_t internalFormat, int width, int height, int depth);
854
855 virtual void texParameteri(uint32_t target, uint32_t pname, int value);
856
857 virtual void framebufferTexture2D(uint32_t target, uint32_t attachment, uint32_t textarget, uint32_t texture,
858 int level);
859 virtual void framebufferTextureLayer(uint32_t target, uint32_t attachment, uint32_t texture, int level, int layer);
860 virtual void framebufferRenderbuffer(uint32_t target, uint32_t attachment, uint32_t renderbuffertarget,
861 uint32_t renderbuffer);
862 virtual uint32_t checkFramebufferStatus(uint32_t target);
863
864 virtual void getFramebufferAttachmentParameteriv(uint32_t target, uint32_t attachment, uint32_t pname, int *params);
865
866 virtual void renderbufferStorage(uint32_t target, uint32_t internalformat, int width, int height);
867 virtual void renderbufferStorageMultisample(uint32_t target, int samples, uint32_t internalFormat, int width,
868 int height);
869
870 virtual void bindBuffer(uint32_t target, uint32_t buffer);
871 virtual void genBuffers(int numBuffers, uint32_t *buffers);
872 virtual void deleteBuffers(int numBuffers, const uint32_t *buffers);
873
874 virtual void bufferData(uint32_t target, intptr_t size, const void *data, uint32_t usage);
875 virtual void bufferSubData(uint32_t target, intptr_t offset, intptr_t size, const void *data);
876
877 virtual void clearColor(float red, float green, float blue, float alpha);
878 virtual void clearDepthf(float depth);
879 virtual void clearStencil(int stencil);
880
881 virtual void clear(uint32_t buffers);
882 virtual void clearBufferiv(uint32_t buffer, int drawbuffer, const int *value);
883 virtual void clearBufferfv(uint32_t buffer, int drawbuffer, const float *value);
884 virtual void clearBufferuiv(uint32_t buffer, int drawbuffer, const uint32_t *value);
885 virtual void clearBufferfi(uint32_t buffer, int drawbuffer, float depth, int stencil);
886 virtual void scissor(int x, int y, int width, int height);
887
888 virtual void enable(uint32_t cap);
889 virtual void disable(uint32_t cap);
890
891 virtual void stencilFunc(uint32_t func, int ref, uint32_t mask);
892 virtual void stencilOp(uint32_t sfail, uint32_t dpfail, uint32_t dppass);
893 virtual void stencilFuncSeparate(uint32_t face, uint32_t func, int ref, uint32_t mask);
894 virtual void stencilOpSeparate(uint32_t face, uint32_t sfail, uint32_t dpfail, uint32_t dppass);
895
896 virtual void depthFunc(uint32_t func);
897 virtual void depthRangef(float n, float f);
898 virtual void depthRange(double n, double f);
899
900 virtual void polygonOffset(float factor, float units);
901 virtual void provokingVertex(uint32_t convention);
902 virtual void primitiveRestartIndex(uint32_t index);
903
904 virtual void blendEquation(uint32_t mode);
905 virtual void blendEquationSeparate(uint32_t modeRGB, uint32_t modeAlpha);
906 virtual void blendFunc(uint32_t src, uint32_t dst);
907 virtual void blendFuncSeparate(uint32_t srcRGB, uint32_t dstRGB, uint32_t srcAlpha, uint32_t dstAlpha);
908 virtual void blendColor(float red, float green, float blue, float alpha);
909
910 virtual void colorMask(bool r, bool g, bool b, bool a);
911 virtual void depthMask(bool mask);
912 virtual void stencilMask(uint32_t mask);
913 virtual void stencilMaskSeparate(uint32_t face, uint32_t mask);
914
915 virtual void blitFramebuffer(int srcX0, int srcY0, int srcX1, int srcY1, int dstX0, int dstY0, int dstX1, int dstY1,
916 uint32_t mask, uint32_t filter);
917
918 virtual void invalidateSubFramebuffer(uint32_t target, int numAttachments, const uint32_t *attachments, int x,
919 int y, int width, int height);
920 virtual void invalidateFramebuffer(uint32_t target, int numAttachments, const uint32_t *attachments);
921
922 virtual void bindVertexArray(uint32_t array);
923 virtual void genVertexArrays(int numArrays, uint32_t *vertexArrays);
924 virtual void deleteVertexArrays(int numArrays, const uint32_t *vertexArrays);
925
926 virtual void vertexAttribPointer(uint32_t index, int size, uint32_t type, bool normalized, int stride,
927 const void *pointer);
928 virtual void vertexAttribIPointer(uint32_t index, int size, uint32_t type, int stride, const void *pointer);
929 virtual void enableVertexAttribArray(uint32_t index);
930 virtual void disableVertexAttribArray(uint32_t index);
931 virtual void vertexAttribDivisor(uint32_t index, uint32_t divisor);
932
933 virtual void vertexAttrib1f(uint32_t index, float);
934 virtual void vertexAttrib2f(uint32_t index, float, float);
935 virtual void vertexAttrib3f(uint32_t index, float, float, float);
936 virtual void vertexAttrib4f(uint32_t index, float, float, float, float);
937 virtual void vertexAttribI4i(uint32_t index, int32_t, int32_t, int32_t, int32_t);
938 virtual void vertexAttribI4ui(uint32_t index, uint32_t, uint32_t, uint32_t, uint32_t);
939
940 virtual int32_t getAttribLocation(uint32_t program, const char *name);
941
942 virtual void uniform1f(int32_t location, float);
943 virtual void uniform1i(int32_t location, int32_t);
944 virtual void uniform1fv(int32_t index, int32_t count, const float *);
945 virtual void uniform2fv(int32_t index, int32_t count, const float *);
946 virtual void uniform3fv(int32_t index, int32_t count, const float *);
947 virtual void uniform4fv(int32_t index, int32_t count, const float *);
948 virtual void uniform1iv(int32_t index, int32_t count, const int32_t *);
949 virtual void uniform2iv(int32_t index, int32_t count, const int32_t *);
950 virtual void uniform3iv(int32_t index, int32_t count, const int32_t *);
951 virtual void uniform4iv(int32_t index, int32_t count, const int32_t *);
952 virtual void uniformMatrix3fv(int32_t location, int32_t count, bool transpose, const float *value);
953 virtual void uniformMatrix4fv(int32_t location, int32_t count, bool transpose, const float *value);
954 virtual int32_t getUniformLocation(uint32_t program, const char *name);
955
956 virtual void lineWidth(float);
957
958 virtual void drawArrays(uint32_t mode, int first, int count);
959 virtual void drawArraysInstanced(uint32_t mode, int first, int count, int instanceCount);
960 virtual void drawElements(uint32_t mode, int count, uint32_t type, const void *indices);
961 virtual void drawElementsBaseVertex(uint32_t mode, int count, uint32_t type, const void *indices, int baseVertex);
962 virtual void drawElementsInstanced(uint32_t mode, int count, uint32_t type, const void *indices, int instanceCount);
963 virtual void drawElementsInstancedBaseVertex(uint32_t mode, int count, uint32_t type, const void *indices,
964 int instanceCount, int baseVertex);
965 virtual void drawRangeElements(uint32_t mode, uint32_t start, uint32_t end, int count, uint32_t type,
966 const void *indices);
967 virtual void drawRangeElementsBaseVertex(uint32_t mode, uint32_t start, uint32_t end, int count, uint32_t type,
968 const void *indices, int baseVertex);
969 virtual void drawArraysIndirect(uint32_t mode, const void *indirect);
970 virtual void drawElementsIndirect(uint32_t mode, uint32_t type, const void *indirect);
971
972 virtual void multiDrawArrays(uint32_t mode, const int *first, const int *count, int primCount);
973 virtual void multiDrawElements(uint32_t mode, const int *count, uint32_t type, const void **indices, int primCount);
974 virtual void multiDrawElementsBaseVertex(uint32_t mode, const int *count, uint32_t type, const void **indices,
975 int primCount, const int *baseVertex);
976
977 virtual uint32_t createProgram(ShaderProgram *program);
978 virtual void useProgram(uint32_t program);
979 virtual void deleteProgram(uint32_t program);
980
981 virtual void readPixels(int x, int y, int width, int height, uint32_t format, uint32_t type, void *data);
982 virtual uint32_t getError(void);
983 virtual void finish(void);
984
985 virtual void getIntegerv(uint32_t pname, int *params);
986 virtual const char *getString(uint32_t pname);
987
988 // Expose helpers from Context.
989 using Context::readPixels;
990 using Context::texImage2D;
991 using Context::texSubImage2D;
992
993 private:
994 ReferenceContext(const ReferenceContext &other); // Not allowed!
995 ReferenceContext &operator=(const ReferenceContext &other); // Not allowed!
996
997 void deleteTexture(rc::Texture *texture);
998 void deleteFramebuffer(rc::Framebuffer *framebuffer);
999 void deleteRenderbuffer(rc::Renderbuffer *renderbuffer);
1000 void deleteBuffer(rc::DataBuffer *buffer);
1001 void deleteVertexArray(rc::VertexArray *vertexArray);
1002 void deleteProgramObject(rc::ShaderProgramObjectContainer *sp);
1003
1004 void acquireFboAttachmentReference(const rc::Framebuffer::Attachment &attachment);
1005 void releaseFboAttachmentReference(const rc::Framebuffer::Attachment &attachment);
1006 tcu::PixelBufferAccess getFboAttachment(const rc::Framebuffer &framebuffer, rc::Framebuffer::AttachmentPoint point);
1007
1008 uint32_t blitResolveMultisampleFramebuffer(uint32_t mask, const tcu::IVec4 &srcRect, const tcu::IVec4 &dstRect,
1009 bool flipX, bool flipY);
1010
getDrawColorbuffer(void)1011 rr::MultisamplePixelBufferAccess getDrawColorbuffer(void)
1012 {
1013 return (m_drawFramebufferBinding) ? (rr::MultisamplePixelBufferAccess::fromSinglesampleAccess(getFboAttachment(
1014 *m_drawFramebufferBinding, rc::Framebuffer::ATTACHMENTPOINT_COLOR0))) :
1015 (m_defaultColorbuffer);
1016 }
getDrawDepthbuffer(void)1017 rr::MultisamplePixelBufferAccess getDrawDepthbuffer(void)
1018 {
1019 return (m_drawFramebufferBinding) ? (rr::MultisamplePixelBufferAccess::fromSinglesampleAccess(getFboAttachment(
1020 *m_drawFramebufferBinding, rc::Framebuffer::ATTACHMENTPOINT_DEPTH))) :
1021 (m_defaultDepthbuffer);
1022 }
getDrawStencilbuffer(void)1023 rr::MultisamplePixelBufferAccess getDrawStencilbuffer(void)
1024 {
1025 return (m_drawFramebufferBinding) ? (rr::MultisamplePixelBufferAccess::fromSinglesampleAccess(getFboAttachment(
1026 *m_drawFramebufferBinding, rc::Framebuffer::ATTACHMENTPOINT_STENCIL))) :
1027 (m_defaultStencilbuffer);
1028 }
getReadColorbuffer(void)1029 rr::MultisamplePixelBufferAccess getReadColorbuffer(void)
1030 {
1031 return (m_readFramebufferBinding) ? (rr::MultisamplePixelBufferAccess::fromSinglesampleAccess(getFboAttachment(
1032 *m_readFramebufferBinding, rc::Framebuffer::ATTACHMENTPOINT_COLOR0))) :
1033 (m_defaultColorbuffer);
1034 }
getReadDepthbuffer(void)1035 rr::MultisamplePixelBufferAccess getReadDepthbuffer(void)
1036 {
1037 return (m_readFramebufferBinding) ? (rr::MultisamplePixelBufferAccess::fromSinglesampleAccess(getFboAttachment(
1038 *m_readFramebufferBinding, rc::Framebuffer::ATTACHMENTPOINT_DEPTH))) :
1039 (m_defaultDepthbuffer);
1040 }
getReadStencilbuffer(void)1041 rr::MultisamplePixelBufferAccess getReadStencilbuffer(void)
1042 {
1043 return (m_readFramebufferBinding) ? (rr::MultisamplePixelBufferAccess::fromSinglesampleAccess(getFboAttachment(
1044 *m_readFramebufferBinding, rc::Framebuffer::ATTACHMENTPOINT_STENCIL))) :
1045 (m_defaultStencilbuffer);
1046 }
1047
1048 const rc::Texture2D &getTexture2D(int unitNdx) const;
1049 const rc::TextureCube &getTextureCube(int unitNdx) const;
getViewport(void) const1050 const tcu::IVec4 &getViewport(void) const
1051 {
1052 return m_viewport;
1053 }
1054
1055 void setError(uint32_t error);
1056
1057 void setTex1DBinding(int unit, rc::Texture1D *tex1D);
1058 void setTex2DBinding(int unit, rc::Texture2D *tex2D);
1059 void setTexCubeBinding(int unit, rc::TextureCube *texCube);
1060 void setTex2DArrayBinding(int unit, rc::Texture2DArray *tex2DArray);
1061 void setTex3DBinding(int unit, rc::Texture3D *tex3D);
1062 void setTexCubeArrayBinding(int unit, rc::TextureCubeArray *texCubeArray);
1063
1064 void setBufferBinding(uint32_t target, rc::DataBuffer *buffer);
1065 rc::DataBuffer *getBufferBinding(uint32_t target) const;
1066
getPixelPackPtr(void * ptrOffset) const1067 void *getPixelPackPtr(void *ptrOffset) const
1068 {
1069 return m_pixelPackBufferBinding ?
1070 (void *)((uintptr_t)m_pixelPackBufferBinding->getData() + (uintptr_t)ptrOffset) :
1071 ptrOffset;
1072 }
getPixelUnpackPtr(const void * ptrOffset) const1073 const void *getPixelUnpackPtr(const void *ptrOffset) const
1074 {
1075 return m_pixelUnpackBufferBinding ?
1076 (const void *)((uintptr_t)m_pixelUnpackBufferBinding->getData() + (uintptr_t)ptrOffset) :
1077 ptrOffset;
1078 }
1079
1080 bool predrawErrorChecks(uint32_t mode);
1081 void drawWithReference(const rr::PrimitiveList &primitives, int instanceCount);
1082
1083 // Helpers for getting valid access object based on current unpack state.
1084 tcu::ConstPixelBufferAccess getUnpack2DAccess(const tcu::TextureFormat &format, int width, int height,
1085 const void *data);
1086 tcu::ConstPixelBufferAccess getUnpack3DAccess(const tcu::TextureFormat &format, int width, int height, int depth,
1087 const void *data);
1088
1089 void uniformv(int32_t index, glu::DataType type, int32_t count, const void *);
1090
1091 struct TextureUnit
1092 {
1093
1094 rc::Texture1D *tex1DBinding;
1095 rc::Texture2D *tex2DBinding;
1096 rc::TextureCube *texCubeBinding;
1097 rc::Texture2DArray *tex2DArrayBinding;
1098 rc::Texture3D *tex3DBinding;
1099 rc::TextureCubeArray *texCubeArrayBinding;
1100
1101 rc::Texture1D default1DTex;
1102 rc::Texture2D default2DTex;
1103 rc::TextureCube defaultCubeTex;
1104 rc::Texture2DArray default2DArrayTex;
1105 rc::Texture3D default3DTex;
1106 rc::TextureCubeArray defaultCubeArrayTex;
1107
TextureUnitsglr::ReferenceContext::TextureUnit1108 TextureUnit(void)
1109 : tex1DBinding(DE_NULL)
1110 , tex2DBinding(DE_NULL)
1111 , texCubeBinding(DE_NULL)
1112 , tex2DArrayBinding(DE_NULL)
1113 , tex3DBinding(DE_NULL)
1114 , texCubeArrayBinding(DE_NULL)
1115 , default1DTex(0)
1116 , default2DTex(0)
1117 , defaultCubeTex(0)
1118 , default2DArrayTex(0)
1119 , default3DTex(0)
1120 , defaultCubeArrayTex(0)
1121 {
1122 }
1123 };
1124
1125 struct StencilState
1126 {
1127 uint32_t func;
1128 int ref;
1129 uint32_t opMask;
1130 uint32_t opStencilFail;
1131 uint32_t opDepthFail;
1132 uint32_t opDepthPass;
1133 uint32_t writeMask;
1134
1135 StencilState(void);
1136 };
1137
1138 ReferenceContextLimits m_limits;
1139
1140 rr::MultisamplePixelBufferAccess m_defaultColorbuffer;
1141 rr::MultisamplePixelBufferAccess m_defaultDepthbuffer;
1142 rr::MultisamplePixelBufferAccess m_defaultStencilbuffer;
1143 rc::VertexArray m_clientVertexArray;
1144
1145 tcu::IVec4 m_viewport;
1146
1147 rc::ObjectManager<rc::Texture> m_textures;
1148 rc::ObjectManager<rc::Framebuffer> m_framebuffers;
1149 rc::ObjectManager<rc::Renderbuffer> m_renderbuffers;
1150 rc::ObjectManager<rc::DataBuffer> m_buffers;
1151 rc::ObjectManager<rc::VertexArray> m_vertexArrays;
1152 rc::ObjectManager<rc::ShaderProgramObjectContainer> m_programs;
1153
1154 int m_activeTexture;
1155 std::vector<TextureUnit> m_textureUnits;
1156 rc::Texture1D m_emptyTex1D;
1157 rc::Texture2D m_emptyTex2D;
1158 rc::TextureCube m_emptyTexCube;
1159 rc::Texture2DArray m_emptyTex2DArray;
1160 rc::Texture3D m_emptyTex3D;
1161 rc::TextureCubeArray m_emptyTexCubeArray;
1162
1163 int m_pixelUnpackRowLength;
1164 int m_pixelUnpackSkipRows;
1165 int m_pixelUnpackSkipPixels;
1166 int m_pixelUnpackImageHeight;
1167 int m_pixelUnpackSkipImages;
1168 int m_pixelUnpackAlignment;
1169 int m_pixelPackAlignment;
1170
1171 rc::Framebuffer *m_readFramebufferBinding;
1172 rc::Framebuffer *m_drawFramebufferBinding;
1173 rc::Renderbuffer *m_renderbufferBinding;
1174 rc::VertexArray *m_vertexArrayBinding;
1175 rc::ShaderProgramObjectContainer *m_currentProgram;
1176
1177 rc::DataBuffer *m_arrayBufferBinding;
1178 rc::DataBuffer *m_pixelPackBufferBinding;
1179 rc::DataBuffer *m_pixelUnpackBufferBinding;
1180 rc::DataBuffer *m_transformFeedbackBufferBinding;
1181 rc::DataBuffer *m_uniformBufferBinding;
1182 rc::DataBuffer *m_copyReadBufferBinding;
1183 rc::DataBuffer *m_copyWriteBufferBinding;
1184 rc::DataBuffer *m_drawIndirectBufferBinding;
1185
1186 tcu::Vec4 m_clearColor;
1187 float m_clearDepth;
1188 int m_clearStencil;
1189
1190 bool m_scissorEnabled;
1191 tcu::IVec4 m_scissorBox;
1192
1193 bool m_stencilTestEnabled;
1194 StencilState m_stencil[rr::FACETYPE_LAST];
1195
1196 bool m_depthTestEnabled;
1197 uint32_t m_depthFunc;
1198 float m_depthRangeNear;
1199 float m_depthRangeFar;
1200
1201 float m_polygonOffsetFactor;
1202 float m_polygonOffsetUnits;
1203 bool m_polygonOffsetFillEnabled;
1204
1205 bool m_provokingFirstVertexConvention;
1206
1207 bool m_blendEnabled;
1208 uint32_t m_blendModeRGB;
1209 uint32_t m_blendModeAlpha;
1210 uint32_t m_blendFactorSrcRGB;
1211 uint32_t m_blendFactorDstRGB;
1212 uint32_t m_blendFactorSrcAlpha;
1213 uint32_t m_blendFactorDstAlpha;
1214 tcu::Vec4 m_blendColor;
1215
1216 bool m_sRGBUpdateEnabled;
1217
1218 bool m_depthClampEnabled;
1219
1220 tcu::BVec4 m_colorMask;
1221 bool m_depthMask;
1222
1223 std::vector<rr::GenericVec4> m_currentAttribs;
1224 float m_lineWidth;
1225
1226 bool m_primitiveRestartFixedIndex;
1227 bool m_primitiveRestartSettableIndex;
1228 uint32_t m_primitiveRestartIndex;
1229
1230 uint32_t m_lastError;
1231
1232 rr::FragmentProcessor m_fragmentProcessor;
1233 std::vector<rr::Fragment> m_fragmentBuffer;
1234 std::vector<float> m_fragmentDepths;
1235 } DE_WARN_UNUSED_TYPE;
1236
1237 } // namespace sglr
1238
1239 #endif // _SGLRREFERENCECONTEXT_HPP
1240