ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / ext_framebuffer_multisample / common.h
blob948a1d4a84a6e57878086062d4500d61074d0558
1 /* Copyright © 2012 Intel Corporation
3 * Permission is hereby granted, free of charge, to any person obtaining a
4 * copy of this software and associated documentation files (the "Software"),
5 * to deal in the Software without restriction, including without limitation
6 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
7 * and/or sell copies of the Software, and to permit persons to whom the
8 * Software is furnished to do so, subject to the following conditions:
10 * The above copyright notice and this permission notice (including the next
11 * paragraph) shall be included in all copies or substantial portions of the
12 * Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20 * IN THE SOFTWARE.
23 /**
24 * \file common.h
25 * This file declares functions which can be utilized to develop new multisample
26 * test cases.
29 #include "piglit-util-gl.h"
30 #include "piglit-test-pattern.h"
31 #include "piglit-fbo.h"
32 #include "math.h"
34 enum test_type_enum {
35 TEST_TYPE_COLOR,
36 TEST_TYPE_SRGB,
37 TEST_TYPE_STENCIL_DRAW,
38 TEST_TYPE_STENCIL_RESOLVE,
39 TEST_TYPE_DEPTH_DRAW,
40 TEST_TYPE_DEPTH_RESOLVE,
43 /**
44 * Fragment shader program we apply to the supersampled color buffer
45 * to produce the reference image. This program manually blends each
46 * 16x16 block of samples in the supersampled color buffer down to a
47 * single sample in the downsampled buffer.
49 class DownsampleProg
51 public:
52 void compile(int supersample_factor);
53 void run(const piglit_util_fbo::Fbo *src_fbo,
54 int dest_width, int dest_height,
55 bool srgb);
57 private:
58 GLint prog;
59 GLuint vertex_buf;
60 GLuint vao;
63 /**
64 * Data structure for keeping track of statistics on pixel accuracy.
66 * We keep track of the number of pixels tested, and the sum of the
67 * squared error, so that we can summarize the RMS error at the
68 * conclusion of the test.
70 class Stats
72 public:
73 Stats();
75 void record(float error)
77 ++count;
78 sum_squared_error += error * error;
81 void summarize();
83 bool is_perfect();
85 bool is_better_than(double rms_error_threshold);
87 private:
88 int count;
89 double sum_squared_error;
92 /**
93 * This data structure wraps up all the data we need to keep track of
94 * to run the test.
96 class Test
98 public:
99 Test(piglit_util_test_pattern::TestPattern *pattern,
100 piglit_util_test_pattern::ManifestProgram *manifest_program,
101 bool test_resolve, GLbitfield blit_type, bool srgb);
102 void init(int num_samples, bool small, bool combine_depth_stencil,
103 int pattern_width, int pattern_height,
104 int supersample_factor, GLenum filter_mode);
105 bool run();
106 void draw_test_image(piglit_util_fbo::Fbo *fbo);
107 void draw_to_default_framebuffer();
108 void draw_reference_image();
109 bool measure_accuracy();
112 * Fbo that we use to just draw test image
114 piglit_util_fbo::Fbo test_fbo;
116 private:
117 void resolve(piglit_util_fbo::Fbo *fbo, GLbitfield which_buffers);
118 void downsample_color(int downsampled_width, int downsampled_height);
119 void show(piglit_util_fbo::Fbo *src_fbo, int x_offset, int y_offset);
120 void draw_pattern(int x_offset, int y_offset, int width, int height);
122 /** The test pattern to draw. */
123 piglit_util_test_pattern::TestPattern *pattern;
126 * The program to use to manifest depth or stencil into color,
127 * or NULL if we're just testing color rendering.
129 piglit_util_test_pattern::ManifestProgram *manifest_program;
132 * True if we are testing the resolve pass, so we should
133 * downsample before manifesting; false if we should manifest
134 * before downsampling.
136 bool test_resolve;
139 * The buffer under test--this should be compatible with the
140 * "mask" argument of
141 * glBlitFramebuffer--i.e. GL_COLOR_BUFFER_BIT,
142 * GL_STENCIL_BUFFER_BIT, or GL_DEPTH_BUFFER_BIT.
144 GLbitfield blit_type;
147 * Fbo that we perform MSAA rendering into.
149 piglit_util_fbo::Fbo multisample_fbo;
152 * Single-sampled fbo that we blit into to force the
153 * implementation to resolve MSAA buffers.
155 piglit_util_fbo::Fbo resolve_fbo;
158 * Large fbo that we perform high-resolution ("supersampled")
159 * rendering into.
161 piglit_util_fbo::Fbo supersample_fbo;
164 * Normal-sized fbo that we manually downsample the
165 * supersampled render result into, to create the reference
166 * image.
168 piglit_util_fbo::Fbo downsample_fbo;
170 int num_samples;
171 int pattern_width;
172 int pattern_height;
173 int supersample_factor;
174 bool srgb;
175 DownsampleProg downsample_prog;
178 * Filter mode to use when downsampling the image
180 GLenum filter_mode;
183 Test *
184 create_test(test_type_enum test_type, int n_samples, bool small,
185 bool combine_depth_stencil, int pattern_width,
186 int pattern_height, int supersample_factor, GLenum filter_mode);