2 * Copyright © 2023 Zeb Figura
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
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
21 * DEALINGS IN THE SOFTWARE.
24 /** @file depth-copy.c
26 * A regression test for a broken code path in radeonsi related to
30 #include "piglit-util-gl.h"
33 PIGLIT_GL_TEST_CONFIG_BEGIN
35 config
.supports_gl_compat_version
= 11;
36 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
| PIGLIT_GL_VISUAL_DOUBLE
|
37 PIGLIT_GL_VISUAL_DEPTH
;
39 PIGLIT_GL_TEST_CONFIG_END
41 void piglit_init(int argc
, char **argv
)
43 piglit_require_extension("GL_ARB_copy_image");
44 piglit_require_extension("GL_ARB_framebuffer_object");
45 glDepthFunc(GL_ALWAYS
);
46 glEnable(GL_DEPTH_TEST
);
50 enum piglit_result
piglit_display(void)
57 glGenTextures(2, depth
);
58 glBindTexture(GL_TEXTURE_2D
, depth
[0]);
59 glTexStorage2D(GL_TEXTURE_2D
, 1, GL_DEPTH_COMPONENT24
, piglit_width
, piglit_height
);
60 glBindTexture(GL_TEXTURE_2D
, depth
[1]);
61 glTexStorage2D(GL_TEXTURE_2D
, 1, GL_DEPTH_COMPONENT24
, piglit_width
, piglit_height
);
63 /* Clear the first texture to 0. */
64 glGenFramebuffers(1, &fb
);
65 glBindFramebuffer(GL_FRAMEBUFFER
, fb
);
66 glFramebufferTexture2D(GL_FRAMEBUFFER
, GL_DEPTH_ATTACHMENT
, GL_TEXTURE_2D
, depth
[0], 0);
67 assert(glCheckFramebufferStatus(GL_FRAMEBUFFER
) == GL_FRAMEBUFFER_COMPLETE
);
69 glClear(GL_DEPTH_BUFFER_BIT
);
71 /* Copy to the second texture. */
72 glCopyImageSubData(depth
[0], GL_TEXTURE_2D
, 0, 0, 0, 0, depth
[1], GL_TEXTURE_2D
, 0, 0, 0, 0, piglit_width
, piglit_height
, 1);
74 /* Clear the first texture to 1. */
76 glClear(GL_DEPTH_BUFFER_BIT
);
78 /* Draw to the first texture. */
80 glBegin(GL_TRIANGLE_STRIP
);
81 glVertex3f(-0.6f
, -0.7f
, 0.5f
);
82 glVertex3f( 0.8f
, 0.5f
, 0.5f
);
83 glVertex3f( 0.7f
, -0.7f
, 0.5f
);
86 pixels
= malloc(piglit_width
* piglit_height
* sizeof(*pixels
));
87 glReadPixels(0, 0, piglit_width
, piglit_height
, GL_DEPTH_COMPONENT
, GL_FLOAT
, pixels
);
88 for (i
= 0; i
< piglit_width
* piglit_height
; ++i
) {
89 GLfloat probe
= pixels
[i
];
90 /* Every pixel should either be 0.75f (tri depth) or 1.0f (clear depth). */
91 if (fabsf(probe
- 0.75f
) >= 0.01 && fabsf(probe
- 1.0f
) >= 0.01) {
92 printf("Got depth %.8e at (%u, %u).\n", probe
, i
% piglit_width
, i
/ piglit_width
);
99 piglit_present_results();
101 glDeleteFramebuffers(1, &fb
);
102 glDeleteTextures(2, depth
);
104 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;