<div dir="ltr">On 26 August 2013 11:48, 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">Currently the test only clears the first layer of the layered attachment, when<br>
glClear and glClearBuffer should clear all layers of the leyered framebuffer<br>
attachment.<br></blockquote><div><br></div><div>Unless otherwise specified, we always assume comments in piglit code refer to piglit behaviours, and comments in Mesa code refer to Mesa behaviours.  So it sounds like you're saying that there's a bug in piglit, when in fact what you're trying to say is that there's a bug in Mesa.<br>
<br>I'm not sure if it's worth mentioning that there's a Mesa bug at all in this commit, since what's important for Piglit is that the test is correct.  But if you do want to mention somethin, I'd recommend saying something like this:<br>
<br></div><div>Note: this test currently fails on Mesa/i965 due to a Mesa bug.  Mesa only clears the first layer of a layered attachement; it should clear all layers.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

---<br>
 tests/spec/gl-3.2/layered-rendering/clear-color.c | 215 ++++++++++++++++++++++<br>
 1 file changed, 215 insertions(+)<br>
 create mode 100644 tests/spec/gl-3.2/layered-rendering/clear-color.c<br>
<br>
diff --git a/tests/spec/gl-3.2/layered-rendering/clear-color.c b/tests/spec/gl-3.2/layered-rendering/clear-color.c<br>
new file mode 100644<br>
index 0000000..68c0be7<br>
--- /dev/null<br>
+++ b/tests/spec/gl-3.2/layered-rendering/clear-color.c<br>
@@ -0,0 +1,215 @@<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-color.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>
+ *      *--------*--------*    Each Layer for both tex1 and tex2 will be<br>
+ *      | layer3 | layer3 |   different colors.<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-3 of both tex1 and tex2 should be the clearColor<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>
+       config.window_width  = 128;<br>
+       config.window_height = 128;<br></blockquote><div><br></div><div>This test doesn't rely on a specific window size, so it shouldn't set window_width and window_height--it should just leave them at their default values.  That allows implementations with unusual width/height limitations (e.g. windows) to run the test properly, and it also makes the test easier to run under simulation (where fragment shading is very time consuming so we like to use small windows).<br>
</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+       config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;<br>
+<br>
+PIGLIT_GL_TEST_CONFIG_END<br>
+<br>
+static GLuint fbo[2];<br>
+static GLuint texture[2];<br>
+static const int layers = 3;<br>
+<br>
+bool<br>
+display_layered_texture(int x, int y, int w, int h, int texWidth, int texHeight,<br>
+                       GLenum textureType, GLuint texture, int layers) {<br>
+       GLuint tempFBO;<br>
+       int i;<br>
+       int dx1, dy1, dx2, dy2;<br>
+<br>
+       dx1 = x;<br>
+       dx2 = x+w;<br>
+<br>
+       /* Gen temp fbo */<br>
+       glGenFramebuffers(1, &tempFBO);<br>
+<br>
+       /* Loop through each layer, attaching the individual layer to the<br>
+        * temp fbo, then blit fbo to the correct location on screen<br>
+        */<br>
+       for(i = 0; i < layers; i++) {<br>
+               GLenum framebufferStatus;<br>
+<br>
+               dy1 = y + (i)  *(h/layers);<br>
+               dy2 = y + (i+1)*(h/layers);<br>
+<br>
+               glBindFramebuffer(GL_FRAMEBUFFER, tempFBO);<br>
+               glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,<br>
+                                         texture, 0, i);<br>
+<br>
+               framebufferStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER);<br>
+               if(framebufferStatus != GL_FRAMEBUFFER_COMPLETE) {<br>
+                       printf("Framebuffer Status: %s\n",<br>
+                              piglit_get_gl_enum_name(framebufferStatus));<br>
+                       return false;<br>
+               }<br>
+<br>
+               glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);<br>
+               glBindFramebuffer(GL_READ_FRAMEBUFFER, tempFBO);<br>
+               glBlitFramebuffer(0, 0, texWidth, texHeight,<br>
+                                 dx1, dy1, dx2, dy2, GL_COLOR_BUFFER_BIT,<br>
+                                 GL_NEAREST);<br>
+       }<br>
+<br>
+       /* Cleanup temp fbo */<br>
+       glBindFramebuffer(GL_FRAMEBUFFER, 0);<br>
+       glDeleteFramebuffers(1, &tempFBO);<br>
+<br>
+       return piglit_check_gl_error(GL_NO_ERROR);<br>
+}<br>
+<br>
+void<br>
+piglit_init(int argc, char **argv)<br>
+{<br>
+       int i, j;<br>
+       GLenum fbstatus;<br>
+       float colorLayers[layers][piglit_width*piglit_height*3];<br>
+       float colors[3][3] = {<br>
+               {0.0, 0.0, 1.0},<br>
+               {0.0, 1.0, 0.0},<br>
+               {1.0, 0.0, 0.0}<br>
+       };<br>
+<br>
+       /* Create color data for texture */<br>
+       for(j = 0; j < layers; j++) {<br>
+               for(i = 0; i < piglit_width*piglit_height; i++) {<br>
+                       colorLayers[j][i*3+0] = colors[j][0];<br>
+                       colorLayers[j][i*3+1] = colors[j][1];<br>
+                       colorLayers[j][i*3+2] = colors[j][2];<br>
+               }<br>
+       }<br>
+<br>
+       glGenTextures(2, texture);<br>
+       glGenFramebuffers(2, fbo);<br>
+       for(i = 0; i < 2; i++) {<br>
+               /* Create texture */<br>
+               glBindTexture(GL_TEXTURE_3D, texture[i]);<br>
+               glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);<br>
+               glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);<br>
+               glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_REPEAT);<br>
+               glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_REPEAT);<br>
+               glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_REPEAT);<br>
+               glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB, piglit_width, piglit_height,<br>
+                            layers, 0, GL_RGB, GL_FLOAT, colorLayers);<br>
+<br>
+               /* Gen Framebuffer */<br>
+               glBindFramebuffer(GL_FRAMEBUFFER, fbo[i]);<br>
+               glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,<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>
+<br>
+       if(!piglit_check_gl_error(GL_NO_ERROR))<br>
+               piglit_report_result(PIGLIT_FAIL);<br>
+}<br>
+<br>
+<br>
+enum piglit_result<br>
+piglit_display(void)<br>
+{<br>
+       bool pass = true;<br>
+       const float clearColor[3] = { 1, 1, 0 };<br>
+<br>
+       /* Clear Defualt Framebuffer */<br>
+       glBindFramebuffer(GL_FRAMEBUFFER, 0);<br>
+       glClearColor(0,0,0,1);<br>
+       glClear(GL_COLOR_BUFFER_BIT);<br>
+<br>
+       /* Clear texture[0] with glClear() */<br>
+       glBindFramebuffer(GL_FRAMEBUFFER, fbo[0]);<br>
+       glClearColor(clearColor[0], clearColor[1], clearColor[2], 1);<br>
+       glClear(GL_COLOR_BUFFER_BIT);<br>
+<br>
+       /* Clear texture[1] with glClearBuffer() */<br>
+       glBindFramebuffer(GL_FRAMEBUFFER, fbo[1]);<br>
+       glClearBufferfv(GL_COLOR, 0, clearColor);<br>
+<br>
+       /* Display glClear texture */<br>
+       if(!display_layered_texture(0, 0, piglit_width/2, piglit_height,<br>
+                                   piglit_width, piglit_height, GL_TEXTURE_3D,<br>
+                                   texture[0], layers)) {<br>
+               printf("Failed to display layered texture for glClear\n");<br>
+               pass = false;<br>
+       }<br>
+<br>
+       /* Display glClearBuffer texture */<br>
+       if(!display_layered_texture(piglit_width/2, 0, piglit_width/2,<br>
+                                   piglit_height, piglit_width, piglit_height,<br>
+                                   GL_TEXTURE_3D, texture[1], layers)) {<br>
+               printf("Failed to display layered texture for glClearBuffer\n");<br>
+               pass = false;<br>
+       }<br>
+<br>
+       /* Check for passing conditions for glClear*/<br>
+       if(!piglit_probe_rect_rgb(0, 0, piglit_width/2, piglit_height,<br>
+                                 clearColor)) {<br>
+               printf("Incorrect probe value for glClear test.\n");<br>
+               pass = false;<br>
+       }<br>
+<br>
+       /* Check for passing conditions for glClearBuffer*/<br>
+       if(!piglit_probe_rect_rgb(piglit_width/2, 0, piglit_width/2,<br>
+                                 piglit_height, clearColor)) {<br>
+               printf("Incorrect probe value for glClearBuffer test.\n");<br>
+               pass = false;<br>
+       }<br></blockquote><div><br></div><div>display_layered_texture isn't guaranteed to draw to the whole screen, since it breaks the region into 3 equal size parts (rounding down).  So for example, fi the window height is 128, display_layered_texture will draw to three rectangles having height 42, for a total height of 126, and that will leave the top two rows of pixels unpainted.  That means the piglit_probe_rect_rgb calls will always fail, even if the implementation is correct.<br>
<br></div><div>Any easy fix would be to change the glClearColor call at the top of this function to glClearColor(1, 1, 0, 1).  That way any pixels that don't get painted by display_layered_texture will have the correct clear color anyhow.<br>
</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+<br>
+       if(!piglit_check_gl_error(GL_NO_ERROR))<br>
+               pass = false;<br>
+<br>
+       piglit_present_results();<br>
+       return pass ? PIGLIT_PASS : PIGLIT_FAIL;<br>
+}<br></blockquote><div><br></div><div>With those fixes, this patch is:<br><br>Reviewed-by: Paul Berry <<a href="mailto:stereotype441@gmail.com">stereotype441@gmail.com</a>><br></div></div></div></div>