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
);
38 void InitRasterizerFunctions();
41 __m128i
fpToFixedPoint(const __m128 vIn
)
43 __m128 vFixed
= _mm_mul_ps(vIn
, _mm_set1_ps(FIXED_POINT_SCALE
));
44 return _mm_cvtps_epi32(vFixed
);
49 STATE_NO_VALID_EDGES
= 0,
53 STATE_ALL_EDGES_VALID
,
54 STATE_VALID_TRI_EDGE_COUNT
,
63 ALL_EDGES_VALID
= 0x7,
67 // Selector for correct templated RasterizeTriangle function
68 PFN_WORK_FUNC
GetRasterizerFunc(
69 SWR_MULTISAMPLE_COUNT numSamples
,
72 SWR_INPUT_COVERAGE InputCoverage
,
74 bool RasterizeScissorEdges
);
76 //////////////////////////////////////////////////////////////////////////
77 /// @brief ValidTriEdges convenience typedefs used for templated function
78 /// specialization supported Fixed Point precisions
79 typedef std::integral_constant
<uint32_t, ALL_EDGES_VALID
> AllEdgesValidT
;
80 typedef std::integral_constant
<uint32_t, E0_E1_VALID
> E0E1ValidT
;
81 typedef std::integral_constant
<uint32_t, E0_E2_VALID
> E0E2ValidT
;
82 typedef std::integral_constant
<uint32_t, E1_E2_VALID
> E1E2ValidT
;
83 typedef std::integral_constant
<uint32_t, NO_VALID_EDGES
> NoEdgesValidT
;
85 typedef std::integral_constant
<uint32_t, STATE_ALL_EDGES_VALID
> StateAllEdgesValidT
;
86 typedef std::integral_constant
<uint32_t, STATE_E0_E1_VALID
> StateE0E1ValidT
;
87 typedef std::integral_constant
<uint32_t, STATE_E0_E2_VALID
> StateE0E2ValidT
;
88 typedef std::integral_constant
<uint32_t, STATE_E1_E2_VALID
> StateE1E2ValidT
;
89 typedef std::integral_constant
<uint32_t, STATE_NO_VALID_EDGES
> StateNoEdgesValidT
;
91 // some specializations to convert from edge state to edge bitmask values
92 template <typename EdgeMask
>
95 static_assert(EdgeMask::value
> STATE_ALL_EDGES_VALID
, "Primary EdgeMaskVal shouldn't be instantiated");
99 struct EdgeMaskVal
<StateAllEdgesValidT
>
101 typedef AllEdgesValidT T
;
105 struct EdgeMaskVal
<StateE0E1ValidT
>
107 typedef E0E1ValidT T
;
111 struct EdgeMaskVal
<StateE0E2ValidT
>
113 typedef E0E2ValidT T
;
117 struct EdgeMaskVal
<StateE1E2ValidT
>
119 typedef E1E2ValidT T
;
123 struct EdgeMaskVal
<StateNoEdgesValidT
>
125 typedef NoEdgesValidT T
;
128 INLINE
uint32_t EdgeValToEdgeState(uint32_t val
)
130 SWR_ASSERT(val
< VALID_TRI_EDGE_COUNT
, "Unexpected tri edge mask");
131 static const uint32_t edgeValToEdgeState
[VALID_TRI_EDGE_COUNT
] = { 0, 0, 0, 1, 0, 2, 3, 4 };
132 return edgeValToEdgeState
[val
];
135 //////////////////////////////////////////////////////////////////////////
136 /// @struct RasterScissorEdgesT
137 /// @brief Primary RasterScissorEdgesT templated struct that holds compile
138 /// time information about the number of edges needed to be rasterized,
139 /// If either the scissor rect or conservative rast is enabled,
140 /// the scissor test is enabled and the rasterizer will test
141 /// 3 triangle edges + 4 scissor edges for coverage.
142 /// @tparam RasterScissorEdgesT: number of multisamples
143 /// @tparam ConservativeT: is this a conservative rasterization
144 /// @tparam EdgeMaskT: Which edges are valid(not degenerate)
145 template <typename RasterScissorEdgesT
, typename ConservativeT
, typename EdgeMaskT
>
146 struct RasterEdgeTraits
148 typedef std::true_type RasterizeScissorEdgesT
;
149 typedef std::integral_constant
<uint32_t, 7> NumEdgesT
;
150 //typedef std::integral_constant<uint32_t, EdgeMaskT::value> ValidEdgeMaskT;
151 typedef typename EdgeMaskVal
<EdgeMaskT
>::T ValidEdgeMaskT
;
154 //////////////////////////////////////////////////////////////////////////
155 /// @brief specialization of RasterEdgeTraits. If neither scissor rect
156 /// nor conservative rast is enabled, only test 3 triangle edges
158 template <typename EdgeMaskT
>
159 struct RasterEdgeTraits
<std::false_type
, std::false_type
, EdgeMaskT
>
161 typedef std::false_type RasterizeScissorEdgesT
;
162 typedef std::integral_constant
<uint32_t, 3> NumEdgesT
;
163 // no need for degenerate edge masking in non-conservative case; rasterize all triangle edges
164 typedef std::integral_constant
<uint32_t, ALL_EDGES_VALID
> ValidEdgeMaskT
;
167 //////////////////////////////////////////////////////////////////////////
168 /// @struct RasterizerTraits
169 /// @brief templated struct that holds compile time information used
170 /// during rasterization. Inherits EdgeTraits and ConservativeRastBETraits.
171 /// @tparam NumSamplesT: number of multisamples
172 /// @tparam ConservativeT: is this a conservative rasterization
173 /// @tparam InputCoverageT: what type of input coverage is the PS expecting?
174 /// (only used with conservative rasterization)
175 /// @tparam RasterScissorEdgesT: do we need to rasterize with a scissor?
176 template <typename NumSamplesT
, typename CenterPatternT
, typename ConservativeT
, typename InputCoverageT
, typename EdgeEnableT
, typename RasterScissorEdgesT
>
177 struct _RasterizerTraits
: public ConservativeRastBETraits
<ConservativeT
, InputCoverageT
>,
178 public RasterEdgeTraits
<RasterScissorEdgesT
, ConservativeT
, EdgeEnableT
>
180 typedef MultisampleTraits
<static_cast<SWR_MULTISAMPLE_COUNT
>(NumSamplesT::value
), CenterPatternT::value
> MT
;
182 /// Fixed point precision the rasterizer is using
183 typedef FixedPointTraits
<Fixed_16_8
> PrecisionT
;
184 /// Fixed point precision of the edge tests used during rasterization
185 typedef FixedPointTraits
<Fixed_X_16
> EdgePrecisionT
;
187 // If conservative rast or MSAA center pattern is enabled, only need a single sample coverage test, with the result copied to all samples
188 typedef std::integral_constant
<int, ConservativeT::value
? 1 : MT::numCoverageSamples
> NumCoverageSamplesT
;
190 static_assert(EdgePrecisionT::BitsT::value
>= ConservativeRastBETraits
<ConservativeT
, InputCoverageT
>::ConservativePrecisionT::BitsT::value
,
191 "Rasterizer edge fixed point precision < required conservative rast precision");
193 /// constants used to offset between different types of raster tiles
194 static const int colorRasterTileStep
{(KNOB_TILE_X_DIM
* KNOB_TILE_Y_DIM
* (FormatTraits
<KNOB_COLOR_HOT_TILE_FORMAT
>::bpp
/ 8)) * MT::numSamples
};
195 static const int depthRasterTileStep
{(KNOB_TILE_X_DIM
* KNOB_TILE_Y_DIM
* (FormatTraits
<KNOB_DEPTH_HOT_TILE_FORMAT
>::bpp
/ 8)) * MT::numSamples
};
196 static const int stencilRasterTileStep
{(KNOB_TILE_X_DIM
* KNOB_TILE_Y_DIM
* (FormatTraits
<KNOB_STENCIL_HOT_TILE_FORMAT
>::bpp
/ 8)) * MT::numSamples
};
197 static const int colorRasterTileRowStep
{(KNOB_MACROTILE_X_DIM
/ KNOB_TILE_X_DIM
) * colorRasterTileStep
};
198 static const int depthRasterTileRowStep
{(KNOB_MACROTILE_X_DIM
/ KNOB_TILE_X_DIM
)* depthRasterTileStep
};
199 static const int stencilRasterTileRowStep
{(KNOB_MACROTILE_X_DIM
/ KNOB_TILE_X_DIM
) * stencilRasterTileStep
};
202 template <uint32_t NumSamplesT
, uint32_t CenterPatternT
, uint32_t ConservativeT
, uint32_t InputCoverageT
, uint32_t EdgeEnableT
, uint32_t RasterScissorEdgesT
>
203 struct RasterizerTraits final
: public _RasterizerTraits
<
204 std::integral_constant
<uint32_t, NumSamplesT
>,
205 std::integral_constant
<bool, CenterPatternT
!= 0>,
206 std::integral_constant
<bool, ConservativeT
!= 0>,
207 std::integral_constant
<uint32_t, InputCoverageT
>,
208 std::integral_constant
<uint32_t, EdgeEnableT
>,
209 std::integral_constant
<bool, RasterScissorEdgesT
!= 0> >