From 983b986303769c90248cfd2a33119b18fd612091 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Sun, 12 Nov 2017 15:12:17 +0100 Subject: [PATCH 1/3] Don't delete BitField copy assignment operator on VS --- Source/Core/Common/BitField.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Source/Core/Common/BitField.h b/Source/Core/Common/BitField.h index c8a81a092a..6866282298 100644 --- a/Source/Core/Common/BitField.h +++ b/Source/Core/Common/BitField.h @@ -124,15 +124,18 @@ public: // so that we can use this within unions constexpr BitField() = default; +// Visual Studio (as of VS2017) considers BitField to not be trivially +// copyable if we delete this copy assignment operator. +// https://developercommunity.visualstudio.com/content/problem/101208/c-compiler-is-overly-strict-regarding-whether-a-cl.html +#ifndef _MSC_VER // We explicitly delete the copy assignment operator here, because the // default copy assignment would copy the full storage value, rather than // just the bits relevant to this particular bit field. // Ideally, we would just implement the copy assignment to copy only the - // relevant bits, but this requires compiler support for unrestricted - // unions. - // TODO: Implement this operator properly once all target compilers - // support unrestricted unions. + // relevant bits, but we're prevented from doing that because the savestate + // code expects that this class is trivially copyable. BitField& operator=(const BitField&) = delete; +#endif __forceinline BitField& operator=(T val) { From 8ad5ea2ede6c19bf3ea9f0ad0ef9c65d7982378f Mon Sep 17 00:00:00 2001 From: JosJuice Date: Sun, 12 Nov 2017 17:20:59 +0100 Subject: [PATCH 2/3] Call Do for every member of SCPFifoStruct individually We need this because VS currently doesn't consider std::is_trivially_copyable::type>::value to be true and because no compiler should consider it to be true if we replace the volatiles with atomics. --- Source/Core/VideoCommon/CommandProcessor.cpp | 27 +++++++++++++++++++- Source/Core/VideoCommon/CommandProcessor.h | 2 ++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/Source/Core/VideoCommon/CommandProcessor.cpp b/Source/Core/VideoCommon/CommandProcessor.cpp index 04ede7c412..424435a178 100644 --- a/Source/Core/VideoCommon/CommandProcessor.cpp +++ b/Source/Core/VideoCommon/CommandProcessor.cpp @@ -50,6 +50,31 @@ static void UpdateInterrupts_Wrapper(u64 userdata, s64 cyclesLate) UpdateInterrupts(userdata); } +void SCPFifoStruct::DoState(PointerWrap& p) +{ + p.Do(CPBase); + p.Do(CPEnd); + p.Do(CPHiWatermark); + p.Do(CPLoWatermark); + p.Do(CPReadWriteDistance); + p.Do(CPWritePointer); + p.Do(CPReadPointer); + p.Do(CPBreakpoint); + p.Do(SafeCPReadPointer); + + p.Do(bFF_GPLinkEnable); + p.Do(bFF_GPReadEnable); + p.Do(bFF_BPEnable); + p.Do(bFF_BPInt); + p.Do(bFF_Breakpoint); + + p.Do(bFF_LoWatermarkInt); + p.Do(bFF_HiWatermarkInt); + + p.Do(bFF_LoWatermark); + p.Do(bFF_HiWatermark); +} + void DoState(PointerWrap& p) { p.DoPOD(m_CPStatusReg); @@ -60,7 +85,7 @@ void DoState(PointerWrap& p) p.Do(m_bboxright); p.Do(m_bboxbottom); p.Do(m_tokenReg); - p.Do(fifo); + fifo.DoState(p); p.Do(s_interrupt_set); p.Do(s_interrupt_waiting); diff --git a/Source/Core/VideoCommon/CommandProcessor.h b/Source/Core/VideoCommon/CommandProcessor.h index 7257d3e861..77623357d9 100644 --- a/Source/Core/VideoCommon/CommandProcessor.h +++ b/Source/Core/VideoCommon/CommandProcessor.h @@ -38,6 +38,8 @@ struct SCPFifoStruct volatile u32 bFF_LoWatermark; volatile u32 bFF_HiWatermark; + + void DoState(PointerWrap& p); }; // This one is shared between gfx thread and emulator thread. From 72b7b96571aa72da730bec6c6720e58a7ebfc977 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Sun, 12 Nov 2017 17:21:11 +0100 Subject: [PATCH 3/3] Remove IsTriviallyCopyable hack for VS --- Source/Core/Common/ChunkFile.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Source/Core/Common/ChunkFile.h b/Source/Core/Common/ChunkFile.h index fdae41102b..ea4bb2cd54 100644 --- a/Source/Core/Common/ChunkFile.h +++ b/Source/Core/Common/ChunkFile.h @@ -41,14 +41,11 @@ #if (__has_feature(is_trivially_copyable) && \ (defined(_LIBCPP_VERSION) || defined(__GLIBCXX__))) || \ - (defined(__GNUC__) && __GNUC__ >= 5) + (defined(__GNUC__) && __GNUC__ >= 5) || defined(_MSC_VER) #define IsTriviallyCopyable(T) \ std::is_trivially_copyable::type>::value #elif __GNUC__ #define IsTriviallyCopyable(T) std::has_trivial_copy_constructor::value -#elif _MSC_VER -// (shuffle2) see https://github.com/dolphin-emu/dolphin/pull/2218 -#define IsTriviallyCopyable(T) 1 #else #error No version of is_trivially_copyable #endif