blob: bc558c2b31e86b66550bfeeaded1fad8dbe45999 [file] [log] [blame]
Nicolas Capens0bac2852016-05-07 06:09:58 -04001// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
John Bauman66b8ab22014-05-06 15:57:45 -04002//
Nicolas Capens0bac2852016-05-07 06:09:58 -04003// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
John Bauman66b8ab22014-05-06 15:57:45 -04006//
Nicolas Capens0bac2852016-05-07 06:09:58 -04007// http://www.apache.org/licenses/LICENSE-2.0
John Bauman66b8ab22014-05-06 15:57:45 -04008//
Nicolas Capens0bac2852016-05-07 06:09:58 -04009// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
John Bauman66b8ab22014-05-06 15:57:45 -040014
15#ifndef sw_PixelRoutine_hpp
16#define sw_PixelRoutine_hpp
17
Nicolas Capens708c24b2017-10-26 13:07:10 -040018#include "Renderer/QuadRasterizer.hpp"
John Bauman66b8ab22014-05-06 15:57:45 -040019
20namespace sw
21{
John Bauman66b8ab22014-05-06 15:57:45 -040022 class PixelShader;
23 class SamplerCore;
24
Alexis Hetuf2a8c372015-07-13 11:08:41 -040025 class PixelRoutine : public sw::QuadRasterizer, public ShaderCore
John Bauman66b8ab22014-05-06 15:57:45 -040026 {
John Bauman66b8ab22014-05-06 15:57:45 -040027 public:
28 PixelRoutine(const PixelProcessor::State &state, const PixelShader *shader);
29
Alexis Hetuf2a8c372015-07-13 11:08:41 -040030 virtual ~PixelRoutine();
John Bauman66b8ab22014-05-06 15:57:45 -040031
32 protected:
Nicolas Capens4f172c72016-01-13 08:34:30 -050033 Float4 z[4]; // Multisampled z
34 Float4 w; // Used as is
35 Float4 rhw; // Reciprocal w
John Bauman66b8ab22014-05-06 15:57:45 -040036
Nicolas Capens3b4c93f2016-05-18 12:51:37 -040037 RegisterArray<MAX_FRAGMENT_INPUTS> v; // Varying registers
John Bauman66b8ab22014-05-06 15:57:45 -040038
Nicolas Capens4f172c72016-01-13 08:34:30 -050039 // Depth output
40 Float4 oDepth;
Alexis Hetuf2a8c372015-07-13 11:08:41 -040041
John Bauman66b8ab22014-05-06 15:57:45 -040042 typedef Shader::SourceParameter Src;
Alexis Hetuf2a8c372015-07-13 11:08:41 -040043 typedef Shader::DestinationParameter Dst;
John Bauman66b8ab22014-05-06 15:57:45 -040044
Nicolas Capens4f172c72016-01-13 08:34:30 -050045 virtual void setBuiltins(Int &x, Int &y, Float4(&z)[4], Float4 &w) = 0;
46 virtual void applyShader(Int cMask[4]) = 0;
47 virtual Bool alphaTest(Int cMask[4]) = 0;
48 virtual void rasterOperation(Float4 &fog, Pointer<Byte> cBuffer[4], Int &x, Int sMask[4], Int zMask[4], Int cMask[4]) = 0;
John Bauman66b8ab22014-05-06 15:57:45 -040049
Nicolas Capens4f172c72016-01-13 08:34:30 -050050 virtual void quad(Pointer<Byte> cBuffer[4], Pointer<Byte> &zBuffer, Pointer<Byte> &sBuffer, Int cMask[4], Int &x, Int &y);
Alexis Hetuf2a8c372015-07-13 11:08:41 -040051
Nicolas Capens4f172c72016-01-13 08:34:30 -050052 void alphaTest(Int &aMask, Short4 &alpha);
53 void alphaToCoverage(Int cMask[4], Float4 &alpha);
54 void fogBlend(Vector4f &c0, Float4 &fog);
55 void pixelFog(Float4 &visibility);
Alexis Hetu3e1fd3a2015-08-11 10:15:34 -040056
57 // Raster operations
Nicolas Capens4f172c72016-01-13 08:34:30 -050058 void alphaBlend(int index, Pointer<Byte> &cBuffer, Vector4s &current, Int &x);
59 void logicOperation(int index, Pointer<Byte> &cBuffer, Vector4s &current, Int &x);
60 void writeColor(int index, Pointer<Byte> &cBuffer, Int &i, Vector4s &current, Int &sMask, Int &zMask, Int &cMask);
61 void alphaBlend(int index, Pointer<Byte> &cBuffer, Vector4f &oC, Int &x);
62 void writeColor(int index, Pointer<Byte> &cBuffer, Int &i, Vector4f &oC, Int &sMask, Int &zMask, Int &cMask);
Alexis Hetu3e1fd3a2015-08-11 10:15:34 -040063
Alexis Hetu049a1872016-04-25 16:59:58 -040064 bool isSRGB(int index) const;
Alexis Hetu3e1fd3a2015-08-11 10:15:34 -040065 UShort4 convertFixed16(Float4 &cf, bool saturate = true);
Nicolas Capens4f172c72016-01-13 08:34:30 -050066 void linearToSRGB12_16(Vector4s &c);
Alexis Hetu3e1fd3a2015-08-11 10:15:34 -040067
Alexis Hetu3e1fd3a2015-08-11 10:15:34 -040068 private:
John Bauman66b8ab22014-05-06 15:57:45 -040069 Float4 interpolateCentroid(Float4 &x, Float4 &y, Float4 &rhw, Pointer<Byte> planeEquation, bool flat, bool perspective);
Nicolas Capens4f172c72016-01-13 08:34:30 -050070 void stencilTest(Pointer<Byte> &sBuffer, int q, Int &x, Int &sMask, Int &cMask);
71 void stencilTest(Byte8 &value, StencilCompareMode stencilCompareMode, bool CCW);
72 void stencilOperation(Byte8 &newValue, Byte8 &bufferValue, StencilOperation stencilPassOperation, StencilOperation stencilZFailOperation, StencilOperation stencilFailOperation, bool CCW, Int &zMask, Int &sMask);
73 void stencilOperation(Byte8 &output, Byte8 &bufferValue, StencilOperation operation, bool CCW);
74 Bool depthTest(Pointer<Byte> &zBuffer, int q, Int &x, Float4 &z, Int &sMask, Int &zMask, Int &cMask);
John Bauman66b8ab22014-05-06 15:57:45 -040075
John Bauman66b8ab22014-05-06 15:57:45 -040076 // Raster operations
Nicolas Capens96d4e092016-11-18 14:22:38 -050077 void blendFactor(Vector4s &blendFactor, const Vector4s &current, const Vector4s &pixel, BlendFactor blendFactorActive);
78 void blendFactorAlpha(Vector4s &blendFactor, const Vector4s &current, const Vector4s &pixel, BlendFactor blendFactorAlphaActive);
Nicolas Capens4f172c72016-01-13 08:34:30 -050079 void readPixel(int index, Pointer<Byte> &cBuffer, Int &x, Vector4s &pixel);
Nicolas Capens96d4e092016-11-18 14:22:38 -050080 void blendFactor(Vector4f &blendFactor, const Vector4f &oC, const Vector4f &pixel, BlendFactor blendFactorActive);
81 void blendFactorAlpha(Vector4f &blendFactor, const Vector4f &oC, const Vector4f &pixel, BlendFactor blendFactorAlphaActive);
Nicolas Capens4f172c72016-01-13 08:34:30 -050082 void writeStencil(Pointer<Byte> &sBuffer, int q, Int &x, Int &sMask, Int &zMask, Int &cMask);
83 void writeDepth(Pointer<Byte> &zBuffer, int q, Int &x, Float4 &z, Int &zMask);
John Bauman66b8ab22014-05-06 15:57:45 -040084
Nicolas Capens4f172c72016-01-13 08:34:30 -050085 void sRGBtoLinear16_12_16(Vector4s &c);
86 void sRGBtoLinear12_16(Vector4s &c);
87 void linearToSRGB16_12_16(Vector4s &c);
John Bauman66b8ab22014-05-06 15:57:45 -040088 Float4 sRGBtoLinear(const Float4 &x);
John Bauman66b8ab22014-05-06 15:57:45 -040089
90 bool colorUsed();
John Bauman66b8ab22014-05-06 15:57:45 -040091 };
92}
93
94#endif // sw_PixelRoutine_hpp