mirror of
https://github.com/stenzek/duckstation.git
synced 2025-07-18 16:10:07 +00:00
Misc: Make bitfield unions trivially copyable
This commit is contained in:
parent
8ca68a052a
commit
a5e3f163a5
@ -12,9 +12,6 @@ struct BitField
|
||||
{
|
||||
static_assert(!std::is_same_v<DataType, bool> || BitCount == 1, "Boolean bitfields should only be 1 bit");
|
||||
|
||||
// We have to delete the copy assignment operator otherwise we can't use this class in anonymous structs/unions.
|
||||
BitField& operator=(const BitField& rhs) = delete;
|
||||
|
||||
ALWAYS_INLINE constexpr BackingDataType GetMask() const
|
||||
{
|
||||
return ((static_cast<BackingDataType>(~0)) >> (8 * sizeof(BackingDataType) - BitCount)) << BitIndex;
|
||||
|
@ -156,14 +156,6 @@ public:
|
||||
Control() = default;
|
||||
|
||||
Control(u8 bits_) : bits(bits_) {}
|
||||
|
||||
Control(const Control& rhs) : bits(rhs.bits) {}
|
||||
|
||||
Control& operator=(const Control& rhs)
|
||||
{
|
||||
bits = rhs.bits;
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
struct
|
||||
@ -189,16 +181,6 @@ public:
|
||||
bool IsData() const { return GetControl().data; }
|
||||
|
||||
bool IsCRCValid() const;
|
||||
|
||||
SubChannelQ() = default;
|
||||
|
||||
SubChannelQ(const SubChannelQ& q) : data(q.data) {}
|
||||
|
||||
SubChannelQ& operator=(const SubChannelQ& q)
|
||||
{
|
||||
data = q.data;
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
static_assert(sizeof(SubChannelQ) == SUBCHANNEL_BYTES_PER_FRAME, "SubChannelQ is correct size");
|
||||
|
||||
|
@ -278,8 +278,8 @@ public:
|
||||
|
||||
// clang-format off
|
||||
ALWAYS_INLINE VertexAttribute() = default;
|
||||
ALWAYS_INLINE constexpr VertexAttribute(const VertexAttribute& rhs) : key(rhs.key) {}
|
||||
ALWAYS_INLINE VertexAttribute& operator=(const VertexAttribute& rhs) { key = rhs.key; return *this; }
|
||||
ALWAYS_INLINE constexpr VertexAttribute(const VertexAttribute& rhs) = default;
|
||||
ALWAYS_INLINE VertexAttribute& operator=(const VertexAttribute& rhs) = default;
|
||||
ALWAYS_INLINE bool operator==(const VertexAttribute& rhs) const { return key == rhs.key; }
|
||||
ALWAYS_INLINE bool operator!=(const VertexAttribute& rhs) const { return key != rhs.key; }
|
||||
ALWAYS_INLINE bool operator<(const VertexAttribute& rhs) const { return key < rhs.key; }
|
||||
@ -369,13 +369,11 @@ public:
|
||||
// TODO: purge this?
|
||||
union RasterizationState
|
||||
{
|
||||
BitField<u8, CullMode, 0, 2> cull_mode;
|
||||
u8 key;
|
||||
|
||||
BitField<u8, CullMode, 0, 2> cull_mode;
|
||||
|
||||
// clang-format off
|
||||
ALWAYS_INLINE RasterizationState() = default;
|
||||
ALWAYS_INLINE RasterizationState(const RasterizationState& rhs) : key(rhs.key) {}
|
||||
ALWAYS_INLINE RasterizationState& operator=(const RasterizationState& rhs) { key = rhs.key; return *this; }
|
||||
ALWAYS_INLINE bool operator==(const RasterizationState& rhs) const { return key == rhs.key; }
|
||||
ALWAYS_INLINE bool operator!=(const RasterizationState& rhs) const { return key != rhs.key; }
|
||||
ALWAYS_INLINE bool operator<(const RasterizationState& rhs) const { return key < rhs.key; }
|
||||
@ -386,14 +384,12 @@ public:
|
||||
|
||||
union DepthState
|
||||
{
|
||||
BitField<u8, DepthFunc, 0, 3> depth_test;
|
||||
BitField<u8, bool, 4, 1> depth_write;
|
||||
u8 key;
|
||||
|
||||
BitField<u8, DepthFunc, 0, 3> depth_test;
|
||||
BitField<u8, bool, 4, 1> depth_write;
|
||||
|
||||
// clang-format off
|
||||
ALWAYS_INLINE DepthState() = default;
|
||||
ALWAYS_INLINE DepthState(const DepthState& rhs) : key(rhs.key) {}
|
||||
ALWAYS_INLINE DepthState& operator=(const DepthState& rhs) { key = rhs.key; return *this; }
|
||||
ALWAYS_INLINE bool operator==(const DepthState& rhs) const { return key == rhs.key; }
|
||||
ALWAYS_INLINE bool operator!=(const DepthState& rhs) const { return key != rhs.key; }
|
||||
ALWAYS_INLINE bool operator<(const DepthState& rhs) const { return key < rhs.key; }
|
||||
@ -405,6 +401,8 @@ public:
|
||||
|
||||
union BlendState
|
||||
{
|
||||
u64 key;
|
||||
|
||||
BitField<u64, bool, 0, 1> enable;
|
||||
BitField<u64, BlendFunc, 1, 4> src_blend;
|
||||
BitField<u64, BlendFunc, 5, 4> src_alpha_blend;
|
||||
@ -422,12 +420,7 @@ public:
|
||||
BitField<u64, u16, 1, 16> blend_factors;
|
||||
BitField<u64, u8, 17, 6> blend_ops;
|
||||
|
||||
u64 key;
|
||||
|
||||
// clang-format off
|
||||
ALWAYS_INLINE BlendState() = default;
|
||||
ALWAYS_INLINE BlendState(const BlendState& rhs) : key(rhs.key) {}
|
||||
ALWAYS_INLINE BlendState& operator=(const BlendState& rhs) { key = rhs.key; return *this; }
|
||||
ALWAYS_INLINE bool operator==(const BlendState& rhs) const { return key == rhs.key; }
|
||||
ALWAYS_INLINE bool operator!=(const BlendState& rhs) const { return key != rhs.key; }
|
||||
ALWAYS_INLINE bool operator<(const BlendState& rhs) const { return key < rhs.key; }
|
||||
|
Loading…
x
Reference in New Issue
Block a user