ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / arb_blend_func_extended / execution / fbo-extended-blend-pattern.c
blob94c779175db492093ac939579829f7198c56e4cd
1 /*
2 * Copyright (c) 2015 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 fbo-extended-blend-pattern.c
26 * @author Iago Toral Quiroga <itoral@igalia.com>
28 * On Intel hardware at least, SIMD16 dual source rendering requires handling
29 * pixel data in two sets of 8 pixels each. Incorrect implementations may fail
30 * to map correct colors for each pixel group (for example by using the color
31 * for the first group as the color for the second group or viceversa). However,
32 * tests that render using solid colors across the entire polygon won't catch
33 * these cases (since in that case the color is the same for boths groups of
34 * pixels).
36 * This test blends using a checker board pattern where each cell is
37 * 10px wide and 10px tall. This makes it so that the two sets of 8 pixels
38 * issued during SIMD16 operation pack different color data for the pixels
39 * involved, enabling testing of correct behavior in that case.
41 * This only tests with one specific blend mode. There is no need to test
42 * others, since the details of SIMD16 operation are independent of the
43 * specific blend mode we use and general testing of the multiple blend modes
44 * and parameters is already covered by the tests in fbo-extended-blend.c.
47 #include "piglit-util-gl.h"
49 PIGLIT_GL_TEST_CONFIG_BEGIN
51 #ifdef PIGLIT_USE_OPENGL
52 config.supports_gl_compat_version = 30;
53 #elif PIGLIT_USE_OPENGL_ES3
54 config.supports_gl_es_version = 30;
55 #else // PIGLIT_USE_OPENGL_ES2
56 config.supports_gl_es_version = 20;
57 #endif
58 config.window_visual = PIGLIT_GL_VISUAL_RGB;
59 config.khr_no_error_support = PIGLIT_NO_ERRORS;
61 PIGLIT_GL_TEST_CONFIG_END
63 static const char *TestName = "fbo-extended-blend-pattern";
65 static GLint uniform_src0, uniform_src1, uniform_src2;
67 #ifdef PIGLIT_USE_OPENGL
68 static const char *vs_text =
69 "#version 130\n"
70 "in vec4 piglit_vertex;\n"
71 "void main() {\n"
72 " gl_Position = piglit_vertex;\n"
73 "}\n"
76 static const char *fs_text =
77 "#version 130\n"
78 "#extension GL_ARB_explicit_attrib_location: require\n"
79 "uniform vec4 src0;\n"
80 "uniform vec4 src1;\n"
81 "uniform vec4 src2;\n"
82 "layout(location = 0, index = 0) out vec4 col0;\n"
83 "layout(location = 0, index = 1) out vec4 col1;\n"
84 "void main() {\n"
85 " int a = int(gl_FragCoord.x) / 10;\n"
86 " int b = int(gl_FragCoord.y) / 10;\n"
87 " int c = (a + b) % 2;\n"
88 " col0 = src0;\n"
89 " if (c == 0)\n"
90 " col1 = src1;\n"
91 " else\n"
92 " col1 = src2;\n"
93 "}\n"
95 #elif PIGLIT_USE_OPENGL_ES3
96 static const char *vs_text =
97 "#version 300 es\n"
98 "in vec4 piglit_vertex;\n"
99 "void main() {\n"
100 " gl_Position = piglit_vertex;\n"
101 "}\n"
104 static const char *fs_text =
105 "#version 300 es\n"
106 "#extension GL_EXT_blend_func_extended : enable\n"
107 "precision highp float;\n"
108 "uniform vec4 src0;\n"
109 "uniform vec4 src1;\n"
110 "uniform vec4 src2;\n"
111 "layout(location = 0, index = 0) out vec4 col0;\n"
112 "layout(location = 0, index = 1) out vec4 col1;\n"
113 "void main() {\n"
114 " int a = int(gl_FragCoord.x) / 10;\n"
115 " int b = int(gl_FragCoord.y) / 10;\n"
116 " int c = (a + b) % 2;\n"
117 " col0 = src0;\n"
118 " if (c == 0)\n"
119 " col1 = src1;\n"
120 " else\n"
121 " col1 = src2;\n"
122 "}\n"
124 #else // PIGLIT_USE_OPENGL_ES2
125 static const char *vs_text =
126 "#version 100\n"
127 "attribute vec4 piglit_vertex;\n"
128 "void main() {\n"
129 " gl_Position = piglit_vertex;\n"
130 "}\n"
133 static const char *fs_text =
134 "#version 100\n"
135 "#extension GL_EXT_blend_func_extended : enable\n"
136 "precision highp float;\n"
137 "uniform vec4 src0;\n"
138 "uniform vec4 src1;\n"
139 "uniform vec4 src2;\n"
140 "void main() {\n"
141 " float a = floor(gl_FragCoord.x / 10.0);\n"
142 " float b = floor(gl_FragCoord.y / 10.0);\n"
143 " float c = floor(mod(a + b, 2.0));\n"
144 " gl_FragColor = src0;\n"
145 " if (c == 0.0)\n"
146 " gl_SecondaryFragColorEXT = src1;\n"
147 " else\n"
148 " gl_SecondaryFragColorEXT = src2;\n"
149 "}\n"
152 #endif
154 static void
155 check_error(int line)
157 GLenum err = glGetError();
158 if (err) {
159 printf("%s: Unexpected error 0x%x at line %d\n", TestName, err, line);
160 piglit_report_result(PIGLIT_FAIL);
164 static void
165 blend(const float *src, const float *src1, const float *src2, const float *dst)
167 glUniform4fv(uniform_src0, 1, dst);
168 piglit_draw_rect(-1, -1, 2, 2);
169 glEnable(GL_BLEND);
170 glBlendFunc(GL_SRC_COLOR, GL_SRC1_COLOR);
171 glUniform4fv(uniform_src0, 1, src);
172 glUniform4fv(uniform_src1, 1, src1);
173 glUniform4fv(uniform_src2, 1, src2);
174 piglit_draw_rect(-1, -1, 2, 2);
175 glDisable(GL_BLEND);
176 glFinish();
179 enum piglit_result
180 piglit_display(void)
182 static const GLfloat dest_color[4] = { 1.0, 1.0, 1.0, 1.0 };
183 static const GLfloat test_color[4] = { 1.0, 0.0, 0.0, 1.0 };
184 static const GLfloat test_color1[4] = { 0.0, 1.0, 0.0, 1.0 };
185 static const GLfloat test_color2[4] = { 0.0, 0.0, 1.0, 1.0 };
186 static const GLfloat expected1[4] = { 1.0, 1.0, 0.0, 1.0 };
187 static const GLfloat expected2[4] = { 1.0, 0.0, 1.0, 1.0 };
188 GLuint prog;
190 glClearColor(0, 0, 0, 1);
191 glClear(GL_COLOR_BUFFER_BIT);
193 prog = piglit_build_simple_program(vs_text, fs_text);
194 glUseProgram(prog);
196 uniform_src0 = glGetUniformLocation(prog, "src0");
197 uniform_src1 = glGetUniformLocation(prog, "src1");
198 uniform_src2 = glGetUniformLocation(prog, "src2");
200 blend(test_color, test_color1, test_color2, dest_color);
201 check_error(__LINE__);
203 if (!piglit_probe_rect_rgba(0, 0, 10, 10, expected1)) /* cell (0,0) */
204 return PIGLIT_FAIL;
205 if (!piglit_probe_rect_rgba(10, 0, 10, 10, expected2)) /* cell (1,0) */
206 return PIGLIT_FAIL;
207 if (!piglit_probe_rect_rgba(0, 10, 10, 10, expected2)) /* cell (0,1) */
208 return PIGLIT_FAIL;
209 if (!piglit_probe_rect_rgba(10, 10, 10, 10, expected1)) /* cell (1,1) */
210 return PIGLIT_FAIL;
212 return PIGLIT_PASS;
215 void
216 piglit_init(int argc, char **argv)
218 #ifdef PIGLIT_USE_OPENGL
219 piglit_require_extension("GL_ARB_blend_func_extended");
220 piglit_require_extension("GL_ARB_explicit_attrib_location");
221 #else // PIGLIT_USE_OPENGL_ES{2, 3}
222 piglit_require_extension("GL_EXT_blend_func_extended");
223 #endif