blob: 72d42537ced369c94c11cf6c46e0e336a05f6395 [file] [log] [blame]
Nicolas Capens68a82382018-10-02 13:16:55 -04001// 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
Nicolas Capens1d8c8db2018-11-05 16:30:42 -050018#include "Device/QuadRasterizer.hpp"
Nicolas Capens68a82382018-10-02 13:16:55 -040019
Nicolas Capens157ba262019-12-10 17:49:14 -050020namespace sw {
21
22class PixelShader;
23class SamplerCore;
24
25class PixelRoutine : public sw::QuadRasterizer
Nicolas Capens68a82382018-10-02 13:16:55 -040026{
Nicolas Capens157ba262019-12-10 17:49:14 -050027public:
28 PixelRoutine(const PixelProcessor::State &state,
Ben Claytonbc1c0672019-12-17 20:37:37 +000029 vk::PipelineLayout const *pipelineLayout,
30 SpirvShader const *spirvShader,
31 const vk::DescriptorSet::Bindings &descriptorSets);
Nicolas Capens68a82382018-10-02 13:16:55 -040032
Nicolas Capens157ba262019-12-10 17:49:14 -050033 virtual ~PixelRoutine();
Nicolas Capens68a82382018-10-02 13:16:55 -040034
Nicolas Capens157ba262019-12-10 17:49:14 -050035protected:
Ben Claytonbc1c0672019-12-17 20:37:37 +000036 Float4 z[4]; // Multisampled z
37 Float4 w; // Used as is
38 Float4 rhw; // Reciprocal w
Nicolas Capens68a82382018-10-02 13:16:55 -040039
Nicolas Capens157ba262019-12-10 17:49:14 -050040 SpirvRoutine routine;
41 const vk::DescriptorSet::Bindings &descriptorSets;
Nicolas Capens68a82382018-10-02 13:16:55 -040042
Nicolas Capens157ba262019-12-10 17:49:14 -050043 // Depth output
44 Float4 oDepth;
Nicolas Capens68a82382018-10-02 13:16:55 -040045
Ben Claytonbc1c0672019-12-17 20:37:37 +000046 virtual void setBuiltins(Int &x, Int &y, Float4 (&z)[4], Float4 &w, Int cMask[4]) = 0;
Nicolas Capens157ba262019-12-10 17:49:14 -050047 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;
Nicolas Capens68a82382018-10-02 13:16:55 -040050
Nicolas Capens157ba262019-12-10 17:49:14 -050051 void quad(Pointer<Byte> cBuffer[4], Pointer<Byte> &zBuffer, Pointer<Byte> &sBuffer, Int cMask[4], Int &x, Int &y) override;
Nicolas Capens68a82382018-10-02 13:16:55 -040052
Nicolas Capens157ba262019-12-10 17:49:14 -050053 void alphaTest(Int &aMask, const Short4 &alpha);
54 void alphaToCoverage(Int cMask[4], const Float4 &alpha);
Nicolas Capens68a82382018-10-02 13:16:55 -040055
Nicolas Capens157ba262019-12-10 17:49:14 -050056 // Raster operations
57 void alphaBlend(int index, const Pointer<Byte> &cBuffer, Vector4s &current, const Int &x);
Ben Claytonbc1c0672019-12-17 20:37:37 +000058 void writeColor(int index, const Pointer<Byte> &cBuffer, const Int &x, Vector4f &oC, const Int &sMask, const Int &zMask, const Int &cMask);
Nicolas Capens157ba262019-12-10 17:49:14 -050059 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 &current, const Int &sMask, const Int &zMask, const Int &cMask);
Nicolas Capens68a82382018-10-02 13:16:55 -040061
Nicolas Capens157ba262019-12-10 17:49:14 -050062 bool isSRGB(int index) const;
63 UShort4 convertFixed16(const Float4 &cf, bool saturate = true);
64 void linearToSRGB12_16(Vector4s &c);
Nicolas Capens68a82382018-10-02 13:16:55 -040065
Nicolas Capens157ba262019-12-10 17:49:14 -050066private:
67 Float4 interpolateCentroid(const Float4 &x, const Float4 &y, const Float4 &rhw, Pointer<Byte> planeEquation, bool flat, bool perspective);
Alexis Hetu1ee36c92020-02-20 14:07:26 -050068 Byte8 stencilReplaceRef(bool isBack);
Nicolas Capens157ba262019-12-10 17:49:14 -050069 void stencilTest(const Pointer<Byte> &sBuffer, int q, const Int &x, Int &sMask, const Int &cMask);
70 void stencilTest(Byte8 &value, VkCompareOp stencilCompareMode, bool isBack);
71 void stencilOperation(Byte8 &newValue, const Byte8 &bufferValue, const PixelProcessor::States::StencilOpState &ops, bool isBack, const Int &zMask, const Int &sMask);
72 void stencilOperation(Byte8 &output, const Byte8 &bufferValue, VkStencilOp operation, bool isBack);
73 Bool depthTest(const Pointer<Byte> &zBuffer, int q, const Int &x, const Float4 &z, const Int &sMask, Int &zMask, const Int &cMask);
Nicolas Capens68a82382018-10-02 13:16:55 -040074
Nicolas Capens157ba262019-12-10 17:49:14 -050075 // Raster operations
76 void blendFactor(Vector4s &blendFactor, const Vector4s &current, const Vector4s &pixel, VkBlendFactor blendFactorActive);
77 void blendFactorAlpha(Vector4s &blendFactor, const Vector4s &current, const Vector4s &pixel, VkBlendFactor blendFactorAlphaActive);
78 void readPixel(int index, const Pointer<Byte> &cBuffer, const Int &x, Vector4s &pixel);
79 void blendFactor(Vector4f &blendFactor, const Vector4f &oC, const Vector4f &pixel, VkBlendFactor blendFactorActive);
80 void blendFactorAlpha(Vector4f &blendFactor, const Vector4f &oC, const Vector4f &pixel, VkBlendFactor blendFactorAlphaActive);
81 void writeStencil(Pointer<Byte> &sBuffer, int q, const Int &x, const Int &sMask, const Int &zMask, const Int &cMask);
82 void writeDepth(Pointer<Byte> &zBuffer, int q, const Int &x, const Float4 &z, const Int &zMask);
Nicolas Capens68a82382018-10-02 13:16:55 -040083
Nicolas Capens157ba262019-12-10 17:49:14 -050084 void sRGBtoLinear16_12_16(Vector4s &c);
85 void linearToSRGB16_12_16(Vector4s &c);
86 Float4 sRGBtoLinear(const Float4 &x);
Nicolas Capens68a82382018-10-02 13:16:55 -040087
Nicolas Capens157ba262019-12-10 17:49:14 -050088 Bool depthTest32F(const Pointer<Byte> &zBuffer, int q, const Int &x, const Float4 &z, const Int &sMask, Int &zMask, const Int &cMask);
89 Bool depthTest16(const Pointer<Byte> &zBuffer, int q, const Int &x, const Float4 &z, const Int &sMask, Int &zMask, const Int &cMask);
Nicolas Capens68a82382018-10-02 13:16:55 -040090
Nicolas Capens157ba262019-12-10 17:49:14 -050091 void writeDepth32F(Pointer<Byte> &zBuffer, int q, const Int &x, const Float4 &z, const Int &zMask);
92 void writeDepth16(Pointer<Byte> &zBuffer, int q, const Int &x, const Float4 &z, const Int &zMask);
93};
Chris Forbesbea47512019-03-12 14:50:55 -070094
Nicolas Capens157ba262019-12-10 17:49:14 -050095} // namespace sw
Nicolas Capens68a82382018-10-02 13:16:55 -040096
Ben Claytonbc1c0672019-12-17 20:37:37 +000097#endif // sw_PixelRoutine_hpp