• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /****************************************************************************
2 * Copyright (C) 2014-2016 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 conservativerast.h
24 *
25 ******************************************************************************/
26 #pragma once
27 #include <type_traits>
28 #include "common/simdintrin.h"
29 
30 enum FixedPointFmt
31 {
32     FP_UNINIT,
33     _16_8,
34     _16_9,
35     _X_16,
36 };
37 
38 //////////////////////////////////////////////////////////////////////////
39 /// @brief convenience typedefs for supported Fixed Point precisions
40 typedef std::integral_constant<uint32_t, FP_UNINIT> Fixed_Uninit;
41 typedef std::integral_constant<uint32_t, _16_8> Fixed_16_8;
42 typedef std::integral_constant<uint32_t, _16_9> Fixed_16_9;
43 typedef std::integral_constant<uint32_t, _X_16> Fixed_X_16;
44 
45 //////////////////////////////////////////////////////////////////////////
46 /// @struct FixedPointTraits
47 /// @brief holds constants relating to converting between FP and Fixed point
48 /// @tparam FT: fixed precision type
49 template<typename FT>
50 struct FixedPointTraits{};
51 
52 //////////////////////////////////////////////////////////////////////////
53 /// @brief Fixed_16_8 specialization of FixedPointTraits
54 template<>
55 struct FixedPointTraits<Fixed_16_8>
56 {
57     /// multiplier to go from FP32 to Fixed Point 16.8
58     typedef std::integral_constant<uint32_t, 256> ScaleT;
59     /// number of bits to shift to go from 16.8 fixed => int32
60     typedef std::integral_constant<uint32_t, 8> BitsT;
61     typedef Fixed_16_8 TypeT;
62 };
63 
64 //////////////////////////////////////////////////////////////////////////
65 /// @brief Fixed_16_9 specialization of FixedPointTraits
66 template<>
67 struct FixedPointTraits<Fixed_16_9>
68 {
69     /// multiplier to go from FP32 to Fixed Point 16.9
70     typedef std::integral_constant<uint32_t, 512> ScaleT;
71     /// number of bits to shift to go from 16.9 fixed => int32
72     typedef std::integral_constant<uint32_t, 9> BitsT;
73     typedef Fixed_16_9 TypeT;
74 };
75 
76 //////////////////////////////////////////////////////////////////////////
77 /// @brief Fixed_16_9 specialization of FixedPointTraits
78 template<>
79 struct FixedPointTraits<Fixed_X_16>
80 {
81     /// multiplier to go from FP32 to Fixed Point X.16
82     typedef std::integral_constant<uint32_t, 65536> ScaleT;
83     /// number of bits to shift to go from X.16 fixed => int32
84     typedef std::integral_constant<uint32_t, 16> BitsT;
85     typedef Fixed_X_16 TypeT;
86 };
87 
88 //////////////////////////////////////////////////////////////////////////
89 /// @brief convenience typedefs for conservative rasterization modes
90 typedef std::false_type StandardRastT;
91 typedef std::true_type ConservativeRastT;
92 
93 //////////////////////////////////////////////////////////////////////////
94 /// @brief convenience typedefs for Input Coverage rasterization modes
95 typedef std::integral_constant<uint32_t, SWR_INPUT_COVERAGE_NONE> NoInputCoverageT;
96 typedef std::integral_constant<uint32_t, SWR_INPUT_COVERAGE_NORMAL> OuterConservativeCoverageT;
97 typedef std::integral_constant<uint32_t, SWR_INPUT_COVERAGE_INNER_CONSERVATIVE> InnerConservativeCoverageT;
98 
99 //////////////////////////////////////////////////////////////////////////
100 /// @struct ConservativeRastTraits
101 /// @brief primary ConservativeRastTraits template. Shouldn't be instantiated
102 /// @tparam ConservativeT: type of conservative rasterization
103 template <typename ConservativeT>
104 struct ConservativeRastFETraits {};
105 
106 //////////////////////////////////////////////////////////////////////////
107 /// @brief StandardRast specialization of ConservativeRastTraits
108 template <>
109 struct ConservativeRastFETraits<StandardRastT>
110 {
111     typedef std::false_type IsConservativeT;
112     typedef std::integral_constant<uint32_t, 0> BoundingBoxOffsetT;
113 };
114 
115 //////////////////////////////////////////////////////////////////////////
116 /// @brief ConservativeRastT specialization of ConservativeRastTraits
117 template <>
118 struct ConservativeRastFETraits<ConservativeRastT>
119 {
120     typedef std::true_type IsConservativeT;
121     typedef std::integral_constant<uint32_t, 1> BoundingBoxOffsetT;
122 };
123 
124 //////////////////////////////////////////////////////////////////////////
125 /// @brief convenience typedefs for ConservativeRastFETraits
126 typedef ConservativeRastFETraits<StandardRastT> FEStandardRastT;
127 typedef ConservativeRastFETraits<ConservativeRastT> FEConservativeRastT;
128 
129 //////////////////////////////////////////////////////////////////////////
130 /// @struct ConservativeRastBETraits
131 /// @brief primary ConservativeRastBETraits template. Shouldn't be instantiated;
132 /// default to standard rasterization behavior
133 /// @tparam ConservativeT: type of conservative rasterization
134 /// @tparam InputCoverageT: type of input coverage requested, if any
135 template <typename ConservativeT, typename _InputCoverageT>
136 struct ConservativeRastBETraits {
137     typedef std::false_type IsConservativeT;
138     typedef _InputCoverageT InputCoverageT;
139     typedef FixedPointTraits<Fixed_16_8> ConservativePrecisionT;
140     typedef std::integral_constant<int32_t, 0> ConservativeEdgeOffsetT;
141     typedef std::integral_constant<int32_t, 0> InnerConservativeEdgeOffsetT;
142 };
143 
144 //////////////////////////////////////////////////////////////////////////
145 /// @brief StandardRastT specialization of ConservativeRastBETraits
146 template <typename _InputCoverageT>
147 struct ConservativeRastBETraits<StandardRastT, _InputCoverageT>
148 {
149     typedef std::false_type IsConservativeT;
150     typedef _InputCoverageT InputCoverageT;
151     typedef FixedPointTraits<Fixed_16_8> ConservativePrecisionT;
152     typedef std::integral_constant<int32_t, 0> ConservativeEdgeOffsetT;
153     typedef std::integral_constant<int32_t, 0> InnerConservativeEdgeOffsetT;
154 };
155 
156 //////////////////////////////////////////////////////////////////////////
157 /// @brief ConservativeRastT specialization of ConservativeRastBETraits
158 /// with no input coverage
159 template <>
160 struct ConservativeRastBETraits<ConservativeRastT, NoInputCoverageT>
161 {
162     typedef std::true_type IsConservativeT;
163     typedef NoInputCoverageT InputCoverageT;
164 
165     typedef FixedPointTraits<Fixed_16_9> ConservativePrecisionT;
166 
167     /// offset edge away from pixel center by 1/2 pixel + 1/512, in Fixed 16.9 precision
168     /// this allows the rasterizer to do the 3 edge coverage tests against a single point, instead of
169     /// of having to compare individual edges to pixel corners to check if any part of the triangle
170     /// intersects a pixel
171     typedef std::integral_constant<int32_t, (ConservativePrecisionT::ScaleT::value/2) + 1> ConservativeEdgeOffsetT;
172     typedef std::integral_constant<int32_t, 0> InnerConservativeEdgeOffsetT;
173 };
174 
175 //////////////////////////////////////////////////////////////////////////
176 /// @brief ConservativeRastT specialization of ConservativeRastBETraits
177 /// with OuterConservativeCoverage
178 template <>
179 struct ConservativeRastBETraits<ConservativeRastT, OuterConservativeCoverageT>
180 {
181     typedef std::true_type IsConservativeT;
182     typedef OuterConservativeCoverageT InputCoverageT;
183 
184     typedef FixedPointTraits<Fixed_16_9> ConservativePrecisionT;
185 
186     /// offset edge away from pixel center by 1/2 pixel + 1/512, in Fixed 16.9 precision
187     /// this allows the rasterizer to do the 3 edge coverage tests against a single point, instead of
188     /// of having to compare individual edges to pixel corners to check if any part of the triangle
189     /// intersects a pixel
190     typedef std::integral_constant<int32_t, (ConservativePrecisionT::ScaleT::value/2) + 1> ConservativeEdgeOffsetT;
191     typedef std::integral_constant<int32_t, 0> InnerConservativeEdgeOffsetT;
192 
193 };
194 
195 //////////////////////////////////////////////////////////////////////////
196 /// @brief ConservativeRastT specialization of ConservativeRastBETraits
197 /// with InnerConservativeCoverage
198 template <>
199 struct ConservativeRastBETraits<ConservativeRastT, InnerConservativeCoverageT>
200 {
201     typedef std::true_type IsConservativeT;
202     typedef InnerConservativeCoverageT InputCoverageT;
203 
204     typedef FixedPointTraits<Fixed_16_9> ConservativePrecisionT;
205 
206     /// offset edge away from pixel center by 1/2 pixel + 1/512, in Fixed 16.9 precision
207     /// this allows the rasterizer to do the 3 edge coverage tests against a single point, instead of
208     /// of having to compare individual edges to pixel corners to check if any part of the triangle
209     /// intersects a pixel
210     typedef std::integral_constant<int32_t, (ConservativePrecisionT::ScaleT::value/2) + 1> ConservativeEdgeOffsetT;
211 
212     /// undo the outer conservative offset and offset edge towards from pixel center by 1/2 pixel + 1/512, in Fixed 16.9 precision
213     /// this allows the rasterizer to do the 3 edge coverage tests against a single point, instead of
214     /// of having to compare individual edges to pixel corners to check if a pixel is fully covered by a triangle
215     typedef std::integral_constant<int32_t, static_cast<int32_t>(-((ConservativePrecisionT::ScaleT::value/2) + 1) - ConservativeEdgeOffsetT::value)> InnerConservativeEdgeOffsetT;
216 };