File: hiz-util.h

package info (click to toggle)
piglit 0~git20200212-f4710c51b-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 106,972 kB
  • sloc: ansic: 263,763; xml: 48,941; python: 29,918; lisp: 19,789; cpp: 12,142; sh: 22; makefile: 20; pascal: 5
file content (204 lines) | stat: -rw-r--r-- 7,187 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/*
 * Copyright © 2011 Intel Corporation
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 * IN THE SOFTWARE.
 *
 * Authors:
 *     Chad Versace <chad.versace@intel.com>
 */

/**
 * \file hiz-util.h
 * \brief Utilities for HiZ tests
 * \author Chad Versace <chad.versace@intel.com>
 */

#pragma once

#include "piglit-util-gl.h"

struct hiz_fbo_options {
	GLenum color_format;
	GLenum depth_format;
	GLenum stencil_format;
	GLenum depth_stencil_format;
};

static const GLfloat hiz_green[4]  = { 0.0, 1.0, 0.0, 1.0 };
static const GLfloat hiz_blue[4]   = { 0.0, 0.0, 1.0, 1.0 };
static const GLfloat hiz_grey[4]   = { 0.5, 0.5, 0.5, 1.0 };

/* These must be defines so that they can be used in constant initializers. */
#define hiz_green_z 0.25
#define hiz_blue_z  0.50
#define hiz_clear_z 0.875

/*
 * \brief Probe the color buffer.
 * \param expected_colors An array of 9 pointers, each to a float[4].
 * \return True if all probes pass.
 *
 * The color buffer is probed as follows.  Let the read buffer's dimension be
 * (w, h) and choose a tuple (i, j) where i and j are in {0, 1, 2}. Then the
 * expected color in the subrectangle
 *     {(x, y) | x in w / 3 * [i, i + 1] and y in h / 3 * [j, j + 1]}
 * is expected_colors[3 * j + i].
 */
bool hiz_probe_color_buffer(const float *expected_colors[]);

/*
 * \brief Probe the depth buffer.
 * \param expected_depths Array of 9 floats.
 * \return True if all probes pass.
 * \see hiz_probe_color_buffer()
 */
bool hiz_probe_depth_buffer(const float expected_depths[]);

/**
 * \brief Probe the stencil buffer.
 * \param expected_stencil Array of 9 ints.
 * \return True if all probes pass.
 * \see hiz_probe_color_buffer()
 */
bool hiz_probe_stencil_buffer(const unsigned expected_stencil[]);

GLuint hiz_make_fbo(const struct hiz_fbo_options *options);

/**
 * \brief For Valgrind's sake, delete the FBO and all attached renderbuffers.
 */
void hiz_delete_fbo(GLuint fbo);

/**
 * \brief Check that depth tests work correctly when rendering to an FBO.
 *
 * This test does not probe the depth buffer because correct operation of 1)
 * depth testing and depth writes (via glDraw*) and of 2) depth buffer
 * reads (via glRead*) are independent. It is possible for 1 to work while
 * 2 to fail. This test covers only case 1.
 *
 * \param options Perform the test with an FBO with the given formats.
 * \return True if test passed.
 */
bool hiz_run_test_depth_test_fbo(const struct hiz_fbo_options *options);

/**
 * Check that depth tests work correctly when rendering to the window
 * framebuffer.
 *
 * \param options Perform the test with an FBO with the given formats.
 * \return True if test passed.
 */
bool hiz_run_test_depth_test_window();

/**
 * \brief Check that depth reads work correctly when rendering to an FBO.
 *
 * First, probe the color buffer to check that depth testing worked as
 * expected. If it did not, then immediately report test failure and do not
 * probe the depth buffer. If depth testing misbehaved, we cannot expect
 * the depth buffer to hold the expected values.
 *
 * For this test, depth test is enabled and stencil test disabled.
 *
 * \param options Perform the test with an FBO with the given formats.
 * \return True if test passed.
 *
 * \see hiz_run_test_depth_read_window()
 */
bool hiz_run_test_depth_read_fbo(const struct hiz_fbo_options *options);

/**
 * \brief Check that depth reads work correctly when rendering to the window
 * framebuffer.
 *
 * \param options Perform the test with an FBO with the given formats.
 * \return True if test passed.
 *
 * \see hiz_run_test_depth_read_fbo()
 */
bool hiz_run_test_depth_read_window();

/**
 * \brief Check that stencil testing works correctly when rendering to an FBO.
 *
 * This test probes only the color buffer; it does not probe the stencil
 * buffer. Stencil test is enabled and depth test disabled.
 *
 * This test does not probe the stencil buffer because correct operation of 1)
 * stencil testing and stencil writes (via glDraw*) and of 2) stencil buffer
 * reads (via glRead*) are independent. It is possible for 1 to work while
 * 2 to fail. This test covers only case 1.
 *
 * \param options Perform the test with an FBO with the given formats.
 * \return True if test passed.
 */
bool hiz_run_test_stencil_test_fbo(const struct hiz_fbo_options *options);

/**
 * Check that stencil testing works correctly when rendering to the window
 * framebuffer.
 *
 * \return True if test passed.
 * \see hiz_run_test_stencil_test_fbo()
 */
bool hiz_run_test_stencil_test_window();

/**
 * \brief Test reading the stencil buffer of an FBO.
 *
 * First, probe the color buffer to check that stencil testing worked as
 * expected. If it did not, then immediately report test failure and do not
 * probe the stencil buffer. If stencil testing misbehaved, we cannot expect
 * the stencil buffer to hold the expected values.
 *
 * For this test, stencil test is enabled and depth test disabled.
 *
 * \param options Perform the test with an FBO with the given formats.
 * \return True if test passed.
 */
bool hiz_run_test_stencil_read_fbo(const struct hiz_fbo_options *options);

/**
 * \brief Test reading the stencil buffer of the window framebuffer.
 *
 * \return True if test passed.
 * \see hiz_run_test_stencil_read_fbo()
 */
bool hiz_run_test_stencil_read_window();

/**
 * Check that rendering to an FBO works correctly when depth and stencil test
 * are simultaneously enabled.
 *
 * This test probes only the color buffer; it does not probe the stencil
 * nor the depth buffer.
 *
 * Superficially, this test appears to simply be hiz_run_test_depth_test_fbo()
 * and hiz_run_test_stencil_test_fbo() amalgamated. But, this test's purpose is
 * more sinister than the sum of its parts. It tests for undefined GPU behavior
 * when stencil read/writes are accidentally enabled in hardware when no
 * stencil buffer is present, and analogously for depth read/writes when no
 * depth buffer is present.
 *
 * \param options Perform the test with an FBO with the given formats.
 * \return True if test passed.
 */
bool hiz_run_test_depth_stencil_test_fbo(const struct hiz_fbo_options *options);