ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / ext_memory_object / api-errors.c
blob15b4b1c43473bd8f4ab82ff9689bf622d8518a6e
1 /*
2 * Copyright (c) 2017 Timothy Arceri
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NON-INFRINGEMENT. IN NO EVENT SHALL VMWARE AND/OR THEIR SUPPLIERS
19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
25 /**
26 * Tests that api errors are thrown where expected for the
27 * GL_EXT_memory_object extension.
30 #include "piglit-util-gl.h"
32 PIGLIT_GL_TEST_CONFIG_BEGIN
34 config.supports_gl_compat_version = 20; /* Need 2.0 for DSA tests */
35 config.window_visual = PIGLIT_GL_VISUAL_RGBA | PIGLIT_GL_VISUAL_DOUBLE;
36 config.khr_no_error_support = PIGLIT_HAS_ERRORS;
38 PIGLIT_GL_TEST_CONFIG_END
41 static bool
42 test_tex_storage_errors(GLenum target, bool dsa)
44 const GLint width = 64, height = 4, depth = 8;
45 GLuint tex;
47 assert(target == GL_TEXTURE_1D ||
48 target == GL_TEXTURE_2D ||
49 target == GL_TEXTURE_3D);
51 glGenTextures(1, &tex);
52 glBindTexture(target, tex);
54 /* Test that passing 0 for <memory> results in an error. */
55 if (target == GL_TEXTURE_1D) {
56 if (dsa) {
57 glTextureStorageMem1DEXT(tex, 1, GL_RGBA8, width, 0,
58 0);
59 } else {
60 glTexStorageMem1DEXT(target, 1, GL_RGBA8, width, 0,
61 0);
64 else if (target == GL_TEXTURE_2D) {
65 if (dsa) {
66 glTextureStorageMem2DEXT(tex, 1, GL_RGBA8, width,
67 height, 0, 0);
68 } else {
69 glTexStorageMem2DEXT(target, 1, GL_RGBA8, width,
70 height, 0, 0);
73 else if (target == GL_TEXTURE_3D) {
74 if (dsa) {
75 glTextureStorageMem3DEXT(tex, 1, GL_RGBA8, width,
76 height, depth, 0, 0);
77 } else {
78 glTexStorageMem3DEXT(target, 1, GL_RGBA8, width,
79 height, depth, 0, 0);
83 /* From the EXT_external_objects spec:
85 * "An INVALID_VALUE error is generated if <memory> is 0 ..."
87 return piglit_check_gl_error(GL_INVALID_VALUE);
90 static bool
91 test_tex_storage_ms_errors(GLenum target, bool dsa)
93 const GLint width = 64, height = 4, depth = 8;
94 GLuint tex;
96 assert(target == GL_TEXTURE_2D_MULTISAMPLE ||
97 target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY);
99 glGenTextures(1, &tex);
100 glBindTexture(target, tex);
102 /* Test that passing 0 for <memory> results in an error. */
103 if (target == GL_TEXTURE_2D_MULTISAMPLE) {
104 if (dsa) {
105 glTextureStorageMem2DMultisampleEXT(tex, 1, GL_RGBA8,
106 width, height,
107 GL_FALSE, 0, 0);
108 } else {
109 glTexStorageMem2DMultisampleEXT(target, 1, GL_RGBA8,
110 width, height,
111 GL_FALSE, 0, 0);
114 else if (target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY) {
115 if (dsa) {
116 glTextureStorageMem3DMultisampleEXT(tex, 1, GL_RGBA8,
117 width, height,
118 depth, GL_FALSE,
119 0, 0);
120 } else {
121 glTexStorageMem3DMultisampleEXT(target, 1, GL_RGBA8,
122 width, height,
123 depth, GL_FALSE,
124 0, 0);
128 /* From the EXT_external_objects spec:
130 * "An INVALID_VALUE error is generated if <memory> is 0 ..."
132 return piglit_check_gl_error(GL_INVALID_VALUE);
135 #define BUF_SIZE (12 * 4 * sizeof(float))
137 static bool
138 test_buffer_storage_errors(bool dsa)
140 GLuint buffer;
142 glGenBuffers(1, &buffer);
143 glBindBuffer(GL_ARRAY_BUFFER, buffer);
145 /* Test that passing 0 for <memory> results in an error. */
146 if (dsa) {
147 glNamedBufferStorageMemEXT(buffer, BUF_SIZE, 0, 0);
148 } else {
149 glBufferStorageMemEXT(GL_ARRAY_BUFFER, BUF_SIZE, 0, 0);
152 /* From the EXT_external_objects spec:
154 * "An INVALID_VALUE error is generated if <memory> is 0 ..."
156 return piglit_check_gl_error(GL_INVALID_VALUE);
159 #define X(f, desc) \
160 do { \
161 const bool subtest_pass = (f); \
162 piglit_report_subtest_result(subtest_pass \
163 ? PIGLIT_PASS : PIGLIT_FAIL, \
164 (desc)); \
165 pass = pass && subtest_pass; \
166 } while (0)
168 enum piglit_result
169 piglit_display(void)
171 /* TODO: currently this test only tests for errors when we pass 0 for
172 * <memory>. We need to test for other errors.
175 bool pass = true;
176 bool dsa = piglit_is_extension_supported("GL_ARB_direct_state_access");
178 X(test_tex_storage_errors(GL_TEXTURE_1D, false), "1D texture");
179 X(test_tex_storage_errors(GL_TEXTURE_2D, false), "2D texture");
180 X(test_tex_storage_errors(GL_TEXTURE_3D, false), "3D texture");
182 if (dsa) {
183 X(test_tex_storage_errors(GL_TEXTURE_1D, true), "1D texture direct state access");
184 X(test_tex_storage_errors(GL_TEXTURE_2D, true), "2D texture direct state access");
185 X(test_tex_storage_errors(GL_TEXTURE_3D, true), "3D texture direct state access");
188 if (piglit_is_extension_supported("GL_ARB_texture_storage_multisample")) {
189 X(test_tex_storage_ms_errors(GL_TEXTURE_2D_MULTISAMPLE, false), "2D texture ms");
190 X(test_tex_storage_ms_errors(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, false), "3D texture ms");
192 if (dsa) {
193 X(test_tex_storage_ms_errors(GL_TEXTURE_2D_MULTISAMPLE, true), "2D texture ms direct state access");
194 X(test_tex_storage_ms_errors(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, true), "3D texture ms direct state access");
198 if (piglit_is_extension_supported("GL_ARB_buffer_storage")) {
199 X(test_buffer_storage_errors(false), "buffer storage");
201 if (dsa) {
202 X(test_buffer_storage_errors(true), "buffer storage direct state access");
206 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
210 void
211 piglit_init(int argc, char **argv)
213 /* From the EXT_external_objects spec:
215 * "GL_EXT_memory_object requires ARB_texture_storage or a
216 * version of OpenGL or OpenGL ES that incorporates it."
218 piglit_require_extension("GL_ARB_texture_storage");
219 piglit_require_extension("GL_EXT_memory_object");