perf/pixel-rate: new pixel throughput microbenchmark
[piglit.git] / tests / spec / ext_transform_feedback / immediate-reuse-uniform-buffer.c
blobc2c9ce6eb1b087b3676c03ff223e0b996f0addf8
1 /*
2 * Copyright © 2011 Intel Corporation
3 * Copyright © 2014 Advanced Micro Devices, Inc.
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
22 * DEALINGS IN THE SOFTWARE.
25 /**
26 * \file immediate-reuse-uniform-buffer.c
28 * Verify that if a transform feedback output buffer is immediately re-used
29 * as an uniform buffer (changing no GL settings except for buffer bindings),
30 * rendering is correct.
32 * The test operates by using a uniform buffer <-> transform feedback loop
33 * that increments a uniform in each draw call. The test starts
34 * with value 0 and transform feedback writes (value+1). Then it uses
35 * the output as an input again and the value should be 1.
38 #include "piglit-util-gl.h"
40 PIGLIT_GL_TEST_CONFIG_BEGIN
42 config.supports_gl_compat_version = 10;
44 config.window_width = 256;
45 config.window_height = 16;
46 config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGB;
47 config.khr_no_error_support = PIGLIT_NO_ERRORS;
49 PIGLIT_GL_TEST_CONFIG_END
51 static const char *vstext =
52 "#version 130\n"
53 "#extension GL_ARB_uniform_buffer_object : require\n"
54 "varying vec4 out_color;\n"
55 "varying int index;\n"
56 "uniform u { int u_const; };"
57 "\n"
58 "void main()\n"
59 "{\n"
60 " int x = 8 + 16 * u_const;\n"
61 " gl_Position = vec4(x / 128.0 - 1.0, 0, 0, 1);\n"
62 " out_color = vec4(float(u_const) / 16.0, \n"
63 " float(16 - u_const) / 16.0, \n"
64 " float(u_const) / 16.0, 1.0);\n"
65 " index = u_const + 1;\n"
66 "}\n";
68 static const char *fstext =
69 "#version 130\n"
70 "varying vec4 out_color;\n"
71 "\n"
72 "void main()\n"
73 "{\n"
74 " gl_FragColor = out_color;\n"
75 "}\n";
77 static const char *varyings[] = { "index" };
79 static GLuint bufs[2];
80 static GLuint prog;
82 void
83 piglit_init(int argc, char **argv)
85 piglit_require_gl_version(30);
86 piglit_require_extension("GL_ARB_uniform_buffer_object");
88 prog = piglit_build_simple_program_unlinked(vstext, fstext);
89 glTransformFeedbackVaryings(prog, 1, varyings, GL_INTERLEAVED_ATTRIBS);
90 glLinkProgram(prog);
91 if (!piglit_link_check_status(prog)) {
92 glDeleteProgram(prog);
93 piglit_report_result(PIGLIT_FAIL);
96 glGenBuffers(2, bufs);
99 enum piglit_result
100 piglit_display(void)
102 int i;
103 bool pass = true;
104 unsigned zero = 0;
106 /* Setup program and initial buffer contents */
107 glBindBuffer(GL_ARRAY_BUFFER, bufs[0]);
108 glBufferData(GL_ARRAY_BUFFER, 4, &zero, GL_STREAM_COPY);
109 glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, bufs[1]);
110 glBufferData(GL_TRANSFORM_FEEDBACK_BUFFER, 4, &zero, GL_STREAM_COPY);
112 glUseProgram(prog);
113 glClear(GL_COLOR_BUFFER_BIT);
114 glPointSize(16);
116 /* Draw 16 times, swapping transform feedback and uniform data
117 * so that transform feedback output is fed back to uniform
118 * input.
120 for (i = 0; i < 16; ++i) {
121 glBindBufferBase(GL_UNIFORM_BUFFER, 0, bufs[i % 2]);
122 glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0,
123 bufs[(i + 1) % 2]);
124 glBeginTransformFeedback(GL_POINTS);
125 glDrawArrays(GL_POINTS, 0, 1);
126 glEndTransformFeedback();
129 /* Check that the proper gradient was drawn */
130 for (i = 0; i < 16; ++i) {
131 float expected_color[3] = {i/16.0, (16 - i)/16.0, i/16.0 };
132 pass = piglit_probe_rect_rgb(16 * i, 0, 16, 16,
133 expected_color) && pass;
136 piglit_present_results();
138 return pass ? PIGLIT_PASS : PIGLIT_FAIL;