1 #ifndef _GLCROBUSTBUFFERACCESSBEHAVIORTESTS_HPP
2 #define _GLCROBUSTBUFFERACCESSBEHAVIORTESTS_HPP
3 /*-------------------------------------------------------------------------
4 * OpenGL Conformance Test Suite
5 * -----------------------------
7 * Copyright (c) 2016 The Khronos Group Inc.
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.
24 */ /*-------------------------------------------------------------------*/
26 * \file glcRobustBufferAccessBehaviorTests.hpp
27 * \brief Declares test classes for "Robust Buffer Access Behavior" functionality.
28 */ /*-------------------------------------------------------------------*/
30 #include "glcTestCase.hpp"
31 #include "glwDefs.hpp"
32 #include "glwEnums.hpp"
36 namespace RobustBufferAccessBehavior
38 /** Replace first occurance of <token> with <text> in <string> starting at <search_posistion>
40 void replaceToken(const glw::GLchar* token, size_t& search_position, const glw::GLchar* text, std::string& string);
42 /** Represents buffer instance
43 * Provides basic buffer functionality
50 Buffer(deqp::Context& context);
54 void InitData(glw::GLenum target, glw::GLenum usage, glw::GLsizeiptr size, const glw::GLvoid* data);
59 void BindBase(glw::GLuint index) const;
61 /* Public static routines */
63 static void Bind(const glw::Functions& gl, glw::GLuint id, glw::GLenum target);
64 static void BindBase(const glw::Functions& gl, glw::GLuint id, glw::GLenum target, glw::GLuint index);
65 static void Data(const glw::Functions& gl, glw::GLenum target, glw::GLenum usage, glw::GLsizeiptr size,
66 const glw::GLvoid* data);
67 static void Generate(const glw::Functions& gl, glw::GLuint& out_id);
68 static void SubData(const glw::Functions& gl, glw::GLenum target, glw::GLintptr offset, glw::GLsizeiptr size,
74 /* Public constants */
75 static const glw::GLuint m_invalid_id;
76 static const glw::GLuint m_n_targets = 13;
77 static const glw::GLenum m_targets[m_n_targets];
83 deqp::Context& m_context;
87 /** Represents framebuffer
88 * Provides basic functionality
95 Framebuffer(deqp::Context& context);
101 /* Public static routines */
102 static void AttachTexture(const glw::Functions& gl, glw::GLenum target, glw::GLenum attachment,
103 glw::GLuint texture_id, glw::GLint level, glw::GLuint width, glw::GLuint height);
105 static void Bind(const glw::Functions& gl, glw::GLenum target, glw::GLuint id);
106 static void Generate(const glw::Functions& gl, glw::GLuint& out_id);
111 /* Public constants */
112 static const glw::GLuint m_invalid_id;
116 deqp::Context& m_context;
119 /** Represents shader instance.
120 * Provides basic functionality for shaders.
127 Shader(deqp::Context& context);
131 void Init(glw::GLenum stage, const std::string& source);
134 /* Public static routines */
136 static void Compile(const glw::Functions& gl, glw::GLuint id);
137 static void Create(const glw::Functions& gl, glw::GLenum stage, glw::GLuint& out_id);
138 static void Source(const glw::Functions& gl, glw::GLuint id, const std::string& source);
143 /* Public constants */
144 static const glw::GLuint m_invalid_id;
148 deqp::Context& m_context;
151 /** Represents program instance.
152 * Provides basic functionality
159 Program(deqp::Context& context);
163 void Init(const std::string& compute_shader, const std::string& fragment_shader, const std::string& geometry_shader,
164 const std::string& tesselation_control_shader, const std::string& tesselation_evaluation_shader,
165 const std::string& vertex_shader);
172 /* Public static routines */
174 static void Attach(const glw::Functions& gl, glw::GLuint program_id, glw::GLuint shader_id);
175 static void Create(const glw::Functions& gl, glw::GLuint& out_id);
176 static void Link(const glw::Functions& gl, glw::GLuint id);
177 static void Use(const glw::Functions& gl, glw::GLuint id);
189 /* Public constants */
190 static const glw::GLuint m_invalid_id;
194 deqp::Context& m_context;
197 /** Represents texture instance
204 Texture(deqp::Context& context);
210 /* Public static routines */
212 static void Bind(const glw::Functions& gl, glw::GLuint id, glw::GLenum target);
214 static void CompressedImage(const glw::Functions& gl, glw::GLenum target, glw::GLint level,
215 glw::GLenum internal_format, glw::GLuint width, glw::GLuint height, glw::GLuint depth,
216 glw::GLsizei image_size, const glw::GLvoid* data);
218 static void Generate(const glw::Functions& gl, glw::GLuint& out_id);
220 static void GetData(const glw::Functions& gl, glw::GLint level, glw::GLenum target, glw::GLenum format,
221 glw::GLenum type, glw::GLvoid* out_data);
223 static void GetData(const glw::Functions& gl, glw::GLuint id, glw::GLint level, glw::GLuint width,
224 glw::GLuint height, glw::GLenum format, glw::GLenum type, glw::GLvoid* out_data);
226 static void GetLevelParameter(const glw::Functions& gl, glw::GLenum target, glw::GLint level, glw::GLenum pname,
229 static void Image(const glw::Functions& gl, glw::GLenum target, glw::GLint level, glw::GLenum internal_format,
230 glw::GLuint width, glw::GLuint height, glw::GLuint depth, glw::GLenum format, glw::GLenum type,
231 const glw::GLvoid* data);
233 static void Storage(const glw::Functions& gl, glw::GLenum target, glw::GLsizei levels, glw::GLenum internal_format,
234 glw::GLuint width, glw::GLuint height, glw::GLuint depth);
236 static void SubImage(const glw::Functions& gl, glw::GLenum target, glw::GLint level, glw::GLint x, glw::GLint y,
237 glw::GLint z, glw::GLsizei width, glw::GLsizei height, glw::GLsizei depth, glw::GLenum format,
238 glw::GLenum type, const glw::GLvoid* pixels);
243 /* Public constants */
244 static const glw::GLuint m_invalid_id;
248 deqp::Context& m_context;
251 /** Represents Vertex array object
252 * Provides basic functionality
259 VertexArray(deqp::Context& Context);
265 /* Public static methods */
266 static void Bind(const glw::Functions& gl, glw::GLuint id);
267 static void Generate(const glw::Functions& gl, glw::GLuint& out_id);
272 /* Public constants */
273 static const glw::GLuint m_invalid_id;
277 deqp::Context& m_context;
280 /** Implementation of test VertexBufferObjects. Description follows:
282 * This test verifies that any "out-of-bound" read from vertex buffer result with abnormal program exit
285 * - prepare vertex buffer with the following vertices:
295 * - prepare element buffer:
314 * - prepare program consisting of vertex and fragment shader that will output
316 * - prepare framebuffer with R8UI texture attached as color 0, filled with
318 * - execute draw call with invalid element buffer;
319 * - inspect contents of framebuffer, it is expected that it is filled with
321 * - clean framebuffer to value 128;
322 * - execute draw call with valid element buffer;
323 * - inspect contents of framebuffer, it is expected that it is filled with
326 class VertexBufferObjectsTest : public deqp::TestCase
330 VertexBufferObjectsTest(deqp::Context& context);
331 VertexBufferObjectsTest(deqp::Context& context, const char* name, const char* description);
332 virtual ~VertexBufferObjectsTest()
336 /* Public methods inherited from TestCase */
337 virtual tcu::TestNode::IterateResult iterate(void);
340 /* Protected methods */
341 virtual std::string getFragmentShader();
342 virtual std::string getVertexShader();
343 virtual void cleanTexture(glw::GLuint texture_id);
344 virtual bool verifyInvalidResults(glw::GLuint texture_id);
345 virtual bool verifyValidResults(glw::GLuint texture_id);
346 virtual bool verifyResults(glw::GLuint texture_id);
349 /** Implementation of test TexelFetch. Description follows:
351 * This test verifies that any "out-of-bound" fetch from texture result in
355 * - prepare program consisting of vertex, geometry and fragment shader that
356 * will output full-screen quad; Each fragment should receive value of
357 * corresponding texel from source texture; Use texelFetch function;
358 * - prepare 16x16 2D R8UI source texture filled with unique values;
359 * - prepare framebuffer with 16x16 R8UI texture as color attachment, filled
361 * - execute draw call;
362 * - inspect contents of framebuffer, it is expected to match source texture;
363 * - modify program so it will fetch invalid texels;
364 * - execute draw call;
365 * - inspect contents of framebuffer, it is expected that it will be filled
366 * with value 0 for RGB channels and with 0, 1 or the biggest representable
367 * integral number for alpha channel.
371 * - RG8_SNORM texture;
373 * - mipmap at level 1;
374 * - a texture with 4 samples.
376 class TexelFetchTest : public deqp::TestCase
380 TexelFetchTest(deqp::Context& context);
381 TexelFetchTest(deqp::Context& context, const glw::GLchar* name, const glw::GLchar* description);
382 virtual ~TexelFetchTest()
386 /* Public methods inherited from TestCase */
387 virtual tcu::TestNode::IterateResult iterate(void);
390 /* Protected enums */
409 /* Protected methods */
410 virtual const glw::GLchar* getTestCaseName() const;
411 virtual void prepareTexture(bool is_source, glw::GLuint texture_id);
413 /* Protected fields */
414 TEST_CASES m_test_case;
417 /* Protected methods */
418 virtual std::string getFragmentShader(bool is_case_valid);
419 virtual std::string getGeometryShader();
420 virtual std::string getVertexShader();
421 virtual bool verifyInvalidResults(glw::GLuint texture_id);
422 virtual bool verifyValidResults(glw::GLuint texture_id);
425 /** Implementation of test ImageLoadStore. Description follows:
427 * This test verifies that any "out-of-bound" access to image result in "zero"
430 * Modify TexelFetch test in the following aspects:
431 * - use compute shader instead of "draw" pipeline;
432 * - use imageLoad instead of texelFetch;
433 * - use destination image instead of framebuffer; Store texel with imageStore;
434 * - for each case from TexelFetch verify:
435 * * valid coordinates for source and destination images;
436 * * invalid coordinates for destination and valid ones for source image;
437 * * valid coordinates for destination and invalid ones for source image.
439 class ImageLoadStoreTest : public TexelFetchTest
443 ImageLoadStoreTest(deqp::Context& context);
444 ImageLoadStoreTest(deqp::Context& context, const char* name, const char* description);
445 virtual ~ImageLoadStoreTest()
449 /* Public methods inherited from TestCase */
450 virtual tcu::TestNode::IterateResult iterate(void);
453 /* Protected methods */
454 virtual std::string getComputeShader(VERSION version);
455 virtual void setTextures(glw::GLuint id_destination, glw::GLuint id_source);
456 virtual bool verifyInvalidResults(glw::GLuint texture_id);
457 virtual bool verifyValidResults(glw::GLuint texture_id);
460 /** Implementation of test StorageBuffer. Description follows:
462 * This test verifies that any "out-of-bound" access to buffer result in zero
466 * - prepare compute shader based on the following code snippet:
468 * uint dst_index = gl_LocalInvocationID.x;
469 * uint src_index = gl_LocalInvocationID.x;
470 * destination[dst_index] = source[src_index];
472 * where source and destination are storage buffers, defined as unsized arrays
474 * - prepare two buffers of 4 floats:
475 * * destination filled with value 1;
476 * * source filled with unique values;
477 * - dispatch program to copy all 4 values;
478 * - inspect program to verify that contents of source buffer were copied to
480 * - repeat steps for the following cases:
481 * * value of dst_index is equal to gl_LocalInvocationID.x + 16; It is
482 * expected that destination buffer will not be modified;
483 * * value of src_index is equal to gl_LocalInvocationID.x + 16; It is
484 * expected that destination buffer will be filled with value 0.
486 class StorageBufferTest : public deqp::TestCase
490 StorageBufferTest(deqp::Context& context);
491 StorageBufferTest(deqp::Context& context, const char* name, const char* description);
492 virtual ~StorageBufferTest()
496 /* Public methods inherited from TestCase */
497 virtual tcu::TestNode::IterateResult iterate(void);
500 /* Protected enums */
510 /* Private methods */
511 virtual std::string getComputeShader();
512 virtual bool verifyResults(glw::GLfloat* buffer_data);
514 /* Protected fields */
518 /** Implementation of test UniformBuffer. Description follows:
520 * This test verifies that any "out-of-bound" read from uniform buffer result
523 * Modify StorageBuffer test in the following aspects:
524 * - use uniform buffer for source instead of storage buffer;
525 * - ignore the case with invalid value of dst_index.
527 class UniformBufferTest : public deqp::TestCase
531 UniformBufferTest(deqp::Context& context);
532 UniformBufferTest(deqp::Context& context, const char* name, const char* description);
533 virtual ~UniformBufferTest()
537 /* Public methods inherited from TestCase */
538 virtual tcu::TestNode::IterateResult iterate(void);
541 /* Protected enums */
550 /* Protected methods */
551 virtual std::string getComputeShader();
552 virtual bool verifyResults(glw::GLfloat* buffer_data);
554 /* Protected fields */
557 } /* RobustBufferAccessBehavior */
559 /** Group class for multi bind conformance tests */
560 class RobustBufferAccessBehaviorTests : public deqp::TestCaseGroup
564 RobustBufferAccessBehaviorTests(deqp::Context& context);
565 virtual ~RobustBufferAccessBehaviorTests(void)
569 virtual void init(void);
572 /* Private methods */
573 RobustBufferAccessBehaviorTests(const RobustBufferAccessBehaviorTests& other);
574 RobustBufferAccessBehaviorTests& operator=(const RobustBufferAccessBehaviorTests& other);
579 #endif // _GLCROBUSTBUFFERACCESSBEHAVIORTESTS_HPP