perf/pixel-rate: new pixel throughput microbenchmark
[piglit.git] / tests / spec / arb_sample_shading / execution / ignore-centroid-qualifier.cpp
blobcea1f88e8e749d7f6cd840a7c1d9312e8a4bc250
1 /*
2 * Copyright (c) 2014 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 ignore-centroid-qualifier.cpp
27 * Tests that all 'in' variables in fragment shader are interpolated at sample
28 * positions when using per sample shading. Ignore the 'centroid' qualifier if
29 * used with 'in' variable.
32 #include "piglit-util-gl.h"
33 #include "piglit-fbo.h"
35 using namespace piglit_util_fbo;
36 const int pattern_width = 128; const int pattern_height = 128;
38 PIGLIT_GL_TEST_CONFIG_BEGIN
39 config.supports_gl_compat_version = 21;
40 config.supports_gl_core_version = 31;
41 config.window_width = 2 * pattern_width;
42 config.window_height = pattern_height;
43 config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA;
44 config.khr_no_error_support = PIGLIT_NO_ERRORS;
46 PIGLIT_GL_TEST_CONFIG_END
48 static Fbo multisampled_fbo;
49 static int sample_pos_loc, sample_id_loc, num_samples;
50 static int draw_prog_left, draw_prog_right, test_prog;
52 enum piglit_result
53 piglit_display(void)
55 float pos[2];
56 bool result = true, pass = true;
58 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, multisampled_fbo.handle);
59 glClear(GL_COLOR_BUFFER_BIT);
61 /* Draw test image in to left half of multisample fbo*/
62 glUseProgram(draw_prog_left);
63 glViewport(0, 0, pattern_width, pattern_height);
64 glEnable(GL_SAMPLE_SHADING);
65 glMinSampleShading(1.0);
66 piglit_draw_rect(-1, -1, 2, 2);
67 glDisable(GL_SAMPLE_SHADING);
69 for(int i = 0; i < num_samples; i++) {
70 /* Draw reference image in to right half of multisample fbo */
71 glUseProgram(draw_prog_right);
72 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, multisampled_fbo.handle);
73 glGetMultisamplefv(GL_SAMPLE_POSITION, i, pos);
74 glUniform2fv(sample_pos_loc, 1, pos);
75 glEnable(GL_SCISSOR_TEST);
76 glScissor(pattern_width, 0, pattern_width, pattern_height);
77 glViewport(pattern_width, 0, pattern_width, pattern_height);
78 glClear(GL_COLOR_BUFFER_BIT);
79 piglit_draw_rect(-1, -1, 2, 2);
80 glDisable(GL_SCISSOR_TEST);
82 /* Draw sample color from multisample texture in to winsys fbo */
83 glUseProgram(test_prog);
84 glUniform1i(sample_id_loc, i);
85 glViewport(0, 0, 2 * pattern_width, pattern_height);
86 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, piglit_winsys_fbo);
87 glClear(GL_COLOR_BUFFER_BIT);
88 piglit_draw_rect(-1, -1, 2, 2);
90 result = piglit_probe_rect_halves_equal_rgba(0, 0,
91 piglit_width,
92 piglit_height);
93 pass = pass && result;
94 printf("sample_id = %d, result = %s\n", i,
95 result ? "pass" : "fail");
97 piglit_present_results();
98 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
101 static void
102 print_usage_and_exit(char *prog_name)
104 printf("Usage: %s <num_samples>\n", prog_name);
105 piglit_report_result(PIGLIT_FAIL);
108 void
109 piglit_init(int argc, char**argv)
111 if (argc != 2)
112 print_usage_and_exit(argv[0]);
114 /* 1st arg: num_samples */
115 char *endptr = NULL;
116 num_samples = strtol(argv[1], &endptr, 0);
117 if (endptr != argv[1] + strlen(argv[1]))
118 print_usage_and_exit(argv[0]);
120 piglit_require_extension("GL_ARB_texture_multisample");
121 piglit_require_extension("GL_ARB_sample_shading");
122 piglit_require_GLSL_version(130);
124 /* Skip the test if num_samples > GL_MAX_SAMPLES */
125 GLint max_samples;
126 glGetIntegerv(GL_MAX_SAMPLES, &max_samples);
127 if (num_samples == 0 || num_samples > max_samples)
128 piglit_report_result(PIGLIT_SKIP);
130 FboConfig msConfig(num_samples, piglit_width, piglit_height);
131 msConfig.num_rb_attachments = 0;
132 msConfig.num_tex_attachments = 1;
133 multisampled_fbo.setup(msConfig);
135 /* Reduced tolerance for stricter color matching */
136 piglit_set_tolerance_for_bits(16, 16, 16, 16);
137 draw_prog_left = piglit_build_simple_program(
138 "#version 130\n"
139 "#extension GL_ARB_sample_shading: require\n"
140 "in vec4 piglit_vertex;\n"
141 "centroid out vec2 test;\n"
142 "void main() {\n"
143 " gl_Position = piglit_vertex;\n"
144 " test = piglit_vertex.xy;\n"
145 "}\n",
147 "#version 130\n"
148 "#extension GL_ARB_sample_shading: require\n"
149 "centroid in vec2 test;\n"
150 "out vec4 fragcolor;\n"
151 "void main() {\n"
152 " fragcolor = vec4(abs(test), 0, 1);\n"
153 "}\n");
155 draw_prog_right = piglit_build_simple_program(
156 "#version 130\n"
157 "uniform vec2 sample_pos;\n"
158 "in vec4 piglit_vertex;\n"
159 "out vec2 ref;\n"
160 "void main() {\n"
161 " gl_Position = piglit_vertex;\n"
162 " ref = piglit_vertex.xy;\n"
163 /* Add an offset to account for interplolation at
164 * sample position. pattern_width == pattern_height
165 * == 128, so the scaling factor between normalized
166 * device coordinates and pixels is 128/2 == 64.
168 " ref += (sample_pos - 0.5) / 64;\n"
169 "}\n",
171 "#version 130\n"
172 "in vec2 ref;\n"
173 "out vec4 fragcolor;\n"
174 "void main() {\n"
175 " fragcolor = vec4(abs(ref), 0, 1);\n"
176 "}\n");
177 sample_pos_loc = glGetUniformLocation(draw_prog_right, "sample_pos");
179 test_prog = piglit_build_simple_program(
180 "#version 130\n"
181 "in vec4 piglit_vertex;\n"
182 "void main() {\n"
183 " gl_Position = piglit_vertex;\n"
184 "}\n",
186 "#version 130\n"
187 "#extension GL_ARB_texture_multisample: require\n"
188 "uniform int sample_id;\n"
189 "uniform sampler2DMS tex;\n"
190 "out vec4 fragcolor;\n"
191 "void main() {\n"
192 " fragcolor = texelFetch(tex, ivec2(gl_FragCoord.xy),\n"
193 " sample_id);\n"
194 "}\n");
196 glUseProgram(test_prog);
197 glUniform1i(glGetUniformLocation(test_prog, "tex"), 0);
198 sample_id_loc = glGetUniformLocation(test_prog, "sample_id");