swr: [rasterizer core/jitter] fix alpha test bug
authorTim Rowley <timothy.o.rowley@intel.com>
Thu, 3 Nov 2016 18:33:13 +0000 (13:33 -0500)
committerTim Rowley <timothy.o.rowley@intel.com>
Mon, 14 Nov 2016 15:02:36 +0000 (09:02 -0600)
Alpha from render target 0 should always be used for alpha test for all
render targets, according to GL and DX9 specs. Previously we were using
alpha from the current render target.

Reviewed-by: Bruce Cherniak <bruce.cherniak@intel.com>
src/gallium/drivers/swr/rasterizer/core/backend.h
src/gallium/drivers/swr/rasterizer/core/state.h
src/gallium/drivers/swr/rasterizer/jitter/blend_jit.cpp

index dc0be90..706b372 100644 (file)
@@ -714,6 +714,7 @@ INLINE void OutputMerger(SWR_PS_CONTEXT &psContext, uint8_t* (&pColorBase)[SWR_N
                 pBlendState,
                 psContext.shaded[rt],
                 psContext.shaded[1],
+                psContext.shaded[0].w,
                 sample,
                 pColorSample,
                 blendOut,
@@ -787,6 +788,7 @@ INLINE void OutputMerger(SWR_PS_CONTEXT &psContext, uint8_t* (&pColorBase)[SWR_N
                 pBlendState,
                 psContext.shaded[rt],
                 psContext.shaded[1],
+                psContext.shaded[0].w,
                 sample,
                 reinterpret_cast<uint8_t *>(&blendSrc),
                 blendOut,
index 5ee12e8..24927cd 100644 (file)
@@ -805,9 +805,13 @@ typedef void(__cdecl *PFN_CS_FUNC)(HANDLE hPrivateData, SWR_CS_CONTEXT* pCsConte
 typedef void(__cdecl *PFN_SO_FUNC)(SWR_STREAMOUT_CONTEXT& soContext);
 typedef void(__cdecl *PFN_PIXEL_KERNEL)(HANDLE hPrivateData, SWR_PS_CONTEXT *pContext);
 typedef void(__cdecl *PFN_CPIXEL_KERNEL)(HANDLE hPrivateData, SWR_PS_CONTEXT *pContext);
-typedef void(__cdecl *PFN_BLEND_JIT_FUNC)(const SWR_BLEND_STATE*, simdvector&, simdvector&, uint32_t, uint8_t*, simdvector&, simdscalari*, simdscalari*);
+typedef void(__cdecl *PFN_BLEND_JIT_FUNC)(const SWR_BLEND_STATE*, 
+    simdvector& vSrc, simdvector& vSrc1, simdscalar& vSrc0Alpha, uint32_t sample, 
+    uint8_t* pDst, simdvector& vResult, simdscalari* vOMask, simdscalari* vCoverageMask);
 typedef simdscalar(*PFN_QUANTIZE_DEPTH)(simdscalar);
 
+
+
 //////////////////////////////////////////////////////////////////////////
 /// FRONTEND_STATE
 /////////////////////////////////////////////////////////////////////////
index 46ea495..b5b21c0 100644 (file)
@@ -443,10 +443,13 @@ struct BlendJit : public Builder
         }
     }
 
-    void AlphaTest(const BLEND_COMPILE_STATE& state, Value* pBlendState, Value* pAlpha, Value* ppMask)
+    void AlphaTest(const BLEND_COMPILE_STATE& state, Value* pBlendState, Value* ppAlpha, Value* ppMask)
     {
         // load uint32_t reference
         Value* pRef = VBROADCAST(LOAD(pBlendState, { 0, SWR_BLEND_STATE_alphaTestReference }));
+        
+        // load alpha
+        Value* pAlpha = LOAD(ppAlpha);
 
         Value* pTest = nullptr;
         if (state.alphaTestFormat == ALPHA_TEST_UNORM8)
@@ -523,6 +526,7 @@ struct BlendJit : public Builder
             PointerType::get(Gen_SWR_BLEND_STATE(JM()), 0), // SWR_BLEND_STATE*
             PointerType::get(mSimdFP32Ty, 0),               // simdvector& src
             PointerType::get(mSimdFP32Ty, 0),               // simdvector& src1
+            PointerType::get(mSimdFP32Ty, 0),               // src0alpha
             Type::getInt32Ty(JM()->mContext),               // sampleNum
             PointerType::get(mSimdFP32Ty, 0),               // uint8_t* pDst
             PointerType::get(mSimdFP32Ty, 0),               // simdvector& result
@@ -545,6 +549,8 @@ struct BlendJit : public Builder
         pSrc->setName("src");
         Value* pSrc1 = &*argitr++;
         pSrc1->setName("src1");
+        Value* pSrc0Alpha = &*argitr++;
+        pSrc0Alpha->setName("src0alpha");
         Value* sampleNum = &*argitr++;
         sampleNum->setName("sampleNum");
         Value* pDst = &*argitr++;
@@ -588,7 +594,7 @@ struct BlendJit : public Builder
         // alpha test
         if (state.desc.alphaTestEnable)
         {
-            AlphaTest(state, pBlendState, src[3], ppMask);
+            AlphaTest(state, pBlendState, pSrc0Alpha, ppMask);
         }
 
         // color blend