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 | |
Nicolas Capens | afdb512 | 2022-06-30 11:31:35 -0400 | [diff] [blame] | 40 | SIMD::Float z[4]; // Multisampled z |
| 41 | SIMD::Float w; // Used as is |
| 42 | SIMD::Float 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 | afdb512 | 2022-06-30 11:31:35 -0400 | [diff] [blame] | 47 | virtual void setBuiltins(Int &x, Int &y, SIMD::Float (&z)[4], SIMD::Float &w, Int cMask[4], const SampleSet &samples) = 0; |
Nicolas Capens | 2855636 | 2021-07-24 02:36:09 -0400 | [diff] [blame] | 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 | afdb512 | 2022-06-30 11:31:35 -0400 | [diff] [blame] | 55 | void alphaToCoverage(Int cMask[4], const SIMD::Float &alpha, const SampleSet &samples); |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 56 | |
Nicolas Capens | 8c5df9c | 2021-10-27 16:29:54 -0400 | [diff] [blame] | 57 | void writeColor(int index, const Pointer<Byte> &cBuffer, const Int &x, Vector4f &color, const Int &sMask, const Int &zMask, const Int &cMask); |
Nicolas Capens | d1116fa | 2022-06-29 10:39:18 -0400 | [diff] [blame] | 58 | SIMD::Float4 alphaBlend(int index, const Pointer<Byte> &cBuffer, const SIMD::Float4 &sourceColor, const Int &x); |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 59 | 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] | 60 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 61 | bool isSRGB(int index) const; |
| 62 | UShort4 convertFixed16(const Float4 &cf, bool saturate = true); |
Sean Risser | b71a556 | 2021-04-01 16:44:48 -0400 | [diff] [blame] | 63 | Float4 convertFloat32(const UShort4 &cf); |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 64 | void linearToSRGB12_16(Vector4s &c); |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 65 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 66 | private: |
Alexis Hetu | 5c0531f | 2022-03-24 17:23:56 -0400 | [diff] [blame] | 67 | bool hasStencilReplaceRef() const; |
| 68 | Byte8 stencilReplaceRef(); |
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); |
Alexis Hetu | f729750 | 2022-06-01 12:48:20 -0400 | [diff] [blame] | 71 | Byte8 stencilOperation(const Byte8 &bufferValue, const PixelProcessor::States::StencilOpState &ops, bool isBack, const Int &zMask, const Int &sMask); |
| 72 | Byte8 stencilOperation(const Byte8 &bufferValue, VkStencilOp operation, bool isBack); |
Nicolas Capens | afdb512 | 2022-06-30 11:31:35 -0400 | [diff] [blame] | 73 | SIMD::Float clampDepth(const SIMD::Float &z); |
| 74 | Bool depthTest(const Pointer<Byte> &zBuffer, int q, const Int &x, const SIMD::Float &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 readPixel(int index, const Pointer<Byte> &cBuffer, const Int &x, Vector4s &pixel); |
Alexis Hetu | 1d6a103 | 2022-07-05 12:20:29 -0400 | [diff] [blame] | 78 | enum BlendFactorModifier |
| 79 | { |
| 80 | None, |
| 81 | OneMinus |
| 82 | }; |
Nicolas Capens | 920f829 | 2021-11-09 13:41:24 -0500 | [diff] [blame] | 83 | Float blendConstant(vk::Format format, int component, BlendFactorModifier modifier = None); |
Nicolas Capens | d1116fa | 2022-06-29 10:39:18 -0400 | [diff] [blame] | 84 | void blendFactorRGB(SIMD::Float4 &blendFactorRGB, const SIMD::Float4 &sourceColor, const SIMD::Float4 &destColor, VkBlendFactor colorBlendFactor, vk::Format format); |
Nicolas Capens | afdb512 | 2022-06-30 11:31:35 -0400 | [diff] [blame] | 85 | void blendFactorAlpha(SIMD::Float &blendFactorAlpha, const SIMD::Float &sourceAlpha, const SIMD::Float &destAlpha, VkBlendFactor alphaBlendFactor, vk::Format format); |
| 86 | |
Nicolas Capens | 7718604 | 2021-10-27 16:29:54 -0400 | [diff] [blame] | 87 | bool blendFactorCanExceedFormatRange(VkBlendFactor blendFactor, vk::Format format); |
Nicolas Capens | d1116fa | 2022-06-29 10:39:18 -0400 | [diff] [blame] | 88 | SIMD::Float4 computeAdvancedBlendMode(int index, const SIMD::Float4 &src, const SIMD::Float4 &dst, const SIMD::Float4 &srcFactor, const SIMD::Float4 &dstFactor); |
Nicolas Capens | afdb512 | 2022-06-30 11:31:35 -0400 | [diff] [blame] | 89 | SIMD::Float blendOpOverlay(SIMD::Float &src, SIMD::Float &dst); |
| 90 | SIMD::Float blendOpColorDodge(SIMD::Float &src, SIMD::Float &dst); |
| 91 | SIMD::Float blendOpColorBurn(SIMD::Float &src, SIMD::Float &dst); |
| 92 | SIMD::Float blendOpHardlight(SIMD::Float &src, SIMD::Float &dst); |
| 93 | SIMD::Float blendOpSoftlight(SIMD::Float &src, SIMD::Float &dst); |
Nicolas Capens | d1116fa | 2022-06-29 10:39:18 -0400 | [diff] [blame] | 94 | void setLumSat(SIMD::Float4 &cbase, SIMD::Float4 &csat, SIMD::Float4 &clum, SIMD::Float &x, SIMD::Float &y, SIMD::Float &z); |
| 95 | void setLum(SIMD::Float4 &cbase, SIMD::Float4 &clum, SIMD::Float &x, SIMD::Float &y, SIMD::Float &z); |
Nicolas Capens | afdb512 | 2022-06-30 11:31:35 -0400 | [diff] [blame] | 96 | SIMD::Float computeLum(SIMD::Float &color, SIMD::Float &lum, SIMD::Float &mincol, SIMD::Float &maxcol, SIMD::Int &negative, SIMD::Int &aboveOne); |
Nicolas Capens | d1116fa | 2022-06-29 10:39:18 -0400 | [diff] [blame] | 97 | SIMD::Float maxRGB(SIMD::Float4 &c); |
| 98 | SIMD::Float minRGB(SIMD::Float4 &c); |
| 99 | SIMD::Float lumRGB(SIMD::Float4 &c); |
| 100 | void premultiply(SIMD::Float4 &c); |
Nicolas Capens | afdb512 | 2022-06-30 11:31:35 -0400 | [diff] [blame] | 101 | |
Nicolas Capens | 8660e1c | 2021-07-26 19:50:09 -0400 | [diff] [blame] | 102 | void writeStencil(Pointer<Byte> &sBuffer, const Int &x, const Int sMask[4], const Int zMask[4], const Int cMask[4], const SampleSet &samples); |
| 103 | void writeDepth(Pointer<Byte> &zBuffer, const Int &x, const Int zMask[4], const SampleSet &samples); |
| 104 | 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] | 105 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 106 | void sRGBtoLinear16_12_16(Vector4s &c); |
| 107 | void linearToSRGB16_12_16(Vector4s &c); |
| 108 | Float4 sRGBtoLinear(const Float4 &x); |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 109 | |
Alexis Hetu | 1d6a103 | 2022-07-05 12:20:29 -0400 | [diff] [blame] | 110 | SIMD::Float getDepthValue32F(const Pointer<Byte> &zBuffer, int q, const Int &x) const; |
| 111 | SIMD::Float getDepthValue16(const Pointer<Byte> &zBuffer, int q, const Int &x) const; |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 112 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 113 | void writeDepth32F(Pointer<Byte> &zBuffer, int q, const Int &x, const Float4 &z, const Int &zMask); |
| 114 | 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] | 115 | |
| 116 | Int4 depthBoundsTest32F(const Pointer<Byte> &zBuffer, int q, const Int &x); |
| 117 | Int4 depthBoundsTest16(const Pointer<Byte> &zBuffer, int q, const Int &x); |
Nicolas Capens | 8460144 | 2021-07-26 17:07:13 -0400 | [diff] [blame] | 118 | |
| 119 | // Derived state parameters |
| 120 | const bool shaderContainsInterpolation; // TODO(b/194714095) |
| 121 | const bool shaderContainsSampleQualifier; |
| 122 | const bool perSampleShading; |
| 123 | const int invocationCount; |
Nicolas Capens | 2855636 | 2021-07-24 02:36:09 -0400 | [diff] [blame] | 124 | |
| 125 | SampleSet getSampleSet(int invocation) const; |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 126 | }; |
Chris Forbes | bea4751 | 2019-03-12 14:50:55 -0700 | [diff] [blame] | 127 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 128 | } // namespace sw |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 129 | |
Ben Clayton | bc1c067be | 2019-12-17 20:37:37 +0000 | [diff] [blame] | 130 | #endif // sw_PixelRoutine_hpp |