ovr_multiview: add some basic glsl tests
[piglit.git] / tests / spec / arb_bindless_texture / legal.c
blob1043afd5a2e6ade5025f0bdd6bcac8dbe6f2fdc7
1 /*
2 * Copyright (C) 2017 Valve Corporation
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 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * 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, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
24 /** \file
26 * Test cases which exercise legal operations when a texture/sampler object
27 * has been referenced by one or more texture handles.
30 #include "common.h"
32 static struct piglit_gl_test_config *piglit_config;
34 PIGLIT_GL_TEST_CONFIG_BEGIN
36 piglit_config = &config;
37 config.supports_gl_compat_version = 33;
38 config.supports_gl_core_version = 33;
39 config.khr_no_error_support = PIGLIT_NO_ERRORS;
41 PIGLIT_GL_TEST_CONFIG_END
43 static enum piglit_result
44 call_TexSubImage_when_texture_is_referenced(void *data)
46 int *img = malloc(16 * 16 * 4 * sizeof(unsigned));
47 GLuint tex;
49 tex = piglit_integer_texture(GL_RGBA32I, 16, 16, 0, 0);
51 glGetTextureHandleARB(tex);
52 if (!piglit_check_gl_error(GL_NO_ERROR)) {
53 free(img);
54 return PIGLIT_FAIL;
57 /* The ARB_bindless_texture spec says:
59 * "The contents of the images in a texture object may still be
60 * updated via commands such as TexSubImage*, CopyTexSubImage*, and
61 * CompressedTexSubImage*, and by rendering to a framebuffer object,
62 * even if the texture object is referenced by one or more texture
63 * handles."
65 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 16, 16, GL_RGBA_INTEGER,
66 GL_INT, img);
67 free(img);
68 if (!piglit_check_gl_error(GL_NO_ERROR))
69 return PIGLIT_FAIL;
71 return PIGLIT_PASS;
74 static enum piglit_result
75 call_CopyTexSubImage_when_texture_is_referenced(void *data)
77 GLuint tex;
79 tex = piglit_rgbw_texture(GL_RGBA8, 16, 16, GL_FALSE, GL_FALSE,
80 GL_UNSIGNED_BYTE);
82 glGetTextureHandleARB(tex);
83 if (!piglit_check_gl_error(GL_NO_ERROR))
84 return PIGLIT_FAIL;
86 /* The ARB_bindless_texture spec says:
88 * "The contents of the images in a texture object may still be
89 * updated via commands such as TexSubImage*, CopyTexSubImage*, and
90 * CompressedTexSubImage*, and by rendering to a framebuffer object,
91 * even if the texture object is referenced by one or more texture
92 * handles."
94 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 16, 16);
95 if (!piglit_check_gl_error(GL_NO_ERROR))
96 return PIGLIT_FAIL;
98 return PIGLIT_PASS;
101 static enum piglit_result
102 call_CompressedTexSubImage_when_texture_is_referenced(void *data)
104 void *compressed;
105 GLuint tex;
106 GLint size;
108 tex = piglit_rgbw_texture(GL_COMPRESSED_RGBA_BPTC_UNORM, 16, 16,
109 GL_FALSE, GL_FALSE, GL_UNSIGNED_NORMALIZED);
111 glGetTextureHandleARB(tex);
112 if (!piglit_check_gl_error(GL_NO_ERROR))
113 return PIGLIT_FAIL;
115 glGetTexLevelParameteriv(GL_TEXTURE_2D, 0,
116 GL_TEXTURE_COMPRESSED_IMAGE_SIZE, &size);
118 compressed = malloc(size);
119 glGetCompressedTexImage(GL_TEXTURE_2D, 0, compressed);
121 /* The ARB_bindless_texture spec says:
123 * "The contents of the images in a texture object may still be
124 * updated via commands such as TexSubImage*, CopyTexSubImage*, and
125 * CompressedTexSubImage*, and by rendering to a framebuffer object,
126 * even if the texture object is referenced by one or more texture
127 * handles."
129 glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 16, 16,
130 GL_COMPRESSED_RGBA_BPTC_UNORM, size,
131 compressed);
132 free(compressed);
133 if (!piglit_check_gl_error(GL_NO_ERROR))
134 return PIGLIT_FAIL;
136 return PIGLIT_PASS;
139 static enum piglit_result
140 call_BufferSubData_when_texture_is_referenced(void *data)
142 static const float red[4] = {1, 0, 0, 0};
143 GLuint tex, tbo;
145 glGenBuffers(1, &tbo);
146 glBindBuffer(GL_TEXTURE_BUFFER, tbo);
147 glBufferData(GL_TEXTURE_BUFFER, sizeof(red), red, GL_STATIC_DRAW);
149 glGenTextures(1, &tex);
150 glBindTexture(GL_TEXTURE_BUFFER, tex);
151 glTexBuffer(GL_TEXTURE_BUFFER, GL_RGBA32F, tbo);
153 glGetTextureHandleARB(tex);
154 if (!piglit_check_gl_error(GL_NO_ERROR))
155 return PIGLIT_FAIL;
157 /* The ARB_bindless_texture spec says:
159 * "The contents of the buffer object may still be updated via buffer
160 * update commands such as BufferSubData and MapBuffer*, or via the
161 * texture update commands, even if the buffer is bound to a texture
162 * while that buffer texture object is referenced by one or more
163 * texture handles."
165 glBufferSubData(GL_TEXTURE_BUFFER, 0, sizeof(red), red);
166 if (!piglit_check_gl_error(GL_NO_ERROR))
167 return PIGLIT_FAIL;
169 return PIGLIT_PASS;
172 static enum piglit_result
173 call_MapBuffer_when_texture_is_referenced(void *data)
175 static const float red[4] = {1, 0, 0, 0};
176 GLuint tex, tbo;
178 glGenBuffers(1, &tbo);
179 glBindBuffer(GL_TEXTURE_BUFFER, tbo);
180 glBufferData(GL_TEXTURE_BUFFER, sizeof(red), red, GL_STATIC_DRAW);
182 glGenTextures(1, &tex);
183 glBindTexture(GL_TEXTURE_BUFFER, tex);
184 glTexBuffer(GL_TEXTURE_BUFFER, GL_RGBA32F, tbo);
186 glGetTextureHandleARB(tex);
187 if (!piglit_check_gl_error(GL_NO_ERROR))
188 return PIGLIT_FAIL;
190 /* The ARB_bindless_texture spec says:
192 * "The contents of the buffer object may still be updated via buffer
193 * update commands such as BufferSubData and MapBuffer*, or via the
194 * texture update commands, even if the buffer is bound to a texture
195 * while that buffer texture object is referenced by one or more
196 * texture handles."
198 glMapBuffer(GL_TEXTURE_BUFFER, GL_READ_ONLY);
199 if (!piglit_check_gl_error(GL_NO_ERROR))
200 return PIGLIT_FAIL;
201 glUnmapBuffer(GL_TEXTURE_BUFFER);
203 return PIGLIT_PASS;
206 static const struct piglit_subtest subtests[] = {
208 "Call glTexSubImage* when a texture handle is referenced",
209 "call_TexSubImage_when_texture_referenced",
210 call_TexSubImage_when_texture_is_referenced,
211 NULL
214 "Call glCopyTexSubImage* when a texture handle is referenced",
215 "call_CopyTexSubImage_when_texture_referenced",
216 call_CopyTexSubImage_when_texture_is_referenced,
217 NULL
220 "Call glCompressedTexSubImage* when a texture handle is referenced",
221 "call_CompressedTexSubImage_when_texture_referenced",
222 call_CompressedTexSubImage_when_texture_is_referenced,
223 NULL
226 "Call glBufferSubData when a texture handle is referenced",
227 "call_BufferSubData_when_texture_referenced",
228 call_BufferSubData_when_texture_is_referenced,
229 NULL
232 "Call glMapBuffer when a texture handle is referenced",
233 "call_MapBuffer_when_texture_referenced",
234 call_MapBuffer_when_texture_is_referenced,
235 NULL
238 NULL,
239 NULL,
240 NULL,
241 NULL
245 enum piglit_result
246 piglit_display(void)
248 return PIGLIT_FAIL;
251 void
252 piglit_init(int argc, char **argv)
254 enum piglit_result result;
256 piglit_require_extension("GL_ARB_bindless_texture");
257 result = piglit_run_selected_subtests(subtests,
258 piglit_config->selected_subtests,
259 piglit_config->num_selected_subtests,
260 PIGLIT_SKIP);
261 piglit_report_result(result);