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 | 2855636 | 2021-07-24 02:36:09 -0400 | [diff] [blame] | 20 | #include <vector> |
| 21 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 22 | namespace sw { |
| 23 | |
| 24 | class PixelShader; |
| 25 | class SamplerCore; |
| 26 | |
| 27 | class PixelRoutine : public sw::QuadRasterizer |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 28 | { |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 29 | public: |
| 30 | PixelRoutine(const PixelProcessor::State &state, |
Ben Clayton | bc1c067be | 2019-12-17 20:37:37 +0000 | [diff] [blame] | 31 | vk::PipelineLayout const *pipelineLayout, |
| 32 | SpirvShader const *spirvShader, |
| 33 | const vk::DescriptorSet::Bindings &descriptorSets); |
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 | virtual ~PixelRoutine(); |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 36 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 37 | protected: |
Nicolas Capens | 2855636 | 2021-07-24 02:36:09 -0400 | [diff] [blame] | 38 | using SampleSet = std::vector<int>; |
| 39 | |
Ben Clayton | bc1c067be | 2019-12-17 20:37:37 +0000 | [diff] [blame] | 40 | Float4 z[4]; // Multisampled z |
| 41 | Float4 w; // Used as is |
| 42 | Float4 rhw; // Reciprocal w |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 43 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 44 | SpirvRoutine routine; |
| 45 | const vk::DescriptorSet::Bindings &descriptorSets; |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 46 | |
Nicolas Capens | 2855636 | 2021-07-24 02:36:09 -0400 | [diff] [blame] | 47 | virtual void setBuiltins(Int &x, Int &y, Float4 (&z)[4], Float4 &w, Int cMask[4], const SampleSet &samples) = 0; |
| 48 | virtual void executeShader(Int cMask[4], Int sMask[4], Int zMask[4], const SampleSet &samples) = 0; |
| 49 | virtual Bool alphaTest(Int cMask[4], const SampleSet &samples) = 0; |
Nicolas Capens | efbbb2f | 2021-09-22 14:20:09 -0400 | [diff] [blame] | 50 | virtual void blendColor(Pointer<Byte> cBuffer[4], Int &x, Int sMask[4], Int zMask[4], Int cMask[4], const SampleSet &samples) = 0; |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 51 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 52 | 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] | 53 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 54 | void alphaTest(Int &aMask, const Short4 &alpha); |
Nicolas Capens | 2855636 | 2021-07-24 02:36:09 -0400 | [diff] [blame] | 55 | void alphaToCoverage(Int cMask[4], const Float4 &alpha, const SampleSet &samples); |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 56 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 57 | void alphaBlend(int index, const Pointer<Byte> &cBuffer, Vector4s ¤t, const Int &x); |
Nicolas Capens | 8c5df9c | 2021-10-27 16:29:54 -0400 | [diff] [blame^] | 58 | void writeColor(int index, const Pointer<Byte> &cBuffer, const Int &x, Vector4f &color, const Int &sMask, const Int &zMask, const Int &cMask); |
| 59 | Vector4f alphaBlend(int index, const Pointer<Byte> &cBuffer, const Vector4f &sourceColor, const Int &x); |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 60 | 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] | 61 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 62 | bool isSRGB(int index) const; |
| 63 | UShort4 convertFixed16(const Float4 &cf, bool saturate = true); |
Sean Risser | b71a556 | 2021-04-01 16:44:48 -0400 | [diff] [blame] | 64 | Float4 convertFloat32(const UShort4 &cf); |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 65 | void linearToSRGB12_16(Vector4s &c); |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 66 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 67 | private: |
Alexis Hetu | 1ee36c9 | 2020-02-20 14:07:26 -0500 | [diff] [blame] | 68 | Byte8 stencilReplaceRef(bool isBack); |
Nicolas Capens | 8660e1c | 2021-07-26 19:50:09 -0400 | [diff] [blame] | 69 | void stencilTest(const Pointer<Byte> &sBuffer, const Int &x, Int sMask[4], const SampleSet &samples); |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 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); |
Nicolas Capens | 7e69c97 | 2021-09-11 00:30:57 -0400 | [diff] [blame] | 73 | Float4 clampDepth(const Float4 &z); |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 74 | 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] | 75 | 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] | 76 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 77 | void blendFactor(Vector4s &blendFactor, const Vector4s ¤t, const Vector4s &pixel, VkBlendFactor blendFactorActive); |
| 78 | void blendFactorAlpha(Vector4s &blendFactor, const Vector4s ¤t, const Vector4s &pixel, VkBlendFactor blendFactorAlphaActive); |
| 79 | void readPixel(int index, const Pointer<Byte> &cBuffer, const Int &x, Vector4s &pixel); |
Nicolas Capens | 8c5df9c | 2021-10-27 16:29:54 -0400 | [diff] [blame^] | 80 | void blendFactorRGB(Vector4f &blendFactorRGB, const Vector4f &sourceColor, const Vector4f &destColor, VkBlendFactor colorBlendFactor, vk::Format format); |
| 81 | void blendFactorAlpha(Float4 &blendFactorAlpha, const Float4 &sourceAlpha, const Float4 &destAlpha, VkBlendFactor alphaBlendFactor, vk::Format format); |
Nicolas Capens | 8660e1c | 2021-07-26 19:50:09 -0400 | [diff] [blame] | 82 | void writeStencil(Pointer<Byte> &sBuffer, const Int &x, const Int sMask[4], const Int zMask[4], const Int cMask[4], const SampleSet &samples); |
| 83 | void writeDepth(Pointer<Byte> &zBuffer, const Int &x, const Int zMask[4], const SampleSet &samples); |
| 84 | void occlusionSampleCount(const Int zMask[4], const Int sMask[4], const SampleSet &samples); |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 85 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 86 | void sRGBtoLinear16_12_16(Vector4s &c); |
| 87 | void linearToSRGB16_12_16(Vector4s &c); |
| 88 | Float4 sRGBtoLinear(const Float4 &x); |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 89 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 90 | Bool depthTest32F(const Pointer<Byte> &zBuffer, int q, const Int &x, const Float4 &z, const Int &sMask, Int &zMask, const Int &cMask); |
| 91 | 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] | 92 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 93 | void writeDepth32F(Pointer<Byte> &zBuffer, int q, const Int &x, const Float4 &z, const Int &zMask); |
| 94 | 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] | 95 | |
| 96 | Int4 depthBoundsTest32F(const Pointer<Byte> &zBuffer, int q, const Int &x); |
| 97 | Int4 depthBoundsTest16(const Pointer<Byte> &zBuffer, int q, const Int &x); |
Nicolas Capens | 8460144 | 2021-07-26 17:07:13 -0400 | [diff] [blame] | 98 | |
| 99 | // Derived state parameters |
| 100 | const bool shaderContainsInterpolation; // TODO(b/194714095) |
| 101 | const bool shaderContainsSampleQualifier; |
| 102 | const bool perSampleShading; |
| 103 | const int invocationCount; |
Nicolas Capens | 2855636 | 2021-07-24 02:36:09 -0400 | [diff] [blame] | 104 | |
| 105 | SampleSet getSampleSet(int invocation) const; |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 106 | }; |
Chris Forbes | bea4751 | 2019-03-12 14:50:55 -0700 | [diff] [blame] | 107 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 108 | } // namespace sw |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 109 | |
Ben Clayton | bc1c067be | 2019-12-17 20:37:37 +0000 | [diff] [blame] | 110 | #endif // sw_PixelRoutine_hpp |