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.
24 /** @file transformfeedback-bufferbase.c
25 * Simple transform feedback test drawing GL_POINTS and making use of the
26 * transform-feedback-related direct state access entry points.
28 * Greatly inspired from ext_transform_feedback/points.c.
30 * From OpenGL 4.5, section 13.2.2 "Transform Feedback Primitive Capture",
33 * "void TransformFeedbackBufferBase( uint xfb, uint index, uint buffer );
35 * xfb must be zero, indicating the default transform feedback object, or the
36 * name of an existing transform feedback object. buffer must be zero or the
37 * name of an existing buffer object.
39 * TransformFeedbackBufferRange and TransformFeedbackBufferBase behave
40 * similarly to BindBufferRange and BindBufferBase, respectively, except
41 * that the target of the operation is xfb, and they do not affect any binding
42 * to the generic TRANSFORM_FEEDBACK_BUFFER target.
45 * An INVALID_OPERATION error is generated if xfb is not zero or the name
46 * of an existing transform feedback object.
47 * An INVALID_VALUE error is generated if buffer is not zero or the name of
48 * an existing buffer object.
49 * An INVALID_VALUE error is generated if index is greater than or equal
50 * to the number of binding points for transform feedback, as described in
52 * An INVALID_VALUE error is generated by TransformFeedbackBufferRange
53 * if offset is negative.
54 * An INVALID_VALUE error is generated by TransformFeedbackBufferRange
55 * if size is less than or equal to zero.
56 * An INVALID_VALUE error is generated by TransformFeedbackBufferRange
57 * if offset or size do not satisfy the constraints described for those
58 * parameters for transform feedback array bindings, as described in
62 #include "piglit-util-gl.h"
63 #include "dsa-utils.h"
65 PIGLIT_GL_TEST_CONFIG_BEGIN
66 config
.supports_gl_core_version
= 31;
67 config
.window_visual
= PIGLIT_GL_VISUAL_DOUBLE
| PIGLIT_GL_VISUAL_RGBA
;
68 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
69 PIGLIT_GL_TEST_CONFIG_END
73 static GLuint xfb_buf
[3], input_buf
, vao
;
74 static const int xfb_buf_size
= 500;
76 static const char *vstext
= {
82 " valOut1 = valIn + 1;"
83 " valOut2 = valIn * 2;"
88 static const GLfloat inputs
[NUM_INPUTS
] = {-1.0, 0.0, 1.0, 3.0};
89 static const GLfloat out1_ret
[NUM_INPUTS
] = { 0.0, 1.0, 2.0, 4.0};
90 static const GLfloat out2_ret
[NUM_INPUTS
] = {-2.0, 0.0, 2.0, 6.0};
93 piglit_init(int argc
, char **argv
)
95 static const char *varyings
[] = { "valOut1", "valOut2" };
98 /* Check the driver. */
99 piglit_require_extension("GL_ARB_transform_feedback3");
100 piglit_require_extension("GL_ARB_direct_state_access");
102 /* Create shaders. */
103 prog
= piglit_build_simple_program_unlinked(vstext
, NULL
);
104 glTransformFeedbackVaryings(prog
, 2, varyings
,
105 GL_SEPARATE_ATTRIBS
);
107 if (!piglit_link_check_status(prog
)) {
108 glDeleteProgram(prog
);
109 piglit_report_result(PIGLIT_FAIL
);
113 /* Set up the Vertex Array Buffer */
114 glEnable(GL_VERTEX_ARRAY
);
115 glGenVertexArrays(1, &vao
);
116 glBindVertexArray(vao
);
118 /* Set up the input data buffer */
119 glGenBuffers(1, &input_buf
);
120 glBindBuffer(GL_ARRAY_BUFFER
, input_buf
);
121 glBufferData(GL_ARRAY_BUFFER
, sizeof(inputs
), inputs
, GL_STATIC_DRAW
);
122 inAttrib
= glGetAttribLocation(prog
, "valIn");
123 piglit_check_gl_error(GL_NO_ERROR
);
124 glVertexAttribPointer(inAttrib
, 1, GL_FLOAT
, GL_FALSE
, 0, 0);
125 glEnableVertexAttribArray(inAttrib
);
129 equal(float a
, float b
)
131 return fabsf(a
- b
) < piglit_tolerance
[0];
137 GLint max_bind_points
= 0;
139 bool pass
= true, test
= true;
143 /* init the transform feedback buffers */
144 glGenBuffers(3, xfb_buf
);
145 glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER
, xfb_buf
[2]);
146 piglit_check_gl_error(GL_NO_ERROR
);
148 /* Fetch the number of bind points */
149 glGetIntegerv(GL_MAX_TRANSFORM_FEEDBACK_BUFFERS
, &max_bind_points
);
150 PIGLIT_SUBTEST_ERROR(GL_NO_ERROR
, pass
, "fetch maximum number of bind "
153 if (piglit_khr_no_error
)
156 /* bind a non-existing transform feedback BO */
157 glTransformFeedbackBufferBase(1337, 0, 0);
158 PIGLIT_SUBTEST_ERROR(GL_INVALID_OPERATION
, pass
,
159 "bind non-existing transform feedback BO");
161 /* bind a non-existing output BO */
162 glTransformFeedbackBufferBase(0, 0, 1337);
163 PIGLIT_SUBTEST_ERROR(GL_INVALID_VALUE
, pass
, "bind a non-existing "
166 /* bind to a negative index */
167 glTransformFeedbackBufferBase(0, -1, xfb_buf
[2]);
168 PIGLIT_SUBTEST_ERROR(GL_INVALID_VALUE
, pass
, "bind negative index");
170 /* bind to an index == max */
171 glTransformFeedbackBufferBase(0, max_bind_points
, xfb_buf
[2]);
172 PIGLIT_SUBTEST_ERROR(GL_INVALID_VALUE
, pass
, "bind to index == "
173 "max_bind_points (%i)", max_bind_points
);
176 /* Set up the transform feedback buffer */
177 for (i
= 0; i
< 2; i
++) {
178 glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER
, xfb_buf
[i
]);
179 glBufferData(GL_TRANSFORM_FEEDBACK_BUFFER
,
180 xfb_buf_size
, NULL
, GL_STREAM_READ
);
181 glTransformFeedbackBufferBase(0, i
, xfb_buf
[i
]);
182 piglit_check_gl_error(GL_NO_ERROR
);
185 /* Set up the query that checks the # of primitives handled */
187 glBeginQuery(GL_PRIMITIVES_GENERATED
, q
);
188 piglit_check_gl_error(GL_NO_ERROR
);
190 /* do the transform feedback */
191 glBeginTransformFeedback(GL_POINTS
);
192 glBindBuffer(GL_ARRAY_BUFFER
, input_buf
);
193 glDrawArrays(GL_POINTS
, 0, NUM_INPUTS
);
194 glEndTransformFeedback();
196 glEndQuery(GL_PRIMITIVES_GENERATED
);
198 /* check the number of primitives */
199 glGetQueryObjectuiv(q
, GL_QUERY_RESULT
, &num_prims
);
200 glDeleteQueries(1, &q
);
201 printf("%u primitives generated:\n", num_prims
);
202 if (num_prims
!= NUM_INPUTS
) {
203 printf("Incorrect number of prims generated.\n");
204 printf("Found %u, expected %u\n", num_prims
, NUM_INPUTS
);
209 /* check the result */
210 glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER
, xfb_buf
[0]);
211 v
= glMapBuffer(GL_TRANSFORM_FEEDBACK_BUFFER
, GL_READ_ONLY
);
212 piglit_check_gl_error(GL_NO_ERROR
);
213 glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER
, xfb_buf
[1]);
214 w
= glMapBuffer(GL_TRANSFORM_FEEDBACK_BUFFER
, GL_READ_ONLY
);
215 piglit_check_gl_error(GL_NO_ERROR
);
217 for (i
= 0; i
< num_prims
; i
++) {
218 printf("%2d: (%2.0g, %2.0g) : ", i
, v
[i
], w
[i
]);
219 if (!equal(v
[i
], out1_ret
[i
]) || !equal(w
[i
], out2_ret
[i
])) {
220 printf("NOK, expected (%2.0g, %2.0g)\n",
221 out1_ret
[i
], out2_ret
[i
]);
226 PIGLIT_SUBTEST_CONDITION(test
, pass
, "general test");
228 piglit_present_results();
230 /* clean-up everything */
231 glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER
, xfb_buf
[0]);
232 glUnmapBuffer(GL_TRANSFORM_FEEDBACK_BUFFER
);
233 glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER
, xfb_buf
[1]);
234 glUnmapBuffer(GL_TRANSFORM_FEEDBACK_BUFFER
);
235 glDeleteBuffers(3, xfb_buf
);
236 glDeleteBuffers(1, &input_buf
);
237 glDeleteVertexArrays(1, &vao
);
238 glDeleteProgram(prog
);
240 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;