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 state.h
24  *
25  * @brief Definitions for API state - complex function implementation.
26  *
27  ******************************************************************************/
28 #pragma once
29 
30 #include "core/state.h"
31 #include "common/simdintrin.h"
32 
33 template <typename MaskT>
expandThenBlend4(uint32_t * min,uint32_t * max)34 INLINE __m128i SWR_MULTISAMPLE_POS::expandThenBlend4(uint32_t* min, uint32_t* max)
35 {
36     __m128i vMin = _mm_set1_epi32(*min);
37     __m128i vMax = _mm_set1_epi32(*max);
38     return _simd_blend4_epi32<MaskT::value>(vMin, vMax);
39 }
40 
PrecalcSampleData(int numSamples)41 INLINE void SWR_MULTISAMPLE_POS::PrecalcSampleData(int numSamples)
42 {
43     for (int i = 0; i < numSamples; i++)
44     {
45         _vXi[i] = _mm_set1_epi32(_xi[i]);
46         _vYi[i] = _mm_set1_epi32(_yi[i]);
47         _vX[i]  = _simd_set1_ps(_x[i]);
48         _vY[i]  = _simd_set1_ps(_y[i]);
49     }
50     // precalculate the raster tile BB for the rasterizer.
51     CalcTileSampleOffsets(numSamples);
52 }
53 
CalcTileSampleOffsets(int numSamples)54 INLINE void SWR_MULTISAMPLE_POS::CalcTileSampleOffsets(int numSamples)
55 {
56     auto minXi  = std::min_element(std::begin(_xi), &_xi[numSamples]);
57     auto maxXi  = std::max_element(std::begin(_xi), &_xi[numSamples]);
58     using xMask = std::integral_constant<int, 0xA>;
59     // BR(max),    BL(min),    UR(max),    UL(min)
60     tileSampleOffsetsX = expandThenBlend4<xMask>(minXi, maxXi);
61 
62     auto minYi  = std::min_element(std::begin(_yi), &_yi[numSamples]);
63     auto maxYi  = std::max_element(std::begin(_yi), &_yi[numSamples]);
64     using yMask = std::integral_constant<int, 0xC>;
65     // BR(max),    BL(min),    UR(max),    UL(min)
66     tileSampleOffsetsY = expandThenBlend4<yMask>(minYi, maxYi);
67 };
68