aboutsummaryrefslogtreecommitdiff
path: root/mesalib/src/gallium/auxiliary
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2011-11-17 16:37:26 +0100
committermarha <marha@users.sourceforge.net>2011-11-17 16:37:26 +0100
commitd41bc08d1ae8c4784c09d8977816c0fadab1ba52 (patch)
tree4dc3081a9af0316eeee02356a44fcc2419e1b15e /mesalib/src/gallium/auxiliary
parent156e37d3879b316329e3e05579414031da2647e2 (diff)
downloadvcxsrv-d41bc08d1ae8c4784c09d8977816c0fadab1ba52.tar.gz
vcxsrv-d41bc08d1ae8c4784c09d8977816c0fadab1ba52.tar.bz2
vcxsrv-d41bc08d1ae8c4784c09d8977816c0fadab1ba52.zip
xserver mesa git update 17 nov 2011
Diffstat (limited to 'mesalib/src/gallium/auxiliary')
-rw-r--r--mesalib/src/gallium/auxiliary/util/u_draw.c214
-rw-r--r--mesalib/src/gallium/auxiliary/util/u_prim.h2
2 files changed, 116 insertions, 100 deletions
diff --git a/mesalib/src/gallium/auxiliary/util/u_draw.c b/mesalib/src/gallium/auxiliary/util/u_draw.c
index 4f2565edb..d16575b73 100644
--- a/mesalib/src/gallium/auxiliary/util/u_draw.c
+++ b/mesalib/src/gallium/auxiliary/util/u_draw.c
@@ -1,99 +1,115 @@
-/**************************************************************************
- *
- * Copyright 2011 VMware, Inc.
- * All Rights Reserved.
- *
- * 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, sub license, 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 NON-INFRINGEMENT.
- * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS 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.
- *
- **************************************************************************/
-
-
-#include "util/u_debug.h"
-#include "util/u_math.h"
-#include "util/u_format.h"
-#include "util/u_draw.h"
-
-
-/**
- * Returns the largest legal index value for the current set of bound vertex
- * buffers. Regardless of any other consideration, all vertex lookups need to
- * be clamped to 0..max_index to prevent an out-of-bound access.
- */
-unsigned
-util_draw_max_index(
- const struct pipe_vertex_buffer *vertex_buffers,
- unsigned nr_vertex_buffers,
- const struct pipe_vertex_element *vertex_elements,
- unsigned nr_vertex_elements,
- const struct pipe_draw_info *info)
-{
- unsigned max_index;
- unsigned i;
-
- max_index = ~0;
- for (i = 0; i < nr_vertex_elements; i++) {
- const struct pipe_vertex_element *element =
- &vertex_elements[i];
- const struct pipe_vertex_buffer *buffer =
- &vertex_buffers[element->vertex_buffer_index];
- unsigned buffer_size;
- const struct util_format_description *format_desc;
- unsigned format_size;
-
- assert(buffer->buffer->height0 == 1);
- assert(buffer->buffer->depth0 == 1);
- buffer_size = buffer->buffer->width0;
-
- format_desc = util_format_description(element->src_format);
- assert(format_desc->block.width == 1);
- assert(format_desc->block.height == 1);
- assert(format_desc->block.bits % 8 == 0);
- format_size = format_desc->block.bits/8;
-
- assert(buffer_size - buffer->buffer_offset <= buffer_size);
- buffer_size -= buffer->buffer_offset;
-
- assert(buffer_size - element->src_offset <= buffer_size);
- buffer_size -= element->src_offset;
-
- assert(buffer_size - format_size <= buffer_size);
- buffer_size -= format_size;
-
- if (buffer->stride != 0) {
- unsigned buffer_max_index;
-
- buffer_max_index = buffer_size / buffer->stride;
-
- if (element->instance_divisor == 0) {
- /* Per-vertex data */
- max_index = MIN2(max_index, buffer_max_index);
- }
- else {
- /* Per-instance data. Simply make sure the state tracker didn't
- * request more instances than those that fit in the buffer */
- assert((info->start_instance + info->instance_count)/element->instance_divisor
- <= (buffer_max_index + 1));
- }
- }
- }
-
- return max_index;
-}
+/**************************************************************************
+ *
+ * Copyright 2011 VMware, Inc.
+ * All Rights Reserved.
+ *
+ * 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, sub license, 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS 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.
+ *
+ **************************************************************************/
+
+
+#include "util/u_debug.h"
+#include "util/u_math.h"
+#include "util/u_format.h"
+#include "util/u_draw.h"
+
+
+/**
+ * Returns the largest legal index value plus one for the current set
+ * of bound vertex buffers. Regardless of any other consideration,
+ * all vertex lookups need to be clamped to 0..max_index-1 to prevent
+ * an out-of-bound access.
+ *
+ * Note that if zero is returned it means that one or more buffers is
+ * too small to contain any valid vertex data.
+ */
+unsigned
+util_draw_max_index(
+ const struct pipe_vertex_buffer *vertex_buffers,
+ unsigned nr_vertex_buffers,
+ const struct pipe_vertex_element *vertex_elements,
+ unsigned nr_vertex_elements,
+ const struct pipe_draw_info *info)
+{
+ unsigned max_index;
+ unsigned i;
+
+ max_index = ~0U - 1;
+ for (i = 0; i < nr_vertex_elements; i++) {
+ const struct pipe_vertex_element *element =
+ &vertex_elements[i];
+ const struct pipe_vertex_buffer *buffer =
+ &vertex_buffers[element->vertex_buffer_index];
+ unsigned buffer_size;
+ const struct util_format_description *format_desc;
+ unsigned format_size;
+
+ assert(buffer->buffer->height0 == 1);
+ assert(buffer->buffer->depth0 == 1);
+ buffer_size = buffer->buffer->width0;
+
+ format_desc = util_format_description(element->src_format);
+ assert(format_desc->block.width == 1);
+ assert(format_desc->block.height == 1);
+ assert(format_desc->block.bits % 8 == 0);
+ format_size = format_desc->block.bits/8;
+
+ if (buffer->buffer_offset >= buffer_size) {
+ /* buffer is too small */
+ return 0;
+ }
+
+ buffer_size -= buffer->buffer_offset;
+
+ if (element->src_offset >= buffer_size) {
+ /* buffer is too small */
+ return 0;
+ }
+
+ buffer_size -= element->src_offset;
+
+ if (format_size > buffer_size) {
+ /* buffer is too small */
+ return 0;
+ }
+
+ buffer_size -= format_size;
+
+ if (buffer->stride != 0) {
+ unsigned buffer_max_index;
+
+ buffer_max_index = buffer_size / buffer->stride;
+
+ if (element->instance_divisor == 0) {
+ /* Per-vertex data */
+ max_index = MIN2(max_index, buffer_max_index);
+ }
+ else {
+ /* Per-instance data. Simply make sure the state tracker didn't
+ * request more instances than those that fit in the buffer */
+ assert((info->start_instance + info->instance_count)/element->instance_divisor
+ <= (buffer_max_index + 1));
+ }
+ }
+ }
+
+ return max_index + 1;
+}
diff --git a/mesalib/src/gallium/auxiliary/util/u_prim.h b/mesalib/src/gallium/auxiliary/util/u_prim.h
index ca7c67d7c..070df643d 100644
--- a/mesalib/src/gallium/auxiliary/util/u_prim.h
+++ b/mesalib/src/gallium/auxiliary/util/u_prim.h
@@ -78,7 +78,7 @@ static INLINE boolean u_validate_pipe_prim( unsigned pipe_prim, unsigned nr )
static INLINE boolean u_trim_pipe_prim( unsigned pipe_prim, unsigned *nr )
{
boolean ok = TRUE;
- const static int values[][2] = {
+ const static unsigned values[][2] = {
{ 1, 0 }, /* PIPE_PRIM_POINTS */
{ 2, 2 }, /* PIPE_PRIM_LINES */
{ 2, 0 }, /* PIPE_PRIM_LINE_LOOP */