Re: [Mesa-dev] [PATCH] draw-robustness: Test robustness for out-of-bounds vertex fetches.

2011-04-01 Thread Ian Romanick
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 04/01/2011 07:12 AM, José Fonseca wrote:
> On 03/31/2011 09:45 PM, Ian Romanick wrote:
>>> +glVertexPointer(2, GL_FLOAT, vertex_stride, (const
>>> void*)(intptr_t)vertex_offset);
>>> +glDrawRangeElements(GL_TRIANGLES,
>>> +min_index,
>>> +max_index,
>>> +index_count,
>>> +GL_UNSIGNED_SHORT,
>>> +(const void*)(intptr_t)index_offset);
>>> +assert(glGetError() == GL_NO_ERROR);
>>> +glFinish();
>>>  
>> Why?  Both for this finish and the one below.
> 
> It helps matching the above printf output with the crashes.  Because
> unlike most other tests this test does not use glReadPixels, so unless
> we call glFinish the draw can be batched and the cpu crash / gpu crash
> could happen much later.

Ah.  That makes sense.  A comment would help. :)
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/

iEYEARECAAYFAk2WG2QACgkQX1gOwKyEAw/K8ACfQl7XtHb6H19Y0JIrtVxHKaCE
EHkAoJCUZxI1L+6rG4J/wTPvNBNlRHU4
=hcng
-END PGP SIGNATURE-
___
mesa-dev mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH] draw-robustness: Test robustness for out-of-bounds vertex fetches.

2011-04-01 Thread José Fonseca

On 03/31/2011 09:45 PM, Ian Romanick wrote:

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 03/31/2011 06:46 AM, [email protected] wrote:
   

From: José Fonseca

Not added to the standard test lists given that ARB_vertex_buffer_object
allows program termination out-of-bounds vertex buffer object fetches
occur.
 

In anticipation of making real GL_ARB_robustness tests, I'd suggest
putting this in tests/spec/ARB_robustness.  We can add it to the general
test list once it has ARB_robustness support, which I see listed as a
todo item.
   

OK.

There are a couple comments below.

   

---
  tests/general/CMakeLists.gl.txt |1 +
  tests/general/draw-robustness.c |  201 +++
  2 files changed, 202 insertions(+), 0 deletions(-)
  create mode 100644 tests/general/draw-robustness.c

diff --git a/tests/general/CMakeLists.gl.txt b/tests/general/CMakeLists.gl.txt
index bbe6507..d373e35 100644
--- a/tests/general/CMakeLists.gl.txt
+++ b/tests/general/CMakeLists.gl.txt
@@ -36,6 +36,7 @@ ENDIF (UNIX)
  add_executable (draw-elements-vs-inputs draw-elements-vs-inputs.c)
  add_executable (draw-instanced draw-instanced.c)
  add_executable (draw-instanced-divisor draw-instanced-divisor.c)
+add_executable (draw-robustness draw-robustness.c)
  add_executable (draw-vertices draw-vertices.c)
  add_executable (draw-vertices-half-float draw-vertices-half-float.c)
  add_executable (fog-modes fog-modes.c)
diff --git a/tests/general/draw-robustness.c b/tests/general/draw-robustness.c
new file mode 100644
index 000..a13f568
--- /dev/null
+++ b/tests/general/draw-robustness.c
@@ -0,0 +1,201 @@
+/*
+ * Copyright (C) 2011 VMware, Inc.
+ * Copyright (C) 2010 Marek Olšák
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ *   Jose Fonseca
+ *   Based on code from Marek Olšák
+ */
+
+/* Test whether out-of-bounds vertex buffer object cause termination.
+ *
+ * Note that the original ARB_vertex_buffer_object extension explicitly states
+ * program termination is allowed when out-of-bounds vertex buffer object
+ * fetches occur.  The ARB_robustness extension does provides an enbale to
+ * guarantee that out-of-bounds buffer object accesses by the GPU will have
+ * deterministic behavior and preclude application instability or termination
+ * due to an incorrect buffer access.  But regardless of ARB_robustness
+ * extension support it is a good idea not to crash.  For example,  viewperf
+ * doesn't properly detect NV_primitive_restart and emits 0x indices
+ * which can result in crashes.
+ *
+ * TODO:
+ * - test out-of-bound index buffer object access
+ * - test more vertex/element formats
+ * - test non-aligned offsets
+ * - provide a command line option to actually enable ARB_robustness
+ */
+
+#include "piglit-util.h"
+
+int piglit_width = 320, piglit_height = 320;
+int piglit_window_mode = GLUT_RGB;
+
+void piglit_init(int argc, char **argv)
+{
+piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
+
+if (!GLEW_VERSION_1_5) {
+printf("Requires OpenGL 1.5\n");
+piglit_report_result(PIGLIT_SKIP);
+}
+
+glShadeModel(GL_FLAT);
+glClearColor(0.2, 0.2, 0.2, 1.0);
+}
+
+static void
+random_vertices(GLsizei offset, GLsizei stride, GLsizei count)
+{
+GLsizei size = offset + (count - 1)*stride + 2 * sizeof(GLfloat);
+GLubyte *vertices;
+GLsizei i;
+
+assert(offset % sizeof(GLfloat) == 0);
+assert(stride % sizeof(GLfloat) == 0);
+
+vertices = malloc(size);
+assert(vertices);
+if (!vertices) {
+return;
+}
 

Since this is with a VBO, why not use MapBuffer/UnmapBuffer instead of
malloc/free?

OK.
   

+if (0) {
+fprintf(stderr, "vertex_offset = %i\n", vertex_offset);
+fprintf(stderr, "vertex_stride = %i\n", vertex_stride);
+fprintf(stderr, "vertex_count = %i\n", vertex_count);
+fprintf(stder

Re: [Mesa-dev] [PATCH] draw-robustness: Test robustness for out-of-bounds vertex fetches.

2011-04-01 Thread José Fonseca

On 03/31/2011 09:38 PM, Eric Anholt wrote:

On Thu, 31 Mar 2011 14:46:32 +0100, [email protected] wrote:
   

+/* Test whether out-of-bounds vertex buffer object cause termination.
+ *
+ * Note that the original ARB_vertex_buffer_object extension explicitly states
+ * program termination is allowed when out-of-bounds vertex buffer object
+ * fetches occur.  The ARB_robustness extension does provides an enbale to
+ * guarantee that out-of-bounds buffer object accesses by the GPU will have
+ * deterministic behavior and preclude application instability or termination
+ * due to an incorrect buffer access.  But regardless of ARB_robustness
+ * extension support it is a good idea not to crash.  For example,  viewperf
+ * doesn't properly detect NV_primitive_restart and emits 0x indices
+ * which can result in crashes.
+ *
+ * TODO:
+ * - test out-of-bound index buffer object access
+ * - test more vertex/element formats
+ * - test non-aligned offsets
+ * - provide a command line option to actually enable ARB_robustness
+ */
 

Instead of a single draw-robustness test to (eventually) test all these
things, a draw-robustness-* collection of tests for each would be way
more useful.
   


Sounds good. Will do.

Jose
___
mesa-dev mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH] draw-robustness: Test robustness for out-of-bounds vertex fetches.

2011-03-31 Thread Ian Romanick
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 03/31/2011 06:46 AM, [email protected] wrote:
> From: José Fonseca 
> 
> Not added to the standard test lists given that ARB_vertex_buffer_object
> allows program termination out-of-bounds vertex buffer object fetches
> occur.

In anticipation of making real GL_ARB_robustness tests, I'd suggest
putting this in tests/spec/ARB_robustness.  We can add it to the general
test list once it has ARB_robustness support, which I see listed as a
todo item.

There are a couple comments below.

> ---
>  tests/general/CMakeLists.gl.txt |1 +
>  tests/general/draw-robustness.c |  201 
> +++
>  2 files changed, 202 insertions(+), 0 deletions(-)
>  create mode 100644 tests/general/draw-robustness.c
> 
> diff --git a/tests/general/CMakeLists.gl.txt b/tests/general/CMakeLists.gl.txt
> index bbe6507..d373e35 100644
> --- a/tests/general/CMakeLists.gl.txt
> +++ b/tests/general/CMakeLists.gl.txt
> @@ -36,6 +36,7 @@ ENDIF (UNIX)
>  add_executable (draw-elements-vs-inputs draw-elements-vs-inputs.c)
>  add_executable (draw-instanced draw-instanced.c)
>  add_executable (draw-instanced-divisor draw-instanced-divisor.c)
> +add_executable (draw-robustness draw-robustness.c)
>  add_executable (draw-vertices draw-vertices.c)
>  add_executable (draw-vertices-half-float draw-vertices-half-float.c)
>  add_executable (fog-modes fog-modes.c)
> diff --git a/tests/general/draw-robustness.c b/tests/general/draw-robustness.c
> new file mode 100644
> index 000..a13f568
> --- /dev/null
> +++ b/tests/general/draw-robustness.c
> @@ -0,0 +1,201 @@
> +/*
> + * Copyright (C) 2011 VMware, Inc.
> + * Copyright (C) 2010 Marek Olšák 
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a
> + * copy of this software and associated documentation files (the "Software"),
> + * to deal in the Software without restriction, including without limitation
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> + * and/or sell copies of the Software, and to permit persons to whom the
> + * Software is furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice (including the next
> + * paragraph) shall be included in all copies or substantial portions of the
> + * Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
> + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
> + * DEALINGS IN THE SOFTWARE.
> + *
> + * Authors:
> + *   Jose Fonseca 
> + *   Based on code from Marek Olšák 
> + */
> +
> +/* Test whether out-of-bounds vertex buffer object cause termination.
> + *
> + * Note that the original ARB_vertex_buffer_object extension explicitly 
> states
> + * program termination is allowed when out-of-bounds vertex buffer object
> + * fetches occur.  The ARB_robustness extension does provides an enbale to
> + * guarantee that out-of-bounds buffer object accesses by the GPU will have
> + * deterministic behavior and preclude application instability or termination
> + * due to an incorrect buffer access.  But regardless of ARB_robustness
> + * extension support it is a good idea not to crash.  For example,  viewperf
> + * doesn't properly detect NV_primitive_restart and emits 0x indices
> + * which can result in crashes.
> + *
> + * TODO:
> + * - test out-of-bound index buffer object access
> + * - test more vertex/element formats
> + * - test non-aligned offsets
> + * - provide a command line option to actually enable ARB_robustness
> + */
> +
> +#include "piglit-util.h"
> +
> +int piglit_width = 320, piglit_height = 320;
> +int piglit_window_mode = GLUT_RGB;
> +
> +void piglit_init(int argc, char **argv)
> +{
> +piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
> +
> +if (!GLEW_VERSION_1_5) {
> +printf("Requires OpenGL 1.5\n");
> +piglit_report_result(PIGLIT_SKIP);
> +}
> +
> +glShadeModel(GL_FLAT);
> +glClearColor(0.2, 0.2, 0.2, 1.0);
> +}
> +
> +static void
> +random_vertices(GLsizei offset, GLsizei stride, GLsizei count)
> +{
> +GLsizei size = offset + (count - 1)*stride + 2 * sizeof(GLfloat);
> +GLubyte *vertices;
> +GLsizei i;
> +
> +assert(offset % sizeof(GLfloat) == 0);
> +assert(stride % sizeof(GLfloat) == 0);
> +
> +vertices = malloc(size);
> +assert(vertices);
> +if (!vertices) {
> +return;
> +}

Since this is with a VBO, why not use MapBuffer/UnmapBuffer instead of
malloc/free?

> +
> +for (i = 0; i < count; ++i) {
> +GLfloat *vertex = (GLfloat *)(vertices + offs

Re: [Mesa-dev] [PATCH] draw-robustness: Test robustness for out-of-bounds vertex fetches.

2011-03-31 Thread Eric Anholt
On Thu, 31 Mar 2011 14:46:32 +0100, [email protected] wrote:
> From: José Fonseca 
> 
> Not added to the standard test lists given that ARB_vertex_buffer_object
> allows program termination out-of-bounds vertex buffer object fetches
> occur.
> ---
>  tests/general/CMakeLists.gl.txt |1 +
>  tests/general/draw-robustness.c |  201 
> +++
>  2 files changed, 202 insertions(+), 0 deletions(-)
>  create mode 100644 tests/general/draw-robustness.c
> 
> diff --git a/tests/general/CMakeLists.gl.txt b/tests/general/CMakeLists.gl.txt
> index bbe6507..d373e35 100644
> --- a/tests/general/CMakeLists.gl.txt
> +++ b/tests/general/CMakeLists.gl.txt
> @@ -36,6 +36,7 @@ ENDIF (UNIX)
>  add_executable (draw-elements-vs-inputs draw-elements-vs-inputs.c)
>  add_executable (draw-instanced draw-instanced.c)
>  add_executable (draw-instanced-divisor draw-instanced-divisor.c)
> +add_executable (draw-robustness draw-robustness.c)
>  add_executable (draw-vertices draw-vertices.c)
>  add_executable (draw-vertices-half-float draw-vertices-half-float.c)
>  add_executable (fog-modes fog-modes.c)
> diff --git a/tests/general/draw-robustness.c b/tests/general/draw-robustness.c
> new file mode 100644
> index 000..a13f568
> --- /dev/null
> +++ b/tests/general/draw-robustness.c
> @@ -0,0 +1,201 @@
> +/*
> + * Copyright (C) 2011 VMware, Inc.
> + * Copyright (C) 2010 Marek Olšák 
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a
> + * copy of this software and associated documentation files (the "Software"),
> + * to deal in the Software without restriction, including without limitation
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> + * and/or sell copies of the Software, and to permit persons to whom the
> + * Software is furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice (including the next
> + * paragraph) shall be included in all copies or substantial portions of the
> + * Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
> + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
> + * DEALINGS IN THE SOFTWARE.
> + *
> + * Authors:
> + *   Jose Fonseca 
> + *   Based on code from Marek Olšák 
> + */
> +
> +/* Test whether out-of-bounds vertex buffer object cause termination.
> + *
> + * Note that the original ARB_vertex_buffer_object extension explicitly 
> states
> + * program termination is allowed when out-of-bounds vertex buffer object
> + * fetches occur.  The ARB_robustness extension does provides an enbale to
> + * guarantee that out-of-bounds buffer object accesses by the GPU will have
> + * deterministic behavior and preclude application instability or termination
> + * due to an incorrect buffer access.  But regardless of ARB_robustness
> + * extension support it is a good idea not to crash.  For example,  viewperf
> + * doesn't properly detect NV_primitive_restart and emits 0x indices
> + * which can result in crashes.
> + *
> + * TODO:
> + * - test out-of-bound index buffer object access
> + * - test more vertex/element formats
> + * - test non-aligned offsets
> + * - provide a command line option to actually enable ARB_robustness
> + */

Instead of a single draw-robustness test to (eventually) test all these
things, a draw-robustness-* collection of tests for each would be way
more useful.


pgpLw62Km8RZb.pgp
Description: PGP signature
___
mesa-dev mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH] draw-robustness: Test robustness for out-of-bounds vertex fetches.

2011-03-31 Thread Keith Whitwell
Looks good.

Keith

On Thu, 2011-03-31 at 14:46 +0100, [email protected] wrote:
> From: José Fonseca 
> 
> Not added to the standard test lists given that ARB_vertex_buffer_object
> allows program termination out-of-bounds vertex buffer object fetches
> occur.
> ---
>  tests/general/CMakeLists.gl.txt |1 +
>  tests/general/draw-robustness.c |  201 
> +++
>  2 files changed, 202 insertions(+), 0 deletions(-)
>  create mode 100644 tests/general/draw-robustness.c
> 
> diff --git a/tests/general/CMakeLists.gl.txt b/tests/general/CMakeLists.gl.txt
> index bbe6507..d373e35 100644
> --- a/tests/general/CMakeLists.gl.txt
> +++ b/tests/general/CMakeLists.gl.txt
> @@ -36,6 +36,7 @@ ENDIF (UNIX)
>  add_executable (draw-elements-vs-inputs draw-elements-vs-inputs.c)
>  add_executable (draw-instanced draw-instanced.c)
>  add_executable (draw-instanced-divisor draw-instanced-divisor.c)
> +add_executable (draw-robustness draw-robustness.c)
>  add_executable (draw-vertices draw-vertices.c)
>  add_executable (draw-vertices-half-float draw-vertices-half-float.c)
>  add_executable (fog-modes fog-modes.c)
> diff --git a/tests/general/draw-robustness.c b/tests/general/draw-robustness.c
> new file mode 100644
> index 000..a13f568
> --- /dev/null
> +++ b/tests/general/draw-robustness.c
> @@ -0,0 +1,201 @@
> +/*
> + * Copyright (C) 2011 VMware, Inc.
> + * Copyright (C) 2010 Marek Olšák 
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a
> + * copy of this software and associated documentation files (the "Software"),
> + * to deal in the Software without restriction, including without limitation
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> + * and/or sell copies of the Software, and to permit persons to whom the
> + * Software is furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice (including the next
> + * paragraph) shall be included in all copies or substantial portions of the
> + * Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
> + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
> + * DEALINGS IN THE SOFTWARE.
> + *
> + * Authors:
> + *   Jose Fonseca 
> + *   Based on code from Marek Olšák 
> + */
> +
> +/* Test whether out-of-bounds vertex buffer object cause termination.
> + *
> + * Note that the original ARB_vertex_buffer_object extension explicitly 
> states
> + * program termination is allowed when out-of-bounds vertex buffer object
> + * fetches occur.  The ARB_robustness extension does provides an enbale to
> + * guarantee that out-of-bounds buffer object accesses by the GPU will have
> + * deterministic behavior and preclude application instability or termination
> + * due to an incorrect buffer access.  But regardless of ARB_robustness
> + * extension support it is a good idea not to crash.  For example,  viewperf
> + * doesn't properly detect NV_primitive_restart and emits 0x indices
> + * which can result in crashes.
> + *
> + * TODO:
> + * - test out-of-bound index buffer object access
> + * - test more vertex/element formats
> + * - test non-aligned offsets
> + * - provide a command line option to actually enable ARB_robustness
> + */
> +
> +#include "piglit-util.h"
> +
> +int piglit_width = 320, piglit_height = 320;
> +int piglit_window_mode = GLUT_RGB;
> +
> +void piglit_init(int argc, char **argv)
> +{
> +piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
> +
> +if (!GLEW_VERSION_1_5) {
> +printf("Requires OpenGL 1.5\n");
> +piglit_report_result(PIGLIT_SKIP);
> +}
> +
> +glShadeModel(GL_FLAT);
> +glClearColor(0.2, 0.2, 0.2, 1.0);
> +}
> +
> +static void
> +random_vertices(GLsizei offset, GLsizei stride, GLsizei count)
> +{
> +GLsizei size = offset + (count - 1)*stride + 2 * sizeof(GLfloat);
> +GLubyte *vertices;
> +GLsizei i;
> +
> +assert(offset % sizeof(GLfloat) == 0);
> +assert(stride % sizeof(GLfloat) == 0);
> +
> +vertices = malloc(size);
> +assert(vertices);
> +if (!vertices) {
> +return;
> +}
> +
> +for (i = 0; i < count; ++i) {
> +GLfloat *vertex = (GLfloat *)(vertices + offset + i*stride);
> +vertex[0] = (rand() % 1000) * .001;
> +vertex[1] = (rand() % 1000) * .001;
> +}
> +
> +glBufferData(GL_ARRAY_BUFFER, size, vertices, GL_STATIC_DRAW);
> +assert(glGetError() == GL_NO_ERROR);
> +
> +free(vertices);
> +}
> +
> +static void
> +random_ushort_indices(GLsizei offset, GLsizei count, GLuint min_index, 

[Mesa-dev] [PATCH] draw-robustness: Test robustness for out-of-bounds vertex fetches.

2011-03-31 Thread jfonseca
From: José Fonseca 

Not added to the standard test lists given that ARB_vertex_buffer_object
allows program termination out-of-bounds vertex buffer object fetches
occur.
---
 tests/general/CMakeLists.gl.txt |1 +
 tests/general/draw-robustness.c |  201 +++
 2 files changed, 202 insertions(+), 0 deletions(-)
 create mode 100644 tests/general/draw-robustness.c

diff --git a/tests/general/CMakeLists.gl.txt b/tests/general/CMakeLists.gl.txt
index bbe6507..d373e35 100644
--- a/tests/general/CMakeLists.gl.txt
+++ b/tests/general/CMakeLists.gl.txt
@@ -36,6 +36,7 @@ ENDIF (UNIX)
 add_executable (draw-elements-vs-inputs draw-elements-vs-inputs.c)
 add_executable (draw-instanced draw-instanced.c)
 add_executable (draw-instanced-divisor draw-instanced-divisor.c)
+add_executable (draw-robustness draw-robustness.c)
 add_executable (draw-vertices draw-vertices.c)
 add_executable (draw-vertices-half-float draw-vertices-half-float.c)
 add_executable (fog-modes fog-modes.c)
diff --git a/tests/general/draw-robustness.c b/tests/general/draw-robustness.c
new file mode 100644
index 000..a13f568
--- /dev/null
+++ b/tests/general/draw-robustness.c
@@ -0,0 +1,201 @@
+/*
+ * Copyright (C) 2011 VMware, Inc.
+ * Copyright (C) 2010 Marek Olšák 
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ *   Jose Fonseca 
+ *   Based on code from Marek Olšák 
+ */
+
+/* Test whether out-of-bounds vertex buffer object cause termination.
+ *
+ * Note that the original ARB_vertex_buffer_object extension explicitly states
+ * program termination is allowed when out-of-bounds vertex buffer object
+ * fetches occur.  The ARB_robustness extension does provides an enbale to
+ * guarantee that out-of-bounds buffer object accesses by the GPU will have
+ * deterministic behavior and preclude application instability or termination
+ * due to an incorrect buffer access.  But regardless of ARB_robustness
+ * extension support it is a good idea not to crash.  For example,  viewperf
+ * doesn't properly detect NV_primitive_restart and emits 0x indices
+ * which can result in crashes.
+ *
+ * TODO:
+ * - test out-of-bound index buffer object access
+ * - test more vertex/element formats
+ * - test non-aligned offsets
+ * - provide a command line option to actually enable ARB_robustness
+ */
+
+#include "piglit-util.h"
+
+int piglit_width = 320, piglit_height = 320;
+int piglit_window_mode = GLUT_RGB;
+
+void piglit_init(int argc, char **argv)
+{
+piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
+
+if (!GLEW_VERSION_1_5) {
+printf("Requires OpenGL 1.5\n");
+piglit_report_result(PIGLIT_SKIP);
+}
+
+glShadeModel(GL_FLAT);
+glClearColor(0.2, 0.2, 0.2, 1.0);
+}
+
+static void
+random_vertices(GLsizei offset, GLsizei stride, GLsizei count)
+{
+GLsizei size = offset + (count - 1)*stride + 2 * sizeof(GLfloat);
+GLubyte *vertices;
+GLsizei i;
+
+assert(offset % sizeof(GLfloat) == 0);
+assert(stride % sizeof(GLfloat) == 0);
+
+vertices = malloc(size);
+assert(vertices);
+if (!vertices) {
+return;
+}
+
+for (i = 0; i < count; ++i) {
+GLfloat *vertex = (GLfloat *)(vertices + offset + i*stride);
+vertex[0] = (rand() % 1000) * .001;
+vertex[1] = (rand() % 1000) * .001;
+}
+
+glBufferData(GL_ARRAY_BUFFER, size, vertices, GL_STATIC_DRAW);
+assert(glGetError() == GL_NO_ERROR);
+
+free(vertices);
+}
+
+static void
+random_ushort_indices(GLsizei offset, GLsizei count, GLuint min_index, GLuint 
max_index)
+{
+GLushort *indices;
+GLsizei size = offset + count*sizeof(*indices);
+GLsizei i;
+
+indices = malloc(size);
+assert(indices);
+if (!indices) {
+return;
+}
+
+assert(offset % sizeof(*indices) == 0);
+for (i = 0; i < count; ++i) {
+GLushort *index = indices + offs