<div dir="ltr">On 5 August 2013 15:32, Anuj Phogat <span dir="ltr"><<a href="mailto:anuj.phogat@gmail.com" target="_blank">anuj.phogat@gmail.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">This test verifies the accuracy of scaled blitting from a single sample<br>
buffer with GL_LINEAR filtering. It compares the output from following<br>
rendering scenarios:<br>
1. Scaled blit using a single sample framebuffer with texture /<br>
renderbuffer attachment.<br>
2. Scaled blit using a glsl shader program.<br>
Signed-off-by: Anuj Phogat <<a href="mailto:anuj.phogat@gmail.com">anuj.phogat@gmail.com</a>><br>
---<br>
tests/all.tests | 1 +<br>
.../ext_framebuffer_multisample/CMakeLists.gl.txt | 1 +<br>
.../blit-scaled-linear.cpp | 297 +++++++++++++++++++++<br>
3 files changed, 299 insertions(+)<br>
create mode 100644 tests/spec/ext_framebuffer_multisample/blit-scaled-linear.cpp<br></blockquote><div><br></div><div>I see that you've placed this test in ext_framebuffer_multisample because it re-uses the test pattern defined in ext_framebuffer_multisample/common.cpp. I'm not comfortable with that--if we start mixing and matching our directory organization like this, it's going to start getting hard to find the files we're looking for. How about if we do a pre-patch that moves the test pattern to a global location (i.e. somewhere in tests/util)? Then this test can go in arb_framebuffer_multisample where it belongs.<br>
</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
diff --git a/tests/all.tests b/tests/all.tests<br>
index 39ee624..07961b5 100644<br>
--- a/tests/all.tests<br>
+++ b/tests/all.tests<br>
@@ -1100,6 +1100,7 @@ for format in ('rgba', 'depth', 'stencil'):<br>
arb_framebuffer_object[test_name] = PlainExecTest(test_name + ' -auto')<br>
add_plain_test(arb_framebuffer_object, 'fbo-alpha')<br>
add_plain_test(arb_framebuffer_object, 'fbo-blit-stretch')<br>
+add_plain_test(arb_framebuffer_object, 'fbo-blit-scaled-linear')<br>
add_plain_test(arb_framebuffer_object, 'fbo-deriv')<br>
add_plain_test(arb_framebuffer_object, 'fbo-luminance-alpha')<br>
add_plain_test(arb_framebuffer_object, 'fbo-getframebufferattachmentparameter-01')<br>
diff --git a/tests/spec/ext_framebuffer_multisample/CMakeLists.gl.txt b/tests/spec/ext_framebuffer_multisample/CMakeLists.gl.txt<br>
index 7f7958f..db26758 100644<br>
--- a/tests/spec/ext_framebuffer_multisample/CMakeLists.gl.txt<br>
+++ b/tests/spec/ext_framebuffer_multisample/CMakeLists.gl.txt<br>
@@ -24,6 +24,7 @@ piglit_add_executable (ext_framebuffer_multisample-alpha-to-one-single-sample-bu<br>
piglit_add_executable (ext_framebuffer_multisample-bitmap common.cpp bitmap.cpp)<br>
piglit_add_executable (ext_framebuffer_multisample-blit-flipped common.cpp blit-flipped.cpp)<br>
piglit_add_executable (ext_framebuffer_multisample-blit-scaled common.cpp blit-scaled.cpp)<br>
+piglit_add_executable (fbo-blit-scaled-linear common.cpp blit-scaled-linear.cpp)<br>
piglit_add_executable (ext_framebuffer_multisample-blit-mismatched-samples common.cpp blit-mismatched-samples.cpp)<br>
piglit_add_executable (ext_framebuffer_multisample-blit-mismatched-sizes common.cpp blit-mismatched-sizes.cpp)<br>
piglit_add_executable (ext_framebuffer_multisample-blit-mismatched-formats common.cpp blit-mismatched-formats.cpp)<br>
diff --git a/tests/spec/ext_framebuffer_multisample/blit-scaled-linear.cpp b/tests/spec/ext_framebuffer_multisample/blit-scaled-linear.cpp<br>
new file mode 100644<br>
index 0000000..f92900f<br>
--- /dev/null<br>
+++ b/tests/spec/ext_framebuffer_multisample/blit-scaled-linear.cpp<br>
@@ -0,0 +1,297 @@<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>
+/** \file blit-scaled-linear.cpp<br>
+ *<br>
+ * This test verifies the accuracy of scaled blitting from a single sample<br>
+ * buffer with GL_LINEAR filter.It compares the output from following<br>
+ * rendering scenarios:<br>
+ * 1. Scaled blit using a framebuffer with texture/renderbuffer attachment.<br>
+ * 2. Scaled blit using glsl shader program.<br>
+ */<br>
+<br>
+#include "common.h"<br>
+const int pattern_width = 258; const int pattern_height = 258;<br>
+<br>
+PIGLIT_GL_TEST_CONFIG_BEGIN<br>
+<br>
+ config.supports_gl_compat_version = 10;<br>
+<br>
+ config.window_width = pattern_width * 2;<br>
+ config.window_height = pattern_height;<br>
+ config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA;<br>
+<br>
+PIGLIT_GL_TEST_CONFIG_END<br>
+<br>
+static TestPattern *test_pattern;<br>
+static unsigned prog, vao, vertex_buf;<br>
+const int srcX0 = 0, srcY0 = 0, dstX0 = 0, dstY0 = 0;<br>
+const int srcX1 = pattern_width / 2, srcY1 = pattern_height / 2;<br>
+static Fbo fbo_tex, fbo_rb, fbo;<br>
+<br>
+void<br>
+compile_shader(void)<br>
+{<br>
+ static const char *vert =<br>
+ "#version 130\n"<br>
+ "uniform mat4 proj;\n"<br>
+ "in vec2 pos;\n"<br>
+ "in vec2 texCoord;\n"<br>
+ "out vec2 textureCoord;\n"<br>
+ "void main()\n"<br>
+ "{\n"<br>
+ " gl_Position = proj * vec4(pos, 0.0, 1.0);\n"<br>
+ " textureCoord = texCoord;\n"<br>
+ "}\n";<br>
+ /* Bilinear filtering of samples using shader program */<br>
+ static const char *frag =<br>
+ "#version 130\n"<br>
+ "#extension GL_ARB_texture_rectangle : enable\n"<br>
+ "in vec2 textureCoord;\n"<br>
+ "uniform sampler2DRect tex2d;\n"<br>
+ "uniform float xmax;\n"<br>
+ "uniform float ymax;\n"<br>
+ "out vec4 out_color;\n"<br>
+ "void main()\n"<br>
+ "{\n"<br>
+ " vec2 f;\n"<br>
+ " vec4 c0, c1, c2, c3;\n"<br>
+ " vec2 tex_coord = textureCoord - vec2(0.5, 0.5);\n"<br>
+ "\n"<br>
+ " tex_coord.xy = clamp(tex_coord.xy,\n"<br>
+ " vec2(0.0, 0.0),\n"<br>
+ " vec2 (xmax - 1.0, ymax - 1.0));\n"<br>
+ "\n"<br>
+ " f.x = fract(tex_coord.x);\n"<br>
+ " f.y = fract(tex_coord.y);\n"<br>
+ "\n"<br>
+ " tex_coord.x = tex_coord.x - f.x;\n"<br>
+ " tex_coord.y = tex_coord.y - f.y;\n"<br>
+ "\n"<br>
+ " c0 = texture2DRect(tex2d, tex_coord.xy + vec2(0, 0));\n"<br>
+ " c1 = texture2DRect(tex2d, tex_coord.xy + vec2(1, 0));\n"<br>
+ " c2 = texture2DRect(tex2d, tex_coord.xy + vec2(0, 1));\n"<br>
+ " c3 = texture2DRect(tex2d, tex_coord.xy + vec2(1, 1));\n"<br>
+ "\n"<br>
+ " vec4 color_x1 = mix(c0, c1, f.x);\n"<br>
+ " vec4 color_x2 = mix(c2, c3, f.x);\n"<br>
+ "\n"<br>
+ " out_color = mix(color_x1, color_x2, f.y);\n"<br>
+ "}\n";<br>
+ /* Compile program */<br>
+ prog = glCreateProgram();<br>
+ GLint vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vert);<br>
+ glAttachShader(prog, vs);<br>
+ piglit_check_gl_error(GL_NO_ERROR);<br>
+ GLint fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, frag);<br>
+ glAttachShader(prog, fs);<br>
+ glBindAttribLocation(prog, 0, "pos");<br>
+ glBindAttribLocation(prog, 1, "texCoord");<br>
+ glLinkProgram(prog);<br>
+ if (!piglit_link_check_status(prog)) {<br>
+ piglit_report_result(PIGLIT_FAIL);<br>
+ }<br>
+<br>
+ /* Set up vertex array object */<br>
+ glGenVertexArrays(1, &vao);<br>
+ glBindVertexArray(vao);<br>
+<br>
+ /* Set up vertex input buffer */<br>
+ glGenBuffers(1, &vertex_buf);<br>
+ glBindBuffer(GL_ARRAY_BUFFER, vertex_buf);<br>
+ glEnableVertexAttribArray(0);<br>
+ glVertexAttribPointer(0, 2, GL_INT, GL_FALSE, 4*sizeof(float),<br>
+ (void *) 0);<br>
+ glEnableVertexAttribArray(1);<br>
+ glVertexAttribPointer(1, 2, GL_INT, GL_FALSE, 4*sizeof(float),<br>
+ (void *) (2*sizeof(float)));<br>
+<br>
+ /* Set up element input buffer to tesselate a quad into<br>
+ * triangles<br>
+ */<br>
+ unsigned int indices[6] = { 0, 1, 2, 0, 2, 3 };<br>
+ GLuint element_buf;<br>
+ glGenBuffers(1, &element_buf);<br>
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, element_buf);<br>
+ glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices,<br>
+ GL_STATIC_DRAW);<br>
+}<br>
+<br>
+void<br>
+blit_scaled_linear_glsl(const Fbo *src_fbo, GLint samples)<br>
+{<br>
+ const float proj[4][4] = {<br>
+ { 1, 0, 0, 0 },<br>
+ { 0, 1, 0, 0 },<br>
+ { 0, 0, 1, 0 },<br>
+ { 0, 0, 0, 1 }};<br>
+<br>
+ int vertex_data[4][4] = {<br>
+ { -1, -1, srcX0, srcY0 },<br>
+ { -1, 1, srcX0, srcY1 },<br>
+ { 1, 1, srcX1, srcY1 },<br>
+ { 1, -1, srcX1, srcY0 }};<br>
+<br>
+ glActiveTexture(GL_TEXTURE0);<br>
+ glBindTexture(GL_TEXTURE_RECTANGLE, src_fbo->color_tex);<br>
+ glUseProgram(prog);<br>
+ glBindVertexArray(vao);<br>
+<br>
+ /* Set up uniforms */<br>
+ glUseProgram(prog);<br>
+ glUniform1i(glGetUniformLocation(prog, "tex2d"), 0);<br>
+ glUniform1f(glGetUniformLocation(prog, "xmin"), 0);<br>
+ glUniform1f(glGetUniformLocation(prog, "ymin"), 0);<br>
+ glUniform1f(glGetUniformLocation(prog, "xmax"),<br>
+ fbo_rb.config.width);<br>
+ glUniform1f(glGetUniformLocation(prog, "ymax"),<br>
+ fbo_rb.config.height);<br>
+ glUniformMatrix4fv(glGetUniformLocation(prog, "proj"), 1,<br>
+ GL_TRUE, &proj[0][0]);<br>
+<br>
+ glBindBuffer(GL_ARRAY_BUFFER, vertex_buf);<br>
+ glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_data), vertex_data,<br>
+ GL_STREAM_DRAW);<br>
+ glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, (void *) 0);<br>
+}<br>
+<br>
+void<br>
+piglit_init(int argc, char **argv)<br>
+{<br>
+ piglit_require_gl_version(21);<br>
+ piglit_require_extension("GL_ARB_vertex_array_object");<br>
+<br>
+ fbo.setup(FboConfig(0, 2 * pattern_width, pattern_height));<br>
+ /* Create two singlesample FBOs with same format and dimensions but<br>
+ * different color attachment types.<br>
+ */<br>
+ FboConfig Config(0, pattern_width / 2, pattern_height / 2);<br>
+ Config.attach_texture = true;<br>
+ fbo_tex.setup(Config);<br>
+ Config.attach_texture = false;<br>
+ fbo_rb.setup(Config);<br>
+<br>
+ test_pattern = new Triangles();<br>
+ test_pattern->compile();<br>
+<br>
+ compile_shader();<br>
+ if (!piglit_check_gl_error(GL_NO_ERROR)) {<br>
+ piglit_report_result(PIGLIT_FAIL);<br>
+ }<br>
+}<br>
+<br>
+bool test_blit_scaled_linear(Fbo fbo_test)<br>
+{<br>
+ GLfloat scale;<br>
+ GLint samples;<br>
+ bool pass = true, result = true;<br>
+<br>
+ /* Draw the test pattern into the framebuffer with texture<br>
+ * attachment.<br>
+ */<br>
+ glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo_tex.handle);<br>
+ glViewport(0, 0, srcX1, srcY1);<br>
+ glGetIntegerv(GL_SAMPLES, &samples);<br>
+ glClear(GL_COLOR_BUFFER_BIT);<br>
+ test_pattern->draw(TestPattern::no_projection);<br>
+<br>
+ if(!fbo_test.config.attach_texture) {<br>
+ /* Blit the framebuffer with texture attachment into the<br>
+ * framebuffer with renderbuffer attachment.<br>
+ */<br>
+ glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo_tex.handle);<br>
+ glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo_rb.handle);<br>
+ glClear(GL_COLOR_BUFFER_BIT);<br>
+ glBlitFramebuffer(0, 0,<br>
+ fbo_tex.config.width,<br>
+ fbo_tex.config.height,<br>
+ 0, 0,<br>
+ fbo_rb.config.width,<br>
+ fbo_rb.config.height,<br>
+ GL_COLOR_BUFFER_BIT, GL_NEAREST);<br>
+ }<br>
+<br>
+ for(scale = 0.1; scale < 2.5f; scale += 0.1) {<br>
+ glBindFramebuffer(GL_DRAW_FRAMEBUFFER, piglit_winsys_fbo);<br>
+ glClear(GL_COLOR_BUFFER_BIT);<br>
+<br>
+ /* Do scaled resolve of fbo_rb to left half of<br>
+ * fbo.<br>
+ */<br>
+ glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo_test.handle);<br>
+ glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo.handle);<br>
+ glClearColor(0.0, 1.0, 0.0, 1.0);<br>
+ glClear(GL_COLOR_BUFFER_BIT);<br>
+ glClearColor(0.0, 0.0, 0.0, 0.0);<br>
+ glEnable(GL_SCISSOR_TEST);<br>
+ glScissor(0, 0, pattern_width, pattern_height);<br>
+ glBlitFramebuffer(srcX0, srcY0,<br>
+ srcX1, srcY1,<br>
+ dstX0, dstY0,<br>
+ dstX0 + srcX1 * scale, dstY0 + srcY1 * scale,<br>
+ GL_COLOR_BUFFER_BIT,<br>
+ GL_LINEAR);<br>
+ glDisable(GL_SCISSOR_TEST);<br>
+<br>
+ /* Use fbo with texture attachment to draw in to right half of<br>
+ * scaled single-sampled buffer using shader program.<br>
+ */<br>
+ glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo_tex.handle);<br>
+ glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo.handle);<br>
+ glViewport(pattern_width + dstX0, dstY0, srcX1 * scale, srcY1 * scale);<br>
+ blit_scaled_linear_glsl(&fbo_tex, samples);<br>
+<br>
+ pass = piglit_check_gl_error(GL_NO_ERROR) && pass;<br>
+ glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo.handle);<br>
+ result = piglit_probe_rect_halves_equal_rgba(0, 0,<br>
+ piglit_width,<br>
+ piglit_height);<br>
+ pass = result && pass;<br>
+<br>
+ glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo.handle);<br>
+ glBindFramebuffer(GL_DRAW_FRAMEBUFFER, piglit_winsys_fbo);<br>
+ glBlitFramebuffer(0, 0, 2 * pattern_width, piglit_height,<br>
+ 0, 0, 2 * pattern_width, piglit_height,<br>
+ GL_COLOR_BUFFER_BIT, GL_NEAREST);<br>
+ piglit_present_results();<br>
+ printf("Attachment = %12s, scale = %f, result = %s\n",<br>
+ fbo_test.config.attach_texture ?<br>
+ "TEXTURE" :<br>
+ "RENDERBUFFER",<br>
+ scale, result ? "pass" : "fail");<br>
+ }<br>
+ return pass;<br>
+}<br>
+<br>
+enum piglit_result<br>
+piglit_display()<br>
+{<br>
+ bool pass = true;<br>
+ printf("Left Image: Linear scaled blit using glBlitFramebuffer.\n"<br>
+ "Right Image: Linear scaled blit using glsl.\n");<br>
+ pass = test_blit_scaled_linear(fbo_tex)<br>
+ && pass;<br>
+ pass = test_blit_scaled_linear(fbo_rb)<br>
+ && pass;<br>
+ return pass ? PIGLIT_PASS : PIGLIT_FAIL;<br>
+}<br>
<span class=""><font color="#888888">--<br>
1.8.1.4<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>