From 26f372240e601980f61bff0ba4651e6ee7d06ca8 Mon Sep 17 00:00:00 2001 From: Nicolas Capens Date: Tue, 22 Sep 2015 09:53:45 -0400 Subject: [PATCH] Fix RGB565 rounding. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Bug 20891368 Change-Id: Icc0957db55cf82e42c0ccb2c8881332f71f52f5f Reviewed-on: https://swiftshader-review.googlesource.com/3993 Tested-by: Nicolas Capens Reviewed-by: Alexis Hétu Reviewed-by: Nicolas Capens --- src/Shader/PixelPipeline.cpp | 116 +++++++++++++++++++++---------------------- src/Shader/PixelRoutine.cpp | 14 +++--- 2 files changed, 65 insertions(+), 65 deletions(-) diff --git a/src/Shader/PixelPipeline.cpp b/src/Shader/PixelPipeline.cpp index 8a38bed72..c89d058d1 100644 --- a/src/Shader/PixelPipeline.cpp +++ b/src/Shader/PixelPipeline.cpp @@ -1,26 +1,26 @@ -// 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(&rBase); - +// 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(&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); - } - + 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.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); - } - + specularPixel(r.current, r.specular); + } + void PixelPipeline::applyShader(PixelRoutine::Registers &rBase, Int cMask[4]) { Registers& r = *static_cast(&rBase); @@ -257,12 +257,12 @@ namespace sw } } } - } - - Bool PixelPipeline::alphaTest(PixelRoutine::Registers &rBase, Int cMask[4]) - { - Registers& r = *static_cast(&rBase); - + } + + Bool PixelPipeline::alphaTest(PixelRoutine::Registers &rBase, Int cMask[4]) + { + Registers& r = *static_cast(&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; - } - - void PixelPipeline::rasterOperation(PixelRoutine::Registers &rBase, Float4 &fog, Pointer cBuffer[4], Int &x, Int sMask[4], Int zMask[4], Int cMask[4]) - { - Registers& r = *static_cast(&rBase); - + return pass != 0x0; + } + + void PixelPipeline::rasterOperation(PixelRoutine::Registers &rBase, Float4 &fog, Pointer cBuffer[4], Int &x, Int sMask[4], Int zMask[4], Int cMask[4]) + { + Registers& r = *static_cast(&rBase); + if(!state.colorWriteActive(0)) { return; @@ -377,9 +377,9 @@ namespace sw break; default: ASSERT(false); - } - } - + } + } + void PixelPipeline::blendTexture(Registers &r, Vector4s &temp, Vector4s &texture, int stage) { Vector4s *arg1; @@ -1172,8 +1172,8 @@ namespace sw default: ASSERT(false); } - } - + } + void PixelPipeline::fogBlend(Registers &r, Vector4s ¤t, Float4 &f, Float4 &z, Float4 &rhw) { if(!state.fogActive) @@ -1197,8 +1197,8 @@ namespace sw current.x += As(MulHigh(invFog, *Pointer(r.data + OFFSET(DrawData, fog.color4[0])))); current.y += As(MulHigh(invFog, *Pointer(r.data + OFFSET(DrawData, fog.color4[1])))); current.z += As(MulHigh(invFog, *Pointer(r.data + OFFSET(DrawData, fog.color4[2])))); - } - + } + void PixelPipeline::specularPixel(Vector4s ¤t, 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); - } - + } + 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 } - + Short4 PixelPipeline::convertFixed12(RValue cf) { return RoundShort4(cf * Float4(0x1000)); @@ -1290,7 +1290,7 @@ namespace sw cf.z = convertSigned12(cs.z); cf.w = convertSigned12(cs.w); } - + void PixelPipeline::writeDestination(Registers &r, Vector4s &d, const Dst &dst) { switch(dst.type) @@ -1324,7 +1324,7 @@ namespace sw ASSERT(false); } } - + Vector4s PixelPipeline::fetchRegisterS(Registers &r, const Src &src) { Vector4s *reg; @@ -1451,7 +1451,7 @@ namespace sw return mod; } - + 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; } -} - +} + diff --git a/src/Shader/PixelRoutine.cpp b/src/Shader/PixelRoutine.cpp index 4c2ce1bfc..389b7f362 100644 --- a/src/Shader/PixelRoutine.cpp +++ b/src/Shader/PixelRoutine.cpp @@ -1391,7 +1391,9 @@ namespace sw switch(state.targetFormat[index]) { case FORMAT_R5G6B5: - // UNIMPLEMENTED(); // FIXME + current.x = AddSat(As(current.x), UShort4(0x0400)); + current.y = AddSat(As(current.y), UShort4(0x0200)); + current.z = AddSat(As(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(As(current.x) >> 8) + Short4(0x0080, 0x0080, 0x0080, 0x0080); - current.y = current.y - As(As(current.y) >> 8) + Short4(0x0080, 0x0080, 0x0080, 0x0080); - current.z = current.z - As(As(current.z) >> 8) + Short4(0x0080, 0x0080, 0x0080, 0x0080); - current.w = current.w - As(As(current.w) >> 8) + Short4(0x0080, 0x0080, 0x0080, 0x0080); - } + current.x = current.x - As(As(current.x) >> 8) + Short4(0x0080, 0x0080, 0x0080, 0x0080); + current.y = current.y - As(As(current.y) >> 8) + Short4(0x0080, 0x0080, 0x0080, 0x0080); + current.z = current.z - As(As(current.z) >> 8) + Short4(0x0080, 0x0080, 0x0080, 0x0080); + current.w = current.w - As(As(current.w) >> 8) + Short4(0x0080, 0x0080, 0x0080, 0x0080); break; } } -- 2.11.0