xref: /aosp_15_r20/external/deqp/modules/gles2/functional/es2fBufferTestUtil.hpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1 #ifndef _ES2FBUFFERTESTUTIL_HPP
2 #define _ES2FBUFFERTESTUTIL_HPP
3 /*-------------------------------------------------------------------------
4  * drawElements Quality Program OpenGL ES 2.0 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 Buffer test utilities.
24  *//*--------------------------------------------------------------------*/
25 
26 #include "tcuDefs.hpp"
27 #include "tcuTestLog.hpp"
28 #include "gluCallLogWrapper.hpp"
29 #include "tes2TestCase.hpp"
30 
31 #include <vector>
32 #include <set>
33 
34 namespace glu
35 {
36 class ShaderProgram;
37 }
38 
39 namespace deqp
40 {
41 namespace gles2
42 {
43 namespace Functional
44 {
45 namespace BufferTestUtil
46 {
47 
48 // Helper functions.
49 
50 void fillWithRandomBytes(uint8_t *ptr, int numBytes, uint32_t seed);
51 bool compareByteArrays(tcu::TestLog &log, const uint8_t *resPtr, const uint8_t *refPtr, int numBytes);
52 const char *getBufferTargetName(uint32_t target);
53 const char *getUsageHintName(uint32_t hint);
54 
55 // Base class for buffer cases.
56 
57 class BufferCase : public TestCase, public glu::CallLogWrapper
58 {
59 public:
60     BufferCase(Context &context, const char *name, const char *description);
61     virtual ~BufferCase(void);
62 
63     void init(void);
64     void deinit(void);
65 
66     uint32_t genBuffer(void);
67     void deleteBuffer(uint32_t buffer);
68     void checkError(void);
69 
70 private:
71     // Resource handles for cleanup in case of unexpected iterate() termination.
72     std::set<uint32_t> m_allocatedBuffers;
73 };
74 
75 // Reference buffer.
76 
77 class ReferenceBuffer
78 {
79 public:
ReferenceBuffer(void)80     ReferenceBuffer(void)
81     {
82     }
~ReferenceBuffer(void)83     ~ReferenceBuffer(void)
84     {
85     }
86 
87     void setSize(int numBytes);
88     void setData(int numBytes, const uint8_t *bytes);
89     void setSubData(int offset, int numBytes, const uint8_t *bytes);
90 
getPtr(int offset=0)91     uint8_t *getPtr(int offset = 0)
92     {
93         return &m_data[offset];
94     }
getPtr(int offset=0) const95     const uint8_t *getPtr(int offset = 0) const
96     {
97         return &m_data[offset];
98     }
99 
100 private:
101     std::vector<uint8_t> m_data;
102 };
103 
104 // Buffer verifier system.
105 
106 enum VerifyType
107 {
108     VERIFY_AS_VERTEX_ARRAY = 0,
109     VERIFY_AS_INDEX_ARRAY,
110 
111     VERIFY_LAST
112 };
113 
114 class BufferVerifierBase : public glu::CallLogWrapper
115 {
116 public:
117     BufferVerifierBase(Context &context);
~BufferVerifierBase(void)118     virtual ~BufferVerifierBase(void)
119     {
120     }
121 
122     virtual int getMinSize(void) const                                                       = DE_NULL;
123     virtual int getAlignment(void) const                                                     = DE_NULL;
124     virtual bool verify(uint32_t buffer, const uint8_t *reference, int offset, int numBytes) = DE_NULL;
125 
126 protected:
127     Context &m_context;
128 
129 private:
130     BufferVerifierBase(const BufferVerifierBase &other);
131     BufferVerifierBase &operator=(const BufferVerifierBase &other);
132 };
133 
134 class BufferVerifier
135 {
136 public:
137     BufferVerifier(Context &context, VerifyType verifyType);
138     ~BufferVerifier(void);
139 
getMinSize(void) const140     int getMinSize(void) const
141     {
142         return m_verifier->getMinSize();
143     }
getAlignment(void) const144     int getAlignment(void) const
145     {
146         return m_verifier->getAlignment();
147     }
148 
149     // \note Offset is applied to reference pointer as well.
150     bool verify(uint32_t buffer, const uint8_t *reference, int offset, int numBytes);
151 
152 private:
153     BufferVerifier(const BufferVerifier &other);
154     BufferVerifier &operator=(const BufferVerifier &other);
155 
156     BufferVerifierBase *m_verifier;
157 };
158 
159 class VertexArrayVerifier : public BufferVerifierBase
160 {
161 public:
162     VertexArrayVerifier(Context &context);
163     ~VertexArrayVerifier(void);
164 
getMinSize(void) const165     int getMinSize(void) const
166     {
167         return 3 * 4;
168     }
getAlignment(void) const169     int getAlignment(void) const
170     {
171         return 1;
172     }
173     bool verify(uint32_t buffer, const uint8_t *reference, int offset, int numBytes);
174 
175 private:
176     glu::ShaderProgram *m_program;
177     uint32_t m_posLoc;
178     uint32_t m_byteVecLoc;
179 };
180 
181 class IndexArrayVerifier : public BufferVerifierBase
182 {
183 public:
184     IndexArrayVerifier(Context &context);
185     ~IndexArrayVerifier(void);
186 
getMinSize(void) const187     int getMinSize(void) const
188     {
189         return 2;
190     }
getAlignment(void) const191     int getAlignment(void) const
192     {
193         return 1;
194     }
195     bool verify(uint32_t buffer, const uint8_t *reference, int offset, int numBytes);
196 
197 private:
198     glu::ShaderProgram *m_program;
199     uint32_t m_posLoc;
200     uint32_t m_colorLoc;
201 };
202 
203 } // namespace BufferTestUtil
204 } // namespace Functional
205 } // namespace gles2
206 } // namespace deqp
207 
208 #endif // _ES2FBUFFERTESTUTIL_HPP
209