• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /****************************************************************************
2 * Copyright (C) 2014-2015 Intel Corporation.   All Rights Reserved.
3 *
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:
10 *
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
13 * Software.
14 *
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
21 * IN THE SOFTWARE.
22 *
23 * @file rasterizer.h
24 *
25 * @brief Definitions for the rasterizer.
26 *
27 ******************************************************************************/
28 #pragma once
29 
30 #include "context.h"
31 #include <type_traits>
32 #include "conservativeRast.h"
33 #include "multisample.h"
34 
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 
39 INLINE
fpToFixedPoint(const __m128 vIn)40 __m128i fpToFixedPoint(const __m128 vIn)
41 {
42     __m128 vFixed = _mm_mul_ps(vIn, _mm_set1_ps(FIXED_POINT_SCALE));
43     return _mm_cvtps_epi32(vFixed);
44 }
45 
46 // Selector for correct templated RasterizeTriangle function
47 PFN_WORK_FUNC GetRasterizerFunc(
48     uint32_t numSamples,
49     bool IsConservative,
50     uint32_t InputCoverage,
51     uint32_t EdgeEnable,
52     bool RasterizeScissorEdges);
53 
54 enum ValidTriEdges
55 {
56     NO_VALID_EDGES = 0,
57     E0_E1_VALID = 0x3,
58     E0_E2_VALID = 0x5,
59     E1_E2_VALID = 0x6,
60     ALL_EDGES_VALID = 0x7,
61     VALID_TRI_EDGE_COUNT,
62 };
63 
64 //////////////////////////////////////////////////////////////////////////
65 /// @brief ValidTriEdges convenience typedefs used for templated function
66 /// specialization supported Fixed Point precisions
67 typedef std::integral_constant<uint32_t, ALL_EDGES_VALID> AllEdgesValidT;
68 typedef std::integral_constant<uint32_t, E0_E1_VALID> E0E1ValidT;
69 typedef std::integral_constant<uint32_t, E0_E2_VALID> E0E2ValidT;
70 typedef std::integral_constant<uint32_t, E1_E2_VALID> E1E2ValidT;
71 typedef std::integral_constant<uint32_t, NO_VALID_EDGES> NoEdgesValidT;
72 
73 //////////////////////////////////////////////////////////////////////////
74 /// @struct RasterScissorEdgesT
75 /// @brief Primary RasterScissorEdgesT templated struct that holds compile
76 /// time information about the number of edges needed to be rasterized,
77 /// If either the scissor rect or conservative rast is enabled,
78 /// the scissor test is enabled and the rasterizer will test
79 /// 3 triangle edges + 4 scissor edges for coverage.
80 /// @tparam RasterScissorEdgesT: number of multisamples
81 /// @tparam ConservativeT: is this a conservative rasterization
82 /// @tparam EdgeMaskT: Which edges are valid(not degenerate)
83 template <typename RasterScissorEdgesT, typename ConservativeT, typename EdgeMaskT>
84 struct RasterEdgeTraits
85 {
86     typedef std::true_type RasterizeScissorEdgesT;
87     typedef std::integral_constant<uint32_t, 7> NumEdgesT;
88     typedef std::integral_constant<uint32_t, EdgeMaskT::value> ValidEdgeMaskT;
89 };
90 
91 //////////////////////////////////////////////////////////////////////////
92 /// @brief specialization of RasterEdgeTraits. If neither scissor rect
93 /// nor conservative rast is enabled, only test 3 triangle edges
94 /// for coverage
95 template <typename EdgeMaskT>
96 struct RasterEdgeTraits<std::false_type, std::false_type, EdgeMaskT>
97 {
98     typedef std::false_type RasterizeScissorEdgesT;
99     typedef std::integral_constant<uint32_t, 3> NumEdgesT;
100     // no need for degenerate edge masking in non-conservative case; rasterize all triangle edges
101     typedef std::integral_constant<uint32_t, ALL_EDGES_VALID> ValidEdgeMaskT;
102 };
103 
104 //////////////////////////////////////////////////////////////////////////
105 /// @struct RasterizerTraits
106 /// @brief templated struct that holds compile time information used
107 /// during rasterization. Inherits EdgeTraits and ConservativeRastBETraits.
108 /// @tparam NumSamplesT: number of multisamples
109 /// @tparam ConservativeT: is this a conservative rasterization
110 /// @tparam InputCoverageT: what type of input coverage is the PS expecting?
111 /// (only used with conservative rasterization)
112 /// @tparam RasterScissorEdgesT: do we need to rasterize with a scissor?
113 template <typename NumSamplesT, typename ConservativeT, typename InputCoverageT, typename EdgeEnableT, typename RasterScissorEdgesT>
114 struct RasterizerTraits final : public ConservativeRastBETraits<ConservativeT, InputCoverageT>,
115                                 public RasterEdgeTraits<RasterScissorEdgesT, ConservativeT, std::integral_constant<uint32_t, EdgeEnableT::value>>
116 {
117     typedef MultisampleTraits<static_cast<SWR_MULTISAMPLE_COUNT>(NumSamplesT::value)> MT;
118 
119     /// Fixed point precision the rasterizer is using
120     typedef FixedPointTraits<Fixed_16_8> PrecisionT;
121     /// Fixed point precision of the edge tests used during rasterization
122     typedef FixedPointTraits<Fixed_X_16> EdgePrecisionT;
123 
124     // If conservative rast is enabled, only need a single sample coverage test, with the result copied to all samples
125     typedef std::integral_constant<int, (ConservativeT::value) ? 1 : MT::numSamples> NumRasterSamplesT;
126 
127     static_assert(EdgePrecisionT::BitsT::value >=  ConservativeRastBETraits<ConservativeT, InputCoverageT>::ConservativePrecisionT::BitsT::value,
128                   "Rasterizer edge fixed point precision < required conservative rast precision");
129 
130     /// constants used to offset between different types of raster tiles
131     static const int colorRasterTileStep{(KNOB_TILE_X_DIM * KNOB_TILE_Y_DIM * (FormatTraits<KNOB_COLOR_HOT_TILE_FORMAT>::bpp / 8)) * MT::numSamples};
132     static const int depthRasterTileStep{(KNOB_TILE_X_DIM * KNOB_TILE_Y_DIM * (FormatTraits<KNOB_DEPTH_HOT_TILE_FORMAT>::bpp / 8)) * MT::numSamples};
133     static const int stencilRasterTileStep{(KNOB_TILE_X_DIM * KNOB_TILE_Y_DIM * (FormatTraits<KNOB_STENCIL_HOT_TILE_FORMAT>::bpp / 8)) * MT::numSamples};
134     static const int colorRasterTileRowStep{(KNOB_MACROTILE_X_DIM / KNOB_TILE_X_DIM) * colorRasterTileStep};
135     static const int depthRasterTileRowStep{(KNOB_MACROTILE_X_DIM / KNOB_TILE_X_DIM)* depthRasterTileStep};
136     static const int stencilRasterTileRowStep{(KNOB_MACROTILE_X_DIM / KNOB_TILE_X_DIM) * stencilRasterTileStep};
137 };
138