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 	deUint32			coverage;
52 	const float*		sampleDepths;
53 
Fragmentrr::Fragment54 	Fragment (const tcu::IVec2& pixelCoord_, const GenericVec4& value_, deUint32 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_, deUint32 coverage_, const float* sampleDepths_)
64 		: pixelCoord	(pixelCoord_)
65 		, value			(value_)
66 		, value1		(value1_)
67 		, coverage		(coverage_)
68 		, sampleDepths	(sampleDepths_)
69 	{
70 	}
71 
Fragmentrr::Fragment72 	Fragment (void)
73 		: pixelCoord	(0)
74 		, value			()
75 		, coverage		(0)
76 		, sampleDepths	(DE_NULL)
77 	{
78 	}
79 } DE_WARN_UNUSED_TYPE;
80 
81 // These functions are for clearing only a specific pixel rectangle in a multisample buffer.
82 // When clearing the entire buffer, tcu::clear, tcu::clearDepth and tcu::clearStencil can be used.
83 void clearMultisampleColorBuffer		(const tcu::PixelBufferAccess& dst, const tcu::Vec4&	value, const WindowRectangle& rect);
84 void clearMultisampleColorBuffer		(const tcu::PixelBufferAccess& dst, const tcu::IVec4&	value, const WindowRectangle& rect);
85 void clearMultisampleColorBuffer		(const tcu::PixelBufferAccess& dst, const tcu::UVec4&	value, 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,
104 									 const Fragment*							fragments,
105 									 int										numFragments,
106 									 FaceType									fragmentFacing,
107 									 const FragmentOperationState&				state);
108 
109 private:
110 	enum
111 	{
112 		SAMPLE_REGISTER_SIZE = 64
113 	};
114 	struct SampleData
115 	{
116 		bool						isAlive;
117 		bool						stencilPassed;
118 		bool						depthPassed;
119 		tcu::Vec4					clampedBlendSrcColor;
120 		tcu::Vec4					clampedBlendSrc1Color;
121 		tcu::Vec4					clampedBlendDstColor;
122 		tcu::Vec3					blendSrcFactorRGB;
123 		float						blendSrcFactorA;
124 		tcu::Vec3					blendDstFactorRGB;
125 		float						blendDstFactorA;
126 		tcu::Vec3					blendedRGB;
127 		float						blendedA;
128 		tcu::Vector<deInt32,  4>	signedValue;		//!< integer targets
129 		tcu::Vector<deUint32, 4>	unsignedValue;		//!< unsigned integer targets
130 	};
131 
132 	// These functions operate on the values in m_sampleRegister and, in some cases, the buffers.
133 
134 	void		executeScissorTest				(int fragNdxOffset, int numSamplesPerFragment, const Fragment* inputFragments, const WindowRectangle& scissorRect);
135 	void		executeStencilCompare			(int fragNdxOffset, int numSamplesPerFragment, const Fragment* inputFragments, const StencilState& stencilState, int numStencilBits, const tcu::ConstPixelBufferAccess& stencilBuffer);
136 	void		executeStencilSFail				(int fragNdxOffset, int numSamplesPerFragment, const Fragment* inputFragments, const StencilState& stencilState, int numStencilBits, const tcu::PixelBufferAccess& stencilBuffer);
137 	void		executeDepthCompare				(int fragNdxOffset, int numSamplesPerFragment, const Fragment* inputFragments, TestFunc depthFunc, const tcu::ConstPixelBufferAccess& depthBuffer);
138 	void		executeDepthWrite				(int fragNdxOffset, int numSamplesPerFragment, const Fragment* inputFragments, const tcu::PixelBufferAccess& depthBuffer);
139 	void		executeStencilDpFailAndPass		(int fragNdxOffset, int numSamplesPerFragment, const Fragment* inputFragments, const StencilState& stencilState, int numStencilBits, const tcu::PixelBufferAccess& stencilBuffer);
140 	void		executeBlendFactorComputeRGB	(const tcu::Vec4& blendColor, const BlendState& blendRGBState);
141 	void		executeBlendFactorComputeA		(const tcu::Vec4& blendColor, const BlendState& blendAState);
142 	void		executeBlend					(const BlendState& blendRGBState, const BlendState& blendAState);
143 	void		executeAdvancedBlend			(BlendEquationAdvanced equation);
144 
145 	void		executeColorWrite				(int fragNdxOffset, int numSamplesPerFragment, const Fragment* inputFragments, bool isSRGB, const tcu::PixelBufferAccess& colorBuffer);
146 	void		executeRGBA8ColorWrite			(int fragNdxOffset, int numSamplesPerFragment, const Fragment* inputFragments, const tcu::PixelBufferAccess& colorBuffer);
147 	void		executeMaskedColorWrite			(int fragNdxOffset, int numSamplesPerFragment, const Fragment* inputFragments, const tcu::Vec4& colorMaskFactor, const tcu::Vec4& colorMaskNegationFactor, bool isSRGB, const tcu::PixelBufferAccess& colorBuffer);
148 	void		executeSignedValueWrite			(int fragNdxOffset, int numSamplesPerFragment, const Fragment* inputFragments, const tcu::BVec4& colorMask, const tcu::PixelBufferAccess& colorBuffer);
149 	void		executeUnsignedValueWrite		(int fragNdxOffset, int numSamplesPerFragment, const Fragment* inputFragments, const tcu::BVec4& colorMask, const tcu::PixelBufferAccess& colorBuffer);
150 
151 	SampleData	m_sampleRegister[SAMPLE_REGISTER_SIZE];
152 } DE_WARN_UNUSED_TYPE;
153 
154 } // rr
155 
156 #endif // _RRFRAGMENTOPERATIONS_HPP
157