<div dir="ltr">On 10 September 2013 17:47, Chad Versace <span dir="ltr"><<a href="mailto:chad.versace@linux.intel.com" target="_blank">chad.versace@linux.intel.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div>On 09/10/2013 01:47 PM, Jacob Penner wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
---<br>
  tests/all.tests                                    |   1 +<br>
  .../gl-3.2/layered-rendering/<u></u>CMakeLists.gl.txt     |   1 +<br>
  tests/spec/gl-3.2/layered-<u></u>rendering/clear-depth.c  | 224 +++++++++++++++++++++<br>
  3 files changed, 226 insertions(+)<br>
  create mode 100644 tests/spec/gl-3.2/layered-<u></u>rendering/clear-depth.c<br>
<br>
diff --git a/tests/all.tests b/tests/all.tests<br>
index e1366ca..2444337 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-<u></u>integer-64iv'<br>
  spec['!OpenGL 3.2/get-integer-64v'] = concurrent_test('gl-3.2-get-<u></u>integer-64v')<br>
  spec['!OpenGL 3.2/layered-rendering/blit'] = concurrent_test('gl-3.2-<u></u>layered-rendering-blit')<br>
  spec['!OpenGL 3.2/layered-rendering/clear-<u></u>color'] = concurrent_test('gl-3.2-<u></u>layered-rendering-clear-color'<u></u>)<br>
+spec['!OpenGL 3.2/layered-rendering/clear-<u></u>depth'] = concurrent_test('gl-3.2-<u></u>layered-rendering-clear-depth'<u></u>)<br>
  spec['!OpenGL 3.2/layered-rendering/<u></u>framebuffertexture-buffer-<u></u>textures'] = concurrent_test('gl-3.2-<u></u>layered-rendering-<u></u>framebuffertexture-buffer-<u></u>textures')<br>
  spec['!OpenGL 3.2/layered-rendering/<u></u>readpixels'] = concurrent_test('gl-3.2-<u></u>layered-rendering-readpixels')<br>
  spec['!OpenGL 3.2/layered-rendering/gl-<u></u>layer'] = concurrent_test('gl-3.2-<u></u>layered-rendering-gl-layer')<br>
diff --git a/tests/spec/gl-3.2/layered-<u></u>rendering/CMakeLists.gl.txt b/tests/spec/gl-3.2/layered-<u></u>rendering/CMakeLists.gl.txt<br>
index 9a26b34..bc4415d 100644<br>
--- a/tests/spec/gl-3.2/layered-<u></u>rendering/CMakeLists.gl.txt<br>
+++ b/tests/spec/gl-3.2/layered-<u></u>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-<u></u>clear-color clear-color.c)<br>
+piglit_add_executable (gl-3.2-layered-rendering-<u></u>clear-depth clear-depth.c)<br>
  piglit_add_executable (gl-3.2-layered-rendering-<u></u>framebuffertexture-buffer-<u></u>textures framebuffertexture-buffer-<u></u>textures.c)<br>
  piglit_add_executable (gl-3.2-layered-rendering-<u></u>readpixels readpixels.c)<br>
  piglit_add_executable (gl-3.2-layered-rendering-gl-<u></u>layer gl-layer.c)<br>
diff --git a/tests/spec/gl-3.2/layered-<u></u>rendering/clear-depth.c b/tests/spec/gl-3.2/layered-<u></u>rendering/clear-depth.c<br>
new file mode 100644<br>
index 0000000..d680780<br>
--- /dev/null<br>
+++ b/tests/spec/gl-3.2/layered-<u></u>rendering/clear-depth.c<br>
@@ -0,0 +1,224 @@<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_<u></u>version = 32;<br>
+       config.supports_gl_core_<u></u>version = 32;<br>
+<br>
+PIGLIT_GL_TEST_CONFIG_END<br>
+<br>
+const char *vs_source = {<br>
+       "#version 150\n"<br>
+       "in vec4 piglit_vertex;\n"<br>
+       "void main()\n"<br>
+       "{\n"<br>
+       "       gl_Position = piglit_vertex;\n"<br>
+       "}\n"<br>
+};<br>
+<br>
+bool<br>
+probe_texture_layered_depth(<u></u>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_<u></u>FRAMEBUFFER_BINDING, &prev_draw_fbo);<br>
+       glGetIntegerv(GL_READ_<u></u>FRAMEBUFFER_BINDING, &prev_read_fbo);<br>
+<br>
+       glGenFramebuffers(1, &fbo);<br>
</blockquote>
<br></div></div>
Even though this is just a test, please cleanup by deleting the temporary fbo.<div><br>
<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+       glBindFramebuffer(GL_<u></u>FRAMEBUFFER, fbo);<br>
+<br>
+       for(k = 0; k < d; k++ ) {<br>
+<br>
+               glFramebufferTextureLayer(GL_<u></u>FRAMEBUFFER, GL_DEPTH_ATTACHMENT,<br>
+                                         texture, 0, k+z);<br>
+<br>
</blockquote>
<br></div>
There already exists a function for probing depth values, piglit_probe_rect_depth.<br>
Just use that instead of open-coding the below probing.<div><div><br>
<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+               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",<br>
+                                              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_<u></u>FRAMEBUFFER, prev_draw_fbo);<br>
+       glBindFramebuffer(GL_READ_<u></u>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>
+       GLint program;<br>
+<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>
+       program = piglit_build_simple_program(<u></u>vs_source, NULL);<br>
+       glUseProgram(program);<br>
+<br>
+       glGenTextures(2, texture);<br>
+       glGenFramebuffers(2, fbo);<br>
+       for(i = 0; i < 2; i++) {<br>
+               glBindTexture(GL_TEXTURE_2D_<u></u>ARRAY, texture[i]);<br>
+               glTexParameteri(GL_TEXTURE_2D_<u></u>ARRAY, GL_TEXTURE_MIN_FILTER,<br>
+                               GL_LINEAR);<br>
+               glTexParameteri(GL_TEXTURE_2D_<u></u>ARRAY, GL_TEXTURE_MAG_FILTER,<br>
+                               GL_LINEAR);<br>
+               glTexParameteri(GL_TEXTURE_2D_<u></u>ARRAY, GL_TEXTURE_WRAP_S,<br>
+                               GL_REPEAT);<br>
+               glTexParameteri(GL_TEXTURE_2D_<u></u>ARRAY, GL_TEXTURE_WRAP_T,<br>
+                               GL_REPEAT);<br>
+               glTexImage3D(GL_TEXTURE_2D_<u></u>ARRAY, 0, GL_DEPTH_COMPONENT32,<br>
+                            10, 10, 4, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);<br>
+<br>
+               glEnable(GL_DEPTH_TEST);<br>
+               glDepthFunc(GL_ALWAYS);<br>
+               glDepthRange(0, 1);<br>
+               glDrawBuffer(GL_NONE);<br>
</blockquote>
<br></div></div>
Ah... I was unaware of piglit_draw_rect_z. Since we're using that function,<br>
there is no need to call glDepthRange.<br>
<br>
I'm confused by the call to glDrawBuffer. What are you trying to accomplish with it?</blockquote><div><br></div><div>Looking at the specs yesterday, I *thought* the call is necessary in order to ensure framebuffer completeness, since there's no color attachment to the framebuffer.  In GL 3.2 (section 4.4.4 Framebuffer Completeness, under the "Whole Framebuffer Completeness" section), the following is listed as a criterion for framebuffer completeness:<br>

<br>The value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE must not be<br>NONE for any color attachment point(s) named by DRAW_BUFFERi.<br><br>{ FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER }<br><br><br></div><div>However, maybe I'm interpreting the spec wrong, because neither Mesa nor the NVIDIA proprietary driver requires the glDrawBuffer() call in order for the framebuffer to be complete.<br>
<br>Any insight on this, Jacob?</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><br>
<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+<br>
+               glBindFramebuffer(GL_<u></u>FRAMEBUFFER, fbo[i]);<br>
+<br>
+               for(j = 0; j < 4; j++) {<br>
+                       glFramebufferTextureLayer(GL_<u></u>FRAMEBUFFER,<br>
+                                                 GL_DEPTH_ATTACHMENT,<br>
+                                                 texture[i], 0, j);<br>
+<br>
+<br>
+                       fbstatus = glCheckFramebufferStatus(GL_<u></u>FRAMEBUFFER);<br>
+                       if(fbstatus != GL_FRAMEBUFFER_COMPLETE){<br>
+                               printf("%s\n", piglit_get_gl_enum_name(<u></u>fbstatus));<br>
+                               piglit_report_result(PIGLIT_<u></u>FAIL);<br>
+                       }<br>
+<br>
+                       piglit_check_gl_error(GL_NO_<u></u>ERROR);<br>
</blockquote>
<br></div>
If you want the test to fail, tt's not enough to call piglit_check_gl_error. That<br>
function doesn't terminate test. You need this:<br>
<br>
        if (!piglit_check_gl_error(GL_NO_<u></u>ERROR))<br>
                piglit_report_result(PIGLIT_<u></u>FAIL);<div><br>
<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+                       piglit_draw_rect_z(depths[j], -1, -1, 2, 2);<br>
+                       piglit_check_gl_error(GL_NO_<u></u>ERROR);<br>
+               }<br>
+<br>
+               glDisable(GL_DEPTH_TEST);<br>
</blockquote>
<br></div>
The code from here...<div><br>
<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+<br>
+               /* Once values are set, attach the texture to the fbo<br>
+                * as a layered texture<br>
+                */<br>
+               glFramebufferTexture(GL_<u></u>FRAMEBUFFER, GL_DEPTH_ATTACHMENT,<br>
+                                    texture[i], 0);<br>
+<br>
+<br>
+               fbstatus = glCheckFramebufferStatus(GL_<u></u>FRAMEBUFFER);<br>
+               if(fbstatus != GL_FRAMEBUFFER_COMPLETE){<br>
+                       printf("%s\n", piglit_get_gl_enum_name(<u></u>fbstatus));<br>
+                       piglit_report_result(PIGLIT_<u></u>FAIL);<br>
+               }<br>
+<br>
+               if(!piglit_check_gl_error(GL_<u></u>NO_ERROR))<br>
+                       piglit_report_result(PIGLIT_<u></u>FAIL);<br>
</blockquote>
<br></div>
... to here. I'm unsure what it is trying to do. I don't see the need to test<br>
for framebuffer completeness if nothing is rendered to the framebuffer<br>
with those attachments.</blockquote><div><br></div><div>IMHO the framebuffer completeness check is useful because if for some unexpected reason the framebuffer isn't complete, the clear calls below will likely fail.  It's easier to debug a test failure caused by unexpected framebuffer incompleteness if the test explicitly checks framebuffer completeness before doing its rendering.<br>
<br></div><div>I'm mildly in favor of keeping the framebuffer completeness check but I don't feel terribly strongly.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div><div><br>
<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+       }<br>
+<br>
+<br>
+       glBindFramebuffer(GL_<u></u>FRAMEBUFFER, fbo[0]);<br>
+       /* Clear fbo 0 with glClear() */<br>
+       glClearDepth(clearDepth);<br>
+       glClear(GL_DEPTH_BUFFER_BIT);<br>
+<br>
+       if(!probe_texture_layered_<u></u>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_<u></u>FRAMEBUFFER, fbo[1]);<br>
+       glClearBufferfv(GL_DEPTH, 0, &clearDepth);<br>
+<br>
+       if(!probe_texture_layered_<u></u>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_<u></u>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>
</blockquote>
<br></div></div>
The rest of the test looks good to me. Of course, we should get Paul's opinion too.</blockquote><div><br><br></div><div>I agree with Chad's comments about deleting the temporary fbo, using piglit_probe_rect_depth, removing the call to glDepthRange(), and checking the return value of piglit_check_gl_error().  With those changes, the patch is:<br>
<br></div><div>Reviewed-by: Paul Berry <<a href="mailto:stereotype441@gmail.com">stereotype441@gmail.com</a>><br><br></div><div>I could go either way on the framebuffer completeness check and the use of glDrawBuffer().<br>
</div></div></div></div>