1*03ce13f7SAndroid Build Coastguard Worker // Copyright 2016 The SwiftShader Authors. All Rights Reserved. 2*03ce13f7SAndroid Build Coastguard Worker // 3*03ce13f7SAndroid Build Coastguard Worker // Licensed under the Apache License, Version 2.0 (the "License"); 4*03ce13f7SAndroid Build Coastguard Worker // you may not use this file except in compliance with the License. 5*03ce13f7SAndroid Build Coastguard Worker // You may obtain a copy of the License at 6*03ce13f7SAndroid Build Coastguard Worker // 7*03ce13f7SAndroid Build Coastguard Worker // http://www.apache.org/licenses/LICENSE-2.0 8*03ce13f7SAndroid Build Coastguard Worker // 9*03ce13f7SAndroid Build Coastguard Worker // Unless required by applicable law or agreed to in writing, software 10*03ce13f7SAndroid Build Coastguard Worker // distributed under the License is distributed on an "AS IS" BASIS, 11*03ce13f7SAndroid Build Coastguard Worker // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12*03ce13f7SAndroid Build Coastguard Worker // See the License for the specific language governing permissions and 13*03ce13f7SAndroid Build Coastguard Worker // limitations under the License. 14*03ce13f7SAndroid Build Coastguard Worker 15*03ce13f7SAndroid Build Coastguard Worker #ifndef sw_PixelRoutine_hpp 16*03ce13f7SAndroid Build Coastguard Worker #define sw_PixelRoutine_hpp 17*03ce13f7SAndroid Build Coastguard Worker 18*03ce13f7SAndroid Build Coastguard Worker #include "Device/QuadRasterizer.hpp" 19*03ce13f7SAndroid Build Coastguard Worker 20*03ce13f7SAndroid Build Coastguard Worker #include <vector> 21*03ce13f7SAndroid Build Coastguard Worker 22*03ce13f7SAndroid Build Coastguard Worker namespace sw { 23*03ce13f7SAndroid Build Coastguard Worker 24*03ce13f7SAndroid Build Coastguard Worker class PixelShader; 25*03ce13f7SAndroid Build Coastguard Worker class SamplerCore; 26*03ce13f7SAndroid Build Coastguard Worker 27*03ce13f7SAndroid Build Coastguard Worker class PixelRoutine : public sw::QuadRasterizer 28*03ce13f7SAndroid Build Coastguard Worker { 29*03ce13f7SAndroid Build Coastguard Worker public: 30*03ce13f7SAndroid Build Coastguard Worker PixelRoutine(const PixelProcessor::State &state, 31*03ce13f7SAndroid Build Coastguard Worker const vk::PipelineLayout *pipelineLayout, 32*03ce13f7SAndroid Build Coastguard Worker const SpirvShader *spirvShader, 33*03ce13f7SAndroid Build Coastguard Worker const vk::Attachments &attachments, 34*03ce13f7SAndroid Build Coastguard Worker const vk::DescriptorSet::Bindings &descriptorSets); 35*03ce13f7SAndroid Build Coastguard Worker 36*03ce13f7SAndroid Build Coastguard Worker virtual ~PixelRoutine(); 37*03ce13f7SAndroid Build Coastguard Worker 38*03ce13f7SAndroid Build Coastguard Worker protected: 39*03ce13f7SAndroid Build Coastguard Worker using SampleSet = std::vector<int>; 40*03ce13f7SAndroid Build Coastguard Worker 41*03ce13f7SAndroid Build Coastguard Worker SIMD::Float z[4]; // Multisampled z 42*03ce13f7SAndroid Build Coastguard Worker SIMD::Float w; // Used as is 43*03ce13f7SAndroid Build Coastguard Worker SIMD::Float rhw; // Reciprocal w 44*03ce13f7SAndroid Build Coastguard Worker 45*03ce13f7SAndroid Build Coastguard Worker SpirvRoutine routine; 46*03ce13f7SAndroid Build Coastguard Worker const vk::Attachments &attachments; 47*03ce13f7SAndroid Build Coastguard Worker const vk::DescriptorSet::Bindings &descriptorSets; 48*03ce13f7SAndroid Build Coastguard Worker 49*03ce13f7SAndroid Build Coastguard Worker virtual void setBuiltins(Int &x, Int &y, SIMD::Float (&z)[4], SIMD::Float &w, Int cMask[4], const SampleSet &samples) = 0; 50*03ce13f7SAndroid Build Coastguard Worker virtual void executeShader(Int cMask[4], Int sMask[4], Int zMask[4], const SampleSet &samples) = 0; 51*03ce13f7SAndroid Build Coastguard Worker virtual Bool alphaTest(Int cMask[4], const SampleSet &samples) = 0; 52*03ce13f7SAndroid Build Coastguard Worker virtual void blendColor(Pointer<Byte> cBuffer[4], Int &x, Int sMask[4], Int zMask[4], Int cMask[4], const SampleSet &samples) = 0; 53*03ce13f7SAndroid Build Coastguard Worker 54*03ce13f7SAndroid Build Coastguard Worker void quad(Pointer<Byte> cBuffer[4], Pointer<Byte> &zBuffer, Pointer<Byte> &sBuffer, Int cMask[4], Int &x, Int &y) override; 55*03ce13f7SAndroid Build Coastguard Worker 56*03ce13f7SAndroid Build Coastguard Worker void alphaTest(Int &aMask, const Short4 &alpha); 57*03ce13f7SAndroid Build Coastguard Worker void alphaToCoverage(Int cMask[4], const SIMD::Float &alpha, const SampleSet &samples); 58*03ce13f7SAndroid Build Coastguard Worker 59*03ce13f7SAndroid Build Coastguard Worker void writeColor(int index, const Pointer<Byte> &cBuffer, const Int &x, Vector4f &color, const Int &sMask, const Int &zMask, const Int &cMask); 60*03ce13f7SAndroid Build Coastguard Worker SIMD::Float4 alphaBlend(int index, const Pointer<Byte> &cBuffer, const SIMD::Float4 &sourceColor, const Int &x); 61*03ce13f7SAndroid Build Coastguard Worker 62*03ce13f7SAndroid Build Coastguard Worker bool isSRGB(int index) const; 63*03ce13f7SAndroid Build Coastguard Worker 64*03ce13f7SAndroid Build Coastguard Worker private: 65*03ce13f7SAndroid Build Coastguard Worker bool hasStencilReplaceRef() const; 66*03ce13f7SAndroid Build Coastguard Worker Byte8 stencilReplaceRef(); 67*03ce13f7SAndroid Build Coastguard Worker void stencilTest(const Pointer<Byte> &sBuffer, const Int &x, Int sMask[4], const SampleSet &samples); 68*03ce13f7SAndroid Build Coastguard Worker void stencilTest(Byte8 &value, VkCompareOp stencilCompareMode, bool isBack); 69*03ce13f7SAndroid Build Coastguard Worker Byte8 stencilOperation(const Byte8 &bufferValue, const PixelProcessor::States::StencilOpState &ops, bool isBack, const Int &zMask, const Int &sMask); 70*03ce13f7SAndroid Build Coastguard Worker Byte8 stencilOperation(const Byte8 &bufferValue, VkStencilOp operation, bool isBack); 71*03ce13f7SAndroid Build Coastguard Worker SIMD::Float clampDepth(const SIMD::Float &z); 72*03ce13f7SAndroid Build Coastguard Worker Bool depthTest(const Pointer<Byte> &zBuffer, int q, const Int &x, const SIMD::Float &z, const Int &sMask, Int &zMask, const Int &cMask); 73*03ce13f7SAndroid Build Coastguard Worker void depthBoundsTest(const Pointer<Byte> &zBuffer, int q, const Int &x, Int &zMask, Int &cMask); 74*03ce13f7SAndroid Build Coastguard Worker 75*03ce13f7SAndroid Build Coastguard Worker void readPixel(int index, const Pointer<Byte> &cBuffer, const Int &x, Vector4s &pixel); 76*03ce13f7SAndroid Build Coastguard Worker enum BlendFactorModifier 77*03ce13f7SAndroid Build Coastguard Worker { 78*03ce13f7SAndroid Build Coastguard Worker None, 79*03ce13f7SAndroid Build Coastguard Worker OneMinus 80*03ce13f7SAndroid Build Coastguard Worker }; 81*03ce13f7SAndroid Build Coastguard Worker Float blendConstant(vk::Format format, int component, BlendFactorModifier modifier = None); 82*03ce13f7SAndroid Build Coastguard Worker void blendFactorRGB(SIMD::Float4 &blendFactorRGB, const SIMD::Float4 &sourceColor, const SIMD::Float4 &destColor, VkBlendFactor colorBlendFactor, vk::Format format); 83*03ce13f7SAndroid Build Coastguard Worker void blendFactorAlpha(SIMD::Float &blendFactorAlpha, const SIMD::Float &sourceAlpha, const SIMD::Float &destAlpha, VkBlendFactor alphaBlendFactor, vk::Format format); 84*03ce13f7SAndroid Build Coastguard Worker 85*03ce13f7SAndroid Build Coastguard Worker bool blendFactorCanExceedFormatRange(VkBlendFactor blendFactor, vk::Format format); 86*03ce13f7SAndroid Build Coastguard Worker SIMD::Float4 computeAdvancedBlendMode(int index, const SIMD::Float4 &src, const SIMD::Float4 &dst, const SIMD::Float4 &srcFactor, const SIMD::Float4 &dstFactor); 87*03ce13f7SAndroid Build Coastguard Worker SIMD::Float blendOpOverlay(SIMD::Float &src, SIMD::Float &dst); 88*03ce13f7SAndroid Build Coastguard Worker SIMD::Float blendOpColorDodge(SIMD::Float &src, SIMD::Float &dst); 89*03ce13f7SAndroid Build Coastguard Worker SIMD::Float blendOpColorBurn(SIMD::Float &src, SIMD::Float &dst); 90*03ce13f7SAndroid Build Coastguard Worker SIMD::Float blendOpHardlight(SIMD::Float &src, SIMD::Float &dst); 91*03ce13f7SAndroid Build Coastguard Worker SIMD::Float blendOpSoftlight(SIMD::Float &src, SIMD::Float &dst); 92*03ce13f7SAndroid Build Coastguard Worker void setLumSat(SIMD::Float4 &cbase, SIMD::Float4 &csat, SIMD::Float4 &clum, SIMD::Float &x, SIMD::Float &y, SIMD::Float &z); 93*03ce13f7SAndroid Build Coastguard Worker void setLum(SIMD::Float4 &cbase, SIMD::Float4 &clum, SIMD::Float &x, SIMD::Float &y, SIMD::Float &z); 94*03ce13f7SAndroid Build Coastguard Worker SIMD::Float computeLum(SIMD::Float &color, SIMD::Float &lum, SIMD::Float &mincol, SIMD::Float &maxcol, SIMD::Int &negative, SIMD::Int &aboveOne); 95*03ce13f7SAndroid Build Coastguard Worker SIMD::Float maxRGB(SIMD::Float4 &c); 96*03ce13f7SAndroid Build Coastguard Worker SIMD::Float minRGB(SIMD::Float4 &c); 97*03ce13f7SAndroid Build Coastguard Worker SIMD::Float lumRGB(SIMD::Float4 &c); 98*03ce13f7SAndroid Build Coastguard Worker void premultiply(SIMD::Float4 &c); 99*03ce13f7SAndroid Build Coastguard Worker 100*03ce13f7SAndroid Build Coastguard Worker void writeStencil(Pointer<Byte> &sBuffer, const Int &x, const Int sMask[4], const Int zMask[4], const Int cMask[4], const SampleSet &samples); 101*03ce13f7SAndroid Build Coastguard Worker void writeDepth(Pointer<Byte> &zBuffer, const Int &x, const Int zMask[4], const SampleSet &samples); 102*03ce13f7SAndroid Build Coastguard Worker void occlusionSampleCount(const Int zMask[4], const Int sMask[4], const SampleSet &samples); 103*03ce13f7SAndroid Build Coastguard Worker 104*03ce13f7SAndroid Build Coastguard Worker SIMD::Float readDepth32F(const Pointer<Byte> &zBuffer, int q, const Int &x) const; 105*03ce13f7SAndroid Build Coastguard Worker SIMD::Float readDepth16(const Pointer<Byte> &zBuffer, int q, const Int &x) const; 106*03ce13f7SAndroid Build Coastguard Worker 107*03ce13f7SAndroid Build Coastguard Worker void writeDepth32F(Pointer<Byte> &zBuffer, int q, const Int &x, const Float4 &z, const Int &zMask); 108*03ce13f7SAndroid Build Coastguard Worker void writeDepth16(Pointer<Byte> &zBuffer, int q, const Int &x, const Float4 &z, const Int &zMask); 109*03ce13f7SAndroid Build Coastguard Worker 110*03ce13f7SAndroid Build Coastguard Worker Int4 depthBoundsTest32F(const Pointer<Byte> &zBuffer, int q, const Int &x); 111*03ce13f7SAndroid Build Coastguard Worker Int4 depthBoundsTest16(const Pointer<Byte> &zBuffer, int q, const Int &x); 112*03ce13f7SAndroid Build Coastguard Worker 113*03ce13f7SAndroid Build Coastguard Worker // Derived state parameters 114*03ce13f7SAndroid Build Coastguard Worker const bool shaderContainsInterpolation; // TODO(b/194714095) 115*03ce13f7SAndroid Build Coastguard Worker const bool perSampleShading; 116*03ce13f7SAndroid Build Coastguard Worker const int invocationCount; 117*03ce13f7SAndroid Build Coastguard Worker 118*03ce13f7SAndroid Build Coastguard Worker SampleSet getSampleSet(int invocation) const; 119*03ce13f7SAndroid Build Coastguard Worker }; 120*03ce13f7SAndroid Build Coastguard Worker 121*03ce13f7SAndroid Build Coastguard Worker } // namespace sw 122*03ce13f7SAndroid Build Coastguard Worker 123*03ce13f7SAndroid Build Coastguard Worker #endif // sw_PixelRoutine_hpp 124