<div dir="ltr">On 18 December 2012 11:54, Ian Romanick <span dir="ltr"><<a href="mailto:idr@freedesktop.org" target="_blank">idr@freedesktop.org</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">On 12/17/2012 10:17 AM, Paul Berry wrote:<br>
<br>
This test looks good.  You should add the note about NVIDIA's driver to the commit message when you push.<br></blockquote><div><br></div><div>Ok, will do.  Thanks.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<br>
Reviewed-by: Ian Romanick <<a href="mailto:ian.d.romanick@intel.com" target="_blank">ian.d.romanick@intel.com</a>><div class="HOEnZb"><div class="h5"><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
---<br>
  tests/all.tests                                    |   6 +<br>
  .../spec/ext_transform_<u></u>feedback/CMakeLists.gl.txt  |   1 +<br>
  tests/spec/ext_transform_<u></u>feedback/change-size.c    | 320 +++++++++++++++++++++<br>
  3 files changed, 327 insertions(+)<br>
  create mode 100644 tests/spec/ext_transform_<u></u>feedback/change-size.c<br>
<br>
diff --git a/tests/all.tests b/tests/all.tests<br>
index c823bcf..1cbbe98 100644<br>
--- a/tests/all.tests<br>
+++ b/tests/all.tests<br>
@@ -1925,6 +1925,12 @@ for mode in ['discard', 'buffer', 'prims_generated', 'prims_written']:<br>
          ext_transform_feedback[test_<u></u>name] = concurrent_test(<br>
                  'ext_transform_feedback-{0}'.<u></u>format(test_name))<br>
<br>
+for test_case in ['base-shrink', 'base-grow', 'offset-shrink', 'offset-grow',<br>
+                  'range-shrink', 'range-grow']:<br>
+        test_name = 'change-size {0}'.format(test_case)<br>
+        ext_transform_feedback[test_<u></u>name] = concurrent_test(<br>
+                'ext_transform_feedback-{0}'.<u></u>format(test_name))<br>
+<br>
  arb_transform_feedback2 = Group()<br>
  spec['ARB_transform_feedback2'<u></u>] = arb_transform_feedback2<br>
  arb_transform_feedback2['draw-<u></u>auto'] = PlainExecTest(['arb_transform_<u></u>feedback2-draw-auto', '-auto'])<br>
diff --git a/tests/spec/ext_transform_<u></u>feedback/CMakeLists.gl.txt b/tests/spec/ext_transform_<u></u>feedback/CMakeLists.gl.txt<br>
index 9325091..63c3f4b 100644<br>
--- a/tests/spec/ext_transform_<u></u>feedback/CMakeLists.gl.txt<br>
+++ b/tests/spec/ext_transform_<u></u>feedback/CMakeLists.gl.txt<br>
@@ -13,6 +13,7 @@ piglit_add_executable (ext_transform_feedback-<u></u>alignment alignment.c)<br>
  piglit_add_executable (ext_transform_feedback-api-<u></u>errors api-errors.c)<br>
  piglit_add_executable (ext_transform_feedback-<u></u>buffer-usage buffer-usage.c)<br>
  piglit_add_executable (ext_transform_feedback-<u></u>builtin-varyings builtin-varyings.c)<br>
+piglit_add_executable (ext_transform_feedback-<u></u>change-size change-size.c)<br>
  piglit_add_executable (ext_transform_feedback-<u></u>discard-api discard-api.c)<br>
  piglit_add_executable (ext_transform_feedback-<u></u>discard-bitmap discard-bitmap.c)<br>
  piglit_add_executable (ext_transform_feedback-<u></u>discard-clear discard-clear.c)<br>
diff --git a/tests/spec/ext_transform_<u></u>feedback/change-size.c b/tests/spec/ext_transform_<u></u>feedback/change-size.c<br>
new file mode 100644<br>
index 0000000..ea6fe46<br>
--- /dev/null<br>
+++ b/tests/spec/ext_transform_<u></u>feedback/change-size.c<br>
@@ -0,0 +1,320 @@<br>
+/*<br>
+ * Copyright © 2012 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<br>
+ * DEALINGS IN THE SOFTWARE.<br>
+ */<br>
+<br>
+/**<br>
+ * \file change-size.c<br>
+ *<br>
+ * Confirm that transform feedback properly handles a change in the<br>
+ * size of a transform feedback buffer after it is bound but before it<br>
+ * is used.<br>
+ *<br>
+ * In particular, this test verifies the following behaviours, from<br>
+ * the GL 4.3 spec, section 6.1.1 ("Binding Buffer Objects to Indexed<br>
+ * Targets"):<br>
+ *<br>
+ *   BindBufferBase binds the entire buffer, even when the size of the buffer<br>
+ *   is changed after the binding is established. It is equivalent to calling<br>
+ *   BindBufferRange with offset zero, while size is determined by the size of<br>
+ *   the bound buffer at the time the binding is used.<br>
+ *<br>
+ *   Regardless of the size specified with BindBufferRange, or indirectly with<br>
+ *   BindBufferBase, the GL will never read or write beyond the end of a bound<br>
+ *   buffer. In some cases this constraint may result in visibly different<br>
+ *   behavior when a buffer overflow would otherwise result, such as described<br>
+ *   for transform feedback operations in section 13.2.2.<br>
+ *<br>
+ * This test verifies that the expected number of primitives are<br>
+ * written after a change to the size of the transform feedback<br>
+ * buffer, using both a GL_TRANSFORM_FEEDBACK_<u></u>PRIMITIVES_WRITTEN query<br>
+ * and by looking at the contents of the buffer itself.  We run<br>
+ * transform feedback in GL_TRIANGLES mode and use a buffer size that<br>
+ * is not a multiple of 3, so that we can look at the last element in<br>
+ * the transform feedback buffer and verify that transform feedback<br>
+ * didn't overwrite it.<br>
+ *<br>
+ * The test performs the following operations:<br>
+ *<br>
+ * 1. Create a transform feedback buffer using glBufferData().<br>
+ *<br>
+ * 2. Bind the buffer for transform feedback using either<br>
+ *    glBindBufferBase, glBindBufferRange, or glBindBufferOffsetEXT<br>
+ *    (if supported).<br>
+ *<br>
+ * 3. Change the size of the bound buffer using glBufferData().  A<br>
+ *    non-null data pointer is passed to glBufferData() to store a<br>
+ *    known pattern in the buffer, so that in step 6 we'll be able to<br>
+ *    determine which parts of the buffer were overwritten.<br>
+ *<br>
+ * 4. Draw some triangles, feeding back a single float from each<br>
+ *    vertex.<br>
+ *<br>
+ * 5. Verify, using a GL_TRANSFORM_FEEDBACK_<u></u>PRIMITIVES_WRITTEN query,<br>
+ *    that the expected number of primitives were written to the<br>
+ *    buffer.<br>
+ *<br>
+ * 6. Verify, using glMapBuffer, that the expected data was written to<br>
+ *    the buffer.<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 = 10;<br>
+<br>
+       config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_ALPHA;<br>
+<br>
+PIGLIT_GL_TEST_CONFIG_END<br>
+<br>
+/**<br>
+ * Maximum buffer size--used for declaraing static arrays.  Measured<br>
+ * in multiples of sizeof(GLfloat).<br>
+ */<br>
+#define MAX_BUFFER_SIZE_FLOATS 10<br>
+<br>
+static GLuint prog;<br>
+static GLuint xfb_buf;<br>
+static GLuint query;<br>
+<br>
+const struct test_case<br>
+{<br>
+       /**<br>
+        * Name of the test case.  NULL is used as a sentinel to mark<br>
+        * the end of the list of test cases.<br>
+        */<br>
+       const char *name;<br>
+<br>
+       /**<br>
+        * Size that the buffer should have before binding.  Measured<br>
+        * in multiples of sizeof(GLfloat).<br>
+        */<br>
+       unsigned initial_size;<br>
+<br>
+       /**<br>
+        * Offset to pass to glBindBufferRange/<u></u>glBindBufferOffsetEXT,<br>
+        * or zero if glBindBufferBase should be used.  Measured in<br>
+        * multiples of sizeof(GLfloat).<br>
+        */<br>
+       unsigned bind_offset;<br>
+<br>
+       /**<br>
+        * Size to pass to glBindBufferRange, or zero if<br>
+        * glBindBufferOffsetEXT/<u></u>glBindBufferBase should be used.<br>
+        * Measured in multiples of sizeof(GLfloat).<br>
+        */<br>
+       unsigned bind_size;<br>
+<br>
+       /**<br>
+        * Size of the buffer that should be passed to<br>
+        * glBindBufferData after the buffer is bound.  Measured in<br>
+        * multiples of sizeof(GLfloat).<br>
+        */<br>
+       unsigned new_size;<br>
+<br>
+       /**<br>
+        * Number of triangles to draw.<br>
+        */<br>
+       unsigned num_draw_triangles;<br>
+<br>
+       /**<br>
+        * Number of primitives that are expected to be written to the<br>
+        * buffer.<br>
+        */<br>
+       unsigned num_feedback_triangles;<br>
+} test_cases[] = {<br>
+       /* name            initial  bind    bind  new   num tris:<br>
+        *                 size     offset  size  size  draw  feedback */<br>
+       { "base-shrink",   7,       0,      0,    4,    2,    1 },<br>
+       { "base-grow",     4,       0,      0,    7,    2,    2 },<br>
+       { "offset-shrink", 10,      3,      0,    7,    2,    1 },<br>
+       { "offset-grow",   7,       3,      0,    10,   2,    2 },<br>
+       { "range-shrink",  10,      3,      7,    7,    2,    1 },<br>
+       { "range-grow",    7,       3,      4,    10,   2,    1 },<br>
+       { NULL,            0,       0,      0,    0,    0,    0 }<br>
+};<br>
+<br>
+const struct test_case *selected_test;<br>
+<br>
+/**<br>
+ * Vertex shader, which simply copies its input attribute to its<br>
+ * output varying, adding 100 in the process.<br>
+ */<br>
+static const char *vstext =<br>
+       "#version 120\n"<br>
+       "attribute float input_value;\n"<br>
+       "varying float output_value;\n"<br>
+       "\n"<br>
+       "void main()\n"<br>
+       "{\n"<br>
+       "  gl_Position = vec4(0.0);\n"<br>
+       "  output_value = 100.0 + input_value;\n"<br>
+       "}\n";<br>
+<br>
+static void<br>
+print_usage_and_exit(const char *prog_name)<br>
+{<br>
+       unsigned i;<br>
+       printf("Usage: %s <test_case>\n"<br>
+              "  where <test_case> is one of the following:\n", prog_name);<br>
+       for (i = 0; test_cases[i].name != NULL; i++)<br>
+               printf("    %s\n", test_cases[i].name);<br>
+       exit(1);<br>
+}<br>
+<br>
+static const struct test_case *<br>
+interpret_test_case_arg(const char *arg)<br>
+{<br>
+       unsigned i;<br>
+       for (i = 0; test_cases[i].name != NULL; i++) {<br>
+               if (strcmp(test_cases[i].name, arg) == 0)<br>
+                       return &test_cases[i];<br>
+       }<br>
+       return NULL;<br>
+}<br>
+<br>
+void<br>
+piglit_init(int argc, char **argv)<br>
+{<br>
+       GLuint vs;<br>
+       const char *varying_name = "output_value";<br>
+<br>
+       /* Parse args */<br>
+       if (argc != 2)<br>
+               print_usage_and_exit(argv[0]);<br>
+       selected_test = interpret_test_case_arg(argv[<u></u>1]);<br>
+       if (selected_test == NULL)<br>
+               print_usage_and_exit(argv[0]);<br>
+<br>
+       /* Make sure required GL features are present */<br>
+       piglit_require_GLSL_version(<u></u>120);<br>
+       piglit_require_transform_<u></u>feedback();<br>
+       if (selected_test->bind_offset != 0 && selected_test->bind_size == 0) {<br>
+               /* Test requires glBindBufferOffsetEXT, which is in<br>
+                * EXT_transform_feedback, but was never adopted into<br>
+                * OpenGL.<br>
+                */<br>
+               piglit_require_extension("GL_<u></u>EXT_transform_feedback");<br>
+       }<br>
+<br>
+       /* Create program and buffer */<br>
+       vs = piglit_compile_shader_text(GL_<u></u>VERTEX_SHADER, vstext);<br>
+       prog = glCreateProgram();<br>
+       glAttachShader(prog, vs);<br>
+       glTransformFeedbackVaryings(<u></u>prog, 1, &varying_name,<br>
+                                   GL_INTERLEAVED_ATTRIBS);<br>
+       glLinkProgram(prog);<br>
+       if (!piglit_link_check_status(<u></u>prog))<br>
+               piglit_report_result(PIGLIT_<u></u>FAIL);<br>
+       glGenBuffers(1, &xfb_buf);<br>
+       glGenQueries(1, &query);<br>
+       if (!piglit_check_gl_error(GL_NO_<u></u>ERROR))<br>
+               piglit_report_result(PIGLIT_<u></u>FAIL);<br>
+}<br>
+<br>
+enum piglit_result<br>
+piglit_display(void)<br>
+{<br>
+       GLint input_index = glGetAttribLocation(prog, "input_value");<br>
+       GLfloat canary_data[MAX_BUFFER_SIZE_<u></u>FLOATS];<br>
+       GLfloat input_data[MAX_BUFFER_SIZE_<u></u>FLOATS];<br>
+       GLfloat expected_data[MAX_BUFFER_SIZE_<u></u>FLOATS];<br>
+       GLfloat *output_data;<br>
+       GLuint query_result;<br>
+       GLboolean pass = GL_TRUE;<br>
+       unsigned i;<br>
+<br>
+       glUseProgram(prog);<br>
+<br>
+       /* Create a transform feedback buffer. */<br>
+       glBindBuffer(GL_TRANSFORM_<u></u>FEEDBACK_BUFFER, xfb_buf);<br>
+       glBufferData(GL_TRANSFORM_<u></u>FEEDBACK_BUFFER,<br>
+                    selected_test->initial_size * sizeof(GLfloat), NULL,<br>
+                    GL_STREAM_READ);<br>
+<br>
+       /* Bind the buffer for transform feedback. */<br>
+       if (selected_test->bind_size != 0) {<br>
+               glBindBufferRange(GL_<u></u>TRANSFORM_FEEDBACK_BUFFER, 0, xfb_buf,<br>
+                                 selected_test->bind_offset * sizeof(GLfloat),<br>
+                                 selected_test->bind_size * sizeof(GLfloat));<br>
+       } else if (selected_test->bind_offset != 0) {<br>
+               glBindBufferOffsetEXT(GL_<u></u>TRANSFORM_FEEDBACK_BUFFER, 0,<br>
+                                     xfb_buf,<br>
+                                     selected_test->bind_offset<br>
+                                     * sizeof(GLfloat));<br>
+       } else {<br>
+               glBindBufferBase(GL_TRANSFORM_<u></u>FEEDBACK_BUFFER, 0, xfb_buf);<br>
+       }<br>
+<br>
+       /* Change the size of the bound buffer. */<br>
+       for (i = 0; i < MAX_BUFFER_SIZE_FLOATS; i++)<br>
+               canary_data[i] = -1;<br>
+       glBufferData(GL_TRANSFORM_<u></u>FEEDBACK_BUFFER,<br>
+                    selected_test->new_size * sizeof(GLfloat), canary_data,<br>
+                    GL_STREAM_READ);<br>
+<br>
+       /* Draw some triangles. */<br>
+       for (i = 0; i < MAX_BUFFER_SIZE_FLOATS; i++)<br>
+               input_data[i] = i + 1;<br>
+       glBindBuffer(GL_ARRAY_BUFFER, 0);<br>
+       glVertexAttribPointer(input_<u></u>index, 1, GL_FLOAT, GL_FALSE,<br>
+                             sizeof(GLfloat), input_data);<br>
+       glEnableVertexAttribArray(<u></u>input_index);<br>
+       glBeginTransformFeedback(GL_<u></u>TRIANGLES);<br>
+       glBeginQuery(GL_TRANSFORM_<u></u>FEEDBACK_PRIMITIVES_WRITTEN, query);<br>
+       glDrawArrays(GL_TRIANGLES, 0, selected_test->num_draw_<u></u>triangles * 3);<br>
+       glEndQuery(GL_TRANSFORM_<u></u>FEEDBACK_PRIMITIVES_WRITTEN);<br>
+       glEndTransformFeedback();<br>
+<br>
+       /* Verify that the expected number of primitives were<br>
+        * written.<br>
+        */<br>
+       glGetQueryObjectuiv(query, GL_QUERY_RESULT, &query_result);<br>
+       printf("PRIMITIVES_WRITTEN: expected=%u, actual=%u\n",<br>
+              selected_test->num_feedback_<u></u>triangles, query_result);<br>
+       if (query_result != selected_test->num_feedback_<u></u>triangles)<br>
+               pass = GL_FALSE;<br>
+<br>
+       /* Verify that the expected data was written. */<br>
+       for (i = 0; i < selected_test->new_size; i++) {<br>
+               if (i >= selected_test->bind_offset &&<br>
+                   i < (3 * selected_test->num_feedback_<u></u>triangles<br>
+                        + selected_test->bind_offset)) {<br>
+                       expected_data[i] = 100.0<br>
+                               + input_data[i - selected_test->bind_offset];<br>
+               } else {<br>
+                       expected_data[i] = canary_data[i];<br>
+               }<br>
+       }<br>
+       output_data = glMapBuffer(GL_TRANSFORM_<u></u>FEEDBACK_BUFFER, GL_READ_ONLY);<br>
+       for (i = 0; i < selected_test->new_size; ++i) {<br>
+               printf("data[%u]: expected=%f, actual=%f\n", i,<br>
+                      expected_data[i], output_data[i]);<br>
+               if (expected_data[i] != output_data[i])<br>
+                       pass = GL_FALSE;<br>
+       }<br>
+       glUnmapBuffer(GL_TRANSFORM_<u></u>FEEDBACK_BUFFER);<br>
+<br>
+       piglit_present_results();<br>
+<br>
+       return pass ? PIGLIT_PASS : PIGLIT_FAIL;<br>
+}<br>
<br>
</blockquote>
<br>
</div></div></blockquote></div><br></div></div>