1 /****************************************************************************
2 * Copyright (C) 2014-2015 Intel Corporation. All Rights Reserved.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
25 * @brief Definitions for the rasterizer.
27 ******************************************************************************/
31 #include <type_traits>
32 #include "conservativeRast.h"
33 #include "multisample.h"
35 void RasterizeLine(DRAW_CONTEXT
*pDC
, uint32_t workerId
, uint32_t macroTile
, void *pData
);
36 void RasterizeSimplePoint(DRAW_CONTEXT
*pDC
, uint32_t workerId
, uint32_t macroTile
, void *pData
);
37 void RasterizeTriPoint(DRAW_CONTEXT
*pDC
, uint32_t workerId
, uint32_t macroTile
, void *pData
);
40 __m128i
fpToFixedPoint(const __m128 vIn
)
42 __m128 vFixed
= _mm_mul_ps(vIn
, _mm_set1_ps(FIXED_POINT_SCALE
));
43 return _mm_cvtps_epi32(vFixed
);
46 // Selector for correct templated RasterizeTriangle function
47 PFN_WORK_FUNC
GetRasterizerFunc(
51 uint32_t InputCoverage
,
53 bool RasterizeScissorEdges
);
57 STATE_NO_VALID_EDGES
= 0,
61 STATE_ALL_EDGES_VALID
,
62 STATE_VALID_TRI_EDGE_COUNT
,
71 ALL_EDGES_VALID
= 0x7,
75 //////////////////////////////////////////////////////////////////////////
76 /// @brief ValidTriEdges convenience typedefs used for templated function
77 /// specialization supported Fixed Point precisions
78 typedef std::integral_constant
<uint32_t, ALL_EDGES_VALID
> AllEdgesValidT
;
79 typedef std::integral_constant
<uint32_t, E0_E1_VALID
> E0E1ValidT
;
80 typedef std::integral_constant
<uint32_t, E0_E2_VALID
> E0E2ValidT
;
81 typedef std::integral_constant
<uint32_t, E1_E2_VALID
> E1E2ValidT
;
82 typedef std::integral_constant
<uint32_t, NO_VALID_EDGES
> NoEdgesValidT
;
84 typedef std::integral_constant
<uint32_t, STATE_ALL_EDGES_VALID
> StateAllEdgesValidT
;
85 typedef std::integral_constant
<uint32_t, STATE_E0_E1_VALID
> StateE0E1ValidT
;
86 typedef std::integral_constant
<uint32_t, STATE_E0_E2_VALID
> StateE0E2ValidT
;
87 typedef std::integral_constant
<uint32_t, STATE_E1_E2_VALID
> StateE1E2ValidT
;
88 typedef std::integral_constant
<uint32_t, STATE_NO_VALID_EDGES
> StateNoEdgesValidT
;
90 // some specializations to convert from edge state to edge bitmask values
91 template <typename EdgeMask
>
94 static_assert(EdgeMask::value
> STATE_ALL_EDGES_VALID
, "Primary EdgeMaskVal shouldn't be instantiated");
98 struct EdgeMaskVal
<StateAllEdgesValidT
>
100 typedef AllEdgesValidT T
;
104 struct EdgeMaskVal
<StateE0E1ValidT
>
106 typedef E0E1ValidT T
;
110 struct EdgeMaskVal
<StateE0E2ValidT
>
112 typedef E0E2ValidT T
;
116 struct EdgeMaskVal
<StateE1E2ValidT
>
118 typedef E1E2ValidT T
;
122 struct EdgeMaskVal
<StateNoEdgesValidT
>
124 typedef NoEdgesValidT T
;
127 INLINE
uint32_t EdgeValToEdgeState(uint32_t val
)
129 SWR_ASSERT(val
< VALID_TRI_EDGE_COUNT
, "Unexpected tri edge mask");
130 static const uint32_t edgeValToEdgeState
[VALID_TRI_EDGE_COUNT
] = { 0, 0, 0, 1, 0, 2, 3, 4 };
131 return edgeValToEdgeState
[val
];
134 //////////////////////////////////////////////////////////////////////////
135 /// @struct RasterScissorEdgesT
136 /// @brief Primary RasterScissorEdgesT templated struct that holds compile
137 /// time information about the number of edges needed to be rasterized,
138 /// If either the scissor rect or conservative rast is enabled,
139 /// the scissor test is enabled and the rasterizer will test
140 /// 3 triangle edges + 4 scissor edges for coverage.
141 /// @tparam RasterScissorEdgesT: number of multisamples
142 /// @tparam ConservativeT: is this a conservative rasterization
143 /// @tparam EdgeMaskT: Which edges are valid(not degenerate)
144 template <typename RasterScissorEdgesT
, typename ConservativeT
, typename EdgeMaskT
>
145 struct RasterEdgeTraits
147 typedef std::true_type RasterizeScissorEdgesT
;
148 typedef std::integral_constant
<uint32_t, 7> NumEdgesT
;
149 //typedef std::integral_constant<uint32_t, EdgeMaskT::value> ValidEdgeMaskT;
150 typedef typename EdgeMaskVal
<EdgeMaskT
>::T ValidEdgeMaskT
;
153 //////////////////////////////////////////////////////////////////////////
154 /// @brief specialization of RasterEdgeTraits. If neither scissor rect
155 /// nor conservative rast is enabled, only test 3 triangle edges
157 template <typename EdgeMaskT
>
158 struct RasterEdgeTraits
<std::false_type
, std::false_type
, EdgeMaskT
>
160 typedef std::false_type RasterizeScissorEdgesT
;
161 typedef std::integral_constant
<uint32_t, 3> NumEdgesT
;
162 // no need for degenerate edge masking in non-conservative case; rasterize all triangle edges
163 typedef std::integral_constant
<uint32_t, ALL_EDGES_VALID
> ValidEdgeMaskT
;
166 //////////////////////////////////////////////////////////////////////////
167 /// @struct RasterizerTraits
168 /// @brief templated struct that holds compile time information used
169 /// during rasterization. Inherits EdgeTraits and ConservativeRastBETraits.
170 /// @tparam NumSamplesT: number of multisamples
171 /// @tparam ConservativeT: is this a conservative rasterization
172 /// @tparam InputCoverageT: what type of input coverage is the PS expecting?
173 /// (only used with conservative rasterization)
174 /// @tparam RasterScissorEdgesT: do we need to rasterize with a scissor?
175 template <typename NumSamplesT
, typename CenterPatternT
, typename ConservativeT
, typename InputCoverageT
, typename EdgeEnableT
, typename RasterScissorEdgesT
>
176 struct RasterizerTraits final
: public ConservativeRastBETraits
<ConservativeT
, InputCoverageT
>,
177 public RasterEdgeTraits
<RasterScissorEdgesT
, ConservativeT
, EdgeEnableT
>
179 typedef MultisampleTraits
<static_cast<SWR_MULTISAMPLE_COUNT
>(NumSamplesT::value
), CenterPatternT::value
> MT
;
181 /// Fixed point precision the rasterizer is using
182 typedef FixedPointTraits
<Fixed_16_8
> PrecisionT
;
183 /// Fixed point precision of the edge tests used during rasterization
184 typedef FixedPointTraits
<Fixed_X_16
> EdgePrecisionT
;
186 // If conservative rast or MSAA center pattern is enabled, only need a single sample coverage test, with the result copied to all samples
187 typedef std::integral_constant
<int, ConservativeT::value
? 1 : MT::numCoverageSamples
> NumCoverageSamplesT
;
189 static_assert(EdgePrecisionT::BitsT::value
>= ConservativeRastBETraits
<ConservativeT
, InputCoverageT
>::ConservativePrecisionT::BitsT::value
,
190 "Rasterizer edge fixed point precision < required conservative rast precision");
192 /// constants used to offset between different types of raster tiles
193 static const int colorRasterTileStep
{(KNOB_TILE_X_DIM
* KNOB_TILE_Y_DIM
* (FormatTraits
<KNOB_COLOR_HOT_TILE_FORMAT
>::bpp
/ 8)) * MT::numSamples
};
194 static const int depthRasterTileStep
{(KNOB_TILE_X_DIM
* KNOB_TILE_Y_DIM
* (FormatTraits
<KNOB_DEPTH_HOT_TILE_FORMAT
>::bpp
/ 8)) * MT::numSamples
};
195 static const int stencilRasterTileStep
{(KNOB_TILE_X_DIM
* KNOB_TILE_Y_DIM
* (FormatTraits
<KNOB_STENCIL_HOT_TILE_FORMAT
>::bpp
/ 8)) * MT::numSamples
};
196 static const int colorRasterTileRowStep
{(KNOB_MACROTILE_X_DIM
/ KNOB_TILE_X_DIM
) * colorRasterTileStep
};
197 static const int depthRasterTileRowStep
{(KNOB_MACROTILE_X_DIM
/ KNOB_TILE_X_DIM
)* depthRasterTileStep
};
198 static const int stencilRasterTileRowStep
{(KNOB_MACROTILE_X_DIM
/ KNOB_TILE_X_DIM
) * stencilRasterTileStep
};