2 * Copyright © 2011 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.
25 * \file buffer-usage.c
27 * Tests for a bug in the i965 driver where transform feedback would
28 * segfault on certain buffer object allocation 'usage' arguments.
31 #include "piglit-util-gl.h"
33 #define NUM_POINTS 10002
34 #define SHIFT_COUNT 64
36 PIGLIT_GL_TEST_CONFIG_BEGIN
38 config
.supports_gl_compat_version
= 10;
40 config
.window_visual
= PIGLIT_GL_VISUAL_DOUBLE
| PIGLIT_GL_VISUAL_RGBA
;
41 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
43 PIGLIT_GL_TEST_CONFIG_END
45 static const char *vstext
=
51 " gl_Position = vec4(0.0);\n"
56 initialize_shader_and_xfb()
59 const char *varying
= "tf";
61 piglit_require_gl_version(30);
62 piglit_require_GLSL_version(130);
63 piglit_require_transform_feedback();
64 vs
= piglit_compile_shader_text(GL_VERTEX_SHADER
, vstext
);
65 prog
= glCreateProgram();
66 glAttachShader(prog
, vs
);
67 glTransformFeedbackVaryings(prog
, 1, &varying
, GL_INTERLEAVED_ATTRIBS
);
69 if (!piglit_link_check_status(prog
)) {
70 glDeleteProgram(prog
);
71 piglit_report_result(PIGLIT_FAIL
);
79 static const GLenum bo_modes
[] = {
93 glEnable(GL_RASTERIZER_DISCARD
);
95 for (i
= 0; i
< ARRAY_SIZE(bo_modes
); i
++) {
96 static GLuint xfb_buf
;
99 /* Make a new TFB output buffer with the chosen usage
100 * mode. Note, from ARB_vertex_buffer_object:
102 * "The specified usage value does not constrain
103 * the actual usage pattern of the data store."
105 glGenBuffers(1, &xfb_buf
);
106 glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER
, xfb_buf
);
107 glBufferData(GL_TRANSFORM_FEEDBACK_BUFFER
,
108 sizeof(float), NULL
, bo_modes
[i
]);
109 glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER
, 0, xfb_buf
);
111 /* Do the draw call. Here's where we segfaulted before. */
112 glBeginTransformFeedback(GL_POINTS
);
113 glDrawArrays(GL_POINTS
, 0, 1);
114 glEndTransformFeedback();
116 /* Test the output, just to be sure. */
117 readback
= glMapBuffer(GL_TRANSFORM_FEEDBACK_BUFFER
,
120 if (readback
[0] != 1.0) {
121 fprintf(stderr
, "Readback found %f, expected 1.0\n",
125 glUnmapBuffer(GL_TRANSFORM_FEEDBACK_BUFFER
);
127 glDeleteBuffers(1, &xfb_buf
);
130 piglit_report_result(pass
? PIGLIT_PASS
: PIGLIT_FAIL
);
134 piglit_init(int argc
, char **argv
)
136 initialize_shader_and_xfb();
140 enum piglit_result
piglit_display(void)
142 /* Test should finish before we reach here. */