2 * Copyright © 2012 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
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
21 * DEALINGS IN THE SOFTWARE.
24 /** @file layout-std140-base-size-and-alignment.c
26 * Tests that glGetActiveUniformsiv() returns the correct offset for
27 * any basic type valid in std140, and for a float just following
28 * that, thus testing the size and base alignment for them.
31 #include "piglit-util-gl.h"
32 #include "uniform-types.h"
34 PIGLIT_GL_TEST_CONFIG_BEGIN
36 config
.supports_gl_compat_version
= 10;
37 config
.supports_gl_core_version
= 31;
38 config
.window_visual
= PIGLIT_GL_VISUAL_DOUBLE
| PIGLIT_GL_VISUAL_RGBA
;
39 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
41 PIGLIT_GL_TEST_CONFIG_END
46 return (v
+ a
- 1) & ~(a
- 1);
50 test_format(const struct uniform_type
*type
, bool row_major
)
52 /* Using 140 to get unsigned ints. */
53 const char *fs_template
=
55 "layout(std140) uniform ubo {\n"
62 " gl_FragColor = vec4(pad) + vec4(%s) + vec4(size_test);\n"
66 const char *uniform_names
[] = { "u", "size_test" };
67 GLuint uniform_indices
[2];
69 int offset
, size
, expected_offset
;
70 const struct uniform_type
*transposed_type
;
75 transposed_type
= get_transposed_type(type
);
77 transposed_type
= type
;
81 else if (type
->size
<= 16)
86 (void)!asprintf(&fs_source
, fs_template
,
87 row_major
&& type
->size
> 16 ? "layout(row_major) " : "",
90 prog
= piglit_build_simple_program(NULL
, fs_source
);
93 glGetUniformIndices(prog
, 2, uniform_names
, uniform_indices
);
94 glGetActiveUniformsiv(prog
, 2, uniform_indices
,
95 GL_UNIFORM_OFFSET
, offsets
);
97 glDeleteProgram(prog
);
100 size
= offsets
[1] - offsets
[0];
102 /* "pad" at the start of the UBO is a float, so our test
103 * uniform would start at byte 4 if not for alignment.
106 expected_offset
= align(expected_offset
, transposed_type
->alignment
);
108 pass
= (offset
== expected_offset
&&
109 size
== transposed_type
->size
);
111 printf("%-10s %10s %8d %-16d %8d %-16d%s\n",
113 row_major
? "y" : "n",
117 transposed_type
->size
,
118 pass
? "" : " FAIL");
124 piglit_init(int argc
, char **argv
)
129 piglit_require_extension("GL_ARB_uniform_buffer_object");
130 piglit_require_GLSL_version(140);
132 printf("%-10s %10s %8s %16s %8s %-16s\n",
134 "offset", "expected offset", "size", "expected size");
136 for (i
= 0; uniform_types
[i
].type
; i
++) {
137 pass
= test_format(&uniform_types
[i
], false) && pass
;
138 pass
= test_format(&uniform_types
[i
], true) && pass
;
141 piglit_report_result(pass
? PIGLIT_PASS
: PIGLIT_FAIL
);
144 enum piglit_result
piglit_display(void)