Home | History | Annotate | Download | only in core
      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 
     34 template <typename MaskT>
     35 INLINE __m128i SWR_MULTISAMPLE_POS::expandThenBlend4(uint32_t* min, uint32_t* max)
     36 {
     37     __m128i vMin = _mm_set1_epi32(*min);
     38     __m128i vMax = _mm_set1_epi32(*max);
     39     return _simd_blend4_epi32<MaskT::value>(vMin, vMax);
     40 }
     41 
     42 INLINE void SWR_MULTISAMPLE_POS::PrecalcSampleData(int numSamples)
     43 {
     44     for(int i = 0; i < numSamples; i++)
     45     {
     46         _vXi[i] = _mm_set1_epi32(_xi[i]);
     47         _vYi[i] = _mm_set1_epi32(_yi[i]);
     48         _vX[i] = _simd_set1_ps(_x[i]);
     49         _vY[i] = _simd_set1_ps(_y[i]);
     50     }
     51     // precalculate the raster tile BB for the rasterizer.
     52     CalcTileSampleOffsets(numSamples);
     53 }
     54 
     55 INLINE void SWR_MULTISAMPLE_POS::CalcTileSampleOffsets(int numSamples)
     56 {
     57     auto minXi = std::min_element(std::begin(_xi), &_xi[numSamples]);
     58     auto maxXi = std::max_element(std::begin(_xi), &_xi[numSamples]);
     59     using xMask = std::integral_constant<int, 0xA>;
     60     // BR(max),    BL(min),    UR(max),    UL(min)
     61     tileSampleOffsetsX = expandThenBlend4<xMask>(minXi, maxXi);
     62 
     63     auto minYi = std::min_element(std::begin(_yi), &_yi[numSamples]);
     64     auto maxYi = std::max_element(std::begin(_yi), &_yi[numSamples]);
     65     using yMask = std::integral_constant<int, 0xC>;
     66     // BR(max),    BL(min),    UR(max),    UL(min)
     67     tileSampleOffsetsY = expandThenBlend4<yMask>(minYi, maxYi);
     68 };
     69