Apply the Apache 2.0 license.
Change-Id: I4a7aeefedcd2d891093520d5a10ebefadcddb5be
Reviewed-on: https://swiftshader-review.googlesource.com/5320
Reviewed-by: Nicolas Capens <capn@google.com>
Tested-by: Nicolas Capens <capn@google.com>
diff --git a/src/Shader/Constants.cpp b/src/Shader/Constants.cpp
index bd15a1f..0420947 100644
--- a/src/Shader/Constants.cpp
+++ b/src/Shader/Constants.cpp
@@ -1,13 +1,16 @@
-// SwiftShader Software Renderer
+// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
-// Copyright(c) 2005-2012 TransGaming Inc.
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
//
-// 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 TransGaming Inc. Without such an agreement, no rights or licenses, express
-// or implied, including but not limited to any patent rights, are granted to you.
+// http://www.apache.org/licenses/LICENSE-2.0
//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
#include "Constants.hpp"
diff --git a/src/Shader/Constants.hpp b/src/Shader/Constants.hpp
index 859955c..e40ad5e 100644
--- a/src/Shader/Constants.hpp
+++ b/src/Shader/Constants.hpp
@@ -1,113 +1,116 @@
-// SwiftShader Software Renderer
-//
-// Copyright(c) 2005-2012 TransGaming 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 TransGaming Inc. Without such an agreement, no rights or licenses, express
-// or implied, including but not limited to any patent rights, are granted to you.
-//
-
-#ifndef sw_Constants_hpp
-#define sw_Constants_hpp
-
-#include "Common/Types.hpp"
-
-namespace sw
-{
- struct Constants
- {
- Constants();
-
- unsigned int transposeBit0[16];
- unsigned int transposeBit1[16];
- unsigned int transposeBit2[16];
-
- ushort4 cWeight[17];
- float4 uvWeight[17];
- float4 uvStart[17];
-
- unsigned int occlusionCount[16];
-
- byte8 maskB4Q[16];
- byte8 invMaskB4Q[16];
- word4 maskW4Q[16];
- word4 invMaskW4Q[16];
- dword4 maskD4X[16];
- dword4 invMaskD4X[16];
- qword maskQ0Q[16];
- qword maskQ1Q[16];
- qword maskQ2Q[16];
- qword maskQ3Q[16];
- qword invMaskQ0Q[16];
- qword invMaskQ1Q[16];
- qword invMaskQ2Q[16];
- qword invMaskQ3Q[16];
- dword4 maskX0X[16];
- dword4 maskX1X[16];
- dword4 maskX2X[16];
- dword4 maskX3X[16];
- dword4 invMaskX0X[16];
- dword4 invMaskX1X[16];
- dword4 invMaskX2X[16];
- dword4 invMaskX3X[16];
- dword2 maskD01Q[16];
- dword2 maskD23Q[16];
- dword2 invMaskD01Q[16];
- dword2 invMaskD23Q[16];
- qword2 maskQ01X[16];
- qword2 maskQ23X[16];
- qword2 invMaskQ01X[16];
- qword2 invMaskQ23X[16];
- word4 maskW01Q[4];
- word4 invMaskW01Q[4];
- dword4 maskD01X[4];
- dword4 invMaskD01X[4];
- word4 mask565Q[8];
- word4 invMask565Q[8];
-
- unsigned short sRGBtoLinear8_12[256];
- unsigned short sRGBtoLinear6_12[64];
- unsigned short sRGBtoLinear5_12[32];
-
- unsigned short linearToSRGB12_16[4096];
- unsigned short sRGBtoLinear12_16[4096];
-
- // Centroid parameters
- float4 sampleX[4][16];
- float4 sampleY[4][16];
- float4 weight[16];
-
- // Fragment offsets
- int Xf[4];
- int Yf[4];
-
- float4 X[4];
- float4 Y[4];
-
- dword maxX[16];
- dword maxY[16];
- dword maxZ[16];
- dword minX[16];
- dword minY[16];
- dword minZ[16];
- dword fini[16];
-
- dword4 maxPos;
-
- float4 unscaleByte;
- float4 unscaleSByte;
- float4 unscaleShort;
- float4 unscaleUShort;
- float4 unscaleInt;
- float4 unscaleUInt;
- float4 unscaleFixed;
-
- float half2float[65536];
- };
-
- extern Constants constants;
-}
-
-#endif // sw_Constants_hpp
+// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef sw_Constants_hpp
+#define sw_Constants_hpp
+
+#include "Common/Types.hpp"
+
+namespace sw
+{
+ struct Constants
+ {
+ Constants();
+
+ unsigned int transposeBit0[16];
+ unsigned int transposeBit1[16];
+ unsigned int transposeBit2[16];
+
+ ushort4 cWeight[17];
+ float4 uvWeight[17];
+ float4 uvStart[17];
+
+ unsigned int occlusionCount[16];
+
+ byte8 maskB4Q[16];
+ byte8 invMaskB4Q[16];
+ word4 maskW4Q[16];
+ word4 invMaskW4Q[16];
+ dword4 maskD4X[16];
+ dword4 invMaskD4X[16];
+ qword maskQ0Q[16];
+ qword maskQ1Q[16];
+ qword maskQ2Q[16];
+ qword maskQ3Q[16];
+ qword invMaskQ0Q[16];
+ qword invMaskQ1Q[16];
+ qword invMaskQ2Q[16];
+ qword invMaskQ3Q[16];
+ dword4 maskX0X[16];
+ dword4 maskX1X[16];
+ dword4 maskX2X[16];
+ dword4 maskX3X[16];
+ dword4 invMaskX0X[16];
+ dword4 invMaskX1X[16];
+ dword4 invMaskX2X[16];
+ dword4 invMaskX3X[16];
+ dword2 maskD01Q[16];
+ dword2 maskD23Q[16];
+ dword2 invMaskD01Q[16];
+ dword2 invMaskD23Q[16];
+ qword2 maskQ01X[16];
+ qword2 maskQ23X[16];
+ qword2 invMaskQ01X[16];
+ qword2 invMaskQ23X[16];
+ word4 maskW01Q[4];
+ word4 invMaskW01Q[4];
+ dword4 maskD01X[4];
+ dword4 invMaskD01X[4];
+ word4 mask565Q[8];
+ word4 invMask565Q[8];
+
+ unsigned short sRGBtoLinear8_12[256];
+ unsigned short sRGBtoLinear6_12[64];
+ unsigned short sRGBtoLinear5_12[32];
+
+ unsigned short linearToSRGB12_16[4096];
+ unsigned short sRGBtoLinear12_16[4096];
+
+ // Centroid parameters
+ float4 sampleX[4][16];
+ float4 sampleY[4][16];
+ float4 weight[16];
+
+ // Fragment offsets
+ int Xf[4];
+ int Yf[4];
+
+ float4 X[4];
+ float4 Y[4];
+
+ dword maxX[16];
+ dword maxY[16];
+ dword maxZ[16];
+ dword minX[16];
+ dword minY[16];
+ dword minZ[16];
+ dword fini[16];
+
+ dword4 maxPos;
+
+ float4 unscaleByte;
+ float4 unscaleSByte;
+ float4 unscaleShort;
+ float4 unscaleUShort;
+ float4 unscaleInt;
+ float4 unscaleUInt;
+ float4 unscaleFixed;
+
+ float half2float[65536];
+ };
+
+ extern Constants constants;
+}
+
+#endif // sw_Constants_hpp
diff --git a/src/Shader/PixelPipeline.cpp b/src/Shader/PixelPipeline.cpp
index 8adeed8..e353c27 100644
--- a/src/Shader/PixelPipeline.cpp
+++ b/src/Shader/PixelPipeline.cpp
@@ -1,13 +1,16 @@
-// SwiftShader Software Renderer
+// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
-// Copyright(c) 2015 Google Inc.
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
//
-// 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.
+// http://www.apache.org/licenses/LICENSE-2.0
//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
#include "PixelPipeline.hpp"
#include "Renderer.hpp"
diff --git a/src/Shader/PixelPipeline.hpp b/src/Shader/PixelPipeline.hpp
index 4d0362d..d8d2a03 100644
--- a/src/Shader/PixelPipeline.hpp
+++ b/src/Shader/PixelPipeline.hpp
@@ -1,111 +1,114 @@
-// 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.
-//
-
-#ifndef sw_PixelPipeline_hpp
-#define sw_PixelPipeline_hpp
-
-#include "PixelRoutine.hpp"
-
-namespace sw
-{
- class PixelPipeline : public PixelRoutine
- {
- public:
- PixelPipeline(const PixelProcessor::State &state, const PixelShader *shader) :
- PixelRoutine(state, shader), current(rs[0]), diffuse(vs[0]), specular(vs[1]), perturbate(false), luminance(false), previousScaling(false) {}
- virtual ~PixelPipeline() {}
-
- protected:
- virtual void setBuiltins(Int &x, Int &y, Float4(&z)[4], Float4 &w);
- virtual void applyShader(Int cMask[4]);
- virtual Bool alphaTest(Int cMask[4]);
- virtual void rasterOperation(Float4 &fog, Pointer<Byte> cBuffer[4], Int &x, Int sMask[4], Int zMask[4], Int cMask[4]);
-
- private:
- Vector4s ¤t;
- Vector4s &diffuse;
- Vector4s &specular;
-
- Vector4s rs[6];
- Vector4s vs[2];
- Vector4s ts[6];
-
- // bem(l) offsets and luminance
- Float4 du;
- Float4 dv;
- Short4 L;
-
- // texm3x3 temporaries
- Float4 u_; // FIXME
- Float4 v_; // FIXME
- Float4 w_; // FIXME
- Float4 U; // FIXME
- Float4 V; // FIXME
- Float4 W; // FIXME
-
- void fixedFunction();
- void blendTexture(Vector4s &temp, Vector4s &texture, int stage);
- void fogBlend(Vector4s ¤t, Float4 &fog);
- void specularPixel(Vector4s ¤t, Vector4s &specular);
-
- void sampleTexture(Vector4s &c, int coordinates, int sampler, bool project = false);
- void sampleTexture(Vector4s &c, int sampler, Float4 &u, Float4 &v, Float4 &w, Float4 &q, bool project = false);
-
- Short4 convertFixed12(RValue<Float4> cf);
- void convertFixed12(Vector4s &cs, Vector4f &cf);
- Float4 convertSigned12(Short4 &cs);
- void convertSigned12(Vector4f &cf, Vector4s &cs);
-
- void writeDestination(Vector4s &d, const Dst &dst);
- Vector4s fetchRegister(const Src &src);
-
- // Instructions
- void MOV(Vector4s &dst, Vector4s &src0);
- void ADD(Vector4s &dst, Vector4s &src0, Vector4s &src1);
- void SUB(Vector4s &dst, Vector4s &src0, Vector4s &src1);
- void MAD(Vector4s &dst, Vector4s &src0, Vector4s &src1, Vector4s &src2);
- void MUL(Vector4s &dst, Vector4s &src0, Vector4s &src1);
- void DP3(Vector4s &dst, Vector4s &src0, Vector4s &src1);
- void DP4(Vector4s &dst, Vector4s &src0, Vector4s &src1);
- void LRP(Vector4s &dst, Vector4s &src0, Vector4s &src1, Vector4s &src2);
- void TEXCOORD(Vector4s &dst, Float4 &u, Float4 &v, Float4 &s, int coordinate);
- void TEXCRD(Vector4s &dst, Float4 &u, Float4 &v, Float4 &s, int coordinate, bool project);
- void TEXDP3(Vector4s &dst, Float4 &u, Float4 &v, Float4 &s, Vector4s &src);
- void TEXDP3TEX(Vector4s &dst, Float4 &u, Float4 &v, Float4 &s, int stage, Vector4s &src0);
- void TEXKILL(Int cMask[4], Float4 &u, Float4 &v, Float4 &s);
- void TEXKILL(Int cMask[4], Vector4s &dst);
- void TEX(Vector4s &dst, Float4 &u, Float4 &v, Float4 &s, int stage, bool project);
- void TEXLD(Vector4s &dst, Vector4s &src, int stage, bool project);
- void TEXBEM(Vector4s &dst, Vector4s &src, Float4 &u, Float4 &v, Float4 &s, int stage);
- void TEXBEML(Vector4s &dst, Vector4s &src, Float4 &u, Float4 &v, Float4 &s, int stage);
- void TEXREG2AR(Vector4s &dst, Vector4s &src0, int stage);
- void TEXREG2GB(Vector4s &dst, Vector4s &src0, int stage);
- void TEXREG2RGB(Vector4s &dst, Vector4s &src0, int stage);
- void TEXM3X2DEPTH(Vector4s &dst, Float4 &u, Float4 &v, Float4 &s, Vector4s &src, bool signedScaling);
- void TEXM3X2PAD(Float4 &u, Float4 &v, Float4 &s, Vector4s &src0, int component, bool signedScaling);
- void TEXM3X2TEX(Vector4s &dst, Float4 &u, Float4 &v, Float4 &s, int stage, Vector4s &src0, bool signedScaling);
- void TEXM3X3(Vector4s &dst, Float4 &u, Float4 &v, Float4 &s, Vector4s &src0, bool signedScaling);
- void TEXM3X3PAD(Float4 &u, Float4 &v, Float4 &s, Vector4s &src0, int component, bool signedScaling);
- void TEXM3X3SPEC(Vector4s &dst, Float4 &u, Float4 &v, Float4 &s, int stage, Vector4s &src0, Vector4s &src1);
- void TEXM3X3TEX(Vector4s &dst, Float4 &u, Float4 &v, Float4 &s, int stage, Vector4s &src0, bool singedScaling);
- void TEXM3X3VSPEC(Vector4s &dst, Float4 &u, Float4 &v, Float4 &s, int stage, Vector4s &src0);
- void TEXDEPTH();
- void CND(Vector4s &dst, Vector4s &src0, Vector4s &src1, Vector4s &src2);
- void CMP(Vector4s &dst, Vector4s &src0, Vector4s &src1, Vector4s &src2);
- void BEM(Vector4s &dst, Vector4s &src0, Vector4s &src1, int stage);
-
- bool perturbate;
- bool luminance;
- bool previousScaling;
- };
-}
-
-#endif
+// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef sw_PixelPipeline_hpp
+#define sw_PixelPipeline_hpp
+
+#include "PixelRoutine.hpp"
+
+namespace sw
+{
+ class PixelPipeline : public PixelRoutine
+ {
+ public:
+ PixelPipeline(const PixelProcessor::State &state, const PixelShader *shader) :
+ PixelRoutine(state, shader), current(rs[0]), diffuse(vs[0]), specular(vs[1]), perturbate(false), luminance(false), previousScaling(false) {}
+ virtual ~PixelPipeline() {}
+
+ protected:
+ virtual void setBuiltins(Int &x, Int &y, Float4(&z)[4], Float4 &w);
+ virtual void applyShader(Int cMask[4]);
+ virtual Bool alphaTest(Int cMask[4]);
+ virtual void rasterOperation(Float4 &fog, Pointer<Byte> cBuffer[4], Int &x, Int sMask[4], Int zMask[4], Int cMask[4]);
+
+ private:
+ Vector4s ¤t;
+ Vector4s &diffuse;
+ Vector4s &specular;
+
+ Vector4s rs[6];
+ Vector4s vs[2];
+ Vector4s ts[6];
+
+ // bem(l) offsets and luminance
+ Float4 du;
+ Float4 dv;
+ Short4 L;
+
+ // texm3x3 temporaries
+ Float4 u_; // FIXME
+ Float4 v_; // FIXME
+ Float4 w_; // FIXME
+ Float4 U; // FIXME
+ Float4 V; // FIXME
+ Float4 W; // FIXME
+
+ void fixedFunction();
+ void blendTexture(Vector4s &temp, Vector4s &texture, int stage);
+ void fogBlend(Vector4s ¤t, Float4 &fog);
+ void specularPixel(Vector4s ¤t, Vector4s &specular);
+
+ void sampleTexture(Vector4s &c, int coordinates, int sampler, bool project = false);
+ void sampleTexture(Vector4s &c, int sampler, Float4 &u, Float4 &v, Float4 &w, Float4 &q, bool project = false);
+
+ Short4 convertFixed12(RValue<Float4> cf);
+ void convertFixed12(Vector4s &cs, Vector4f &cf);
+ Float4 convertSigned12(Short4 &cs);
+ void convertSigned12(Vector4f &cf, Vector4s &cs);
+
+ void writeDestination(Vector4s &d, const Dst &dst);
+ Vector4s fetchRegister(const Src &src);
+
+ // Instructions
+ void MOV(Vector4s &dst, Vector4s &src0);
+ void ADD(Vector4s &dst, Vector4s &src0, Vector4s &src1);
+ void SUB(Vector4s &dst, Vector4s &src0, Vector4s &src1);
+ void MAD(Vector4s &dst, Vector4s &src0, Vector4s &src1, Vector4s &src2);
+ void MUL(Vector4s &dst, Vector4s &src0, Vector4s &src1);
+ void DP3(Vector4s &dst, Vector4s &src0, Vector4s &src1);
+ void DP4(Vector4s &dst, Vector4s &src0, Vector4s &src1);
+ void LRP(Vector4s &dst, Vector4s &src0, Vector4s &src1, Vector4s &src2);
+ void TEXCOORD(Vector4s &dst, Float4 &u, Float4 &v, Float4 &s, int coordinate);
+ void TEXCRD(Vector4s &dst, Float4 &u, Float4 &v, Float4 &s, int coordinate, bool project);
+ void TEXDP3(Vector4s &dst, Float4 &u, Float4 &v, Float4 &s, Vector4s &src);
+ void TEXDP3TEX(Vector4s &dst, Float4 &u, Float4 &v, Float4 &s, int stage, Vector4s &src0);
+ void TEXKILL(Int cMask[4], Float4 &u, Float4 &v, Float4 &s);
+ void TEXKILL(Int cMask[4], Vector4s &dst);
+ void TEX(Vector4s &dst, Float4 &u, Float4 &v, Float4 &s, int stage, bool project);
+ void TEXLD(Vector4s &dst, Vector4s &src, int stage, bool project);
+ void TEXBEM(Vector4s &dst, Vector4s &src, Float4 &u, Float4 &v, Float4 &s, int stage);
+ void TEXBEML(Vector4s &dst, Vector4s &src, Float4 &u, Float4 &v, Float4 &s, int stage);
+ void TEXREG2AR(Vector4s &dst, Vector4s &src0, int stage);
+ void TEXREG2GB(Vector4s &dst, Vector4s &src0, int stage);
+ void TEXREG2RGB(Vector4s &dst, Vector4s &src0, int stage);
+ void TEXM3X2DEPTH(Vector4s &dst, Float4 &u, Float4 &v, Float4 &s, Vector4s &src, bool signedScaling);
+ void TEXM3X2PAD(Float4 &u, Float4 &v, Float4 &s, Vector4s &src0, int component, bool signedScaling);
+ void TEXM3X2TEX(Vector4s &dst, Float4 &u, Float4 &v, Float4 &s, int stage, Vector4s &src0, bool signedScaling);
+ void TEXM3X3(Vector4s &dst, Float4 &u, Float4 &v, Float4 &s, Vector4s &src0, bool signedScaling);
+ void TEXM3X3PAD(Float4 &u, Float4 &v, Float4 &s, Vector4s &src0, int component, bool signedScaling);
+ void TEXM3X3SPEC(Vector4s &dst, Float4 &u, Float4 &v, Float4 &s, int stage, Vector4s &src0, Vector4s &src1);
+ void TEXM3X3TEX(Vector4s &dst, Float4 &u, Float4 &v, Float4 &s, int stage, Vector4s &src0, bool singedScaling);
+ void TEXM3X3VSPEC(Vector4s &dst, Float4 &u, Float4 &v, Float4 &s, int stage, Vector4s &src0);
+ void TEXDEPTH();
+ void CND(Vector4s &dst, Vector4s &src0, Vector4s &src1, Vector4s &src2);
+ void CMP(Vector4s &dst, Vector4s &src0, Vector4s &src1, Vector4s &src2);
+ void BEM(Vector4s &dst, Vector4s &src0, Vector4s &src1, int stage);
+
+ bool perturbate;
+ bool luminance;
+ bool previousScaling;
+ };
+}
+
+#endif
diff --git a/src/Shader/PixelProgram.cpp b/src/Shader/PixelProgram.cpp
index 2984b9e..d229a92 100644
--- a/src/Shader/PixelProgram.cpp
+++ b/src/Shader/PixelProgram.cpp
@@ -1,13 +1,16 @@
-// SwiftShader Software Renderer
+// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
-// Copyright(c) 2015 Google Inc.
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
//
-// 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.
+// http://www.apache.org/licenses/LICENSE-2.0
//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
#include "PixelProgram.hpp"
#include "Primitive.hpp"
diff --git a/src/Shader/PixelProgram.hpp b/src/Shader/PixelProgram.hpp
index 085255d..a518cc1 100644
--- a/src/Shader/PixelProgram.hpp
+++ b/src/Shader/PixelProgram.hpp
@@ -1,165 +1,168 @@
-// 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.
-//
-
-#ifndef sw_PixelProgram_hpp
-#define sw_PixelProgram_hpp
-
-#include "PixelRoutine.hpp"
-#include "SamplerCore.hpp"
-
-namespace sw
-{
- class PixelProgram : public PixelRoutine
- {
- public:
- PixelProgram(const PixelProcessor::State &state, const PixelShader *shader) :
- PixelRoutine(state, shader), r(shader && shader->dynamicallyIndexedTemporaries),
- loopDepth(-1), ifDepth(0), loopRepDepth(0), breakDepth(0), currentLabel(-1), whileTest(false)
- {
- for(int i = 0; i < 2048; ++i)
- {
- labelBlock[i] = 0;
- }
-
- enableStack[0] = Int4(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF);
-
- if(shader && shader->containsBreakInstruction())
- {
- enableBreak = Int4(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF);
- }
-
- if(shader && shader->containsContinueInstruction())
- {
- enableContinue = Int4(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF);
- }
- }
-
- virtual ~PixelProgram() {}
-
- protected:
- virtual void setBuiltins(Int &x, Int &y, Float4(&z)[4], Float4 &w);
- virtual void applyShader(Int cMask[4]);
- virtual Bool alphaTest(Int cMask[4]);
- virtual void rasterOperation(Float4 &fog, Pointer<Byte> cBuffer[4], Int &x, Int sMask[4], Int zMask[4], Int cMask[4]);
-
- private:
- // Temporary registers
- RegisterArray<4096> r;
-
- // Color outputs
- Vector4f c[RENDERTARGETS];
- RegisterArray<RENDERTARGETS, true> oC;
-
- // Shader variables
- Vector4f vPos;
- Vector4f vFace;
-
- // DX9 specific variables
- Vector4f p0;
- Array<Int, 4> aL;
- Array<Int, 4> increment;
- Array<Int, 4> iteration;
-
- Int loopDepth; // FIXME: Add support for switch
- Int stackIndex; // FIXME: Inc/decrement callStack
- Array<UInt, 16> callStack;
-
- // Per pixel based on conditions reached
- Int enableIndex;
- Array<Int4, 1 + 24> enableStack;
- Int4 enableBreak;
- Int4 enableContinue;
- Int4 enableLeave;
-
- void sampleTexture(Vector4f &c, const Src &sampler, Float4 &u, Float4 &v, Float4 &w, Float4 &q, Vector4f &dsx, Vector4f &dsy, bool project, SamplerMethod method);
- void sampleTexture(Vector4f &c, int sampler, Float4 &u, Float4 &v, Float4 &w, Float4 &q, Vector4f &dsx, Vector4f &dsy, bool project, SamplerMethod method);
-
- // Raster operations
- void clampColor(Vector4f oC[RENDERTARGETS]);
-
- Int4 enableMask(const Shader::Instruction *instruction);
-
- Vector4f fetchRegister(const Src &src, unsigned int offset = 0);
- Vector4f readConstant(const Src &src, unsigned int offset = 0);
- RValue<Pointer<Byte>> uniformAddress(int bufferIndex, unsigned int index);
- RValue<Pointer<Byte>> uniformAddress(int bufferIndex, unsigned int index, Int& offset);
- Int relativeAddress(const Shader::Parameter &var, int bufferIndex = -1);
-
- Float4 linearToSRGB(const Float4 &x);
-
- // Instructions
- typedef Shader::Control Control;
-
- void M3X2(Vector4f &dst, Vector4f &src0, const Src &src1);
- void M3X3(Vector4f &dst, Vector4f &src0, const Src &src1);
- void M3X4(Vector4f &dst, Vector4f &src0, const Src &src1);
- void M4X3(Vector4f &dst, Vector4f &src0, const Src &src1);
- void M4X4(Vector4f &dst, Vector4f &src0, const Src &src1);
- void TEXLD(Vector4f &dst, Vector4f &src0, const Src &src1, bool project, bool bias);
- void TEXLDD(Vector4f &dst, Vector4f &src0, const Src &src1, Vector4f &src2, Vector4f &src3, bool project);
- void TEXLDL(Vector4f &dst, Vector4f &src0, const Src &src1, bool project);
- void TEXSIZE(Vector4f &dst, Float4 &lod, const Src &src1);
- void TEXKILL(Int cMask[4], Vector4f &src, unsigned char mask);
- void TEXOFFSET(Vector4f &dst, Vector4f &src, const Src&, Vector4f &src2, Vector4f &src3, bool project, bool bias);
- void TEXLDL(Vector4f &dst, Vector4f &src0, const Src &src1, Vector4f &src2, bool project, bool bias);
- void TEXELFETCH(Vector4f &dst, Vector4f &src, const Src&, Vector4f &src2);
- void TEXELFETCH(Vector4f &dst, Vector4f &src, const Src&, Vector4f &src2, Vector4f &src3);
- void TEXGRAD(Vector4f &dst, Vector4f &src, const Src&, Vector4f &src2, Vector4f &src3);
- void TEXGRAD(Vector4f &dst, Vector4f &src, const Src&, Vector4f &src2, Vector4f &src3, Vector4f &src4);
- void DISCARD(Int cMask[4], const Shader::Instruction *instruction);
- void DFDX(Vector4f &dst, Vector4f &src);
- void DFDY(Vector4f &dst, Vector4f &src);
- void FWIDTH(Vector4f &dst, Vector4f &src);
- void BREAK();
- void BREAKC(Vector4f &src0, Vector4f &src1, Control);
- void BREAKP(const Src &predicateRegister);
- void BREAK(Int4 &condition);
- void CONTINUE();
- void TEST();
- void CALL(int labelIndex, int callSiteIndex);
- void CALLNZ(int labelIndex, int callSiteIndex, const Src &src);
- void CALLNZb(int labelIndex, int callSiteIndex, const Src &boolRegister);
- void CALLNZp(int labelIndex, int callSiteIndex, const Src &predicateRegister);
- void ELSE();
- void ENDIF();
- void ENDLOOP();
- void ENDREP();
- void ENDWHILE();
- void IF(const Src &src);
- void IFb(const Src &boolRegister);
- void IFp(const Src &predicateRegister);
- void IFC(Vector4f &src0, Vector4f &src1, Control);
- void IF(Int4 &condition);
- void LABEL(int labelIndex);
- void LOOP(const Src &integerRegister);
- void REP(const Src &integerRegister);
- void WHILE(const Src &temporaryRegister);
- void RET();
- void LEAVE();
-
- int ifDepth;
- int loopRepDepth;
- int breakDepth;
- int currentLabel;
- bool whileTest;
-
- // FIXME: Get rid of llvm::
- llvm::BasicBlock *ifFalseBlock[24 + 24];
- llvm::BasicBlock *loopRepTestBlock[4];
- llvm::BasicBlock *loopRepEndBlock[4];
- llvm::BasicBlock *labelBlock[2048];
- std::vector<llvm::BasicBlock*> callRetBlock[2048];
- llvm::BasicBlock *returnBlock;
- bool isConditionalIf[24 + 24];
- };
-}
-
-#endif
+// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef sw_PixelProgram_hpp
+#define sw_PixelProgram_hpp
+
+#include "PixelRoutine.hpp"
+#include "SamplerCore.hpp"
+
+namespace sw
+{
+ class PixelProgram : public PixelRoutine
+ {
+ public:
+ PixelProgram(const PixelProcessor::State &state, const PixelShader *shader) :
+ PixelRoutine(state, shader), r(shader && shader->dynamicallyIndexedTemporaries),
+ loopDepth(-1), ifDepth(0), loopRepDepth(0), breakDepth(0), currentLabel(-1), whileTest(false)
+ {
+ for(int i = 0; i < 2048; ++i)
+ {
+ labelBlock[i] = 0;
+ }
+
+ enableStack[0] = Int4(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF);
+
+ if(shader && shader->containsBreakInstruction())
+ {
+ enableBreak = Int4(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF);
+ }
+
+ if(shader && shader->containsContinueInstruction())
+ {
+ enableContinue = Int4(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF);
+ }
+ }
+
+ virtual ~PixelProgram() {}
+
+ protected:
+ virtual void setBuiltins(Int &x, Int &y, Float4(&z)[4], Float4 &w);
+ virtual void applyShader(Int cMask[4]);
+ virtual Bool alphaTest(Int cMask[4]);
+ virtual void rasterOperation(Float4 &fog, Pointer<Byte> cBuffer[4], Int &x, Int sMask[4], Int zMask[4], Int cMask[4]);
+
+ private:
+ // Temporary registers
+ RegisterArray<4096> r;
+
+ // Color outputs
+ Vector4f c[RENDERTARGETS];
+ RegisterArray<RENDERTARGETS, true> oC;
+
+ // Shader variables
+ Vector4f vPos;
+ Vector4f vFace;
+
+ // DX9 specific variables
+ Vector4f p0;
+ Array<Int, 4> aL;
+ Array<Int, 4> increment;
+ Array<Int, 4> iteration;
+
+ Int loopDepth; // FIXME: Add support for switch
+ Int stackIndex; // FIXME: Inc/decrement callStack
+ Array<UInt, 16> callStack;
+
+ // Per pixel based on conditions reached
+ Int enableIndex;
+ Array<Int4, 1 + 24> enableStack;
+ Int4 enableBreak;
+ Int4 enableContinue;
+ Int4 enableLeave;
+
+ void sampleTexture(Vector4f &c, const Src &sampler, Float4 &u, Float4 &v, Float4 &w, Float4 &q, Vector4f &dsx, Vector4f &dsy, bool project, SamplerMethod method);
+ void sampleTexture(Vector4f &c, int sampler, Float4 &u, Float4 &v, Float4 &w, Float4 &q, Vector4f &dsx, Vector4f &dsy, bool project, SamplerMethod method);
+
+ // Raster operations
+ void clampColor(Vector4f oC[RENDERTARGETS]);
+
+ Int4 enableMask(const Shader::Instruction *instruction);
+
+ Vector4f fetchRegister(const Src &src, unsigned int offset = 0);
+ Vector4f readConstant(const Src &src, unsigned int offset = 0);
+ RValue<Pointer<Byte>> uniformAddress(int bufferIndex, unsigned int index);
+ RValue<Pointer<Byte>> uniformAddress(int bufferIndex, unsigned int index, Int& offset);
+ Int relativeAddress(const Shader::Parameter &var, int bufferIndex = -1);
+
+ Float4 linearToSRGB(const Float4 &x);
+
+ // Instructions
+ typedef Shader::Control Control;
+
+ void M3X2(Vector4f &dst, Vector4f &src0, const Src &src1);
+ void M3X3(Vector4f &dst, Vector4f &src0, const Src &src1);
+ void M3X4(Vector4f &dst, Vector4f &src0, const Src &src1);
+ void M4X3(Vector4f &dst, Vector4f &src0, const Src &src1);
+ void M4X4(Vector4f &dst, Vector4f &src0, const Src &src1);
+ void TEXLD(Vector4f &dst, Vector4f &src0, const Src &src1, bool project, bool bias);
+ void TEXLDD(Vector4f &dst, Vector4f &src0, const Src &src1, Vector4f &src2, Vector4f &src3, bool project);
+ void TEXLDL(Vector4f &dst, Vector4f &src0, const Src &src1, bool project);
+ void TEXSIZE(Vector4f &dst, Float4 &lod, const Src &src1);
+ void TEXKILL(Int cMask[4], Vector4f &src, unsigned char mask);
+ void TEXOFFSET(Vector4f &dst, Vector4f &src, const Src&, Vector4f &src2, Vector4f &src3, bool project, bool bias);
+ void TEXLDL(Vector4f &dst, Vector4f &src0, const Src &src1, Vector4f &src2, bool project, bool bias);
+ void TEXELFETCH(Vector4f &dst, Vector4f &src, const Src&, Vector4f &src2);
+ void TEXELFETCH(Vector4f &dst, Vector4f &src, const Src&, Vector4f &src2, Vector4f &src3);
+ void TEXGRAD(Vector4f &dst, Vector4f &src, const Src&, Vector4f &src2, Vector4f &src3);
+ void TEXGRAD(Vector4f &dst, Vector4f &src, const Src&, Vector4f &src2, Vector4f &src3, Vector4f &src4);
+ void DISCARD(Int cMask[4], const Shader::Instruction *instruction);
+ void DFDX(Vector4f &dst, Vector4f &src);
+ void DFDY(Vector4f &dst, Vector4f &src);
+ void FWIDTH(Vector4f &dst, Vector4f &src);
+ void BREAK();
+ void BREAKC(Vector4f &src0, Vector4f &src1, Control);
+ void BREAKP(const Src &predicateRegister);
+ void BREAK(Int4 &condition);
+ void CONTINUE();
+ void TEST();
+ void CALL(int labelIndex, int callSiteIndex);
+ void CALLNZ(int labelIndex, int callSiteIndex, const Src &src);
+ void CALLNZb(int labelIndex, int callSiteIndex, const Src &boolRegister);
+ void CALLNZp(int labelIndex, int callSiteIndex, const Src &predicateRegister);
+ void ELSE();
+ void ENDIF();
+ void ENDLOOP();
+ void ENDREP();
+ void ENDWHILE();
+ void IF(const Src &src);
+ void IFb(const Src &boolRegister);
+ void IFp(const Src &predicateRegister);
+ void IFC(Vector4f &src0, Vector4f &src1, Control);
+ void IF(Int4 &condition);
+ void LABEL(int labelIndex);
+ void LOOP(const Src &integerRegister);
+ void REP(const Src &integerRegister);
+ void WHILE(const Src &temporaryRegister);
+ void RET();
+ void LEAVE();
+
+ int ifDepth;
+ int loopRepDepth;
+ int breakDepth;
+ int currentLabel;
+ bool whileTest;
+
+ // FIXME: Get rid of llvm::
+ llvm::BasicBlock *ifFalseBlock[24 + 24];
+ llvm::BasicBlock *loopRepTestBlock[4];
+ llvm::BasicBlock *loopRepEndBlock[4];
+ llvm::BasicBlock *labelBlock[2048];
+ std::vector<llvm::BasicBlock*> callRetBlock[2048];
+ llvm::BasicBlock *returnBlock;
+ bool isConditionalIf[24 + 24];
+ };
+}
+
+#endif
diff --git a/src/Shader/PixelRoutine.cpp b/src/Shader/PixelRoutine.cpp
index a1a752c..b28a428 100644
--- a/src/Shader/PixelRoutine.cpp
+++ b/src/Shader/PixelRoutine.cpp
@@ -1,13 +1,16 @@
-// SwiftShader Software Renderer
+// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
-// Copyright(c) 2005-2013 TransGaming Inc.
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
//
-// 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 TransGaming Inc. Without such an agreement, no rights or licenses, express
-// or implied, including but not limited to any patent rights, are granted to you.
+// http://www.apache.org/licenses/LICENSE-2.0
//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
#include "PixelRoutine.hpp"
diff --git a/src/Shader/PixelRoutine.hpp b/src/Shader/PixelRoutine.hpp
index 2cce393..89fe7ff 100644
--- a/src/Shader/PixelRoutine.hpp
+++ b/src/Shader/PixelRoutine.hpp
@@ -1,13 +1,16 @@
-// SwiftShader Software Renderer
+// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
-// Copyright(c) 2005-2013 TransGaming Inc.
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
//
-// 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 TransGaming Inc. Without such an agreement, no rights or licenses, express
-// or implied, including but not limited to any patent rights, are granted to you.
+// http://www.apache.org/licenses/LICENSE-2.0
//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
#ifndef sw_PixelRoutine_hpp
#define sw_PixelRoutine_hpp
diff --git a/src/Shader/PixelShader.cpp b/src/Shader/PixelShader.cpp
index 2147fea..8cdfaff 100644
--- a/src/Shader/PixelShader.cpp
+++ b/src/Shader/PixelShader.cpp
@@ -1,13 +1,16 @@
-// SwiftShader Software Renderer
+// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
-// Copyright(c) 2005-2013 TransGaming Inc.
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
//
-// 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 TransGaming Inc. Without such an agreement, no rights or licenses, express
-// or implied, including but not limited to any patent rights, are granted to you.
+// http://www.apache.org/licenses/LICENSE-2.0
//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
#include "PixelShader.hpp"
diff --git a/src/Shader/PixelShader.hpp b/src/Shader/PixelShader.hpp
index f57794e..cb568a8 100644
--- a/src/Shader/PixelShader.hpp
+++ b/src/Shader/PixelShader.hpp
@@ -1,13 +1,16 @@
-// SwiftShader Software Renderer
+// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
-// Copyright(c) 2005-2013 TransGaming Inc.
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
//
-// 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 TransGaming Inc. Without such an agreement, no rights or licenses, express
-// or implied, including but not limited to any patent rights, are granted to you.
+// http://www.apache.org/licenses/LICENSE-2.0
//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
#ifndef sw_PixelShader_hpp
#define sw_PixelShader_hpp
diff --git a/src/Shader/SamplerCore.cpp b/src/Shader/SamplerCore.cpp
index 956f526..a4de5f5 100644
--- a/src/Shader/SamplerCore.cpp
+++ b/src/Shader/SamplerCore.cpp
@@ -1,13 +1,16 @@
-// SwiftShader Software Renderer
+// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
-// Copyright(c) 2005-2013 TransGaming Inc.
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
//
-// 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 TransGaming Inc. Without such an agreement, no rights or licenses, express
-// or implied, including but not limited to any patent rights, are granted to you.
+// http://www.apache.org/licenses/LICENSE-2.0
//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
#include "SamplerCore.hpp"
diff --git a/src/Shader/SamplerCore.hpp b/src/Shader/SamplerCore.hpp
index 91e40db..8b915ee 100644
--- a/src/Shader/SamplerCore.hpp
+++ b/src/Shader/SamplerCore.hpp
@@ -1,85 +1,88 @@
-// SwiftShader Software Renderer
-//
-// Copyright(c) 2005-2012 TransGaming 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 TransGaming Inc. Without such an agreement, no rights or licenses, express
-// or implied, including but not limited to any patent rights, are granted to you.
-//
-
-#ifndef sw_SamplerCore_hpp
-#define sw_SamplerCore_hpp
-
-#include "PixelRoutine.hpp"
-#include "Reactor/Nucleus.hpp"
-
-namespace sw
-{
- enum SamplerMethod
- {
- Implicit,
- Bias,
- Lod,
- Grad,
- };
-
- class SamplerCore
- {
- public:
- SamplerCore(Pointer<Byte> &r, const Sampler::State &state);
-
- void sampleTexture(Pointer<Byte> &texture, Vector4s &c, Float4 &u, Float4 &v, Float4 &w, Float4 &q, Vector4f &dsx, Vector4f &dsy, SamplerMethod method = Implicit);
- void sampleTexture(Pointer<Byte> &texture, Vector4f &c, Float4 &u, Float4 &v, Float4 &w, Float4 &q, Vector4f &dsx, Vector4f &dsy, SamplerMethod method = Implicit);
-
- private:
- void sampleTexture(Pointer<Byte> &texture, Vector4s &c, Float4 &u, Float4 &v, Float4 &w, Float4 &q, Vector4f &dsx, Vector4f &dsy, SamplerMethod method, bool fixed12);
-
- void border(Short4 &mask, Float4 &coordinates);
- void border(Int4 &mask, Float4 &coordinates);
- Short4 offsetSample(Short4 &uvw, Pointer<Byte> &mipmap, int halfOffset, bool wrap, int count, Float &lod);
- void sampleFilter(Pointer<Byte> &texture, Vector4s &c, Float4 &u, Float4 &v, Float4 &w, Float &lod, Float &anisotropy, Float4 &uDelta, Float4 &vDelta, Int face[4], SamplerMethod method);
- void sampleAniso(Pointer<Byte> &texture, Vector4s &c, Float4 &u, Float4 &v, Float4 &w, Float &lod, Float &anisotropy, Float4 &uDelta, Float4 &vDelta, Int face[4], bool secondLOD, SamplerMethod method);
- void sampleQuad(Pointer<Byte> &texture, Vector4s &c, Float4 &u, Float4 &v, Float4 &w, Float &lod, Int face[4], bool secondLOD);
- void sampleQuad2D(Pointer<Byte> &texture, Vector4s &c, Float4 &u, Float4 &v, Float4 &w, Float &lod, Int face[4], bool secondLOD);
- void sample3D(Pointer<Byte> &texture, Vector4s &c, Float4 &u, Float4 &v, Float4 &w, Float &lod, bool secondLOD);
- void sampleFloatFilter(Pointer<Byte> &texture, Vector4f &c, Float4 &u, Float4 &v, Float4 &w, Float &lod, Float &anisotropy, Float4 &uDelta, Float4 &vDelta, Int face[4], SamplerMethod method);
- void sampleFloatAniso(Pointer<Byte> &texture, Vector4f &c, Float4 &u, Float4 &v, Float4 &w, Float &lod, Float &anisotropy, Float4 &uDelta, Float4 &vDelta, Int face[4], bool secondLOD, SamplerMethod method);
- void sampleFloat(Pointer<Byte> &texture, Vector4f &c, Float4 &u, Float4 &v, Float4 &w, Float &lod, Int face[4], bool secondLOD);
- void sampleFloat2D(Pointer<Byte> &texture, Vector4f &c, Float4 &u, Float4 &v, Float4 &w, Float &lod, Int face[4], bool secondLOD);
- void sampleFloat3D(Pointer<Byte> &texture, Vector4f &c, Float4 &u, Float4 &v, Float4 &w, Float &lod, bool secondLOD);
- void computeLod(Pointer<Byte> &texture, Float &lod, Float &anisotropy, Float4 &uDelta, Float4 &vDelta, Float4 &u, Float4 &v, const Float &lodBias, Vector4f &dsx, Vector4f &dsy, SamplerMethod method);
- void computeLodCube(Pointer<Byte> &texture, Float &lod, Float4 &x, Float4 &y, Float4 &z, const Float &lodBias, Vector4f &dsx, Vector4f &dsy, SamplerMethod method);
- void computeLod3D(Pointer<Byte> &texture, Float &lod, Float4 &u, Float4 &v, Float4 &w, const Float &lodBias, Vector4f &dsx, Vector4f &dsy, SamplerMethod method);
- void cubeFace(Int face[4], Float4 &U, Float4 &V, Float4 &lodX, Float4 &lodY, Float4 &lodZ, Float4 &x, Float4 &y, Float4 &z);
- void computeIndices(Int index[4], Short4 uuuu, Short4 vvvv, Short4 wwww, const Pointer<Byte> &mipmap);
- void sampleTexel(Vector4s &c, Short4 &u, Short4 &v, Short4 &s, Pointer<Byte> &mipmap, Pointer<Byte> buffer[4]);
- void sampleTexel(Vector4f &c, Short4 &u, Short4 &v, Short4 &s, Float4 &z, Pointer<Byte> &mipmap, Pointer<Byte> buffer[4]);
- 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 convertFixed12(Short4 &ci, Float4 &cf);
- void convertFixed12(Vector4s &cs, Vector4f &cf);
- void convertSigned12(Float4 &cf, Short4 &ci);
- void convertSigned15(Float4 &cf, Short4 &ci);
- void convertUnsigned16(Float4 &cf, Short4 &ci);
- void sRGBtoLinear16_8_12(Short4 &c);
- void sRGBtoLinear16_6_12(Short4 &c);
- void sRGBtoLinear16_5_12(Short4 &c);
-
- bool hasFloatTexture() const;
- bool hasUnsignedTextureComponent(int component) const;
- int textureComponentCount() const;
- bool has16bitTextureFormat() const;
- bool has8bitTextureComponents() const;
- bool has16bitTextureComponents() const;
- bool hasYuvFormat() const;
- bool isRGBComponent(int component) const;
-
- Pointer<Byte> &constants;
- const Sampler::State &state;
- };
-}
-
-#endif // sw_SamplerCore_hpp
+// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef sw_SamplerCore_hpp
+#define sw_SamplerCore_hpp
+
+#include "PixelRoutine.hpp"
+#include "Reactor/Nucleus.hpp"
+
+namespace sw
+{
+ enum SamplerMethod
+ {
+ Implicit,
+ Bias,
+ Lod,
+ Grad,
+ };
+
+ class SamplerCore
+ {
+ public:
+ SamplerCore(Pointer<Byte> &r, const Sampler::State &state);
+
+ void sampleTexture(Pointer<Byte> &texture, Vector4s &c, Float4 &u, Float4 &v, Float4 &w, Float4 &q, Vector4f &dsx, Vector4f &dsy, SamplerMethod method = Implicit);
+ void sampleTexture(Pointer<Byte> &texture, Vector4f &c, Float4 &u, Float4 &v, Float4 &w, Float4 &q, Vector4f &dsx, Vector4f &dsy, SamplerMethod method = Implicit);
+
+ private:
+ void sampleTexture(Pointer<Byte> &texture, Vector4s &c, Float4 &u, Float4 &v, Float4 &w, Float4 &q, Vector4f &dsx, Vector4f &dsy, SamplerMethod method, bool fixed12);
+
+ void border(Short4 &mask, Float4 &coordinates);
+ void border(Int4 &mask, Float4 &coordinates);
+ Short4 offsetSample(Short4 &uvw, Pointer<Byte> &mipmap, int halfOffset, bool wrap, int count, Float &lod);
+ void sampleFilter(Pointer<Byte> &texture, Vector4s &c, Float4 &u, Float4 &v, Float4 &w, Float &lod, Float &anisotropy, Float4 &uDelta, Float4 &vDelta, Int face[4], SamplerMethod method);
+ void sampleAniso(Pointer<Byte> &texture, Vector4s &c, Float4 &u, Float4 &v, Float4 &w, Float &lod, Float &anisotropy, Float4 &uDelta, Float4 &vDelta, Int face[4], bool secondLOD, SamplerMethod method);
+ void sampleQuad(Pointer<Byte> &texture, Vector4s &c, Float4 &u, Float4 &v, Float4 &w, Float &lod, Int face[4], bool secondLOD);
+ void sampleQuad2D(Pointer<Byte> &texture, Vector4s &c, Float4 &u, Float4 &v, Float4 &w, Float &lod, Int face[4], bool secondLOD);
+ void sample3D(Pointer<Byte> &texture, Vector4s &c, Float4 &u, Float4 &v, Float4 &w, Float &lod, bool secondLOD);
+ void sampleFloatFilter(Pointer<Byte> &texture, Vector4f &c, Float4 &u, Float4 &v, Float4 &w, Float &lod, Float &anisotropy, Float4 &uDelta, Float4 &vDelta, Int face[4], SamplerMethod method);
+ void sampleFloatAniso(Pointer<Byte> &texture, Vector4f &c, Float4 &u, Float4 &v, Float4 &w, Float &lod, Float &anisotropy, Float4 &uDelta, Float4 &vDelta, Int face[4], bool secondLOD, SamplerMethod method);
+ void sampleFloat(Pointer<Byte> &texture, Vector4f &c, Float4 &u, Float4 &v, Float4 &w, Float &lod, Int face[4], bool secondLOD);
+ void sampleFloat2D(Pointer<Byte> &texture, Vector4f &c, Float4 &u, Float4 &v, Float4 &w, Float &lod, Int face[4], bool secondLOD);
+ void sampleFloat3D(Pointer<Byte> &texture, Vector4f &c, Float4 &u, Float4 &v, Float4 &w, Float &lod, bool secondLOD);
+ void computeLod(Pointer<Byte> &texture, Float &lod, Float &anisotropy, Float4 &uDelta, Float4 &vDelta, Float4 &u, Float4 &v, const Float &lodBias, Vector4f &dsx, Vector4f &dsy, SamplerMethod method);
+ void computeLodCube(Pointer<Byte> &texture, Float &lod, Float4 &x, Float4 &y, Float4 &z, const Float &lodBias, Vector4f &dsx, Vector4f &dsy, SamplerMethod method);
+ void computeLod3D(Pointer<Byte> &texture, Float &lod, Float4 &u, Float4 &v, Float4 &w, const Float &lodBias, Vector4f &dsx, Vector4f &dsy, SamplerMethod method);
+ void cubeFace(Int face[4], Float4 &U, Float4 &V, Float4 &lodX, Float4 &lodY, Float4 &lodZ, Float4 &x, Float4 &y, Float4 &z);
+ void computeIndices(Int index[4], Short4 uuuu, Short4 vvvv, Short4 wwww, const Pointer<Byte> &mipmap);
+ void sampleTexel(Vector4s &c, Short4 &u, Short4 &v, Short4 &s, Pointer<Byte> &mipmap, Pointer<Byte> buffer[4]);
+ void sampleTexel(Vector4f &c, Short4 &u, Short4 &v, Short4 &s, Float4 &z, Pointer<Byte> &mipmap, Pointer<Byte> buffer[4]);
+ 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 convertFixed12(Short4 &ci, Float4 &cf);
+ void convertFixed12(Vector4s &cs, Vector4f &cf);
+ void convertSigned12(Float4 &cf, Short4 &ci);
+ void convertSigned15(Float4 &cf, Short4 &ci);
+ void convertUnsigned16(Float4 &cf, Short4 &ci);
+ void sRGBtoLinear16_8_12(Short4 &c);
+ void sRGBtoLinear16_6_12(Short4 &c);
+ void sRGBtoLinear16_5_12(Short4 &c);
+
+ bool hasFloatTexture() const;
+ bool hasUnsignedTextureComponent(int component) const;
+ int textureComponentCount() const;
+ bool has16bitTextureFormat() const;
+ bool has8bitTextureComponents() const;
+ bool has16bitTextureComponents() const;
+ bool hasYuvFormat() const;
+ bool isRGBComponent(int component) const;
+
+ Pointer<Byte> &constants;
+ const Sampler::State &state;
+ };
+}
+
+#endif // sw_SamplerCore_hpp
diff --git a/src/Shader/SetupRoutine.cpp b/src/Shader/SetupRoutine.cpp
index 1e2e897..36753bd 100644
--- a/src/Shader/SetupRoutine.cpp
+++ b/src/Shader/SetupRoutine.cpp
@@ -1,13 +1,16 @@
-// SwiftShader Software Renderer
+// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
-// Copyright(c) 2005-2012 TransGaming Inc.
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
//
-// 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 TransGaming Inc. Without such an agreement, no rights or licenses, express
-// or implied, including but not limited to any patent rights, are granted to you.
+// http://www.apache.org/licenses/LICENSE-2.0
//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
#include "SetupRoutine.hpp"
@@ -163,7 +166,7 @@
// Vertical range
Int yMin = Y[0];
Int yMax = Y[0];
-
+
Int i = 1;
Do
diff --git a/src/Shader/SetupRoutine.hpp b/src/Shader/SetupRoutine.hpp
index ea89a04b..9534b63 100644
--- a/src/Shader/SetupRoutine.hpp
+++ b/src/Shader/SetupRoutine.hpp
@@ -1,44 +1,47 @@
-// SwiftShader Software Renderer
-//
-// Copyright(c) 2005-2012 TransGaming 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 TransGaming Inc. Without such an agreement, no rights or licenses, express
-// or implied, including but not limited to any patent rights, are granted to you.
-//
-
-#ifndef sw_SetupRoutine_hpp
-#define sw_SetupRoutine_hpp
-
-#include "SetupProcessor.hpp"
-#include "Reactor/Nucleus.hpp"
-
-namespace sw
-{
- class Context;
-
- class SetupRoutine
- {
- public:
- SetupRoutine(const SetupProcessor::State &state);
-
- virtual ~SetupRoutine();
-
- void generate();
- Routine *getRoutine();
-
- private:
- void setupGradient(Pointer<Byte> &primitive, Pointer<Byte> &triangle, Float4 &w012, Float4 (&m)[3], Pointer<Byte> &v0, Pointer<Byte> &v1, Pointer<Byte> &v2, int attribute, int planeEquation, bool flatShading, bool sprite, bool perspective, bool wrap, int component);
- void edge(Pointer<Byte> &primitive, Pointer<Byte> &data, const Int &X1, const Int &Y1, const Int &X2, const Int &Y2, Int &q);
- void conditionalRotate1(Bool condition, Pointer<Byte> &v0, Pointer<Byte> &v1, Pointer<Byte> &v2);
- void conditionalRotate2(Bool condition, Pointer<Byte> &v0, Pointer<Byte> &v1, Pointer<Byte> &v2);
-
- const SetupProcessor::State &state;
-
- Routine *routine;
- };
-}
-
-#endif // sw_SetupRoutine_hpp
+// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef sw_SetupRoutine_hpp
+#define sw_SetupRoutine_hpp
+
+#include "SetupProcessor.hpp"
+#include "Reactor/Nucleus.hpp"
+
+namespace sw
+{
+ class Context;
+
+ class SetupRoutine
+ {
+ public:
+ SetupRoutine(const SetupProcessor::State &state);
+
+ virtual ~SetupRoutine();
+
+ void generate();
+ Routine *getRoutine();
+
+ private:
+ void setupGradient(Pointer<Byte> &primitive, Pointer<Byte> &triangle, Float4 &w012, Float4 (&m)[3], Pointer<Byte> &v0, Pointer<Byte> &v1, Pointer<Byte> &v2, int attribute, int planeEquation, bool flatShading, bool sprite, bool perspective, bool wrap, int component);
+ void edge(Pointer<Byte> &primitive, Pointer<Byte> &data, const Int &X1, const Int &Y1, const Int &X2, const Int &Y2, Int &q);
+ void conditionalRotate1(Bool condition, Pointer<Byte> &v0, Pointer<Byte> &v1, Pointer<Byte> &v2);
+ void conditionalRotate2(Bool condition, Pointer<Byte> &v0, Pointer<Byte> &v1, Pointer<Byte> &v2);
+
+ const SetupProcessor::State &state;
+
+ Routine *routine;
+ };
+}
+
+#endif // sw_SetupRoutine_hpp
diff --git a/src/Shader/Shader.cpp b/src/Shader/Shader.cpp
index 7c3f9bb..8e92d2e 100644
--- a/src/Shader/Shader.cpp
+++ b/src/Shader/Shader.cpp
@@ -1,13 +1,16 @@
-// SwiftShader Software Renderer
+// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
-// Copyright(c) 2005-2013 TransGaming Inc.
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
//
-// 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 TransGaming Inc. Without such an agreement, no rights or licenses, express
-// or implied, including but not limited to any patent rights, are granted to you.
+// http://www.apache.org/licenses/LICENSE-2.0
//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
#include "Shader.hpp"
@@ -61,7 +64,7 @@
}
}
- Shader::Opcode Shader::OPCODE_NRM(int i)
+ Shader::Opcode Shader::OPCODE_NRM(int i)
{
switch(i)
{
diff --git a/src/Shader/Shader.hpp b/src/Shader/Shader.hpp
index a5785c8..d26a5b7 100644
--- a/src/Shader/Shader.hpp
+++ b/src/Shader/Shader.hpp
@@ -1,644 +1,647 @@
-// SwiftShader Software Renderer
-//
-// Copyright(c) 2005-2012 TransGaming 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 TransGaming Inc. Without such an agreement, no rights or licenses, express
-// or implied, including but not limited to any patent rights, are granted to you.
-//
-
-#ifndef sw_Shader_hpp
-#define sw_Shader_hpp
-
-#include "Common/Types.hpp"
-
-#include <string>
-#include <vector>
-
-namespace sw
-{
- class Shader
- {
- public:
- enum ShaderType
- {
- SHADER_PIXEL = 0xFFFF,
- SHADER_VERTEX = 0xFFFE,
- SHADER_GEOMETRY = 0xFFFD
- };
-
- enum Opcode
- {
- // Matches order in d3d9types.h
- OPCODE_NOP = 0,
- OPCODE_MOV,
- OPCODE_ADD,
- OPCODE_SUB,
- OPCODE_MAD,
- OPCODE_MUL,
- OPCODE_RCPX,
- OPCODE_RSQX,
- OPCODE_DP3,
- OPCODE_DP4,
- OPCODE_MIN,
- OPCODE_MAX,
- OPCODE_SLT,
- OPCODE_SGE,
- OPCODE_EXP2X, // D3DSIO_EXP
- OPCODE_LOG2X, // D3DSIO_LOG
- OPCODE_LIT,
- OPCODE_ATT, // D3DSIO_DST
- OPCODE_LRP,
- OPCODE_FRC,
- OPCODE_M4X4,
- OPCODE_M4X3,
- OPCODE_M3X4,
- OPCODE_M3X3,
- OPCODE_M3X2,
- OPCODE_CALL,
- OPCODE_CALLNZ,
- OPCODE_LOOP,
- OPCODE_RET,
- OPCODE_ENDLOOP,
- OPCODE_LABEL,
- OPCODE_DCL,
- OPCODE_POWX,
- OPCODE_CRS,
- OPCODE_SGN,
- OPCODE_ABS,
- OPCODE_NRM3, // D3DSIO_NRM
- OPCODE_SINCOS,
- OPCODE_REP,
- OPCODE_ENDREP,
- OPCODE_IF,
- OPCODE_IFC,
- OPCODE_ELSE,
- OPCODE_ENDIF,
- OPCODE_BREAK,
- OPCODE_BREAKC,
- OPCODE_MOVA,
- OPCODE_DEFB,
- OPCODE_DEFI,
-
- OPCODE_TEXCOORD = 64,
- OPCODE_TEXKILL,
- OPCODE_TEX,
- OPCODE_TEXBEM,
- OPCODE_TEXBEML,
- OPCODE_TEXREG2AR,
- OPCODE_TEXREG2GB,
- OPCODE_TEXM3X2PAD,
- OPCODE_TEXM3X2TEX,
- OPCODE_TEXM3X3PAD,
- OPCODE_TEXM3X3TEX,
- OPCODE_RESERVED0,
- OPCODE_TEXM3X3SPEC,
- OPCODE_TEXM3X3VSPEC,
- OPCODE_EXPP,
- OPCODE_LOGP,
- OPCODE_CND,
- OPCODE_DEF,
- OPCODE_TEXREG2RGB,
- OPCODE_TEXDP3TEX,
- OPCODE_TEXM3X2DEPTH,
- OPCODE_TEXDP3,
- OPCODE_TEXM3X3,
- OPCODE_TEXDEPTH,
- OPCODE_CMP0, // D3DSIO_CMP
- OPCODE_BEM,
- OPCODE_DP2ADD,
- OPCODE_DFDX, // D3DSIO_DSX
- OPCODE_DFDY, // D3DSIO_DSY
- OPCODE_TEXLDD,
- OPCODE_CMP, // D3DSIO_SETP
- OPCODE_TEXLDL,
- OPCODE_BREAKP,
- OPCODE_TEXSIZE,
-
- OPCODE_PHASE = 0xFFFD,
- OPCODE_COMMENT = 0xFFFE,
- OPCODE_END = 0xFFFF,
-
- OPCODE_PS_1_0 = 0xFFFF0100,
- OPCODE_PS_1_1 = 0xFFFF0101,
- OPCODE_PS_1_2 = 0xFFFF0102,
- OPCODE_PS_1_3 = 0xFFFF0103,
- OPCODE_PS_1_4 = 0xFFFF0104,
- OPCODE_PS_2_0 = 0xFFFF0200,
- OPCODE_PS_2_x = 0xFFFF0201,
- OPCODE_PS_3_0 = 0xFFFF0300,
-
- OPCODE_VS_1_0 = 0xFFFE0100,
- OPCODE_VS_1_1 = 0xFFFE0101,
- OPCODE_VS_2_0 = 0xFFFE0200,
- OPCODE_VS_2_x = 0xFFFE0201,
- OPCODE_VS_2_sw = 0xFFFE02FF,
- OPCODE_VS_3_0 = 0xFFFE0300,
- OPCODE_VS_3_sw = 0xFFFE03FF,
-
- OPCODE_NULL = 0x10000000, // Dead instruction, to be eliminated
- OPCODE_WHILE,
- OPCODE_ENDWHILE,
- OPCODE_COS,
- OPCODE_SIN,
- OPCODE_TAN,
- OPCODE_ACOS,
- OPCODE_ASIN,
- OPCODE_ATAN,
- OPCODE_ATAN2,
- OPCODE_COSH,
- OPCODE_SINH,
- OPCODE_TANH,
- OPCODE_ACOSH,
- OPCODE_ASINH,
- OPCODE_ATANH,
- OPCODE_DP1,
- OPCODE_DP2,
- OPCODE_TRUNC,
- OPCODE_FLOOR,
- OPCODE_ROUND,
- OPCODE_ROUNDEVEN,
- OPCODE_CEIL,
- OPCODE_SQRT,
- OPCODE_RSQ,
- OPCODE_LEN2,
- OPCODE_LEN3,
- OPCODE_LEN4,
- OPCODE_DIST1,
- OPCODE_DIST2,
- OPCODE_DIST3,
- OPCODE_DIST4,
- OPCODE_NRM2,
- OPCODE_NRM4,
- OPCODE_DIV,
- OPCODE_MOD,
- OPCODE_EXP2,
- OPCODE_LOG2,
- OPCODE_EXP,
- OPCODE_LOG,
- OPCODE_POW,
- OPCODE_F2B, // Float to bool
- OPCODE_B2F, // Bool to float
- OPCODE_F2I, // Float to int
- OPCODE_I2F, // Int to float
- OPCODE_F2U, // Float to uint
- OPCODE_U2F, // Uint to float
- OPCODE_I2B, // Int to bool
- OPCODE_B2I, // Bool to int
- OPCODE_DET2,
- OPCODE_DET3,
- OPCODE_DET4,
- OPCODE_ALL,
- OPCODE_ANY,
- OPCODE_NEG,
- OPCODE_NOT,
- OPCODE_OR,
- OPCODE_XOR,
- OPCODE_AND,
- OPCODE_EQ,
- OPCODE_NE,
- OPCODE_STEP,
- OPCODE_SMOOTH,
- OPCODE_ISNAN,
- OPCODE_ISINF,
- OPCODE_TEXOFFSET,
- OPCODE_TEXLDLOFFSET,
- OPCODE_TEXELFETCH,
- OPCODE_TEXELFETCHOFFSET,
- OPCODE_TEXGRAD,
- OPCODE_TEXGRADOFFSET,
- OPCODE_FLOATBITSTOINT,
- OPCODE_FLOATBITSTOUINT,
- OPCODE_INTBITSTOFLOAT,
- OPCODE_UINTBITSTOFLOAT,
- OPCODE_PACKSNORM2x16,
- OPCODE_PACKUNORM2x16,
- OPCODE_PACKHALF2x16,
- OPCODE_UNPACKSNORM2x16,
- OPCODE_UNPACKUNORM2x16,
- OPCODE_UNPACKHALF2x16,
- OPCODE_FORWARD1,
- OPCODE_FORWARD2,
- OPCODE_FORWARD3,
- OPCODE_FORWARD4,
- OPCODE_REFLECT1,
- OPCODE_REFLECT2,
- OPCODE_REFLECT3,
- OPCODE_REFLECT4,
- OPCODE_REFRACT1,
- OPCODE_REFRACT2,
- OPCODE_REFRACT3,
- OPCODE_REFRACT4,
- OPCODE_ICMP,
- OPCODE_UCMP,
- OPCODE_SELECT,
- OPCODE_EXTRACT,
- OPCODE_INSERT,
- OPCODE_DISCARD,
- OPCODE_FWIDTH,
- OPCODE_LEAVE, // Return before the end of the function
- OPCODE_CONTINUE,
- OPCODE_TEST, // Marks the end of the code that can be skipped by 'continue'
-
- // Integer opcodes
- OPCODE_INEG,
- OPCODE_IABS,
- OPCODE_ISGN,
- OPCODE_IADD,
- OPCODE_ISUB,
- OPCODE_IMUL,
- OPCODE_IDIV,
- OPCODE_IMAD,
- OPCODE_IMOD,
- OPCODE_SHL,
- OPCODE_ISHR,
- OPCODE_IMIN,
- OPCODE_IMAX,
-
- // Unsigned integer opcodes
- OPCODE_UDIV,
- OPCODE_UMOD,
- OPCODE_USHR,
- OPCODE_UMIN,
- OPCODE_UMAX,
- };
-
- static Opcode OPCODE_DP(int);
- static Opcode OPCODE_LEN(int);
- static Opcode OPCODE_DIST(int);
- static Opcode OPCODE_NRM(int);
- static Opcode OPCODE_FORWARD(int);
- static Opcode OPCODE_REFLECT(int);
- static Opcode OPCODE_REFRACT(int);
-
- enum Control
- {
- CONTROL_RESERVED0,
- CONTROL_GT,
- CONTROL_EQ,
- CONTROL_GE,
- CONTROL_LT,
- CONTROL_NE,
- CONTROL_LE,
- CONTROL_RESERVED1
- };
-
- enum SamplerType
- {
- SAMPLER_UNKNOWN,
- SAMPLER_1D,
- SAMPLER_2D,
- SAMPLER_CUBE,
- SAMPLER_VOLUME
- };
-
- enum Usage // For vertex input/output declarations
- {
- USAGE_POSITION = 0,
- USAGE_BLENDWEIGHT = 1,
- USAGE_BLENDINDICES = 2,
- USAGE_NORMAL = 3,
- USAGE_PSIZE = 4,
- USAGE_TEXCOORD = 5,
- USAGE_TANGENT = 6,
- USAGE_BINORMAL = 7,
- USAGE_TESSFACTOR = 8,
- USAGE_POSITIONT = 9,
- USAGE_COLOR = 10,
- USAGE_FOG = 11,
- USAGE_DEPTH = 12,
- USAGE_SAMPLE = 13
- };
-
- enum ParameterType
- {
- PARAMETER_TEMP = 0,
- PARAMETER_INPUT = 1,
- PARAMETER_CONST = 2,
- PARAMETER_TEXTURE = 3,
- PARAMETER_ADDR = 3,
- PARAMETER_RASTOUT = 4,
- PARAMETER_ATTROUT = 5,
- PARAMETER_TEXCRDOUT = 6,
- PARAMETER_OUTPUT = 6,
- PARAMETER_CONSTINT = 7,
- PARAMETER_COLOROUT = 8,
- PARAMETER_DEPTHOUT = 9,
- PARAMETER_SAMPLER = 10,
- PARAMETER_CONST2 = 11,
- PARAMETER_CONST3 = 12,
- PARAMETER_CONST4 = 13,
- PARAMETER_CONSTBOOL = 14,
- PARAMETER_LOOP = 15,
- PARAMETER_TEMPFLOAT16 = 16,
- PARAMETER_MISCTYPE = 17,
- PARAMETER_LABEL = 18,
- PARAMETER_PREDICATE = 19,
-
- // PARAMETER_FLOAT1LITERAL,
- // PARAMETER_FLOAT2LITERAL,
- // PARAMETER_FLOAT3LITERAL,
- PARAMETER_FLOAT4LITERAL,
- PARAMETER_BOOL1LITERAL,
- // PARAMETER_BOOL2LITERAL,
- // PARAMETER_BOOL3LITERAL,
- // PARAMETER_BOOL4LITERAL,
- // PARAMETER_INT1LITERAL,
- // PARAMETER_INT2LITERAL,
- // PARAMETER_INT3LITERAL,
- PARAMETER_INT4LITERAL,
-
- PARAMETER_VOID
- };
-
- enum Modifier
- {
- MODIFIER_NONE,
- MODIFIER_NEGATE,
- MODIFIER_BIAS,
- MODIFIER_BIAS_NEGATE,
- MODIFIER_SIGN,
- MODIFIER_SIGN_NEGATE,
- MODIFIER_COMPLEMENT,
- MODIFIER_X2,
- MODIFIER_X2_NEGATE,
- MODIFIER_DZ,
- MODIFIER_DW,
- MODIFIER_ABS,
- MODIFIER_ABS_NEGATE,
- MODIFIER_NOT
- };
-
- enum Analysis
- {
- // Flags indicating whether an instruction is affected by an execution enable mask
- ANALYSIS_BRANCH = 0x00000001,
- ANALYSIS_BREAK = 0x00000002,
- ANALYSIS_CONTINUE = 0x00000004,
- ANALYSIS_LEAVE = 0x00000008,
- };
-
- struct Parameter
- {
- union
- {
- struct
- {
- unsigned int index; // For registers types
-
- struct
- {
- ParameterType type : 8;
- unsigned int index;
- unsigned int swizzle : 8;
- unsigned int scale;
- bool deterministic; // Equal accross shader instances run in lockstep (e.g. unrollable loop couters)
- } rel;
- };
-
- float value[4]; // For float constants
- int integer[4]; // For integer constants
- int boolean[4]; // For boolean constants
-
- struct
- {
- unsigned int label; // Label index
- unsigned int callSite; // Call index (per label)
- };
- };
-
- Parameter() : index(0), type(PARAMETER_VOID)
- {
- rel.type = PARAMETER_VOID;
- rel.index = 0;
- rel.swizzle = 0;
- rel.scale = 1;
- rel.deterministic = false;
- }
-
- std::string string(ShaderType shaderType, unsigned short version) const;
- std::string typeString(ShaderType shaderType, unsigned short version) const;
- std::string relativeString() const;
-
- ParameterType type : 8;
- };
-
- struct DestinationParameter : Parameter
- {
- union
- {
- unsigned char mask;
-
- struct
- {
- bool x : 1;
- bool y : 1;
- bool z : 1;
- bool w : 1;
- };
- };
-
- DestinationParameter() : mask(0xF), integer(false), saturate(false), partialPrecision(false), centroid(false), shift(0)
- {
- }
-
- std::string modifierString() const;
- std::string shiftString() const;
- std::string maskString() const;
-
- bool integer : 1;
- bool saturate : 1;
- bool partialPrecision : 1;
- bool centroid : 1;
- signed char shift : 4;
- };
-
- struct SourceParameter : Parameter
- {
- SourceParameter() : swizzle(0xE4), modifier(MODIFIER_NONE), bufferIndex(-1)
- {
- }
-
- std::string swizzleString() const;
- std::string preModifierString() const;
- std::string postModifierString() const;
-
- unsigned int swizzle : 8;
- Modifier modifier : 8;
- int bufferIndex : 8;
- };
-
- struct Instruction
- {
- explicit Instruction(Opcode opcode);
- Instruction(const unsigned long *token, int size, unsigned char majorVersion);
-
- virtual ~Instruction();
-
- void parseOperationToken(unsigned long token, unsigned char majorVersion);
- void parseDeclarationToken(unsigned long token);
- void parseDestinationToken(const unsigned long *token, unsigned char majorVersion);
- void parseSourceToken(int i, const unsigned long *token, unsigned char majorVersion);
-
- std::string string(ShaderType shaderType, unsigned short version) const;
- static std::string swizzleString(ParameterType type, unsigned char swizzle);
- std::string operationString(unsigned short version) const;
- std::string controlString() const;
-
- bool isBranch() const;
- bool isCall() const;
- bool isBreak() const;
- bool isLoop() const;
- bool isEndLoop() const;
-
- bool isPredicated() const;
-
- Opcode opcode;
-
- union
- {
- Control control;
-
- struct
- {
- unsigned char project : 1;
- unsigned char bias : 1;
- };
- };
-
- bool predicate;
- bool predicateNot; // Negative predicate
- unsigned char predicateSwizzle;
-
- bool coissue;
- SamplerType samplerType;
- Usage usage;
- unsigned char usageIndex;
-
- DestinationParameter dst;
- SourceParameter src[5];
-
- union
- {
- unsigned int analysis;
-
- struct
- {
- // Keep in sync with Shader::Analysis flags
- unsigned int analysisBranch : 1;
- unsigned int analysisBreak : 1;
- unsigned int analysisContinue : 1;
- unsigned int analysisLeave : 1;
- };
- };
- };
-
- Shader();
-
- virtual ~Shader();
-
- int getSerialID() const;
- size_t getLength() const;
- ShaderType getShaderType() const;
- unsigned short getVersion() const;
-
- void append(Instruction *instruction);
- void declareSampler(int i);
-
- const Instruction *getInstruction(unsigned int i) const;
- int size(unsigned long opcode) const;
- static int size(unsigned long opcode, unsigned short version);
-
- void print(const char *fileName, ...) const;
- void printInstruction(int index, const char *fileName) const;
-
- static bool maskContainsComponent(int mask, int component);
- static bool swizzleContainsComponent(int swizzle, int component);
- static bool swizzleContainsComponentMasked(int swizzle, int component, int mask);
-
- bool containsDynamicBranching() const;
- bool containsBreakInstruction() const;
- bool containsContinueInstruction() const;
- bool containsLeaveInstruction() const;
- bool containsDefineInstruction() const;
- bool usesSampler(int i) const;
-
- struct Semantic
- {
- Semantic(unsigned char usage = 0xFF, unsigned char index = 0xFF) : usage(usage), index(index), centroid(false)
- {
- }
-
- bool operator==(const Semantic &semantic) const
- {
- return usage == semantic.usage && index == semantic.index;
- }
-
- bool active() const
- {
- return usage != 0xFF;
- }
-
- unsigned char usage;
- unsigned char index;
- bool centroid;
- };
-
- void optimize();
- virtual void analyze() = 0;
-
- // FIXME: Private
- unsigned int dirtyConstantsF;
- unsigned int dirtyConstantsI;
- unsigned int dirtyConstantsB;
-
- bool dynamicallyIndexedTemporaries;
- bool dynamicallyIndexedInput;
- bool dynamicallyIndexedOutput;
-
- protected:
- void parse(const unsigned long *token);
-
- void optimizeLeave();
- void optimizeCall();
- void removeNull();
-
- void analyzeDirtyConstants();
- void analyzeDynamicBranching();
- void analyzeSamplers();
- void analyzeCallSites();
- void analyzeDynamicIndexing();
- void markFunctionAnalysis(unsigned int functionLabel, Analysis flag);
-
- ShaderType shaderType;
-
- union
- {
- unsigned short version;
-
- struct
- {
- unsigned char minorVersion;
- unsigned char majorVersion;
- };
- };
-
- std::vector<Instruction*> instruction;
-
- unsigned short usedSamplers; // Bit flags
-
- private:
- const int serialID;
- static volatile int serialCounter;
-
- bool dynamicBranching;
- bool containsBreak;
- bool containsContinue;
- bool containsLeave;
- bool containsDefine;
- };
-}
-
-#endif // sw_Shader_hpp
+// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef sw_Shader_hpp
+#define sw_Shader_hpp
+
+#include "Common/Types.hpp"
+
+#include <string>
+#include <vector>
+
+namespace sw
+{
+ class Shader
+ {
+ public:
+ enum ShaderType
+ {
+ SHADER_PIXEL = 0xFFFF,
+ SHADER_VERTEX = 0xFFFE,
+ SHADER_GEOMETRY = 0xFFFD
+ };
+
+ enum Opcode
+ {
+ // Matches order in d3d9types.h
+ OPCODE_NOP = 0,
+ OPCODE_MOV,
+ OPCODE_ADD,
+ OPCODE_SUB,
+ OPCODE_MAD,
+ OPCODE_MUL,
+ OPCODE_RCPX,
+ OPCODE_RSQX,
+ OPCODE_DP3,
+ OPCODE_DP4,
+ OPCODE_MIN,
+ OPCODE_MAX,
+ OPCODE_SLT,
+ OPCODE_SGE,
+ OPCODE_EXP2X, // D3DSIO_EXP
+ OPCODE_LOG2X, // D3DSIO_LOG
+ OPCODE_LIT,
+ OPCODE_ATT, // D3DSIO_DST
+ OPCODE_LRP,
+ OPCODE_FRC,
+ OPCODE_M4X4,
+ OPCODE_M4X3,
+ OPCODE_M3X4,
+ OPCODE_M3X3,
+ OPCODE_M3X2,
+ OPCODE_CALL,
+ OPCODE_CALLNZ,
+ OPCODE_LOOP,
+ OPCODE_RET,
+ OPCODE_ENDLOOP,
+ OPCODE_LABEL,
+ OPCODE_DCL,
+ OPCODE_POWX,
+ OPCODE_CRS,
+ OPCODE_SGN,
+ OPCODE_ABS,
+ OPCODE_NRM3, // D3DSIO_NRM
+ OPCODE_SINCOS,
+ OPCODE_REP,
+ OPCODE_ENDREP,
+ OPCODE_IF,
+ OPCODE_IFC,
+ OPCODE_ELSE,
+ OPCODE_ENDIF,
+ OPCODE_BREAK,
+ OPCODE_BREAKC,
+ OPCODE_MOVA,
+ OPCODE_DEFB,
+ OPCODE_DEFI,
+
+ OPCODE_TEXCOORD = 64,
+ OPCODE_TEXKILL,
+ OPCODE_TEX,
+ OPCODE_TEXBEM,
+ OPCODE_TEXBEML,
+ OPCODE_TEXREG2AR,
+ OPCODE_TEXREG2GB,
+ OPCODE_TEXM3X2PAD,
+ OPCODE_TEXM3X2TEX,
+ OPCODE_TEXM3X3PAD,
+ OPCODE_TEXM3X3TEX,
+ OPCODE_RESERVED0,
+ OPCODE_TEXM3X3SPEC,
+ OPCODE_TEXM3X3VSPEC,
+ OPCODE_EXPP,
+ OPCODE_LOGP,
+ OPCODE_CND,
+ OPCODE_DEF,
+ OPCODE_TEXREG2RGB,
+ OPCODE_TEXDP3TEX,
+ OPCODE_TEXM3X2DEPTH,
+ OPCODE_TEXDP3,
+ OPCODE_TEXM3X3,
+ OPCODE_TEXDEPTH,
+ OPCODE_CMP0, // D3DSIO_CMP
+ OPCODE_BEM,
+ OPCODE_DP2ADD,
+ OPCODE_DFDX, // D3DSIO_DSX
+ OPCODE_DFDY, // D3DSIO_DSY
+ OPCODE_TEXLDD,
+ OPCODE_CMP, // D3DSIO_SETP
+ OPCODE_TEXLDL,
+ OPCODE_BREAKP,
+ OPCODE_TEXSIZE,
+
+ OPCODE_PHASE = 0xFFFD,
+ OPCODE_COMMENT = 0xFFFE,
+ OPCODE_END = 0xFFFF,
+
+ OPCODE_PS_1_0 = 0xFFFF0100,
+ OPCODE_PS_1_1 = 0xFFFF0101,
+ OPCODE_PS_1_2 = 0xFFFF0102,
+ OPCODE_PS_1_3 = 0xFFFF0103,
+ OPCODE_PS_1_4 = 0xFFFF0104,
+ OPCODE_PS_2_0 = 0xFFFF0200,
+ OPCODE_PS_2_x = 0xFFFF0201,
+ OPCODE_PS_3_0 = 0xFFFF0300,
+
+ OPCODE_VS_1_0 = 0xFFFE0100,
+ OPCODE_VS_1_1 = 0xFFFE0101,
+ OPCODE_VS_2_0 = 0xFFFE0200,
+ OPCODE_VS_2_x = 0xFFFE0201,
+ OPCODE_VS_2_sw = 0xFFFE02FF,
+ OPCODE_VS_3_0 = 0xFFFE0300,
+ OPCODE_VS_3_sw = 0xFFFE03FF,
+
+ OPCODE_NULL = 0x10000000, // Dead instruction, to be eliminated
+ OPCODE_WHILE,
+ OPCODE_ENDWHILE,
+ OPCODE_COS,
+ OPCODE_SIN,
+ OPCODE_TAN,
+ OPCODE_ACOS,
+ OPCODE_ASIN,
+ OPCODE_ATAN,
+ OPCODE_ATAN2,
+ OPCODE_COSH,
+ OPCODE_SINH,
+ OPCODE_TANH,
+ OPCODE_ACOSH,
+ OPCODE_ASINH,
+ OPCODE_ATANH,
+ OPCODE_DP1,
+ OPCODE_DP2,
+ OPCODE_TRUNC,
+ OPCODE_FLOOR,
+ OPCODE_ROUND,
+ OPCODE_ROUNDEVEN,
+ OPCODE_CEIL,
+ OPCODE_SQRT,
+ OPCODE_RSQ,
+ OPCODE_LEN2,
+ OPCODE_LEN3,
+ OPCODE_LEN4,
+ OPCODE_DIST1,
+ OPCODE_DIST2,
+ OPCODE_DIST3,
+ OPCODE_DIST4,
+ OPCODE_NRM2,
+ OPCODE_NRM4,
+ OPCODE_DIV,
+ OPCODE_MOD,
+ OPCODE_EXP2,
+ OPCODE_LOG2,
+ OPCODE_EXP,
+ OPCODE_LOG,
+ OPCODE_POW,
+ OPCODE_F2B, // Float to bool
+ OPCODE_B2F, // Bool to float
+ OPCODE_F2I, // Float to int
+ OPCODE_I2F, // Int to float
+ OPCODE_F2U, // Float to uint
+ OPCODE_U2F, // Uint to float
+ OPCODE_I2B, // Int to bool
+ OPCODE_B2I, // Bool to int
+ OPCODE_DET2,
+ OPCODE_DET3,
+ OPCODE_DET4,
+ OPCODE_ALL,
+ OPCODE_ANY,
+ OPCODE_NEG,
+ OPCODE_NOT,
+ OPCODE_OR,
+ OPCODE_XOR,
+ OPCODE_AND,
+ OPCODE_EQ,
+ OPCODE_NE,
+ OPCODE_STEP,
+ OPCODE_SMOOTH,
+ OPCODE_ISNAN,
+ OPCODE_ISINF,
+ OPCODE_TEXOFFSET,
+ OPCODE_TEXLDLOFFSET,
+ OPCODE_TEXELFETCH,
+ OPCODE_TEXELFETCHOFFSET,
+ OPCODE_TEXGRAD,
+ OPCODE_TEXGRADOFFSET,
+ OPCODE_FLOATBITSTOINT,
+ OPCODE_FLOATBITSTOUINT,
+ OPCODE_INTBITSTOFLOAT,
+ OPCODE_UINTBITSTOFLOAT,
+ OPCODE_PACKSNORM2x16,
+ OPCODE_PACKUNORM2x16,
+ OPCODE_PACKHALF2x16,
+ OPCODE_UNPACKSNORM2x16,
+ OPCODE_UNPACKUNORM2x16,
+ OPCODE_UNPACKHALF2x16,
+ OPCODE_FORWARD1,
+ OPCODE_FORWARD2,
+ OPCODE_FORWARD3,
+ OPCODE_FORWARD4,
+ OPCODE_REFLECT1,
+ OPCODE_REFLECT2,
+ OPCODE_REFLECT3,
+ OPCODE_REFLECT4,
+ OPCODE_REFRACT1,
+ OPCODE_REFRACT2,
+ OPCODE_REFRACT3,
+ OPCODE_REFRACT4,
+ OPCODE_ICMP,
+ OPCODE_UCMP,
+ OPCODE_SELECT,
+ OPCODE_EXTRACT,
+ OPCODE_INSERT,
+ OPCODE_DISCARD,
+ OPCODE_FWIDTH,
+ OPCODE_LEAVE, // Return before the end of the function
+ OPCODE_CONTINUE,
+ OPCODE_TEST, // Marks the end of the code that can be skipped by 'continue'
+
+ // Integer opcodes
+ OPCODE_INEG,
+ OPCODE_IABS,
+ OPCODE_ISGN,
+ OPCODE_IADD,
+ OPCODE_ISUB,
+ OPCODE_IMUL,
+ OPCODE_IDIV,
+ OPCODE_IMAD,
+ OPCODE_IMOD,
+ OPCODE_SHL,
+ OPCODE_ISHR,
+ OPCODE_IMIN,
+ OPCODE_IMAX,
+
+ // Unsigned integer opcodes
+ OPCODE_UDIV,
+ OPCODE_UMOD,
+ OPCODE_USHR,
+ OPCODE_UMIN,
+ OPCODE_UMAX,
+ };
+
+ static Opcode OPCODE_DP(int);
+ static Opcode OPCODE_LEN(int);
+ static Opcode OPCODE_DIST(int);
+ static Opcode OPCODE_NRM(int);
+ static Opcode OPCODE_FORWARD(int);
+ static Opcode OPCODE_REFLECT(int);
+ static Opcode OPCODE_REFRACT(int);
+
+ enum Control
+ {
+ CONTROL_RESERVED0,
+ CONTROL_GT,
+ CONTROL_EQ,
+ CONTROL_GE,
+ CONTROL_LT,
+ CONTROL_NE,
+ CONTROL_LE,
+ CONTROL_RESERVED1
+ };
+
+ enum SamplerType
+ {
+ SAMPLER_UNKNOWN,
+ SAMPLER_1D,
+ SAMPLER_2D,
+ SAMPLER_CUBE,
+ SAMPLER_VOLUME
+ };
+
+ enum Usage // For vertex input/output declarations
+ {
+ USAGE_POSITION = 0,
+ USAGE_BLENDWEIGHT = 1,
+ USAGE_BLENDINDICES = 2,
+ USAGE_NORMAL = 3,
+ USAGE_PSIZE = 4,
+ USAGE_TEXCOORD = 5,
+ USAGE_TANGENT = 6,
+ USAGE_BINORMAL = 7,
+ USAGE_TESSFACTOR = 8,
+ USAGE_POSITIONT = 9,
+ USAGE_COLOR = 10,
+ USAGE_FOG = 11,
+ USAGE_DEPTH = 12,
+ USAGE_SAMPLE = 13
+ };
+
+ enum ParameterType
+ {
+ PARAMETER_TEMP = 0,
+ PARAMETER_INPUT = 1,
+ PARAMETER_CONST = 2,
+ PARAMETER_TEXTURE = 3,
+ PARAMETER_ADDR = 3,
+ PARAMETER_RASTOUT = 4,
+ PARAMETER_ATTROUT = 5,
+ PARAMETER_TEXCRDOUT = 6,
+ PARAMETER_OUTPUT = 6,
+ PARAMETER_CONSTINT = 7,
+ PARAMETER_COLOROUT = 8,
+ PARAMETER_DEPTHOUT = 9,
+ PARAMETER_SAMPLER = 10,
+ PARAMETER_CONST2 = 11,
+ PARAMETER_CONST3 = 12,
+ PARAMETER_CONST4 = 13,
+ PARAMETER_CONSTBOOL = 14,
+ PARAMETER_LOOP = 15,
+ PARAMETER_TEMPFLOAT16 = 16,
+ PARAMETER_MISCTYPE = 17,
+ PARAMETER_LABEL = 18,
+ PARAMETER_PREDICATE = 19,
+
+ // PARAMETER_FLOAT1LITERAL,
+ // PARAMETER_FLOAT2LITERAL,
+ // PARAMETER_FLOAT3LITERAL,
+ PARAMETER_FLOAT4LITERAL,
+ PARAMETER_BOOL1LITERAL,
+ // PARAMETER_BOOL2LITERAL,
+ // PARAMETER_BOOL3LITERAL,
+ // PARAMETER_BOOL4LITERAL,
+ // PARAMETER_INT1LITERAL,
+ // PARAMETER_INT2LITERAL,
+ // PARAMETER_INT3LITERAL,
+ PARAMETER_INT4LITERAL,
+
+ PARAMETER_VOID
+ };
+
+ enum Modifier
+ {
+ MODIFIER_NONE,
+ MODIFIER_NEGATE,
+ MODIFIER_BIAS,
+ MODIFIER_BIAS_NEGATE,
+ MODIFIER_SIGN,
+ MODIFIER_SIGN_NEGATE,
+ MODIFIER_COMPLEMENT,
+ MODIFIER_X2,
+ MODIFIER_X2_NEGATE,
+ MODIFIER_DZ,
+ MODIFIER_DW,
+ MODIFIER_ABS,
+ MODIFIER_ABS_NEGATE,
+ MODIFIER_NOT
+ };
+
+ enum Analysis
+ {
+ // Flags indicating whether an instruction is affected by an execution enable mask
+ ANALYSIS_BRANCH = 0x00000001,
+ ANALYSIS_BREAK = 0x00000002,
+ ANALYSIS_CONTINUE = 0x00000004,
+ ANALYSIS_LEAVE = 0x00000008,
+ };
+
+ struct Parameter
+ {
+ union
+ {
+ struct
+ {
+ unsigned int index; // For registers types
+
+ struct
+ {
+ ParameterType type : 8;
+ unsigned int index;
+ unsigned int swizzle : 8;
+ unsigned int scale;
+ bool deterministic; // Equal accross shader instances run in lockstep (e.g. unrollable loop couters)
+ } rel;
+ };
+
+ float value[4]; // For float constants
+ int integer[4]; // For integer constants
+ int boolean[4]; // For boolean constants
+
+ struct
+ {
+ unsigned int label; // Label index
+ unsigned int callSite; // Call index (per label)
+ };
+ };
+
+ Parameter() : index(0), type(PARAMETER_VOID)
+ {
+ rel.type = PARAMETER_VOID;
+ rel.index = 0;
+ rel.swizzle = 0;
+ rel.scale = 1;
+ rel.deterministic = false;
+ }
+
+ std::string string(ShaderType shaderType, unsigned short version) const;
+ std::string typeString(ShaderType shaderType, unsigned short version) const;
+ std::string relativeString() const;
+
+ ParameterType type : 8;
+ };
+
+ struct DestinationParameter : Parameter
+ {
+ union
+ {
+ unsigned char mask;
+
+ struct
+ {
+ bool x : 1;
+ bool y : 1;
+ bool z : 1;
+ bool w : 1;
+ };
+ };
+
+ DestinationParameter() : mask(0xF), integer(false), saturate(false), partialPrecision(false), centroid(false), shift(0)
+ {
+ }
+
+ std::string modifierString() const;
+ std::string shiftString() const;
+ std::string maskString() const;
+
+ bool integer : 1;
+ bool saturate : 1;
+ bool partialPrecision : 1;
+ bool centroid : 1;
+ signed char shift : 4;
+ };
+
+ struct SourceParameter : Parameter
+ {
+ SourceParameter() : swizzle(0xE4), modifier(MODIFIER_NONE), bufferIndex(-1)
+ {
+ }
+
+ std::string swizzleString() const;
+ std::string preModifierString() const;
+ std::string postModifierString() const;
+
+ unsigned int swizzle : 8;
+ Modifier modifier : 8;
+ int bufferIndex : 8;
+ };
+
+ struct Instruction
+ {
+ explicit Instruction(Opcode opcode);
+ Instruction(const unsigned long *token, int size, unsigned char majorVersion);
+
+ virtual ~Instruction();
+
+ void parseOperationToken(unsigned long token, unsigned char majorVersion);
+ void parseDeclarationToken(unsigned long token);
+ void parseDestinationToken(const unsigned long *token, unsigned char majorVersion);
+ void parseSourceToken(int i, const unsigned long *token, unsigned char majorVersion);
+
+ std::string string(ShaderType shaderType, unsigned short version) const;
+ static std::string swizzleString(ParameterType type, unsigned char swizzle);
+ std::string operationString(unsigned short version) const;
+ std::string controlString() const;
+
+ bool isBranch() const;
+ bool isCall() const;
+ bool isBreak() const;
+ bool isLoop() const;
+ bool isEndLoop() const;
+
+ bool isPredicated() const;
+
+ Opcode opcode;
+
+ union
+ {
+ Control control;
+
+ struct
+ {
+ unsigned char project : 1;
+ unsigned char bias : 1;
+ };
+ };
+
+ bool predicate;
+ bool predicateNot; // Negative predicate
+ unsigned char predicateSwizzle;
+
+ bool coissue;
+ SamplerType samplerType;
+ Usage usage;
+ unsigned char usageIndex;
+
+ DestinationParameter dst;
+ SourceParameter src[5];
+
+ union
+ {
+ unsigned int analysis;
+
+ struct
+ {
+ // Keep in sync with Shader::Analysis flags
+ unsigned int analysisBranch : 1;
+ unsigned int analysisBreak : 1;
+ unsigned int analysisContinue : 1;
+ unsigned int analysisLeave : 1;
+ };
+ };
+ };
+
+ Shader();
+
+ virtual ~Shader();
+
+ int getSerialID() const;
+ size_t getLength() const;
+ ShaderType getShaderType() const;
+ unsigned short getVersion() const;
+
+ void append(Instruction *instruction);
+ void declareSampler(int i);
+
+ const Instruction *getInstruction(unsigned int i) const;
+ int size(unsigned long opcode) const;
+ static int size(unsigned long opcode, unsigned short version);
+
+ void print(const char *fileName, ...) const;
+ void printInstruction(int index, const char *fileName) const;
+
+ static bool maskContainsComponent(int mask, int component);
+ static bool swizzleContainsComponent(int swizzle, int component);
+ static bool swizzleContainsComponentMasked(int swizzle, int component, int mask);
+
+ bool containsDynamicBranching() const;
+ bool containsBreakInstruction() const;
+ bool containsContinueInstruction() const;
+ bool containsLeaveInstruction() const;
+ bool containsDefineInstruction() const;
+ bool usesSampler(int i) const;
+
+ struct Semantic
+ {
+ Semantic(unsigned char usage = 0xFF, unsigned char index = 0xFF) : usage(usage), index(index), centroid(false)
+ {
+ }
+
+ bool operator==(const Semantic &semantic) const
+ {
+ return usage == semantic.usage && index == semantic.index;
+ }
+
+ bool active() const
+ {
+ return usage != 0xFF;
+ }
+
+ unsigned char usage;
+ unsigned char index;
+ bool centroid;
+ };
+
+ void optimize();
+ virtual void analyze() = 0;
+
+ // FIXME: Private
+ unsigned int dirtyConstantsF;
+ unsigned int dirtyConstantsI;
+ unsigned int dirtyConstantsB;
+
+ bool dynamicallyIndexedTemporaries;
+ bool dynamicallyIndexedInput;
+ bool dynamicallyIndexedOutput;
+
+ protected:
+ void parse(const unsigned long *token);
+
+ void optimizeLeave();
+ void optimizeCall();
+ void removeNull();
+
+ void analyzeDirtyConstants();
+ void analyzeDynamicBranching();
+ void analyzeSamplers();
+ void analyzeCallSites();
+ void analyzeDynamicIndexing();
+ void markFunctionAnalysis(unsigned int functionLabel, Analysis flag);
+
+ ShaderType shaderType;
+
+ union
+ {
+ unsigned short version;
+
+ struct
+ {
+ unsigned char minorVersion;
+ unsigned char majorVersion;
+ };
+ };
+
+ std::vector<Instruction*> instruction;
+
+ unsigned short usedSamplers; // Bit flags
+
+ private:
+ const int serialID;
+ static volatile int serialCounter;
+
+ bool dynamicBranching;
+ bool containsBreak;
+ bool containsContinue;
+ bool containsLeave;
+ bool containsDefine;
+ };
+}
+
+#endif // sw_Shader_hpp
diff --git a/src/Shader/ShaderCore.cpp b/src/Shader/ShaderCore.cpp
index b978d9e..685848a 100644
--- a/src/Shader/ShaderCore.cpp
+++ b/src/Shader/ShaderCore.cpp
@@ -1,13 +1,16 @@
-// SwiftShader Software Renderer
+// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
-// Copyright(c) 2005-2012 TransGaming Inc.
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
//
-// 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 TransGaming Inc. Without such an agreement, no rights or licenses, express
-// or implied, including but not limited to any patent rights, are granted to you.
+// http://www.apache.org/licenses/LICENSE-2.0
//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
#include "ShaderCore.hpp"
@@ -200,7 +203,7 @@
Float4 x0;
Float4 x1;
Int4 x2;
-
+
x0 = x;
x0 = Min(x0, As<Float4>(Int4(0x43010000))); // 129.00000e+0f
@@ -224,7 +227,7 @@
x1 *= x0;
x1 += As<Float4>(Int4(0x3F7FFFFF)); // 9.9999994e-1f
x1 *= As<Float4>(x2);
-
+
return x1;
}
@@ -234,9 +237,9 @@
Float4 x1;
Float4 x2;
Float4 x3;
-
+
x0 = x;
-
+
x1 = As<Float4>(As<Int4>(x0) & Int4(0x7F800000));
x1 = As<Float4>(As<UInt4>(x1) >> 8);
x1 = As<Float4>(As<Int4>(x1) | As<Int4>(Float4(1.0f)));
@@ -248,7 +251,7 @@
x2 /= x3;
x1 += (x0 - Float4(1.0f)) * x2;
-
+
return x1;
}
@@ -357,7 +360,7 @@
{
// cos(x) = sin(x + pi/2)
Float4 y = x + Float4(1.57079632e+0f);
-
+
// Wrap around
y -= As<Float4>(CmpNLT(y, Float4(3.14159265e+0f)) & As<Int4>(Float4(6.28318530e+0f)));
@@ -418,7 +421,7 @@
// Approximation of atan in [-1..1]
Float4 theta = y * (Float4(-0.27f) * Abs(y) + Float4(1.05539816f));
-
+
// +/-pi/2 depending on sign of x
Float4 sgnPi_2 = As<Float4>(As<Int4>(Float4(1.57079632e+0f)) ^ (As<Int4>(x) & Int4(0x80000000)));
@@ -1029,7 +1032,7 @@
}
void ShaderCore::exp2x(Vector4f &dst, const Vector4f &src, bool pp)
- {
+ {
Float4 exp = exponential2(src.x, pp);
dst.x = exp;
@@ -1132,7 +1135,7 @@
static const uint32_t c_nanbit = 0x200;
static const uint32_t c_infty_as_fp16 = 0x7c00;
static const uint32_t c_clamp = (31 << 23) - 0x1000;
-
+
UInt4 justsign = UInt4(mask_sign) & As<UInt4>(floatBits);
UInt4 absf = As<UInt4>(floatBits) ^ justsign;
UInt4 b_isnormal = CmpNLE(UInt4(c_f32infty), absf);
@@ -1347,7 +1350,7 @@
dst.z = As<Float4>(flip ^ As<Int4>(N.z));
dst.w = As<Float4>(flip ^ As<Int4>(N.w));
}
-
+
void ShaderCore::reflect1(Vector4f &dst, const Vector4f &I, const Vector4f &N)
{
Float4 d = N.x * I.x;
@@ -1492,7 +1495,7 @@
dst.z = src.z * rsq;
dst.w = src.w * rsq;
}
-
+
void ShaderCore::sincos(Vector4f &dst, const Vector4f &src, bool pp)
{
dst.x = cosine_pi(src.x, pp);
@@ -1620,7 +1623,7 @@
exp2x(dst, src, true); // FIXME: 10-bit precision suffices
}
}
-
+
void ShaderCore::logp(Vector4f &dst, const Vector4f &src, unsigned short version)
{
if(version < 0x0200)
@@ -1651,7 +1654,7 @@
log2x(dst, src, true);
}
}
-
+
void ShaderCore::cmp0(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2)
{
cmp0(dst.x, src0.x, src1.x, src2.x);
diff --git a/src/Shader/ShaderCore.hpp b/src/Shader/ShaderCore.hpp
index 7eeec42..f105c50 100644
--- a/src/Shader/ShaderCore.hpp
+++ b/src/Shader/ShaderCore.hpp
@@ -1,393 +1,396 @@
-// SwiftShader Software Renderer
-//
-// Copyright(c) 2005-2012 TransGaming 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 TransGaming Inc. Without such an agreement, no rights or licenses, express
-// or implied, including but not limited to any patent rights, are granted to you.
-//
-
-#ifndef sw_ShaderCore_hpp
-#define sw_ShaderCore_hpp
-
-#include "Debug.hpp"
-#include "Shader.hpp"
-#include "Reactor/Reactor.hpp"
-
-namespace sw
-{
- class Vector4s
- {
- public:
- Vector4s();
- Vector4s(unsigned short x, unsigned short y, unsigned short z, unsigned short w);
- Vector4s(const Vector4s &rhs);
-
- Short4 &operator[](int i);
- Vector4s &operator=(const Vector4s &rhs);
-
- Short4 x;
- Short4 y;
- Short4 z;
- Short4 w;
- };
-
- class Vector4i
- {
- public:
- Vector4i();
- Vector4i(int x, int y, int z, int w);
- Vector4i(const Vector4i &rhs);
-
- Int4 &operator[](int i);
- Vector4i &operator=(const Vector4i &rhs);
-
- Int4 x;
- Int4 y;
- Int4 z;
- Int4 w;
- };
-
- class Vector4u
- {
- public:
- Vector4u();
- Vector4u(unsigned int x, unsigned int y, unsigned int z, unsigned int w);
- Vector4u(const Vector4u &rhs);
-
- UInt4 &operator[](int i);
- Vector4u &operator=(const Vector4u &rhs);
-
- UInt4 x;
- UInt4 y;
- UInt4 z;
- UInt4 w;
- };
-
- class Vector4f
- {
- public:
- Vector4f();
- Vector4f(float x, float y, float z, float w);
- Vector4f(const Vector4f &rhs);
-
- Float4 &operator[](int i);
- Vector4f &operator=(const Vector4f &rhs);
-
- Float4 x;
- Float4 y;
- Float4 z;
- Float4 w;
- };
-
- Float4 exponential2(RValue<Float4> x, bool pp = false);
- Float4 logarithm2(RValue<Float4> x, bool abs, bool pp = false);
- Float4 exponential(RValue<Float4> x, bool pp = false);
- Float4 logarithm(RValue<Float4> x, bool abs, bool pp = false);
- Float4 power(RValue<Float4> x, RValue<Float4> y, bool pp = false);
- Float4 reciprocal(RValue<Float4> x, bool pp = false, bool finite = false, bool exactAtPow2 = false);
- Float4 reciprocalSquareRoot(RValue<Float4> x, bool abs, bool pp = false);
- Float4 modulo(RValue<Float4> x, RValue<Float4> y);
- Float4 sine_pi(RValue<Float4> x, bool pp = false); // limited to [-pi, pi] range
- Float4 cosine_pi(RValue<Float4> x, bool pp = false); // limited to [-pi, pi] range
- Float4 sine(RValue<Float4> x, bool pp = false);
- Float4 cosine(RValue<Float4> x, bool pp = false);
- Float4 tangent(RValue<Float4> x, bool pp = false);
- Float4 arccos(RValue<Float4> x, bool pp = false);
- Float4 arcsin(RValue<Float4> x, bool pp = false);
- Float4 arctan(RValue<Float4> x, bool pp = false);
- Float4 arctan(RValue<Float4> y, RValue<Float4> x, bool pp = false);
- Float4 sineh(RValue<Float4> x, bool pp = false);
- Float4 cosineh(RValue<Float4> x, bool pp = false);
- Float4 tangenth(RValue<Float4> x, bool pp = false);
- Float4 arccosh(RValue<Float4> x, bool pp = false); // Limited to x >= 1
- Float4 arcsinh(RValue<Float4> x, bool pp = false);
- Float4 arctanh(RValue<Float4> x, bool pp = false); // Limited to ]-1, 1[ range
-
- Float4 dot2(const Vector4f &v0, const Vector4f &v1);
- Float4 dot3(const Vector4f &v0, const Vector4f &v1);
- Float4 dot4(const Vector4f &v0, const Vector4f &v1);
-
- void transpose4x4(Short4 &row0, Short4 &row1, Short4 &row2, Short4 &row3);
- void transpose4x4(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3);
- void transpose4x3(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3);
- void transpose4x2(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3);
- void transpose4x1(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3);
- void transpose2x4(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3);
- void transpose2x4h(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3);
- void transpose4xN(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3, int N);
-
- class Register
- {
- public:
- Register(const Reference<Float4> &x, const Reference<Float4> &y, const Reference<Float4> &z, const Reference<Float4> &w) : x(x), y(y), z(z), w(w)
- {
- }
-
- Reference<Float4> &operator[](int i)
- {
- switch(i)
- {
- default:
- case 0: return x;
- case 1: return y;
- case 2: return z;
- case 3: return w;
- }
- }
-
- Register &operator=(const Register &rhs)
- {
- x = rhs.x;
- y = rhs.y;
- z = rhs.z;
- w = rhs.w;
-
- return *this;
- }
-
- Register &operator=(const Vector4f &rhs)
- {
- x = rhs.x;
- y = rhs.y;
- z = rhs.z;
- w = rhs.w;
-
- return *this;
- }
-
- operator Vector4f()
- {
- Vector4f v;
-
- v.x = x;
- v.y = y;
- v.z = z;
- v.w = w;
-
- return v;
- }
-
- Reference<Float4> x;
- Reference<Float4> y;
- Reference<Float4> z;
- Reference<Float4> w;
- };
-
- template<int S, bool D = false>
- class RegisterArray
- {
- public:
- RegisterArray(bool dynamic = D) : dynamic(dynamic)
- {
- if(dynamic)
- {
- x = new Array<Float4>(S);
- y = new Array<Float4>(S);
- z = new Array<Float4>(S);
- w = new Array<Float4>(S);
- }
- else
- {
- x = new Array<Float4>[S];
- y = new Array<Float4>[S];
- z = new Array<Float4>[S];
- w = new Array<Float4>[S];
- }
- }
-
- ~RegisterArray()
- {
- if(dynamic)
- {
- delete x;
- delete y;
- delete z;
- delete w;
- }
- else
- {
- delete[] x;
- delete[] y;
- delete[] z;
- delete[] w;
- }
- }
-
- Register operator[](int i)
- {
- if(dynamic)
- {
- return Register(x[0][i], y[0][i], z[0][i], w[0][i]);
- }
- else
- {
- return Register(x[i][0], y[i][0], z[i][0], w[i][0]);
- }
- }
-
- Register operator[](RValue<Int> i)
- {
- ASSERT(dynamic);
-
- return Register(x[0][i], y[0][i], z[0][i], w[0][i]);
- }
-
- private:
- const bool dynamic;
- Array<Float4> *x;
- Array<Float4> *y;
- Array<Float4> *z;
- Array<Float4> *w;
- };
-
- class ShaderCore
- {
- typedef Shader::Control Control;
-
- public:
- void mov(Vector4f &dst, const Vector4f &src, bool integerDestination = false);
- void neg(Vector4f &dst, const Vector4f &src);
- void ineg(Vector4f &dst, const Vector4f &src);
- void f2b(Vector4f &dst, const Vector4f &src);
- void b2f(Vector4f &dst, const Vector4f &src);
- void f2i(Vector4f &dst, const Vector4f &src);
- void i2f(Vector4f &dst, const Vector4f &src);
- void f2u(Vector4f &dst, const Vector4f &src);
- void u2f(Vector4f &dst, const Vector4f &src);
- void i2b(Vector4f &dst, const Vector4f &src);
- void b2i(Vector4f &dst, const Vector4f &src);
- void add(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
- void iadd(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
- void sub(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
- void isub(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
- void mad(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2);
- void imad(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2);
- void mul(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
- void imul(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
- void rcpx(Vector4f &dst, const Vector4f &src, bool pp = false);
- void div(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
- void idiv(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
- void udiv(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
- void mod(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
- void imod(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
- void umod(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
- void shl(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
- void ishr(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
- void ushr(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
- void rsqx(Vector4f &dst, const Vector4f &src, bool pp = false);
- void sqrt(Vector4f &dst, const Vector4f &src, bool pp = false);
- void rsq(Vector4f &dst, const Vector4f &src, bool pp = false);
- void len2(Float4 &dst, const Vector4f &src, bool pp = false);
- void len3(Float4 &dst, const Vector4f &src, bool pp = false);
- void len4(Float4 &dst, const Vector4f &src, bool pp = false);
- void dist1(Float4 &dst, const Vector4f &src0, const Vector4f &src1, bool pp = false);
- void dist2(Float4 &dst, const Vector4f &src0, const Vector4f &src1, bool pp = false);
- void dist3(Float4 &dst, const Vector4f &src0, const Vector4f &src1, bool pp = false);
- void dist4(Float4 &dst, const Vector4f &src0, const Vector4f &src1, bool pp = false);
- void dp1(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
- void dp2(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
- void dp2add(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2);
- void dp3(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
- void dp4(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
- void det2(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
- void det3(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2);
- void det4(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2, const Vector4f &src3);
- void min(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
- void imin(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
- void umin(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
- void max(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
- void imax(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
- void umax(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
- void slt(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
- void step(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
- void exp2x(Vector4f &dst, const Vector4f &src, bool pp = false);
- void exp2(Vector4f &dst, const Vector4f &src, bool pp = false);
- void exp(Vector4f &dst, const Vector4f &src, bool pp = false);
- void log2x(Vector4f &dst, const Vector4f &src, bool pp = false);
- void log2(Vector4f &dst, const Vector4f &src, bool pp = false);
- void log(Vector4f &dst, const Vector4f &src, bool pp = false);
- void lit(Vector4f &dst, const Vector4f &src);
- void att(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
- void lrp(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2);
- void smooth(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2);
- void packHalf2x16(Vector4f &dst, const Vector4f &src);
- void unpackHalf2x16(Vector4f &dst, const Vector4f &src);
- void packSnorm2x16(Vector4f &dst, const Vector4f &src);
- void packUnorm2x16(Vector4f &dst, const Vector4f &src);
- void unpackSnorm2x16(Vector4f &dst, const Vector4f &src);
- void unpackUnorm2x16(Vector4f &dst, const Vector4f &src);
- void frc(Vector4f &dst, const Vector4f &src);
- void trunc(Vector4f &dst, const Vector4f &src);
- void floor(Vector4f &dst, const Vector4f &src);
- void round(Vector4f &dst, const Vector4f &src);
- void roundEven(Vector4f &dst, const Vector4f &src);
- void ceil(Vector4f &dst, const Vector4f &src);
- void powx(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, bool pp = false);
- void pow(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, bool pp = false);
- void crs(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
- void forward1(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2);
- void forward2(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2);
- void forward3(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2);
- void forward4(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2);
- void reflect1(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
- void reflect2(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
- void reflect3(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
- void reflect4(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
- void refract1(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Float4 &src2);
- void refract2(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Float4 &src2);
- void refract3(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Float4 &src2);
- void refract4(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Float4 &src2);
- void sgn(Vector4f &dst, const Vector4f &src);
- void isgn(Vector4f &dst, const Vector4f &src);
- void abs(Vector4f &dst, const Vector4f &src);
- void iabs(Vector4f &dst, const Vector4f &src);
- void nrm2(Vector4f &dst, const Vector4f &src, bool pp = false);
- void nrm3(Vector4f &dst, const Vector4f &src, bool pp = false);
- void nrm4(Vector4f &dst, const Vector4f &src, bool pp = false);
- void sincos(Vector4f &dst, const Vector4f &src, bool pp = false);
- void cos(Vector4f &dst, const Vector4f &src, bool pp = false);
- void sin(Vector4f &dst, const Vector4f &src, bool pp = false);
- void tan(Vector4f &dst, const Vector4f &src, bool pp = false);
- void acos(Vector4f &dst, const Vector4f &src, bool pp = false);
- void asin(Vector4f &dst, const Vector4f &src, bool pp = false);
- void atan(Vector4f &dst, const Vector4f &src, bool pp = false);
- void atan2(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, bool pp = false);
- void cosh(Vector4f &dst, const Vector4f &src, bool pp = false);
- void sinh(Vector4f &dst, const Vector4f &src, bool pp = false);
- void tanh(Vector4f &dst, const Vector4f &src, bool pp = false);
- void acosh(Vector4f &dst, const Vector4f &src, bool pp = false);
- void asinh(Vector4f &dst, const Vector4f &src, bool pp = false);
- void atanh(Vector4f &dst, const Vector4f &src, bool pp = false);
- void expp(Vector4f &dst, const Vector4f &src, unsigned short version);
- void logp(Vector4f &dst, const Vector4f &src, unsigned short version);
- void cmp0(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2);
- void cmp(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, Control control);
- void icmp(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, Control control);
- void ucmp(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, Control control);
- void select(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2);
- void extract(Float4 &dst, const Vector4f &src0, const Float4 &src1);
- void insert(Vector4f &dst, const Vector4f &src, const Float4 &element, const Float4 &index);
- void all(Float4 &dst, const Vector4f &src);
- void any(Float4 &dst, const Vector4f &src);
- void not(Vector4f &dst, const Vector4f &src);
- void or(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
- void xor(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
- void and(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
- void equal(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
- void notEqual(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
-
- private:
- void sgn(Float4 &dst, const Float4 &src);
- void isgn(Float4 &dst, const Float4 &src);
- void cmp0(Float4 &dst, const Float4 &src0, const Float4 &src1, const Float4 &src2);
- void cmp0i(Float4 &dst, const Float4 &src0, const Float4 &src1, const Float4 &src2);
- void select(Float4 &dst, RValue<Int4> src0, const Float4 &src1, const Float4 &src2);
- void floatToHalfBits(Float4& dst, const Float4& floatBits, bool storeInUpperBits);
- void halfToFloatBits(Float4& dst, const Float4& halfBits);
- };
-}
-
-#endif // sw_ShaderCore_hpp
+// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef sw_ShaderCore_hpp
+#define sw_ShaderCore_hpp
+
+#include "Debug.hpp"
+#include "Shader.hpp"
+#include "Reactor/Reactor.hpp"
+
+namespace sw
+{
+ class Vector4s
+ {
+ public:
+ Vector4s();
+ Vector4s(unsigned short x, unsigned short y, unsigned short z, unsigned short w);
+ Vector4s(const Vector4s &rhs);
+
+ Short4 &operator[](int i);
+ Vector4s &operator=(const Vector4s &rhs);
+
+ Short4 x;
+ Short4 y;
+ Short4 z;
+ Short4 w;
+ };
+
+ class Vector4i
+ {
+ public:
+ Vector4i();
+ Vector4i(int x, int y, int z, int w);
+ Vector4i(const Vector4i &rhs);
+
+ Int4 &operator[](int i);
+ Vector4i &operator=(const Vector4i &rhs);
+
+ Int4 x;
+ Int4 y;
+ Int4 z;
+ Int4 w;
+ };
+
+ class Vector4u
+ {
+ public:
+ Vector4u();
+ Vector4u(unsigned int x, unsigned int y, unsigned int z, unsigned int w);
+ Vector4u(const Vector4u &rhs);
+
+ UInt4 &operator[](int i);
+ Vector4u &operator=(const Vector4u &rhs);
+
+ UInt4 x;
+ UInt4 y;
+ UInt4 z;
+ UInt4 w;
+ };
+
+ class Vector4f
+ {
+ public:
+ Vector4f();
+ Vector4f(float x, float y, float z, float w);
+ Vector4f(const Vector4f &rhs);
+
+ Float4 &operator[](int i);
+ Vector4f &operator=(const Vector4f &rhs);
+
+ Float4 x;
+ Float4 y;
+ Float4 z;
+ Float4 w;
+ };
+
+ Float4 exponential2(RValue<Float4> x, bool pp = false);
+ Float4 logarithm2(RValue<Float4> x, bool abs, bool pp = false);
+ Float4 exponential(RValue<Float4> x, bool pp = false);
+ Float4 logarithm(RValue<Float4> x, bool abs, bool pp = false);
+ Float4 power(RValue<Float4> x, RValue<Float4> y, bool pp = false);
+ Float4 reciprocal(RValue<Float4> x, bool pp = false, bool finite = false, bool exactAtPow2 = false);
+ Float4 reciprocalSquareRoot(RValue<Float4> x, bool abs, bool pp = false);
+ Float4 modulo(RValue<Float4> x, RValue<Float4> y);
+ Float4 sine_pi(RValue<Float4> x, bool pp = false); // limited to [-pi, pi] range
+ Float4 cosine_pi(RValue<Float4> x, bool pp = false); // limited to [-pi, pi] range
+ Float4 sine(RValue<Float4> x, bool pp = false);
+ Float4 cosine(RValue<Float4> x, bool pp = false);
+ Float4 tangent(RValue<Float4> x, bool pp = false);
+ Float4 arccos(RValue<Float4> x, bool pp = false);
+ Float4 arcsin(RValue<Float4> x, bool pp = false);
+ Float4 arctan(RValue<Float4> x, bool pp = false);
+ Float4 arctan(RValue<Float4> y, RValue<Float4> x, bool pp = false);
+ Float4 sineh(RValue<Float4> x, bool pp = false);
+ Float4 cosineh(RValue<Float4> x, bool pp = false);
+ Float4 tangenth(RValue<Float4> x, bool pp = false);
+ Float4 arccosh(RValue<Float4> x, bool pp = false); // Limited to x >= 1
+ Float4 arcsinh(RValue<Float4> x, bool pp = false);
+ Float4 arctanh(RValue<Float4> x, bool pp = false); // Limited to ]-1, 1[ range
+
+ Float4 dot2(const Vector4f &v0, const Vector4f &v1);
+ Float4 dot3(const Vector4f &v0, const Vector4f &v1);
+ Float4 dot4(const Vector4f &v0, const Vector4f &v1);
+
+ void transpose4x4(Short4 &row0, Short4 &row1, Short4 &row2, Short4 &row3);
+ void transpose4x4(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3);
+ void transpose4x3(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3);
+ void transpose4x2(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3);
+ void transpose4x1(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3);
+ void transpose2x4(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3);
+ void transpose2x4h(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3);
+ void transpose4xN(Float4 &row0, Float4 &row1, Float4 &row2, Float4 &row3, int N);
+
+ class Register
+ {
+ public:
+ Register(const Reference<Float4> &x, const Reference<Float4> &y, const Reference<Float4> &z, const Reference<Float4> &w) : x(x), y(y), z(z), w(w)
+ {
+ }
+
+ Reference<Float4> &operator[](int i)
+ {
+ switch(i)
+ {
+ default:
+ case 0: return x;
+ case 1: return y;
+ case 2: return z;
+ case 3: return w;
+ }
+ }
+
+ Register &operator=(const Register &rhs)
+ {
+ x = rhs.x;
+ y = rhs.y;
+ z = rhs.z;
+ w = rhs.w;
+
+ return *this;
+ }
+
+ Register &operator=(const Vector4f &rhs)
+ {
+ x = rhs.x;
+ y = rhs.y;
+ z = rhs.z;
+ w = rhs.w;
+
+ return *this;
+ }
+
+ operator Vector4f()
+ {
+ Vector4f v;
+
+ v.x = x;
+ v.y = y;
+ v.z = z;
+ v.w = w;
+
+ return v;
+ }
+
+ Reference<Float4> x;
+ Reference<Float4> y;
+ Reference<Float4> z;
+ Reference<Float4> w;
+ };
+
+ template<int S, bool D = false>
+ class RegisterArray
+ {
+ public:
+ RegisterArray(bool dynamic = D) : dynamic(dynamic)
+ {
+ if(dynamic)
+ {
+ x = new Array<Float4>(S);
+ y = new Array<Float4>(S);
+ z = new Array<Float4>(S);
+ w = new Array<Float4>(S);
+ }
+ else
+ {
+ x = new Array<Float4>[S];
+ y = new Array<Float4>[S];
+ z = new Array<Float4>[S];
+ w = new Array<Float4>[S];
+ }
+ }
+
+ ~RegisterArray()
+ {
+ if(dynamic)
+ {
+ delete x;
+ delete y;
+ delete z;
+ delete w;
+ }
+ else
+ {
+ delete[] x;
+ delete[] y;
+ delete[] z;
+ delete[] w;
+ }
+ }
+
+ Register operator[](int i)
+ {
+ if(dynamic)
+ {
+ return Register(x[0][i], y[0][i], z[0][i], w[0][i]);
+ }
+ else
+ {
+ return Register(x[i][0], y[i][0], z[i][0], w[i][0]);
+ }
+ }
+
+ Register operator[](RValue<Int> i)
+ {
+ ASSERT(dynamic);
+
+ return Register(x[0][i], y[0][i], z[0][i], w[0][i]);
+ }
+
+ private:
+ const bool dynamic;
+ Array<Float4> *x;
+ Array<Float4> *y;
+ Array<Float4> *z;
+ Array<Float4> *w;
+ };
+
+ class ShaderCore
+ {
+ typedef Shader::Control Control;
+
+ public:
+ void mov(Vector4f &dst, const Vector4f &src, bool integerDestination = false);
+ void neg(Vector4f &dst, const Vector4f &src);
+ void ineg(Vector4f &dst, const Vector4f &src);
+ void f2b(Vector4f &dst, const Vector4f &src);
+ void b2f(Vector4f &dst, const Vector4f &src);
+ void f2i(Vector4f &dst, const Vector4f &src);
+ void i2f(Vector4f &dst, const Vector4f &src);
+ void f2u(Vector4f &dst, const Vector4f &src);
+ void u2f(Vector4f &dst, const Vector4f &src);
+ void i2b(Vector4f &dst, const Vector4f &src);
+ void b2i(Vector4f &dst, const Vector4f &src);
+ void add(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
+ void iadd(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
+ void sub(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
+ void isub(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
+ void mad(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2);
+ void imad(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2);
+ void mul(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
+ void imul(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
+ void rcpx(Vector4f &dst, const Vector4f &src, bool pp = false);
+ void div(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
+ void idiv(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
+ void udiv(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
+ void mod(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
+ void imod(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
+ void umod(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
+ void shl(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
+ void ishr(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
+ void ushr(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
+ void rsqx(Vector4f &dst, const Vector4f &src, bool pp = false);
+ void sqrt(Vector4f &dst, const Vector4f &src, bool pp = false);
+ void rsq(Vector4f &dst, const Vector4f &src, bool pp = false);
+ void len2(Float4 &dst, const Vector4f &src, bool pp = false);
+ void len3(Float4 &dst, const Vector4f &src, bool pp = false);
+ void len4(Float4 &dst, const Vector4f &src, bool pp = false);
+ void dist1(Float4 &dst, const Vector4f &src0, const Vector4f &src1, bool pp = false);
+ void dist2(Float4 &dst, const Vector4f &src0, const Vector4f &src1, bool pp = false);
+ void dist3(Float4 &dst, const Vector4f &src0, const Vector4f &src1, bool pp = false);
+ void dist4(Float4 &dst, const Vector4f &src0, const Vector4f &src1, bool pp = false);
+ void dp1(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
+ void dp2(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
+ void dp2add(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2);
+ void dp3(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
+ void dp4(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
+ void det2(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
+ void det3(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2);
+ void det4(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2, const Vector4f &src3);
+ void min(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
+ void imin(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
+ void umin(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
+ void max(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
+ void imax(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
+ void umax(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
+ void slt(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
+ void step(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
+ void exp2x(Vector4f &dst, const Vector4f &src, bool pp = false);
+ void exp2(Vector4f &dst, const Vector4f &src, bool pp = false);
+ void exp(Vector4f &dst, const Vector4f &src, bool pp = false);
+ void log2x(Vector4f &dst, const Vector4f &src, bool pp = false);
+ void log2(Vector4f &dst, const Vector4f &src, bool pp = false);
+ void log(Vector4f &dst, const Vector4f &src, bool pp = false);
+ void lit(Vector4f &dst, const Vector4f &src);
+ void att(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
+ void lrp(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2);
+ void smooth(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2);
+ void packHalf2x16(Vector4f &dst, const Vector4f &src);
+ void unpackHalf2x16(Vector4f &dst, const Vector4f &src);
+ void packSnorm2x16(Vector4f &dst, const Vector4f &src);
+ void packUnorm2x16(Vector4f &dst, const Vector4f &src);
+ void unpackSnorm2x16(Vector4f &dst, const Vector4f &src);
+ void unpackUnorm2x16(Vector4f &dst, const Vector4f &src);
+ void frc(Vector4f &dst, const Vector4f &src);
+ void trunc(Vector4f &dst, const Vector4f &src);
+ void floor(Vector4f &dst, const Vector4f &src);
+ void round(Vector4f &dst, const Vector4f &src);
+ void roundEven(Vector4f &dst, const Vector4f &src);
+ void ceil(Vector4f &dst, const Vector4f &src);
+ void powx(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, bool pp = false);
+ void pow(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, bool pp = false);
+ void crs(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
+ void forward1(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2);
+ void forward2(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2);
+ void forward3(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2);
+ void forward4(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2);
+ void reflect1(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
+ void reflect2(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
+ void reflect3(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
+ void reflect4(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
+ void refract1(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Float4 &src2);
+ void refract2(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Float4 &src2);
+ void refract3(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Float4 &src2);
+ void refract4(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Float4 &src2);
+ void sgn(Vector4f &dst, const Vector4f &src);
+ void isgn(Vector4f &dst, const Vector4f &src);
+ void abs(Vector4f &dst, const Vector4f &src);
+ void iabs(Vector4f &dst, const Vector4f &src);
+ void nrm2(Vector4f &dst, const Vector4f &src, bool pp = false);
+ void nrm3(Vector4f &dst, const Vector4f &src, bool pp = false);
+ void nrm4(Vector4f &dst, const Vector4f &src, bool pp = false);
+ void sincos(Vector4f &dst, const Vector4f &src, bool pp = false);
+ void cos(Vector4f &dst, const Vector4f &src, bool pp = false);
+ void sin(Vector4f &dst, const Vector4f &src, bool pp = false);
+ void tan(Vector4f &dst, const Vector4f &src, bool pp = false);
+ void acos(Vector4f &dst, const Vector4f &src, bool pp = false);
+ void asin(Vector4f &dst, const Vector4f &src, bool pp = false);
+ void atan(Vector4f &dst, const Vector4f &src, bool pp = false);
+ void atan2(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, bool pp = false);
+ void cosh(Vector4f &dst, const Vector4f &src, bool pp = false);
+ void sinh(Vector4f &dst, const Vector4f &src, bool pp = false);
+ void tanh(Vector4f &dst, const Vector4f &src, bool pp = false);
+ void acosh(Vector4f &dst, const Vector4f &src, bool pp = false);
+ void asinh(Vector4f &dst, const Vector4f &src, bool pp = false);
+ void atanh(Vector4f &dst, const Vector4f &src, bool pp = false);
+ void expp(Vector4f &dst, const Vector4f &src, unsigned short version);
+ void logp(Vector4f &dst, const Vector4f &src, unsigned short version);
+ void cmp0(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2);
+ void cmp(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, Control control);
+ void icmp(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, Control control);
+ void ucmp(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, Control control);
+ void select(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2);
+ void extract(Float4 &dst, const Vector4f &src0, const Float4 &src1);
+ void insert(Vector4f &dst, const Vector4f &src, const Float4 &element, const Float4 &index);
+ void all(Float4 &dst, const Vector4f &src);
+ void any(Float4 &dst, const Vector4f &src);
+ void not(Vector4f &dst, const Vector4f &src);
+ void or(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
+ void xor(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
+ void and(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
+ void equal(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
+ void notEqual(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
+
+ private:
+ void sgn(Float4 &dst, const Float4 &src);
+ void isgn(Float4 &dst, const Float4 &src);
+ void cmp0(Float4 &dst, const Float4 &src0, const Float4 &src1, const Float4 &src2);
+ void cmp0i(Float4 &dst, const Float4 &src0, const Float4 &src1, const Float4 &src2);
+ void select(Float4 &dst, RValue<Int4> src0, const Float4 &src1, const Float4 &src2);
+ void floatToHalfBits(Float4& dst, const Float4& floatBits, bool storeInUpperBits);
+ void halfToFloatBits(Float4& dst, const Float4& halfBits);
+ };
+}
+
+#endif // sw_ShaderCore_hpp
diff --git a/src/Shader/VertexPipeline.cpp b/src/Shader/VertexPipeline.cpp
index c2fa31f..a214d90 100644
--- a/src/Shader/VertexPipeline.cpp
+++ b/src/Shader/VertexPipeline.cpp
@@ -1,13 +1,16 @@
-// SwiftShader Software Renderer
+// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
-// Copyright(c) 2005-2012 TransGaming Inc.
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
//
-// 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 TransGaming Inc. Without such an agreement, no rights or licenses, express
-// or implied, including but not limited to any patent rights, are granted to you.
+// http://www.apache.org/licenses/LICENSE-2.0
//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
#include "VertexPipeline.hpp"
diff --git a/src/Shader/VertexPipeline.hpp b/src/Shader/VertexPipeline.hpp
index babe214..e8b954c 100644
--- a/src/Shader/VertexPipeline.hpp
+++ b/src/Shader/VertexPipeline.hpp
@@ -1,42 +1,45 @@
-// SwiftShader Software Renderer
-//
-// Copyright(c) 2005-2012 TransGaming 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 TransGaming Inc. Without such an agreement, no rights or licenses, express
-// or implied, including but not limited to any patent rights, are granted to you.
-//
-
-#ifndef sw_VertexPipeline_hpp
-#define sw_VertexPipeline_hpp
-
-#include "VertexRoutine.hpp"
-
-#include "Context.hpp"
-#include "VertexProcessor.hpp"
-
-namespace sw
-{
- class VertexPipeline : public VertexRoutine
- {
- public:
- VertexPipeline(const VertexProcessor::State &state);
-
- virtual ~VertexPipeline();
-
- private:
- void pipeline() override;
- void processTextureCoordinate(int stage, Vector4f &normal, Vector4f &position);
- void processPointSize();
-
- Vector4f transformBlend(const Register &src, const Pointer<Byte> &matrix, bool homogenous);
- Vector4f transform(const Register &src, const Pointer<Byte> &matrix, bool homogenous);
- Vector4f transform(const Register &src, const Pointer<Byte> &matrix, UInt index[4], bool homogenous);
- Vector4f normalize(Vector4f &src);
- Float4 power(Float4 &src0, Float4 &src1);
- };
-};
-
-#endif // sw_VertexPipeline_hpp
+// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef sw_VertexPipeline_hpp
+#define sw_VertexPipeline_hpp
+
+#include "VertexRoutine.hpp"
+
+#include "Context.hpp"
+#include "VertexProcessor.hpp"
+
+namespace sw
+{
+ class VertexPipeline : public VertexRoutine
+ {
+ public:
+ VertexPipeline(const VertexProcessor::State &state);
+
+ virtual ~VertexPipeline();
+
+ private:
+ void pipeline() override;
+ void processTextureCoordinate(int stage, Vector4f &normal, Vector4f &position);
+ void processPointSize();
+
+ Vector4f transformBlend(const Register &src, const Pointer<Byte> &matrix, bool homogenous);
+ Vector4f transform(const Register &src, const Pointer<Byte> &matrix, bool homogenous);
+ Vector4f transform(const Register &src, const Pointer<Byte> &matrix, UInt index[4], bool homogenous);
+ Vector4f normalize(Vector4f &src);
+ Float4 power(Float4 &src0, Float4 &src1);
+ };
+};
+
+#endif // sw_VertexPipeline_hpp
diff --git a/src/Shader/VertexProgram.cpp b/src/Shader/VertexProgram.cpp
index 492dd41..5be2070 100644
--- a/src/Shader/VertexProgram.cpp
+++ b/src/Shader/VertexProgram.cpp
@@ -1,13 +1,16 @@
-// SwiftShader Software Renderer
+// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
-// Copyright(c) 2005-2013 TransGaming Inc.
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
//
-// 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 TransGaming Inc. Without such an agreement, no rights or licenses, express
-// or implied, including but not limited to any patent rights, are granted to you.
+// http://www.apache.org/licenses/LICENSE-2.0
//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
#include "VertexProgram.hpp"
@@ -674,7 +677,7 @@
reg = readConstant(src, offset);
break;
case Shader::PARAMETER_INPUT:
- if(src.rel.type == Shader::PARAMETER_VOID)
+ if(src.rel.type == Shader::PARAMETER_VOID)
{
reg = v[i];
}
@@ -682,7 +685,7 @@
{
reg = v[i + relativeAddress(src, src.bufferIndex)];
}
- break;
+ break;
case Shader::PARAMETER_VOID: return r[0]; // Dummy
case Shader::PARAMETER_FLOAT4LITERAL:
reg.x = Float4(src.value[0]);
@@ -706,7 +709,7 @@
}
return reg;
case Shader::PARAMETER_OUTPUT:
- if(src.rel.type == Shader::PARAMETER_VOID)
+ if(src.rel.type == Shader::PARAMETER_VOID)
{
reg = o[i];
}
diff --git a/src/Shader/VertexProgram.hpp b/src/Shader/VertexProgram.hpp
index 98e09cd..f4f1677 100644
--- a/src/Shader/VertexProgram.hpp
+++ b/src/Shader/VertexProgram.hpp
@@ -1,13 +1,16 @@
-// SwiftShader Software Renderer
+// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
-// Copyright(c) 2005-2012 TransGaming Inc.
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
//
-// 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 TransGaming Inc. Without such an agreement, no rights or licenses, express
-// or implied, including but not limited to any patent rights, are granted to you.
+// http://www.apache.org/licenses/LICENSE-2.0
//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
#ifndef sw_VertexProgram_hpp
#define sw_VertexProgram_hpp
diff --git a/src/Shader/VertexRoutine.cpp b/src/Shader/VertexRoutine.cpp
index 812bf0c..e5405ef 100644
--- a/src/Shader/VertexRoutine.cpp
+++ b/src/Shader/VertexRoutine.cpp
@@ -1,13 +1,16 @@
-// SwiftShader Software Renderer
+// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
-// Copyright(c) 2005-2012 TransGaming Inc.
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
//
-// 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 TransGaming Inc. Without such an agreement, no rights or licenses, express
-// or implied, including but not limited to any patent rights, are granted to you.
+// http://www.apache.org/licenses/LICENSE-2.0
//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
#include "VertexRoutine.hpp"
diff --git a/src/Shader/VertexRoutine.hpp b/src/Shader/VertexRoutine.hpp
index 1861d10..71aeb5b 100644
--- a/src/Shader/VertexRoutine.hpp
+++ b/src/Shader/VertexRoutine.hpp
@@ -1,13 +1,16 @@
-// SwiftShader Software Renderer
+// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
-// Copyright(c) 2005-2013 TransGaming Inc.
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
//
-// 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 TransGaming Inc. Without such an agreement, no rights or licenses, express
-// or implied, including but not limited to any patent rights, are granted to you.
+// http://www.apache.org/licenses/LICENSE-2.0
//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
#ifndef sw_VertexRoutine_hpp
#define sw_VertexRoutine_hpp
diff --git a/src/Shader/VertexShader.cpp b/src/Shader/VertexShader.cpp
index dc8bd06..1de8c93 100644
--- a/src/Shader/VertexShader.cpp
+++ b/src/Shader/VertexShader.cpp
@@ -1,13 +1,16 @@
-// SwiftShader Software Renderer
+// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
-// Copyright(c) 2005-2013 TransGaming Inc.
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
//
-// 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 TransGaming Inc. Without such an agreement, no rights or licenses, express
-// or implied, including but not limited to any patent rights, are granted to you.
+// http://www.apache.org/licenses/LICENSE-2.0
//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
#include "VertexShader.hpp"
diff --git a/src/Shader/VertexShader.hpp b/src/Shader/VertexShader.hpp
index 127d64c..f8760fb 100644
--- a/src/Shader/VertexShader.hpp
+++ b/src/Shader/VertexShader.hpp
@@ -1,13 +1,16 @@
-// SwiftShader Software Renderer
+// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
-// Copyright(c) 2005-2013 TransGaming Inc.
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
//
-// 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 TransGaming Inc. Without such an agreement, no rights or licenses, express
-// or implied, including but not limited to any patent rights, are granted to you.
+// http://www.apache.org/licenses/LICENSE-2.0
//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
#ifndef sw_VertexShader_hpp
#define sw_VertexShader_hpp