From 545fee9c94c2671f6ae55fa54b1ab734c2ad8b91 Mon Sep 17 00:00:00 2001 From: "Admiral H. Curtiss" Date: Wed, 23 Nov 2022 21:58:18 +0100 Subject: [PATCH] Core/CommandProcessor: Reformat single/dual core dependent MMIO handlers. --- Source/Core/VideoCommon/CommandProcessor.cpp | 153 +++++++++++-------- 1 file changed, 88 insertions(+), 65 deletions(-) diff --git a/Source/Core/VideoCommon/CommandProcessor.cpp b/Source/Core/VideoCommon/CommandProcessor.cpp index ded0260b11..ada2d02904 100644 --- a/Source/Core/VideoCommon/CommandProcessor.cpp +++ b/Source/Core/VideoCommon/CommandProcessor.cpp @@ -265,80 +265,103 @@ void RegisterMMIO(MMIO::Mapping* mmio, u32 base) mmio->Register(base | PERF_SELECT, MMIO::InvalidRead(), MMIO::Nop()); // Some MMIOs have different handlers for single core vs. dual core mode. - mmio->Register( - base | FIFO_RW_DISTANCE_LO, - IsOnThread() ? MMIO::ComplexRead([](Core::System&, u32) { - if (fifo.CPWritePointer.load(std::memory_order_relaxed) >= - fifo.SafeCPReadPointer.load(std::memory_order_relaxed)) - { - return static_cast(fifo.CPWritePointer.load(std::memory_order_relaxed) - - fifo.SafeCPReadPointer.load(std::memory_order_relaxed)); - } - else - { - return static_cast(fifo.CPEnd.load(std::memory_order_relaxed) - - fifo.SafeCPReadPointer.load(std::memory_order_relaxed) + - fifo.CPWritePointer.load(std::memory_order_relaxed) - - fifo.CPBase.load(std::memory_order_relaxed) + 32); - } - }) : - MMIO::DirectRead(MMIO::Utils::LowPart(&fifo.CPReadWriteDistance)), - MMIO::DirectWrite(MMIO::Utils::LowPart(&fifo.CPReadWriteDistance), - WMASK_LO_ALIGN_32BIT)); - mmio->Register(base | FIFO_RW_DISTANCE_HI, - IsOnThread() ? - MMIO::ComplexRead([](Core::System&, u32) { - Fifo::SyncGPUForRegisterAccess(); - if (fifo.CPWritePointer.load(std::memory_order_relaxed) >= - fifo.SafeCPReadPointer.load(std::memory_order_relaxed)) - { - return (fifo.CPWritePointer.load(std::memory_order_relaxed) - - fifo.SafeCPReadPointer.load(std::memory_order_relaxed)) >> - 16; - } - else - { - return (fifo.CPEnd.load(std::memory_order_relaxed) - - fifo.SafeCPReadPointer.load(std::memory_order_relaxed) + - fifo.CPWritePointer.load(std::memory_order_relaxed) - - fifo.CPBase.load(std::memory_order_relaxed) + 32) >> - 16; - } - }) : - MMIO::ComplexRead([](Core::System&, u32) { - Fifo::SyncGPUForRegisterAccess(); - return fifo.CPReadWriteDistance.load(std::memory_order_relaxed) >> 16; - }), + const bool is_on_thread = IsOnThread(); + MMIO::ReadHandlingMethod* fifo_rw_distance_lo_r; + if (is_on_thread) + { + fifo_rw_distance_lo_r = MMIO::ComplexRead([](Core::System&, u32) { + if (fifo.CPWritePointer.load(std::memory_order_relaxed) >= + fifo.SafeCPReadPointer.load(std::memory_order_relaxed)) + { + return static_cast(fifo.CPWritePointer.load(std::memory_order_relaxed) - + fifo.SafeCPReadPointer.load(std::memory_order_relaxed)); + } + else + { + return static_cast(fifo.CPEnd.load(std::memory_order_relaxed) - + fifo.SafeCPReadPointer.load(std::memory_order_relaxed) + + fifo.CPWritePointer.load(std::memory_order_relaxed) - + fifo.CPBase.load(std::memory_order_relaxed) + 32); + } + }); + } + else + { + fifo_rw_distance_lo_r = MMIO::DirectRead(MMIO::Utils::LowPart(&fifo.CPReadWriteDistance)); + } + mmio->Register(base | FIFO_RW_DISTANCE_LO, fifo_rw_distance_lo_r, + MMIO::DirectWrite(MMIO::Utils::LowPart(&fifo.CPReadWriteDistance), + WMASK_LO_ALIGN_32BIT)); + + MMIO::ReadHandlingMethod* fifo_rw_distance_hi_r; + if (is_on_thread) + { + fifo_rw_distance_hi_r = MMIO::ComplexRead([](Core::System&, u32) { + Fifo::SyncGPUForRegisterAccess(); + if (fifo.CPWritePointer.load(std::memory_order_relaxed) >= + fifo.SafeCPReadPointer.load(std::memory_order_relaxed)) + { + return (fifo.CPWritePointer.load(std::memory_order_relaxed) - + fifo.SafeCPReadPointer.load(std::memory_order_relaxed)) >> + 16; + } + else + { + return (fifo.CPEnd.load(std::memory_order_relaxed) - + fifo.SafeCPReadPointer.load(std::memory_order_relaxed) + + fifo.CPWritePointer.load(std::memory_order_relaxed) - + fifo.CPBase.load(std::memory_order_relaxed) + 32) >> + 16; + } + }); + } + else + { + fifo_rw_distance_hi_r = MMIO::ComplexRead([](Core::System&, u32) { + Fifo::SyncGPUForRegisterAccess(); + return fifo.CPReadWriteDistance.load(std::memory_order_relaxed) >> 16; + }); + } + mmio->Register(base | FIFO_RW_DISTANCE_HI, fifo_rw_distance_hi_r, MMIO::ComplexWrite([WMASK_HI_RESTRICT](Core::System&, u32, u16 val) { Fifo::SyncGPUForRegisterAccess(); WriteHigh(fifo.CPReadWriteDistance, val & WMASK_HI_RESTRICT); Fifo::RunGpu(); })); + mmio->Register( base | FIFO_READ_POINTER_LO, - IsOnThread() ? MMIO::DirectRead(MMIO::Utils::LowPart(&fifo.SafeCPReadPointer)) : + is_on_thread ? MMIO::DirectRead(MMIO::Utils::LowPart(&fifo.SafeCPReadPointer)) : MMIO::DirectRead(MMIO::Utils::LowPart(&fifo.CPReadPointer)), MMIO::DirectWrite(MMIO::Utils::LowPart(&fifo.CPReadPointer), WMASK_LO_ALIGN_32BIT)); - mmio->Register( - base | FIFO_READ_POINTER_HI, - IsOnThread() ? MMIO::ComplexRead([](Core::System&, u32) { - Fifo::SyncGPUForRegisterAccess(); - return fifo.SafeCPReadPointer.load(std::memory_order_relaxed) >> 16; - }) : - MMIO::ComplexRead([](Core::System&, u32) { - Fifo::SyncGPUForRegisterAccess(); - return fifo.CPReadPointer.load(std::memory_order_relaxed) >> 16; - }), - IsOnThread() ? MMIO::ComplexWrite([WMASK_HI_RESTRICT](Core::System&, u32, u16 val) { - Fifo::SyncGPUForRegisterAccess(); - WriteHigh(fifo.CPReadPointer, val & WMASK_HI_RESTRICT); - fifo.SafeCPReadPointer.store(fifo.CPReadPointer.load(std::memory_order_relaxed), - std::memory_order_relaxed); - }) : - MMIO::ComplexWrite([WMASK_HI_RESTRICT](Core::System&, u32, u16 val) { - Fifo::SyncGPUForRegisterAccess(); - WriteHigh(fifo.CPReadPointer, val & WMASK_HI_RESTRICT); - })); + + MMIO::ReadHandlingMethod* fifo_read_hi_r; + MMIO::WriteHandlingMethod* fifo_read_hi_w; + if (is_on_thread) + { + fifo_read_hi_r = MMIO::ComplexRead([](Core::System&, u32) { + Fifo::SyncGPUForRegisterAccess(); + return fifo.SafeCPReadPointer.load(std::memory_order_relaxed) >> 16; + }); + fifo_read_hi_w = MMIO::ComplexWrite([WMASK_HI_RESTRICT](Core::System&, u32, u16 val) { + Fifo::SyncGPUForRegisterAccess(); + WriteHigh(fifo.CPReadPointer, val & WMASK_HI_RESTRICT); + fifo.SafeCPReadPointer.store(fifo.CPReadPointer.load(std::memory_order_relaxed), + std::memory_order_relaxed); + }); + } + else + { + fifo_read_hi_r = MMIO::ComplexRead([](Core::System&, u32) { + Fifo::SyncGPUForRegisterAccess(); + return fifo.CPReadPointer.load(std::memory_order_relaxed) >> 16; + }); + fifo_read_hi_w = MMIO::ComplexWrite([WMASK_HI_RESTRICT](Core::System&, u32, u16 val) { + Fifo::SyncGPUForRegisterAccess(); + WriteHigh(fifo.CPReadPointer, val & WMASK_HI_RESTRICT); + }); + } + mmio->Register(base | FIFO_READ_POINTER_HI, fifo_read_hi_r, fifo_read_hi_w); } void GatherPipeBursted()