[Piglit] [PATCH 2/6] MSAA tests: port all GLSL shaders to GLSL 1.20
Marek Olšák
maraeo at gmail.com
Sun Jan 6 06:12:15 PST 2013
---
tests/spec/ext_framebuffer_multisample/common.cpp | 126 ++++++++++++--------
.../draw-buffers-common.cpp | 52 +++++---
.../ext_framebuffer_multisample/interpolation.cpp | 28 ++---
.../polygon-stipple.cpp | 6 +-
.../sample-coverage.cpp | 6 +-
5 files changed, 130 insertions(+), 88 deletions(-)
diff --git a/tests/spec/ext_framebuffer_multisample/common.cpp b/tests/spec/ext_framebuffer_multisample/common.cpp
index fe6b40b..9109b86 100644
--- a/tests/spec/ext_framebuffer_multisample/common.cpp
+++ b/tests/spec/ext_framebuffer_multisample/common.cpp
@@ -195,12 +195,13 @@ Fbo::try_setup(const FboConfig &new_config)
GL_COLOR_ATTACHMENT0,
GL_RENDERBUFFER, color_rb);
} else {
- glBindTexture(GL_TEXTURE_2D, color_tex);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
+ piglit_require_extension("GL_ARB_texture_rectangle");
+ glBindTexture(GL_TEXTURE_RECTANGLE, color_tex);
+ glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MIN_FILTER,
GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
+ glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MAG_FILTER,
GL_NEAREST);
- glTexImage2D(GL_TEXTURE_2D,
+ glTexImage2D(GL_TEXTURE_RECTANGLE,
0 /* level */,
config.color_internalformat,
config.width,
@@ -211,7 +212,7 @@ Fbo::try_setup(const FboConfig &new_config)
NULL /* data */);
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER,
GL_COLOR_ATTACHMENT0,
- GL_TEXTURE_2D,
+ GL_TEXTURE_RECTANGLE,
color_tex,
0 /* level */);
}
@@ -274,10 +275,10 @@ void
DownsampleProg::compile(int supersample_factor)
{
static const char *vert =
- "#version 130\n"
- "in vec2 pos;\n"
- "in vec2 texCoord;\n"
- "out vec2 texCoordVarying;\n"
+ "#version 120\n"
+ "attribute vec2 pos;\n"
+ "attribute vec2 texCoord;\n"
+ "varying vec2 texCoordVarying;\n"
"void main()\n"
"{\n"
" gl_Position = vec4(pos, 0.0, 1.0);\n"
@@ -285,18 +286,18 @@ DownsampleProg::compile(int supersample_factor)
"}\n";
static const char *frag =
- "#version 130\n"
- "uniform sampler2D samp;\n"
+ "#version 120\n"
+ "uniform sampler2DRect samp;\n"
"uniform int supersample_factor;\n"
- "in vec2 texCoordVarying;\n"
+ "varying vec2 texCoordVarying;\n"
"void main()\n"
"{\n"
" vec4 sum = vec4(0.0);\n"
- " ivec2 pixel = ivec2(texCoordVarying);\n"
+ " vec2 pixel = floor(texCoordVarying);\n"
" for (int i = 0; i < supersample_factor; ++i) {\n"
" for (int j = 0; j < supersample_factor; ++j) {\n"
- " sum += texelFetch(\n"
- " samp, pixel * supersample_factor + ivec2(i, j), 0);\n"
+ " sum += texture2DRect(\n"
+ " samp, pixel * float(supersample_factor) + vec2(i, j));\n"
" }\n"
" }\n"
" gl_FragColor = sum / (supersample_factor * supersample_factor);\n"
@@ -354,7 +355,7 @@ DownsampleProg::run(const Fbo *src_fbo, int dest_width, int dest_height,
float h = dest_height;
glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D, src_fbo->color_tex);
+ glBindTexture(GL_TEXTURE_RECTANGLE, src_fbo->color_tex);
glUseProgram(prog);
glBindVertexArray(vao);
@@ -384,15 +385,15 @@ void
ManifestStencil::compile()
{
static const char *vert =
- "#version 130\n"
- "in vec2 pos;\n"
+ "#version 120\n"
+ "attribute vec2 pos;\n"
"void main()\n"
"{\n"
" gl_Position = vec4(pos, 0.0, 1.0);\n"
"}\n";
static const char *frag =
- "#version 130\n"
+ "#version 120\n"
"uniform vec4 color;\n"
"void main()\n"
"{\n"
@@ -483,8 +484,8 @@ void
ManifestDepth::compile()
{
static const char *vert =
- "#version 130\n"
- "in vec2 pos;\n"
+ "#version 120\n"
+ "attribute vec2 pos;\n"
"uniform float depth;\n"
"void main()\n"
"{\n"
@@ -492,7 +493,7 @@ ManifestDepth::compile()
"}\n";
static const char *frag =
- "#version 130\n"
+ "#version 120\n"
"uniform vec4 color;\n"
"void main()\n"
"{\n"
@@ -618,8 +619,8 @@ void Triangles::compile()
float final_scale = 0.95;
static const char *vert =
- "#version 130\n"
- "in vec2 pos_within_tri;\n"
+ "#version 120\n"
+ "attribute vec2 pos_within_tri;\n"
"uniform float tri_scale;\n"
"uniform float rotation_delta;\n"
"uniform int tris_across;\n"
@@ -633,7 +634,7 @@ void Triangles::compile()
" float rotation = rotation_delta * tri_num;\n"
" pos = mat2(cos(rotation), sin(rotation),\n"
" -sin(rotation), cos(rotation)) * pos;\n"
- " int i = tri_num % tris_across;\n"
+ " int i = int(mod(float(tri_num), float(tris_across)));\n"
" int j = tris_across - 1 - tri_num / tris_across;\n"
" pos += (vec2(i, j) * 2.0 + 1.0) / tris_across - 1.0;\n"
" pos *= final_scale;\n"
@@ -641,7 +642,7 @@ void Triangles::compile()
"}\n";
static const char *frag =
- "#version 130\n"
+ "#version 120\n"
"void main()\n"
"{\n"
" gl_FragColor = vec4(1.0);\n"
@@ -731,13 +732,13 @@ InterpolationTestPattern::compile()
float final_scale = 0.95;
static const char *vert =
- "#version 130\n"
- "in vec2 pos_within_tri;\n"
- "in vec3 in_barycentric_coords;\n"
- "out vec3 barycentric_coords;\n"
- "centroid out vec3 barycentric_coords_centroid;\n"
- "out vec2 pixel_pos;\n"
- "centroid out vec2 pixel_pos_centroid;\n"
+ "#version 120\n"
+ "attribute vec2 pos_within_tri;\n"
+ "attribute vec3 in_barycentric_coords;\n"
+ "varying vec3 barycentric_coords;\n"
+ "centroid varying vec3 barycentric_coords_centroid;\n"
+ "varying vec2 pixel_pos;\n"
+ "centroid varying vec2 pixel_pos_centroid;\n"
"uniform float tri_scale;\n"
"uniform float rotation_delta;\n"
"uniform int tris_across;\n"
@@ -752,7 +753,7 @@ InterpolationTestPattern::compile()
" float rotation = rotation_delta * tri_num;\n"
" pos = mat2(cos(rotation), sin(rotation),\n"
" -sin(rotation), cos(rotation)) * pos;\n"
- " int i = tri_num % tris_across;\n"
+ " int i = int(mod(float(tri_num), float(tris_across)));\n"
" int j = tris_across - 1 - tri_num / tris_across;\n"
" pos += (vec2(i, j) * 2.0 + 1.0) / tris_across - 1.0;\n"
" pos *= final_scale;\n"
@@ -852,8 +853,8 @@ void Lines::compile()
float final_scale = 0.95;
static const char *vert =
- "#version 130\n"
- "in vec2 pos_line;\n"
+ "#version 120\n"
+ "attribute vec2 pos_line;\n"
"uniform float line_scale;\n"
"uniform float rotation_delta;\n"
"uniform int lines_across;\n"
@@ -867,7 +868,7 @@ void Lines::compile()
" float rotation = rotation_delta * line_num;\n"
" pos = mat2(cos(rotation), sin(rotation),\n"
" -sin(rotation), cos(rotation)) * pos;\n"
- " int i = line_num % lines_across;\n"
+ " int i = int(mod(float(line_num), float(lines_across)));\n"
" int j = lines_across - 1 - line_num / lines_across;\n"
" pos += (vec2(i, j) * 2.0 + 1.0) / lines_across - 1.0;\n"
" pos *= final_scale;\n"
@@ -875,7 +876,7 @@ void Lines::compile()
"}\n";
static const char *frag =
- "#version 130\n"
+ "#version 120\n"
"void main()\n"
"{\n"
" gl_FragColor = vec4(1.0);\n"
@@ -951,8 +952,8 @@ void Points::compile()
float final_scale = 0.95;
static const char *vert =
- "#version 130\n"
- "in vec2 pos_point;\n"
+ "#version 120\n"
+ "attribute vec2 pos_point;\n"
"uniform float point_scale;\n"
"uniform int points_across;\n"
"uniform float final_scale;\n"
@@ -963,7 +964,7 @@ void Points::compile()
"void main()\n"
"{\n"
" vec2 pos = point_scale * pos_point;\n"
- " int i = point_num % points_across;\n"
+ " int i = int(mod(float(point_num), float(points_across)));\n"
" int j = points_across - 1 - point_num / points_across;\n"
" pos += (vec2(i, j) * 2.0 + 1.0) / points_across - 1.0;\n"
" pos *= final_scale;\n"
@@ -971,7 +972,7 @@ void Points::compile()
"}\n";
static const char *frag =
- "#version 130\n"
+ "#version 120\n"
"void main()\n"
"{\n"
" gl_FragColor = vec4(1.0);\n"
@@ -1076,15 +1077,20 @@ void Sunburst::compile()
{ { 0.0, 1.0 }, { 0, 1, 0 } },
{ { 0.3, -0.8 }, { 0, 0, 1 } }
};
+ bool need_glsl130 = out_type == GL_INT || out_type == GL_UNSIGNED_INT;
+
+ if (need_glsl130) {
+ piglit_require_gl_version(30);
+ }
/* Total number of triangles drawn */
num_tris = 7;
- static const char *vert =
- "#version 130\n"
- "in vec2 pos_within_tri;\n"
- "in vec3 in_barycentric_coords;\n"
- "out vec3 barycentric_coords;\n"
+ static const char *vert_template =
+ "#version %s\n"
+ "attribute vec2 pos_within_tri;\n"
+ "attribute vec3 in_barycentric_coords;\n"
+ "varying vec3 barycentric_coords;\n"
"uniform float rotation;\n"
"uniform float vert_depth;\n"
"uniform mat4 proj;\n"
@@ -1099,17 +1105,23 @@ void Sunburst::compile()
"}\n";
static const char *frag_template =
- "#version 130\n"
+ "#version %s\n"
"#define OUT_TYPE %s\n"
"#define COMPUTE_DEPTH %s\n"
"uniform float frag_depth;\n"
- "in vec3 barycentric_coords;\n"
+ "varying vec3 barycentric_coords;\n"
"uniform mat3x4 draw_colors;\n"
- "out OUT_TYPE frag_out;\n"
+ "#if __VERSION__ == 130\n"
+ " out OUT_TYPE frag_out;\n"
+ "#endif\n"
"\n"
"void main()\n"
"{\n"
+ "#if __VERSION__ == 130\n"
" frag_out = OUT_TYPE(draw_colors * barycentric_coords);\n"
+ "#else\n"
+ " gl_FragColor = draw_colors * barycentric_coords;\n"
+ "#endif\n"
"#if COMPUTE_DEPTH\n"
" gl_FragDepth = (frag_depth + 1.0) / 2.0;\n"
"#endif\n"
@@ -1117,20 +1129,30 @@ void Sunburst::compile()
/* Compile program */
prog = glCreateProgram();
+ unsigned vert_alloc_len =
+ strlen(vert_template) + 4;
+ char *vert = (char *) malloc(vert_alloc_len);
+ sprintf(vert, vert_template, need_glsl130 ? "130" : "120");
GLint vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vert);
+ free(vert);
glAttachShader(prog, vs);
+
const char *out_type_glsl = get_out_type_glsl();
unsigned frag_alloc_len =
strlen(frag_template) + strlen(out_type_glsl) + 1;
char *frag = (char *) malloc(frag_alloc_len);
- sprintf(frag, frag_template, out_type_glsl,
+ sprintf(frag, frag_template, need_glsl130 ? "130" : "120",
+ out_type_glsl,
compute_depth ? "1" : "0");
GLint fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, frag);
free(frag);
glAttachShader(prog, fs);
+
glBindAttribLocation(prog, 0, "pos_within_tri");
glBindAttribLocation(prog, 1, "in_barycentric_coords");
- glBindFragDataLocation(prog, 0, "frag_out");
+ if (need_glsl130) {
+ glBindFragDataLocation(prog, 0, "frag_out");
+ }
glLinkProgram(prog);
if (!piglit_link_check_status(prog)) {
piglit_report_result(PIGLIT_FAIL);
diff --git a/tests/spec/ext_framebuffer_multisample/draw-buffers-common.cpp b/tests/spec/ext_framebuffer_multisample/draw-buffers-common.cpp
index 3831720..e3a98b2 100644
--- a/tests/spec/ext_framebuffer_multisample/draw-buffers-common.cpp
+++ b/tests/spec/ext_framebuffer_multisample/draw-buffers-common.cpp
@@ -107,9 +107,9 @@ static const GLenum draw_buffers[] = {
/* Offset the viewport transformation on depth value passed to the vertex
* shader by setting it to (2 * depth - 1.0).
*/
-static const char *vert =
- "#version 130\n"
- "in vec2 pos;\n"
+static const char *vert_template =
+ "#version %s\n"
+ "attribute vec2 pos;\n"
"uniform float depth;\n"
"void main()\n"
"{\n"
@@ -122,13 +122,19 @@ static const char *vert =
* are enabled or not.
*/
static const char *frag_template =
- "#version 130\n"
+ "#version %s\n"
"#define DUAL_SRC_BLEND %d\n"
"#define ALPHA_TO_COVERAGE %d\n"
"#define OUT_TYPE %s\n"
+ "#if __VERSION__ == 130\n"
"out OUT_TYPE frag_out_0;\n"
"out vec4 frag_out_1;\n"
"out vec4 frag_out_2;\n"
+ "#else\n"
+ "#define frag_out_0 gl_FragData[0]\n"
+ "#define frag_out_1 gl_FragData[1]\n"
+ "#define frag_out_2 gl_FragData[2]\n"
+ "#endif\n"
"uniform OUT_TYPE frag_0_color;\n"
"uniform vec4 color;\n"
"void main()\n"
@@ -155,16 +161,28 @@ get_out_type_glsl(void)
void
shader_compile(bool sample_alpha_to_coverage, bool dual_src_blend)
{
+ bool need_glsl130 = is_buffer_zero_integer_format || dual_src_blend;
+
+ if (need_glsl130) {
+ piglit_require_gl_version(30);
+ }
+
is_dual_src_blending = dual_src_blend;
+
/* Compile program */
+ unsigned vert_alloc_len = strlen(vert_template) + 4;
+ char *vert = (char *) malloc(vert_alloc_len);
+ sprintf(vert, vert_template, need_glsl130 ? "130" : "120");
GLint vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vert);
+ free(vert);
/* Generate appropriate fragment shader program */
- const char *out_type_glsl = get_out_type_glsl();;
+ const char *out_type_glsl = get_out_type_glsl();
unsigned frag_alloc_len = strlen(frag_template) +
strlen(out_type_glsl) + 1;
char *frag = (char *) malloc(frag_alloc_len);
- sprintf(frag, frag_template, is_dual_src_blending,
+ sprintf(frag, frag_template, need_glsl130 ? "130" : "120",
+ is_dual_src_blending,
sample_alpha_to_coverage, out_type_glsl);
GLint fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, frag);
@@ -175,18 +193,20 @@ shader_compile(bool sample_alpha_to_coverage, bool dual_src_blend)
}
free(frag);
- if (is_dual_src_blending) {
- glBindFragDataLocationIndexed(prog, 0, 0, "frag_out_0");
- glBindFragDataLocationIndexed(prog, 0, 1, "frag_out_1");
+ if (need_glsl130) {
+ if (is_dual_src_blending) {
+ glBindFragDataLocationIndexed(prog, 0, 0, "frag_out_0");
+ glBindFragDataLocationIndexed(prog, 0, 1, "frag_out_1");
+ }
+ else if (num_draw_buffers > 1) {
+ glBindFragDataLocation(prog, 0, "frag_out_0");
+ glBindFragDataLocation(prog, 1, "frag_out_1");
+ glBindFragDataLocation(prog, 2, "frag_out_2");
+ }
+ else
+ glBindFragDataLocation(prog, 0, "frag_out_0");
}
- else if (num_draw_buffers > 1) {
- glBindFragDataLocation(prog, 0, "frag_out_0");
- glBindFragDataLocation(prog, 1, "frag_out_1");
- glBindFragDataLocation(prog, 2, "frag_out_2");
- }
- else
- glBindFragDataLocation(prog, 0, "frag_out_0");
glBindAttribLocation(prog, 0, "pos");
glEnableVertexAttribArray(0);
diff --git a/tests/spec/ext_framebuffer_multisample/interpolation.cpp b/tests/spec/ext_framebuffer_multisample/interpolation.cpp
index 841e0e1..c54491b 100644
--- a/tests/spec/ext_framebuffer_multisample/interpolation.cpp
+++ b/tests/spec/ext_framebuffer_multisample/interpolation.cpp
@@ -167,8 +167,8 @@ bool disable_msaa_during_test_image = false;
* each triangle.
*/
const char *frag_non_centroid_barycentric =
- "#version 130\n"
- "in vec3 barycentric_coords;\n"
+ "#version 120\n"
+ "varying vec3 barycentric_coords;\n"
"\n"
"void main()\n"
"{\n"
@@ -182,8 +182,8 @@ const char *frag_non_centroid_barycentric =
* triangle.
*/
const char *frag_centroid_barycentric =
- "#version 130\n"
- "centroid in vec3 barycentric_coords_centroid;\n"
+ "#version 120\n"
+ "centroid varying vec3 barycentric_coords_centroid;\n"
"\n"
"void main()\n"
"{\n"
@@ -197,8 +197,8 @@ const char *frag_centroid_barycentric =
* barycentric coordinates is outside the range [0, 1].
*/
const char *frag_centroid_range_check =
- "#version 130\n"
- "centroid in vec3 barycentric_coords_centroid;\n"
+ "#version 120\n"
+ "centroid varying vec3 barycentric_coords_centroid;\n"
"\n"
"void main()\n"
"{\n"
@@ -218,8 +218,8 @@ const char *frag_centroid_range_check =
* are non-centroid interpolated.
*/
const char *frag_non_centroid_deriv =
- "#version 130\n"
- "in vec2 pixel_pos;\n"
+ "#version 120\n"
+ "varying vec2 pixel_pos;\n"
"\n"
"void main()\n"
"{\n"
@@ -237,8 +237,8 @@ const char *frag_non_centroid_deriv =
* are non-centroid interpolated.
*/
const char *frag_centroid_deriv =
- "#version 130\n"
- "centroid in vec2 pixel_pos_centroid;\n"
+ "#version 120\n"
+ "centroid varying vec2 pixel_pos_centroid;\n"
"\n"
"void main()\n"
"{\n"
@@ -254,8 +254,8 @@ const char *frag_centroid_deriv =
* tolerance.
*/
const char *frag_centroid_deriv_range_check =
- "#version 130\n"
- "centroid in vec2 pixel_pos_centroid;\n"
+ "#version 120\n"
+ "centroid varying vec2 pixel_pos_centroid;\n"
"\n"
"void main()\n"
"{\n"
@@ -272,7 +272,7 @@ const char *frag_centroid_deriv_range_check =
* frag_centroid_range_check and frag_centroid_deriv_range_check).
*/
const char *frag_blue =
- "#version 130\n"
+ "#version 120\n"
"\n"
"void main()\n"
"{\n"
@@ -286,7 +286,7 @@ const char *frag_blue =
* frag_centroid_deriv).
*/
const char *frag_rg_0_5 =
- "#version 130\n"
+ "#version 120\n"
"\n"
"void main()\n"
"{\n"
diff --git a/tests/spec/ext_framebuffer_multisample/polygon-stipple.cpp b/tests/spec/ext_framebuffer_multisample/polygon-stipple.cpp
index 578ac60..3394695 100644
--- a/tests/spec/ext_framebuffer_multisample/polygon-stipple.cpp
+++ b/tests/spec/ext_framebuffer_multisample/polygon-stipple.cpp
@@ -97,8 +97,8 @@ static GLubyte stipple_pattern[] =
};
static const char *vert =
- "#version 130\n"
- "in vec2 pos;\n"
+ "#version 120\n"
+ "attribute vec2 pos;\n"
"uniform float depth;\n"
"void main()\n"
"{\n"
@@ -107,7 +107,7 @@ static const char *vert =
"}\n";
static const char *frag =
- "#version 130\n"
+ "#version 120\n"
"uniform vec4 color;\n"
"void main()\n"
"{\n"
diff --git a/tests/spec/ext_framebuffer_multisample/sample-coverage.cpp b/tests/spec/ext_framebuffer_multisample/sample-coverage.cpp
index 1838f8e..d0ce4a0 100644
--- a/tests/spec/ext_framebuffer_multisample/sample-coverage.cpp
+++ b/tests/spec/ext_framebuffer_multisample/sample-coverage.cpp
@@ -91,8 +91,8 @@ static int depth_loc;
static const float bg_color[4] = { 0.4, 0.6, 0.0, 0.8 };
static const char *vert =
- "#version 130\n"
- "in vec2 pos;\n"
+ "#version 120\n"
+ "attribute vec2 pos;\n"
"uniform float depth;\n"
"void main()\n"
"{\n"
@@ -101,7 +101,7 @@ static const char *vert =
"}\n";
static const char *frag =
- "#version 130\n"
+ "#version 120\n"
"uniform vec4 color;\n"
"void main()\n"
"{\n"
--
1.7.10.4
More information about the Piglit
mailing list