Skip to content

Commit b265bca

Browse files
committed
build: Add fallback for std::atomic_ref
1 parent 4bb4815 commit b265bca

File tree

4 files changed

+40
-10
lines changed

4 files changed

+40
-10
lines changed

src/Cafe/HW/Latte/Core/LatteCommandProcessor.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -509,20 +509,20 @@ LatteCMDPtr LatteCP_itMemWrite(LatteCMDPtr cmd, uint32 nWords)
509509
if (word1 == 0x40000)
510510
{
511511
// write U32
512-
std::atomic_ref<uint32be> atomicRef(*memPtr);
512+
stdx::atomic_ref<uint32be> atomicRef(*memPtr);
513513
atomicRef.store(word2);
514514
}
515515
else if (word1 == 0x00000)
516516
{
517517
// write U64
518518
// note: The U32s are swapped here, but needs verification. Also, it seems like the two U32 halves are written independently and the U64 as a whole is not atomic -> investiagte
519-
std::atomic_ref<uint64be> atomicRef(*(uint64be*)memPtr);
519+
stdx::atomic_ref<uint64be> atomicRef(*(uint64be*)memPtr);
520520
atomicRef.store(((uint64le)word2 << 32) | word3);
521521
}
522522
else if (word1 == 0x20000)
523523
{
524524
// write U64 (little endian)
525-
std::atomic_ref<uint64le> atomicRef(*(uint64le*)memPtr);
525+
stdx::atomic_ref<uint64le> atomicRef(*(uint64le*)memPtr);
526526
atomicRef.store(((uint64le)word3 << 32) | word2);
527527
}
528528
else
@@ -543,7 +543,7 @@ LatteCMDPtr LatteCP_itEventWriteEOP(LatteCMDPtr cmd, uint32 nWords)
543543

544544
if (word0 == 0x504 && (word2&0x40000000)) // todo - figure out the flags
545545
{
546-
std::atomic_ref<uint64be> atomicRef(*(uint64be*)memory_getPointerFromPhysicalOffset(word1));
546+
stdx::atomic_ref<uint64be> atomicRef(*(uint64be*)memory_getPointerFromPhysicalOffset(word1));
547547
uint64 val = ((uint64)word4 << 32) | word3;
548548
atomicRef.store(val);
549549
}
@@ -554,8 +554,8 @@ LatteCMDPtr LatteCP_itEventWriteEOP(LatteCMDPtr cmd, uint32 nWords)
554554
if (triggerInterrupt)
555555
{
556556
// todo - timestamp interrupt
557-
TCL::TCLGPUNotifyNewRetirementTimestamp();
558557
}
558+
TCL::TCLGPUNotifyNewRetirementTimestamp();
559559
return cmd;
560560
}
561561

src/Cafe/OS/libs/TCL/TCL.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace TCL
3030
{
3131
MEMPTR<uint32> b;
3232
// this is the timestamp of the last buffer that was retired by the GPU
33-
std::atomic_ref<uint64be> retireTimestamp(s_tclStatePPC->gpuRetireMarker);
33+
stdx::atomic_ref<uint64be> retireTimestamp(s_tclStatePPC->gpuRetireMarker);
3434
*timestampOut = retireTimestamp.load();
3535
return 0;
3636
}
@@ -48,7 +48,7 @@ namespace TCL
4848
{
4949
while ( true )
5050
{
51-
std::atomic_ref<uint64be> retireTimestamp(s_tclStatePPC->gpuRetireMarker);
51+
stdx::atomic_ref<uint64be> retireTimestamp(s_tclStatePPC->gpuRetireMarker);
5252
uint64 currentTimestamp = retireTimestamp.load();
5353
if (currentTimestamp >= waitTs)
5454
return 0;

src/Cafe/OS/libs/gx2/GX2_Command.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ namespace GX2
114114
// current position of where the GPU is reading from. Updated via a memory write command submitted to the GPU
115115
uint32 GX2Command_GetPoolGPUReadIndex()
116116
{
117-
std::atomic_ref<MEMPTR<uint32be>> _readPtr(s_commandState->gpuCommandReadPtr);
117+
stdx::atomic_ref<MEMPTR<uint32be>> _readPtr(s_commandState->gpuCommandReadPtr);
118118
MEMPTR<uint32be> currentReadPtr = _readPtr.load();
119119
cemu_assert_debug(currentReadPtr);
120120
return (uint32)(currentReadPtr.GetPtr() - s_commandState->commandPoolBase.GetPtr());
@@ -125,7 +125,7 @@ namespace GX2
125125
uint64 retiredTimeStamp = GX2GetRetiredTimeStamp();
126126
retiredTimeStamp += 1;
127127
// but cant be higher than the submission timestamp
128-
std::atomic_ref<uint64be> _lastSubmissionTime(s_commandState->lastSubmissionTime);
128+
stdx::atomic_ref<uint64be> _lastSubmissionTime(s_commandState->lastSubmissionTime);
129129
uint64 submissionTimeStamp = _lastSubmissionTime.load();
130130
if (retiredTimeStamp > submissionTimeStamp)
131131
retiredTimeStamp = submissionTimeStamp;
@@ -294,7 +294,7 @@ namespace GX2
294294

295295
uint64 GX2GetLastSubmittedTimeStamp()
296296
{
297-
std::atomic_ref<uint64be> _lastSubmissionTime(s_commandState->lastSubmissionTime);
297+
stdx::atomic_ref<uint64be> _lastSubmissionTime(s_commandState->lastSubmissionTime);
298298
return _lastSubmissionTime.load();
299299
}
300300

src/Common/precompiled.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,4 +616,34 @@ namespace stdx
616616
scope_exit& operator=(scope_exit) = delete;
617617
void release() { m_released = true;}
618618
};
619+
620+
// Xcode 16 doesn't have std::atomic_ref support, so lets provide a minimalst reimplementation as a fallback
621+
#ifdef __cpp_lib_atomic_ref
622+
#include <atomic>
623+
template<typename T>
624+
using atomic_ref = std::atomic_ref<T>;
625+
#else
626+
template<typename T>
627+
class atomic_ref
628+
{
629+
static_assert(std::is_trivially_copyable<T>::value, "atomic_ref requires trivially copyable types");
630+
631+
public:
632+
using value_type = T;
633+
634+
explicit atomic_ref(T& obj) noexcept : ptr_(std::addressof(obj)) {}
635+
636+
T load(std::memory_order order = std::memory_order_seq_cst) const noexcept
637+
{
638+
return __atomic_load_n(ptr_, static_cast<int>(order));
639+
}
640+
641+
void store(T desired, std::memory_order order = std::memory_order_seq_cst) const noexcept
642+
{
643+
__atomic_store_n(ptr_, desired, static_cast<int>(order));
644+
}
645+
private:
646+
T* ptr_;
647+
};
648+
#endif
619649
}

0 commit comments

Comments
 (0)