From a5e3f163a5b352482ced2fe1cf659835105df80e Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sun, 13 Jul 2025 20:16:59 +1000 Subject: [PATCH] Misc: Make bitfield unions trivially copyable --- src/common/bitfield.h | 3 --- src/util/cd_image.h | 18 ------------------ src/util/gpu_device.h | 25 +++++++++---------------- 3 files changed, 9 insertions(+), 37 deletions(-) diff --git a/src/common/bitfield.h b/src/common/bitfield.h index 73aff18c4..29b2d2f08 100644 --- a/src/common/bitfield.h +++ b/src/common/bitfield.h @@ -12,9 +12,6 @@ struct BitField { static_assert(!std::is_same_v || 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(~0)) >> (8 * sizeof(BackingDataType) - BitCount)) << BitIndex; diff --git a/src/util/cd_image.h b/src/util/cd_image.h index 85de1bdb5..2cc792b5b 100644 --- a/src/util/cd_image.h +++ b/src/util/cd_image.h @@ -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"); diff --git a/src/util/gpu_device.h b/src/util/gpu_device.h index 40f6dc1a8..05f0e6ee6 100644 --- a/src/util/gpu_device.h +++ b/src/util/gpu_device.h @@ -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 cull_mode; u8 key; + BitField 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 depth_test; - BitField depth_write; u8 key; + BitField depth_test; + BitField 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 enable; BitField src_blend; BitField src_alpha_blend; @@ -422,12 +420,7 @@ public: BitField blend_factors; BitField 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; }