1 /*
2 * Copyright © 2015 Intel Corporation
3 *
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:
10 *
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.
14 *
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.
22 */
23
24 /**
25 * \file samples-pnames.c
26 * Verify a handful of conditions required by the spec for
27 * NUM_SAMPLE_COUNTS and SAMPLES pnames.
28 *
29 * This cover query1 overrun test, plus query1 api-error.
30 */
31
32 #include "common.h"
33
34 PIGLIT_GL_TEST_CONFIG_BEGIN
35
36 config.supports_gl_compat_version = 10;
37 config.window_visual = PIGLIT_GL_VISUAL_RGB;
38 config.khr_no_error_support = PIGLIT_NO_ERRORS;
39
40 PIGLIT_GL_TEST_CONFIG_END
41
42 static const GLenum without_multisample_targets[] = {
43 GL_TEXTURE_1D,
44 GL_TEXTURE_1D_ARRAY,
45 GL_TEXTURE_2D,
46 GL_TEXTURE_2D_ARRAY,
47 GL_TEXTURE_3D,
48 GL_TEXTURE_CUBE_MAP,
49 GL_TEXTURE_CUBE_MAP_ARRAY,
50 GL_TEXTURE_RECTANGLE,
51 GL_TEXTURE_BUFFER
52 };
53
54 static const GLenum non_renderable_internalformats[] = {
55 GL_COMPRESSED_RGB,
56 GL_COMPRESSED_RGBA,
57 GL_COMPRESSED_ALPHA,
58 GL_COMPRESSED_LUMINANCE,
59 GL_COMPRESSED_LUMINANCE_ALPHA,
60 GL_COMPRESSED_INTENSITY,
61 GL_COMPRESSED_SRGB,
62 GL_COMPRESSED_SRGB_ALPHA,
63 GL_COMPRESSED_SLUMINANCE,
64 GL_COMPRESSED_SLUMINANCE_ALPHA,
65 GL_COMPRESSED_RED,
66 GL_COMPRESSED_RG,
67 GL_COMPRESSED_RED_RGTC1,
68 GL_COMPRESSED_SIGNED_RED_RGTC1,
69 GL_COMPRESSED_RG_RGTC2,
70 GL_COMPRESSED_SIGNED_RG_RGTC2,
71 GL_COMPRESSED_RGBA_BPTC_UNORM_ARB,
72 GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_ARB,
73 GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB,
74 GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB,
75 GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
76 GL_COMPRESSED_RGBA_S3TC_DXT1_EXT,
77 GL_COMPRESSED_RGBA_S3TC_DXT3_EXT,
78 GL_COMPRESSED_RGBA_S3TC_DXT5_EXT,
79 GL_COMPRESSED_RGB_FXT1_3DFX,
80 GL_COMPRESSED_RGBA_FXT1_3DFX,
81 GL_COMPRESSED_SRGB_S3TC_DXT1_EXT,
82 GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT,
83 GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT,
84 GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT,
85 GL_COMPRESSED_LUMINANCE_LATC1_EXT,
86 GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT,
87 GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT,
88 GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT,
89 GL_YCBCR_MESA,
90 GL_GREEN_INTEGER_EXT,
91 GL_BLUE_INTEGER_EXT,
92 GL_ALPHA_INTEGER_EXT,
93 GL_RGB_INTEGER_EXT,
94 GL_RGBA_INTEGER_EXT,
95 GL_BGR_INTEGER_EXT,
96 GL_BGRA_INTEGER_EXT,
97 GL_LUMINANCE_INTEGER_EXT,
98 GL_LUMINANCE_ALPHA_INTEGER_EXT,
99 };
100
101 static const GLenum tex_shared_exponent_formats[] = {
102 GL_RGB9_E5,
103 };
104
105 enum piglit_result
piglit_display(void)106 piglit_display(void)
107 {
108 return PIGLIT_FAIL;
109 }
110
111 static void
fill_data_and_copy(test_data * data,test_data * data_copy)112 fill_data_and_copy(test_data *data,
113 test_data *data_copy)
114 {
115 unsigned i;
116
117 for (i = 0; i < test_data_get_params_size(data); i++) {
118 /* It seems very unlikely that an implementation will
119 * support 0xDEADBEEF samples*/
120 test_data_set_value_at_index(data, i, 0xDEADBEEF);
121 test_data_set_value_at_index(data_copy, i, 0xDEADBEEF);
122 }
123 }
124
125 static bool
check_params_unmodified(test_data * data,test_data * data_copy)126 check_params_unmodified(test_data *data,
127 test_data *data_copy)
128 {
129 unsigned i;
130 bool result;
131
132 for (i = 0; i < test_data_get_params_size(data); i++) {
133 result = test_data_equal_at_index(data, data_copy, i);
134
135 if (!result)
136 break;
137 }
138
139 return result;
140 }
141
142 static bool
try(const GLenum * targets,unsigned num_targets,const GLenum * internalformats,unsigned num_internalformats,GLenum pname,test_data * data)143 try(const GLenum *targets, unsigned num_targets,
144 const GLenum *internalformats, unsigned num_internalformats,
145 GLenum pname, test_data *data)
146 {
147 test_data *data_copy = test_data_clone(data);
148 bool pass = true;
149 unsigned i;
150 unsigned j;
151
152 for (i = 0; i < num_targets; i++) {
153 for (j = 0; j < num_internalformats; j++) {
154 bool error_test;
155 bool value_test;
156
157 /* Needed for to check if the data was unmodified */
158 fill_data_and_copy(data, data_copy);
159
160 /* First we try with size 0 */
161 test_data_execute_with_size(data, targets[i],
162 internalformats[j],
163 pname, 0);
164
165 error_test =
166 piglit_check_gl_error(GL_NO_ERROR);
167
168 value_test = check_params_unmodified(data, data_copy);
169
170 /* Now we try with a real size */
171 test_data_execute(data, targets[i], internalformats[j],
172 pname);
173
174 error_test = error_test &&
175 piglit_check_gl_error(GL_NO_ERROR);
176
177 if (pname == GL_NUM_SAMPLE_COUNTS) {
178 value_test = value_test &&
179 test_data_is_unsupported_response(data,
180 GL_NUM_SAMPLE_COUNTS);
181 } else {
182 value_test = value_test &&
183 check_params_unmodified(data, data_copy);
184 }
185
186 if (error_test && value_test)
187 continue;
188
189 print_failing_case(targets[i], internalformats[j], pname, data);
190
191 pass = false;
192 }
193 }
194
195 test_data_clear(&data_copy);
196
197 return pass;
198 }
199
200 static bool
check_num_sample_counts(void)201 check_num_sample_counts(void)
202 {
203 bool pass = true;
204 test_data *data = test_data_new(0, 64);
205 int testing64;
206
207 for (testing64 = 0; testing64 <= 1; testing64++) {
208 test_data_set_testing64(data, testing64);
209
210 /* The GL_ARB_internalformat_query2 spec says:
211 *
212 * - NUM_SAMPLE_COUNTS: The number of sample counts that would
213 * be returned by querying SAMPLES is returned in <params>.
214 * * If <internalformat> is not color-renderable,
215 * depth-renderable, or stencil-renderable (as defined
216 * in section 4.4.4) ...
217 */
218 pass = try(valid_targets, ARRAY_SIZE(valid_targets),
219 non_renderable_internalformats, ARRAY_SIZE(non_renderable_internalformats),
220 GL_NUM_SAMPLE_COUNTS, data)
221 && pass;
222
223 /* RGB9_E5 is not defined as color-renderable unless
224 * EXT_texture_shared_exponent is exposed.
225 */
226 if (!piglit_is_extension_supported("GL_EXT_texture_shared_exponent")) {
227 pass = try(valid_targets, ARRAY_SIZE(valid_targets),
228 tex_shared_exponent_formats, 1,
229 GL_NUM_SAMPLE_COUNTS, data)
230 && pass;
231 }
232
233 /*
234 * ... or if <target> does not support
235 * multiple samples (ie other than
236 * TEXTURE_2D_MULTISAMPLE,
237 * TEXTURE_2D_MULTISAMPLE_ARRAY, or RENDERBUFFER), 0 is
238 * returned.
239 */
240 pass = try(without_multisample_targets, ARRAY_SIZE(without_multisample_targets),
241 valid_internalformats, num_valid_internalformats,
242 GL_NUM_SAMPLE_COUNTS, data)
243 && pass;
244 }
245
246 piglit_report_subtest_result(pass ? PIGLIT_PASS : PIGLIT_FAIL,
247 "%s", piglit_get_gl_enum_name(GL_NUM_SAMPLE_COUNTS));
248
249 test_data_clear(&data);
250
251 return pass;
252 }
253
254 static bool
check_samples(void)255 check_samples(void)
256 {
257 bool pass = true;
258 test_data *data = test_data_new(0, 64);
259 int testing64;
260
261 /*
262 * Note: Checking if we are getting a proper min and maximum
263 * value, and if the returned values are positive in
264 * descending order is done at minmax test, as that one needs
265 * to use SAMPLES and NUM_SAMPLES_COUNT combined. This test
266 * file is about testing each pname individually.
267 */
268
269 for (testing64 = 0; testing64 <= 1; testing64++) {
270 test_data_set_testing64(data, testing64);
271 /* The GL_ARB_internalformat_query2 spec for SAMPLES says:
272 *
273 * If <internalformat> is not color-renderable, depth-renderable, or
274 * stencil-renderable (as defined in section 4.4.4),
275 */
276
277 pass = try(valid_targets, ARRAY_SIZE(valid_targets),
278 non_renderable_internalformats, ARRAY_SIZE(non_renderable_internalformats),
279 GL_SAMPLES, data)
280 && pass;
281
282 /* RGB9_E5 is not defined as color-renderable unless
283 * EXT_texture_shared_exponent is exposed.
284 */
285 if (!piglit_is_extension_supported("GL_EXT_texture_shared_exponent")) {
286 pass = try(valid_targets, ARRAY_SIZE(valid_targets),
287 tex_shared_exponent_formats, 1,
288 GL_SAMPLES, data)
289 && pass;
290 }
291
292 /*
293 * or if <target> does not support multiple samples (ie other
294 * than TEXTURE_2D_MULTISAMPLE, TEXTURE_2D_MULTISAMPLE_ARRAY,
295 * or RENDERBUFFER), <params> is not modified.
296 */
297
298 pass = try(without_multisample_targets, ARRAY_SIZE(without_multisample_targets),
299 valid_internalformats, num_valid_internalformats,
300 GL_SAMPLES, data)
301 && pass;
302 }
303
304 piglit_report_subtest_result(pass ? PIGLIT_PASS : PIGLIT_FAIL,
305 "%s", piglit_get_gl_enum_name(GL_SAMPLES));
306
307 test_data_clear(&data);
308
309 return pass;
310 }
311
312 void
piglit_init(int argc,char ** argv)313 piglit_init(int argc, char **argv)
314 {
315 bool pass = true;
316
317 piglit_require_extension("GL_ARB_framebuffer_object");
318 piglit_require_extension("GL_ARB_internalformat_query2");
319 initialize_valid_internalformats();
320
321 pass = check_num_sample_counts() && pass;
322 pass = check_samples() && pass;
323
324 piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
325 }
326