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.
22 * \file glcRobustBufferAccessBehaviorTests.hpp
23 * \brief Declares test classes for "Robust Buffer Access Behavior" functionality.
24 */ /*-------------------------------------------------------------------*/
26 #include "glcRobustnessTests.hpp"
27 #include "glcTestCase.hpp"
28 #include "glwDefs.hpp"
29 #include "glwEnums.hpp"
35 namespace RobustBufferAccessBehavior
37 /** Replace first occurance of <token> with <text> in <string> starting at <search_posistion>
39 void replaceToken(const glw::GLchar* token, size_t& search_position, const glw::GLchar* text, std::string& string);
41 /** Represents buffer instance
42 * Provides basic buffer functionality
49 Buffer(const glw::Functions& gl);
53 void InitData(glw::GLenum target, glw::GLenum usage, glw::GLsizeiptr size, const glw::GLvoid* data);
58 void BindBase(glw::GLuint index) const;
60 /* Public static routines */
62 static void Bind(const glw::Functions& gl, glw::GLuint id, glw::GLenum target);
63 static void BindBase(const glw::Functions& gl, glw::GLuint id, glw::GLenum target, glw::GLuint index);
64 static void Data(const glw::Functions& gl, glw::GLenum target, glw::GLenum usage, glw::GLsizeiptr size,
65 const glw::GLvoid* data);
66 static void Generate(const glw::Functions& gl, glw::GLuint& out_id);
67 static void SubData(const glw::Functions& gl, glw::GLenum target, glw::GLintptr offset, glw::GLsizeiptr size,
73 /* Public constants */
74 static const glw::GLuint m_invalid_id;
75 static const glw::GLuint m_n_targets = 13;
76 static const glw::GLenum m_targets[m_n_targets];
82 const glw::Functions& m_gl;
86 /** Represents framebuffer
87 * Provides basic functionality
94 Framebuffer(const glw::Functions& gl);
100 /* Public static routines */
101 static void AttachTexture(const glw::Functions& gl, glw::GLenum target, glw::GLenum attachment,
102 glw::GLuint texture_id, glw::GLint level, glw::GLuint width, glw::GLuint height);
104 static void Bind(const glw::Functions& gl, glw::GLenum target, glw::GLuint id);
105 static void Generate(const glw::Functions& gl, glw::GLuint& out_id);
110 /* Public constants */
111 static const glw::GLuint m_invalid_id;
115 const glw::Functions& m_gl;
118 /** Represents shader instance.
119 * Provides basic functionality for shaders.
126 Shader(const glw::Functions& gl);
130 void Init(glw::GLenum stage, const std::string& source);
133 /* Public static routines */
135 static void Compile(const glw::Functions& gl, glw::GLuint id);
136 static void Create(const glw::Functions& gl, glw::GLenum stage, glw::GLuint& out_id);
137 static void Source(const glw::Functions& gl, glw::GLuint id, const std::string& source);
142 /* Public constants */
143 static const glw::GLuint m_invalid_id;
147 const glw::Functions& m_gl;
150 /** Represents program instance.
151 * Provides basic functionality
158 Program(const glw::Functions& gl);
162 void Init(const std::string& compute_shader, const std::string& fragment_shader, const std::string& geometry_shader,
163 const std::string& tesselation_control_shader, const std::string& tesselation_evaluation_shader,
164 const std::string& vertex_shader);
171 /* Public static routines */
173 static void Attach(const glw::Functions& gl, glw::GLuint program_id, glw::GLuint shader_id);
174 static void Create(const glw::Functions& gl, glw::GLuint& out_id);
175 static void Link(const glw::Functions& gl, glw::GLuint id);
176 static void Use(const glw::Functions& gl, glw::GLuint id);
188 /* Public constants */
189 static const glw::GLuint m_invalid_id;
193 const glw::Functions& m_gl;
196 /** Represents texture instance
203 Texture(const glw::Functions& gl);
209 /* Public static routines */
211 static void Bind(const glw::Functions& gl, glw::GLuint id, glw::GLenum target);
213 static void CompressedImage(const glw::Functions& gl, glw::GLenum target, glw::GLint level,
214 glw::GLenum internal_format, glw::GLuint width, glw::GLuint height, glw::GLuint depth,
215 glw::GLsizei image_size, const glw::GLvoid* data);
217 static void Generate(const glw::Functions& gl, glw::GLuint& out_id);
219 static void GetData(const glw::Functions& gl, glw::GLint level, glw::GLenum target, glw::GLenum format,
220 glw::GLenum type, glw::GLvoid* out_data);
222 static void GetData(const glw::Functions& gl, glw::GLuint id, glw::GLint level, glw::GLuint width,
223 glw::GLuint height, glw::GLenum format, glw::GLenum type, glw::GLvoid* out_data);
225 static void GetLevelParameter(const glw::Functions& gl, glw::GLenum target, glw::GLint level, glw::GLenum pname,
228 static void Image(const glw::Functions& gl, glw::GLenum target, glw::GLint level, glw::GLenum internal_format,
229 glw::GLuint width, glw::GLuint height, glw::GLuint depth, glw::GLenum format, glw::GLenum type,
230 const glw::GLvoid* data);
232 static void Storage(const glw::Functions& gl, glw::GLenum target, glw::GLsizei levels, glw::GLenum internal_format,
233 glw::GLuint width, glw::GLuint height, glw::GLuint depth);
235 static void SubImage(const glw::Functions& gl, glw::GLenum target, glw::GLint level, glw::GLint x, glw::GLint y,
236 glw::GLint z, glw::GLsizei width, glw::GLsizei height, glw::GLsizei depth, glw::GLenum format,
237 glw::GLenum type, const glw::GLvoid* pixels);
242 /* Public constants */
243 static const glw::GLuint m_invalid_id;
247 const glw::Functions& m_gl;
250 /** Represents Vertex array object
251 * Provides basic functionality
258 VertexArray(const glw::Functions& gl);
264 /* Public static methods */
265 static void Bind(const glw::Functions& gl, glw::GLuint id);
266 static void Generate(const glw::Functions& gl, glw::GLuint& out_id);
271 /* Public constants */
272 static const glw::GLuint m_invalid_id;
276 const glw::Functions& m_gl;
279 class RobustnessBase : public tcu::TestCase
282 RobustnessBase(tcu::TestContext& testCtx, const char* name, const char* description, glu::ApiType apiType);
284 glu::RenderContext* createRobustContext(
285 glu::ResetNotificationStrategy reset = glu::RESET_NOTIFICATION_STRATEGY_NO_RESET_NOTIFICATION);
288 glu::ApiType m_api_type;
289 bool m_context_is_es;
290 bool m_has_khr_robust_buffer_access;
292 std::map<std::string, std::string> m_specializationMap;
295 /** Implementation of test VertexBufferObjects. Description follows:
297 * This test verifies that any "out-of-bound" read from vertex buffer result with abnormal program exit
300 * - prepare vertex buffer with the following vertices:
310 * - prepare element buffer:
329 * - prepare program consisting of vertex and fragment shader that will output
331 * - prepare framebuffer with R8UI texture attached as color 0, filled with
333 * - execute draw call with invalid element buffer;
334 * - inspect contents of framebuffer, it is expected that it is filled with
336 * - clean framebuffer to value 128;
337 * - execute draw call with valid element buffer;
338 * - inspect contents of framebuffer, it is expected that it is filled with
341 class VertexBufferObjectsTest : public RobustnessBase
345 VertexBufferObjectsTest(tcu::TestContext& testCtx, glu::ApiType apiType);
346 virtual ~VertexBufferObjectsTest()
350 /* Public methods inherited from TestCase */
351 virtual tcu::TestNode::IterateResult iterate(void);
354 /* Protected methods */
355 std::string getFragmentShader();
356 std::string getVertexShader();
357 void cleanTexture(const glw::Functions& gl, glw::GLuint texture_id);
358 bool verifyInvalidResults(const glw::Functions& gl, glw::GLuint texture_id);
359 bool verifyValidResults(const glw::Functions& gl, glw::GLuint texture_id);
360 bool verifyResults(const glw::Functions& gl, glw::GLuint texture_id);
363 /** Implementation of test TexelFetch. Description follows:
365 * This test verifies that any "out-of-bound" fetch from texture result in
369 * - prepare program consisting of vertex, geometry and fragment shader that
370 * will output full-screen quad; Each fragment should receive value of
371 * corresponding texel from source texture; Use texelFetch function;
372 * - prepare 16x16 2D R8UI source texture filled with unique values;
373 * - prepare framebuffer with 16x16 R8UI texture as color attachment, filled
375 * - execute draw call;
376 * - inspect contents of framebuffer, it is expected to match source texture;
377 * - modify program so it will fetch invalid texels;
378 * - execute draw call;
379 * - inspect contents of framebuffer, it is expected that it will be filled
380 * with value 0 for RGB channels and with 0, 1 or the biggest representable
381 * integral number for alpha channel.
385 * - RG8_SNORM texture;
387 * - mipmap at level 1;
388 * - a texture with 4 samples.
390 class TexelFetchTest : public RobustnessBase
394 TexelFetchTest(tcu::TestContext& testCtx, glu::ApiType apiType);
395 TexelFetchTest(tcu::TestContext& testCtx, const char* name, const char* description, glu::ApiType apiType);
396 virtual ~TexelFetchTest()
400 /* Public methods inherited from TestCase */
401 virtual tcu::TestNode::IterateResult iterate(void);
404 /* Protected enums */
423 /* Protected methods */
424 const glw::GLchar* getTestCaseName() const;
425 void prepareTexture(const glw::Functions& gl, bool is_source, glw::GLuint texture_id);
427 /* Protected fields */
428 TEST_CASES m_test_case;
431 /* Protected methods */
432 std::string getFragmentShader(const glu::ContextType& contextType, bool is_case_valid,
433 glw::GLuint fetch_offset = 0);
434 std::string getGeometryShader();
435 std::string getVertexShader();
436 virtual bool verifyInvalidResults(const glw::Functions& gl, glw::GLuint texture_id);
437 virtual bool verifyValidResults(const glw::Functions& gl, glw::GLuint texture_id);
440 /** Implementation of test ImageLoadStore. Description follows:
442 * This test verifies that any "out-of-bound" access to image result in "zero"
445 * Modify TexelFetch test in the following aspects:
446 * - use compute shader instead of "draw" pipeline;
447 * - use imageLoad instead of texelFetch;
448 * - use destination image instead of framebuffer; Store texel with imageStore;
449 * - for each case from TexelFetch verify:
450 * * valid coordinates for source and destination images;
451 * * invalid coordinates for destination and valid ones for source image;
452 * * valid coordinates for destination and invalid ones for source image.
454 class ImageLoadStoreTest : public TexelFetchTest
458 ImageLoadStoreTest(tcu::TestContext& testCtx, glu::ApiType apiType);
459 virtual ~ImageLoadStoreTest()
463 /* Public methods inherited from TestCase */
464 virtual tcu::TestNode::IterateResult iterate(void);
467 /* Protected methods */
468 std::string getComputeShader(VERSION version, glw::GLuint coord_offset = 0, glw::GLuint sample_offset = 0);
469 void setTextures(const glw::Functions& gl, glw::GLuint id_destination, glw::GLuint id_source);
470 bool verifyInvalidResults(const glw::Functions& gl, glw::GLuint texture_id);
471 bool verifyValidResults(const glw::Functions& gl, glw::GLuint texture_id);
474 /** Implementation of test StorageBuffer. Description follows:
476 * This test verifies that any "out-of-bound" access to buffer result in zero
480 * - prepare compute shader based on the following code snippet:
482 * uint dst_index = gl_LocalInvocationID.x;
483 * uint src_index = gl_LocalInvocationID.x;
484 * destination[dst_index] = source[src_index];
486 * where source and destination are storage buffers, defined as unsized arrays
488 * - prepare two buffers of 4 floats:
489 * * destination filled with value 1;
490 * * source filled with unique values;
491 * - dispatch program to copy all 4 values;
492 * - inspect program to verify that contents of source buffer were copied to
494 * - repeat steps for the following cases:
495 * * value of dst_index is equal to gl_LocalInvocationID.x + 16; It is
496 * expected that destination buffer will not be modified;
497 * * value of src_index is equal to gl_LocalInvocationID.x + 16; It is
498 * expected that destination buffer will be filled with value 0.
500 class StorageBufferTest : public RobustnessBase
504 StorageBufferTest(tcu::TestContext& testCtx, glu::ApiType apiType);
505 virtual ~StorageBufferTest()
509 /* Public methods inherited from TestCase */
510 virtual tcu::TestNode::IterateResult iterate(void);
513 /* Protected enums */
523 /* Private methods */
524 std::string getComputeShader(glw::GLuint offset);
525 bool verifyResults(glw::GLfloat* buffer_data);
527 /* Protected fields */
530 /* Protected constants */
531 static const glw::GLfloat m_destination_data[4];
532 static const glw::GLfloat m_source_data[4];
535 /** Implementation of test UniformBuffer. Description follows:
537 * This test verifies that any "out-of-bound" read from uniform buffer result
540 * Modify StorageBuffer test in the following aspects:
541 * - use uniform buffer for source instead of storage buffer;
542 * - ignore the case with invalid value of dst_index.
544 class UniformBufferTest : public RobustnessBase
548 UniformBufferTest(tcu::TestContext& testCtx, glu::ApiType apiType);
549 virtual ~UniformBufferTest()
553 /* Public methods inherited from TestCase */
554 virtual tcu::TestNode::IterateResult iterate(void);
557 /* Protected enums */
566 /* Protected methods */
567 std::string getComputeShader(glw::GLuint offset);
568 bool verifyResults(glw::GLfloat* buffer_data);
570 /* Protected fields */
573 } /* RobustBufferAccessBehavior */
575 /** Group class for multi bind conformance tests */
576 class RobustBufferAccessBehaviorTests : public tcu::TestCaseGroup
580 RobustBufferAccessBehaviorTests(tcu::TestContext& testCtx, glu::ApiType apiType);
581 virtual ~RobustBufferAccessBehaviorTests(void)
585 virtual void init(void);
588 /* Private methods */
589 RobustBufferAccessBehaviorTests(const RobustBufferAccessBehaviorTests& other);
590 RobustBufferAccessBehaviorTests& operator=(const RobustBufferAccessBehaviorTests& other);
592 glu::ApiType m_ApiType;
597 #endif // _GLCROBUSTBUFFERACCESSBEHAVIORTESTS_HPP