OSDN Git Service

Fix RGB565 rounding.
authorNicolas Capens <capn@google.com>
Tue, 22 Sep 2015 13:53:45 +0000 (09:53 -0400)
committerNicolas Capens <capn@google.com>
Tue, 22 Sep 2015 17:04:48 +0000 (17:04 +0000)
Bug 20891368

Change-Id: Icc0957db55cf82e42c0ccb2c8881332f71f52f5f
Reviewed-on: https://swiftshader-review.googlesource.com/3993
Tested-by: Nicolas Capens <capn@google.com>
Reviewed-by: Alexis Hétu <sugoi@google.com>
Reviewed-by: Nicolas Capens <capn@google.com>
src/Shader/PixelPipeline.cpp
src/Shader/PixelRoutine.cpp

index 8a38bed..c89d058 100644 (file)
@@ -1,26 +1,26 @@
-// SwiftShader Software Renderer\r
-//\r
-// Copyright(c) 2015 Google Inc.\r
-//\r
-// All rights reserved. No part of this software may be copied, distributed, transmitted,\r
-// transcribed, stored in a retrieval system, translated into any human or computer\r
-// language by any means, or disclosed to third parties without the explicit written\r
-// agreement of Google Inc. Without such an agreement, no rights or licenses, express\r
-// or implied, including but not limited to any patent rights, are granted to you.\r
-//\r
-\r
-#include "PixelPipeline.hpp"\r
-#include "Renderer.hpp"\r
-#include "SamplerCore.hpp"\r
-\r
-namespace sw\r
-{\r
-       extern bool postBlendSRGB;\r
-\r
-       void PixelPipeline::setBuiltins(PixelRoutine::Registers &rBase, Int &x, Int &y, Float4(&z)[4], Float4 &w)\r
-       {\r
-               Registers& r = *static_cast<Registers*>(&rBase);\r
-\r
+// SwiftShader Software Renderer
+//
+// Copyright(c) 2015 Google Inc.
+//
+// All rights reserved. No part of this software may be copied, distributed, transmitted,
+// transcribed, stored in a retrieval system, translated into any human or computer
+// language by any means, or disclosed to third parties without the explicit written
+// agreement of Google Inc. Without such an agreement, no rights or licenses, express
+// or implied, including but not limited to any patent rights, are granted to you.
+//
+
+#include "PixelPipeline.hpp"
+#include "Renderer.hpp"
+#include "SamplerCore.hpp"
+
+namespace sw
+{
+       extern bool postBlendSRGB;
+
+       void PixelPipeline::setBuiltins(PixelRoutine::Registers &rBase, Int &x, Int &y, Float4(&z)[4], Float4 &w)
+       {
+               Registers& r = *static_cast<Registers*>(&rBase);
+
                if(state.color[0].component & 0x1) r.diffuse.x = convertFixed12(r.vf[0].x); else r.diffuse.x = Short4(0x1000);
                if(state.color[0].component & 0x2) r.diffuse.y = convertFixed12(r.vf[0].y); else r.diffuse.y = Short4(0x1000);
                if(state.color[0].component & 0x4) r.diffuse.z = convertFixed12(r.vf[0].z); else r.diffuse.z = Short4(0x1000);
@@ -29,11 +29,11 @@ namespace sw
                if(state.color[1].component & 0x1) r.specular.x = convertFixed12(r.vf[1].x); else r.specular.x = Short4(0x0000, 0x0000, 0x0000, 0x0000);
                if(state.color[1].component & 0x2) r.specular.y = convertFixed12(r.vf[1].y); else r.specular.y = Short4(0x0000, 0x0000, 0x0000, 0x0000);
                if(state.color[1].component & 0x4) r.specular.z = convertFixed12(r.vf[1].z); else r.specular.z = Short4(0x0000, 0x0000, 0x0000, 0x0000);
-               if(state.color[1].component & 0x8) r.specular.w = convertFixed12(r.vf[1].w); else r.specular.w = Short4(0x0000, 0x0000, 0x0000, 0x0000);\r
-       }\r
-\r
+               if(state.color[1].component & 0x8) r.specular.w = convertFixed12(r.vf[1].w); else r.specular.w = Short4(0x0000, 0x0000, 0x0000, 0x0000);
+       }
+
        void PixelPipeline::fixedFunction(Registers& r)
-       {\r
+       {
                r.current = r.diffuse;
                Vector4s temp(0x0000, 0x0000, 0x0000, 0x0000);
 
@@ -54,9 +54,9 @@ namespace sw
                        blendTexture(r, temp, texture, stage);
                }
 
-               specularPixel(r.current, r.specular);\r
-       }\r
-\r
+               specularPixel(r.current, r.specular);
+       }
+
        void PixelPipeline::applyShader(PixelRoutine::Registers &rBase, Int cMask[4])
        {
                Registers& r = *static_cast<Registers*>(&rBase);
@@ -257,12 +257,12 @@ namespace sw
                                }
                        }
                }
-       }\r
-\r
-       Bool PixelPipeline::alphaTest(PixelRoutine::Registers &rBase, Int cMask[4])\r
-       {\r
-               Registers& r = *static_cast<Registers*>(&rBase);\r
-\r
+       }
+
+       Bool PixelPipeline::alphaTest(PixelRoutine::Registers &rBase, Int cMask[4])
+       {
+               Registers& r = *static_cast<Registers*>(&rBase);
+
                r.current.x = Min(r.current.x, Short4(0x0FFF, 0x0FFF, 0x0FFF, 0x0FFF)); r.current.x = Max(r.current.x, Short4(0x0000, 0x0000, 0x0000, 0x0000));
                r.current.y = Min(r.current.y, Short4(0x0FFF, 0x0FFF, 0x0FFF, 0x0FFF)); r.current.y = Max(r.current.y, Short4(0x0000, 0x0000, 0x0000, 0x0000));
                r.current.z = Min(r.current.z, Short4(0x0FFF, 0x0FFF, 0x0FFF, 0x0FFF)); r.current.z = Max(r.current.z, Short4(0x0000, 0x0000, 0x0000, 0x0000));
@@ -299,13 +299,13 @@ namespace sw
                        pass = pass | cMask[q];
                }
 
-               return pass != 0x0;\r
-       }\r
-\r
-       void PixelPipeline::rasterOperation(PixelRoutine::Registers &rBase, Float4 &fog, Pointer<Byte> cBuffer[4], Int &x, Int sMask[4], Int zMask[4], Int cMask[4])\r
-       {\r
-               Registers& r = *static_cast<Registers*>(&rBase);\r
-\r
+               return pass != 0x0;
+       }
+
+       void PixelPipeline::rasterOperation(PixelRoutine::Registers &rBase, Float4 &fog, Pointer<Byte> cBuffer[4], Int &x, Int sMask[4], Int zMask[4], Int cMask[4])
+       {
+               Registers& r = *static_cast<Registers*>(&rBase);
+
                if(!state.colorWriteActive(0))
                {
                        return;
@@ -377,9 +377,9 @@ namespace sw
                        break;
                default:
                        ASSERT(false);
-               }\r
-       }\r
-\r
+               }
+       }
+
        void PixelPipeline::blendTexture(Registers &r, Vector4s &temp, Vector4s &texture, int stage)
        {
                Vector4s *arg1;
@@ -1172,8 +1172,8 @@ namespace sw
                default:
                        ASSERT(false);
                }
-       }\r
-\r
+       }
+
        void PixelPipeline::fogBlend(Registers &r, Vector4s &current, Float4 &f, Float4 &z, Float4 &rhw)
        {
                if(!state.fogActive)
@@ -1197,8 +1197,8 @@ namespace sw
                current.x += As<Short4>(MulHigh(invFog, *Pointer<UShort4>(r.data + OFFSET(DrawData, fog.color4[0]))));
                current.y += As<Short4>(MulHigh(invFog, *Pointer<UShort4>(r.data + OFFSET(DrawData, fog.color4[1]))));
                current.z += As<Short4>(MulHigh(invFog, *Pointer<UShort4>(r.data + OFFSET(DrawData, fog.color4[2]))));
-       }\r
-\r
+       }
+
        void PixelPipeline::specularPixel(Vector4s &current, Vector4s &specular)
        {
                if(!state.specularAdd)
@@ -1209,8 +1209,8 @@ namespace sw
                current.x = AddSat(current.x, specular.x);
                current.y = AddSat(current.y, specular.y);
                current.z = AddSat(current.z, specular.z);
-       }\r
-\r
+       }
+
        void PixelPipeline::sampleTexture(Registers &r, Vector4s &c, int coordinates, int stage, bool project)
        {
                Float4 u = r.vf[2 + coordinates].x;
@@ -1264,7 +1264,7 @@ namespace sw
                r.cycles[PERF_TEX] += Ticks() - texTime;
 #endif
        }
-\r
+
        Short4 PixelPipeline::convertFixed12(RValue<Float4> cf)
        {
                return RoundShort4(cf * Float4(0x1000));
@@ -1290,7 +1290,7 @@ namespace sw
                cf.z = convertSigned12(cs.z);
                cf.w = convertSigned12(cs.w);
        }
-\r
+
        void PixelPipeline::writeDestination(Registers &r, Vector4s &d, const Dst &dst)
        {
                switch(dst.type)
@@ -1324,7 +1324,7 @@ namespace sw
                        ASSERT(false);
                }
        }
-\r
+
        Vector4s PixelPipeline::fetchRegisterS(Registers &r, const Src &src)
        {
                Vector4s *reg;
@@ -1451,7 +1451,7 @@ namespace sw
 
                return mod;
        }
-\r
+
        void PixelPipeline::MOV(Vector4s &dst, Vector4s &src0)
        {
                dst.x = src0.x;
@@ -1964,5 +1964,5 @@ namespace sw
                t0 = AddSat(t0, src0.y);
                dst.y = t0;
        }
-}\r
-\r
+}
+
index 4c2ce1b..389b7f3 100644 (file)
@@ -1391,7 +1391,9 @@ namespace sw
                        switch(state.targetFormat[index])
                        {
                        case FORMAT_R5G6B5:
-                       //      UNIMPLEMENTED();   // FIXME
+                               current.x = AddSat(As<UShort4>(current.x), UShort4(0x0400));
+                               current.y = AddSat(As<UShort4>(current.y), UShort4(0x0200));
+                               current.z = AddSat(As<UShort4>(current.z), UShort4(0x0400));
                                break;
                        case FORMAT_X8G8R8B8Q:
                        case FORMAT_A8G8R8B8Q:
@@ -1399,12 +1401,10 @@ namespace sw
                        case FORMAT_X8B8G8R8:
                        case FORMAT_A8R8G8B8:
                        case FORMAT_A8B8G8R8:
-                               {
-                                       current.x = current.x - As<Short4>(As<UShort4>(current.x) >> 8) + Short4(0x0080, 0x0080, 0x0080, 0x0080);
-                                       current.y = current.y - As<Short4>(As<UShort4>(current.y) >> 8) + Short4(0x0080, 0x0080, 0x0080, 0x0080);
-                                       current.z = current.z - As<Short4>(As<UShort4>(current.z) >> 8) + Short4(0x0080, 0x0080, 0x0080, 0x0080);
-                                       current.w = current.w - As<Short4>(As<UShort4>(current.w) >> 8) + Short4(0x0080, 0x0080, 0x0080, 0x0080);
-                               }
+                               current.x = current.x - As<Short4>(As<UShort4>(current.x) >> 8) + Short4(0x0080, 0x0080, 0x0080, 0x0080);
+                               current.y = current.y - As<Short4>(As<UShort4>(current.y) >> 8) + Short4(0x0080, 0x0080, 0x0080, 0x0080);
+                               current.z = current.z - As<Short4>(As<UShort4>(current.z) >> 8) + Short4(0x0080, 0x0080, 0x0080, 0x0080);
+                               current.w = current.w - As<Short4>(As<UShort4>(current.w) >> 8) + Short4(0x0080, 0x0080, 0x0080, 0x0080);
                                break;
                        }
                }