OSDN Git Service

Refactor sampleTexel() to use a return value.
authorNicolas Capens <capn@google.com>
Tue, 1 Aug 2017 21:00:36 +0000 (17:00 -0400)
committerNicolas Capens <nicolascapens@google.com>
Wed, 2 Aug 2017 12:33:46 +0000 (12:33 +0000)
We can rely on return value optimization to return Reactor types at the
same cost as passing them by reference.

Change-Id: I9f092bcefd17131a07bef32032c5f2ab98392328
Reviewed-on: https://swiftshader-review.googlesource.com/10569
Tested-by: Nicolas Capens <nicolascapens@google.com>
Reviewed-by: Alexis Hétu <sugoi@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
src/Shader/SamplerCore.cpp
src/Shader/SamplerCore.hpp

index 9c58e70..62f76fa 100644 (file)
@@ -802,24 +802,19 @@ namespace sw
 
                if(state.textureFilter == FILTER_POINT || texelFetch)
                {
-                       sampleTexel(c, uuuu, vvvv, wwww, offset, mipmap, buffer, function);
+                       c = sampleTexel(uuuu, vvvv, wwww, offset, mipmap, buffer, function);
                }
                else
                {
-                       Vector4s c0;
-                       Vector4s c1;
-                       Vector4s c2;
-                       Vector4s c3;
-
                        Short4 uuuu0 = offsetSample(uuuu, mipmap, OFFSET(Mipmap,uHalf), state.addressingModeU == ADDRESSING_WRAP, gather ? 0 : -1, lod);
                        Short4 vvvv0 = offsetSample(vvvv, mipmap, OFFSET(Mipmap,vHalf), state.addressingModeV == ADDRESSING_WRAP, gather ? 0 : -1, lod);
                        Short4 uuuu1 = offsetSample(uuuu, mipmap, OFFSET(Mipmap,uHalf), state.addressingModeU == ADDRESSING_WRAP, gather ? 2 : +1, lod);
                        Short4 vvvv1 = offsetSample(vvvv, mipmap, OFFSET(Mipmap,vHalf), state.addressingModeV == ADDRESSING_WRAP, gather ? 2 : +1, lod);
 
-                       sampleTexel(c0, uuuu0, vvvv0, wwww, offset, mipmap, buffer, function);
-                       sampleTexel(c1, uuuu1, vvvv0, wwww, offset, mipmap, buffer, function);
-                       sampleTexel(c2, uuuu0, vvvv1, wwww, offset, mipmap, buffer, function);
-                       sampleTexel(c3, uuuu1, vvvv1, wwww, offset, mipmap, buffer, function);
+                       Vector4s c0 = sampleTexel(uuuu0, vvvv0, wwww, offset, mipmap, buffer, function);
+                       Vector4s c1 = sampleTexel(uuuu1, vvvv0, wwww, offset, mipmap, buffer, function);
+                       Vector4s c2 = sampleTexel(uuuu0, vvvv1, wwww, offset, mipmap, buffer, function);
+                       Vector4s c3 = sampleTexel(uuuu1, vvvv1, wwww, offset, mipmap, buffer, function);
 
                        if(!gather)   // Blend
                        {
@@ -998,7 +993,7 @@ namespace sw
 
                if(state.textureFilter == FILTER_POINT || texelFetch)
                {
-                       sampleTexel(c_, uuuu, vvvv, wwww, offset, mipmap, buffer, function);
+                       c_ = sampleTexel(uuuu, vvvv, wwww, offset, mipmap, buffer, function);
                }
                else
                {
@@ -1070,7 +1065,7 @@ namespace sw
                                {
                                        for(int k = 0; k < 2; k++)
                                        {
-                                               sampleTexel(c[i][j][k], u[i][j][k], v[i][j][k], s[i][j][k], offset, mipmap, buffer, function);
+                                               c[i][j][k] = sampleTexel(u[i][j][k], v[i][j][k], s[i][j][k], offset, mipmap, buffer, function);
 
                                                if(componentCount >= 1) { if(hasUnsignedTextureComponent(0)) c[i][j][k].x = MulHigh(As<UShort4>(c[i][j][k].x), f[1 - i][1 - j][1 - k]); else c[i][j][k].x = MulHigh(c[i][j][k].x, fs[1 - i][1 - j][1 - k]); }
                                                if(componentCount >= 2) { if(hasUnsignedTextureComponent(1)) c[i][j][k].y = MulHigh(As<UShort4>(c[i][j][k].y), f[1 - i][1 - j][1 - k]); else c[i][j][k].y = MulHigh(c[i][j][k].y, fs[1 - i][1 - j][1 - k]); }
@@ -1274,21 +1269,16 @@ namespace sw
 
                if(state.textureFilter == FILTER_POINT || (function == Fetch))
                {
-                       sampleTexel(c, x0, y0, z0, w, mipmap, buffer, function);
+                       c = sampleTexel(x0, y0, z0, w, mipmap, buffer, function);
                }
                else
                {
-                       Vector4f c0;
-                       Vector4f c1;
-                       Vector4f c2;
-                       Vector4f c3;
-
                        y1 *= pitchP;
 
-                       sampleTexel(c0, x0, y0, z0, w, mipmap, buffer, function);
-                       sampleTexel(c1, x1, y0, z0, w, mipmap, buffer, function);
-                       sampleTexel(c2, x0, y1, z0, w, mipmap, buffer, function);
-                       sampleTexel(c3, x1, y1, z0, w, mipmap, buffer, function);
+                       Vector4f c0 = sampleTexel(x0, y0, z0, w, mipmap, buffer, function);
+                       Vector4f c1 = sampleTexel(x1, y0, z0, w, mipmap, buffer, function);
+                       Vector4f c2 = sampleTexel(x0, y1, z0, w, mipmap, buffer, function);
+                       Vector4f c3 = sampleTexel(x1, y1, z0, w, mipmap, buffer, function);
 
                        if(!gather)   // Blend
                        {
@@ -1341,30 +1331,21 @@ namespace sw
 
                if(state.textureFilter == FILTER_POINT || (function == Fetch))
                {
-                       sampleTexel(c, x0, y0, z0, w, mipmap, buffer, function);
+                       c = sampleTexel(x0, y0, z0, w, mipmap, buffer, function);
                }
                else
                {
-                       Vector4f &c0 = c;
-                       Vector4f c1;
-                       Vector4f c2;
-                       Vector4f c3;
-                       Vector4f c4;
-                       Vector4f c5;
-                       Vector4f c6;
-                       Vector4f c7;
-
                        y1 *= pitchP;
                        z1 *= sliceP;
 
-                       sampleTexel(c0, x0, y0, z0, w, mipmap, buffer, function);
-                       sampleTexel(c1, x1, y0, z0, w, mipmap, buffer, function);
-                       sampleTexel(c2, x0, y1, z0, w, mipmap, buffer, function);
-                       sampleTexel(c3, x1, y1, z0, w, mipmap, buffer, function);
-                       sampleTexel(c4, x0, y0, z1, w, mipmap, buffer, function);
-                       sampleTexel(c5, x1, y0, z1, w, mipmap, buffer, function);
-                       sampleTexel(c6, x0, y1, z1, w, mipmap, buffer, function);
-                       sampleTexel(c7, x1, y1, z1, w, mipmap, buffer, function);
+                       Vector4f c0 = sampleTexel(x0, y0, z0, w, mipmap, buffer, function);
+                       Vector4f c1 = sampleTexel(x1, y0, z0, w, mipmap, buffer, function);
+                       Vector4f c2 = sampleTexel(x0, y1, z0, w, mipmap, buffer, function);
+                       Vector4f c3 = sampleTexel(x1, y1, z0, w, mipmap, buffer, function);
+                       Vector4f c4 = sampleTexel(x0, y0, z1, w, mipmap, buffer, function);
+                       Vector4f c5 = sampleTexel(x1, y0, z1, w, mipmap, buffer, function);
+                       Vector4f c6 = sampleTexel(x0, y1, z1, w, mipmap, buffer, function);
+                       Vector4f c7 = sampleTexel(x1, y1, z1, w, mipmap, buffer, function);
 
                        // Blend first slice
                        if(componentCount >= 1) c0.x = c0.x + fu * (c1.x - c0.x);
@@ -1399,10 +1380,10 @@ namespace sw
                        if(componentCount >= 4) c4.w = c4.w + fv * (c6.w - c4.w);
 
                        // Blend slices
-                       if(componentCount >= 1) c0.x = c0.x + fw * (c4.x - c0.x);
-                       if(componentCount >= 2) c0.y = c0.y + fw * (c4.y - c0.y);
-                       if(componentCount >= 3) c0.z = c0.z + fw * (c4.z - c0.z);
-                       if(componentCount >= 4) c0.w = c0.w + fw * (c4.w - c0.w);
+                       if(componentCount >= 1) c.x = c0.x + fw * (c4.x - c0.x);
+                       if(componentCount >= 2) c.y = c0.y + fw * (c4.y - c0.y);
+                       if(componentCount >= 3) c.z = c0.z + fw * (c4.z - c0.z);
+                       if(componentCount >= 4) c.w = c0.w + fw * (c4.w - c0.w);
                }
        }
 
@@ -1760,8 +1741,10 @@ namespace sw
                }
        }
 
-       void SamplerCore::sampleTexel(Vector4s &c, UInt index[4], Pointer<Byte> buffer[4])
+       Vector4s SamplerCore::sampleTexel(UInt index[4], Pointer<Byte> buffer[4])
        {
+               Vector4s c;
+
                int f0 = state.textureType == TEXTURE_CUBE ? 0 : 0;
                int f1 = state.textureType == TEXTURE_CUBE ? 1 : 0;
                int f2 = state.textureType == TEXTURE_CUBE ? 2 : 0;
@@ -1988,12 +1971,15 @@ namespace sw
                        }
                }
                else ASSERT(false);
+
+               return c;
        }
 
-       void SamplerCore::sampleTexel(Vector4s &c, Short4 &uuuu, Short4 &vvvv, Short4 &wwww, Vector4f &offset, Pointer<Byte> &mipmap, Pointer<Byte> buffer[4], SamplerFunction function)
+       Vector4s SamplerCore::sampleTexel(Short4 &uuuu, Short4 &vvvv, Short4 &wwww, Vector4f &offset, Pointer<Byte> &mipmap, Pointer<Byte> buffer[4], SamplerFunction function)
        {
-               UInt index[4];
+               Vector4s c;
 
+               UInt index[4];
                computeIndices(index, uuuu, vvvv, wwww, offset, mipmap, function);
 
                if(hasYuvFormat())
@@ -2092,14 +2078,17 @@ namespace sw
                }
                else
                {
-                       sampleTexel(c, index, buffer);
+                       return sampleTexel(index, buffer);
                }
+
+               return c;
        }
 
-       void SamplerCore::sampleTexel(Vector4f &c, Int4 &uuuu, Int4 &vvvv, Int4 &wwww, Float4 &z, Pointer<Byte> &mipmap, Pointer<Byte> buffer[4], SamplerFunction function)
+       Vector4f SamplerCore::sampleTexel(Int4 &uuuu, Int4 &vvvv, Int4 &wwww, Float4 &z, Pointer<Byte> &mipmap, Pointer<Byte> buffer[4], SamplerFunction function)
        {
-               UInt index[4];
+               Vector4f c;
 
+               UInt index[4];
                computeIndices(index, uuuu, vvvv, wwww, mipmap, function);
 
                if(hasFloatTexture() || has32bitIntegerTextureComponents())
@@ -2160,8 +2149,7 @@ namespace sw
                {
                        ASSERT(!hasYuvFormat());
 
-                       Vector4s cs;
-                       sampleTexel(cs, index, buffer);
+                       Vector4s cs = sampleTexel(index, buffer);
 
                        bool isInteger = Surface::isNonNormalizedInteger(state.textureFormat);
                        int componentCount = textureComponentCount();
@@ -2191,6 +2179,8 @@ namespace sw
                                }
                        }
                }
+
+               return c;
        }
 
        void SamplerCore::selectMipmap(Pointer<Byte> &texture, Pointer<Byte> buffer[4], Pointer<Byte> &mipmap, Float &lod, Int face[4], bool secondLOD)
index e4529e2..9f8e85b 100644 (file)
@@ -77,10 +77,10 @@ namespace sw
                Short4 applyOffset(Short4 &uvw, Float4 &offset, const Int4 &whd, AddressingMode mode);
                void computeIndices(UInt index[4], Short4 uuuu, Short4 vvvv, Short4 wwww, Vector4f &offset, const Pointer<Byte> &mipmap, SamplerFunction function);
                void computeIndices(UInt index[4], Int4& uuuu, Int4& vvvv, Int4& wwww, const Pointer<Byte> &mipmap, SamplerFunction function);
-               void sampleTexel(Vector4s &c, Short4 &u, Short4 &v, Short4 &s, Vector4f &offset, Pointer<Byte> &mipmap, Pointer<Byte> buffer[4], SamplerFunction function);
-               void sampleTexel(Vector4f &c, Short4 &u, Short4 &v, Short4 &s, Vector4f &offset, Float4 &z, Pointer<Byte> &mipmap, Pointer<Byte> buffer[4], SamplerFunction function);
-               void sampleTexel(Vector4s &c, UInt index[4], Pointer<Byte> buffer[4]);
-               void sampleTexel(Vector4f &c, Int4 &u, Int4 &v, Int4 &s, Float4 &z, Pointer<Byte> &mipmap, Pointer<Byte> buffer[4], SamplerFunction function);
+               Vector4s sampleTexel(Short4 &u, Short4 &v, Short4 &s, Vector4f &offset, Pointer<Byte> &mipmap, Pointer<Byte> buffer[4], SamplerFunction function);
+               Vector4f sampleTexel(Short4 &u, Short4 &v, Short4 &s, Vector4f &offset, Float4 &z, Pointer<Byte> &mipmap, Pointer<Byte> buffer[4], SamplerFunction function);
+               Vector4s sampleTexel(UInt index[4], Pointer<Byte> buffer[4]);
+               Vector4f sampleTexel(Int4 &u, Int4 &v, Int4 &s, Float4 &z, Pointer<Byte> &mipmap, Pointer<Byte> buffer[4], SamplerFunction function);
                void selectMipmap(Pointer<Byte> &texture, Pointer<Byte> buffer[4], Pointer<Byte> &mipmap, Float &lod, Int face[4], bool secondLOD);
                Short4 address(Float4 &uw, AddressingMode addressingMode, Pointer<Byte>& mipmap);
                void address(Float4 &uw, Int4& xyz0, Int4& xyz1, Float4& f, Pointer<Byte>& mipmap, Float4 &texOffset, Int4 &filter, int whd, AddressingMode addressingMode, SamplerFunction function);