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