swr/rast: Faster frustum prim culling
authorGeorge Kyriazis <george.kyriazis@intel.com>
Wed, 7 Feb 2018 18:24:23 +0000 (12:24 -0600)
committerGeorge Kyriazis <george.kyriazis@intel.com>
Wed, 28 Feb 2018 17:42:46 +0000 (11:42 -0600)
Fix clipper validMask setting. We don't need to run frustum rejected
primitives through the clipper.  Perform frustum culling with only
frustum clip codes. Guardband clip codes cannot be used because they
overlap frustum codes.

Reviewed-By: Bruce Cherniak <bruce.cherniak@intel.com>
src/gallium/drivers/swr/rasterizer/core/clip.h

index 8d2590a49816e66913310a9e42c43c6afddf2691..0f8399c742c6169d637a9daa2df2c0b653ac06cd 100644 (file)
@@ -60,6 +60,7 @@ enum SWR_CLIPCODES
 };
 
 #define GUARDBAND_CLIP_MASK (FRUSTUM_NEAR|FRUSTUM_FAR|GUARDBAND_LEFT|GUARDBAND_TOP|GUARDBAND_RIGHT|GUARDBAND_BOTTOM|NEGW)
+#define FRUSTUM_CLIP_MASK (FRUSTUM_NEAR|FRUSTUM_FAR|FRUSTUM_LEFT|FRUSTUM_RIGHT|FRUSTUM_TOP|FRUSTUM_BOTTOM)
 
 template<typename SIMD_T>
 void ComputeClipCodes(const API_STATE &state, const Vec4<SIMD_T> &vertex, Float<SIMD_T> &clipCodes, Integer<SIMD_T> const &viewportIndexes)
@@ -708,15 +709,18 @@ public:
             primMask &= ~ComputeUserClipCullMask(pa, prim);
         }
 
-        // cull prims outside view frustum
         Float<SIMD_T> clipIntersection = ComputeClipCodeIntersection();
+        // Mask out non-frustum codes
+        clipIntersection = SIMD_T::and_ps(clipIntersection, SIMD_T::castsi_ps(SIMD_T::set1_epi32(FRUSTUM_CLIP_MASK)));
+
+        // cull prims outside view frustum
         int validMask = primMask & SimdHelper<SIMD_T>::cmpeq_ps_mask(clipIntersection, SIMD_T::setzero_ps());
 
         // skip clipping for points
         uint32_t clipMask = 0;
         if (NumVertsPerPrim != 1)
         {
-            clipMask = primMask & ComputeClipMask();
+            clipMask = validMask & ComputeClipMask();
         }
 
         AR_EVENT(ClipInfoEvent(numInvoc, validMask, clipMask));
@@ -726,7 +730,7 @@ public:
             RDTSC_BEGIN(FEGuardbandClip, pa.pDC->drawId);
             // we have to clip tris, execute the clipper, which will also
             // call the binner
-            ClipSimd(prim, SIMD_T::vmask_ps(primMask), SIMD_T::vmask_ps(clipMask), pa, primId, viewportIdx, rtIdx);
+            ClipSimd(prim, SIMD_T::vmask_ps(validMask), SIMD_T::vmask_ps(clipMask), pa, primId, viewportIdx, rtIdx);
             RDTSC_END(FEGuardbandClip, 1);
         }
         else if (validMask)