1 /* Copyright © 2012 Intel Corporation
3 * Permission is hereby granted, free of charge, to any person obtaining a
4 * copy of this software and associated documentation files (the "Software"),
5 * to deal in the Software without restriction, including without limitation
6 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
7 * and/or sell copies of the Software, and to permit persons to whom the
8 * Software is furnished to do so, subject to the following conditions:
10 * The above copyright notice and this permission notice (including the next
11 * paragraph) shall be included in all copies or substantial portions of the
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
25 * Test for the minimum maximum value in the GL_ARB_texture_buffer_object spec.
28 #include "piglit-util-gl.h"
41 static const struct format
{
46 enum channels channels
;
48 { GL_ALPHA8
, GL_UNSIGNED_BYTE
, 1, true, A
},
49 { GL_ALPHA16
, GL_UNSIGNED_SHORT
, 1, true, A
},
50 { GL_ALPHA16F_ARB
, GL_HALF_FLOAT
, 1, false, A
},
51 { GL_ALPHA32F_ARB
, GL_FLOAT
, 1, false, A
},
52 { GL_ALPHA8I_EXT
, GL_BYTE
, 1, false, A
},
53 { GL_ALPHA16I_EXT
, GL_SHORT
, 1, false, A
},
54 { GL_ALPHA32I_EXT
, GL_INT
, 1, false, A
},
55 { GL_ALPHA8UI_EXT
, GL_UNSIGNED_BYTE
, 1, false, A
},
56 { GL_ALPHA16UI_EXT
, GL_UNSIGNED_SHORT
, 1, false, A
},
57 { GL_ALPHA32UI_EXT
, GL_UNSIGNED_INT
, 1, false, A
},
59 { GL_LUMINANCE8
, GL_UNSIGNED_BYTE
, 1, true, L
},
60 { GL_LUMINANCE16
, GL_UNSIGNED_SHORT
, 1, true, L
},
61 { GL_LUMINANCE16F_ARB
, GL_HALF_FLOAT
, 1, false, L
},
62 { GL_LUMINANCE32F_ARB
, GL_FLOAT
, 1, false, L
},
63 { GL_LUMINANCE8I_EXT
, GL_BYTE
, 1, false, L
},
64 { GL_LUMINANCE16I_EXT
, GL_SHORT
, 1, false, L
},
65 { GL_LUMINANCE32I_EXT
, GL_INT
, 1, false, L
},
66 { GL_LUMINANCE8UI_EXT
, GL_UNSIGNED_BYTE
, 1, false, L
},
67 { GL_LUMINANCE16UI_EXT
, GL_UNSIGNED_SHORT
, 1, false, L
},
68 { GL_LUMINANCE32UI_EXT
, GL_UNSIGNED_INT
, 1, false, L
},
70 { GL_LUMINANCE8_ALPHA8
, GL_UNSIGNED_BYTE
, 2, true, LA
},
71 { GL_LUMINANCE16_ALPHA16
, GL_UNSIGNED_SHORT
, 2, true, LA
},
72 { GL_LUMINANCE_ALPHA16F_ARB
, GL_HALF_FLOAT
, 2, false, LA
},
73 { GL_LUMINANCE_ALPHA32F_ARB
, GL_FLOAT
, 2, false, LA
},
74 { GL_LUMINANCE_ALPHA8I_EXT
, GL_BYTE
, 2, false, LA
},
75 { GL_LUMINANCE_ALPHA16I_EXT
, GL_SHORT
, 2, false, LA
},
76 { GL_LUMINANCE_ALPHA32I_EXT
, GL_INT
, 2, false, LA
},
77 { GL_LUMINANCE_ALPHA8UI_EXT
, GL_UNSIGNED_BYTE
, 2, false, LA
},
78 { GL_LUMINANCE_ALPHA16UI_EXT
, GL_UNSIGNED_SHORT
, 2, false, LA
},
79 { GL_LUMINANCE_ALPHA32UI_EXT
, GL_UNSIGNED_INT
, 2, false, LA
},
81 { GL_INTENSITY8
, GL_UNSIGNED_BYTE
, 1, true, I
},
82 { GL_INTENSITY16
, GL_UNSIGNED_SHORT
, 1, true, I
},
83 { GL_INTENSITY16F_ARB
, GL_HALF_FLOAT
, 1, false, I
},
84 { GL_INTENSITY32F_ARB
, GL_FLOAT
, 1, false, I
},
85 { GL_INTENSITY8I_EXT
, GL_BYTE
, 1, false, I
},
86 { GL_INTENSITY16I_EXT
, GL_SHORT
, 1, false, I
},
87 { GL_INTENSITY32I_EXT
, GL_INT
, 1, false, I
},
88 { GL_INTENSITY8UI_EXT
, GL_UNSIGNED_BYTE
, 1, false, I
},
89 { GL_INTENSITY16UI_EXT
, GL_UNSIGNED_SHORT
, 1, false, I
},
90 { GL_INTENSITY32UI_EXT
, GL_UNSIGNED_INT
, 1, false, I
},
92 { GL_RGBA8
, GL_UNSIGNED_BYTE
, 4, true, RGBA
},
93 { GL_RGBA16
, GL_UNSIGNED_SHORT
, 4, true, RGBA
},
94 { GL_RGBA16F
, GL_HALF_FLOAT
, 4, false, RGBA
},
95 { GL_RGBA32F
, GL_FLOAT
, 4, false, RGBA
},
96 { GL_RGBA8I_EXT
, GL_BYTE
, 4, false, RGBA
},
97 { GL_RGBA16I_EXT
, GL_SHORT
, 4, false, RGBA
},
98 { GL_RGBA32I_EXT
, GL_INT
, 4, false, RGBA
},
99 { GL_RGBA8UI_EXT
, GL_UNSIGNED_BYTE
, 4, false, RGBA
},
100 { GL_RGBA16UI_EXT
, GL_UNSIGNED_SHORT
, 4, false, RGBA
},
101 { GL_RGBA32UI_EXT
, GL_UNSIGNED_INT
, 4, false, RGBA
},
103 /* These don't appear in the GL_ARB_texture_buffer_object or
104 * GL_ARB_texture_rg specs, but they do appear in the GL 3.1
105 * specification's table for buffer texture formats. We
106 * assume that the intent was for RG to be included even in
107 * ARB_tbo + ARB_texture_rg
109 { GL_R8
, GL_UNSIGNED_BYTE
, 1, true, R
},
110 { GL_R16
, GL_UNSIGNED_SHORT
, 1, true, R
},
111 { GL_R16F
, GL_HALF_FLOAT
, 1, false, R
},
112 { GL_R32F
, GL_FLOAT
, 1, false, R
},
113 { GL_R8I
, GL_BYTE
, 1, false, R
},
114 { GL_R16I
, GL_SHORT
, 1, false, R
},
115 { GL_R32I
, GL_INT
, 1, false, R
},
116 { GL_R8UI
, GL_UNSIGNED_BYTE
, 1, false, R
},
117 { GL_R16UI
, GL_UNSIGNED_SHORT
, 1, false, R
},
118 { GL_R32UI
, GL_UNSIGNED_INT
, 1, false, R
},
120 { GL_RG8
, GL_UNSIGNED_BYTE
, 2, true, RG
},
121 { GL_RG16
, GL_UNSIGNED_SHORT
, 2, true, RG
},
122 { GL_RG16F
, GL_HALF_FLOAT
, 2, false, RG
},
123 { GL_RG32F
, GL_FLOAT
, 2, false, RG
},
124 { GL_RG8I
, GL_BYTE
, 2, false, RG
},
125 { GL_RG16I
, GL_SHORT
, 2, false, RG
},
126 { GL_RG32I
, GL_INT
, 2, false, RG
},
127 { GL_RG8UI
, GL_UNSIGNED_BYTE
, 2, false, RG
},
128 { GL_RG16UI
, GL_UNSIGNED_SHORT
, 2, false, RG
},
129 { GL_RG32UI
, GL_UNSIGNED_INT
, 2, false, RG
},
131 { GL_RGB32F
, GL_FLOAT
, 3, false, RGB
},
132 { GL_RGB32I
, GL_INT
, 3, false, RGB
},
133 { GL_RGB32UI
, GL_UNSIGNED_INT
, 3, false, RGB
},
142 int expected_location
;
145 struct program prog_f
;
146 struct program prog_i
;
147 struct program prog_u
;
148 static int vertex_location
;
152 static uint8_t uint8_data
[] = {
153 0x00, 0x01, 0x02, 0x03,
154 0x10, 0x20, 0x30, 0x40,
155 0x60, 0x90, 0xa0, 0xff,
158 static uint16_t uint16_data
[] = {
159 0x0000, 0x0001, 0x0002, 0x0003,
160 0x4000, 0x8000, 0xc000, 0xffff,
163 static uint32_t uint32_data
[] = {
164 0x00000000, 0x00000001, 0x00000002, 0x00000003,
165 0x40000000, 0x80000000, 0xc0000000, 0xffffffff,
168 static float float_data
[] = {
169 0.0, 0.25, 0.5, 0.75,
171 -1.0, -2.0, -3.0, -4.0,
177 return -1.0 + 2.0 * x
/ piglit_width
;
183 return -1.0 + 2.0 * y
/ piglit_height
;
187 get_expected_f(const struct format
*format
, int sample
, float *expected
)
189 float chans
[4] = { 0 };
192 for (i
= 0; i
< format
->components
; i
++) {
193 int comp
= sample
* format
->components
+ i
;
195 switch (format
->type
) {
197 chans
[i
] = float_data
[comp
];
200 chans
[i
] = float_data
[comp
];
202 case GL_UNSIGNED_BYTE
:
203 chans
[i
] = uint8_data
[comp
] / 255.0;
205 case GL_UNSIGNED_SHORT
:
206 chans
[i
] = uint16_data
[comp
] / 65535.0;
209 printf("line %d, bad type: %s\n", __LINE__
,
210 piglit_get_gl_enum_name(format
->type
));
211 memset(expected
, 0, 16);
216 switch (format
->channels
) {
218 expected
[0] = chans
[0];
219 expected
[1] = chans
[1];
220 expected
[2] = chans
[2];
221 expected
[3] = chans
[3];
224 expected
[0] = chans
[0];
225 expected
[1] = chans
[1];
226 expected
[2] = chans
[2];
230 expected
[0] = chans
[0];
231 expected
[1] = chans
[1];
237 expected
[0] = chans
[0];
247 expected
[3] = chans
[0];
251 expected
[0] = chans
[0];
252 expected
[1] = chans
[0];
253 expected
[2] = chans
[0];
258 expected
[0] = chans
[0];
259 expected
[1] = chans
[0];
260 expected
[2] = chans
[0];
261 expected
[3] = chans
[1];
265 expected
[0] = chans
[0];
266 expected
[1] = chans
[0];
267 expected
[2] = chans
[0];
268 expected
[3] = chans
[0];
276 get_expected_i(const struct format
*format
, int sample
, uint32_t *expected
)
278 uint32_t chans
[4] = { 0 };
281 for (i
= 0; i
< format
->components
; i
++) {
282 int comp
= sample
* format
->components
+ i
;
284 switch (format
->type
) {
286 chans
[i
] = ((int8_t *)uint8_data
)[comp
];
288 case GL_UNSIGNED_BYTE
:
289 chans
[i
] = uint8_data
[comp
];
292 chans
[i
] = ((int16_t *)uint16_data
)[comp
];
294 case GL_UNSIGNED_SHORT
:
295 chans
[i
] = uint16_data
[comp
];
298 case GL_UNSIGNED_INT
:
299 chans
[i
] = uint32_data
[comp
];
302 printf("line %d, bad type: %s\n", __LINE__
,
303 piglit_get_gl_enum_name(format
->type
));
304 memset(expected
, 0, 16);
309 switch (format
->channels
) {
311 expected
[0] = chans
[0];
312 expected
[1] = chans
[1];
313 expected
[2] = chans
[2];
314 expected
[3] = chans
[3];
317 expected
[0] = chans
[0];
318 expected
[1] = chans
[1];
319 expected
[2] = chans
[2];
323 expected
[0] = chans
[0];
324 expected
[1] = chans
[1];
330 expected
[0] = chans
[0];
340 expected
[3] = chans
[0];
344 expected
[0] = chans
[0];
345 expected
[1] = chans
[0];
346 expected
[2] = chans
[0];
351 expected
[0] = chans
[0];
352 expected
[1] = chans
[0];
353 expected
[2] = chans
[0];
354 expected
[3] = chans
[1];
358 expected
[0] = chans
[0];
359 expected
[1] = chans
[0];
360 expected
[2] = chans
[0];
361 expected
[3] = chans
[0];
369 test_format(int format_index
)
371 const struct format
*format
= &formats
[format_index
];
373 bool is_rg
= (format
->channels
== R
||
374 format
->channels
== RG
);
375 bool is_arb
= (format
->channels
== I
||
376 format
->channels
== L
||
377 format
->channels
== LA
||
378 format
->channels
== A
);
379 bool is_rgb32
= (format
->channels
== RGB
);
381 int data_components
, num_samples
;
383 bool returns_float
= (format
->norm
||
384 format
->type
== GL_FLOAT
||
385 format
->type
== GL_HALF_FLOAT
);
386 bool returns_int
= (!format
->norm
&&
387 (format
->type
== GL_BYTE
||
388 format
->type
== GL_SHORT
||
389 format
->type
== GL_INT
));
390 bool returns_uint
= (!format
->norm
&&
391 (format
->type
== GL_UNSIGNED_BYTE
||
392 format
->type
== GL_UNSIGNED_SHORT
||
393 format
->type
== GL_UNSIGNED_INT
));
394 struct program
*prog
;
398 else if (returns_int
)
403 glUseProgram(prog
->prog
);
405 if (test_arb
!= is_arb
)
408 if (is_rgb32
&& !test_rgb32
)
411 /* These didn't exist in the extension before being promoted to
414 if (is_rg
&& piglit_get_gl_version() < 31)
417 printf("Testing %s\n", piglit_get_gl_enum_name(format
->format
));
419 glGenBuffers(1, &bo
);
420 glBindBuffer(GL_TEXTURE_BUFFER
, bo
);
422 glGenTextures(1, &tex
);
423 glBindTexture(GL_TEXTURE_BUFFER
, tex
);
425 glTexBuffer(GL_TEXTURE_BUFFER
, format
->format
, bo
);
427 switch (format
->type
) {
429 case GL_UNSIGNED_BYTE
:
430 glBufferData(GL_TEXTURE_BUFFER
, sizeof(uint8_data
), uint8_data
,
432 data_components
= ARRAY_SIZE(uint8_data
);
436 case GL_UNSIGNED_SHORT
:
437 glBufferData(GL_TEXTURE_BUFFER
, sizeof(uint16_data
),
438 uint16_data
, GL_STATIC_READ
);
439 data_components
= ARRAY_SIZE(uint16_data
);
443 case GL_UNSIGNED_INT
:
444 glBufferData(GL_TEXTURE_BUFFER
, sizeof(uint32_data
),
445 uint32_data
, GL_STATIC_READ
);
446 data_components
= ARRAY_SIZE(uint32_data
);
450 glBufferData(GL_TEXTURE_BUFFER
, sizeof(float_data
), float_data
,
452 data_components
= ARRAY_SIZE(float_data
);
455 case GL_HALF_FLOAT
: {
456 unsigned short hf_data
[ARRAY_SIZE(float_data
)];
457 for (i
= 0; i
< ARRAY_SIZE(float_data
); i
++) {
458 hf_data
[i
] = piglit_half_from_float(float_data
[i
]);
460 glBufferData(GL_TEXTURE_BUFFER
, sizeof(hf_data
), hf_data
,
462 data_components
= ARRAY_SIZE(float_data
);
468 printf("line %d, bad type: %s\n", __LINE__
,
469 piglit_get_gl_enum_name(format
->type
));
473 num_samples
= data_components
/ format
->components
;
475 for (i
= 0; i
< num_samples
; i
++) {
476 float x1
= 5 + i
* 10;
477 float x2
= 10 + i
* 10;
478 float y1
= piglit_height
- (5 + y_index
* 10);
479 float y2
= piglit_height
- (10 + y_index
* 10);
481 transform_x(x1
), transform_y(y1
),
482 transform_x(x2
), transform_y(y1
),
483 transform_x(x2
), transform_y(y2
),
484 transform_x(x1
), transform_y(y2
),
487 uint32_t expected_i
[4];
488 const float green
[4] = {0, 1, 0, 0};
491 if (!get_expected_f(format
, i
, expected_f
))
493 glUniform4fv(prog
->expected_location
, 1, expected_f
);
495 if (!get_expected_i(format
, i
, expected_i
))
498 glUniform4uiv(prog
->expected_location
, 1,
501 glUniform4iv(prog
->expected_location
, 1,
506 glUniform1i(prog
->pos_location
, i
);
508 glBufferData(GL_ARRAY_BUFFER_ARB
, sizeof(verts
), verts
,
510 glDrawArrays(GL_TRIANGLE_FAN
, 0, 4);
513 !piglit_probe_rect_rgba(x1
, y2
,
514 x2
- x1
, y1
- y2
, green
)) {
516 printf(" Texel: %d %d %d %d\n",
517 expected_i
[0], expected_i
[1],
518 expected_i
[2], expected_i
[3]);
519 } else if (returns_uint
) {
520 printf(" Texel: %u %u %u %u\n",
521 expected_i
[0], expected_i
[1],
522 expected_i
[2], expected_i
[3]);
524 printf(" Texel: %f %f %f %f\n",
525 expected_f
[0], expected_f
[1],
526 expected_f
[2], expected_f
[3]);
532 glDeleteBuffers(1, &bo
);
533 glDeleteTextures(1, &tex
);
538 piglit_report_subtest_result(pass
? PIGLIT_PASS
: PIGLIT_FAIL
,
539 "%s", piglit_get_gl_enum_name(format
->format
));
540 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
546 enum piglit_result result
= PIGLIT_SKIP
;
550 glClearColor(0.5, 0.5, 0.5, 0.5);
551 glClear(GL_COLOR_BUFFER_BIT
);
555 /* For GL core, we need to have a vertex array object bound.
556 * Otherwise, we don't particularly have to. Always use a
557 * vertex buffer object, though.
559 glGenBuffers(1, &vbo
);
560 glBindBuffer(GL_ARRAY_BUFFER_ARB
, vbo
);
561 if (piglit_get_gl_version() >= 31) {
563 glGenVertexArrays(1, &vao
);
564 glBindVertexArray(vao
);
566 glVertexAttribPointer(vertex_location
, 2, GL_FLOAT
, GL_FALSE
, 0, 0);
567 glEnableVertexAttribArray(vertex_location
);
569 for (i
= 0; i
< ARRAY_SIZE(formats
); i
++) {
570 piglit_merge_result(&result
, test_format(i
));
573 glDeleteBuffers(1, &vbo
);
574 glDeleteVertexArrays(1, &vao
);
576 piglit_present_results();
581 static char *vs_vert_source
=
585 "uniform %ssamplerBuffer s;\n"
587 "uniform %svec4 expected;"
590 " gl_Position = vertex;\n"
592 " %svec4 result = texelFetch(s, pos);\n"
593 " %svec4 delta = result - expected;\n"
594 " bvec4 fail = greaterThanEqual(abs(delta), %s);\n"
595 " if (any(fail)) {\n"
596 " color = 0.25 + 0.5 * vec4(fail);\n"
598 " color = vec4(0.0, 1.0, 0.0, 0.0);\n"
602 static char *fs_vert_source
=
607 " gl_FragColor = color;\n"
611 static char *vs_frag_source
=
616 " gl_Position = vertex;\n"
619 static char *fs_frag_source
=
621 "uniform %ssamplerBuffer s;\n"
623 "uniform %svec4 expected;"
626 " %svec4 result = texelFetch(s, pos);\n"
627 " %svec4 delta = result - expected;\n"
628 " bvec4 fail = greaterThanEqual(abs(delta), %s);\n"
629 " if (any(fail)) {\n"
630 " gl_FragColor = 0.25 + 0.5 * vec4(fail);\n"
632 " gl_FragColor = vec4(0.0, 1.0, 0.0, 0.0);\n"
637 create_program(struct program
*program
, const char *type
)
639 char *fs_source
, *vs_source
;
643 if (strcmp(type
, "") == 0)
644 threshold
= "vec4(0.02)";
646 threshold
= "ivec4(1)";
649 (void)!asprintf(&vs_source
, vs_vert_source
, type
, type
, type
, type
,
651 fs_source
= fs_vert_source
;
653 vs_source
= vs_frag_source
;
654 (void)!asprintf(&fs_source
, fs_frag_source
, type
, type
, type
, type
,
658 prog
= piglit_build_simple_program(vs_source
, fs_source
);
660 program
->prog
= prog
;
661 program
->pos_location
= glGetUniformLocation(prog
, "pos");
662 program
->expected_location
= glGetUniformLocation(prog
,
664 vertex_location
= glGetAttribLocation(prog
, "vertex");
665 assert(vertex_location
== 0);
671 create_program(&prog_f
, "");
672 create_program(&prog_i
, "i");
673 create_program(&prog_u
, "u");
677 usage(const char *name
)
679 printf("usage: %s <fs | vs> <core | arb>\n", name
);
680 piglit_report_result(PIGLIT_FAIL
);
684 piglit_init(int argc
, char **argv
)
686 piglit_require_GLSL_version(140);
688 piglit_require_extension("GL_EXT_texture_integer");
689 piglit_require_extension("GL_ARB_texture_rg");
692 piglit_require_extension("GL_ARB_texture_buffer_object");
694 if (piglit_get_gl_version() < 31)
695 piglit_require_extension("GL_ARB_texture_buffer_object");
697 if (piglit_is_extension_supported("GL_ARB_texture_buffer_object_rgb32"))
705 PIGLIT_GL_TEST_CONFIG_BEGIN
706 test_vs
= PIGLIT_STRIP_ARG("vs");
707 if (!test_vs
&& !PIGLIT_STRIP_ARG("fs"))
710 test_arb
= PIGLIT_STRIP_ARG("arb");
711 if (!test_arb
&& !PIGLIT_STRIP_ARG("core"))
715 config
.supports_gl_compat_version
= 10;
717 config
.supports_gl_core_version
= 31;
719 config
.window_width
= 200;
720 config
.window_height
= 500;
721 config
.window_visual
= PIGLIT_GL_VISUAL_DOUBLE
| PIGLIT_GL_VISUAL_RGBA
;
722 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
723 PIGLIT_GL_TEST_CONFIG_END