1 /*
2 * Copyright © 2013 Intel Corporation
3 *
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:
10 *
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.
14 *
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.
22 */
23
24 /**
25 * \file nonflat-interal.c
26 *
27 * Test that non-flat integral vertex shader outputs can be captured
28 * with transform feedback.
29 */
30
31 #include "piglit-util-gl.h"
32
33 PIGLIT_GL_TEST_CONFIG_BEGIN
34 config.supports_gl_compat_version = 30;
35 config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA;
36 config.khr_no_error_support = PIGLIT_NO_ERRORS;
37 PIGLIT_GL_TEST_CONFIG_END
38
39
40 static const char vs_text[] =
41 "#version 130\n"
42 "out int out_int;\n"
43 "out ivec2 out_ivec2;\n"
44 "out ivec3 out_ivec3;\n"
45 "out ivec4 out_ivec4;\n"
46 "out uint out_uint;\n"
47 "out uvec2 out_uvec2;\n"
48 "out uvec3 out_uvec3;\n"
49 "out uvec4 out_uvec4;\n"
50 "void main()\n"
51 "{\n"
52 " gl_Position = vec4(0.0);\n"
53 " out_int = 11;\n"
54 " out_ivec2 = ivec2(21, 22);\n"
55 " out_ivec3 = ivec3(31, 32, 33);\n"
56 " out_ivec4 = ivec4(41, 42, 43, 44);\n"
57 " out_uint = 51u;\n"
58 " out_uvec2 = uvec2(61u, 62u);\n"
59 " out_uvec3 = uvec3(71u, 72u, 73u);\n"
60 " out_uvec4 = uvec4(81u, 82u, 83u, 84u);\n"
61 "}\n";
62
63
64 static const GLchar *varyings[] = {
65 "out_int", "out_ivec2", "out_ivec3", "out_ivec4",
66 "out_uint", "out_uvec2", "out_uvec3", "out_uvec4"
67 };
68
69
70 static const GLint expected_xfb_result[] = {
71 11, 21, 22, 31, 32, 33, 41, 42, 43, 44,
72 51, 61, 62, 71, 72, 73, 81, 82, 83, 84
73 };
74
75
76 void
piglit_init(int argc,char ** argv)77 piglit_init(int argc, char **argv)
78 {
79 bool pass = true;
80 const GLint *readback;
81 GLuint buf;
82 void *initial_data;
83 int i;
84 GLuint prog = piglit_build_simple_program_unlinked(vs_text, NULL);
85 glTransformFeedbackVaryings(prog, ARRAY_SIZE(varyings), varyings,
86 GL_INTERLEAVED_ATTRIBS);
87 glLinkProgram(prog);
88 if (!piglit_link_check_status(prog) ||
89 !piglit_check_gl_error(GL_NO_ERROR)) {
90 piglit_report_result(PIGLIT_FAIL);
91 }
92 glUseProgram(prog);
93
94 /* Create transform feedback buffer and pre-load it with
95 * garbage.
96 */
97 glGenBuffers(1, &buf);
98 initial_data = malloc(sizeof(expected_xfb_result));
99 memset(initial_data, 0xcc, sizeof(expected_xfb_result));
100 glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, buf);
101 glBufferData(GL_TRANSFORM_FEEDBACK_BUFFER, sizeof(expected_xfb_result),
102 initial_data, GL_STREAM_READ);
103 free(initial_data);
104
105 /* Run the test */
106 glEnable(GL_RASTERIZER_DISCARD);
107 glBeginTransformFeedback(GL_POINTS);
108 glDrawArrays(GL_POINTS, 0, 1);
109 glEndTransformFeedback();
110
111 /* Check output */
112 readback = glMapBufferRange(GL_TRANSFORM_FEEDBACK_BUFFER, 0,
113 sizeof(expected_xfb_result),
114 GL_MAP_READ_BIT);
115 for (i = 0; i < ARRAY_SIZE(expected_xfb_result); i++) {
116 if (readback[i] != expected_xfb_result[i]) {
117 printf("XFB[%i] == %i, expected %i\n", i, readback[i],
118 expected_xfb_result[i]);
119 pass = false;
120 }
121 }
122 glUnmapBuffer(GL_TRANSFORM_FEEDBACK_BUFFER);
123
124 pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
125 piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
126 }
127
128
129 enum piglit_result
piglit_display(void)130 piglit_display(void)
131 {
132 /* Should never be reached */
133 return PIGLIT_FAIL;
134 }
135