swr/rast: increase number of possible draws in flight
[mesa.git] / src / gallium / drivers / swr / rasterizer / core / format_types.h
index 5f21c96030946029445d232e9ffecc8d8411ebf0..43053b646f644ba7a730215d4f5c838f18323d0c 100644 (file)
@@ -28,6 +28,7 @@
 #pragma once
 
 #include "utils.h"
+#include "common/simdintrin.h"
 
 //////////////////////////////////////////////////////////////////////////
 /// PackTraits - Helpers for packing / unpacking same pixel sizes
@@ -42,7 +43,7 @@ struct PackTraits
     static simdscalar pack(simdscalar &in) = delete;
 #if ENABLE_AVX512_SIMD16
     static simd16scalar loadSOA_16(const uint8_t *pSrc) = delete;
-    static void SIMDAPI storeSOA(uint8_t *pDst, simd16scalar src) = delete;
+    static void SIMDCALL storeSOA(uint8_t *pDst, simd16scalar src) = delete;
     static simd16scalar unpack(simd16scalar &in) = delete;
     static simd16scalar pack(simd16scalar &in) = delete;
 #endif
@@ -62,7 +63,7 @@ struct PackTraits<0, false>
     static simdscalar pack(simdscalar &in) { return _simd_setzero_ps(); }
 #if ENABLE_AVX512_SIMD16
     static simd16scalar loadSOA_16(const uint8_t *pSrc) { return _simd16_setzero_ps(); }
-    static void SIMDAPI storeSOA(uint8_t *pDst, simd16scalar src) { return; }
+    static void SIMDCALL storeSOA(uint8_t *pDst, simd16scalar src) { return; }
     static simd16scalar unpack(simd16scalar &in) { return _simd16_setzero_ps(); }
     static simd16scalar pack(simd16scalar &in) { return _simd16_setzero_ps(); }
 #endif
@@ -108,7 +109,7 @@ struct PackTraits<8, false>
 
         __m256i result = _mm256_castsi128_si256(resLo);
         result = _mm256_insertf128_si256(result, resHi, 1);
-        return _mm256_castsi256_ps(result);
+        return simdscalar{ _mm256_castsi256_ps(result) };
 #else
         return _mm256_castsi256_ps(_mm256_cvtepu8_epi32(_mm_castps_si128(_mm256_castps256_ps128(in))));
 #endif
@@ -143,7 +144,7 @@ struct PackTraits<8, false>
         return result;
     }
 
-    static void SIMDAPI storeSOA(uint8_t *pDst, simd16scalar src)
+    static void SIMDCALL storeSOA(uint8_t *pDst, simd16scalar src)
     {
         // store simd16 bytes
         _mm_store_ps(reinterpret_cast<float *>(pDst), _mm256_castps256_ps128(_simd16_extract_ps(src, 0)));
@@ -151,7 +152,8 @@ struct PackTraits<8, false>
 
     static simd16scalar unpack(simd16scalar &in)
     {
-        simd16scalari result = _simd16_cvtepu8_epi32(_mm_castps_si128(_mm256_castps256_ps128(_simd16_extract_ps(in, 0))));
+        simd4scalari tmp = _mm_castps_si128(_mm256_castps256_ps128(_simd16_extract_ps(in, 0)));
+        simd16scalari result = _simd16_cvtepu8_epi32(tmp);
 
         return _simd16_castsi_ps(result);
     }
@@ -258,7 +260,7 @@ struct PackTraits<8, true>
         return result;
     }
 
-    static void SIMDAPI storeSOA(uint8_t *pDst, simd16scalar src)
+    static void SIMDCALL storeSOA(uint8_t *pDst, simd16scalar src)
     {
         // store simd16 bytes
         _mm_store_ps(reinterpret_cast<float *>(pDst), _mm256_castps256_ps128(_simd16_extract_ps(src, 0)));
@@ -266,7 +268,8 @@ struct PackTraits<8, true>
 
     static simd16scalar unpack(simd16scalar &in)
     {
-        simd16scalari result = _simd16_cvtepu8_epi32(_mm_castps_si128(_mm256_castps256_ps128(_simd16_extract_ps(in, 0))));
+        simd4scalari tmp = _mm_castps_si128(_mm256_castps256_ps128(_simd16_extract_ps(in, 0)));
+        simd16scalari result = _simd16_cvtepu8_epi32(tmp);
 
         return _simd16_castsi_ps(result);
     }
@@ -369,7 +372,7 @@ struct PackTraits<16, false>
         return result;
     }
 
-    static void SIMDAPI storeSOA(uint8_t *pDst, simd16scalar src)
+    static void SIMDCALL storeSOA(uint8_t *pDst, simd16scalar src)
     {
         _simd_store_ps(reinterpret_cast<float *>(pDst), _simd16_extract_ps(src, 0));
     }
@@ -468,7 +471,7 @@ struct PackTraits<16, true>
         return result;
     }
 
-    static void SIMDAPI storeSOA(uint8_t *pDst, simd16scalar src)
+    static void SIMDCALL storeSOA(uint8_t *pDst, simd16scalar src)
     {
         _simd_store_ps(reinterpret_cast<float *>(pDst), _simd16_extract_ps(src, 0));
     }
@@ -513,7 +516,7 @@ struct PackTraits<32, false>
         return _simd16_load_ps(reinterpret_cast<const float *>(pSrc));
     }
 
-    static void SIMDAPI storeSOA(uint8_t *pDst, simd16scalar src)
+    static void SIMDCALL storeSOA(uint8_t *pDst, simd16scalar src)
     {
         _simd16_store_ps(reinterpret_cast<float *>(pDst), src);
     }
@@ -811,7 +814,7 @@ static inline __m128 ConvertFloatToSRGB2(__m128& Src)
 
 #if ENABLE_AVX512_SIMD16
 template< unsigned expnum, unsigned expden, unsigned coeffnum, unsigned coeffden >
-inline static simd16scalar SIMDAPI fastpow(simd16scalar value)
+inline static simd16scalar SIMDCALL fastpow(simd16scalar value)
 {
     static const float factor1 = exp2(127.0f * expden / expnum - 127.0f)
         * powf(1.0f * coeffnum / coeffden, 1.0f * expden / expnum);
@@ -833,7 +836,7 @@ inline static simd16scalar SIMDAPI fastpow(simd16scalar value)
     return result;
 }
 
-inline static simd16scalar SIMDAPI pow512_4(simd16scalar arg)
+inline static simd16scalar SIMDCALL pow512_4(simd16scalar arg)
 {
     // 5/12 is too small, so compute the 4th root of 20/12 instead.
     // 20/12 = 5/3 = 1 + 2/3 = 2 - 1/3. 2/3 is a suitable argument for fastpow.
@@ -854,7 +857,7 @@ inline static simd16scalar SIMDAPI pow512_4(simd16scalar arg)
     return xavg;
 }
 
-inline static simd16scalar SIMDAPI powf_wrapper(const simd16scalar base, float exp)
+inline static simd16scalar SIMDCALL powf_wrapper(const simd16scalar base, float exp)
 {
     const float *f = reinterpret_cast<const float *>(&base);
 
@@ -1110,91 +1113,74 @@ template<> struct TypeTraits<SWR_TYPE_FLOAT, 32> : PackTraits<32>
 };
 
 //////////////////////////////////////////////////////////////////////////
-/// Format1 - Bitfield for single component formats.
+/// FormatIntType - Calculate base integer type for pixel components based
+///                 on total number of bits.  Components can be smaller
+///                 that this type, but the entire pixel must not be
+///                 any smaller than this type.
 //////////////////////////////////////////////////////////////////////////
-template<uint32_t x>
-struct Format1
+template <uint32_t bits, bool bits8 = bits <= 8, bool bits16 = bits <= 16>
+struct FormatIntType
 {
-    union
-    {
-        uint32_t r : x;
-
-        ///@ The following are here to provide full template needed in Formats.
-        uint32_t g : x;
-        uint32_t b : x;
-        uint32_t a : x;
-    };
+    typedef uint32_t TYPE;
 };
 
-//////////////////////////////////////////////////////////////////////////
-/// Format1 - Bitfield for single component formats - 8 bit specialization
-//////////////////////////////////////////////////////////////////////////
-template<>
-struct Format1<8>
+template <uint32_t bits>
+struct FormatIntType<bits, true, true>
 {
-    union
-    {
-        uint8_t r;
-
-        ///@ The following are here to provide full template needed in Formats.
-        uint8_t g;
-        uint8_t b;
-        uint8_t a;
-    };
+    typedef uint8_t TYPE;
 };
 
-//////////////////////////////////////////////////////////////////////////
-/// Format1 - Bitfield for single component formats - 16 bit specialization
-//////////////////////////////////////////////////////////////////////////
-template<>
-struct Format1<16>
+template <uint32_t bits>
+struct FormatIntType<bits, false, true>
 {
-    union
-    {
-        uint16_t r;
-
-        ///@ The following are here to provide full template needed in Formats.
-        uint16_t g;
-        uint16_t b;
-        uint16_t a;
-    };
+    typedef uint16_t TYPE;
 };
 
 //////////////////////////////////////////////////////////////////////////
-/// Format2 - Bitfield for 2 component formats.
+/// Format1 - Bitfield for single component formats.
 //////////////////////////////////////////////////////////////////////////
-template<uint32_t x, uint32_t y>
-union Format2
+template<uint32_t x>
+union Format1
 {
+    typedef typename FormatIntType<x>::TYPE TYPE;
     struct
     {
-        uint32_t r : x;
-        uint32_t g : y;
+        TYPE r : x;
     };
+
+    ///@ The following are here to provide full template needed in Formats.
     struct
     {
-        ///@ The following are here to provide full template needed in Formats.
-        uint32_t b : x;
-        uint32_t a : y;
+        TYPE g : x;
+    };
+    struct 
+    {
+        TYPE b : x;
+    };
+    struct  
+    {
+        TYPE a : x;
     };
 };
 
 //////////////////////////////////////////////////////////////////////////
-/// Format2 - Bitfield for 2 component formats - 16 bit specialization
+/// Format2 - Bitfield for 2 component formats.
 //////////////////////////////////////////////////////////////////////////
-template<>
-union Format2<8,8>
+template<uint32_t x, uint32_t y>
+union Format2
 {
+    typedef typename FormatIntType<x + y>::TYPE TYPE;
+
     struct
     {
-        uint16_t r : 8;
-        uint16_t g : 8;
+        TYPE r : x;
+        TYPE g : y;
     };
     struct
     {
         ///@ The following are here to provide full template needed in Formats.
-        uint16_t b : 8;
-        uint16_t a : 8;
+        TYPE b : x;
+        TYPE a : y;
     };
 };
 
@@ -1204,28 +1190,15 @@ union Format2<8,8>
 template<uint32_t x, uint32_t y, uint32_t z>
 union Format3
 {
-    struct
-    {
-        uint32_t r : x;
-        uint32_t g : y;
-        uint32_t b : z;
-    };
-    uint32_t a;  ///@note This is here to provide full template needed in Formats.
-};
+    typedef typename FormatIntType<x + y + z>::TYPE TYPE;
 
-//////////////////////////////////////////////////////////////////////////
-/// Format3 - Bitfield for 3 component formats - 16 bit specialization
-//////////////////////////////////////////////////////////////////////////
-template<>
-union Format3<5,6,5>
-{
     struct
     {
-        uint16_t r : 5;
-        uint16_t g : 6;
-        uint16_t b : 5;
+        TYPE r : x;
+        TYPE g : y;
+        TYPE b : z;
     };
-    uint16_t a;  ///@note This is here to provide full template needed in Formats.
+    TYPE a;  ///@note This is here to provide full template needed in Formats.
 };
 
 //////////////////////////////////////////////////////////////////////////
@@ -1234,34 +1207,12 @@ union Format3<5,6,5>
 template<uint32_t x, uint32_t y, uint32_t z, uint32_t w>
 struct Format4
 {
-    uint32_t r : x;
-    uint32_t g : y;
-    uint32_t b : z;
-    uint32_t a : w;
-};
-
-//////////////////////////////////////////////////////////////////////////
-/// Format4 - Bitfield for 4 component formats - 16 bit specialization
-//////////////////////////////////////////////////////////////////////////
-template<>
-struct Format4<5,5,5,1>
-{
-    uint16_t r : 5;
-    uint16_t g : 5;
-    uint16_t b : 5;
-    uint16_t a : 1;
-};
+    typedef typename FormatIntType<x + y + z + w>::TYPE TYPE;
 
-//////////////////////////////////////////////////////////////////////////
-/// Format4 - Bitfield for 4 component formats - 16 bit specialization
-//////////////////////////////////////////////////////////////////////////
-template<>
-struct Format4<4,4,4,4>
-{
-    uint16_t r : 4;
-    uint16_t g : 4;
-    uint16_t b : 4;
-    uint16_t a : 4;
+    TYPE r : x;
+    TYPE g : y;
+    TYPE b : z;
+    TYPE a : w;
 };
 
 //////////////////////////////////////////////////////////////////////////
@@ -1461,7 +1412,7 @@ struct ComponentTraits
         return TypeTraits<X, NumBitsX>::loadSOA_16(pSrc);
     }
 
-    INLINE static void SIMDAPI storeSOA(uint32_t comp, uint8_t *pDst, simd16scalar src)
+    INLINE static void SIMDCALL storeSOA(uint32_t comp, uint8_t *pDst, simd16scalar src)
     {
         switch (comp)
         {