1 #ifndef _GLSBUFFERTESTUTIL_HPP
2 #define _GLSBUFFERTESTUTIL_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 Buffer test utilities.
24  *//*--------------------------------------------------------------------*/
25 
26 #include "tcuDefs.hpp"
27 #include "tcuTestCase.hpp"
28 #include "gluCallLogWrapper.hpp"
29 #include "gluObjectWrapper.hpp"
30 
31 #include <vector>
32 #include <set>
33 
34 namespace tcu
35 {
36 class TestLog;
37 }
38 
39 namespace glu
40 {
41 class RenderContext;
42 class ShaderProgram;
43 }
44 
45 namespace deqp
46 {
47 namespace gls
48 {
49 namespace BufferTestUtil
50 {
51 
52 // Helper functions.
53 
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);
58 
59 // Base class for buffer cases.
60 
61 class BufferCase : public tcu::TestCase, public glu::CallLogWrapper
62 {
63 public:
64 							BufferCase							(tcu::TestContext& testCtx, glu::RenderContext& renderCtx, const char* name, const char* description);
65 	virtual					~BufferCase							(void);
66 
67 	void					init								(void);
68 	void					deinit								(void);
69 
70 	deUint32				genBuffer							(void);
71 	void					deleteBuffer						(deUint32 buffer);
72 	void					checkError							(void);
73 
74 protected:
75 	glu::RenderContext&		m_renderCtx;
76 
77 private:
78 	// Resource handles for cleanup in case of unexpected iterate() termination.
79 	std::set<deUint32>		m_allocatedBuffers;
80 };
81 
82 // Reference buffer.
83 
84 class ReferenceBuffer
85 {
86 public:
ReferenceBuffer(void)87 							ReferenceBuffer			(void) {}
~ReferenceBuffer(void)88 							~ReferenceBuffer		(void) {}
89 
90 	void					setSize					(int numBytes);
91 	void					setData					(int numBytes, const deUint8* bytes);
92 	void					setSubData				(int offset, int numBytes, const deUint8* bytes);
93 
getPtr(int offset=0)94 	deUint8*				getPtr					(int offset = 0)		{ return &m_data[offset]; }
getPtr(int offset=0) const95 	const deUint8*			getPtr					(int offset = 0) const	{ return &m_data[offset]; }
96 
97 private:
98 	std::vector<deUint8>	m_data;
99 };
100 
101 // Buffer writer system.
102 
103 enum WriteType
104 {
105 	WRITE_BUFFER_SUB_DATA = 0,
106 	WRITE_BUFFER_WRITE_MAP,
107 	WRITE_TRANSFORM_FEEDBACK,
108 	WRITE_PIXEL_PACK,
109 
110 	WRITE_LAST
111 };
112 
113 const char*	getWriteTypeDescription	(WriteType type);
114 
115 class BufferWriterBase : protected glu::CallLogWrapper
116 {
117 public:
118 							BufferWriterBase		(glu::RenderContext& renderCtx, tcu::TestLog& log);
~BufferWriterBase(void)119 	virtual					~BufferWriterBase		(void) {}
120 
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);
125 
126 protected:
127 	glu::RenderContext&		m_renderCtx;
128 
129 private:
130 							BufferWriterBase		(const BufferWriterBase& other);
131 	BufferWriterBase&		operator=				(const BufferWriterBase& other);
132 };
133 
134 class BufferWriter
135 {
136 public:
137 							BufferWriter			(glu::RenderContext& renderCtx, tcu::TestLog& log, WriteType writeType);
138 							~BufferWriter			(void);
139 
getMinSize(void) const140 	int						getMinSize				(void) const { return m_writer->getMinSize();	}
getAlignment(void) const141 	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);
144 
145 private:
146 							BufferWriter			(const BufferWriter& other);
147 	BufferWriter&			operator=				(const BufferWriter& other);
148 
149 	BufferWriterBase*		m_writer;
150 };
151 
152 class BufferSubDataWriter : public BufferWriterBase
153 {
154 public:
BufferSubDataWriter(glu::RenderContext & renderCtx,tcu::TestLog & log)155 						BufferSubDataWriter			(glu::RenderContext& renderCtx, tcu::TestLog& log) : BufferWriterBase(renderCtx, log) {}
~BufferSubDataWriter(void)156 						~BufferSubDataWriter		(void) {}
157 
getMinSize(void) const158 	int					getMinSize					(void) const { return 1; }
getAlignment(void) const159 	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);
162 };
163 
164 class BufferWriteMapWriter : public BufferWriterBase
165 {
166 public:
BufferWriteMapWriter(glu::RenderContext & renderCtx,tcu::TestLog & log)167 						BufferWriteMapWriter		(glu::RenderContext& renderCtx, tcu::TestLog& log) : BufferWriterBase(renderCtx, log) {}
~BufferWriteMapWriter(void)168 						~BufferWriteMapWriter		(void) {}
169 
getMinSize(void) const170 	int					getMinSize					(void) const { return 1; }
getAlignment(void) const171 	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);
174 };
175 
176 // Buffer verifier system.
177 
178 enum VerifyType
179 {
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,
185 
186 	VERIFY_LAST
187 };
188 
189 const char* getVerifyTypeDescription (VerifyType type);
190 
191 class BufferVerifierBase : public glu::CallLogWrapper
192 {
193 public:
194 							BufferVerifierBase		(glu::RenderContext& renderCtx, tcu::TestLog& log);
~BufferVerifierBase(void)195 	virtual					~BufferVerifierBase		(void) {}
196 
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);
201 
202 protected:
203 	glu::RenderContext&		m_renderCtx;
204 	tcu::TestLog&			m_log;
205 
206 private:
207 							BufferVerifierBase		(const BufferVerifierBase& other);
208 	BufferVerifierBase&		operator=				(const BufferVerifierBase& other);
209 };
210 
211 class BufferVerifier
212 {
213 public:
214 							BufferVerifier			(glu::RenderContext& renderCtx, tcu::TestLog& log, VerifyType verifyType);
215 							~BufferVerifier			(void);
216 
getMinSize(void) const217 	int						getMinSize				(void) const { return m_verifier->getMinSize();		}
getAlignment(void) const218 	int						getAlignment			(void) const { return m_verifier->getAlignment();	}
219 
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);
223 
224 private:
225 							BufferVerifier			(const BufferVerifier& other);
226 	BufferVerifier&			operator=				(const BufferVerifier& other);
227 
228 	BufferVerifierBase*		m_verifier;
229 };
230 
231 class BufferMapVerifier : public BufferVerifierBase
232 {
233 public:
BufferMapVerifier(glu::RenderContext & renderCtx,tcu::TestLog & log)234 						BufferMapVerifier		(glu::RenderContext& renderCtx, tcu::TestLog& log) : BufferVerifierBase(renderCtx, log) {}
~BufferMapVerifier(void)235 						~BufferMapVerifier		(void) {}
236 
getMinSize(void) const237 	int					getMinSize				(void) const { return 1; }
getAlignment(void) const238 	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);
241 };
242 
243 class VertexArrayVerifier : public BufferVerifierBase
244 {
245 public:
246 						VertexArrayVerifier		(glu::RenderContext& renderCtx, tcu::TestLog& log);
247 						~VertexArrayVerifier	(void);
248 
getMinSize(void) const249 	int					getMinSize				(void) const { return 3*4; }
getAlignment(void) const250 	int					getAlignment			(void) const { return 1; }
251 	bool				verify					(deUint32 buffer, const deUint8* reference, int offset, int numBytes);
252 
253 private:
254 	glu::ShaderProgram*	m_program;
255 	deUint32			m_posLoc;
256 	deUint32			m_byteVecLoc;
257 
258 	deUint32			m_vao;
259 	deUint32			m_positionBuf;
260 	deUint32			m_indexBuf;
261 };
262 
263 class IndexArrayVerifier : public BufferVerifierBase
264 {
265 public:
266 						IndexArrayVerifier		(glu::RenderContext& renderCtx, tcu::TestLog& log);
267 						~IndexArrayVerifier		(void);
268 
getMinSize(void) const269 	int					getMinSize				(void) const { return 2; }
getAlignment(void) const270 	int					getAlignment			(void) const { return 1; }
271 	bool				verify					(deUint32 buffer, const deUint8* reference, int offset, int numBytes);
272 
273 private:
274 	glu::ShaderProgram*	m_program;
275 	deUint32			m_posLoc;
276 	deUint32			m_colorLoc;
277 
278 	deUint32			m_vao;
279 	deUint32			m_positionBuf;
280 	deUint32			m_colorBuf;
281 };
282 
283 } // BufferTestUtil
284 } // gls
285 } // deqp
286 
287 #endif // _GLSBUFFERTESTUTIL_HPP
288