xref: /aosp_15_r20/external/deqp/modules/glshared/glsLifetimeTests.hpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1 #ifndef _GLSLIFETIMETESTS_HPP
2 #define _GLSLIFETIMETESTS_HPP
3 /*-------------------------------------------------------------------------
4  * drawElements Quality Program OpenGL (ES) Module
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 Common object lifetime tests.
24  *//*--------------------------------------------------------------------*/
25 
26 #include "deRandom.hpp"
27 #include "deUniquePtr.hpp"
28 #include "tcuSurface.hpp"
29 #include "tcuTestCase.hpp"
30 #include "tcuTestContext.hpp"
31 #include "gluCallLogWrapper.hpp"
32 #include "gluRenderContext.hpp"
33 #include "glwDefs.hpp"
34 #include "glwEnums.hpp"
35 
36 #include <vector>
37 
38 namespace deqp
39 {
40 namespace gls
41 {
42 namespace LifetimeTests
43 {
44 namespace details
45 {
46 
47 using de::MovePtr;
48 using de::Random;
49 using glu::CallLogWrapper;
50 using glu::RenderContext;
51 using std::vector;
52 using tcu::Surface;
53 using tcu::TestCaseGroup;
54 using tcu::TestContext;
55 using tcu::TestLog;
56 using namespace glw;
57 
58 typedef void (CallLogWrapper::*BindFunc)(GLenum target, GLuint name);
59 typedef void (CallLogWrapper::*GenFunc)(GLsizei n, GLuint *names);
60 typedef void (CallLogWrapper::*DeleteFunc)(GLsizei n, const GLuint *names);
61 typedef GLboolean (CallLogWrapper::*ExistsFunc)(GLuint name);
62 
63 class Context
64 {
65 public:
Context(const RenderContext & renderCtx,TestContext & testCtx)66     Context(const RenderContext &renderCtx, TestContext &testCtx) : m_renderCtx(renderCtx), m_testCtx(testCtx)
67     {
68     }
getRenderContext(void) const69     const RenderContext &getRenderContext(void) const
70     {
71         return m_renderCtx;
72     }
getTestContext(void) const73     TestContext &getTestContext(void) const
74     {
75         return m_testCtx;
76     }
gl(void) const77     const Functions &gl(void) const
78     {
79         return m_renderCtx.getFunctions();
80     }
log(void) const81     TestLog &log(void) const
82     {
83         return m_testCtx.getLog();
84     }
85 
86 private:
87     const RenderContext &m_renderCtx;
88     TestContext &m_testCtx;
89 };
90 
91 class ContextWrapper : public CallLogWrapper
92 {
93 public:
getContext(void) const94     const Context &getContext(void) const
95     {
96         return m_ctx;
97     }
getRenderContext(void) const98     const RenderContext &getRenderContext(void) const
99     {
100         return m_ctx.getRenderContext();
101     }
getTestContext(void) const102     TestContext &getTestContext(void) const
103     {
104         return m_ctx.getTestContext();
105     }
gl(void) const106     const Functions &gl(void) const
107     {
108         return m_ctx.gl();
109     }
log(void) const110     TestLog &log(void) const
111     {
112         return m_ctx.log();
113     }
enableLogging(bool enable)114     void enableLogging(bool enable)
115     {
116         CallLogWrapper::enableLogging(enable);
117     }
118 
119 protected:
120     ContextWrapper(const Context &ctx);
121     const Context m_ctx;
122 };
123 
124 class Binder : public ContextWrapper
125 {
126 public:
~Binder(void)127     virtual ~Binder(void)
128     {
129     }
130     virtual void bind(GLuint name)  = 0;
131     virtual GLuint getBinding(void) = 0;
genRequired(void) const132     virtual bool genRequired(void) const
133     {
134         return true;
135     }
136 
137 protected:
Binder(const Context & ctx)138     Binder(const Context &ctx) : ContextWrapper(ctx)
139     {
140     }
141 };
142 
143 class SimpleBinder : public Binder
144 {
145 public:
SimpleBinder(const Context & ctx,BindFunc bindFunc,GLenum bindTarget,GLenum bindingParam,bool genRequired_=false)146     SimpleBinder(const Context &ctx, BindFunc bindFunc, GLenum bindTarget, GLenum bindingParam,
147                  bool genRequired_ = false)
148         : Binder(ctx)
149         , m_bindFunc(bindFunc)
150         , m_bindTarget(bindTarget)
151         , m_bindingParam(bindingParam)
152         , m_genRequired(genRequired_)
153     {
154     }
155 
156     void bind(GLuint name);
157     GLuint getBinding(void);
genRequired(void) const158     bool genRequired(void) const
159     {
160         return m_genRequired;
161     }
162 
163 private:
164     const BindFunc m_bindFunc;
165     const GLenum m_bindTarget;
166     const GLenum m_bindingParam;
167     const bool m_genRequired;
168 };
169 
170 class Type : public ContextWrapper
171 {
172 public:
~Type(void)173     virtual ~Type(void)
174     {
175     }
176     virtual GLuint gen(void)          = 0;
177     virtual void release(GLuint name) = 0;
178     virtual bool exists(GLuint name)  = 0;
isDeleteFlagged(GLuint name)179     virtual bool isDeleteFlagged(GLuint name)
180     {
181         DE_UNREF(name);
182         return false;
183     }
binder(void) const184     virtual Binder *binder(void) const
185     {
186         return DE_NULL;
187     }
188     virtual const char *getName(void) const = 0;
nameLingers(void) const189     virtual bool nameLingers(void) const
190     {
191         return false;
192     }
genCreates(void) const193     virtual bool genCreates(void) const
194     {
195         return false;
196     }
197 
198 protected:
Type(const Context & ctx)199     Type(const Context &ctx) : ContextWrapper(ctx)
200     {
201     }
202 };
203 
204 class SimpleType : public Type
205 {
206 public:
SimpleType(const Context & ctx,const char * name,GenFunc genFunc,DeleteFunc deleteFunc,ExistsFunc existsFunc,Binder * binder_=DE_NULL,bool genCreates_=false)207     SimpleType(const Context &ctx, const char *name, GenFunc genFunc, DeleteFunc deleteFunc, ExistsFunc existsFunc,
208                Binder *binder_ = DE_NULL, bool genCreates_ = false)
209         : Type(ctx)
210         , m_getName(name)
211         , m_genFunc(genFunc)
212         , m_deleteFunc(deleteFunc)
213         , m_existsFunc(existsFunc)
214         , m_binder(binder_)
215         , m_genCreates(genCreates_)
216     {
217     }
218 
219     GLuint gen(void);
release(GLuint name)220     void release(GLuint name)
221     {
222         (this->*m_deleteFunc)(1, &name);
223     }
exists(GLuint name)224     bool exists(GLuint name)
225     {
226         return (this->*m_existsFunc)(name) != GL_FALSE;
227     }
binder(void) const228     Binder *binder(void) const
229     {
230         return m_binder;
231     }
getName(void) const232     const char *getName(void) const
233     {
234         return m_getName;
235     }
nameLingers(void) const236     bool nameLingers(void) const
237     {
238         return false;
239     }
genCreates(void) const240     bool genCreates(void) const
241     {
242         return m_genCreates;
243     }
244 
245 private:
246     const char *const m_getName;
247     const GenFunc m_genFunc;
248     const DeleteFunc m_deleteFunc;
249     const ExistsFunc m_existsFunc;
250     Binder *const m_binder;
251     const bool m_genCreates;
252 };
253 
254 class ProgramType : public Type
255 {
256 public:
ProgramType(const Context & ctx)257     ProgramType(const Context &ctx) : Type(ctx)
258     {
259     }
nameLingers(void) const260     bool nameLingers(void) const
261     {
262         return true;
263     }
genCreates(void) const264     bool genCreates(void) const
265     {
266         return true;
267     }
getName(void) const268     const char *getName(void) const
269     {
270         return "program";
271     }
gen(void)272     GLuint gen(void)
273     {
274         return glCreateProgram();
275     }
release(GLuint name)276     void release(GLuint name)
277     {
278         glDeleteProgram(name);
279     }
exists(GLuint name)280     bool exists(GLuint name)
281     {
282         return glIsProgram(name) != GL_FALSE;
283     }
284     bool isDeleteFlagged(GLuint name);
285 };
286 
287 class ShaderType : public Type
288 {
289 public:
ShaderType(const Context & ctx)290     ShaderType(const Context &ctx) : Type(ctx)
291     {
292     }
nameLingers(void) const293     bool nameLingers(void) const
294     {
295         return true;
296     }
genCreates(void) const297     bool genCreates(void) const
298     {
299         return true;
300     }
getName(void) const301     const char *getName(void) const
302     {
303         return "shader";
304     }
gen(void)305     GLuint gen(void)
306     {
307         return glCreateShader(GL_FRAGMENT_SHADER);
308     }
release(GLuint name)309     void release(GLuint name)
310     {
311         glDeleteShader(name);
312     }
exists(GLuint name)313     bool exists(GLuint name)
314     {
315         return glIsShader(name) != GL_FALSE;
316     }
317     bool isDeleteFlagged(GLuint name);
318 };
319 
320 class Attacher : public ContextWrapper
321 {
322 public:
323     virtual void initAttachment(GLuint seed, GLuint attachment) = 0;
324     virtual void attach(GLuint element, GLuint container)       = 0;
325     virtual void detach(GLuint element, GLuint container)       = 0;
326     virtual GLuint getAttachment(GLuint container)              = 0;
canAttachDeleted(void) const327     virtual bool canAttachDeleted(void) const
328     {
329         return true;
330     }
331 
getElementType(void) const332     Type &getElementType(void) const
333     {
334         return m_elementType;
335     }
getContainerType(void) const336     Type &getContainerType(void) const
337     {
338         return m_containerType;
339     }
~Attacher(void)340     virtual ~Attacher(void)
341     {
342     }
343 
344 protected:
Attacher(const Context & ctx,Type & elementType,Type & containerType)345     Attacher(const Context &ctx, Type &elementType, Type &containerType)
346         : ContextWrapper(ctx)
347         , m_elementType(elementType)
348         , m_containerType(containerType)
349     {
350     }
351 
352 private:
353     Type &m_elementType;
354     Type &m_containerType;
355 };
356 
357 class InputAttacher : public ContextWrapper
358 {
359 public:
getAttacher(void) const360     Attacher &getAttacher(void) const
361     {
362         return m_attacher;
363     }
364     virtual void drawContainer(GLuint container, Surface &dst) = 0;
365 
366 protected:
InputAttacher(Attacher & attacher)367     InputAttacher(Attacher &attacher) : ContextWrapper(attacher.getContext()), m_attacher(attacher)
368     {
369     }
370     Attacher &m_attacher;
371 };
372 
373 class OutputAttacher : public ContextWrapper
374 {
375 public:
getAttacher(void) const376     Attacher &getAttacher(void) const
377     {
378         return m_attacher;
379     }
380     virtual void setupContainer(GLuint seed, GLuint container)   = 0;
381     virtual void drawAttachment(GLuint attachment, Surface &dst) = 0;
382 
383 protected:
OutputAttacher(Attacher & attacher)384     OutputAttacher(Attacher &attacher) : ContextWrapper(attacher.getContext()), m_attacher(attacher)
385     {
386     }
387     Attacher &m_attacher;
388 };
389 
390 class Types : public ContextWrapper
391 {
392 public:
Types(const Context & ctx)393     Types(const Context &ctx) : ContextWrapper(ctx)
394     {
395     }
396     virtual Type &getProgramType(void) = 0;
getTypes(void)397     const vector<Type *> &getTypes(void)
398     {
399         return m_types;
400     }
getAttachers(void)401     const vector<Attacher *> &getAttachers(void)
402     {
403         return m_attachers;
404     }
getInputAttachers(void)405     const vector<InputAttacher *> &getInputAttachers(void)
406     {
407         return m_inAttachers;
408     }
getOutputAttachers(void)409     const vector<OutputAttacher *> &getOutputAttachers(void)
410     {
411         return m_outAttachers;
412     }
~Types(void)413     virtual ~Types(void)
414     {
415     }
416 
417 protected:
418     vector<Type *> m_types;
419     vector<Attacher *> m_attachers;
420     vector<InputAttacher *> m_inAttachers;
421     vector<OutputAttacher *> m_outAttachers;
422 };
423 
424 class FboAttacher : public Attacher
425 {
426 public:
427     void initAttachment(GLuint seed, GLuint element);
428 
429 protected:
FboAttacher(const Context & ctx,Type & elementType,Type & containerType)430     FboAttacher(const Context &ctx, Type &elementType, Type &containerType) : Attacher(ctx, elementType, containerType)
431     {
432     }
433     virtual void initStorage(void) = 0;
434 };
435 
436 class FboInputAttacher : public InputAttacher
437 {
438 public:
FboInputAttacher(FboAttacher & attacher)439     FboInputAttacher(FboAttacher &attacher) : InputAttacher(attacher)
440     {
441     }
442     void drawContainer(GLuint container, Surface &dst);
443 };
444 
445 class FboOutputAttacher : public OutputAttacher
446 {
447 public:
FboOutputAttacher(FboAttacher & attacher)448     FboOutputAttacher(FboAttacher &attacher) : OutputAttacher(attacher)
449     {
450     }
451     void setupContainer(GLuint seed, GLuint container);
452     void drawAttachment(GLuint attachment, Surface &dst);
453 };
454 
455 class TextureFboAttacher : public FboAttacher
456 {
457 public:
TextureFboAttacher(const Context & ctx,Type & elementType,Type & containerType)458     TextureFboAttacher(const Context &ctx, Type &elementType, Type &containerType)
459         : FboAttacher(ctx, elementType, containerType)
460     {
461     }
462 
463     void initStorage(void);
464     void attach(GLuint element, GLuint container);
465     void detach(GLuint element, GLuint container);
466     GLuint getAttachment(GLuint container);
467 };
468 
469 class RboFboAttacher : public FboAttacher
470 {
471 public:
RboFboAttacher(const Context & ctx,Type & elementType,Type & containerType)472     RboFboAttacher(const Context &ctx, Type &elementType, Type &containerType)
473         : FboAttacher(ctx, elementType, containerType)
474     {
475     }
476 
477     void initStorage(void);
478     void attach(GLuint element, GLuint container);
479     void detach(GLuint element, GLuint container);
480     GLuint getAttachment(GLuint container);
481 };
482 
483 class ShaderProgramAttacher : public Attacher
484 {
485 public:
ShaderProgramAttacher(const Context & ctx,Type & elementType,Type & containerType)486     ShaderProgramAttacher(const Context &ctx, Type &elementType, Type &containerType)
487         : Attacher(ctx, elementType, containerType)
488     {
489     }
490 
491     void initAttachment(GLuint seed, GLuint element);
492     void attach(GLuint element, GLuint container);
493     void detach(GLuint element, GLuint container);
494     GLuint getAttachment(GLuint container);
495 };
496 
497 class ShaderProgramInputAttacher : public InputAttacher
498 {
499 public:
ShaderProgramInputAttacher(Attacher & attacher)500     ShaderProgramInputAttacher(Attacher &attacher) : InputAttacher(attacher)
501     {
502     }
503 
504     void drawContainer(GLuint container, Surface &dst);
505 };
506 
507 class ES2Types : public Types
508 {
509 public:
510     ES2Types(const Context &ctx);
getProgramType(void)511     Type &getProgramType(void)
512     {
513         return m_programType;
514     }
515 
516 protected:
517     SimpleBinder m_bufferBind;
518     SimpleType m_bufferType;
519     SimpleBinder m_textureBind;
520     SimpleType m_textureType;
521     SimpleBinder m_rboBind;
522     SimpleType m_rboType;
523     SimpleBinder m_fboBind;
524     SimpleType m_fboType;
525     ShaderType m_shaderType;
526     ProgramType m_programType;
527     TextureFboAttacher m_texFboAtt;
528     FboInputAttacher m_texFboInAtt;
529     FboOutputAttacher m_texFboOutAtt;
530     RboFboAttacher m_rboFboAtt;
531     FboInputAttacher m_rboFboInAtt;
532     FboOutputAttacher m_rboFboOutAtt;
533     ShaderProgramAttacher m_shaderAtt;
534     ShaderProgramInputAttacher m_shaderInAtt;
535 };
536 
537 MovePtr<TestCaseGroup> createGroup(TestContext &testCtx, Type &type);
538 void addTestCases(TestCaseGroup &group, Types &types);
539 
540 struct Rectangle
541 {
Rectangledeqp::gls::LifetimeTests::details::Rectangle542     Rectangle(GLint x_, GLint y_, GLint width_, GLint height_) : x(x_), y(y_), width(width_), height(height_)
543     {
544     }
545     GLint x;
546     GLint y;
547     GLint width;
548     GLint height;
549 };
550 
551 Rectangle randomViewport(const RenderContext &ctx, GLint maxWidth, GLint maxHeight, Random &rnd);
552 void setViewport(const RenderContext &renderCtx, const Rectangle &rect);
553 void readRectangle(const RenderContext &renderCtx, const Rectangle &rect, Surface &dst);
554 
555 } // namespace details
556 
557 using details::BindFunc;
558 using details::DeleteFunc;
559 using details::ExistsFunc;
560 using details::GenFunc;
561 
562 using details::Attacher;
563 using details::Binder;
564 using details::Context;
565 using details::ES2Types;
566 using details::InputAttacher;
567 using details::OutputAttacher;
568 using details::SimpleBinder;
569 using details::SimpleType;
570 using details::Type;
571 using details::Types;
572 
573 using details::addTestCases;
574 using details::createGroup;
575 
576 using details::randomViewport;
577 using details::readRectangle;
578 using details::Rectangle;
579 using details::setViewport;
580 
581 } // namespace LifetimeTests
582 } // namespace gls
583 } // namespace deqp
584 
585 #endif // _GLSLIFETIMETESTS_HPP
586