2 * Copyright © 2015 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.
27 * Test for gl_DrawIDARB with indirect multi-draw. For mesa, this is
28 * interesting because this is the only mode where we actually get
29 * multiple _mesa_prim into the backend in one call. This tests that
30 * we properly reemit state to update gl_DrawIDARB between rendering,
31 * which on i965 involves reemitting vertex buffer state.
33 * Also, on i965, we source the vertex and instance ID from an
34 * internal vertex buffer for direct rdraw, but point the vertex
35 * buffer the parameter buffer for indirect draws. The baseinstance
36 * subtest verifies that this all works right. Conversely, the
37 * vertexid subtest doesn't reference gl_DrawIDARB and is useful for
38 * validating that we don't reemit vertex buffer state between multi
39 * draw calls. We can't test for that with this test, of course, but
40 * we can inspect the generate command stream from the driver.
43 #include "piglit-util-gl.h"
45 PIGLIT_GL_TEST_CONFIG_BEGIN
47 config
.supports_gl_core_version
= 31;
48 config
.window_visual
= PIGLIT_GL_VISUAL_RGBA
| PIGLIT_GL_VISUAL_DOUBLE
;
50 PIGLIT_GL_TEST_CONFIG_END
52 static const char vs_template
[] =
54 "#extension GL_ARB_shader_draw_parameters: require\n"
56 "layout(location = 0) in vec2 pos;\n"
57 "layout(location = 1) in ivec4 ref;\n"
62 " gl_Position = vec4(pos, 0.0, 1.0);\n"
64 " color = vec4(0, 1, 0, 1);\n"
66 " color = vec4(1, 0, 0, 1);\n"
69 static const char fs_text
[] =
76 " gl_FragColor = color;\n"
80 piglit_init(int argc
, char **argv
)
85 if (strcmp(argv
[1], "drawid") == 0) {
86 (void)!asprintf(&vs_text
, vs_template
,
87 "ref.x == gl_DrawIDARB");
88 } else if (strcmp(argv
[1], "basevertex") == 0) {
89 (void)!asprintf(&vs_text
, vs_template
,
90 "ref.xy == ivec2(gl_DrawIDARB, gl_BaseVertexARB)");
91 } else if (strcmp(argv
[1], "baseinstance") == 0) {
92 (void)!asprintf(&vs_text
, vs_template
,
93 "ref.xz == ivec2(gl_DrawIDARB, gl_BaseInstanceARB)");
94 } else if (strcmp(argv
[1], "vertexid") == 0) {
95 (void)!asprintf(&vs_text
, vs_template
,
96 "ref.w == gl_VertexID");
98 printf("Unknown subtest: %s\n", argv
[1]);
99 piglit_report_result(PIGLIT_FAIL
);
102 piglit_require_GLSL_version(330);
104 piglit_require_extension("GL_ARB_shader_draw_parameters");
105 piglit_require_extension("GL_ARB_base_instance");
107 prog
= piglit_build_simple_program(vs_text
, fs_text
);
114 GLuint instanceCount
;
126 float vertex_array
[16];
127 int reference_array
[32];
154 const int indices
[12] = {
159 float green
[] = {0, 1, 0, 1};
161 GLuint vao
, vbo
, ibo
, dbo
;
162 glGenVertexArrays(1, &vao
);
163 glBindVertexArray(vao
);
165 glGenBuffers(1, &vbo
);
166 glBindBuffer(GL_ARRAY_BUFFER
, vbo
);
167 glBufferData(GL_ARRAY_BUFFER
, sizeof(geometry
), &geometry
, GL_STATIC_DRAW
);
169 glVertexAttribPointer(0, 2, GL_FLOAT
, GL_FALSE
,
171 (void *) ((char *) &geometry
.vertex_array
- (char *) &geometry
));
173 glVertexAttribIPointer(1, 4, GL_UNSIGNED_INT
,
175 (void *) ((char *) &geometry
.reference_array
- (char *) &geometry
));
177 /* Enable the attributes */
178 glEnableVertexAttribArray(0);
179 glEnableVertexAttribArray(1);
181 glGenBuffers(1, &ibo
);
182 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER
, ibo
);
183 glBufferData(GL_ELEMENT_ARRAY_BUFFER
, sizeof(indices
), indices
, GL_STATIC_DRAW
);
185 struct cmd cmds
[] = {
202 glGenBuffers(1, &dbo
);
203 glBindBuffer(GL_DRAW_INDIRECT_BUFFER
, dbo
);
204 glBufferData(GL_DRAW_INDIRECT_BUFFER
, sizeof(cmds
), cmds
, GL_STATIC_DRAW
);
206 glMultiDrawElementsIndirect(GL_TRIANGLES
,
210 pass
= piglit_probe_rect_rgba(0, 0, piglit_width
, piglit_height
,
213 piglit_present_results();
215 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;