ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / arb_separate_shader_objects / sso-common.c
blob64907261a7363c889c2d14c2132bd3fff4a93a69
1 /*
2 * Copyright © 2013 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 DEALINGS
21 * IN THE SOFTWARE.
24 /**
25 * \file sso-common.c
26 * Utility functions used by multiple separate shader objects tests.
28 #include "piglit-util-gl.h"
29 #include "sso-common.h"
31 /**
32 * Pick a GLSL version that will work with explicit location layout qualifiers
34 * Some NVIDIA drivers have issues with layout qualifiers, 'in' keywords, and
35 * 'out' keywords in "lower" GLSL versions. If the driver supports GLSL >=
36 * 1.40, use 1.40. Otherwise, pick the highest version that the driver
37 * supports.
39 * 1.40 is selected as the maximum version because core-profile contexts
40 * aren't required to support versions earlier than 1.40. Otherwise, 1.30
41 * would also work.
43 unsigned
44 pick_a_glsl_version(void)
46 unsigned glsl_version;
47 bool es;
48 int glsl_major;
49 int glsl_minor;
51 piglit_get_glsl_version(&es, &glsl_major, &glsl_minor);
52 glsl_version = ((glsl_major * 100) + glsl_minor) >= 140
53 ? 140 : ((glsl_major * 100) + glsl_minor);
55 return glsl_version;
58 GLuint
59 format_and_link_program(GLenum type, const char* code, unsigned glsl_version)
61 char *source;
62 GLuint prog;
64 (void)!asprintf(&source, code, glsl_version);
65 prog = glCreateShaderProgramv(type, 1,
66 (const GLchar *const *) &source);
68 piglit_link_check_status(prog);
69 free(source);
71 return prog;
74 /**
75 * Create a transform feedback object and some storage for the data
77 * \note
78 * The XFB object will be bound on exit. The buffer object for the XFB data
79 * will be bound to the XFB object and the \c GL_TRANSFORM_FEEDBACK_BUFFER
80 * binding on exit.
82 void
83 configure_transform_feedback_object(GLuint *xfb, GLuint *buf)
85 glGenBuffers(1, buf);
86 glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, *buf);
87 glBufferData(GL_TRANSFORM_FEEDBACK_BUFFER, 1024, NULL, GL_STREAM_READ);
89 glGenTransformFeedbacks(1, xfb);
91 glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, *xfb);
92 glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, *buf);
95 /**
96 * Create a separable vertex shader program with transform feedback output
98 * A vertex shader must be created using the "traditional" API because
99 * \c glTransformFeedbackVaryings must be called before linking. There is no
100 * way to do that with \c glCreateShaderProgramv.
102 bool
103 CreateShaderProgram_with_xfb(const char *source,
104 const char **varyings,
105 unsigned num_varyings,
106 GLuint *vs_prog)
108 GLuint vs = piglit_compile_shader_text(GL_VERTEX_SHADER, source);
110 *vs_prog = glCreateProgram();
111 glAttachShader(*vs_prog, vs);
113 glProgramParameteri(*vs_prog, GL_PROGRAM_SEPARABLE, GL_TRUE);
114 glTransformFeedbackVaryings(*vs_prog, num_varyings, varyings,
115 GL_INTERLEAVED_ATTRIBS);
116 glLinkProgram(*vs_prog);
117 glDeleteShader(vs);
119 return piglit_link_check_status(*vs_prog);