summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/gallium/drivers/swr/rasterizer/core/format_types.h148
1 files changed, 48 insertions, 100 deletions
diff --git a/src/gallium/drivers/swr/rasterizer/core/format_types.h b/src/gallium/drivers/swr/rasterizer/core/format_types.h
index 5f21c960309..e7e17f696e8 100644
--- a/src/gallium/drivers/swr/rasterizer/core/format_types.h
+++ b/src/gallium/drivers/swr/rasterizer/core/format_types.h
@@ -1110,91 +1110,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 +1187,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 +1204,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;
-};
+ typedef typename FormatIntType<x + y + z + w>::TYPE TYPE;
-//////////////////////////////////////////////////////////////////////////
-/// 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;
-};
-
-//////////////////////////////////////////////////////////////////////////
-/// 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;
};
//////////////////////////////////////////////////////////////////////////