1 | // Copyright 2016 The SwiftShader Authors. All Rights Reserved. |
2 | // |
3 | // 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 |
6 | // |
7 | // http://www.apache.org/licenses/LICENSE-2.0 |
8 | // |
9 | // 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. |
14 | |
15 | #ifndef sw_PixelRoutine_hpp |
16 | #define sw_PixelRoutine_hpp |
17 | |
18 | #include "Device/QuadRasterizer.hpp" |
19 | |
20 | namespace sw |
21 | { |
22 | class PixelShader; |
23 | class SamplerCore; |
24 | |
25 | class PixelRoutine : public sw::QuadRasterizer |
26 | { |
27 | public: |
28 | PixelRoutine(const PixelProcessor::State &state, |
29 | vk::PipelineLayout const *pipelineLayout, |
30 | SpirvShader const *spirvShader, |
31 | const vk::DescriptorSet::Bindings &descriptorSets); |
32 | |
33 | virtual ~PixelRoutine(); |
34 | |
35 | protected: |
36 | Float4 z[4]; // Multisampled z |
37 | Float4 w; // Used as is |
38 | Float4 rhw; // Reciprocal w |
39 | |
40 | SpirvRoutine routine; |
41 | const vk::DescriptorSet::Bindings &descriptorSets; |
42 | |
43 | // Depth output |
44 | Float4 oDepth; |
45 | |
46 | virtual void setBuiltins(Int &x, Int &y, Float4(&z)[4], Float4 &w, Int cMask[4]) = 0; |
47 | virtual void applyShader(Int cMask[4], Int sMask[4], Int zMask[4]) = 0; |
48 | virtual Bool alphaTest(Int cMask[4]) = 0; |
49 | virtual void rasterOperation(Pointer<Byte> cBuffer[4], Int &x, Int sMask[4], Int zMask[4], Int cMask[4]) = 0; |
50 | |
51 | void quad(Pointer<Byte> cBuffer[4], Pointer<Byte> &zBuffer, Pointer<Byte> &sBuffer, Int cMask[4], Int &x, Int &y) override; |
52 | |
53 | void alphaTest(Int &aMask, const Short4 &alpha); |
54 | void alphaToCoverage(Int cMask[4], const Float4 &alpha); |
55 | |
56 | // Raster operations |
57 | void alphaBlend(int index, const Pointer<Byte> &cBuffer, Vector4s ¤t, const Int &x); |
58 | void writeColor(int index, const Pointer<Byte> &cBuffer, const Int& x, Vector4f& oC, const Int& sMask, const Int& zMask, const Int& cMask); |
59 | void alphaBlend(int index, const Pointer<Byte> &cBuffer, Vector4f &oC, const Int &x); |
60 | void writeColor(int index, const Pointer<Byte> &cBuffer, const Int &x, Vector4s ¤t, const Int &sMask, const Int &zMask, const Int &cMask); |
61 | |
62 | bool isSRGB(int index) const; |
63 | UShort4 convertFixed16(const Float4 &cf, bool saturate = true); |
64 | void linearToSRGB12_16(Vector4s &c); |
65 | |
66 | private: |
67 | Float4 interpolateCentroid(const Float4 &x, const Float4 &y, const Float4 &rhw, Pointer<Byte> planeEquation, bool flat, bool perspective); |
68 | void stencilTest(const Pointer<Byte> &sBuffer, int q, const Int &x, Int &sMask, const Int &cMask); |
69 | void stencilTest(Byte8 &value, VkCompareOp stencilCompareMode, bool isBack); |
70 | void stencilOperation(Byte8 &newValue, const Byte8 &bufferValue, const PixelProcessor::States::StencilOpState &ops, bool isBack, const Int &zMask, const Int &sMask); |
71 | void stencilOperation(Byte8 &output, const Byte8 &bufferValue, VkStencilOp operation, bool isBack); |
72 | Bool depthTest(const Pointer<Byte> &zBuffer, int q, const Int &x, const Float4 &z, const Int &sMask, Int &zMask, const Int &cMask); |
73 | |
74 | // Raster operations |
75 | void blendFactor(Vector4s &blendFactor, const Vector4s ¤t, const Vector4s &pixel, VkBlendFactor blendFactorActive); |
76 | void blendFactorAlpha(Vector4s &blendFactor, const Vector4s ¤t, const Vector4s &pixel, VkBlendFactor blendFactorAlphaActive); |
77 | void readPixel(int index, const Pointer<Byte> &cBuffer, const Int &x, Vector4s &pixel); |
78 | void blendFactor(Vector4f &blendFactor, const Vector4f &oC, const Vector4f &pixel, VkBlendFactor blendFactorActive); |
79 | void blendFactorAlpha(Vector4f &blendFactor, const Vector4f &oC, const Vector4f &pixel, VkBlendFactor blendFactorAlphaActive); |
80 | void writeStencil(Pointer<Byte> &sBuffer, int q, const Int &x, const Int &sMask, const Int &zMask, const Int &cMask); |
81 | void writeDepth(Pointer<Byte> &zBuffer, int q, const Int &x, const Float4 &z, const Int &zMask); |
82 | |
83 | void sRGBtoLinear16_12_16(Vector4s &c); |
84 | void linearToSRGB16_12_16(Vector4s &c); |
85 | Float4 sRGBtoLinear(const Float4 &x); |
86 | |
87 | Bool depthTest32F(const Pointer<Byte> &zBuffer, int q, const Int &x, const Float4 &z, const Int &sMask, Int &zMask, const Int &cMask); |
88 | Bool depthTest16(const Pointer<Byte> &zBuffer, int q, const Int &x, const Float4 &z, const Int &sMask, Int &zMask, const Int &cMask); |
89 | |
90 | void writeDepth32F(Pointer<Byte> &zBuffer, int q, const Int &x, const Float4 &z, const Int &zMask); |
91 | void writeDepth16(Pointer<Byte> &zBuffer, int q, const Int &x, const Float4 &z, const Int &zMask); |
92 | }; |
93 | } |
94 | |
95 | #endif // sw_PixelRoutine_hpp |
96 | |