1 /*
2 * Copyright © 2011 Marek Olšák <maraeo@gmail.com>
3 * Copyright © 2015 Red Hat
4 *
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:
11 *
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.
15 *
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 DEALINGS
22 * IN THE SOFTWARE.
23 *
24 * Authors:
25 * Dave Airlie
26 */
27
28 /**
29 * ARB_gpu_shader_fp64 + EXT_transform_feedback test.
30 *
31 * Test writing separate double vertex attribs into a buffer object.
32 * this is based on Marek's separate.c test for EXT_transform_feedback
33 */
34
35 #include "piglit-util-gl.h"
36
37 PIGLIT_GL_TEST_CONFIG_BEGIN
38
39 config.supports_gl_core_version = 32;
40 config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA;
41 config.khr_no_error_support = PIGLIT_NO_ERRORS;
42
43 PIGLIT_GL_TEST_CONFIG_END
44
45 static const char *vstext = {
46 "#version 150\n"
47 "#extension GL_ARB_gpu_shader_fp64 : require\n"
48 "in vec4 vertex;"
49 "out vec4 color;"
50 "out vec4 texcoord[2];"
51 "out dvec3 v3;"
52 "out dvec2 v2;"
53 "void main() {"
54 " gl_Position = vertex;"
55 " color = vec4(1.0, 0.9, 0.8, 0.7);"
56 " texcoord[0] = vec4(0.5);"
57 " texcoord[1] = vec4(0.6, 0.0, 0.1, 0.6);"
58 " v2 = dvec2(0.2lf, 0.7lf);"
59 " v3 = dvec3(0.55lf, 0.66lf, 0.77lf);"
60 "}"
61 };
62
63 static const char *varyings[] = {"v3", "color", "v2", "texcoord[1]"};
64 GLuint buf[4];
65 GLuint prog;
66 GLuint vbo, vao;
67
68 #define NUM_OUT_VERTICES 6
69
piglit_init(int argc,char ** argv)70 void piglit_init(int argc, char **argv)
71 {
72 GLuint vs;
73 GLint maxcomps, maxattrs;
74 unsigned i;
75
76 /* Check the driver. */
77 piglit_require_transform_feedback();
78 piglit_require_extension("GL_ARB_gpu_shader_fp64");
79
80 glGetIntegerv(GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS_EXT, &maxattrs);
81 if (maxattrs < 4) {
82 fprintf(stderr, "Not enough separate attribs supported by transform feedback.\n");
83 piglit_report_result(PIGLIT_SKIP);
84 }
85 glGetIntegerv(GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS_EXT, &maxcomps);
86 if (maxcomps < 4) {
87 fprintf(stderr, "Not enough separate components supported by transform feedback.\n");
88 piglit_report_result(PIGLIT_SKIP);
89 }
90
91 /* Create shaders. */
92 vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vstext);
93 prog = glCreateProgram();
94 glAttachShader(prog, vs);
95 glTransformFeedbackVaryings(prog, sizeof(varyings)/sizeof(varyings[0]),
96 varyings, GL_SEPARATE_ATTRIBS_EXT);
97 glLinkProgram(prog);
98 if (!piglit_link_check_status(prog)) {
99 glDeleteProgram(prog);
100 piglit_report_result(PIGLIT_FAIL);
101 }
102
103 /* Set up the transform feedback buffer. */
104 glGenBuffers(4, buf);
105 for (i = 0; i < 4; i++) {
106 unsigned j;
107 float *ptr;
108 glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER_EXT, buf[i]);
109 glBufferData(GL_TRANSFORM_FEEDBACK_BUFFER_EXT,
110 NUM_OUT_VERTICES*8*sizeof(float), NULL, GL_STREAM_READ);
111 ptr = glMapBuffer(GL_TRANSFORM_FEEDBACK_BUFFER_EXT, GL_WRITE_ONLY);
112 for (j = 0; j < NUM_OUT_VERTICES*4; j++) {
113 ptr[j] = 0.123456;
114 }
115 glUnmapBuffer(GL_TRANSFORM_FEEDBACK_BUFFER_EXT);
116 glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER_EXT, i, buf[i]);
117 }
118
119 if (!piglit_check_gl_error(GL_NO_ERROR))
120 piglit_report_result(PIGLIT_FAIL);
121
122 glClearColor(0.2, 0.2, 0.2, 1.0);
123 }
124
piglit_display(void)125 enum piglit_result piglit_display(void)
126 {
127 bool pass = true;
128 static const float verts[] = {
129 10, 10,
130 10, 20,
131 20, 20,
132 20, 10
133 };
134 static const double v3[] = {0.55, 0.66, 0.77};
135 static const float frontcolor[] = {1.0, 0.9, 0.8, 0.7};
136 static const double v2[] = {0.2, 0.7};
137 static const float texcoord1[] = {0.6, 0.0, 0.1, 0.6};
138
139 glGenVertexArrays(1, &vao);
140 glBindVertexArray(vao);
141
142 glGenBuffers(1, &vbo);
143 glBindBuffer(GL_ARRAY_BUFFER, vbo);
144 glBufferData(GL_ARRAY_BUFFER, sizeof(verts), verts, GL_STATIC_DRAW);
145 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, (GLvoid const *)0);
146
147 glClear(GL_COLOR_BUFFER_BIT);
148
149 /* Render into TFBO. */
150 glUseProgram(prog);
151 glEnable(GL_RASTERIZER_DISCARD);
152 glBeginTransformFeedback(GL_TRIANGLES);
153 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
154 glEndTransformFeedback();
155 glDisable(GL_RASTERIZER_DISCARD);
156
157 if (!piglit_check_gl_error(GL_NO_ERROR))
158 piglit_report_result(PIGLIT_FAIL);
159
160 pass = piglit_probe_buffer_doubles(buf[0], GL_TRANSFORM_FEEDBACK_BUFFER_EXT,
161 "Buffer[0]", NUM_OUT_VERTICES, 3, v3) && pass;
162 pass = piglit_probe_buffer(buf[1], GL_TRANSFORM_FEEDBACK_BUFFER_EXT,
163 "Buffer[1]", NUM_OUT_VERTICES, 4, frontcolor)&& pass;
164 pass = piglit_probe_buffer_doubles(buf[2], GL_TRANSFORM_FEEDBACK_BUFFER_EXT,
165 "Buffer[2]", NUM_OUT_VERTICES, 2, v2) && pass;
166 pass = piglit_probe_buffer(buf[3], GL_TRANSFORM_FEEDBACK_BUFFER_EXT,
167 "Buffer[3]", NUM_OUT_VERTICES, 4, texcoord1) && pass;
168
169 if (!piglit_check_gl_error(GL_NO_ERROR))
170 piglit_report_result(PIGLIT_FAIL);
171
172 piglit_present_results();
173
174 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
175 }
176