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
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
26 * Test cases which exercise legal operations when a texture/sampler object
27 * has been referenced by one or more texture handles.
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));
49 tex
= piglit_integer_texture(GL_RGBA32I
, 16, 16, 0, 0);
51 glGetTextureHandleARB(tex
);
52 if (!piglit_check_gl_error(GL_NO_ERROR
)) {
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
65 glTexSubImage2D(GL_TEXTURE_2D
, 0, 0, 0, 16, 16, GL_RGBA_INTEGER
,
68 if (!piglit_check_gl_error(GL_NO_ERROR
))
74 static enum piglit_result
75 call_CopyTexSubImage_when_texture_is_referenced(void *data
)
79 tex
= piglit_rgbw_texture(GL_RGBA8
, 16, 16, GL_FALSE
, GL_FALSE
,
82 glGetTextureHandleARB(tex
);
83 if (!piglit_check_gl_error(GL_NO_ERROR
))
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
94 glCopyTexSubImage2D(GL_TEXTURE_2D
, 0, 0, 0, 0, 0, 16, 16);
95 if (!piglit_check_gl_error(GL_NO_ERROR
))
101 static enum piglit_result
102 call_CompressedTexSubImage_when_texture_is_referenced(void *data
)
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
))
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
129 glCompressedTexSubImage2D(GL_TEXTURE_2D
, 0, 0, 0, 16, 16,
130 GL_COMPRESSED_RGBA_BPTC_UNORM
, size
,
133 if (!piglit_check_gl_error(GL_NO_ERROR
))
139 static enum piglit_result
140 call_BufferSubData_when_texture_is_referenced(void *data
)
142 static const float red
[4] = {1, 0, 0, 0};
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
))
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
165 glBufferSubData(GL_TEXTURE_BUFFER
, 0, sizeof(red
), red
);
166 if (!piglit_check_gl_error(GL_NO_ERROR
))
172 static enum piglit_result
173 call_MapBuffer_when_texture_is_referenced(void *data
)
175 static const float red
[4] = {1, 0, 0, 0};
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
))
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
198 glMapBuffer(GL_TEXTURE_BUFFER
, GL_READ_ONLY
);
199 if (!piglit_check_gl_error(GL_NO_ERROR
))
201 glUnmapBuffer(GL_TEXTURE_BUFFER
);
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
,
214 "Call glCopyTexSubImage* when a texture handle is referenced",
215 "call_CopyTexSubImage_when_texture_referenced",
216 call_CopyTexSubImage_when_texture_is_referenced
,
220 "Call glCompressedTexSubImage* when a texture handle is referenced",
221 "call_CompressedTexSubImage_when_texture_referenced",
222 call_CompressedTexSubImage_when_texture_is_referenced
,
226 "Call glBufferSubData when a texture handle is referenced",
227 "call_BufferSubData_when_texture_referenced",
228 call_BufferSubData_when_texture_is_referenced
,
232 "Call glMapBuffer when a texture handle is referenced",
233 "call_MapBuffer_when_texture_referenced",
234 call_MapBuffer_when_texture_is_referenced
,
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
,
261 piglit_report_result(result
);