OSDN Git Service

Eliminate unnecessary inverse masks.
[android-x86/external-swiftshader.git] / src / Shader / PixelRoutine.cpp
index 41472a4..44fafd3 100644 (file)
@@ -18,7 +18,6 @@
 #include "QuadRasterizer.hpp"
 #include "Surface.hpp"
 #include "Primitive.hpp"
-#include "CPUID.hpp"
 #include "SamplerCore.hpp"
 #include "Constants.hpp"
 #include "Debug.hpp"
@@ -321,7 +320,7 @@ namespace sw
                        buffer += q * *Pointer<Int>(data + OFFSET(DrawData,stencilSliceB));
                }
 
-               Byte8 value = As<Byte8>(Long1(*Pointer<UInt>(buffer)));
+               Byte8 value = *Pointer<Byte8>(buffer);
                Byte8 valueCCW = value;
 
                if(!state.noStencilMask)
@@ -355,10 +354,10 @@ namespace sw
                switch(stencilCompareMode)
                {
                case STENCIL_ALWAYS:
-                       value = Byte8(0xFFFFFFFFFFFFFFFF);
+                       value = Byte8(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF);
                        break;
                case STENCIL_NEVER:
-                       value = Byte8(0x0000000000000000);
+                       value = Byte8(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
                        break;
                case STENCIL_LESS:                      // a < b ~ b > a
                        value += Byte8(0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80);
@@ -369,7 +368,7 @@ namespace sw
                        break;
                case STENCIL_NOTEQUAL:          // a != b ~ !(a == b)
                        value = CmpEQ(value, *Pointer<Byte8>(data + OFFSET(DrawData,stencil[CCW].referenceMaskedQ)));
-                       value ^= Byte8(0xFFFFFFFFFFFFFFFF);
+                       value ^= Byte8(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF);
                        break;
                case STENCIL_LESSEQUAL: // a <= b ~ (b > a) || (a == b)
                        equal = value;
@@ -387,7 +386,7 @@ namespace sw
                case STENCIL_GREATEREQUAL:      // a >= b ~ !(a < b) ~ !(b > a)
                        value += Byte8(0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80);
                        value = CmpGT(As<SByte8>(value), *Pointer<SByte8>(data + OFFSET(DrawData,stencil[CCW].referenceMaskedSignedQ)));
-                       value ^= Byte8(0xFFFFFFFFFFFFFFFF);
+                       value ^= Byte8(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF);
                        break;
                default:
                        ASSERT(false);
@@ -763,7 +762,7 @@ namespace sw
                        buffer += q * *Pointer<Int>(data + OFFSET(DrawData,stencilSliceB));
                }
 
-               Byte8 bufferValue = As<Byte8>(Long1(*Pointer<UInt>(buffer)));
+               Byte8 bufferValue = *Pointer<Byte8>(buffer);
 
                Byte8 newValue;
                stencilOperation(newValue, bufferValue, state.stencilPassOperation, state.stencilZFailOperation, state.stencilFailOperation, false, zMask, sMask);
@@ -799,7 +798,7 @@ namespace sw
                bufferValue &= *Pointer<Byte8>(constants + OFFSET(Constants,invMaskB4Q) + 8 * cMask);
                newValue |= bufferValue;
 
-               *Pointer<UInt>(buffer) = UInt(As<Long>(newValue));
+               *Pointer<Byte4>(buffer) = Byte4(newValue);
        }
 
        void PixelRoutine::stencilOperation(Byte8 &newValue, Byte8 &bufferValue, StencilOperation stencilPassOperation, StencilOperation stencilZFailOperation, StencilOperation stencilFailOperation, bool CCW, Int &zMask, Int &sMask)
@@ -843,7 +842,7 @@ namespace sw
                        output = bufferValue;
                        break;
                case OPERATION_ZERO:
-                       output = Byte8(0x0000000000000000);
+                       output = Byte8(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
                        break;
                case OPERATION_REPLACE:
                        output = *Pointer<Byte8>(data + OFFSET(DrawData,stencil[CCW].referenceQ));
@@ -855,7 +854,7 @@ namespace sw
                        output = SubSat(bufferValue, Byte8(1, 1, 1, 1, 1, 1, 1, 1));
                        break;
                case OPERATION_INVERT:
-                       output = bufferValue ^ Byte8(0xFFFFFFFFFFFFFFFF);
+                       output = bufferValue ^ Byte8(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF);
                        break;
                case OPERATION_INCR:
                        output = bufferValue + Byte8(1, 1, 1, 1, 1, 1, 1, 1);
@@ -868,7 +867,7 @@ namespace sw
                }
        }
 
-       void PixelRoutine::blendFactor(const Vector4s &blendFactor, const Vector4s &current, const Vector4s &pixel, BlendFactor blendFactorActive)
+       void PixelRoutine::blendFactor(Vector4s &blendFactor, const Vector4s &current, const Vector4s &pixel, BlendFactor blendFactorActive)
        {
                switch(blendFactorActive)
                {
@@ -949,7 +948,7 @@ namespace sw
                }
        }
 
-       void PixelRoutine::blendFactorAlpha(const Vector4s &blendFactor, const Vector4s &current, const Vector4s &pixel, BlendFactor blendFactorAlphaActive)
+       void PixelRoutine::blendFactorAlpha(Vector4s &blendFactor, const Vector4s &current, const Vector4s &pixel, BlendFactor blendFactorAlphaActive)
        {
                switch(blendFactorAlphaActive)
                {
@@ -1574,7 +1573,7 @@ namespace sw
                                {
                                        Int masked = value;
                                        c01 &= *Pointer<Int>(constants + OFFSET(Constants,mask565Q[bgraWriteMask & 0x7][0]));
-                                       masked &= *Pointer<Int>(constants + OFFSET(Constants,invMask565Q[bgraWriteMask & 0x7][0]));
+                                       masked &= *Pointer<Int>(constants + OFFSET(Constants,mask565Q[~bgraWriteMask & 0x7][0]));
                                        c01 |= masked;
                                }
 
@@ -1592,7 +1591,7 @@ namespace sw
                                {
                                        Int masked = value;
                                        c23 &= *Pointer<Int>(constants + OFFSET(Constants,mask565Q[bgraWriteMask & 0x7][0]));
-                                       masked &= *Pointer<Int>(constants + OFFSET(Constants,invMask565Q[bgraWriteMask & 0x7][0]));
+                                       masked &= *Pointer<Int>(constants + OFFSET(Constants,mask565Q[~bgraWriteMask & 0x7][0]));
                                        c23 |= masked;
                                }
 
@@ -1792,7 +1791,7 @@ namespace sw
                                {
                                        Short4 masked = value;
                                        current.x &= *Pointer<Short4>(constants + OFFSET(Constants,maskW01Q[rgbaWriteMask & 0x3][0]));
-                                       masked &= *Pointer<Short4>(constants + OFFSET(Constants,invMaskW01Q[rgbaWriteMask & 0x3][0]));
+                                       masked &= *Pointer<Short4>(constants + OFFSET(Constants,maskW01Q[~rgbaWriteMask & 0x3][0]));
                                        current.x |= masked;
                                }
 
@@ -1809,7 +1808,7 @@ namespace sw
                                {
                                        Short4 masked = value;
                                        current.y &= *Pointer<Short4>(constants + OFFSET(Constants,maskW01Q[rgbaWriteMask & 0x3][0]));
-                                       masked &= *Pointer<Short4>(constants + OFFSET(Constants,invMaskW01Q[rgbaWriteMask & 0x3][0]));
+                                       masked &= *Pointer<Short4>(constants + OFFSET(Constants,maskW01Q[~rgbaWriteMask & 0x3][0]));
                                        current.y |= masked;
                                }
 
@@ -1899,7 +1898,7 @@ namespace sw
                }
        }
 
-       void PixelRoutine::blendFactor(const Vector4f &blendFactor, const Vector4f &oC, const Vector4f &pixel, BlendFactor blendFactorActive)
+       void PixelRoutine::blendFactor(Vector4f &blendFactor, const Vector4f &oC, const Vector4f &pixel, BlendFactor blendFactorActive)
        {
                switch(blendFactorActive)
                {
@@ -1970,7 +1969,7 @@ namespace sw
                }
        }
 
-       void PixelRoutine::blendFactorAlpha(const Vector4f &blendFactor, const Vector4f &oC, const Vector4f &pixel, BlendFactor blendFactorAlphaActive)
+       void PixelRoutine::blendFactorAlpha(Vector4f &blendFactor, const Vector4f &oC, const Vector4f &pixel, BlendFactor blendFactorAlphaActive)
        {
                switch(blendFactorAlphaActive)
                {
@@ -2390,7 +2389,7 @@ namespace sw
                        {
                                Float4 masked = value;
                                oC.x = As<Float4>(As<Int4>(oC.x) & *Pointer<Int4>(constants + OFFSET(Constants,maskD01X[rgbaWriteMask & 0x3][0])));
-                               masked = As<Float4>(As<Int4>(masked) & *Pointer<Int4>(constants + OFFSET(Constants,invMaskD01X[rgbaWriteMask & 0x3][0])));
+                               masked = As<Float4>(As<Int4>(masked) & *Pointer<Int4>(constants + OFFSET(Constants,maskD01X[~rgbaWriteMask & 0x3][0])));
                                oC.x = As<Float4>(As<Int4>(oC.x) | As<Int4>(masked));
                        }
 
@@ -2409,7 +2408,7 @@ namespace sw
 
                                masked = value;
                                oC.y = As<Float4>(As<Int4>(oC.y) & *Pointer<Int4>(constants + OFFSET(Constants,maskD01X[rgbaWriteMask & 0x3][0])));
-                               masked = As<Float4>(As<Int4>(masked) & *Pointer<Int4>(constants + OFFSET(Constants,invMaskD01X[rgbaWriteMask & 0x3][0])));
+                               masked = As<Float4>(As<Int4>(masked) & *Pointer<Int4>(constants + OFFSET(Constants,maskD01X[~rgbaWriteMask & 0x3][0])));
                                oC.y = As<Float4>(As<Int4>(oC.y) | As<Int4>(masked));
                        }
 
@@ -2544,7 +2543,7 @@ namespace sw
                        }
 
                        {
-                               value = (state.targetFormat[index] == FORMAT_X32B32G32R32F) ? Float4(1.0f) : *Pointer<Float4>(buffer + 16, 16);
+                               value = *Pointer<Float4>(buffer + 16, 16);
 
                                if(rgbaWriteMask != 0x0000000F)
                                {