swr: [rasterizer core] track guardbands per viewport rect
authorTim Rowley <timothy.o.rowley@intel.com>
Thu, 18 Aug 2016 18:12:48 +0000 (13:12 -0500)
committerTim Rowley <timothy.o.rowley@intel.com>
Mon, 29 Aug 2016 17:41:51 +0000 (12:41 -0500)
Signed-off-by: Tim Rowley <timothy.o.rowley@intel.com>
src/gallium/drivers/swr/rasterizer/core/api.cpp
src/gallium/drivers/swr/rasterizer/core/clip.h
src/gallium/drivers/swr/rasterizer/core/context.h

index 5369c21250a406e0b6c92d3c455f9c1d6719a4c3..599d1f4ed9d7d831ccc898357965720915e79a84 100644 (file)
@@ -639,13 +639,18 @@ void SwrSetBlendFunc(
 }
 
 // update guardband multipliers for the viewport
-void updateGuardband(API_STATE *pState)
+void updateGuardbands(API_STATE *pState)
 {
-    // guardband center is viewport center
-    pState->gbState.left    = KNOB_GUARDBAND_WIDTH  / pState->vp[0].width;
-    pState->gbState.right   = KNOB_GUARDBAND_WIDTH  / pState->vp[0].width;
-    pState->gbState.top     = KNOB_GUARDBAND_HEIGHT / pState->vp[0].height;
-    pState->gbState.bottom  = KNOB_GUARDBAND_HEIGHT / pState->vp[0].height;
+    uint32_t numGbs = pState->gsState.emitsRenderTargetArrayIndex ? KNOB_NUM_VIEWPORTS_SCISSORS : 1;
+
+    for(uint32_t i = 0; i < numGbs; ++i)
+    {
+        // guardband center is viewport center
+        pState->gbState.left[i] = KNOB_GUARDBAND_WIDTH / pState->vp[i].width;
+        pState->gbState.right[i] = KNOB_GUARDBAND_WIDTH / pState->vp[i].width;
+        pState->gbState.top[i] = KNOB_GUARDBAND_HEIGHT / pState->vp[i].height;
+        pState->gbState.bottom[i] = KNOB_GUARDBAND_HEIGHT / pState->vp[i].height;
+    }
 }
 
 void SwrSetRastState(
@@ -709,7 +714,7 @@ void SwrSetViewports(
         }
     }
 
-    updateGuardband(pState);
+    updateGuardbands(pState);
 }
 
 void SwrSetScissorRects(
index 2736992b579b19a60a473b5dce8b6662c1a694d7..2f3ce85442af4958f6fb03f03104dc1623d26520 100644 (file)
@@ -63,7 +63,7 @@ void Clip(const float *pTriangle, const float *pAttribs, int numAttribs, float *
           int *numVerts, float *pOutAttribs);
 
 INLINE
-void ComputeClipCodes(DRIVER_TYPE type, const API_STATE& state, const simdvector& vertex, simdscalar& clipCodes)
+void ComputeClipCodes(DRIVER_TYPE type, const API_STATE& state, const simdvector& vertex, simdscalar& clipCodes, simdscalari viewportIndexes)
 {
     clipCodes = _simd_setzero_ps();
 
@@ -110,22 +110,22 @@ void ComputeClipCodes(DRIVER_TYPE type, const API_STATE& state, const simdvector
     clipCodes = _simd_or_ps(clipCodes, _simd_and_ps(vRes, _simd_castsi_ps(_simd_set1_epi32(NEGW))));
 
     // GUARDBAND_LEFT
-    simdscalar gbMult = _simd_mul_ps(vNegW, _simd_set1_ps(state.gbState.left));
+    simdscalar gbMult = _simd_mul_ps(vNegW, _simd_i32gather_ps(&state.gbState.left[0], viewportIndexes, 4));
     vRes = _simd_cmplt_ps(vertex.x, gbMult);
     clipCodes = _simd_or_ps(clipCodes, _simd_and_ps(vRes, _simd_castsi_ps(_simd_set1_epi32(GUARDBAND_LEFT))));
 
     // GUARDBAND_TOP
-    gbMult = _simd_mul_ps(vNegW, _simd_set1_ps(state.gbState.top));
+    gbMult = _simd_mul_ps(vNegW, _simd_i32gather_ps(&state.gbState.top[0], viewportIndexes, 4));
     vRes = _simd_cmplt_ps(vertex.y, gbMult);
     clipCodes = _simd_or_ps(clipCodes, _simd_and_ps(vRes, _simd_castsi_ps(_simd_set1_epi32(GUARDBAND_TOP))));
 
     // GUARDBAND_RIGHT
-    gbMult = _simd_mul_ps(vertex.w, _simd_set1_ps(state.gbState.right));
+    gbMult = _simd_mul_ps(vertex.w, _simd_i32gather_ps(&state.gbState.right[0], viewportIndexes, 4));
     vRes = _simd_cmpgt_ps(vertex.x, gbMult);
     clipCodes = _simd_or_ps(clipCodes, _simd_and_ps(vRes, _simd_castsi_ps(_simd_set1_epi32(GUARDBAND_RIGHT))));
 
     // GUARDBAND_BOTTOM
-    gbMult = _simd_mul_ps(vertex.w, _simd_set1_ps(state.gbState.bottom));
+    gbMult = _simd_mul_ps(vertex.w, _simd_i32gather_ps(&state.gbState.bottom[0], viewportIndexes, 4));
     vRes = _simd_cmpgt_ps(vertex.y, gbMult);
     clipCodes = _simd_or_ps(clipCodes, _simd_and_ps(vRes, _simd_castsi_ps(_simd_set1_epi32(GUARDBAND_BOTTOM))));
 }
@@ -140,11 +140,11 @@ public:
         static_assert(NumVertsPerPrim >= 1 && NumVertsPerPrim <= 3, "Invalid NumVertsPerPrim");
     }
 
-    void ComputeClipCodes(simdvector vertex[])
+    void ComputeClipCodes(simdvector vertex[], simdscalari viewportIndexes)
     {
         for (uint32_t i = 0; i < NumVertsPerPrim; ++i)
         {
-            ::ComputeClipCodes(this->driverType, this->state, vertex[i], this->clipCodes[i]);
+            ::ComputeClipCodes(this->driverType, this->state, vertex[i], this->clipCodes[i], viewportIndexes);
         }
     }
 
@@ -524,7 +524,7 @@ public:
         uint32_t numInvoc = _mm_popcnt_u32(primMask);
         UPDATE_STAT_FE(CInvocations, numInvoc);
 
-        ComputeClipCodes(prim);
+        ComputeClipCodes(prim, viewportIdx);
 
         // cull prims with NAN coords
         primMask &= ~ComputeNaNMask(prim);
index c311cb8cab0e52f2a16c1931984e3441d69eab8b..0848264f8fadf9d35d4071b32d30eb96fa5f0aab 100644 (file)
@@ -209,9 +209,12 @@ struct FE_WORK
     } desc;
 };
 
-struct GUARDBAND
+struct GUARDBANDS
 {
-    float left, right, top, bottom;
+    float left[KNOB_NUM_VIEWPORTS_SCISSORS];
+    float right[KNOB_NUM_VIEWPORTS_SCISSORS];
+    float top[KNOB_NUM_VIEWPORTS_SCISSORS];
+    float bottom[KNOB_NUM_VIEWPORTS_SCISSORS];
 };
 
 struct PA_STATE;
@@ -269,7 +272,7 @@ OSALIGNLINE(struct) API_STATE
     // floating point multisample offsets
     float samplePos[SWR_MAX_NUM_MULTISAMPLES * 2];
 
-    GUARDBAND               gbState;
+    GUARDBANDS               gbState;
 
     SWR_VIEWPORT            vp[KNOB_NUM_VIEWPORTS_SCISSORS];
     SWR_VIEWPORT_MATRICES   vpMatrices;