File: samples-pnames.c

package info (click to toggle)
piglit 0~git20200212-f4710c51b-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 106,972 kB
  • sloc: ansic: 263,763; xml: 48,941; python: 29,918; lisp: 19,789; cpp: 12,142; sh: 22; makefile: 20; pascal: 5
file content (325 lines) | stat: -rw-r--r-- 11,068 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
/*
 * Copyright © 2015 Intel Corporation
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 * IN THE SOFTWARE.
 */

/**
 * \file samples-pnames.c
 * Verify a handful of conditions required by the spec for
 * NUM_SAMPLE_COUNTS and SAMPLES pnames.
 *
 * This cover query1 overrun test, plus query1 api-error.
 */

#include "common.h"

PIGLIT_GL_TEST_CONFIG_BEGIN

	config.supports_gl_compat_version = 10;
	config.window_visual = PIGLIT_GL_VISUAL_RGB;
	config.khr_no_error_support = PIGLIT_NO_ERRORS;

PIGLIT_GL_TEST_CONFIG_END

static const GLenum without_multisample_targets[] = {
        GL_TEXTURE_1D,
        GL_TEXTURE_1D_ARRAY,
        GL_TEXTURE_2D,
        GL_TEXTURE_2D_ARRAY,
        GL_TEXTURE_3D,
        GL_TEXTURE_CUBE_MAP,
        GL_TEXTURE_CUBE_MAP_ARRAY,
        GL_TEXTURE_RECTANGLE,
        GL_TEXTURE_BUFFER
};

static const GLenum non_renderable_internalformats[] = {
	GL_COMPRESSED_RGB,
	GL_COMPRESSED_RGBA,
	GL_COMPRESSED_ALPHA,
	GL_COMPRESSED_LUMINANCE,
	GL_COMPRESSED_LUMINANCE_ALPHA,
	GL_COMPRESSED_INTENSITY,
	GL_COMPRESSED_SRGB,
	GL_COMPRESSED_SRGB_ALPHA,
	GL_COMPRESSED_SLUMINANCE,
	GL_COMPRESSED_SLUMINANCE_ALPHA,
	GL_COMPRESSED_RED,
	GL_COMPRESSED_RG,
	GL_COMPRESSED_RED_RGTC1,
	GL_COMPRESSED_SIGNED_RED_RGTC1,
	GL_COMPRESSED_RG_RGTC2,
	GL_COMPRESSED_SIGNED_RG_RGTC2,
	GL_COMPRESSED_RGBA_BPTC_UNORM_ARB,
	GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_ARB,
	GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB,
	GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB,
	GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
	GL_COMPRESSED_RGBA_S3TC_DXT1_EXT,
	GL_COMPRESSED_RGBA_S3TC_DXT3_EXT,
	GL_COMPRESSED_RGBA_S3TC_DXT5_EXT,
	GL_COMPRESSED_RGB_FXT1_3DFX,
	GL_COMPRESSED_RGBA_FXT1_3DFX,
	GL_COMPRESSED_SRGB_S3TC_DXT1_EXT,
	GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT,
	GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT,
	GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT,
	GL_COMPRESSED_LUMINANCE_LATC1_EXT,
	GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT,
	GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT,
	GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT,
	GL_YCBCR_MESA,
	GL_GREEN_INTEGER_EXT,
	GL_BLUE_INTEGER_EXT,
	GL_ALPHA_INTEGER_EXT,
	GL_RGB_INTEGER_EXT,
	GL_RGBA_INTEGER_EXT,
	GL_BGR_INTEGER_EXT,
	GL_BGRA_INTEGER_EXT,
	GL_LUMINANCE_INTEGER_EXT,
	GL_LUMINANCE_ALPHA_INTEGER_EXT,
};

static const GLenum tex_shared_exponent_formats[] = {
	GL_RGB9_E5,
};

enum piglit_result
piglit_display(void)
{
	return PIGLIT_FAIL;
}

static void
fill_data_and_copy(test_data *data,
                   test_data *data_copy)
{
        unsigned i;

        for (i = 0; i < test_data_get_params_size(data); i++) {
                /* It seems very unlikely that an implementation will
                 * support 0xDEADBEEF samples*/
                test_data_set_value_at_index(data, i, 0xDEADBEEF);
                test_data_set_value_at_index(data_copy, i, 0xDEADBEEF);
        }
}

static bool
check_params_unmodified(test_data *data,
                        test_data *data_copy)
{
        unsigned i;
        bool result;

        for (i = 0; i < test_data_get_params_size(data); i++) {
                result = test_data_equal_at_index(data, data_copy, i);

                if (!result)
                        break;
        }

        return result;
}

static bool
try(const GLenum *targets, unsigned num_targets,
    const GLenum *internalformats, unsigned num_internalformats,
    GLenum pname, test_data *data)
{
        test_data *data_copy = test_data_clone(data);
        bool pass = true;
        unsigned i;
        unsigned j;

	for (i = 0; i < num_targets; i++) {
		for (j = 0; j < num_internalformats; j++) {
                        bool error_test;
                        bool value_test;

                        /* Needed for to check if the data was unmodified  */
                        fill_data_and_copy(data, data_copy);

                        /* First we try with size 0 */
                        test_data_execute_with_size(data, targets[i],
                                                    internalformats[j],
                                                    pname, 0);

                        error_test =
                                piglit_check_gl_error(GL_NO_ERROR);

                        value_test = check_params_unmodified(data, data_copy);

                        /* Now we try with a real size */
                        test_data_execute(data, targets[i], internalformats[j],
                                          pname);

                        error_test = error_test &&
                                piglit_check_gl_error(GL_NO_ERROR);

                        if (pname == GL_NUM_SAMPLE_COUNTS) {
                                value_test = value_test &&
                                        test_data_is_unsupported_response(data,
                                                                          GL_NUM_SAMPLE_COUNTS);
                        } else {
                                value_test = value_test &&
                                        check_params_unmodified(data, data_copy);
                        }

                        if (error_test && value_test)
                                continue;

                        print_failing_case(targets[i], internalformats[j], pname, data);

                        pass = false;
                }
        }

        test_data_clear(&data_copy);

	return pass;
}

static bool
check_num_sample_counts(void)
{
        bool pass = true;
        test_data *data = test_data_new(0, 64);
        int testing64;

        for (testing64 = 0; testing64 <= 1; testing64++) {
                test_data_set_testing64(data, testing64);

                /* The GL_ARB_internalformat_query2 spec says:
                 *
                 * - NUM_SAMPLE_COUNTS: The number of sample counts that would
                 *   be returned by querying SAMPLES is returned in <params>.
                 *      * If <internalformat> is not color-renderable,
                 *        depth-renderable, or stencil-renderable (as defined
                 *        in section 4.4.4) ...
                 */
                pass = try(valid_targets, ARRAY_SIZE(valid_targets),
                           non_renderable_internalformats, ARRAY_SIZE(non_renderable_internalformats),
                           GL_NUM_SAMPLE_COUNTS, data)
                        && pass;

		/* RGB9_E5 is not defined as color-renderable unless
		 * EXT_texture_shared_exponent is exposed.
		 */
		if (!piglit_is_extension_supported("GL_EXT_texture_shared_exponent")) {
			pass = try(valid_targets, ARRAY_SIZE(valid_targets),
				   tex_shared_exponent_formats, 1,
				   GL_NUM_SAMPLE_COUNTS, data)
				&& pass;
		}

                /*
                 *        ... or if <target> does not support
                 *        multiple samples (ie other than
                 *        TEXTURE_2D_MULTISAMPLE,
                 *        TEXTURE_2D_MULTISAMPLE_ARRAY, or RENDERBUFFER), 0 is
                 *        returned.
                 */
                pass = try(without_multisample_targets, ARRAY_SIZE(without_multisample_targets),
                           valid_internalformats, num_valid_internalformats,
                           GL_NUM_SAMPLE_COUNTS, data)
                        && pass;
        }

        piglit_report_subtest_result(pass ? PIGLIT_PASS : PIGLIT_FAIL,
                                     "%s", piglit_get_gl_enum_name(GL_NUM_SAMPLE_COUNTS));

        test_data_clear(&data);

        return pass;
}

static bool
check_samples(void)
{
        bool pass = true;
        test_data *data = test_data_new(0, 64);
        int testing64;

        /*
         * Note: Checking if we are getting a proper min and maximum
         * value, and if the returned values are positive in
         * descending order is done at minmax test, as that one needs
         * to use SAMPLES and NUM_SAMPLES_COUNT combined. This test
         * file is about testing each pname individually.
         */

        for (testing64 = 0; testing64 <= 1; testing64++) {
                test_data_set_testing64(data, testing64);
                /* The GL_ARB_internalformat_query2 spec for SAMPLES says:
                 *
                 * If <internalformat> is not color-renderable, depth-renderable, or
                 * stencil-renderable (as defined in section 4.4.4),
                 */

                pass = try(valid_targets, ARRAY_SIZE(valid_targets),
                           non_renderable_internalformats, ARRAY_SIZE(non_renderable_internalformats),
                           GL_SAMPLES, data)
                        && pass;

		/* RGB9_E5 is not defined as color-renderable unless
		 * EXT_texture_shared_exponent is exposed.
		 */
		if (!piglit_is_extension_supported("GL_EXT_texture_shared_exponent")) {
			pass = try(valid_targets, ARRAY_SIZE(valid_targets),
				   tex_shared_exponent_formats, 1,
				   GL_SAMPLES, data)
				&& pass;
		}

                /*
                 * or if <target> does not support multiple samples (ie other
                 * than TEXTURE_2D_MULTISAMPLE, TEXTURE_2D_MULTISAMPLE_ARRAY,
                 * or RENDERBUFFER), <params> is not modified.
                 */

                pass = try(without_multisample_targets, ARRAY_SIZE(without_multisample_targets),
                           valid_internalformats, num_valid_internalformats,
                           GL_SAMPLES, data)
                        && pass;
        }

        piglit_report_subtest_result(pass ? PIGLIT_PASS : PIGLIT_FAIL,
                                     "%s", piglit_get_gl_enum_name(GL_SAMPLES));

        test_data_clear(&data);

        return pass;
}

void
piglit_init(int argc, char **argv)
{
        bool pass = true;

        piglit_require_extension("GL_ARB_framebuffer_object");
        piglit_require_extension("GL_ARB_internalformat_query2");
        initialize_valid_internalformats();

        pass = check_num_sample_counts() && pass;
        pass = check_samples() && pass;

        piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
}