[Mesa-dev] [PATCH] swr: Don't crash when encountering a VBO with stride = 0.

Bruce Cherniak bruce.cherniak at intel.com
Tue Jun 13 22:26:49 UTC 2017


The swr driver uses vertex_buffer->stride to determinine the number
of elements in a VBO. A recent change to the state-tracker made it
possible for VBO's with stride=0. This resulted in a divide by zero
crash in the driver. The solution is to use the pre-calculated vertex
element stream_pitch in this case.

This patch fixes the crash in a number of piglit and VTK tests introduced
by 17f776c27be266f2.

There are several VTK tests that still crash and need proper handling of
vertex_buffer_index.  This will come in a follow-on patch.
---
 src/gallium/drivers/swr/swr_state.cpp | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/gallium/drivers/swr/swr_state.cpp b/src/gallium/drivers/swr/swr_state.cpp
index 08549e51a1..0641699c4b 100644
--- a/src/gallium/drivers/swr/swr_state.cpp
+++ b/src/gallium/drivers/swr/swr_state.cpp
@@ -1249,7 +1249,12 @@ swr_update_derived(struct pipe_context *pipe,
          if (!vb->is_user_buffer) {
             /* VBO
              * size is based on buffer->width0 rather than info.max_index
-             * to prevent having to validate VBO on each draw */
+             * to prevent having to validate VBO on each draw.
+             *
+             * If pitch=0, use the stream_pitch which is calculated during
+             * creation of vertex_elements_state. */
+            if (!pitch)
+               pitch = ctx->velems->stream_pitch[i];
             size = vb->buffer.resource->width0;
             elems = size / pitch;
             partial_inbounds = size % pitch;
-- 
2.11.0



More information about the mesa-dev mailing list