glsl: test loop unroll with uint overflow
[piglit.git] / tests / spec / arb_draw_indirect / transform-feedback.c
blob8ce560d979a66d4d5cb88e1ef48a39f87b2c3fbb
1 /*
2 * Copyright (c) 2013 Intel Corporation
3 * Copyright (c) 2016 Advanced Micro Devices
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22 * IN THE SOFTWARE.
26 /* Test indirect data generated by transform feedback to catch flushing bugs.
28 * Based on draw-arrays.c.
31 #include "piglit-util-gl.h"
33 PIGLIT_GL_TEST_CONFIG_BEGIN
35 config.supports_gl_core_version = 31;
37 config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGB;
38 config.khr_no_error_support = PIGLIT_NO_ERRORS;
40 PIGLIT_GL_TEST_CONFIG_END
42 GLuint draw_vao;
43 GLint tf_prog, draw_prog;
44 GLint tf_in;
46 float red[] = {1,0,0};
47 float blue[] = {0,0,1};
49 float vertices_data[] = {
50 -1, -1,
51 1, -1,
52 -1, 1,
55 GLint indirect_data[] = {
56 3, /* count */
57 1, /* primcount */
58 0, /* first vertex */
59 0, /* mbz */
62 enum piglit_result
63 piglit_display(void)
65 bool pass = true;
67 glViewport(0, 0, 128, 128);
69 glClearColor(0,0,1,1);
70 glClear(GL_COLOR_BUFFER_BIT);
72 /* Set vertex array already for transform feedback - its contents are
73 * irrelevant. */
74 glBindVertexArray(draw_vao);
76 glUseProgram(tf_prog);
77 glUniform4iv(tf_in, 1, indirect_data);
79 glEnable(GL_RASTERIZER_DISCARD);
80 glBeginTransformFeedback(GL_POINTS);
81 glDrawArrays(GL_POINTS, 0, 1);
82 glEndTransformFeedback();
83 glDisable(GL_RASTERIZER_DISCARD);
85 glUseProgram(draw_prog);
87 glDrawArraysIndirect(GL_TRIANGLES, (GLvoid const *)0);
89 glUseProgram(0);
91 piglit_present_results();
93 pass = piglit_probe_pixel_rgb(32, 32, red) && pass;
94 pass = piglit_probe_pixel_rgb(96, 96, blue) && pass;
96 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
99 void
100 piglit_init(int argc, char **argv)
102 static const char* const tf_out = "tf_out";
103 GLint zeros[4] = { 0, 0, 0, 0 };
104 GLuint vertices_bo;
105 GLuint indirect_bo;
107 piglit_require_extension("GL_ARB_draw_indirect");
109 glGenVertexArrays(1, &draw_vao);
110 glBindVertexArray(draw_vao);
112 glGenBuffers(1, &vertices_bo);
113 glBindBuffer(GL_ARRAY_BUFFER, vertices_bo);
114 glBufferData(GL_ARRAY_BUFFER, sizeof(vertices_data), vertices_data, GL_STATIC_DRAW);
115 glEnableVertexAttribArray(0);
116 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0);
118 glGenBuffers(1, &indirect_bo);
119 glBindBuffer(GL_DRAW_INDIRECT_BUFFER, indirect_bo);
120 /* Fill with zeros so that the default contents are safe (don't lead
121 * to excessive GPU processing times that will be mistaken for hangs).
123 glBufferData(GL_DRAW_INDIRECT_BUFFER, sizeof(indirect_data), zeros, GL_STATIC_DRAW);
125 draw_prog = piglit_build_simple_program(
126 "#version 130\n"
127 "#extension GL_ARB_explicit_attrib_location: require\n"
128 "\n"
129 "layout(location=0) in vec2 pos;\n"
130 "\n"
131 "void main() {\n"
132 " gl_Position = vec4(pos, 0, 1);\n"
133 "}\n",
135 "#version 130\n"
136 "\n"
137 "void main() {\n"
138 " gl_FragColor = vec4(1,0,0,1);\n"
139 "}\n");
141 glBindVertexArray(0);
143 tf_prog = piglit_build_simple_program_unlinked(
144 "#version 130\n"
145 "\n"
146 "out ivec4 tf_out;\n"
147 "uniform ivec4 tf_in;\n"
148 "\n"
149 "void main() {\n"
150 " tf_out = tf_in;\n"
151 " gl_Position = vec4(0);\n"
152 "}\n",
153 NULL);
154 glTransformFeedbackVaryings(tf_prog, 1, &tf_out, GL_INTERLEAVED_ATTRIBS);
155 glLinkProgram(tf_prog);
156 if (!piglit_link_check_status(tf_prog))
157 piglit_report_result(PIGLIT_FAIL);
158 piglit_check_gl_error(GL_NO_ERROR);
160 tf_in = glGetUniformLocation(tf_prog, "tf_in");
162 glBindBufferRange(GL_TRANSFORM_FEEDBACK_BUFFER, 0, indirect_bo, 0, sizeof(indirect_data));