1 #ifndef _GLSBUFFERTESTUTIL_HPP
2 #define _GLSBUFFERTESTUTIL_HPP
3 /*-------------------------------------------------------------------------
4 * drawElements Quality Program OpenGL (ES) Module
5 * -----------------------------------------------
7 * Copyright 2014 The Android Open Source Project
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
23 * \brief Buffer test utilities.
24 *//*--------------------------------------------------------------------*/
26 #include "tcuDefs.hpp"
27 #include "tcuTestCase.hpp"
28 #include "gluCallLogWrapper.hpp"
29 #include "gluObjectWrapper.hpp"
49 namespace BufferTestUtil
54 void fillWithRandomBytes (deUint8* ptr, int numBytes, deUint32 seed);
55 bool compareByteArrays (tcu::TestLog& log, const deUint8* resPtr, const deUint8* refPtr, int numBytes);
56 const char* getBufferTargetName (deUint32 target);
57 const char* getUsageHintName (deUint32 hint);
59 // Base class for buffer cases.
61 class BufferCase : public tcu::TestCase, public glu::CallLogWrapper
64 BufferCase (tcu::TestContext& testCtx, glu::RenderContext& renderCtx, const char* name, const char* description);
65 virtual ~BufferCase (void);
70 deUint32 genBuffer (void);
71 void deleteBuffer (deUint32 buffer);
72 void checkError (void);
75 glu::RenderContext& m_renderCtx;
78 // Resource handles for cleanup in case of unexpected iterate() termination.
79 std::set<deUint32> m_allocatedBuffers;
87 ReferenceBuffer (void) {}
88 ~ReferenceBuffer (void) {}
90 void setSize (int numBytes);
91 void setData (int numBytes, const deUint8* bytes);
92 void setSubData (int offset, int numBytes, const deUint8* bytes);
94 deUint8* getPtr (int offset = 0) { return &m_data[offset]; }
95 const deUint8* getPtr (int offset = 0) const { return &m_data[offset]; }
98 std::vector<deUint8> m_data;
101 // Buffer writer system.
105 WRITE_BUFFER_SUB_DATA = 0,
106 WRITE_BUFFER_WRITE_MAP,
107 WRITE_TRANSFORM_FEEDBACK,
113 const char* getWriteTypeDescription (WriteType type);
115 class BufferWriterBase : protected glu::CallLogWrapper
118 BufferWriterBase (glu::RenderContext& renderCtx, tcu::TestLog& log);
119 virtual ~BufferWriterBase (void) {}
121 virtual int getMinSize (void) const = DE_NULL;
122 virtual int getAlignment (void) const = DE_NULL;
123 virtual void write (deUint32 buffer, int offset, int numBytes, const deUint8* bytes) = DE_NULL;
124 virtual void write (deUint32 buffer, int offset, int numBytes, const deUint8* bytes, deUint32 targetHint);
127 glu::RenderContext& m_renderCtx;
130 BufferWriterBase (const BufferWriterBase& other);
131 BufferWriterBase& operator= (const BufferWriterBase& other);
137 BufferWriter (glu::RenderContext& renderCtx, tcu::TestLog& log, WriteType writeType);
138 ~BufferWriter (void);
140 int getMinSize (void) const { return m_writer->getMinSize(); }
141 int getAlignment (void) const { return m_writer->getAlignment(); }
142 void write (deUint32 buffer, int offset, int numBytes, const deUint8* bytes);
143 void write (deUint32 buffer, int offset, int numBytes, const deUint8* bytes, deUint32 targetHint);
146 BufferWriter (const BufferWriter& other);
147 BufferWriter& operator= (const BufferWriter& other);
149 BufferWriterBase* m_writer;
152 class BufferSubDataWriter : public BufferWriterBase
155 BufferSubDataWriter (glu::RenderContext& renderCtx, tcu::TestLog& log) : BufferWriterBase(renderCtx, log) {}
156 ~BufferSubDataWriter (void) {}
158 int getMinSize (void) const { return 1; }
159 int getAlignment (void) const { return 1; }
160 virtual void write (deUint32 buffer, int offset, int numBytes, const deUint8* bytes);
161 virtual void write (deUint32 buffer, int offset, int numBytes, const deUint8* bytes, deUint32 target);
164 class BufferWriteMapWriter : public BufferWriterBase
167 BufferWriteMapWriter (glu::RenderContext& renderCtx, tcu::TestLog& log) : BufferWriterBase(renderCtx, log) {}
168 ~BufferWriteMapWriter (void) {}
170 int getMinSize (void) const { return 1; }
171 int getAlignment (void) const { return 1; }
172 virtual void write (deUint32 buffer, int offset, int numBytes, const deUint8* bytes);
173 virtual void write (deUint32 buffer, int offset, int numBytes, const deUint8* bytes, deUint32 target);
176 // Buffer verifier system.
180 VERIFY_AS_VERTEX_ARRAY = 0,
181 VERIFY_AS_INDEX_ARRAY,
182 VERIFY_AS_UNIFORM_BUFFER,
183 VERIFY_AS_PIXEL_UNPACK_BUFFER,
184 VERIFY_BUFFER_READ_MAP,
189 const char* getVerifyTypeDescription (VerifyType type);
191 class BufferVerifierBase : public glu::CallLogWrapper
194 BufferVerifierBase (glu::RenderContext& renderCtx, tcu::TestLog& log);
195 virtual ~BufferVerifierBase (void) {}
197 virtual int getMinSize (void) const = DE_NULL;
198 virtual int getAlignment (void) const = DE_NULL;
199 virtual bool verify (deUint32 buffer, const deUint8* reference, int offset, int numBytes) = DE_NULL;
200 virtual bool verify (deUint32 buffer, const deUint8* reference, int offset, int numBytes, deUint32 targetHint);
203 glu::RenderContext& m_renderCtx;
207 BufferVerifierBase (const BufferVerifierBase& other);
208 BufferVerifierBase& operator= (const BufferVerifierBase& other);
214 BufferVerifier (glu::RenderContext& renderCtx, tcu::TestLog& log, VerifyType verifyType);
215 ~BufferVerifier (void);
217 int getMinSize (void) const { return m_verifier->getMinSize(); }
218 int getAlignment (void) const { return m_verifier->getAlignment(); }
220 // \note Offset is applied to reference pointer as well.
221 bool verify (deUint32 buffer, const deUint8* reference, int offset, int numBytes);
222 bool verify (deUint32 buffer, const deUint8* reference, int offset, int numBytes, deUint32 targetHint);
225 BufferVerifier (const BufferVerifier& other);
226 BufferVerifier& operator= (const BufferVerifier& other);
228 BufferVerifierBase* m_verifier;
231 class BufferMapVerifier : public BufferVerifierBase
234 BufferMapVerifier (glu::RenderContext& renderCtx, tcu::TestLog& log) : BufferVerifierBase(renderCtx, log) {}
235 ~BufferMapVerifier (void) {}
237 int getMinSize (void) const { return 1; }
238 int getAlignment (void) const { return 1; }
239 bool verify (deUint32 buffer, const deUint8* reference, int offset, int numBytes);
240 bool verify (deUint32 buffer, const deUint8* reference, int offset, int numBytes, deUint32 target);
243 class VertexArrayVerifier : public BufferVerifierBase
246 VertexArrayVerifier (glu::RenderContext& renderCtx, tcu::TestLog& log);
247 ~VertexArrayVerifier (void);
249 int getMinSize (void) const { return 3*4; }
250 int getAlignment (void) const { return 1; }
251 bool verify (deUint32 buffer, const deUint8* reference, int offset, int numBytes);
254 glu::ShaderProgram* m_program;
256 deUint32 m_byteVecLoc;
259 deUint32 m_positionBuf;
263 class IndexArrayVerifier : public BufferVerifierBase
266 IndexArrayVerifier (glu::RenderContext& renderCtx, tcu::TestLog& log);
267 ~IndexArrayVerifier (void);
269 int getMinSize (void) const { return 2; }
270 int getAlignment (void) const { return 1; }
271 bool verify (deUint32 buffer, const deUint8* reference, int offset, int numBytes);
274 glu::ShaderProgram* m_program;
279 deUint32 m_positionBuf;
287 #endif // _GLSBUFFERTESTUTIL_HPP