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 } // namespace glu 44 45 namespace deqp 46 { 47 namespace gls 48 { 49 namespace BufferTestUtil 50 { 51 52 // Helper functions. 53 54 void fillWithRandomBytes(uint8_t *ptr, int numBytes, uint32_t seed); 55 bool compareByteArrays(tcu::TestLog &log, const uint8_t *resPtr, const uint8_t *refPtr, int numBytes); 56 const char *getBufferTargetName(uint32_t target); 57 const char *getUsageHintName(uint32_t 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 uint32_t genBuffer(void); 71 void deleteBuffer(uint32_t 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<uint32_t> m_allocatedBuffers; 80 }; 81 82 // Reference buffer. 83 84 class ReferenceBuffer 85 { 86 public: ReferenceBuffer(void)87 ReferenceBuffer(void) 88 { 89 } ~ReferenceBuffer(void)90 ~ReferenceBuffer(void) 91 { 92 } 93 94 void setSize(int numBytes); 95 void setData(int numBytes, const uint8_t *bytes); 96 void setSubData(int offset, int numBytes, const uint8_t *bytes); 97 getPtr(int offset=0)98 uint8_t *getPtr(int offset = 0) 99 { 100 return &m_data[offset]; 101 } getPtr(int offset=0) const102 const uint8_t *getPtr(int offset = 0) const 103 { 104 return &m_data[offset]; 105 } 106 107 private: 108 std::vector<uint8_t> m_data; 109 }; 110 111 // Buffer writer system. 112 113 enum WriteType 114 { 115 WRITE_BUFFER_SUB_DATA = 0, 116 WRITE_BUFFER_WRITE_MAP, 117 WRITE_TRANSFORM_FEEDBACK, 118 WRITE_PIXEL_PACK, 119 120 WRITE_LAST 121 }; 122 123 const char *getWriteTypeDescription(WriteType type); 124 125 class BufferWriterBase : protected glu::CallLogWrapper 126 { 127 public: 128 BufferWriterBase(glu::RenderContext &renderCtx, tcu::TestLog &log); ~BufferWriterBase(void)129 virtual ~BufferWriterBase(void) 130 { 131 } 132 133 virtual int getMinSize(void) const = DE_NULL; 134 virtual int getAlignment(void) const = DE_NULL; 135 virtual void write(uint32_t buffer, int offset, int numBytes, const uint8_t *bytes) = DE_NULL; 136 virtual void write(uint32_t buffer, int offset, int numBytes, const uint8_t *bytes, uint32_t targetHint); 137 138 protected: 139 glu::RenderContext &m_renderCtx; 140 141 private: 142 BufferWriterBase(const BufferWriterBase &other); 143 BufferWriterBase &operator=(const BufferWriterBase &other); 144 }; 145 146 class BufferWriter 147 { 148 public: 149 BufferWriter(glu::RenderContext &renderCtx, tcu::TestLog &log, WriteType writeType); 150 ~BufferWriter(void); 151 getMinSize(void) const152 int getMinSize(void) const 153 { 154 return m_writer->getMinSize(); 155 } getAlignment(void) const156 int getAlignment(void) const 157 { 158 return m_writer->getAlignment(); 159 } 160 void write(uint32_t buffer, int offset, int numBytes, const uint8_t *bytes); 161 void write(uint32_t buffer, int offset, int numBytes, const uint8_t *bytes, uint32_t targetHint); 162 163 private: 164 BufferWriter(const BufferWriter &other); 165 BufferWriter &operator=(const BufferWriter &other); 166 167 BufferWriterBase *m_writer; 168 }; 169 170 class BufferSubDataWriter : public BufferWriterBase 171 { 172 public: BufferSubDataWriter(glu::RenderContext & renderCtx,tcu::TestLog & log)173 BufferSubDataWriter(glu::RenderContext &renderCtx, tcu::TestLog &log) : BufferWriterBase(renderCtx, log) 174 { 175 } ~BufferSubDataWriter(void)176 ~BufferSubDataWriter(void) 177 { 178 } 179 getMinSize(void) const180 int getMinSize(void) const 181 { 182 return 1; 183 } getAlignment(void) const184 int getAlignment(void) const 185 { 186 return 1; 187 } 188 virtual void write(uint32_t buffer, int offset, int numBytes, const uint8_t *bytes); 189 virtual void write(uint32_t buffer, int offset, int numBytes, const uint8_t *bytes, uint32_t target); 190 }; 191 192 class BufferWriteMapWriter : public BufferWriterBase 193 { 194 public: BufferWriteMapWriter(glu::RenderContext & renderCtx,tcu::TestLog & log)195 BufferWriteMapWriter(glu::RenderContext &renderCtx, tcu::TestLog &log) : BufferWriterBase(renderCtx, log) 196 { 197 } ~BufferWriteMapWriter(void)198 ~BufferWriteMapWriter(void) 199 { 200 } 201 getMinSize(void) const202 int getMinSize(void) const 203 { 204 return 1; 205 } getAlignment(void) const206 int getAlignment(void) const 207 { 208 return 1; 209 } 210 virtual void write(uint32_t buffer, int offset, int numBytes, const uint8_t *bytes); 211 virtual void write(uint32_t buffer, int offset, int numBytes, const uint8_t *bytes, uint32_t target); 212 }; 213 214 // Buffer verifier system. 215 216 enum VerifyType 217 { 218 VERIFY_AS_VERTEX_ARRAY = 0, 219 VERIFY_AS_INDEX_ARRAY, 220 VERIFY_AS_UNIFORM_BUFFER, 221 VERIFY_AS_PIXEL_UNPACK_BUFFER, 222 VERIFY_BUFFER_READ_MAP, 223 224 VERIFY_LAST 225 }; 226 227 const char *getVerifyTypeDescription(VerifyType type); 228 229 class BufferVerifierBase : public glu::CallLogWrapper 230 { 231 public: 232 BufferVerifierBase(glu::RenderContext &renderCtx, tcu::TestLog &log); ~BufferVerifierBase(void)233 virtual ~BufferVerifierBase(void) 234 { 235 } 236 237 virtual int getMinSize(void) const = DE_NULL; 238 virtual int getAlignment(void) const = DE_NULL; 239 virtual bool verify(uint32_t buffer, const uint8_t *reference, int offset, int numBytes) = DE_NULL; 240 virtual bool verify(uint32_t buffer, const uint8_t *reference, int offset, int numBytes, uint32_t targetHint); 241 242 protected: 243 glu::RenderContext &m_renderCtx; 244 tcu::TestLog &m_log; 245 246 private: 247 BufferVerifierBase(const BufferVerifierBase &other); 248 BufferVerifierBase &operator=(const BufferVerifierBase &other); 249 }; 250 251 class BufferVerifier 252 { 253 public: 254 BufferVerifier(glu::RenderContext &renderCtx, tcu::TestLog &log, VerifyType verifyType); 255 ~BufferVerifier(void); 256 getMinSize(void) const257 int getMinSize(void) const 258 { 259 return m_verifier->getMinSize(); 260 } getAlignment(void) const261 int getAlignment(void) const 262 { 263 return m_verifier->getAlignment(); 264 } 265 266 // \note Offset is applied to reference pointer as well. 267 bool verify(uint32_t buffer, const uint8_t *reference, int offset, int numBytes); 268 bool verify(uint32_t buffer, const uint8_t *reference, int offset, int numBytes, uint32_t targetHint); 269 270 private: 271 BufferVerifier(const BufferVerifier &other); 272 BufferVerifier &operator=(const BufferVerifier &other); 273 274 BufferVerifierBase *m_verifier; 275 }; 276 277 class BufferMapVerifier : public BufferVerifierBase 278 { 279 public: BufferMapVerifier(glu::RenderContext & renderCtx,tcu::TestLog & log)280 BufferMapVerifier(glu::RenderContext &renderCtx, tcu::TestLog &log) : BufferVerifierBase(renderCtx, log) 281 { 282 } ~BufferMapVerifier(void)283 ~BufferMapVerifier(void) 284 { 285 } 286 getMinSize(void) const287 int getMinSize(void) const 288 { 289 return 1; 290 } getAlignment(void) const291 int getAlignment(void) const 292 { 293 return 1; 294 } 295 bool verify(uint32_t buffer, const uint8_t *reference, int offset, int numBytes); 296 bool verify(uint32_t buffer, const uint8_t *reference, int offset, int numBytes, uint32_t target); 297 }; 298 299 class VertexArrayVerifier : public BufferVerifierBase 300 { 301 public: 302 VertexArrayVerifier(glu::RenderContext &renderCtx, tcu::TestLog &log); 303 ~VertexArrayVerifier(void); 304 getMinSize(void) const305 int getMinSize(void) const 306 { 307 return 3 * 4; 308 } getAlignment(void) const309 int getAlignment(void) const 310 { 311 return 1; 312 } 313 bool verify(uint32_t buffer, const uint8_t *reference, int offset, int numBytes); 314 315 private: 316 glu::ShaderProgram *m_program; 317 uint32_t m_posLoc; 318 uint32_t m_byteVecLoc; 319 320 uint32_t m_vao; 321 uint32_t m_positionBuf; 322 uint32_t m_indexBuf; 323 }; 324 325 class IndexArrayVerifier : public BufferVerifierBase 326 { 327 public: 328 IndexArrayVerifier(glu::RenderContext &renderCtx, tcu::TestLog &log); 329 ~IndexArrayVerifier(void); 330 getMinSize(void) const331 int getMinSize(void) const 332 { 333 return 2; 334 } getAlignment(void) const335 int getAlignment(void) const 336 { 337 return 1; 338 } 339 bool verify(uint32_t buffer, const uint8_t *reference, int offset, int numBytes); 340 341 private: 342 glu::ShaderProgram *m_program; 343 uint32_t m_posLoc; 344 uint32_t m_colorLoc; 345 346 uint32_t m_vao; 347 uint32_t m_positionBuf; 348 uint32_t m_colorBuf; 349 }; 350 351 } // namespace BufferTestUtil 352 } // namespace gls 353 } // namespace deqp 354 355 #endif // _GLSBUFFERTESTUTIL_HPP 356