ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / arb_stencil_texturing / blit_corrupts_state.c
blobdb3e9d8ea9fc3f6969ec8a109e457103ae519852
1 /*
2 * Copyright © 2016 Intel 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 /**
25 * \file blit-corrupts-state.c
26 * Tests for a bug in glBlitFramebuffer corrupting GL_DEPTH_STENCIL_TEXTURE_MODE
28 * The default state for GL_DEPTH_STENCIL_TEXTURE_MODE is GL_DEPTH_COMPONENT.
29 * Create two GL_DEPTH_STENCIL textures and two framebuffer objects. Attach
30 * one texture to each of the FBOs, and blit stencil from one to the other.
31 * After the blit operation verify that the state of
32 * GL_DEPTH_STENCIL_TEXTURE_MODE has not changed.
35 #include "piglit-util-gl.h"
37 PIGLIT_GL_TEST_CONFIG_BEGIN
39 config.supports_gl_compat_version = 30;
40 config.supports_gl_core_version = 31;
42 PIGLIT_GL_TEST_CONFIG_END
44 static bool
45 check_texture_state(GLenum target, unsigned line)
47 GLint value;
49 glGetTexParameteriv(target,
50 GL_DEPTH_STENCIL_TEXTURE_MODE,
51 &value);
52 if (value != GL_DEPTH_COMPONENT) {
53 printf("%s, %d: Expected GL_DEPTH_COMPONENT, got %s "
54 "(0x%04x).\n",
55 __func__, line,
56 piglit_get_gl_enum_name(value),
57 value);
58 return false;
61 return true;
64 static void
65 setup_texture(GLenum target)
67 /* All of the non-multisample targets should have the minification and
68 * the magnification set to GL_NEAREST. Setting the filters for
69 * multisample targets results in a GL error.
71 if (target != GL_TEXTURE_2D_MULTISAMPLE &&
72 target != GL_TEXTURE_2D_MULTISAMPLE_ARRAY) {
73 glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
74 glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
77 switch (target) {
78 case GL_TEXTURE_1D:
79 glTexImage1D(target,
80 0 /* level */,
81 GL_DEPTH24_STENCIL8,
82 16 /* width */,
83 0 /* border */,
84 GL_DEPTH_STENCIL,
85 GL_UNSIGNED_INT_24_8,
86 NULL);
87 break;
89 case GL_TEXTURE_2D:
90 case GL_TEXTURE_RECTANGLE:
91 case GL_TEXTURE_1D_ARRAY:
92 glTexImage2D(target,
93 0 /* level */,
94 GL_DEPTH24_STENCIL8,
95 16 /* width */,
96 16 /* height */,
97 0 /* border */,
98 GL_DEPTH_STENCIL,
99 GL_UNSIGNED_INT_24_8,
100 NULL);
101 break;
103 case GL_TEXTURE_CUBE_MAP:
104 for (unsigned i = 0; i < 6; i++) {
105 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i,
106 0 /* level */,
107 GL_DEPTH24_STENCIL8,
108 16 /* width */,
109 16 /* height */,
110 0 /* border */,
111 GL_DEPTH_STENCIL,
112 GL_UNSIGNED_INT_24_8,
113 NULL);
115 break;
117 case GL_TEXTURE_2D_ARRAY:
118 case GL_TEXTURE_CUBE_MAP_ARRAY:
119 glTexImage3D(target,
120 0 /* level */,
121 GL_DEPTH24_STENCIL8,
122 16 /* width */,
123 16 /* height */,
124 12 /* depth */,
125 0 /* border */,
126 GL_DEPTH_STENCIL,
127 GL_UNSIGNED_INT_24_8,
128 NULL);
129 break;
131 case GL_TEXTURE_2D_MULTISAMPLE:
132 glTexImage2DMultisample(target,
133 2 /* samples */,
134 GL_DEPTH24_STENCIL8,
135 16 /* width */,
136 16 /* height */,
137 GL_TRUE /* fixedsamplelocations */);
138 break;
140 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
141 glTexImage3DMultisample(target,
142 2 /* samples */,
143 GL_DEPTH24_STENCIL8,
144 16 /* width */,
145 16 /* height */,
146 2 /* depth */,
147 GL_TRUE /* fixedsamplelocations */);
148 break;
152 static void
153 setup_fbo(GLenum target, GLenum textarget, GLuint attachment)
155 GLenum status;
157 switch (textarget) {
158 case GL_TEXTURE_1D:
159 glFramebufferTexture1D(target, GL_DEPTH_STENCIL_ATTACHMENT,
160 textarget, attachment,
161 0 /* level */);
162 break;
164 case GL_TEXTURE_2D:
165 case GL_TEXTURE_2D_MULTISAMPLE:
166 case GL_TEXTURE_RECTANGLE:
167 glFramebufferTexture2D(target, GL_DEPTH_STENCIL_ATTACHMENT,
168 textarget, attachment,
169 0 /* level */);
170 break;
172 case GL_TEXTURE_1D_ARRAY:
173 case GL_TEXTURE_2D_ARRAY:
174 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
175 case GL_TEXTURE_CUBE_MAP:
176 case GL_TEXTURE_CUBE_MAP_ARRAY:
177 glFramebufferTextureLayer(target, GL_DEPTH_STENCIL_ATTACHMENT,
178 attachment,
179 0 /* level */,
180 0 /* layer */);
181 break;
184 status = glCheckFramebufferStatus(target);
185 if (status != GL_FRAMEBUFFER_COMPLETE) {
186 printf("Framebuffer incomplete: %s (0x%04x).\n",
187 piglit_get_gl_enum_name(status),
188 status);
189 piglit_report_result(PIGLIT_FAIL);
193 static const struct {
194 GLenum target;
195 const char *required_extension;
196 } test_vectors[] = {
197 { GL_TEXTURE_1D, NULL },
198 { GL_TEXTURE_2D, NULL },
200 { GL_TEXTURE_RECTANGLE, "GL_ARB_texture_rectangle" },
201 { GL_TEXTURE_2D_MULTISAMPLE, "GL_ARB_texture_multisample" },
202 { GL_TEXTURE_2D_MULTISAMPLE_ARRAY, "GL_ARB_texture_multisample" },
205 * These do not require any extensions because they are part of OpenGL
206 * 3.0. This is especially important for GL_TEXTURE_CUBE_MAP. This
207 * target existed before 3.0, but it could not be used for
208 * GL_DEPTH_COMPONENT or GL_DEPTH_STENCIL formats before then.
210 /*@{*/
211 { GL_TEXTURE_1D_ARRAY, NULL },
212 { GL_TEXTURE_2D_ARRAY, NULL },
213 { GL_TEXTURE_CUBE_MAP, NULL },
214 /*@}*/
216 { GL_TEXTURE_CUBE_MAP_ARRAY, "GL_ARB_texture_cube_map_array" },
219 static NORETURN void
220 usage_and_exit(const char *name)
222 printf("Usage: %s <target>\n\n"
223 "Where <target> is one of:\n",
224 name);
226 for (unsigned i = 0; i < ARRAY_SIZE(test_vectors); i++) {
227 const char *target_name =
228 piglit_get_gl_enum_name(test_vectors[i].target);
229 if (test_vectors[i].required_extension == NULL)
230 printf("\t%s\n",
231 target_name);
232 else
233 printf("\t%s (requires %s)\n",
234 target_name,
235 test_vectors[i].required_extension);
238 piglit_report_result(PIGLIT_FAIL);
241 void
242 piglit_init(int argc, char **argv)
244 GLuint tex[2];
245 GLuint fbo[2];
246 bool pass = true;
247 GLenum target = 0;
249 piglit_require_extension("GL_ARB_stencil_texturing");
251 if (argc != 2)
252 usage_and_exit(argv[0]);
254 for (unsigned i = 0; i < ARRAY_SIZE(test_vectors); i++) {
255 if (strcmp(piglit_get_gl_enum_name(test_vectors[i].target),
256 argv[1]) == 0) {
257 if (test_vectors[i].required_extension != NULL)
258 piglit_require_extension(test_vectors[i].required_extension);
260 target = test_vectors[i].target;
261 break;
265 if (target == 0)
266 usage_and_exit(argv[0]);
268 glGenTextures(ARRAY_SIZE(tex), tex);
269 glGenFramebuffers(ARRAY_SIZE(fbo), fbo);
271 glBindTexture(target, tex[0]);
272 setup_texture(target);
273 pass = check_texture_state(target, __LINE__) && pass;
275 glBindTexture(target, tex[1]);
276 setup_texture(target);
277 pass = check_texture_state(target, __LINE__) && pass;
279 glBindTexture(target, 0);
281 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo[0]);
282 glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo[1]);
284 setup_fbo(GL_DRAW_FRAMEBUFFER, target, tex[0]);
285 setup_fbo(GL_READ_FRAMEBUFFER, target, tex[1]);
287 glBlitFramebuffer(0, 0, 15, 15,
288 0, 0, 15, 15,
289 GL_STENCIL_BUFFER_BIT, GL_NEAREST);
291 glBindTexture(target, tex[0]);
292 pass = check_texture_state(target, __LINE__) && pass;
294 glBindTexture(target, tex[1]);
295 pass = check_texture_state(target, __LINE__) && pass;
297 glBindTexture(target, 0);
298 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
299 glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
300 glDeleteTextures(ARRAY_SIZE(tex), tex);
301 glDeleteFramebuffers(ARRAY_SIZE(fbo), fbo);
303 pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
305 piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
308 enum piglit_result
309 piglit_display(void)
311 /* UNREACHABLE */
312 return PIGLIT_FAIL;