ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / ext_transform_feedback / buffer-usage.c
blobd7fbe62c52c0c547da448a3922e88d25e0743ba7
1 /*
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
13 * Software.
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 /**
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 =
46 "#version 130\n"
47 "out float tf;\n"
48 "\n"
49 "void main()\n"
50 "{\n"
51 " gl_Position = vec4(0.0);\n"
52 " tf = 1.0;\n"
53 "}\n";
55 static void
56 initialize_shader_and_xfb()
58 GLuint prog, vs;
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);
68 glLinkProgram(prog);
69 if (!piglit_link_check_status(prog)) {
70 glDeleteProgram(prog);
71 piglit_report_result(PIGLIT_FAIL);
73 glUseProgram(prog);
76 static void
77 draw()
79 static const GLenum bo_modes[] = {
80 GL_STREAM_DRAW,
81 GL_STREAM_READ,
82 GL_STREAM_COPY,
83 GL_STATIC_DRAW,
84 GL_STATIC_READ,
85 GL_STATIC_COPY,
86 GL_DYNAMIC_DRAW,
87 GL_DYNAMIC_READ,
88 GL_DYNAMIC_COPY,
90 int i;
91 bool pass = true;
93 glEnable(GL_RASTERIZER_DISCARD);
95 for (i = 0; i < ARRAY_SIZE(bo_modes); i++) {
96 static GLuint xfb_buf;
97 float *readback;
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,
118 GL_READ_ONLY);
120 if (readback[0] != 1.0) {
121 fprintf(stderr, "Readback found %f, expected 1.0\n",
122 readback[0]);
123 pass = false;
125 glUnmapBuffer(GL_TRANSFORM_FEEDBACK_BUFFER);
127 glDeleteBuffers(1, &xfb_buf);
130 piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
133 void
134 piglit_init(int argc, char **argv)
136 initialize_shader_and_xfb();
137 draw();
140 enum piglit_result piglit_display(void)
142 /* Test should finish before we reach here. */
143 return PIGLIT_FAIL;