<div dir="ltr">(Note: Cc'ing Chad, since this test erroneously passes on i965 due to a subtle HiZ bug.  See my comments below)<br><div><br>On 3 September 2013 15:52, Jacob Penner <span dir="ltr"><<a href="mailto:jkpenner91@gmail.com" target="_blank">jkpenner91@gmail.com</a>></span> wrote:<br>
<div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">---<br>
 tests/all.tests                                    |   1 +<br>
 .../gl-3.2/layered-rendering/CMakeLists.gl.txt     |   1 +<br>
 tests/spec/gl-3.2/layered-rendering/clear-depth.c  | 185 +++++++++++++++++++++<br>
 3 files changed, 187 insertions(+)<br>
 create mode 100644 tests/spec/gl-3.2/layered-rendering/clear-depth.c<br>
<br>
diff --git a/tests/all.tests b/tests/all.tests<br>
index 59fb0e2..c6d0c71 100644<br>
--- a/tests/all.tests<br>
+++ b/tests/all.tests<br>
@@ -750,6 +750,7 @@ spec['!OpenGL 3.2/get-integer-64iv'] = concurrent_test('gl-3.2-get-integer-64iv'<br>
 spec['!OpenGL 3.2/get-integer-64v'] = concurrent_test('gl-3.2-get-integer-64v')<br>
 spec['!OpenGL 3.2/layered-rendering/blit'] = concurrent_test('gl-3.2-layered-rendering-blit')<br>
 spec['!OpenGL 3.2/layered-rendering/clear-color'] = concurrent_test('gl-3.2-layered-rendering-clear-color')<br>
+spec['!OpenGL 3.2/layered-rendering/clear-depth'] = concurrent_test('gl-3.2-layered-rendering-clear-depth')<br>
 spec['!OpenGL 3.2/layered-rendering/framebuffertexture-buffer-textures'] = concurrent_test('gl-3.2-layered-rendering-framebuffertexture-buffer-textures')<br>
 spec['!OpenGL 3.2/layered-rendering/readpixels'] = concurrent_test('gl-3.2-layered-rendering-readpixels')<br>
 spec['!OpenGL 3.2/layered-rendering/gl-layer'] = concurrent_test('gl-3.2-layered-rendering-gl-layer')<br>
diff --git a/tests/spec/gl-3.2/layered-rendering/CMakeLists.gl.txt b/tests/spec/gl-3.2/layered-rendering/CMakeLists.gl.txt<br>
index 9a26b34..bc4415d 100644<br>
--- a/tests/spec/gl-3.2/layered-rendering/CMakeLists.gl.txt<br>
+++ b/tests/spec/gl-3.2/layered-rendering/CMakeLists.gl.txt<br>
@@ -11,6 +11,7 @@ link_libraries (<br>
<br>
 piglit_add_executable (gl-3.2-layered-rendering-blit blit.c)<br>
 piglit_add_executable (gl-3.2-layered-rendering-clear-color clear-color.c)<br>
+piglit_add_executable (gl-3.2-layered-rendering-clear-depth clear-depth.c)<br>
 piglit_add_executable (gl-3.2-layered-rendering-framebuffertexture-buffer-textures framebuffertexture-buffer-textures.c)<br>
 piglit_add_executable (gl-3.2-layered-rendering-readpixels readpixels.c)<br>
 piglit_add_executable (gl-3.2-layered-rendering-gl-layer gl-layer.c)<br>
diff --git a/tests/spec/gl-3.2/layered-rendering/clear-depth.c b/tests/spec/gl-3.2/layered-rendering/clear-depth.c<br>
new file mode 100644<br>
index 0000000..9c0cd53<br>
--- /dev/null<br>
+++ b/tests/spec/gl-3.2/layered-rendering/clear-depth.c<br>
@@ -0,0 +1,185 @@<br>
+/*<br>
+ * Copyright © 2013 Intel Corporation<br>
+ *<br>
+ * Permission is hereby granted, free of charge, to any person obtaining a<br>
+ * copy of this software and associated documentation files (the "Software"),<br>
+ * to deal in the Software without restriction, including without limitation<br>
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,<br>
+ * and/or sell copies of the Software, and to permit persons to whom the<br>
+ * Software is furnished to do so, subject to the following conditions:<br>
+ *<br>
+ * The above copyright notice and this permission notice (including the next<br>
+ * paragraph) shall be included in all copies or substantial portions of the<br>
+ * Software.<br>
+ *<br>
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br>
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL<br>
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br>
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING<br>
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS<br>
+ * IN THE SOFTWARE.<br>
+ */<br>
+<br>
+<br>
+/** @file clear-depth.c<br>
+ *<br>
+ * Section 4.4.7(Framebuffer Objects) From GL spec 3.2 core:<br>
+ * When the Clear or ClearBuffer* commands are used to clear a layered<br>
+ * framebuffer attachment, all layers of the attachment are cleared.<br>
+ *<br>
+ * Test Layout<br>
+ *         Tex1     Tex2<br>
+ *     *--------*--------*<br>
+ *      | layer4 | layer4 |<br>
+ *      *--------*--------*    Each Layer for both tex1 and tex2 will be<br>
+ *      | layer3 | layer3 |   different depths.<br>
+ *      *--------*--------*<br>
+ *      | layer2 | layer2 |    Tex1 will be cleared using glClear()<br>
+ *      *--------*--------*<br>
+ *      | layer1 | layer1 |    Tex2 will be cleared using glClearBuffer()<br>
+ *      *--------*--------*<br>
+ *<br>
+ *      Result:<br>
+ *        Layer 1-4 of both tex1 and tex2 should be the clearDepth<br>
+ */<br>
+<br>
+#include "piglit-util-gl-common.h"<br>
+<br>
+PIGLIT_GL_TEST_CONFIG_BEGIN<br>
+<br>
+       config.supports_gl_compat_version = 32;<br>
+       config.supports_gl_core_version = 32;<br>
+<br>
+PIGLIT_GL_TEST_CONFIG_END<br>
+<br>
+bool<br>
+probe_texture_layered_depth(GLuint texture, int x, int y, int z,<br>
+                           int w, int h, int d, float *expected)<br>
+{<br>
+       GLint prev_read_fbo;<br>
+       GLint prev_draw_fbo;<br>
+<br>
+       GLuint fbo;<br>
+       int i, j, k;<br>
+<br>
+       GLfloat *probe;<br>
+       GLfloat *pixels = malloc(w*h*sizeof(float));<br>
+<br>
+       glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &prev_draw_fbo);<br>
+       glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &prev_read_fbo);<br>
+<br>
+       glGenFramebuffers(1, &fbo);<br>
+       glBindFramebuffer(GL_FRAMEBUFFER, fbo);<br>
+<br>
+       for(k = z; k < z+d; k++ ) {<br></blockquote><div><br></div><div>I prefer how you did this in patch 2, where k runs from 0 to d, and then you use "k+d" in the call to glFramebufferTextureLayer call below.  That way if the caller passes a nonzero value for z, then expected[0] is the expected depth value of the first layer to be probed.<br>
</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+<br>
+               glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,<br>
+                                         texture, 0, k);<br>
+<br>
+               glReadPixels(x, y, w, h, GL_DEPTH_COMPONENT, GL_FLOAT, pixels);<br>
+<br>
+               for(j = 0; j < h; j++) {<br>
+                       for(i = 0; i < w; i++) {<br>
+                               probe = &pixels[j*w+i];<br>
+                               if (fabs(*probe - expected[k]) >= 0.01) {<br>
+                                       printf("Probe depth at (%i,%i,%i)\n", x+i, y+j,z+k);<br>
+                                       printf("  Expected: %f\n", expected[k]);<br>
+                                       printf("  Observed: %f\n", *probe);<br>
+<br>
+                                       free(pixels);<br>
+                                       return false;<br>
+                               }<br>
+                       }<br>
+               }<br>
+       }<br>
+       free(pixels);<br>
+<br>
+       glBindFramebuffer(GL_DRAW_FRAMEBUFFER, prev_draw_fbo);<br>
+       glBindFramebuffer(GL_READ_FRAMEBUFFER, prev_read_fbo);<br>
+       return true;<br>
+}<br>
+<br>
+void<br>
+piglit_init(int argc, char **argv)<br>
+{<br>
+<br>
+       int i, j;<br>
+       GLenum fbstatus;<br>
+       bool pass = true;<br>
+       GLuint fbo[2], texture[2];<br>
+<br>
+       float depthData[4][10*10];<br>
+       float depths[4] = {<br>
+               0.25, 0.5, 0.75, 1.0<br>
+       };<br>
+<br>
+       GLfloat clearDepth = 0.0;<br>
+       float expected[4] = { 0.0, 0.0, 0.0, 0.0 };<br>
+<br>
+       /* Create depth data for textures */<br>
+       for(j = 0; j < 4; j++) {<br>
+               for(i = 0; i < 10*10; i++) {<br>
+                       depthData[j][i] = depths[j];<br>
+               }<br>
+       }<br>
+<br>
+       glGenTextures(2, texture);<br>
+       glGenFramebuffers(2, fbo);<br>
+       for(i = 0; i < 2; i++) {<br>
+               glBindTexture(GL_TEXTURE_2D_ARRAY, texture[i]);<br>
+               glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR);<br>
+               glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);<br>
+               glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_REPEAT);<br>
+               glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_REPEAT);<br>
+               glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_DEPTH_COMPONENT16,<br>
+                            10, 10, 4, 0, GL_DEPTH_COMPONENT, GL_FLOAT, depthData);<br>
+<br>
+               glBindFramebuffer(GL_FRAMEBUFFER, fbo[i]);<br>
+               glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,<br>
+                                    texture[i], 0);<br>
+<br>
+               fbstatus = glCheckFramebufferStatus(GL_FRAMEBUFFER);<br>
+               if(fbstatus != GL_FRAMEBUFFER_COMPLETE){<br>
+                       printf("%s\n", piglit_get_gl_enum_name(fbstatus));<br>
+                       piglit_report_result(PIGLIT_FAIL);<br>
+               }<br>
+<br>
+               if(!piglit_check_gl_error(GL_NO_ERROR))<br>
+                       piglit_report_result(PIGLIT_FAIL);<br>
+       }<br>
+<br>
+       /* Clear fbo 0 with glClear() */<br>
+       glClearDepth(clearDepth);<br>
+<br>
+       glBindFramebuffer(GL_FRAMEBUFFER, fbo[0]);<br>
+       glClear(GL_DEPTH_BUFFER_BIT);<br>
+<br>
+       if(!probe_texture_layered_depth(texture[0], 0, 0, 0, 10,<br>
+                                       10, 4, expected)) {<br>
+               printf("Incorrect depth values recieved with glClear()\n");<br>
+               pass = false;<br>
+       }<br>
+<br>
+       /* Clear fbo 1 with glClearBuffer() */<br>
+       glBindFramebuffer(GL_FRAMEBUFFER, fbo[1]);<br>
+       glClearBufferfv(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, &clearDepth);<br></blockquote><div><br></div><div>This needs to be:<br><br>glClearBufferfv(GL_DEPTH, 0, &clearDepth);<br><br><br><br><br></div><div>With this fixed, the test passes, which surprised me, because I expected it to fail (I've looked at the code in Mesa, and we haven't implemented proper handling for layered depth clears yet).<br>
<br></div><div>I did a little digging and here's what is happening:<br><br></div><div>When the buffer is first created, its contents are undefined.  But in a typical test run it happens to get allocated using zero-initialized pages, and zero in the HiZ buffer means "clear", so the state looks like this:<br>
<br></div><div>depth buffer: all layers 0.  hiz buffer: all layers clear.  resolve map: all layers need HiZ resolve<br><br></div><div>So far so good.  When the initial buffer contents get uploaded using glTexImage3D, the state becomes:<br>
<br></div><div>depth buffer: layers initialized to {.25, .5, .75, 1}.  hiz buffer: all layers clear.  resolve map: all layers need HiZ resolve<br><br></div><div>This is also correct (the HiZ buffer being in the clear state is not a problem because all layers are marked as needing a HiZ resolve).<br>
<br>The next thing that happens is glClear().  What glClear() *should* do is put all layers of the hiz buffer in the "clear" state, and all layers of the resolve map in the "need depth resolve" state.  It does the correct thing to the resolve map, but due to a bug it only clears layer 0 of the HiZ buffer.<br>
<br></div><div>The problem is, all layers of the HiZ buffer are already in the clear state, so we wind up in the correct state by accident:<br><br></div><div>depth buffer: layers initialized to {.25, .5, .75, 1}.  hiz buffer: all layers clear.  resolve map: all layers need depth resolve<br>
<br></div><div>And so the test passes by dumb luck.<br></div><div><br></div><div>I think what we need to do is modify the test so that rather than populating the buffer using glTexImage3D, it populates it by doing drawing operations to all layers.  That way the HiZ buffer will be in a more realistic state by the time we try to do the clear, so the test will notice if the clear fails to have the proper effect on all layers.<br>
<br></div><div>But I wouldn't mind a second opinion on that.  Chad (or anyone else familiar with HiZ on Intel), care to comment?<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

+<br>
+       if(!probe_texture_layered_depth(texture[1], 0, 0, 0, 10,<br>
+                                       10, 4, expected)) {<br>
+               printf("Incorrect depth values recieved with glClearBuffer()\n");<br>
+               pass = false;<br>
+       }<br>
+<br>
+       pass = piglit_check_gl_error(GL_NO_ERROR) && pass;<br>
+<br>
+       piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);<br>
+}<br>
+<br>
+<br>
+enum piglit_result<br>
+piglit_display(void)<br>
+{<br>
+       /* UNREACHABLE */<br>
+       return PIGLIT_FAIL;<br>
+}<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.8.3.1<br>
<br>
_______________________________________________<br>
Piglit mailing list<br>
<a href="mailto:Piglit@lists.freedesktop.org">Piglit@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/piglit" target="_blank">http://lists.freedesktop.org/mailman/listinfo/piglit</a><br>
</font></span></blockquote></div><br></div></div></div>