[Mesa-stable] [PATCH] swr/rast: Fix index buffer overfetch issue for non-indexed draws

George Kyriazis george.kyriazis at intel.com
Thu Feb 22 15:14:07 UTC 2018


Populate pLastIndex, even for the non-indexed case.  A zero pLastIndex
can cause the index offsets inside the fetcher to have non-sensical values
that can be either very large positive or very large negative numbers.

cc: mesa-stable at lists.freedesktop.org
---
 src/gallium/drivers/swr/rasterizer/core/frontend.cpp    | 15 +++++++++++++++
 src/gallium/drivers/swr/rasterizer/jitter/fetch_jit.cpp |  2 +-
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/src/gallium/drivers/swr/rasterizer/core/frontend.cpp b/src/gallium/drivers/swr/rasterizer/core/frontend.cpp
index 9600f78..ce6cb68 100644
--- a/src/gallium/drivers/swr/rasterizer/core/frontend.cpp
+++ b/src/gallium/drivers/swr/rasterizer/core/frontend.cpp
@@ -1724,6 +1724,21 @@ void ProcessDraw(
 
             if (i < endVertex)
             {
+                if (!IsIndexedT::value)
+                {
+                    fetchInfo_lo.pLastIndex = fetchInfo_lo.pIndices;
+                    uint32_t offset;
+                    offset = std::min(endVertex-i, (uint32_t) KNOB_SIMD16_WIDTH);
+#if USE_SIMD16_SHADERS
+                    fetchInfo_lo.pLastIndex += offset;
+#else
+                    fetchInfo_lo.pLastIndex += std::min(offset, (uint32_t) KNOB_SIMD_WIDTH);
+                    uint32_t offset2 = std::min(offset, (uint32_t) KNOB_SIMD16_WIDTH)-KNOB_SIMD_WIDTH;
+                    assert(offset >= 0);
+                    fetchInfo_hi.pLastIndex = fetchInfo_hi.pIndices;
+                    fetchInfo_hi.pLastIndex += offset2;
+#endif
+                }
                 // 1. Execute FS/VS for a single SIMD.
                 AR_BEGIN(FEFetchShader, pDC->drawId);
 #if USE_SIMD16_SHADERS
diff --git a/src/gallium/drivers/swr/rasterizer/jitter/fetch_jit.cpp b/src/gallium/drivers/swr/rasterizer/jitter/fetch_jit.cpp
index 091db24..0bd2935 100644
--- a/src/gallium/drivers/swr/rasterizer/jitter/fetch_jit.cpp
+++ b/src/gallium/drivers/swr/rasterizer/jitter/fetch_jit.cpp
@@ -1872,7 +1872,7 @@ Value* FetchJit::GetSimdValid32bitIndices(Value* pIndices, Value* pLastIndex)
     //     vIndexMask    -1-1-1-1 0 0 0 0 : offsets < max pass
     //     vLoadedIndices 0 1 2 3 0 0 0 0 : offsets >= max masked to 0
     Value* vMaxIndex = VBROADCAST(numIndicesLeft);
-    Value* vIndexMask = VPCMPGTD(vMaxIndex,vIndexOffsets);
+    Value* vIndexMask = VPCMPGTD(vMaxIndex, vIndexOffsets);
 
     // VMASKLOAD takes an *i8 src pointer
     pIndices = BITCAST(pIndices,PointerType::get(mInt8Ty,0));
-- 
2.7.4



More information about the mesa-stable mailing list