1*35238bceSAndroid Build Coastguard Worker #ifndef _RRFRAGMENTOPERATIONS_HPP 2*35238bceSAndroid Build Coastguard Worker #define _RRFRAGMENTOPERATIONS_HPP 3*35238bceSAndroid Build Coastguard Worker /*------------------------------------------------------------------------- 4*35238bceSAndroid Build Coastguard Worker * drawElements Quality Program Reference Renderer 5*35238bceSAndroid Build Coastguard Worker * ----------------------------------------------- 6*35238bceSAndroid Build Coastguard Worker * 7*35238bceSAndroid Build Coastguard Worker * Copyright 2014 The Android Open Source Project 8*35238bceSAndroid Build Coastguard Worker * 9*35238bceSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 10*35238bceSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 11*35238bceSAndroid Build Coastguard Worker * You may obtain a copy of the License at 12*35238bceSAndroid Build Coastguard Worker * 13*35238bceSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 14*35238bceSAndroid Build Coastguard Worker * 15*35238bceSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 16*35238bceSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 17*35238bceSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18*35238bceSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 19*35238bceSAndroid Build Coastguard Worker * limitations under the License. 20*35238bceSAndroid Build Coastguard Worker * 21*35238bceSAndroid Build Coastguard Worker *//*! 22*35238bceSAndroid Build Coastguard Worker * \file 23*35238bceSAndroid Build Coastguard Worker * \brief Reference implementation for per-fragment operations. 24*35238bceSAndroid Build Coastguard Worker * 25*35238bceSAndroid Build Coastguard Worker * \note In this file, a multisample buffer means a tcu::PixelBufferAccess 26*35238bceSAndroid Build Coastguard Worker * (or ConstPixelBufferAccess) where the x coordinate is the sample 27*35238bceSAndroid Build Coastguard Worker * index and the y and z coordinates are the pixel's x and y 28*35238bceSAndroid Build Coastguard Worker * coordinates, respectively. To prevent supplying a buffer in 29*35238bceSAndroid Build Coastguard Worker * a wrong format the buffers are wrapped in rr::MultisamplePixelBufferAccess 30*35238bceSAndroid Build Coastguard Worker * wrapper. FragmentProcessor::render() operates on 31*35238bceSAndroid Build Coastguard Worker * this kind of buffers. The function fromSinglesampleAccess() can be 32*35238bceSAndroid Build Coastguard Worker * used to get a one-sampled multisample access to a normal 2d 33*35238bceSAndroid Build Coastguard Worker * buffer. 34*35238bceSAndroid Build Coastguard Worker *//*--------------------------------------------------------------------*/ 35*35238bceSAndroid Build Coastguard Worker 36*35238bceSAndroid Build Coastguard Worker #include "rrDefs.hpp" 37*35238bceSAndroid Build Coastguard Worker #include "tcuVector.hpp" 38*35238bceSAndroid Build Coastguard Worker #include "tcuTexture.hpp" 39*35238bceSAndroid Build Coastguard Worker #include "rrRenderState.hpp" 40*35238bceSAndroid Build Coastguard Worker #include "rrGenericVector.hpp" 41*35238bceSAndroid Build Coastguard Worker #include "rrMultisamplePixelBufferAccess.hpp" 42*35238bceSAndroid Build Coastguard Worker 43*35238bceSAndroid Build Coastguard Worker namespace rr 44*35238bceSAndroid Build Coastguard Worker { 45*35238bceSAndroid Build Coastguard Worker 46*35238bceSAndroid Build Coastguard Worker struct Fragment 47*35238bceSAndroid Build Coastguard Worker { 48*35238bceSAndroid Build Coastguard Worker tcu::IVec2 pixelCoord; 49*35238bceSAndroid Build Coastguard Worker GenericVec4 value; 50*35238bceSAndroid Build Coastguard Worker GenericVec4 value1; 51*35238bceSAndroid Build Coastguard Worker uint32_t coverage; 52*35238bceSAndroid Build Coastguard Worker const float *sampleDepths; 53*35238bceSAndroid Build Coastguard Worker Fragmentrr::Fragment54*35238bceSAndroid Build Coastguard Worker Fragment(const tcu::IVec2 &pixelCoord_, const GenericVec4 &value_, uint32_t coverage_, const float *sampleDepths_) 55*35238bceSAndroid Build Coastguard Worker : pixelCoord(pixelCoord_) 56*35238bceSAndroid Build Coastguard Worker , value(value_) 57*35238bceSAndroid Build Coastguard Worker , value1() 58*35238bceSAndroid Build Coastguard Worker , coverage(coverage_) 59*35238bceSAndroid Build Coastguard Worker , sampleDepths(sampleDepths_) 60*35238bceSAndroid Build Coastguard Worker { 61*35238bceSAndroid Build Coastguard Worker } 62*35238bceSAndroid Build Coastguard Worker Fragmentrr::Fragment63*35238bceSAndroid Build Coastguard Worker Fragment(const tcu::IVec2 &pixelCoord_, const GenericVec4 &value_, const GenericVec4 &value1_, uint32_t coverage_, 64*35238bceSAndroid Build Coastguard Worker const float *sampleDepths_) 65*35238bceSAndroid Build Coastguard Worker : pixelCoord(pixelCoord_) 66*35238bceSAndroid Build Coastguard Worker , value(value_) 67*35238bceSAndroid Build Coastguard Worker , value1(value1_) 68*35238bceSAndroid Build Coastguard Worker , coverage(coverage_) 69*35238bceSAndroid Build Coastguard Worker , sampleDepths(sampleDepths_) 70*35238bceSAndroid Build Coastguard Worker { 71*35238bceSAndroid Build Coastguard Worker } 72*35238bceSAndroid Build Coastguard Worker Fragmentrr::Fragment73*35238bceSAndroid Build Coastguard Worker Fragment(void) : pixelCoord(0), value(), coverage(0), sampleDepths(DE_NULL) 74*35238bceSAndroid Build Coastguard Worker { 75*35238bceSAndroid Build Coastguard Worker } 76*35238bceSAndroid Build Coastguard Worker } DE_WARN_UNUSED_TYPE; 77*35238bceSAndroid Build Coastguard Worker 78*35238bceSAndroid Build Coastguard Worker // These functions are for clearing only a specific pixel rectangle in a multisample buffer. 79*35238bceSAndroid Build Coastguard Worker // When clearing the entire buffer, tcu::clear, tcu::clearDepth and tcu::clearStencil can be used. 80*35238bceSAndroid Build Coastguard Worker void clearMultisampleColorBuffer(const tcu::PixelBufferAccess &dst, const tcu::Vec4 &value, 81*35238bceSAndroid Build Coastguard Worker const WindowRectangle &rect); 82*35238bceSAndroid Build Coastguard Worker void clearMultisampleColorBuffer(const tcu::PixelBufferAccess &dst, const tcu::IVec4 &value, 83*35238bceSAndroid Build Coastguard Worker const WindowRectangle &rect); 84*35238bceSAndroid Build Coastguard Worker void clearMultisampleColorBuffer(const tcu::PixelBufferAccess &dst, const tcu::UVec4 &value, 85*35238bceSAndroid Build Coastguard Worker const WindowRectangle &rect); 86*35238bceSAndroid Build Coastguard Worker void clearMultisampleDepthBuffer(const tcu::PixelBufferAccess &dst, float value, const WindowRectangle &rect); 87*35238bceSAndroid Build Coastguard Worker void clearMultisampleStencilBuffer(const tcu::PixelBufferAccess &dst, int value, const WindowRectangle &rect); 88*35238bceSAndroid Build Coastguard Worker 89*35238bceSAndroid Build Coastguard Worker /*--------------------------------------------------------------------*//*! 90*35238bceSAndroid Build Coastguard Worker * \brief Reference fragment renderer. 91*35238bceSAndroid Build Coastguard Worker * 92*35238bceSAndroid Build Coastguard Worker * FragmentProcessor.render() draws a given set of fragments. No two 93*35238bceSAndroid Build Coastguard Worker * fragments given in one render() call should have the same pixel 94*35238bceSAndroid Build Coastguard Worker * coordinates coordinates, and they must all have the same facing. 95*35238bceSAndroid Build Coastguard Worker *//*--------------------------------------------------------------------*/ 96*35238bceSAndroid Build Coastguard Worker class FragmentProcessor 97*35238bceSAndroid Build Coastguard Worker { 98*35238bceSAndroid Build Coastguard Worker public: 99*35238bceSAndroid Build Coastguard Worker FragmentProcessor(void); 100*35238bceSAndroid Build Coastguard Worker 101*35238bceSAndroid Build Coastguard Worker void render(const rr::MultisamplePixelBufferAccess &colorMultisampleBuffer, 102*35238bceSAndroid Build Coastguard Worker const rr::MultisamplePixelBufferAccess &depthMultisampleBuffer, 103*35238bceSAndroid Build Coastguard Worker const rr::MultisamplePixelBufferAccess &stencilMultisampleBuffer, const Fragment *fragments, 104*35238bceSAndroid Build Coastguard Worker int numFragments, FaceType fragmentFacing, const FragmentOperationState &state); 105*35238bceSAndroid Build Coastguard Worker 106*35238bceSAndroid Build Coastguard Worker private: 107*35238bceSAndroid Build Coastguard Worker enum 108*35238bceSAndroid Build Coastguard Worker { 109*35238bceSAndroid Build Coastguard Worker SAMPLE_REGISTER_SIZE = 64 110*35238bceSAndroid Build Coastguard Worker }; 111*35238bceSAndroid Build Coastguard Worker struct SampleData 112*35238bceSAndroid Build Coastguard Worker { 113*35238bceSAndroid Build Coastguard Worker bool isAlive; 114*35238bceSAndroid Build Coastguard Worker bool stencilPassed; 115*35238bceSAndroid Build Coastguard Worker bool depthPassed; 116*35238bceSAndroid Build Coastguard Worker tcu::Vec4 clampedBlendSrcColor; 117*35238bceSAndroid Build Coastguard Worker tcu::Vec4 clampedBlendSrc1Color; 118*35238bceSAndroid Build Coastguard Worker tcu::Vec4 clampedBlendDstColor; 119*35238bceSAndroid Build Coastguard Worker tcu::Vec3 blendSrcFactorRGB; 120*35238bceSAndroid Build Coastguard Worker float blendSrcFactorA; 121*35238bceSAndroid Build Coastguard Worker tcu::Vec3 blendDstFactorRGB; 122*35238bceSAndroid Build Coastguard Worker float blendDstFactorA; 123*35238bceSAndroid Build Coastguard Worker tcu::Vec3 blendedRGB; 124*35238bceSAndroid Build Coastguard Worker float blendedA; 125*35238bceSAndroid Build Coastguard Worker tcu::Vector<int32_t, 4> signedValue; //!< integer targets 126*35238bceSAndroid Build Coastguard Worker tcu::Vector<uint32_t, 4> unsignedValue; //!< unsigned integer targets 127*35238bceSAndroid Build Coastguard Worker }; 128*35238bceSAndroid Build Coastguard Worker 129*35238bceSAndroid Build Coastguard Worker // These functions operate on the values in m_sampleRegister and, in some cases, the buffers. 130*35238bceSAndroid Build Coastguard Worker 131*35238bceSAndroid Build Coastguard Worker void executeScissorTest(int fragNdxOffset, int numSamplesPerFragment, const Fragment *inputFragments, 132*35238bceSAndroid Build Coastguard Worker const WindowRectangle &scissorRect); 133*35238bceSAndroid Build Coastguard Worker void executeStencilCompare(int fragNdxOffset, int numSamplesPerFragment, const Fragment *inputFragments, 134*35238bceSAndroid Build Coastguard Worker const StencilState &stencilState, int numStencilBits, 135*35238bceSAndroid Build Coastguard Worker const tcu::ConstPixelBufferAccess &stencilBuffer); 136*35238bceSAndroid Build Coastguard Worker void executeStencilSFail(int fragNdxOffset, int numSamplesPerFragment, const Fragment *inputFragments, 137*35238bceSAndroid Build Coastguard Worker const StencilState &stencilState, int numStencilBits, 138*35238bceSAndroid Build Coastguard Worker const tcu::PixelBufferAccess &stencilBuffer); 139*35238bceSAndroid Build Coastguard Worker void executeDepthBoundsTest(int fragNdxOffset, int numSamplesPerFragment, const Fragment *inputFragments, 140*35238bceSAndroid Build Coastguard Worker const float minDepthBound, const float maxDepthBound, 141*35238bceSAndroid Build Coastguard Worker const tcu::ConstPixelBufferAccess &depthBuffer); 142*35238bceSAndroid Build Coastguard Worker void executeDepthCompare(int fragNdxOffset, int numSamplesPerFragment, const Fragment *inputFragments, 143*35238bceSAndroid Build Coastguard Worker TestFunc depthFunc, const tcu::ConstPixelBufferAccess &depthBuffer); 144*35238bceSAndroid Build Coastguard Worker void executeDepthWrite(int fragNdxOffset, int numSamplesPerFragment, const Fragment *inputFragments, 145*35238bceSAndroid Build Coastguard Worker const tcu::PixelBufferAccess &depthBuffer); 146*35238bceSAndroid Build Coastguard Worker void executeStencilDpFailAndPass(int fragNdxOffset, int numSamplesPerFragment, const Fragment *inputFragments, 147*35238bceSAndroid Build Coastguard Worker const StencilState &stencilState, int numStencilBits, 148*35238bceSAndroid Build Coastguard Worker const tcu::PixelBufferAccess &stencilBuffer); 149*35238bceSAndroid Build Coastguard Worker void executeBlendFactorComputeRGB(const tcu::Vec4 &blendColor, const BlendState &blendRGBState); 150*35238bceSAndroid Build Coastguard Worker void executeBlendFactorComputeA(const tcu::Vec4 &blendColor, const BlendState &blendAState); 151*35238bceSAndroid Build Coastguard Worker void executeBlend(const BlendState &blendRGBState, const BlendState &blendAState); 152*35238bceSAndroid Build Coastguard Worker void executeAdvancedBlend(BlendEquationAdvanced equation); 153*35238bceSAndroid Build Coastguard Worker 154*35238bceSAndroid Build Coastguard Worker void executeColorWrite(int fragNdxOffset, int numSamplesPerFragment, const Fragment *inputFragments, bool isSRGB, 155*35238bceSAndroid Build Coastguard Worker const tcu::PixelBufferAccess &colorBuffer); 156*35238bceSAndroid Build Coastguard Worker void executeRGBA8ColorWrite(int fragNdxOffset, int numSamplesPerFragment, const Fragment *inputFragments, 157*35238bceSAndroid Build Coastguard Worker const tcu::PixelBufferAccess &colorBuffer); 158*35238bceSAndroid Build Coastguard Worker void executeMaskedColorWrite(int fragNdxOffset, int numSamplesPerFragment, const Fragment *inputFragments, 159*35238bceSAndroid Build Coastguard Worker const tcu::Vec4 &colorMaskFactor, const tcu::Vec4 &colorMaskNegationFactor, 160*35238bceSAndroid Build Coastguard Worker bool isSRGB, const tcu::PixelBufferAccess &colorBuffer); 161*35238bceSAndroid Build Coastguard Worker void executeSignedValueWrite(int fragNdxOffset, int numSamplesPerFragment, const Fragment *inputFragments, 162*35238bceSAndroid Build Coastguard Worker const tcu::BVec4 &colorMask, const tcu::PixelBufferAccess &colorBuffer); 163*35238bceSAndroid Build Coastguard Worker void executeUnsignedValueWrite(int fragNdxOffset, int numSamplesPerFragment, const Fragment *inputFragments, 164*35238bceSAndroid Build Coastguard Worker const tcu::BVec4 &colorMask, const tcu::PixelBufferAccess &colorBuffer); 165*35238bceSAndroid Build Coastguard Worker 166*35238bceSAndroid Build Coastguard Worker SampleData m_sampleRegister[SAMPLE_REGISTER_SIZE]; 167*35238bceSAndroid Build Coastguard Worker } DE_WARN_UNUSED_TYPE; 168*35238bceSAndroid Build Coastguard Worker 169*35238bceSAndroid Build Coastguard Worker } // namespace rr 170*35238bceSAndroid Build Coastguard Worker 171*35238bceSAndroid Build Coastguard Worker #endif // _RRFRAGMENTOPERATIONS_HPP 172