From: Tim Rowley Date: Fri, 26 May 2017 06:47:58 +0000 (-0500) Subject: swr/rast: Fix invalid 16-bit format traits for A1R5G5B5 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=8716e0d8b45194f34b57ec963d95abbcf40b66c4;p=mesa.git swr/rast: Fix invalid 16-bit format traits for A1R5G5B5 Correctly handle formats of <= 16 bits where the component bits don't add up to the pixel size. Reviewed-by: Bruce Cherniak --- 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 : 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 -struct Format1 +template +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 +struct FormatIntType { - 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 +struct FormatIntType { - 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 -union Format2 +template +union Format1 { + typedef typename FormatIntType::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 +union Format2 { + typedef typename FormatIntType::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 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::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 struct Format4 { - uint32_t r : x; - uint32_t g : y; - uint32_t b : z; - uint32_t a : w; -}; + typedef typename FormatIntType::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; }; //////////////////////////////////////////////////////////////////////////