Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 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 | |
Nicolas Capens | 1d8c8db | 2018-11-05 16:30:42 -0500 | [diff] [blame] | 18 | #include "Device/QuadRasterizer.hpp" |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 19 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 20 | namespace sw { |
| 21 | |
| 22 | class PixelShader; |
| 23 | class SamplerCore; |
| 24 | |
| 25 | class PixelRoutine : public sw::QuadRasterizer |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 26 | { |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 27 | public: |
| 28 | PixelRoutine(const PixelProcessor::State &state, |
Ben Clayton | bc1c067be | 2019-12-17 20:37:37 +0000 | [diff] [blame] | 29 | vk::PipelineLayout const *pipelineLayout, |
| 30 | SpirvShader const *spirvShader, |
| 31 | const vk::DescriptorSet::Bindings &descriptorSets); |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 32 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 33 | virtual ~PixelRoutine(); |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 34 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 35 | protected: |
Ben Clayton | bc1c067be | 2019-12-17 20:37:37 +0000 | [diff] [blame] | 36 | Float4 z[4]; // Multisampled z |
| 37 | Float4 w; // Used as is |
| 38 | Float4 rhw; // Reciprocal w |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 39 | |
Alexis Hetu | dc8e77f | 2020-07-28 16:53:07 -0400 | [diff] [blame] | 40 | uint32_t outputMasks[RENDERTARGETS]; // TODO(b/162348737): Determine whether unwritten output should be left untouched |
| 41 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 42 | SpirvRoutine routine; |
| 43 | const vk::DescriptorSet::Bindings &descriptorSets; |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 44 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 45 | // Depth output |
| 46 | Float4 oDepth; |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 47 | |
Alexis Hetu | 09df3eb | 2021-01-14 10:46:33 -0500 | [diff] [blame] | 48 | virtual void setBuiltins(Int &x, Int &y, Float4 (&z)[4], Float4 &w, Int cMask[4], int sampleId) = 0; |
| 49 | virtual void applyShader(Int cMask[4], Int sMask[4], Int zMask[4], int sampleId) = 0; |
| 50 | virtual Bool alphaTest(Int cMask[4], int sampleId) = 0; |
| 51 | virtual void rasterOperation(Pointer<Byte> cBuffer[4], Int &x, Int sMask[4], Int zMask[4], Int cMask[4], int sampleId) = 0; |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 52 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 53 | void quad(Pointer<Byte> cBuffer[4], Pointer<Byte> &zBuffer, Pointer<Byte> &sBuffer, Int cMask[4], Int &x, Int &y) override; |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 54 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 55 | void alphaTest(Int &aMask, const Short4 &alpha); |
Alexis Hetu | 09df3eb | 2021-01-14 10:46:33 -0500 | [diff] [blame] | 56 | void alphaToCoverage(Int cMask[4], const Float4 &alpha, int sampleId); |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 57 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 58 | // Raster operations |
| 59 | void alphaBlend(int index, const Pointer<Byte> &cBuffer, Vector4s ¤t, const Int &x); |
Ben Clayton | bc1c067be | 2019-12-17 20:37:37 +0000 | [diff] [blame] | 60 | void writeColor(int index, const Pointer<Byte> &cBuffer, const Int &x, Vector4f &oC, const Int &sMask, const Int &zMask, const Int &cMask); |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 61 | void alphaBlend(int index, const Pointer<Byte> &cBuffer, Vector4f &oC, const Int &x); |
| 62 | void writeColor(int index, const Pointer<Byte> &cBuffer, const Int &x, Vector4s ¤t, const Int &sMask, const Int &zMask, const Int &cMask); |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 63 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 64 | bool isSRGB(int index) const; |
| 65 | UShort4 convertFixed16(const Float4 &cf, bool saturate = true); |
Sean Risser | b71a556 | 2021-04-01 16:44:48 -0400 | [diff] [blame] | 66 | Float4 convertFloat32(const UShort4 &cf); |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 67 | void linearToSRGB12_16(Vector4s &c); |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 68 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 69 | private: |
Alexis Hetu | 1ee36c9 | 2020-02-20 14:07:26 -0500 | [diff] [blame] | 70 | Byte8 stencilReplaceRef(bool isBack); |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 71 | void stencilTest(const Pointer<Byte> &sBuffer, int q, const Int &x, Int &sMask, const Int &cMask); |
| 72 | void stencilTest(Byte8 &value, VkCompareOp stencilCompareMode, bool isBack); |
| 73 | void stencilOperation(Byte8 &newValue, const Byte8 &bufferValue, const PixelProcessor::States::StencilOpState &ops, bool isBack, const Int &zMask, const Int &sMask); |
| 74 | void stencilOperation(Byte8 &output, const Byte8 &bufferValue, VkStencilOp operation, bool isBack); |
| 75 | Bool depthTest(const Pointer<Byte> &zBuffer, int q, const Int &x, const Float4 &z, const Int &sMask, Int &zMask, const Int &cMask); |
Sean Risser | b71a556 | 2021-04-01 16:44:48 -0400 | [diff] [blame] | 76 | void depthBoundsTest(const Pointer<Byte> &zBuffer, int q, const Int &x, Int &zMask, Int &cMask); |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 77 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 78 | // Raster operations |
| 79 | void blendFactor(Vector4s &blendFactor, const Vector4s ¤t, const Vector4s &pixel, VkBlendFactor blendFactorActive); |
| 80 | void blendFactorAlpha(Vector4s &blendFactor, const Vector4s ¤t, const Vector4s &pixel, VkBlendFactor blendFactorAlphaActive); |
| 81 | void readPixel(int index, const Pointer<Byte> &cBuffer, const Int &x, Vector4s &pixel); |
| 82 | void blendFactor(Vector4f &blendFactor, const Vector4f &oC, const Vector4f &pixel, VkBlendFactor blendFactorActive); |
| 83 | void blendFactorAlpha(Vector4f &blendFactor, const Vector4f &oC, const Vector4f &pixel, VkBlendFactor blendFactorAlphaActive); |
| 84 | void writeStencil(Pointer<Byte> &sBuffer, int q, const Int &x, const Int &sMask, const Int &zMask, const Int &cMask); |
| 85 | void writeDepth(Pointer<Byte> &zBuffer, int q, const Int &x, const Float4 &z, const Int &zMask); |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 86 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 87 | void sRGBtoLinear16_12_16(Vector4s &c); |
| 88 | void linearToSRGB16_12_16(Vector4s &c); |
| 89 | Float4 sRGBtoLinear(const Float4 &x); |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 90 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 91 | Bool depthTest32F(const Pointer<Byte> &zBuffer, int q, const Int &x, const Float4 &z, const Int &sMask, Int &zMask, const Int &cMask); |
| 92 | Bool depthTest16(const Pointer<Byte> &zBuffer, int q, const Int &x, const Float4 &z, const Int &sMask, Int &zMask, const Int &cMask); |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 93 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 94 | void writeDepth32F(Pointer<Byte> &zBuffer, int q, const Int &x, const Float4 &z, const Int &zMask); |
| 95 | void writeDepth16(Pointer<Byte> &zBuffer, int q, const Int &x, const Float4 &z, const Int &zMask); |
Sean Risser | b71a556 | 2021-04-01 16:44:48 -0400 | [diff] [blame] | 96 | |
| 97 | Int4 depthBoundsTest32F(const Pointer<Byte> &zBuffer, int q, const Int &x); |
| 98 | Int4 depthBoundsTest16(const Pointer<Byte> &zBuffer, int q, const Int &x); |
Nicolas Capens | 8460144 | 2021-07-26 17:07:13 -0400 | [diff] [blame^] | 99 | |
| 100 | // Derived state parameters |
| 101 | const bool shaderContainsInterpolation; // TODO(b/194714095) |
| 102 | const bool shaderContainsSampleQualifier; |
| 103 | const bool perSampleShading; |
| 104 | const int invocationCount; |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 105 | }; |
Chris Forbes | bea4751 | 2019-03-12 14:50:55 -0700 | [diff] [blame] | 106 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 107 | } // namespace sw |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 108 | |
Ben Clayton | bc1c067be | 2019-12-17 20:37:37 +0000 | [diff] [blame] | 109 | #endif // sw_PixelRoutine_hpp |