1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
|
/*
* Copyright © 2014 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
/**
* \file xfb-rendezvous_by_location.c
* Verify that transform feedback data lands in the correct place when
* rendezvous-by-location is used.
*
* Use a single vertex shader with outputs with non-contiguous explicit
* locations. Specify transform feedback with the vertex shader outputs
* landing in a different order than the explicit locations specify. Verify
* that the order specified by glTransformFeedbackVaryings is used.
*/
#include "piglit-util-gl.h"
#include "sso-common.h"
PIGLIT_GL_TEST_CONFIG_BEGIN
config.supports_gl_compat_version = 21;
config.supports_gl_core_version = 31;
config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
PIGLIT_GL_TEST_CONFIG_END
static const char *vs_template =
"#version %d\n"
"#extension GL_ARB_separate_shader_objects: require\n"
"#extension GL_ARB_explicit_attrib_location: require\n"
"\n"
"layout(location = 0) in vec4 piglit_vertex;\n"
"\n"
"layout(location = 1) out vec3 a;\n"
"layout(location = 3) out vec3 b;\n"
"\n"
"void main()\n"
"{\n"
" gl_Position = piglit_vertex;\n"
" a = piglit_vertex.xyz;\n"
" b = vec3(3, 5, 7);\n"
"}\n"
;
void piglit_init(int argc, char **argv)
{
unsigned glsl_version;
GLuint vs_prog = 0;
GLuint buf = 0;
GLuint xfb = 0;
GLuint pipe = 0;
char *source;
float *data;
unsigned i;
bool pass = true;
static const char *varyings[] = {"b", "a"};
/* The vertex data is expected in this order because piglit_draw_rect
* uses a GL_TRIANGLE_STRIP to draw the rectangle.
*/
static const float expected_data[6 * 6] = {
3, 5, 7, -1, -1, 0,
3, 5, 7, 1, -1, 0,
3, 5, 7, -1, 1, 0,
3, 5, 7, -1, 1, 0,
3, 5, 7, 1, -1, 0,
3, 5, 7, 1, 1, 0
};
piglit_require_extension("GL_ARB_separate_shader_objects");
piglit_require_extension("GL_ARB_explicit_attrib_location");
piglit_require_extension("GL_ARB_transform_feedback2");
glsl_version = pick_a_glsl_version();
/* The vertex shader must be created using the "traditional" method
* because we the call glTransformFeedbackVaryings before linking.
*/
(void)!asprintf(&source, vs_template, glsl_version);
if (!CreateShaderProgram_with_xfb(source, varyings,
ARRAY_SIZE(varyings), &vs_prog)) {
pass = false;
goto done;
}
glGenProgramPipelines(1, &pipe);
glBindProgramPipeline(pipe);
glUseProgramStages(pipe,
GL_VERTEX_SHADER_BIT,
vs_prog);
configure_transform_feedback_object(&xfb, &buf);
glEnable(GL_RASTERIZER_DISCARD);
/* This will generate 4 vertices worth of transform feedback data.
*/
glBeginTransformFeedback(GL_TRIANGLES);
piglit_draw_rect(-1, -1, 2, 2);
glEndTransformFeedback();
/* Verify that the correct data landed in the correct places.
*/
data = glMapBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, GL_READ_ONLY);
for (i = 0; i < 6; i++) {
if (memcmp(&data[i * 6], &expected_data[i * 6],
sizeof(float) * 6) != 0) {
printf("Incorrect XFB data for veretx %d. Got\n", i);
printf(" %f %f %f %f %f %f\n",
data[(i * 6) + 0],
data[(i * 6) + 1],
data[(i * 6) + 2],
data[(i * 6) + 3],
data[(i * 6) + 4],
data[(i * 6) + 5]);
printf("but expected\n");
printf(" %f %f %f %f %f %f\n\n",
expected_data[(i * 6) + 0],
expected_data[(i * 6) + 1],
expected_data[(i * 6) + 2],
expected_data[(i * 6) + 3],
expected_data[(i * 6) + 4],
expected_data[(i * 6) + 5]);
}
}
glUnmapBuffer(GL_TRANSFORM_FEEDBACK_BUFFER);
pass = piglit_check_gl_error(0) && pass;
done:
free(source);
glBindProgramPipeline(0);
glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, 0);
glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
glDeleteBuffers(1, &buf);
glDeleteTransformFeedbacks(1, &xfb);
glDeleteProgramPipelines(1, &pipe);
glDeleteProgram(vs_prog);
pass = piglit_check_gl_error(0) && pass;
piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
}
enum piglit_result
piglit_display(void)
{
return PIGLIT_FAIL;
}
|