From 9e0722ab1781d91e2df381c28375bc6567b3392b Mon Sep 17 00:00:00 2001 From: lizzie Date: Thu, 7 May 2026 18:14:58 +0000 Subject: [PATCH 1/9] fixups --- .ci/managarm/build.sh | 113 ++++++++++++++++++++++++++++++++++++++++++ tools/README.md | 1 + tools/sysvpatch.c | 24 +++++++++ 3 files changed, 138 insertions(+) create mode 100755 .ci/managarm/build.sh create mode 100644 tools/sysvpatch.c diff --git a/.ci/managarm/build.sh b/.ci/managarm/build.sh new file mode 100755 index 0000000000..a5a6e9a9a9 --- /dev/null +++ b/.ci/managarm/build.sh @@ -0,0 +1,113 @@ +#!/usr/local/bin/bash -ex + +# SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project +# SPDX-License-Identifier: GPL-3.0-or-later + +WORK_PATH="$PWD" + +export CFLAGS="-U__FreeBSD__ -U__MMX__ -U__SSE__ -U__SSE2__ -U__SSE3__ -D_DEFAULT_SOURCE=1 -D__managarm__=1 -I$MANAGARM_ROOTFS/usr/include -I$MANAGARM_ROOTFS/usr/share/freestnd-cxx-hdrs/x86_64/include -I$MANAGARM_ROOTFS/usr/share/freestnd-c-hdrs/x86_64/include" +export CXXFLAGS="-U__FreeBSD__ -U__MMX__ -U__SSE__ -U__SSE2__ -U__SSE3__ -D_DEFAULT_SOURCE=1 -D__managarm__=1 -I$MANAGARM_ROOTFS/usr/include/c++/14.2.0 -I$MANAGARM_ROOTFS/usr/include -I$MANAGARM_ROOTFS/usr/include/c++/14.2.0/x86_64-managarm -I$MANAGARM_ROOTFS/usr/share/freestnd-c-hdrs/x86_64/include" +export CC=clang +export CXX=clang++ +export LD=ld.lld + +[ -z ${MANAGARM_ROOTFS+x} ] && exit + +[ -f "managarm-toolchain.cmake" ] || cat << EOF >"managarm-toolchain.cmake" +set(CMAKE_SYSROOT "$MANAGARM_ROOTFS/usr") +set(CMAKE_STAGING_PREFIX "$MANAGARM_ROOTFS/usr") +set(CMAKE_SYSTEM_NAME "managarm") +set(UNIX TRUE) + +set(CMAKE_C_FLAGS "$CFLAGS") +set(CMAKE_CXX_FLAGS "$CXXFLAGS") + +set(CMAKE_EXE_LINKER_FLAGS "-L$MANAGARM_ROOTFS/usr/lib64 -L$MANAGARM_ROOTFS/usr/lib -L$MANAGARM_ROOTFS/usr/lib/gcc/x86_64-managarm/14.2.0") +set(CMAKE_C_LINK_FLAGS "-L$MANAGARM_ROOTFS/usr/lib64 -L$MANAGARM_ROOTFS/usr/lib -L$MANAGARM_ROOTFS/usr/lib/gcc/x86_64-managarm/14.2.0") +set(CMAKE_CXX_LINK_FLAGS "-L$MANAGARM_ROOTFS/usr/lib64 -L$MANAGARM_ROOTFS/usr/lib -L$MANAGARM_ROOTFS/usr/lib/gcc/x86_64-managarm/14.2.0") + +set(CMAKE_C_COMPILER "$CC") +set(CMAKE_CXX_COMPILER "$CXX") +set(CMAKE_LINKER "$LD") +set(CMAKE_C_LINK_EXECUTABLE " -o -lc -lgcc ") +set(CMAKE_CXX_LINK_EXECUTABLE " -o -lc -lstdc++ -lgcc ") + +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) + +# TODO: Why does cmake not set this? +set(CMAKE_SIZEOF_VOID_P 8) +EOF + +[ -z ${NPROC+x} ] && NPROC=$(nproc || 1) + +build_openssl() { + [ -d "$WORK_PATH/openssl" ] || git clone --depth=1 https://github.com/openssl/openssl "$WORK_PATH/openssl" + cd "$WORK_PATH/openssl" + [ -f Makefile ] || ./Configure -ffreestanding \ + -L$MANAGARM_ROOTFS/usr/lib -lc \ + -I$MANAGARM_ROOTFS/usr/include \ + no-threads no-shared no-afalgeng no-async no-capieng no-cmp no-cms no-comp no-ct \ + no-docs no-dgram no-dso no-dynamic-engine no-engine no-filenames no-gost \ + no-http no-legacy no-module no-nextprotoneg no-ocsp no-padlockeng no-quic \ + no-srp no-srtp no-ssl-trace no-static-engine no-tests no-thread-pool no-ts \ + no-ui-console no-uplink no-ssl3-method no-tls1-method no-tls1_1-method \ + no-dtls1-method no-dtls1_2-method no-argon2 no-bf no-blake2 no-cast \ + no-dsa no-idea no-md4 no-mdc2 no-ocb no-rc2 no-rc4 no-rmd160 no-scrypt \ + no-siphash no-siv no-sm2 no-sm3 no-sm4 no-whirlpool no-apps \ + --prefix=$MANAGARM_ROOTFS/usr BSD-generic64 + gmake -j8 + sudo gmake install -j8 + cd "$WORK_PATH" +} +[ -f "$MANAGARM_ROOTFS/usr/lib/libssl.a" ] || build_openssl + +# Normally a platform has a package manager +# but managarm has one thats so underdeveloped +# we may as well do it ourselves +export EXTRA_CMAKE_FLAGS=("${EXTRA_CMAKE_FLAGS[@]}" $@) +cmake -S . -B build -G "Unix Makefiles" \ + -DCMAKE_TOOLCHAIN_FILE="managarm-toolchain.cmake" \ + -DENABLE_QT_TRANSLATION=OFF \ + -DENABLE_CUBEB=OFF \ + -DCMAKE_BUILD_TYPE=RelWithDebInfo \ + -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ + -DCMAKE_CXX_FLAGS="$ARCH_FLAGS -pipe" \ + -DCMAKE_C_FLAGS="$ARCH_FLAGS -pipe" \ + -DENABLE_SDL2=ON \ + -DENABLE_LIBUSB=OFF \ + -DENABLE_UPDATE_CHECKER=OFF \ + -DENABLE_QT=OFF \ + -DENABLE_OPENGL=OFF \ + -DENABLE_OPENSSL=OFF \ + -DENABLE_WEB_SERVICE=OFF \ + -DUSE_DISCORD_PRESENCE=OFF \ + -DCPMUTIL_FORCE_BUNDLED=ON \ + -DOPENSSL_ROOT_DIR="$MANAGARM_ROOTFS/usr" \ + -DOPENSSL_SSL_LIBRARY="$MANAGARM_ROOTFS/usr/lib/libssl.a" \ + -DOPENSSL_CRYPTO_LIBRARY="$MANAGARM_ROOTFS/usr/lib/libcrypto.a" \ + -DOPENSSL_INCLUDE_DIR="$MANAGARM_ROOTFS/usr/include/openssl" \ + -DYUZU_USE_EXTERNAL_FFMPEG=ON \ + -DYUZU_USE_CPM=ON \ + -DDYNARMIC_ENABLE_NO_EXECUTE_SUPPORT=OFF \ + -DDYNARMIC_TESTS=ON \ + -DYUZU_TESTS=ON \ + -DYUZU_USE_EXTERNAL_SDL2=ON \ + -DHAVE_SDL_THREADS=ON \ + -DSDL_THREADS=ON \ + -DSDL_PTHREADS=ON \ + -DSDL_THREAD_PTHREAD=ON \ + -DSDL_PTHREADS_SEM=OFF \ + -DSDL_ALTIVEC=OFF \ + -DSDL_DISKAUDIO=OFF \ + -DSDL_DIRECTFB=ON \ + -DSDL_OPENGL=ON \ + -DSDL_OPENGLES=ON \ + -DSDL_PTHREADS=ON \ + -DSDL_PTHREADS_SEM=OFF \ + -DSDL_STATIC=ON \ + "${EXTRA_CMAKE_FLAGS[@]}" || exit + +cmake --build build -t yuzu-cmd -- -j$NPROC diff --git a/tools/README.md b/tools/README.md index 767892e7ac..863cc8405c 100644 --- a/tools/README.md +++ b/tools/README.md @@ -22,6 +22,7 @@ Tools for Eden and other subprojects. - `clang-format.sh`: Runs `clang-format` on the entire codebase. * Requires: clang - `find-unused-strings.sh`: Find any unused strings in the Android app (XML -> Kotlin). +- `sysvpatch.c`: Patches ELF files so their OS/ABI is SYSV (managarm workaround). ## Android It's recommended to run these scritps after almost any Android change, as they are relatively fast and important both for APK bloat and CI. diff --git a/tools/sysvpatch.c b/tools/sysvpatch.c new file mode 100644 index 0000000000..08d88eadb5 --- /dev/null +++ b/tools/sysvpatch.c @@ -0,0 +1,24 @@ +#include +#include +#include +#include +#include +int main(int argc, char *argv[]) { + char s[BUFSIZ]; + snprintf(s, sizeof s, "strip %s", argv[1]); + system(s); + struct stat st; + int fd = open(argv[1], O_RDONLY); + if (fd) { + fstat(fd, &st); + char *buf = malloc(st.st_size); + write(fd, buf, st.st_size); + close(fd); + /* set elf type to 0 = SYSV */ + buf[7] = 0; + write(fileno(stdout), buf, st.st_size); + free(buf); + return EXIT_SUCCESS; + } + return EXIT_FAILURE; +} From d5c50f8e9b0681b169e474f4f83ea3019fbee458 Mon Sep 17 00:00:00 2001 From: lizzie Date: Thu, 30 Apr 2026 16:30:19 +0000 Subject: [PATCH 2/9] [video_core] Remove redundant references in GPU engine structs Signed-off-by: lizzie --- src/video_core/control/channel_state.cpp | 4 +- src/video_core/control/channel_state.h | 2 +- src/video_core/dma_pusher.cpp | 32 ++--- src/video_core/dma_pusher.h | 53 ++++--- src/video_core/engines/puller.cpp | 139 ++++++++----------- src/video_core/engines/puller.h | 46 ++----- src/video_core/gpu.cpp | 168 +++++++---------------- 7 files changed, 163 insertions(+), 281 deletions(-) diff --git a/src/video_core/control/channel_state.cpp b/src/video_core/control/channel_state.cpp index d07c7e2a83..49e2e270b1 100644 --- a/src/video_core/control/channel_state.cpp +++ b/src/video_core/control/channel_state.cpp @@ -19,10 +19,10 @@ namespace Tegra::Control { ChannelState::ChannelState(s32 bind_id_) : bind_id{bind_id_}, initialized{} {} -void ChannelState::Init(Core::System& system, GPU& gpu, u64 program_id_) { +void ChannelState::Init(Core::System& system, u64 program_id_) { ASSERT(memory_manager); program_id = program_id_; - dma_pusher.emplace(system, gpu, *memory_manager, *this); + dma_pusher.emplace(system, *memory_manager, *this); maxwell_3d.emplace(system, *memory_manager); fermi_2d.emplace(*memory_manager); kepler_compute.emplace(system, *memory_manager); diff --git a/src/video_core/control/channel_state.h b/src/video_core/control/channel_state.h index 2984d2e09e..c72e1446e7 100644 --- a/src/video_core/control/channel_state.h +++ b/src/video_core/control/channel_state.h @@ -34,7 +34,7 @@ namespace Control { struct ChannelState { explicit ChannelState(s32 bind_id); - void Init(Core::System& system, GPU& gpu, u64 program_id); + void Init(Core::System& system, u64 program_id); void BindRasterizer(VideoCore::RasterizerInterface* rasterizer); diff --git a/src/video_core/dma_pusher.cpp b/src/video_core/dma_pusher.cpp index 3844a8e2f9..5f6b34836c 100644 --- a/src/video_core/dma_pusher.cpp +++ b/src/video_core/dma_pusher.cpp @@ -12,37 +12,32 @@ #include "video_core/guest_memory.h" #include "video_core/memory_manager.h" #include "video_core/rasterizer_interface.h" -#include "video_core/texture_cache/util.h" - -#ifdef _MSC_VER -#include -#endif namespace Tegra { constexpr u32 MacroRegistersStart = 0xE00; [[maybe_unused]] constexpr u32 ComputeInline = 0x6D; -DmaPusher::DmaPusher(Core::System& system_, GPU& gpu_, MemoryManager& memory_manager_, - Control::ChannelState& channel_state_) - : gpu{gpu_}, system{system_}, memory_manager{memory_manager_}, puller{gpu_, memory_manager_, - *this, channel_state_}, signal_sync{false}, synced{false} {} +DmaPusher::DmaPusher(Core::System& system_, MemoryManager& memory_manager_, Control::ChannelState& channel_state_) + : system{system_} + , memory_manager{memory_manager_} + , channel_state{channel_state_} + , signal_sync{false} + , synced{false} +{} DmaPusher::~DmaPusher() = default; void DmaPusher::DispatchCalls() { - dma_pushbuffer_subindex = 0; - dma_state.is_last_call = true; - while (system.IsPoweredOn()) { if (!Step()) { break; } } - gpu.FlushCommands(); - gpu.OnCommandListEnd(); + system.GPU().FlushCommands(); + system.GPU().OnCommandListEnd(); } bool DmaPusher::Step() { @@ -171,9 +166,9 @@ void DmaPusher::SetState(const CommandHeader& command_header) { dma_state.method_count = command_header.method_count; } -void DmaPusher::CallMethod(u32 argument) const { +void DmaPusher::CallMethod(u32 argument) { if (dma_state.method < non_puller_methods) { - puller.CallPullerMethod(Engines::Puller::MethodCall{ + puller.CallPullerMethod(*this, Engines::Puller::MethodCall{ dma_state.method, argument, dma_state.subchannel, @@ -191,9 +186,9 @@ void DmaPusher::CallMethod(u32 argument) const { } } -void DmaPusher::CallMultiMethod(const u32* base_start, u32 num_methods) const { +void DmaPusher::CallMultiMethod(const u32* base_start, u32 num_methods) { if (dma_state.method < non_puller_methods) { - puller.CallMultiMethod(dma_state.method, dma_state.subchannel, base_start, num_methods, dma_state.method_count); + puller.CallMultiMethod(*this, dma_state.method, dma_state.subchannel, base_start, num_methods, dma_state.method_count); } else { auto subchannel = subchannels[dma_state.subchannel]; subchannel->ConsumeSink(); @@ -204,7 +199,6 @@ void DmaPusher::CallMultiMethod(const u32* base_start, u32 num_methods) const { void DmaPusher::BindRasterizer(VideoCore::RasterizerInterface* rasterizer_) { rasterizer = rasterizer_; - puller.BindRasterizer(rasterizer); } } // namespace Tegra diff --git a/src/video_core/dma_pusher.h b/src/video_core/dma_pusher.h index f850513603..d8ae737a46 100644 --- a/src/video_core/dma_pusher.h +++ b/src/video_core/dma_pusher.h @@ -109,25 +109,21 @@ inline CommandHeader BuildCommandHeader(BufferMethods method, u32 arg_count, Sub struct CommandList final { CommandList() = default; explicit CommandList(std::size_t size) : command_lists(size) {} - explicit CommandList( - boost::container::small_vector&& prefetch_command_list_) + explicit CommandList(boost::container::small_vector&& prefetch_command_list_) : prefetch_command_list{std::move(prefetch_command_list_)} {} boost::container::small_vector command_lists; boost::container::small_vector prefetch_command_list; }; -/** - * The DmaPusher class implements DMA submission to FIFOs, providing an area of memory that the - * emulated app fills with commands and tells PFIFO to process. The pushbuffers are then assembled - * into a "command stream" consisting of 32-bit words that make up "commands". - * See https://envytools.readthedocs.io/en/latest/hw/fifo/dma-pusher.html#fifo-dma-pusher for - * details on this implementation. - */ +/// @brief The DmaPusher class implements DMA submission to FIFOs, providing an area of memory that the +/// emulated app fills with commands and tells PFIFO to process. The pushbuffers are then assembled +/// into a "command stream" consisting of 32-bit words that make up "commands". +/// See https://envytools.readthedocs.io/en/latest/hw/fifo/dma-pusher.html#fifo-dma-pusher for +/// details on this implementation. class DmaPusher final { public: - explicit DmaPusher(Core::System& system_, GPU& gpu_, MemoryManager& memory_manager_, - Control::ChannelState& channel_state_); + explicit DmaPusher(Core::System& system_, MemoryManager& memory_manager_, Control::ChannelState& channel_state_); ~DmaPusher(); void Push(CommandList&& entries) { @@ -136,8 +132,7 @@ public: void DispatchCalls(); - void BindSubchannel(Engines::EngineInterface* engine, u32 subchannel_id, - Engines::EngineTypes engine_type) { + void BindSubchannel(Engines::EngineInterface* engine, u32 subchannel_id, Engines::EngineTypes engine_type) { subchannels[subchannel_id] = engine; subchannel_type[subchannel_id] = engine_type; } @@ -152,11 +147,11 @@ private: void SetState(const CommandHeader& command_header); - void CallMethod(u32 argument) const; - void CallMultiMethod(const u32* base_start, u32 num_methods) const; + void CallMethod(u32 argument); + void CallMultiMethod(const u32* base_start, u32 num_methods); - Common::ScratchBuffer - command_headers; ///< Buffer for list of commands fetched at once +public: + Common::ScratchBuffer command_headers; ///< Buffer for list of commands fetched at once std::queue dma_pushbuffer; ///< Queue of command lists to be processed std::size_t dma_pushbuffer_subindex{}; ///< Index within a command list within the pushbuffer @@ -172,24 +167,24 @@ private: bool is_last_call; }; + Core::System& system; + MemoryManager& memory_manager; + Control::ChannelState& channel_state; + DmaState dma_state{}; - bool dma_increment_once{}; - - const bool ib_enable{true}; ///< IB mode enabled - std::array subchannels{}; std::array subchannel_type; - GPU& gpu; - Core::System& system; - MemoryManager& memory_manager; - mutable Engines::Puller puller; - - VideoCore::RasterizerInterface* rasterizer; - bool signal_sync; - bool synced; + Engines::Puller puller; std::mutex sync_mutex; std::condition_variable sync_cv; + + VideoCore::RasterizerInterface* rasterizer = nullptr; + + const bool ib_enable : 1 = true; ///< IB mode enabled + bool dma_increment_once : 1 = false; + bool signal_sync : 1 = false; + bool synced : 1 = false; }; } // namespace Tegra diff --git a/src/video_core/engines/puller.cpp b/src/video_core/engines/puller.cpp index 4030f93d49..b153619c16 100644 --- a/src/video_core/engines/puller.cpp +++ b/src/video_core/engines/puller.cpp @@ -22,37 +22,29 @@ namespace Tegra::Engines { -Puller::Puller(GPU& gpu_, MemoryManager& memory_manager_, DmaPusher& dma_pusher_, - Control::ChannelState& channel_state_) - : gpu{gpu_}, memory_manager{memory_manager_}, dma_pusher{dma_pusher_}, channel_state{ - channel_state_} {} - -Puller::~Puller() = default; - -void Puller::ProcessBindMethod(const MethodCall& method_call) { +void Puller::ProcessBindMethod(DmaPusher& dma_pusher, const MethodCall& method_call) { // Bind the current subchannel to the desired engine id. - LOG_DEBUG(HW_GPU, "Binding subchannel {} to engine {}", method_call.subchannel, - method_call.argument); + LOG_DEBUG(HW_GPU, "Binding subchannel {} to engine {}", method_call.subchannel, method_call.argument); const auto engine_id = static_cast(method_call.argument); bound_engines[method_call.subchannel] = engine_id; switch (engine_id) { case EngineID::FERMI_TWOD_A: - dma_pusher.BindSubchannel(&*channel_state.fermi_2d, method_call.subchannel, EngineTypes::Fermi2D); + dma_pusher.BindSubchannel(&*dma_pusher.channel_state.fermi_2d, method_call.subchannel, EngineTypes::Fermi2D); break; case EngineID::MAXWELL_B: - dma_pusher.BindSubchannel(&*channel_state.maxwell_3d, method_call.subchannel, EngineTypes::Maxwell3D); + dma_pusher.BindSubchannel(&*dma_pusher.channel_state.maxwell_3d, method_call.subchannel, EngineTypes::Maxwell3D); break; case EngineID::KEPLER_COMPUTE_B: - dma_pusher.BindSubchannel(&*channel_state.kepler_compute, method_call.subchannel, EngineTypes::KeplerCompute); + dma_pusher.BindSubchannel(&*dma_pusher.channel_state.kepler_compute, method_call.subchannel, EngineTypes::KeplerCompute); break; case EngineID::MAXWELL_DMA_COPY_A: - dma_pusher.BindSubchannel(&*channel_state.maxwell_dma, method_call.subchannel, EngineTypes::MaxwellDMA); + dma_pusher.BindSubchannel(&*dma_pusher.channel_state.maxwell_dma, method_call.subchannel, EngineTypes::MaxwellDMA); break; case EngineID::KEPLER_INLINE_TO_MEMORY_B: - dma_pusher.BindSubchannel(&*channel_state.kepler_memory, method_call.subchannel, EngineTypes::KeplerMemory); + dma_pusher.BindSubchannel(&*dma_pusher.channel_state.kepler_memory, method_call.subchannel, EngineTypes::KeplerMemory); break; case EngineID::NV01_TIMER: - dma_pusher.BindSubchannel(&*channel_state.nv01_timer, method_call.subchannel, EngineTypes::Nv01Timer); + dma_pusher.BindSubchannel(&*dma_pusher.channel_state.nv01_timer, method_call.subchannel, EngineTypes::Nv01Timer); break; default: UNIMPLEMENTED_MSG("Unimplemented engine {:04X}", engine_id); @@ -60,15 +52,15 @@ void Puller::ProcessBindMethod(const MethodCall& method_call) { } } -void Puller::ProcessFenceActionMethod() { +void Puller::ProcessFenceActionMethod(DmaPusher& dma_pusher) { switch (regs.fence_action.op) { case Puller::FenceOperation::Acquire: // UNIMPLEMENTED_MSG("Channel Scheduling pending."); // WaitFence(regs.fence_action.syncpoint_id, regs.fence_value); - rasterizer->ReleaseFences(); + dma_pusher.rasterizer->ReleaseFences(); break; case Puller::FenceOperation::Increment: - rasterizer->SignalSyncPoint(regs.fence_action.syncpoint_id); + dma_pusher.rasterizer->SignalSyncPoint(regs.fence_action.syncpoint_id); break; default: UNIMPLEMENTED_MSG("Unimplemented operation {}", regs.fence_action.op.Value()); @@ -76,37 +68,35 @@ void Puller::ProcessFenceActionMethod() { } } -void Puller::ProcessSemaphoreTriggerMethod() { +void Puller::ProcessSemaphoreTriggerMethod(DmaPusher& dma_pusher) { const auto semaphoreOperationMask = 0xF; - const auto op = - static_cast(regs.semaphore_trigger & semaphoreOperationMask); + const auto op = GpuSemaphoreOperation(regs.semaphore_trigger & semaphoreOperationMask); if (op == GpuSemaphoreOperation::WriteLong) { const GPUVAddr sequence_address{regs.semaphore_address.SemaphoreAddress()}; const u32 payload = regs.semaphore_sequence; - rasterizer->Query(sequence_address, VideoCommon::QueryType::Payload, - VideoCommon::QueryPropertiesFlags::HasTimeout, payload, 0); + dma_pusher.rasterizer->Query(sequence_address, VideoCommon::QueryType::Payload, VideoCommon::QueryPropertiesFlags::HasTimeout, payload, 0); } else { do { - const u32 word{memory_manager.Read(regs.semaphore_address.SemaphoreAddress())}; + const u32 word = dma_pusher.memory_manager.Read(regs.semaphore_address.SemaphoreAddress()); regs.acquire_source = true; regs.acquire_value = regs.semaphore_sequence; if (op == GpuSemaphoreOperation::AcquireEqual) { regs.acquire_active = true; regs.acquire_mode = false; if (word != regs.acquire_value) { - rasterizer->ReleaseFences(); + dma_pusher.rasterizer->ReleaseFences(); continue; } } else if (op == GpuSemaphoreOperation::AcquireGequal) { regs.acquire_active = true; regs.acquire_mode = true; if (word < regs.acquire_value) { - rasterizer->ReleaseFences(); + dma_pusher.rasterizer->ReleaseFences(); continue; } } else if (op == GpuSemaphoreOperation::AcquireMask) { if (word && regs.semaphore_sequence == 0) { - rasterizer->ReleaseFences(); + dma_pusher.rasterizer->ReleaseFences(); continue; } } else { @@ -116,21 +106,20 @@ void Puller::ProcessSemaphoreTriggerMethod() { } } -void Puller::ProcessSemaphoreRelease() { +void Puller::ProcessSemaphoreRelease(DmaPusher& dma_pusher) { const GPUVAddr sequence_address{regs.semaphore_address.SemaphoreAddress()}; const u32 payload = regs.semaphore_release; - rasterizer->Query(sequence_address, VideoCommon::QueryType::Payload, - VideoCommon::QueryPropertiesFlags::IsAFence, payload, 0); + dma_pusher.rasterizer->Query(sequence_address, VideoCommon::QueryType::Payload, VideoCommon::QueryPropertiesFlags::IsAFence, payload, 0); } -void Puller::ProcessSemaphoreAcquire() { - u32 word = memory_manager.Read(regs.semaphore_address.SemaphoreAddress()); +void Puller::ProcessSemaphoreAcquire(DmaPusher& dma_pusher) { + u32 word = dma_pusher.memory_manager.Read(regs.semaphore_address.SemaphoreAddress()); const auto value = regs.semaphore_acquire; while (word != value) { regs.acquire_active = true; regs.acquire_value = value; - rasterizer->ReleaseFences(); - word = memory_manager.Read(regs.semaphore_address.SemaphoreAddress()); + dma_pusher.rasterizer->ReleaseFences(); + word = dma_pusher.memory_manager.Read(regs.semaphore_address.SemaphoreAddress()); // TODO(kemathe73) figure out how to do the acquire_timeout regs.acquire_mode = false; regs.acquire_source = false; @@ -138,13 +127,13 @@ void Puller::ProcessSemaphoreAcquire() { } /// Calls a GPU puller method. -void Puller::CallPullerMethod(const MethodCall& method_call) { +void Puller::CallPullerMethod(DmaPusher& dma_pusher, const MethodCall& method_call) { regs.reg_array[method_call.method] = method_call.argument; const auto method = static_cast(method_call.method); switch (method) { case BufferMethods::BindObject: { - ProcessBindMethod(method_call); + ProcessBindMethod(dma_pusher, method_call); break; } case BufferMethods::Nop: @@ -155,16 +144,16 @@ void Puller::CallPullerMethod(const MethodCall& method_call) { case BufferMethods::WrcacheFlush: break; case BufferMethods::RefCnt: - rasterizer->SignalReference(); + dma_pusher.rasterizer->SignalReference(); break; case BufferMethods::SyncpointOperation: - ProcessFenceActionMethod(); + ProcessFenceActionMethod(dma_pusher); break; case BufferMethods::WaitForIdle: - rasterizer->WaitForIdle(); + dma_pusher.rasterizer->WaitForIdle(); break; case BufferMethods::SemaphoreOperation: { - ProcessSemaphoreTriggerMethod(); + ProcessSemaphoreTriggerMethod(dma_pusher); break; } case BufferMethods::NonStallInterrupt: { @@ -177,7 +166,7 @@ void Puller::CallPullerMethod(const MethodCall& method_call) { } case BufferMethods::MemOpB: { // Implement this better. - rasterizer->InvalidateGPUCache(); + dma_pusher.rasterizer->InvalidateGPUCache(); break; } case BufferMethods::MemOpC: @@ -186,11 +175,11 @@ void Puller::CallPullerMethod(const MethodCall& method_call) { break; } case BufferMethods::SemaphoreAcquire: { - ProcessSemaphoreAcquire(); + ProcessSemaphoreAcquire(dma_pusher); break; } case BufferMethods::SemaphoreRelease: { - ProcessSemaphoreRelease(); + ProcessSemaphoreRelease(dma_pusher); break; } case BufferMethods::Yield: { @@ -205,27 +194,26 @@ void Puller::CallPullerMethod(const MethodCall& method_call) { } /// Calls a GPU engine method. -void Puller::CallEngineMethod(const MethodCall& method_call) { +void Puller::CallEngineMethod(DmaPusher& dma_pusher, const MethodCall& method_call) { const EngineID engine = bound_engines[method_call.subchannel]; - switch (engine) { case EngineID::FERMI_TWOD_A: - channel_state.fermi_2d->CallMethod(method_call.method, method_call.argument, method_call.IsLastCall()); + dma_pusher.channel_state.fermi_2d->CallMethod(method_call.method, method_call.argument, method_call.IsLastCall()); break; case EngineID::MAXWELL_B: - channel_state.maxwell_3d->CallMethod(method_call.method, method_call.argument, method_call.IsLastCall()); + dma_pusher.channel_state.maxwell_3d->CallMethod(method_call.method, method_call.argument, method_call.IsLastCall()); break; case EngineID::KEPLER_COMPUTE_B: - channel_state.kepler_compute->CallMethod(method_call.method, method_call.argument, method_call.IsLastCall()); + dma_pusher.channel_state.kepler_compute->CallMethod(method_call.method, method_call.argument, method_call.IsLastCall()); break; case EngineID::MAXWELL_DMA_COPY_A: - channel_state.maxwell_dma->CallMethod(method_call.method, method_call.argument, method_call.IsLastCall()); + dma_pusher.channel_state.maxwell_dma->CallMethod(method_call.method, method_call.argument, method_call.IsLastCall()); break; case EngineID::KEPLER_INLINE_TO_MEMORY_B: - channel_state.kepler_memory->CallMethod(method_call.method, method_call.argument, method_call.IsLastCall()); + dma_pusher.channel_state.kepler_memory->CallMethod(method_call.method, method_call.argument, method_call.IsLastCall()); break; case EngineID::NV01_TIMER: - channel_state.nv01_timer->CallMethod(method_call.method, method_call.argument, method_call.IsLastCall()); + dma_pusher.channel_state.nv01_timer->CallMethod(method_call.method, method_call.argument, method_call.IsLastCall()); break; default: UNIMPLEMENTED_MSG("Unimplemented engine"); @@ -234,28 +222,26 @@ void Puller::CallEngineMethod(const MethodCall& method_call) { } /// Calls a GPU engine multivalue method. -void Puller::CallEngineMultiMethod(u32 method, u32 subchannel, const u32* base_start, u32 amount, - u32 methods_pending) { +void Puller::CallEngineMultiMethod(DmaPusher& dma_pusher, u32 method, u32 subchannel, const u32* base_start, u32 amount, u32 methods_pending) { const EngineID engine = bound_engines[subchannel]; - switch (engine) { case EngineID::FERMI_TWOD_A: - channel_state.fermi_2d->CallMultiMethod(method, base_start, amount, methods_pending); + dma_pusher.channel_state.fermi_2d->CallMultiMethod(method, base_start, amount, methods_pending); break; case EngineID::MAXWELL_B: - channel_state.maxwell_3d->CallMultiMethod(method, base_start, amount, methods_pending); + dma_pusher.channel_state.maxwell_3d->CallMultiMethod(method, base_start, amount, methods_pending); break; case EngineID::KEPLER_COMPUTE_B: - channel_state.kepler_compute->CallMultiMethod(method, base_start, amount, methods_pending); + dma_pusher.channel_state.kepler_compute->CallMultiMethod(method, base_start, amount, methods_pending); break; case EngineID::MAXWELL_DMA_COPY_A: - channel_state.maxwell_dma->CallMultiMethod(method, base_start, amount, methods_pending); + dma_pusher.channel_state.maxwell_dma->CallMultiMethod(method, base_start, amount, methods_pending); break; case EngineID::KEPLER_INLINE_TO_MEMORY_B: - channel_state.kepler_memory->CallMultiMethod(method, base_start, amount, methods_pending); + dma_pusher.channel_state.kepler_memory->CallMultiMethod(method, base_start, amount, methods_pending); break; case EngineID::NV01_TIMER: - channel_state.nv01_timer->CallMultiMethod(method, base_start, amount, methods_pending); + dma_pusher.channel_state.nv01_timer->CallMultiMethod(method, base_start, amount, methods_pending); break; default: UNIMPLEMENTED_MSG("Unimplemented engine"); @@ -264,31 +250,26 @@ void Puller::CallEngineMultiMethod(u32 method, u32 subchannel, const u32* base_s } /// Calls a GPU method. -void Puller::CallMethod(const MethodCall& method_call) { - LOG_TRACE(HW_GPU, "Processing method {:08X} on subchannel {}", method_call.method, - method_call.subchannel); - +void Puller::CallMethod(DmaPusher& dma_pusher, const MethodCall& method_call) { + LOG_TRACE(HW_GPU, "Processing method {:08X} on subchannel {}", method_call.method, method_call.subchannel); ASSERT(method_call.subchannel < bound_engines.size()); - if (ExecuteMethodOnEngine(method_call.method)) { - CallEngineMethod(method_call); + if (ExecuteMethodOnEngine(dma_pusher, method_call.method)) { + CallEngineMethod(dma_pusher, method_call); } else { - CallPullerMethod(method_call); + CallPullerMethod(dma_pusher, method_call); } } /// Calls a GPU multivalue method. -void Puller::CallMultiMethod(u32 method, u32 subchannel, const u32* base_start, u32 amount, - u32 methods_pending) { +void Puller::CallMultiMethod(DmaPusher& dma_pusher, u32 method, u32 subchannel, const u32* base_start, u32 amount, u32 methods_pending) { LOG_TRACE(HW_GPU, "Processing method {:08X} on subchannel {}", method, subchannel); - ASSERT(subchannel < bound_engines.size()); - - if (ExecuteMethodOnEngine(method)) { - CallEngineMultiMethod(method, subchannel, base_start, amount, methods_pending); + if (ExecuteMethodOnEngine(dma_pusher, method)) { + CallEngineMultiMethod(dma_pusher, method, subchannel, base_start, amount, methods_pending); } else { for (u32 i = 0; i < amount; i++) { - CallPullerMethod(MethodCall{ + CallPullerMethod(dma_pusher, MethodCall{ method, base_start[i], subchannel, @@ -298,13 +279,9 @@ void Puller::CallMultiMethod(u32 method, u32 subchannel, const u32* base_start, } } -void Puller::BindRasterizer(VideoCore::RasterizerInterface* rasterizer_) { - rasterizer = rasterizer_; -} - /// Determines where the method should be executed. -[[nodiscard]] bool Puller::ExecuteMethodOnEngine(u32 method) { - const auto buffer_method = static_cast(method); +[[nodiscard]] bool Puller::ExecuteMethodOnEngine(DmaPusher& dma_pusher, u32 method) { + const auto buffer_method = BufferMethods(method); return buffer_method >= BufferMethods::NonPullerMethods; } diff --git a/src/video_core/engines/puller.h b/src/video_core/engines/puller.h index fe5102e3ed..e8994f5640 100644 --- a/src/video_core/engines/puller.h +++ b/src/video_core/engines/puller.h @@ -70,32 +70,13 @@ public: BitField<8, 24, u32> syncpoint_id; }; - explicit Puller(GPU& gpu_, MemoryManager& memory_manager_, DmaPusher& dma_pusher, - Control::ChannelState& channel_state); - ~Puller(); - - void CallMethod(const MethodCall& method_call); - - void CallMultiMethod(u32 method, u32 subchannel, const u32* base_start, u32 amount, - u32 methods_pending); - - void BindRasterizer(VideoCore::RasterizerInterface* rasterizer); - - void CallPullerMethod(const MethodCall& method_call); - - void CallEngineMethod(const MethodCall& method_call); - - void CallEngineMultiMethod(u32 method, u32 subchannel, const u32* base_start, u32 amount, - u32 methods_pending); - + void CallMethod(DmaPusher& dma_pusher, const MethodCall& method_call); + void CallMultiMethod(DmaPusher& dma_pusher, u32 method, u32 subchannel, const u32* base_start, u32 amount, u32 methods_pending); + void BindRasterizer(DmaPusher& dma_pusher, VideoCore::RasterizerInterface* rasterizer); + void CallPullerMethod(DmaPusher& dma_pusher, const MethodCall& method_call); + void CallEngineMethod(DmaPusher& dma_pusher, const MethodCall& method_call); + void CallEngineMultiMethod(DmaPusher& dma_pusher, u32 method, u32 subchannel, const u32* base_start, u32 amount, u32 methods_pending); private: - Tegra::GPU& gpu; - - MemoryManager& memory_manager; - DmaPusher& dma_pusher; - Control::ChannelState& channel_state; - VideoCore::RasterizerInterface* rasterizer = nullptr; - static constexpr std::size_t NUM_REGS = 0x800; struct Regs { static constexpr size_t NUM_REGS = 0x40; @@ -139,12 +120,12 @@ private: }; } regs{}; - void ProcessBindMethod(const MethodCall& method_call); - void ProcessFenceActionMethod(); - void ProcessSemaphoreAcquire(); - void ProcessSemaphoreRelease(); - void ProcessSemaphoreTriggerMethod(); - [[nodiscard]] bool ExecuteMethodOnEngine(u32 method); + void ProcessBindMethod(DmaPusher& dma_pusher, const MethodCall& method_call); + void ProcessFenceActionMethod(DmaPusher& dma_pusher); + void ProcessSemaphoreAcquire(DmaPusher& dma_pusher); + void ProcessSemaphoreRelease(DmaPusher& dma_pusher); + void ProcessSemaphoreTriggerMethod(DmaPusher& dma_pusher); + [[nodiscard]] bool ExecuteMethodOnEngine(DmaPusher& dma_pusher, u32 method); /// Mapping of command subchannels to their bound engine ids std::array bound_engines{}; @@ -157,8 +138,7 @@ private: }; #define ASSERT_REG_POSITION(field_name, position) \ - static_assert(offsetof(Regs, field_name) == position * 4, \ - "Field " #field_name " has invalid position") + static_assert(offsetof(Regs, field_name) == position * 4, "Field " #field_name " has invalid position") ASSERT_REG_POSITION(semaphore_address, 0x4); ASSERT_REG_POSITION(semaphore_sequence, 0x6); diff --git a/src/video_core/gpu.cpp b/src/video_core/gpu.cpp index 5f4054212f..44dbb93c3d 100644 --- a/src/video_core/gpu.cpp +++ b/src/video_core/gpu.cpp @@ -40,30 +40,32 @@ namespace Tegra { struct GPU::Impl { - explicit Impl(GPU& gpu_, Core::System& system_, bool is_async_, bool use_nvdec_) - : gpu{gpu_}, system{system_}, host1x{system.Host1x()}, use_nvdec{use_nvdec_}, - shader_notify{std::make_unique()}, is_async{is_async_}, - gpu_thread{system_, is_async_}, scheduler{std::make_unique(gpu)} {} + explicit Impl(Core::System& system_, bool is_async_, bool use_nvdec_) + : system{system_} + , use_nvdec{use_nvdec_} + , shader_notify() + , is_async{is_async_} + , gpu_thread{system_, is_async_} + , scheduler(system_.GPU()) + {} ~Impl() = default; std::shared_ptr CreateChannel(s32 channel_id) { auto channel_state = std::make_shared(channel_id); channels.emplace(channel_id, channel_state); - scheduler->DeclareChannel(channel_state); + scheduler.DeclareChannel(channel_state); return channel_state; } void BindChannel(s32 channel_id) { - if (bound_channel == channel_id) { - return; + if (bound_channel != channel_id) { + auto it = channels.find(channel_id); + ASSERT(it != channels.end()); + bound_channel = channel_id; + current_channel = it->second.get(); + renderer->ReadRasterizer()->BindChannel(*current_channel); } - auto it = channels.find(channel_id); - ASSERT(it != channels.end()); - bound_channel = channel_id; - current_channel = it->second.get(); - - rasterizer->BindChannel(*current_channel); } std::shared_ptr AllocateChannel() { @@ -71,13 +73,13 @@ struct GPU::Impl { } void InitChannel(Control::ChannelState& to_init, u64 program_id) { - to_init.Init(system, gpu, program_id); - to_init.BindRasterizer(rasterizer); - rasterizer->InitializeChannel(to_init); + to_init.Init(system, program_id); + to_init.BindRasterizer(renderer->ReadRasterizer()); + renderer->ReadRasterizer()->InitializeChannel(to_init); } void InitAddressSpace(Tegra::MemoryManager& memory_manager) { - memory_manager.BindRasterizer(rasterizer); + memory_manager.BindRasterizer(renderer->ReadRasterizer()); } void ReleaseChannel(Control::ChannelState& to_release) { @@ -87,26 +89,26 @@ struct GPU::Impl { /// Binds a renderer to the GPU. void BindRenderer(std::unique_ptr renderer_) { renderer = std::move(renderer_); - rasterizer = renderer->ReadRasterizer(); - host1x.MemoryManager().BindInterface(rasterizer); - host1x.gmmu_manager.BindRasterizer(rasterizer); + system.Host1x().MemoryManager().BindInterface(renderer->ReadRasterizer()); + system.Host1x().GMMU().BindRasterizer(renderer->ReadRasterizer()); } /// Flush all current written commands into the host GPU for execution. void FlushCommands() { - rasterizer->FlushCommands(); + renderer->ReadRasterizer()->FlushCommands(); } /// Synchronizes CPU writes with Host GPU memory. void InvalidateGPUCache() { - std::function callback_writes( - [this](PAddr address, size_t size) { rasterizer->OnCacheInvalidation(address, size); }); + std::function callback_writes([this](PAddr address, size_t size) { + renderer->ReadRasterizer()->OnCacheInvalidation(address, size); + }); system.GatherGPUDirtyMemory(callback_writes); } /// Signal the ending of command list. void OnCommandListEnd() { - rasterizer->ReleaseFences(false); + renderer->ReadRasterizer()->ReleaseFences(false); Settings::UpdateGPUAccuracy(); } @@ -143,62 +145,6 @@ struct GPU::Impl { } } - /// Returns a reference to the Maxwell3D GPU engine. - [[nodiscard]] Engines::Maxwell3D& Maxwell3D() { - ASSERT(current_channel); - return *current_channel->maxwell_3d; - } - - /// Returns a const reference to the Maxwell3D GPU engine. - [[nodiscard]] const Engines::Maxwell3D& Maxwell3D() const { - ASSERT(current_channel); - return *current_channel->maxwell_3d; - } - - /// Returns a reference to the KeplerCompute GPU engine. - [[nodiscard]] Engines::KeplerCompute& KeplerCompute() { - ASSERT(current_channel); - return *current_channel->kepler_compute; - } - - /// Returns a reference to the KeplerCompute GPU engine. - [[nodiscard]] const Engines::KeplerCompute& KeplerCompute() const { - ASSERT(current_channel); - return *current_channel->kepler_compute; - } - - /// Returns a reference to the GPU DMA pusher. - [[nodiscard]] Tegra::DmaPusher& DmaPusher() { - ASSERT(current_channel); - return *current_channel->dma_pusher; - } - - /// Returns a const reference to the GPU DMA pusher. - [[nodiscard]] const Tegra::DmaPusher& DmaPusher() const { - ASSERT(current_channel); - return *current_channel->dma_pusher; - } - - /// Returns a reference to the underlying renderer. - [[nodiscard]] VideoCore::RendererBase& Renderer() { - return *renderer; - } - - /// Returns a const reference to the underlying renderer. - [[nodiscard]] const VideoCore::RendererBase& Renderer() const { - return *renderer; - } - - /// Returns a reference to the shader notifier. - [[nodiscard]] VideoCore::ShaderNotify& ShaderNotify() { - return *shader_notify; - } - - /// Returns a const reference to the shader notifier. - [[nodiscard]] const VideoCore::ShaderNotify& ShaderNotify() const { - return *shader_notify; - } - [[nodiscard]] u64 GetTicks() const { u64 gpu_tick = system.CoreTiming().GetGPUTicks(); Settings::GpuOverclock overclock = Settings::values.fast_gpu_time.GetValue(); @@ -210,14 +156,6 @@ struct GPU::Impl { return gpu_tick; } - [[nodiscard]] bool IsAsync() const { - return is_async; - } - - [[nodiscard]] bool UseNvdec() const { - return use_nvdec; - } - void RendererFrameEndNotify() { system.GetPerfStats().EndGameFrame(); } @@ -227,7 +165,7 @@ struct GPU::Impl { /// core timing events. void Start() { Settings::UpdateGPUAccuracy(); - gpu_thread.StartThread(*renderer, renderer->Context(), *scheduler); + gpu_thread.StartThread(*renderer, renderer->Context(), scheduler); } void NotifyShutdown() { @@ -260,14 +198,13 @@ struct GPU::Impl { } VideoCore::RasterizerDownloadArea OnCPURead(DAddr addr, u64 size) { - auto raster_area = rasterizer->GetFlushArea(addr, size); + auto raster_area = renderer->ReadRasterizer()->GetFlushArea(addr, size); if (raster_area.preemtive) { return raster_area; } raster_area.preemtive = true; const u64 fence = RequestSyncOperation([this, &raster_area]() { - rasterizer->FlushRegion(raster_area.start_address, - raster_area.end_address - raster_area.start_address); + renderer->ReadRasterizer()->FlushRegion(raster_area.start_address, raster_area.end_address - raster_area.start_address); }); gpu_thread.TickGPU(); WaitForSyncOperation(fence); @@ -280,7 +217,7 @@ struct GPU::Impl { } bool OnCPUWrite(DAddr addr, u64 size) { - return rasterizer->OnCPUWrite(addr, size); + return renderer->ReadRasterizer()->OnCPUWrite(addr, size); } /// Notify rasterizer that any caches of the specified region should be flushed and invalidated @@ -305,7 +242,7 @@ struct GPU::Impl { } const auto wait_fence = RequestSyncOperation([this, current_request_counter, &layers, &fences, num_fences] { - auto& syncpoint_manager = host1x.GetSyncpointManager(); + auto& syncpoint_manager = system.Host1x().GetSyncpointManager(); if (num_fences == 0) { renderer->Composite(layers); } @@ -338,17 +275,14 @@ struct GPU::Impl { return out; } - GPU& gpu; Core::System& system; - Host1x::Host1x& host1x; std::unique_ptr renderer; - VideoCore::RasterizerInterface* rasterizer = nullptr; const bool use_nvdec; s32 new_channel_id{1}; /// Shader build notifier - std::unique_ptr shader_notify; + VideoCore::ShaderNotify shader_notify; /// When true, we are about to shut down emulation session, so terminate outstanding tasks std::atomic_bool shutting_down{}; @@ -372,7 +306,7 @@ struct GPU::Impl { VideoCommon::GPUThread::ThreadManager gpu_thread; std::unique_ptr cpu_context; - std::unique_ptr scheduler; + Tegra::Control::Scheduler scheduler; ankerl::unordered_dense::map> channels; Tegra::Control::ChannelState* current_channel; s32 bound_channel{-1}; @@ -383,7 +317,8 @@ struct GPU::Impl { }; GPU::GPU(Core::System& system, bool is_async, bool use_nvdec) - : impl{std::make_unique(*this, system, is_async, use_nvdec)} {} + : impl{std::make_unique(system, is_async, use_nvdec)} +{} GPU::~GPU() = default; @@ -424,8 +359,9 @@ void GPU::OnCommandListEnd() { } u64 GPU::RequestFlush(DAddr addr, std::size_t size) { - return impl->RequestSyncOperation( - [this, addr, size]() { impl->rasterizer->FlushRegion(addr, size); }); + return impl->RequestSyncOperation([this, addr, size]() { + impl->renderer->ReadRasterizer()->FlushRegion(addr, size); + }); } u64 GPU::CurrentSyncRequestFence() const { @@ -442,52 +378,52 @@ void GPU::TickWork() { /// Gets a mutable reference to the Host1x interface Host1x::Host1x& GPU::Host1x() { - return impl->host1x; + return impl->system.Host1x(); } /// Gets an immutable reference to the Host1x interface. const Host1x::Host1x& GPU::Host1x() const { - return impl->host1x; + return impl->system.Host1x(); } Engines::Maxwell3D& GPU::Maxwell3D() { - return impl->Maxwell3D(); + return *impl->current_channel->maxwell_3d; } const Engines::Maxwell3D& GPU::Maxwell3D() const { - return impl->Maxwell3D(); + return *impl->current_channel->maxwell_3d; } Engines::KeplerCompute& GPU::KeplerCompute() { - return impl->KeplerCompute(); + return *impl->current_channel->kepler_compute; } const Engines::KeplerCompute& GPU::KeplerCompute() const { - return impl->KeplerCompute(); + return *impl->current_channel->kepler_compute; } Tegra::DmaPusher& GPU::DmaPusher() { - return impl->DmaPusher(); + return *impl->current_channel->dma_pusher; } const Tegra::DmaPusher& GPU::DmaPusher() const { - return impl->DmaPusher(); + return *impl->current_channel->dma_pusher; } VideoCore::RendererBase& GPU::Renderer() { - return impl->Renderer(); + return *impl->renderer; } const VideoCore::RendererBase& GPU::Renderer() const { - return impl->Renderer(); + return *impl->renderer; } VideoCore::ShaderNotify& GPU::ShaderNotify() { - return impl->ShaderNotify(); + return impl->shader_notify; } const VideoCore::ShaderNotify& GPU::ShaderNotify() const { - return impl->ShaderNotify(); + return impl->shader_notify; } void GPU::RequestComposite(std::vector&& layers, @@ -504,11 +440,11 @@ u64 GPU::GetTicks() const { } bool GPU::IsAsync() const { - return impl->IsAsync(); + return impl->is_async; } bool GPU::UseNvdec() const { - return impl->UseNvdec(); + return impl->use_nvdec; } void GPU::RendererFrameEndNotify() { From 62e69e4ecddf2622cfb4e0d24756c83f4216fb1d Mon Sep 17 00:00:00 2001 From: lizzie Date: Thu, 30 Apr 2026 16:55:49 +0000 Subject: [PATCH 3/9] fx --- src/video_core/dma_pusher.cpp | 2 +- src/video_core/dma_pusher.h | 2 +- src/video_core/gpu.cpp | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/video_core/dma_pusher.cpp b/src/video_core/dma_pusher.cpp index 5f6b34836c..109d46dfe7 100644 --- a/src/video_core/dma_pusher.cpp +++ b/src/video_core/dma_pusher.cpp @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project +// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project // SPDX-License-Identifier: GPL-3.0-or-later // SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project diff --git a/src/video_core/dma_pusher.h b/src/video_core/dma_pusher.h index d8ae737a46..62af628511 100644 --- a/src/video_core/dma_pusher.h +++ b/src/video_core/dma_pusher.h @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project +// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project // SPDX-License-Identifier: GPL-3.0-or-later // SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project diff --git a/src/video_core/gpu.cpp b/src/video_core/gpu.cpp index 44dbb93c3d..675e818625 100644 --- a/src/video_core/gpu.cpp +++ b/src/video_core/gpu.cpp @@ -89,8 +89,8 @@ struct GPU::Impl { /// Binds a renderer to the GPU. void BindRenderer(std::unique_ptr renderer_) { renderer = std::move(renderer_); - system.Host1x().MemoryManager().BindInterface(renderer->ReadRasterizer()); - system.Host1x().GMMU().BindRasterizer(renderer->ReadRasterizer()); + system.Host1x().memory_manager.BindInterface(renderer->ReadRasterizer()); + system.Host1x().gmmu_manager.BindRasterizer(renderer->ReadRasterizer()); } /// Flush all current written commands into the host GPU for execution. From 557b61e214991f62bce133f99ba5f04a068fdcde Mon Sep 17 00:00:00 2001 From: lizzie Date: Thu, 7 May 2026 18:13:59 +0000 Subject: [PATCH 4/9] fix strerror_r on managarm --- src/common/error.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/error.cpp b/src/common/error.cpp index 1b2009db71..17d2f452bf 100644 --- a/src/common/error.cpp +++ b/src/common/error.cpp @@ -30,7 +30,7 @@ std::string NativeErrorToString(int e) { return ret; #else char err_str[255]; -#if defined(ANDROID) || \ +#if defined(__managarm__) || defined(ANDROID) || \ (defined(__GLIBC__) && (_GNU_SOURCE || (_POSIX_C_SOURCE < 200112L && _XOPEN_SOURCE < 600))) // Thread safe (GNU-specific) const char* str = strerror_r(e, err_str, sizeof(err_str)); From d4297a1106b92d0a0c6f7b45d4990b7086607c07 Mon Sep 17 00:00:00 2001 From: lizzie Date: Thu, 7 May 2026 19:29:37 +0000 Subject: [PATCH 5/9] manaleg fixes for dynarmic common context --- externals/ffmpeg/CMakeLists.txt | 3 ++- src/dynarmic/src/dynarmic/common/context.h | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/externals/ffmpeg/CMakeLists.txt b/externals/ffmpeg/CMakeLists.txt index 2d85876ad2..7c53af18c2 100644 --- a/externals/ffmpeg/CMakeLists.txt +++ b/externals/ffmpeg/CMakeLists.txt @@ -168,7 +168,8 @@ if (PLATFORM_PS4) --extra-libs="${FFmpeg_CROSS_COMPILE_LIBS}" ) elseif (PLATFORM_MANAGARM) - # Required for proper stuff + # Required for proper stuff, otherwise truncf and cosf won't get detected + list(APPEND FFmpeg_CROSS_COMPILE_LIBS -lm) list(APPEND FFmpeg_CROSS_COMPILE_FLAGS --disable-pthreads --extra-libs="${FFmpeg_CROSS_COMPILE_LIBS}" diff --git a/src/dynarmic/src/dynarmic/common/context.h b/src/dynarmic/src/dynarmic/common/context.h index e849c9861b..61e5379300 100644 --- a/src/dynarmic/src/dynarmic/common/context.h +++ b/src/dynarmic/src/dynarmic/common/context.h @@ -121,6 +121,9 @@ # elif defined(__DragonFly__) # define CTX_RIP (mctx.mc_rip) # define CTX_RSP (mctx.mc_rsp) +# elif defined(__managarm__) +# define CTX_RIP (mctx.__pollution(gregs)[REG_RIP]) +# define CTX_RSP (mctx.__pollution(gregs)[REG_RSP]) # else # error "unknown platform" # endif From 1c57f2317e3e0a6f0f375176a8e4b091998928e1 Mon Sep 17 00:00:00 2001 From: lizzie Date: Sat, 16 May 2026 15:21:40 +0000 Subject: [PATCH 6/9] script not needed, use xbps --- .ci/managarm/build.sh | 113 ------------------------------------------ src/common/error.cpp | 3 ++ 2 files changed, 3 insertions(+), 113 deletions(-) delete mode 100755 .ci/managarm/build.sh diff --git a/.ci/managarm/build.sh b/.ci/managarm/build.sh deleted file mode 100755 index a5a6e9a9a9..0000000000 --- a/.ci/managarm/build.sh +++ /dev/null @@ -1,113 +0,0 @@ -#!/usr/local/bin/bash -ex - -# SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project -# SPDX-License-Identifier: GPL-3.0-or-later - -WORK_PATH="$PWD" - -export CFLAGS="-U__FreeBSD__ -U__MMX__ -U__SSE__ -U__SSE2__ -U__SSE3__ -D_DEFAULT_SOURCE=1 -D__managarm__=1 -I$MANAGARM_ROOTFS/usr/include -I$MANAGARM_ROOTFS/usr/share/freestnd-cxx-hdrs/x86_64/include -I$MANAGARM_ROOTFS/usr/share/freestnd-c-hdrs/x86_64/include" -export CXXFLAGS="-U__FreeBSD__ -U__MMX__ -U__SSE__ -U__SSE2__ -U__SSE3__ -D_DEFAULT_SOURCE=1 -D__managarm__=1 -I$MANAGARM_ROOTFS/usr/include/c++/14.2.0 -I$MANAGARM_ROOTFS/usr/include -I$MANAGARM_ROOTFS/usr/include/c++/14.2.0/x86_64-managarm -I$MANAGARM_ROOTFS/usr/share/freestnd-c-hdrs/x86_64/include" -export CC=clang -export CXX=clang++ -export LD=ld.lld - -[ -z ${MANAGARM_ROOTFS+x} ] && exit - -[ -f "managarm-toolchain.cmake" ] || cat << EOF >"managarm-toolchain.cmake" -set(CMAKE_SYSROOT "$MANAGARM_ROOTFS/usr") -set(CMAKE_STAGING_PREFIX "$MANAGARM_ROOTFS/usr") -set(CMAKE_SYSTEM_NAME "managarm") -set(UNIX TRUE) - -set(CMAKE_C_FLAGS "$CFLAGS") -set(CMAKE_CXX_FLAGS "$CXXFLAGS") - -set(CMAKE_EXE_LINKER_FLAGS "-L$MANAGARM_ROOTFS/usr/lib64 -L$MANAGARM_ROOTFS/usr/lib -L$MANAGARM_ROOTFS/usr/lib/gcc/x86_64-managarm/14.2.0") -set(CMAKE_C_LINK_FLAGS "-L$MANAGARM_ROOTFS/usr/lib64 -L$MANAGARM_ROOTFS/usr/lib -L$MANAGARM_ROOTFS/usr/lib/gcc/x86_64-managarm/14.2.0") -set(CMAKE_CXX_LINK_FLAGS "-L$MANAGARM_ROOTFS/usr/lib64 -L$MANAGARM_ROOTFS/usr/lib -L$MANAGARM_ROOTFS/usr/lib/gcc/x86_64-managarm/14.2.0") - -set(CMAKE_C_COMPILER "$CC") -set(CMAKE_CXX_COMPILER "$CXX") -set(CMAKE_LINKER "$LD") -set(CMAKE_C_LINK_EXECUTABLE " -o -lc -lgcc ") -set(CMAKE_CXX_LINK_EXECUTABLE " -o -lc -lstdc++ -lgcc ") - -set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) -set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) -set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) -set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) - -# TODO: Why does cmake not set this? -set(CMAKE_SIZEOF_VOID_P 8) -EOF - -[ -z ${NPROC+x} ] && NPROC=$(nproc || 1) - -build_openssl() { - [ -d "$WORK_PATH/openssl" ] || git clone --depth=1 https://github.com/openssl/openssl "$WORK_PATH/openssl" - cd "$WORK_PATH/openssl" - [ -f Makefile ] || ./Configure -ffreestanding \ - -L$MANAGARM_ROOTFS/usr/lib -lc \ - -I$MANAGARM_ROOTFS/usr/include \ - no-threads no-shared no-afalgeng no-async no-capieng no-cmp no-cms no-comp no-ct \ - no-docs no-dgram no-dso no-dynamic-engine no-engine no-filenames no-gost \ - no-http no-legacy no-module no-nextprotoneg no-ocsp no-padlockeng no-quic \ - no-srp no-srtp no-ssl-trace no-static-engine no-tests no-thread-pool no-ts \ - no-ui-console no-uplink no-ssl3-method no-tls1-method no-tls1_1-method \ - no-dtls1-method no-dtls1_2-method no-argon2 no-bf no-blake2 no-cast \ - no-dsa no-idea no-md4 no-mdc2 no-ocb no-rc2 no-rc4 no-rmd160 no-scrypt \ - no-siphash no-siv no-sm2 no-sm3 no-sm4 no-whirlpool no-apps \ - --prefix=$MANAGARM_ROOTFS/usr BSD-generic64 - gmake -j8 - sudo gmake install -j8 - cd "$WORK_PATH" -} -[ -f "$MANAGARM_ROOTFS/usr/lib/libssl.a" ] || build_openssl - -# Normally a platform has a package manager -# but managarm has one thats so underdeveloped -# we may as well do it ourselves -export EXTRA_CMAKE_FLAGS=("${EXTRA_CMAKE_FLAGS[@]}" $@) -cmake -S . -B build -G "Unix Makefiles" \ - -DCMAKE_TOOLCHAIN_FILE="managarm-toolchain.cmake" \ - -DENABLE_QT_TRANSLATION=OFF \ - -DENABLE_CUBEB=OFF \ - -DCMAKE_BUILD_TYPE=RelWithDebInfo \ - -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ - -DCMAKE_CXX_FLAGS="$ARCH_FLAGS -pipe" \ - -DCMAKE_C_FLAGS="$ARCH_FLAGS -pipe" \ - -DENABLE_SDL2=ON \ - -DENABLE_LIBUSB=OFF \ - -DENABLE_UPDATE_CHECKER=OFF \ - -DENABLE_QT=OFF \ - -DENABLE_OPENGL=OFF \ - -DENABLE_OPENSSL=OFF \ - -DENABLE_WEB_SERVICE=OFF \ - -DUSE_DISCORD_PRESENCE=OFF \ - -DCPMUTIL_FORCE_BUNDLED=ON \ - -DOPENSSL_ROOT_DIR="$MANAGARM_ROOTFS/usr" \ - -DOPENSSL_SSL_LIBRARY="$MANAGARM_ROOTFS/usr/lib/libssl.a" \ - -DOPENSSL_CRYPTO_LIBRARY="$MANAGARM_ROOTFS/usr/lib/libcrypto.a" \ - -DOPENSSL_INCLUDE_DIR="$MANAGARM_ROOTFS/usr/include/openssl" \ - -DYUZU_USE_EXTERNAL_FFMPEG=ON \ - -DYUZU_USE_CPM=ON \ - -DDYNARMIC_ENABLE_NO_EXECUTE_SUPPORT=OFF \ - -DDYNARMIC_TESTS=ON \ - -DYUZU_TESTS=ON \ - -DYUZU_USE_EXTERNAL_SDL2=ON \ - -DHAVE_SDL_THREADS=ON \ - -DSDL_THREADS=ON \ - -DSDL_PTHREADS=ON \ - -DSDL_THREAD_PTHREAD=ON \ - -DSDL_PTHREADS_SEM=OFF \ - -DSDL_ALTIVEC=OFF \ - -DSDL_DISKAUDIO=OFF \ - -DSDL_DIRECTFB=ON \ - -DSDL_OPENGL=ON \ - -DSDL_OPENGLES=ON \ - -DSDL_PTHREADS=ON \ - -DSDL_PTHREADS_SEM=OFF \ - -DSDL_STATIC=ON \ - "${EXTRA_CMAKE_FLAGS[@]}" || exit - -cmake --build build -t yuzu-cmd -- -j$NPROC diff --git a/src/common/error.cpp b/src/common/error.cpp index 17d2f452bf..2c0f17281f 100644 --- a/src/common/error.cpp +++ b/src/common/error.cpp @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + // SPDX-FileCopyrightText: 2013 Dolphin Emulator Project // SPDX-FileCopyrightText: 2014 Citra Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later From b9b2fb02b534a7f9683cdd02cc2df9825cfa0ba6 Mon Sep 17 00:00:00 2001 From: lizzie Date: Sat, 16 May 2026 15:22:59 +0000 Subject: [PATCH 7/9] revert --- src/video_core/control/channel_state.cpp | 4 +- src/video_core/control/channel_state.h | 2 +- src/video_core/dma_pusher.cpp | 34 +++-- src/video_core/dma_pusher.h | 55 ++++---- src/video_core/engines/puller.cpp | 139 +++++++++++-------- src/video_core/engines/puller.h | 46 +++++-- src/video_core/gpu.cpp | 168 ++++++++++++++++------- 7 files changed, 283 insertions(+), 165 deletions(-) diff --git a/src/video_core/control/channel_state.cpp b/src/video_core/control/channel_state.cpp index 49e2e270b1..d07c7e2a83 100644 --- a/src/video_core/control/channel_state.cpp +++ b/src/video_core/control/channel_state.cpp @@ -19,10 +19,10 @@ namespace Tegra::Control { ChannelState::ChannelState(s32 bind_id_) : bind_id{bind_id_}, initialized{} {} -void ChannelState::Init(Core::System& system, u64 program_id_) { +void ChannelState::Init(Core::System& system, GPU& gpu, u64 program_id_) { ASSERT(memory_manager); program_id = program_id_; - dma_pusher.emplace(system, *memory_manager, *this); + dma_pusher.emplace(system, gpu, *memory_manager, *this); maxwell_3d.emplace(system, *memory_manager); fermi_2d.emplace(*memory_manager); kepler_compute.emplace(system, *memory_manager); diff --git a/src/video_core/control/channel_state.h b/src/video_core/control/channel_state.h index c72e1446e7..2984d2e09e 100644 --- a/src/video_core/control/channel_state.h +++ b/src/video_core/control/channel_state.h @@ -34,7 +34,7 @@ namespace Control { struct ChannelState { explicit ChannelState(s32 bind_id); - void Init(Core::System& system, u64 program_id); + void Init(Core::System& system, GPU& gpu, u64 program_id); void BindRasterizer(VideoCore::RasterizerInterface* rasterizer); diff --git a/src/video_core/dma_pusher.cpp b/src/video_core/dma_pusher.cpp index 109d46dfe7..3844a8e2f9 100644 --- a/src/video_core/dma_pusher.cpp +++ b/src/video_core/dma_pusher.cpp @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project +// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project // SPDX-License-Identifier: GPL-3.0-or-later // SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project @@ -12,32 +12,37 @@ #include "video_core/guest_memory.h" #include "video_core/memory_manager.h" #include "video_core/rasterizer_interface.h" +#include "video_core/texture_cache/util.h" + +#ifdef _MSC_VER +#include +#endif namespace Tegra { constexpr u32 MacroRegistersStart = 0xE00; [[maybe_unused]] constexpr u32 ComputeInline = 0x6D; -DmaPusher::DmaPusher(Core::System& system_, MemoryManager& memory_manager_, Control::ChannelState& channel_state_) - : system{system_} - , memory_manager{memory_manager_} - , channel_state{channel_state_} - , signal_sync{false} - , synced{false} -{} +DmaPusher::DmaPusher(Core::System& system_, GPU& gpu_, MemoryManager& memory_manager_, + Control::ChannelState& channel_state_) + : gpu{gpu_}, system{system_}, memory_manager{memory_manager_}, puller{gpu_, memory_manager_, + *this, channel_state_}, signal_sync{false}, synced{false} {} DmaPusher::~DmaPusher() = default; void DmaPusher::DispatchCalls() { + dma_pushbuffer_subindex = 0; + dma_state.is_last_call = true; + while (system.IsPoweredOn()) { if (!Step()) { break; } } - system.GPU().FlushCommands(); - system.GPU().OnCommandListEnd(); + gpu.FlushCommands(); + gpu.OnCommandListEnd(); } bool DmaPusher::Step() { @@ -166,9 +171,9 @@ void DmaPusher::SetState(const CommandHeader& command_header) { dma_state.method_count = command_header.method_count; } -void DmaPusher::CallMethod(u32 argument) { +void DmaPusher::CallMethod(u32 argument) const { if (dma_state.method < non_puller_methods) { - puller.CallPullerMethod(*this, Engines::Puller::MethodCall{ + puller.CallPullerMethod(Engines::Puller::MethodCall{ dma_state.method, argument, dma_state.subchannel, @@ -186,9 +191,9 @@ void DmaPusher::CallMethod(u32 argument) { } } -void DmaPusher::CallMultiMethod(const u32* base_start, u32 num_methods) { +void DmaPusher::CallMultiMethod(const u32* base_start, u32 num_methods) const { if (dma_state.method < non_puller_methods) { - puller.CallMultiMethod(*this, dma_state.method, dma_state.subchannel, base_start, num_methods, dma_state.method_count); + puller.CallMultiMethod(dma_state.method, dma_state.subchannel, base_start, num_methods, dma_state.method_count); } else { auto subchannel = subchannels[dma_state.subchannel]; subchannel->ConsumeSink(); @@ -199,6 +204,7 @@ void DmaPusher::CallMultiMethod(const u32* base_start, u32 num_methods) { void DmaPusher::BindRasterizer(VideoCore::RasterizerInterface* rasterizer_) { rasterizer = rasterizer_; + puller.BindRasterizer(rasterizer); } } // namespace Tegra diff --git a/src/video_core/dma_pusher.h b/src/video_core/dma_pusher.h index 62af628511..f850513603 100644 --- a/src/video_core/dma_pusher.h +++ b/src/video_core/dma_pusher.h @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project +// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project // SPDX-License-Identifier: GPL-3.0-or-later // SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project @@ -109,21 +109,25 @@ inline CommandHeader BuildCommandHeader(BufferMethods method, u32 arg_count, Sub struct CommandList final { CommandList() = default; explicit CommandList(std::size_t size) : command_lists(size) {} - explicit CommandList(boost::container::small_vector&& prefetch_command_list_) + explicit CommandList( + boost::container::small_vector&& prefetch_command_list_) : prefetch_command_list{std::move(prefetch_command_list_)} {} boost::container::small_vector command_lists; boost::container::small_vector prefetch_command_list; }; -/// @brief The DmaPusher class implements DMA submission to FIFOs, providing an area of memory that the -/// emulated app fills with commands and tells PFIFO to process. The pushbuffers are then assembled -/// into a "command stream" consisting of 32-bit words that make up "commands". -/// See https://envytools.readthedocs.io/en/latest/hw/fifo/dma-pusher.html#fifo-dma-pusher for -/// details on this implementation. +/** + * The DmaPusher class implements DMA submission to FIFOs, providing an area of memory that the + * emulated app fills with commands and tells PFIFO to process. The pushbuffers are then assembled + * into a "command stream" consisting of 32-bit words that make up "commands". + * See https://envytools.readthedocs.io/en/latest/hw/fifo/dma-pusher.html#fifo-dma-pusher for + * details on this implementation. + */ class DmaPusher final { public: - explicit DmaPusher(Core::System& system_, MemoryManager& memory_manager_, Control::ChannelState& channel_state_); + explicit DmaPusher(Core::System& system_, GPU& gpu_, MemoryManager& memory_manager_, + Control::ChannelState& channel_state_); ~DmaPusher(); void Push(CommandList&& entries) { @@ -132,7 +136,8 @@ public: void DispatchCalls(); - void BindSubchannel(Engines::EngineInterface* engine, u32 subchannel_id, Engines::EngineTypes engine_type) { + void BindSubchannel(Engines::EngineInterface* engine, u32 subchannel_id, + Engines::EngineTypes engine_type) { subchannels[subchannel_id] = engine; subchannel_type[subchannel_id] = engine_type; } @@ -147,11 +152,11 @@ private: void SetState(const CommandHeader& command_header); - void CallMethod(u32 argument); - void CallMultiMethod(const u32* base_start, u32 num_methods); + void CallMethod(u32 argument) const; + void CallMultiMethod(const u32* base_start, u32 num_methods) const; -public: - Common::ScratchBuffer command_headers; ///< Buffer for list of commands fetched at once + Common::ScratchBuffer + command_headers; ///< Buffer for list of commands fetched at once std::queue dma_pushbuffer; ///< Queue of command lists to be processed std::size_t dma_pushbuffer_subindex{}; ///< Index within a command list within the pushbuffer @@ -167,24 +172,24 @@ public: bool is_last_call; }; - Core::System& system; - MemoryManager& memory_manager; - Control::ChannelState& channel_state; - DmaState dma_state{}; + bool dma_increment_once{}; + + const bool ib_enable{true}; ///< IB mode enabled + std::array subchannels{}; std::array subchannel_type; - Engines::Puller puller; + GPU& gpu; + Core::System& system; + MemoryManager& memory_manager; + mutable Engines::Puller puller; + + VideoCore::RasterizerInterface* rasterizer; + bool signal_sync; + bool synced; std::mutex sync_mutex; std::condition_variable sync_cv; - - VideoCore::RasterizerInterface* rasterizer = nullptr; - - const bool ib_enable : 1 = true; ///< IB mode enabled - bool dma_increment_once : 1 = false; - bool signal_sync : 1 = false; - bool synced : 1 = false; }; } // namespace Tegra diff --git a/src/video_core/engines/puller.cpp b/src/video_core/engines/puller.cpp index b153619c16..4030f93d49 100644 --- a/src/video_core/engines/puller.cpp +++ b/src/video_core/engines/puller.cpp @@ -22,29 +22,37 @@ namespace Tegra::Engines { -void Puller::ProcessBindMethod(DmaPusher& dma_pusher, const MethodCall& method_call) { +Puller::Puller(GPU& gpu_, MemoryManager& memory_manager_, DmaPusher& dma_pusher_, + Control::ChannelState& channel_state_) + : gpu{gpu_}, memory_manager{memory_manager_}, dma_pusher{dma_pusher_}, channel_state{ + channel_state_} {} + +Puller::~Puller() = default; + +void Puller::ProcessBindMethod(const MethodCall& method_call) { // Bind the current subchannel to the desired engine id. - LOG_DEBUG(HW_GPU, "Binding subchannel {} to engine {}", method_call.subchannel, method_call.argument); + LOG_DEBUG(HW_GPU, "Binding subchannel {} to engine {}", method_call.subchannel, + method_call.argument); const auto engine_id = static_cast(method_call.argument); bound_engines[method_call.subchannel] = engine_id; switch (engine_id) { case EngineID::FERMI_TWOD_A: - dma_pusher.BindSubchannel(&*dma_pusher.channel_state.fermi_2d, method_call.subchannel, EngineTypes::Fermi2D); + dma_pusher.BindSubchannel(&*channel_state.fermi_2d, method_call.subchannel, EngineTypes::Fermi2D); break; case EngineID::MAXWELL_B: - dma_pusher.BindSubchannel(&*dma_pusher.channel_state.maxwell_3d, method_call.subchannel, EngineTypes::Maxwell3D); + dma_pusher.BindSubchannel(&*channel_state.maxwell_3d, method_call.subchannel, EngineTypes::Maxwell3D); break; case EngineID::KEPLER_COMPUTE_B: - dma_pusher.BindSubchannel(&*dma_pusher.channel_state.kepler_compute, method_call.subchannel, EngineTypes::KeplerCompute); + dma_pusher.BindSubchannel(&*channel_state.kepler_compute, method_call.subchannel, EngineTypes::KeplerCompute); break; case EngineID::MAXWELL_DMA_COPY_A: - dma_pusher.BindSubchannel(&*dma_pusher.channel_state.maxwell_dma, method_call.subchannel, EngineTypes::MaxwellDMA); + dma_pusher.BindSubchannel(&*channel_state.maxwell_dma, method_call.subchannel, EngineTypes::MaxwellDMA); break; case EngineID::KEPLER_INLINE_TO_MEMORY_B: - dma_pusher.BindSubchannel(&*dma_pusher.channel_state.kepler_memory, method_call.subchannel, EngineTypes::KeplerMemory); + dma_pusher.BindSubchannel(&*channel_state.kepler_memory, method_call.subchannel, EngineTypes::KeplerMemory); break; case EngineID::NV01_TIMER: - dma_pusher.BindSubchannel(&*dma_pusher.channel_state.nv01_timer, method_call.subchannel, EngineTypes::Nv01Timer); + dma_pusher.BindSubchannel(&*channel_state.nv01_timer, method_call.subchannel, EngineTypes::Nv01Timer); break; default: UNIMPLEMENTED_MSG("Unimplemented engine {:04X}", engine_id); @@ -52,15 +60,15 @@ void Puller::ProcessBindMethod(DmaPusher& dma_pusher, const MethodCall& method_c } } -void Puller::ProcessFenceActionMethod(DmaPusher& dma_pusher) { +void Puller::ProcessFenceActionMethod() { switch (regs.fence_action.op) { case Puller::FenceOperation::Acquire: // UNIMPLEMENTED_MSG("Channel Scheduling pending."); // WaitFence(regs.fence_action.syncpoint_id, regs.fence_value); - dma_pusher.rasterizer->ReleaseFences(); + rasterizer->ReleaseFences(); break; case Puller::FenceOperation::Increment: - dma_pusher.rasterizer->SignalSyncPoint(regs.fence_action.syncpoint_id); + rasterizer->SignalSyncPoint(regs.fence_action.syncpoint_id); break; default: UNIMPLEMENTED_MSG("Unimplemented operation {}", regs.fence_action.op.Value()); @@ -68,35 +76,37 @@ void Puller::ProcessFenceActionMethod(DmaPusher& dma_pusher) { } } -void Puller::ProcessSemaphoreTriggerMethod(DmaPusher& dma_pusher) { +void Puller::ProcessSemaphoreTriggerMethod() { const auto semaphoreOperationMask = 0xF; - const auto op = GpuSemaphoreOperation(regs.semaphore_trigger & semaphoreOperationMask); + const auto op = + static_cast(regs.semaphore_trigger & semaphoreOperationMask); if (op == GpuSemaphoreOperation::WriteLong) { const GPUVAddr sequence_address{regs.semaphore_address.SemaphoreAddress()}; const u32 payload = regs.semaphore_sequence; - dma_pusher.rasterizer->Query(sequence_address, VideoCommon::QueryType::Payload, VideoCommon::QueryPropertiesFlags::HasTimeout, payload, 0); + rasterizer->Query(sequence_address, VideoCommon::QueryType::Payload, + VideoCommon::QueryPropertiesFlags::HasTimeout, payload, 0); } else { do { - const u32 word = dma_pusher.memory_manager.Read(regs.semaphore_address.SemaphoreAddress()); + const u32 word{memory_manager.Read(regs.semaphore_address.SemaphoreAddress())}; regs.acquire_source = true; regs.acquire_value = regs.semaphore_sequence; if (op == GpuSemaphoreOperation::AcquireEqual) { regs.acquire_active = true; regs.acquire_mode = false; if (word != regs.acquire_value) { - dma_pusher.rasterizer->ReleaseFences(); + rasterizer->ReleaseFences(); continue; } } else if (op == GpuSemaphoreOperation::AcquireGequal) { regs.acquire_active = true; regs.acquire_mode = true; if (word < regs.acquire_value) { - dma_pusher.rasterizer->ReleaseFences(); + rasterizer->ReleaseFences(); continue; } } else if (op == GpuSemaphoreOperation::AcquireMask) { if (word && regs.semaphore_sequence == 0) { - dma_pusher.rasterizer->ReleaseFences(); + rasterizer->ReleaseFences(); continue; } } else { @@ -106,20 +116,21 @@ void Puller::ProcessSemaphoreTriggerMethod(DmaPusher& dma_pusher) { } } -void Puller::ProcessSemaphoreRelease(DmaPusher& dma_pusher) { +void Puller::ProcessSemaphoreRelease() { const GPUVAddr sequence_address{regs.semaphore_address.SemaphoreAddress()}; const u32 payload = regs.semaphore_release; - dma_pusher.rasterizer->Query(sequence_address, VideoCommon::QueryType::Payload, VideoCommon::QueryPropertiesFlags::IsAFence, payload, 0); + rasterizer->Query(sequence_address, VideoCommon::QueryType::Payload, + VideoCommon::QueryPropertiesFlags::IsAFence, payload, 0); } -void Puller::ProcessSemaphoreAcquire(DmaPusher& dma_pusher) { - u32 word = dma_pusher.memory_manager.Read(regs.semaphore_address.SemaphoreAddress()); +void Puller::ProcessSemaphoreAcquire() { + u32 word = memory_manager.Read(regs.semaphore_address.SemaphoreAddress()); const auto value = regs.semaphore_acquire; while (word != value) { regs.acquire_active = true; regs.acquire_value = value; - dma_pusher.rasterizer->ReleaseFences(); - word = dma_pusher.memory_manager.Read(regs.semaphore_address.SemaphoreAddress()); + rasterizer->ReleaseFences(); + word = memory_manager.Read(regs.semaphore_address.SemaphoreAddress()); // TODO(kemathe73) figure out how to do the acquire_timeout regs.acquire_mode = false; regs.acquire_source = false; @@ -127,13 +138,13 @@ void Puller::ProcessSemaphoreAcquire(DmaPusher& dma_pusher) { } /// Calls a GPU puller method. -void Puller::CallPullerMethod(DmaPusher& dma_pusher, const MethodCall& method_call) { +void Puller::CallPullerMethod(const MethodCall& method_call) { regs.reg_array[method_call.method] = method_call.argument; const auto method = static_cast(method_call.method); switch (method) { case BufferMethods::BindObject: { - ProcessBindMethod(dma_pusher, method_call); + ProcessBindMethod(method_call); break; } case BufferMethods::Nop: @@ -144,16 +155,16 @@ void Puller::CallPullerMethod(DmaPusher& dma_pusher, const MethodCall& method_ca case BufferMethods::WrcacheFlush: break; case BufferMethods::RefCnt: - dma_pusher.rasterizer->SignalReference(); + rasterizer->SignalReference(); break; case BufferMethods::SyncpointOperation: - ProcessFenceActionMethod(dma_pusher); + ProcessFenceActionMethod(); break; case BufferMethods::WaitForIdle: - dma_pusher.rasterizer->WaitForIdle(); + rasterizer->WaitForIdle(); break; case BufferMethods::SemaphoreOperation: { - ProcessSemaphoreTriggerMethod(dma_pusher); + ProcessSemaphoreTriggerMethod(); break; } case BufferMethods::NonStallInterrupt: { @@ -166,7 +177,7 @@ void Puller::CallPullerMethod(DmaPusher& dma_pusher, const MethodCall& method_ca } case BufferMethods::MemOpB: { // Implement this better. - dma_pusher.rasterizer->InvalidateGPUCache(); + rasterizer->InvalidateGPUCache(); break; } case BufferMethods::MemOpC: @@ -175,11 +186,11 @@ void Puller::CallPullerMethod(DmaPusher& dma_pusher, const MethodCall& method_ca break; } case BufferMethods::SemaphoreAcquire: { - ProcessSemaphoreAcquire(dma_pusher); + ProcessSemaphoreAcquire(); break; } case BufferMethods::SemaphoreRelease: { - ProcessSemaphoreRelease(dma_pusher); + ProcessSemaphoreRelease(); break; } case BufferMethods::Yield: { @@ -194,26 +205,27 @@ void Puller::CallPullerMethod(DmaPusher& dma_pusher, const MethodCall& method_ca } /// Calls a GPU engine method. -void Puller::CallEngineMethod(DmaPusher& dma_pusher, const MethodCall& method_call) { +void Puller::CallEngineMethod(const MethodCall& method_call) { const EngineID engine = bound_engines[method_call.subchannel]; + switch (engine) { case EngineID::FERMI_TWOD_A: - dma_pusher.channel_state.fermi_2d->CallMethod(method_call.method, method_call.argument, method_call.IsLastCall()); + channel_state.fermi_2d->CallMethod(method_call.method, method_call.argument, method_call.IsLastCall()); break; case EngineID::MAXWELL_B: - dma_pusher.channel_state.maxwell_3d->CallMethod(method_call.method, method_call.argument, method_call.IsLastCall()); + channel_state.maxwell_3d->CallMethod(method_call.method, method_call.argument, method_call.IsLastCall()); break; case EngineID::KEPLER_COMPUTE_B: - dma_pusher.channel_state.kepler_compute->CallMethod(method_call.method, method_call.argument, method_call.IsLastCall()); + channel_state.kepler_compute->CallMethod(method_call.method, method_call.argument, method_call.IsLastCall()); break; case EngineID::MAXWELL_DMA_COPY_A: - dma_pusher.channel_state.maxwell_dma->CallMethod(method_call.method, method_call.argument, method_call.IsLastCall()); + channel_state.maxwell_dma->CallMethod(method_call.method, method_call.argument, method_call.IsLastCall()); break; case EngineID::KEPLER_INLINE_TO_MEMORY_B: - dma_pusher.channel_state.kepler_memory->CallMethod(method_call.method, method_call.argument, method_call.IsLastCall()); + channel_state.kepler_memory->CallMethod(method_call.method, method_call.argument, method_call.IsLastCall()); break; case EngineID::NV01_TIMER: - dma_pusher.channel_state.nv01_timer->CallMethod(method_call.method, method_call.argument, method_call.IsLastCall()); + channel_state.nv01_timer->CallMethod(method_call.method, method_call.argument, method_call.IsLastCall()); break; default: UNIMPLEMENTED_MSG("Unimplemented engine"); @@ -222,26 +234,28 @@ void Puller::CallEngineMethod(DmaPusher& dma_pusher, const MethodCall& method_ca } /// Calls a GPU engine multivalue method. -void Puller::CallEngineMultiMethod(DmaPusher& dma_pusher, u32 method, u32 subchannel, const u32* base_start, u32 amount, u32 methods_pending) { +void Puller::CallEngineMultiMethod(u32 method, u32 subchannel, const u32* base_start, u32 amount, + u32 methods_pending) { const EngineID engine = bound_engines[subchannel]; + switch (engine) { case EngineID::FERMI_TWOD_A: - dma_pusher.channel_state.fermi_2d->CallMultiMethod(method, base_start, amount, methods_pending); + channel_state.fermi_2d->CallMultiMethod(method, base_start, amount, methods_pending); break; case EngineID::MAXWELL_B: - dma_pusher.channel_state.maxwell_3d->CallMultiMethod(method, base_start, amount, methods_pending); + channel_state.maxwell_3d->CallMultiMethod(method, base_start, amount, methods_pending); break; case EngineID::KEPLER_COMPUTE_B: - dma_pusher.channel_state.kepler_compute->CallMultiMethod(method, base_start, amount, methods_pending); + channel_state.kepler_compute->CallMultiMethod(method, base_start, amount, methods_pending); break; case EngineID::MAXWELL_DMA_COPY_A: - dma_pusher.channel_state.maxwell_dma->CallMultiMethod(method, base_start, amount, methods_pending); + channel_state.maxwell_dma->CallMultiMethod(method, base_start, amount, methods_pending); break; case EngineID::KEPLER_INLINE_TO_MEMORY_B: - dma_pusher.channel_state.kepler_memory->CallMultiMethod(method, base_start, amount, methods_pending); + channel_state.kepler_memory->CallMultiMethod(method, base_start, amount, methods_pending); break; case EngineID::NV01_TIMER: - dma_pusher.channel_state.nv01_timer->CallMultiMethod(method, base_start, amount, methods_pending); + channel_state.nv01_timer->CallMultiMethod(method, base_start, amount, methods_pending); break; default: UNIMPLEMENTED_MSG("Unimplemented engine"); @@ -250,26 +264,31 @@ void Puller::CallEngineMultiMethod(DmaPusher& dma_pusher, u32 method, u32 subcha } /// Calls a GPU method. -void Puller::CallMethod(DmaPusher& dma_pusher, const MethodCall& method_call) { - LOG_TRACE(HW_GPU, "Processing method {:08X} on subchannel {}", method_call.method, method_call.subchannel); +void Puller::CallMethod(const MethodCall& method_call) { + LOG_TRACE(HW_GPU, "Processing method {:08X} on subchannel {}", method_call.method, + method_call.subchannel); + ASSERT(method_call.subchannel < bound_engines.size()); - if (ExecuteMethodOnEngine(dma_pusher, method_call.method)) { - CallEngineMethod(dma_pusher, method_call); + if (ExecuteMethodOnEngine(method_call.method)) { + CallEngineMethod(method_call); } else { - CallPullerMethod(dma_pusher, method_call); + CallPullerMethod(method_call); } } /// Calls a GPU multivalue method. -void Puller::CallMultiMethod(DmaPusher& dma_pusher, u32 method, u32 subchannel, const u32* base_start, u32 amount, u32 methods_pending) { +void Puller::CallMultiMethod(u32 method, u32 subchannel, const u32* base_start, u32 amount, + u32 methods_pending) { LOG_TRACE(HW_GPU, "Processing method {:08X} on subchannel {}", method, subchannel); + ASSERT(subchannel < bound_engines.size()); - if (ExecuteMethodOnEngine(dma_pusher, method)) { - CallEngineMultiMethod(dma_pusher, method, subchannel, base_start, amount, methods_pending); + + if (ExecuteMethodOnEngine(method)) { + CallEngineMultiMethod(method, subchannel, base_start, amount, methods_pending); } else { for (u32 i = 0; i < amount; i++) { - CallPullerMethod(dma_pusher, MethodCall{ + CallPullerMethod(MethodCall{ method, base_start[i], subchannel, @@ -279,9 +298,13 @@ void Puller::CallMultiMethod(DmaPusher& dma_pusher, u32 method, u32 subchannel, } } +void Puller::BindRasterizer(VideoCore::RasterizerInterface* rasterizer_) { + rasterizer = rasterizer_; +} + /// Determines where the method should be executed. -[[nodiscard]] bool Puller::ExecuteMethodOnEngine(DmaPusher& dma_pusher, u32 method) { - const auto buffer_method = BufferMethods(method); +[[nodiscard]] bool Puller::ExecuteMethodOnEngine(u32 method) { + const auto buffer_method = static_cast(method); return buffer_method >= BufferMethods::NonPullerMethods; } diff --git a/src/video_core/engines/puller.h b/src/video_core/engines/puller.h index e8994f5640..fe5102e3ed 100644 --- a/src/video_core/engines/puller.h +++ b/src/video_core/engines/puller.h @@ -70,13 +70,32 @@ public: BitField<8, 24, u32> syncpoint_id; }; - void CallMethod(DmaPusher& dma_pusher, const MethodCall& method_call); - void CallMultiMethod(DmaPusher& dma_pusher, u32 method, u32 subchannel, const u32* base_start, u32 amount, u32 methods_pending); - void BindRasterizer(DmaPusher& dma_pusher, VideoCore::RasterizerInterface* rasterizer); - void CallPullerMethod(DmaPusher& dma_pusher, const MethodCall& method_call); - void CallEngineMethod(DmaPusher& dma_pusher, const MethodCall& method_call); - void CallEngineMultiMethod(DmaPusher& dma_pusher, u32 method, u32 subchannel, const u32* base_start, u32 amount, u32 methods_pending); + explicit Puller(GPU& gpu_, MemoryManager& memory_manager_, DmaPusher& dma_pusher, + Control::ChannelState& channel_state); + ~Puller(); + + void CallMethod(const MethodCall& method_call); + + void CallMultiMethod(u32 method, u32 subchannel, const u32* base_start, u32 amount, + u32 methods_pending); + + void BindRasterizer(VideoCore::RasterizerInterface* rasterizer); + + void CallPullerMethod(const MethodCall& method_call); + + void CallEngineMethod(const MethodCall& method_call); + + void CallEngineMultiMethod(u32 method, u32 subchannel, const u32* base_start, u32 amount, + u32 methods_pending); + private: + Tegra::GPU& gpu; + + MemoryManager& memory_manager; + DmaPusher& dma_pusher; + Control::ChannelState& channel_state; + VideoCore::RasterizerInterface* rasterizer = nullptr; + static constexpr std::size_t NUM_REGS = 0x800; struct Regs { static constexpr size_t NUM_REGS = 0x40; @@ -120,12 +139,12 @@ private: }; } regs{}; - void ProcessBindMethod(DmaPusher& dma_pusher, const MethodCall& method_call); - void ProcessFenceActionMethod(DmaPusher& dma_pusher); - void ProcessSemaphoreAcquire(DmaPusher& dma_pusher); - void ProcessSemaphoreRelease(DmaPusher& dma_pusher); - void ProcessSemaphoreTriggerMethod(DmaPusher& dma_pusher); - [[nodiscard]] bool ExecuteMethodOnEngine(DmaPusher& dma_pusher, u32 method); + void ProcessBindMethod(const MethodCall& method_call); + void ProcessFenceActionMethod(); + void ProcessSemaphoreAcquire(); + void ProcessSemaphoreRelease(); + void ProcessSemaphoreTriggerMethod(); + [[nodiscard]] bool ExecuteMethodOnEngine(u32 method); /// Mapping of command subchannels to their bound engine ids std::array bound_engines{}; @@ -138,7 +157,8 @@ private: }; #define ASSERT_REG_POSITION(field_name, position) \ - static_assert(offsetof(Regs, field_name) == position * 4, "Field " #field_name " has invalid position") + static_assert(offsetof(Regs, field_name) == position * 4, \ + "Field " #field_name " has invalid position") ASSERT_REG_POSITION(semaphore_address, 0x4); ASSERT_REG_POSITION(semaphore_sequence, 0x6); diff --git a/src/video_core/gpu.cpp b/src/video_core/gpu.cpp index 675e818625..5f4054212f 100644 --- a/src/video_core/gpu.cpp +++ b/src/video_core/gpu.cpp @@ -40,32 +40,30 @@ namespace Tegra { struct GPU::Impl { - explicit Impl(Core::System& system_, bool is_async_, bool use_nvdec_) - : system{system_} - , use_nvdec{use_nvdec_} - , shader_notify() - , is_async{is_async_} - , gpu_thread{system_, is_async_} - , scheduler(system_.GPU()) - {} + explicit Impl(GPU& gpu_, Core::System& system_, bool is_async_, bool use_nvdec_) + : gpu{gpu_}, system{system_}, host1x{system.Host1x()}, use_nvdec{use_nvdec_}, + shader_notify{std::make_unique()}, is_async{is_async_}, + gpu_thread{system_, is_async_}, scheduler{std::make_unique(gpu)} {} ~Impl() = default; std::shared_ptr CreateChannel(s32 channel_id) { auto channel_state = std::make_shared(channel_id); channels.emplace(channel_id, channel_state); - scheduler.DeclareChannel(channel_state); + scheduler->DeclareChannel(channel_state); return channel_state; } void BindChannel(s32 channel_id) { - if (bound_channel != channel_id) { - auto it = channels.find(channel_id); - ASSERT(it != channels.end()); - bound_channel = channel_id; - current_channel = it->second.get(); - renderer->ReadRasterizer()->BindChannel(*current_channel); + if (bound_channel == channel_id) { + return; } + auto it = channels.find(channel_id); + ASSERT(it != channels.end()); + bound_channel = channel_id; + current_channel = it->second.get(); + + rasterizer->BindChannel(*current_channel); } std::shared_ptr AllocateChannel() { @@ -73,13 +71,13 @@ struct GPU::Impl { } void InitChannel(Control::ChannelState& to_init, u64 program_id) { - to_init.Init(system, program_id); - to_init.BindRasterizer(renderer->ReadRasterizer()); - renderer->ReadRasterizer()->InitializeChannel(to_init); + to_init.Init(system, gpu, program_id); + to_init.BindRasterizer(rasterizer); + rasterizer->InitializeChannel(to_init); } void InitAddressSpace(Tegra::MemoryManager& memory_manager) { - memory_manager.BindRasterizer(renderer->ReadRasterizer()); + memory_manager.BindRasterizer(rasterizer); } void ReleaseChannel(Control::ChannelState& to_release) { @@ -89,26 +87,26 @@ struct GPU::Impl { /// Binds a renderer to the GPU. void BindRenderer(std::unique_ptr renderer_) { renderer = std::move(renderer_); - system.Host1x().memory_manager.BindInterface(renderer->ReadRasterizer()); - system.Host1x().gmmu_manager.BindRasterizer(renderer->ReadRasterizer()); + rasterizer = renderer->ReadRasterizer(); + host1x.MemoryManager().BindInterface(rasterizer); + host1x.gmmu_manager.BindRasterizer(rasterizer); } /// Flush all current written commands into the host GPU for execution. void FlushCommands() { - renderer->ReadRasterizer()->FlushCommands(); + rasterizer->FlushCommands(); } /// Synchronizes CPU writes with Host GPU memory. void InvalidateGPUCache() { - std::function callback_writes([this](PAddr address, size_t size) { - renderer->ReadRasterizer()->OnCacheInvalidation(address, size); - }); + std::function callback_writes( + [this](PAddr address, size_t size) { rasterizer->OnCacheInvalidation(address, size); }); system.GatherGPUDirtyMemory(callback_writes); } /// Signal the ending of command list. void OnCommandListEnd() { - renderer->ReadRasterizer()->ReleaseFences(false); + rasterizer->ReleaseFences(false); Settings::UpdateGPUAccuracy(); } @@ -145,6 +143,62 @@ struct GPU::Impl { } } + /// Returns a reference to the Maxwell3D GPU engine. + [[nodiscard]] Engines::Maxwell3D& Maxwell3D() { + ASSERT(current_channel); + return *current_channel->maxwell_3d; + } + + /// Returns a const reference to the Maxwell3D GPU engine. + [[nodiscard]] const Engines::Maxwell3D& Maxwell3D() const { + ASSERT(current_channel); + return *current_channel->maxwell_3d; + } + + /// Returns a reference to the KeplerCompute GPU engine. + [[nodiscard]] Engines::KeplerCompute& KeplerCompute() { + ASSERT(current_channel); + return *current_channel->kepler_compute; + } + + /// Returns a reference to the KeplerCompute GPU engine. + [[nodiscard]] const Engines::KeplerCompute& KeplerCompute() const { + ASSERT(current_channel); + return *current_channel->kepler_compute; + } + + /// Returns a reference to the GPU DMA pusher. + [[nodiscard]] Tegra::DmaPusher& DmaPusher() { + ASSERT(current_channel); + return *current_channel->dma_pusher; + } + + /// Returns a const reference to the GPU DMA pusher. + [[nodiscard]] const Tegra::DmaPusher& DmaPusher() const { + ASSERT(current_channel); + return *current_channel->dma_pusher; + } + + /// Returns a reference to the underlying renderer. + [[nodiscard]] VideoCore::RendererBase& Renderer() { + return *renderer; + } + + /// Returns a const reference to the underlying renderer. + [[nodiscard]] const VideoCore::RendererBase& Renderer() const { + return *renderer; + } + + /// Returns a reference to the shader notifier. + [[nodiscard]] VideoCore::ShaderNotify& ShaderNotify() { + return *shader_notify; + } + + /// Returns a const reference to the shader notifier. + [[nodiscard]] const VideoCore::ShaderNotify& ShaderNotify() const { + return *shader_notify; + } + [[nodiscard]] u64 GetTicks() const { u64 gpu_tick = system.CoreTiming().GetGPUTicks(); Settings::GpuOverclock overclock = Settings::values.fast_gpu_time.GetValue(); @@ -156,6 +210,14 @@ struct GPU::Impl { return gpu_tick; } + [[nodiscard]] bool IsAsync() const { + return is_async; + } + + [[nodiscard]] bool UseNvdec() const { + return use_nvdec; + } + void RendererFrameEndNotify() { system.GetPerfStats().EndGameFrame(); } @@ -165,7 +227,7 @@ struct GPU::Impl { /// core timing events. void Start() { Settings::UpdateGPUAccuracy(); - gpu_thread.StartThread(*renderer, renderer->Context(), scheduler); + gpu_thread.StartThread(*renderer, renderer->Context(), *scheduler); } void NotifyShutdown() { @@ -198,13 +260,14 @@ struct GPU::Impl { } VideoCore::RasterizerDownloadArea OnCPURead(DAddr addr, u64 size) { - auto raster_area = renderer->ReadRasterizer()->GetFlushArea(addr, size); + auto raster_area = rasterizer->GetFlushArea(addr, size); if (raster_area.preemtive) { return raster_area; } raster_area.preemtive = true; const u64 fence = RequestSyncOperation([this, &raster_area]() { - renderer->ReadRasterizer()->FlushRegion(raster_area.start_address, raster_area.end_address - raster_area.start_address); + rasterizer->FlushRegion(raster_area.start_address, + raster_area.end_address - raster_area.start_address); }); gpu_thread.TickGPU(); WaitForSyncOperation(fence); @@ -217,7 +280,7 @@ struct GPU::Impl { } bool OnCPUWrite(DAddr addr, u64 size) { - return renderer->ReadRasterizer()->OnCPUWrite(addr, size); + return rasterizer->OnCPUWrite(addr, size); } /// Notify rasterizer that any caches of the specified region should be flushed and invalidated @@ -242,7 +305,7 @@ struct GPU::Impl { } const auto wait_fence = RequestSyncOperation([this, current_request_counter, &layers, &fences, num_fences] { - auto& syncpoint_manager = system.Host1x().GetSyncpointManager(); + auto& syncpoint_manager = host1x.GetSyncpointManager(); if (num_fences == 0) { renderer->Composite(layers); } @@ -275,14 +338,17 @@ struct GPU::Impl { return out; } + GPU& gpu; Core::System& system; + Host1x::Host1x& host1x; std::unique_ptr renderer; + VideoCore::RasterizerInterface* rasterizer = nullptr; const bool use_nvdec; s32 new_channel_id{1}; /// Shader build notifier - VideoCore::ShaderNotify shader_notify; + std::unique_ptr shader_notify; /// When true, we are about to shut down emulation session, so terminate outstanding tasks std::atomic_bool shutting_down{}; @@ -306,7 +372,7 @@ struct GPU::Impl { VideoCommon::GPUThread::ThreadManager gpu_thread; std::unique_ptr cpu_context; - Tegra::Control::Scheduler scheduler; + std::unique_ptr scheduler; ankerl::unordered_dense::map> channels; Tegra::Control::ChannelState* current_channel; s32 bound_channel{-1}; @@ -317,8 +383,7 @@ struct GPU::Impl { }; GPU::GPU(Core::System& system, bool is_async, bool use_nvdec) - : impl{std::make_unique(system, is_async, use_nvdec)} -{} + : impl{std::make_unique(*this, system, is_async, use_nvdec)} {} GPU::~GPU() = default; @@ -359,9 +424,8 @@ void GPU::OnCommandListEnd() { } u64 GPU::RequestFlush(DAddr addr, std::size_t size) { - return impl->RequestSyncOperation([this, addr, size]() { - impl->renderer->ReadRasterizer()->FlushRegion(addr, size); - }); + return impl->RequestSyncOperation( + [this, addr, size]() { impl->rasterizer->FlushRegion(addr, size); }); } u64 GPU::CurrentSyncRequestFence() const { @@ -378,52 +442,52 @@ void GPU::TickWork() { /// Gets a mutable reference to the Host1x interface Host1x::Host1x& GPU::Host1x() { - return impl->system.Host1x(); + return impl->host1x; } /// Gets an immutable reference to the Host1x interface. const Host1x::Host1x& GPU::Host1x() const { - return impl->system.Host1x(); + return impl->host1x; } Engines::Maxwell3D& GPU::Maxwell3D() { - return *impl->current_channel->maxwell_3d; + return impl->Maxwell3D(); } const Engines::Maxwell3D& GPU::Maxwell3D() const { - return *impl->current_channel->maxwell_3d; + return impl->Maxwell3D(); } Engines::KeplerCompute& GPU::KeplerCompute() { - return *impl->current_channel->kepler_compute; + return impl->KeplerCompute(); } const Engines::KeplerCompute& GPU::KeplerCompute() const { - return *impl->current_channel->kepler_compute; + return impl->KeplerCompute(); } Tegra::DmaPusher& GPU::DmaPusher() { - return *impl->current_channel->dma_pusher; + return impl->DmaPusher(); } const Tegra::DmaPusher& GPU::DmaPusher() const { - return *impl->current_channel->dma_pusher; + return impl->DmaPusher(); } VideoCore::RendererBase& GPU::Renderer() { - return *impl->renderer; + return impl->Renderer(); } const VideoCore::RendererBase& GPU::Renderer() const { - return *impl->renderer; + return impl->Renderer(); } VideoCore::ShaderNotify& GPU::ShaderNotify() { - return impl->shader_notify; + return impl->ShaderNotify(); } const VideoCore::ShaderNotify& GPU::ShaderNotify() const { - return impl->shader_notify; + return impl->ShaderNotify(); } void GPU::RequestComposite(std::vector&& layers, @@ -440,11 +504,11 @@ u64 GPU::GetTicks() const { } bool GPU::IsAsync() const { - return impl->is_async; + return impl->IsAsync(); } bool GPU::UseNvdec() const { - return impl->use_nvdec; + return impl->UseNvdec(); } void GPU::RendererFrameEndNotify() { From f0e2e877531ad85b58e3ae45f70adf0459c6505b Mon Sep 17 00:00:00 2001 From: lizzie Date: Wed, 20 May 2026 19:29:21 +0000 Subject: [PATCH 8/9] Use managarm special fastmem fallback --- src/common/host_memory.cpp | 68 ++++++++++++++++++++++++++++++-------- src/common/host_memory.h | 7 ++++ 2 files changed, 62 insertions(+), 13 deletions(-) diff --git a/src/common/host_memory.cpp b/src/common/host_memory.cpp index 04f3a65778..c405ce4053 100644 --- a/src/common/host_memory.cpp +++ b/src/common/host_memory.cpp @@ -32,6 +32,8 @@ #include #elif defined(__FreeBSD__) #include +#elif defined(__OPENORBIS__) +#include #endif // FreeBSD @@ -391,6 +393,9 @@ private: ankerl::unordered_dense::map placeholder_host_pointers; ///< Placeholder backing offset }; +#elif defined(__OPENORBIS__) || defined(__managarm__) +// None of the luxuries of POSIX, all of the suffering +// For managarm: see https://github.com/managarm/managarm/issues/1370 #else // ^^^ Windows ^^^ vvv POSIX vvv #ifdef ARCHITECTURE_arm64 @@ -507,7 +512,7 @@ public: fd = shm_open_anon(O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW, 0600); #elif defined(__FreeBSD__) fd = shm_open(SHM_ANON, O_RDWR, 0600); -#elif defined(__APPLE__) +#elif defined(__APPLE__) || defined(__managarm__) // macOS doesn't have memfd_create, use anonymous temporary file char template_path[] = "/tmp/eden_mem_XXXXXX"; fd = mkstemp(template_path); @@ -669,17 +674,47 @@ private: #endif // ^^^ POSIX ^^^ -HostMemory::HostMemory(size_t backing_size_, size_t virtual_size_) : backing_size(backing_size_), virtual_size(virtual_size_) { - // Try to allocate a fastmem arena. - // The implementation will fail with std::bad_alloc on errors. - impl = std::make_unique(AlignUp(backing_size, PageAlignment), AlignUp(virtual_size, PageAlignment) + HugePageSize); - backing_base = impl->backing_base; - virtual_base = impl->virtual_base; - if (virtual_base) { - // Ensure the virtual base is aligned to the L2 block size. - virtual_base = reinterpret_cast(Common::AlignUp(uintptr_t(virtual_base), HugePageSize)); - virtual_base_offset = virtual_base - impl->virtual_base; +HostMemory::HostMemory(size_t backing_size_, size_t virtual_size_) + : backing_size(backing_size_) + , virtual_size(virtual_size_) +{ +#if defined(__OPENORBIS__) || defined(__managarm__) + LOG_WARNING(HW_Memory, "Platform doesn't support fastmem"); + fallback_buffer.emplace(backing_size); + backing_base = fallback_buffer->data(); + virtual_base = nullptr; +#else + bool has_memfd = true; // all platforms support it +#ifdef _WIN32 + // EXCEPT WINDOWS who may not (Windows 8.1, 7, Vista, etc) + DynamicLibrary kernelbase_dll("KernelBase"); + has_memfd = kernelbase_dll.IsOpen(); + if (has_memfd) { + PFN_CreateFileMapping2 p{}; + GetFuncAddress(kernelbase_dll, "CreateFileMapping2", p); + has_memfd = p != nullptr; } +#endif + if (has_memfd) { + // Try to allocate a fastmem arena. + // The implementation will fail with std::bad_alloc on errors. + impl = std::make_unique(AlignUp(backing_size, PageAlignment), AlignUp(virtual_size, PageAlignment) + HugePageSize); + backing_base = impl->backing_base; + virtual_base = impl->virtual_base; + if (virtual_base) { + // Ensure the virtual base is aligned to the L2 block size. + virtual_base = reinterpret_cast(Common::AlignUp(uintptr_t(virtual_base), HugePageSize)); + virtual_base_offset = virtual_base - impl->virtual_base; + } + } else { + LOG_WARNING(HW_Memory, "Platform doesn't support fastmem"); +#ifdef _WIN32 + fallback_buffer.emplace(backing_size); + backing_base = fallback_buffer->data(); + virtual_base = nullptr; +#endif + } +#endif } HostMemory::~HostMemory() = default; @@ -688,8 +723,8 @@ HostMemory::HostMemory(HostMemory&&) noexcept = default; HostMemory& HostMemory::operator=(HostMemory&&) noexcept = default; -void HostMemory::Map(size_t virtual_offset, size_t host_offset, size_t length, - MemoryPermission perms, bool separate_heap) { +void HostMemory::Map(size_t virtual_offset, size_t host_offset, size_t length, MemoryPermission perms, bool separate_heap) { +#if !(defined(__OPENORBIS__) || defined(__managarm__)) ASSERT(virtual_offset % PageAlignment == 0); ASSERT(host_offset % PageAlignment == 0); ASSERT(length % PageAlignment == 0); @@ -699,9 +734,11 @@ void HostMemory::Map(size_t virtual_offset, size_t host_offset, size_t length, return; } impl->Map(virtual_offset + virtual_base_offset, host_offset, length, perms); +#endif } void HostMemory::Unmap(size_t virtual_offset, size_t length, bool separate_heap) { +#if !(defined(__OPENORBIS__) || defined(__managarm__)) ASSERT(virtual_offset % PageAlignment == 0); ASSERT(length % PageAlignment == 0); ASSERT(virtual_offset + length <= virtual_size); @@ -709,9 +746,11 @@ void HostMemory::Unmap(size_t virtual_offset, size_t length, bool separate_heap) return; } impl->Unmap(virtual_offset + virtual_base_offset, length); +#endif } void HostMemory::Protect(size_t virtual_offset, size_t length, MemoryPermission perm) { +#if !(defined(__OPENORBIS__) || defined(__managarm__)) ASSERT(virtual_offset % PageAlignment == 0); ASSERT(length % PageAlignment == 0); ASSERT(virtual_offset + length <= virtual_size); @@ -722,6 +761,7 @@ void HostMemory::Protect(size_t virtual_offset, size_t length, MemoryPermission const bool write = True(perm & MemoryPermission::Write); const bool execute = True(perm & MemoryPermission::Execute); impl->Protect(virtual_offset + virtual_base_offset, length, read, write, execute); +#endif } void HostMemory::ClearBackingRegion(size_t physical_offset, size_t length, u32 fill_value) { @@ -729,10 +769,12 @@ void HostMemory::ClearBackingRegion(size_t physical_offset, size_t length, u32 f } void HostMemory::EnableDirectMappedAddress() { +#if !(defined(__OPENORBIS__) || defined(__managarm__)) if (impl) { impl->EnableDirectMappedAddress(); virtual_size += reinterpret_cast(virtual_base); } +#endif } } // namespace Common diff --git a/src/common/host_memory.h b/src/common/host_memory.h index 8dd30aa9de..577be22b19 100644 --- a/src/common/host_memory.h +++ b/src/common/host_memory.h @@ -7,6 +7,7 @@ #pragma once #include +#include #include "common/common_funcs.h" #include "common/common_types.h" #include "common/virtual_buffer.h" @@ -76,12 +77,18 @@ private: size_t backing_size{}; size_t virtual_size{}; +#if !(defined(__OPENORBIS__) || defined(__managarm__)) // Low level handler for the platform dependent memory routines class Impl; std::unique_ptr impl; +#endif u8* backing_base{}; u8* virtual_base{}; size_t virtual_base_offset{}; +// Windows requires it for kernels whom lack proper support for some functions! +#if defined(__OPENORBIS__) || defined(__managarm__) || defined(_WIN32) + std::optional> fallback_buffer; +#endif }; } // namespace Common From 1bfdba1da43f5ab0660574ae8c4ae44f4ce763c1 Mon Sep 17 00:00:00 2001 From: lizzie Date: Wed, 20 May 2026 19:41:19 +0000 Subject: [PATCH 9/9] license + fix --- src/common/host_memory.h | 2 +- src/common/virtual_buffer.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/common/host_memory.h b/src/common/host_memory.h index 577be22b19..3ff4cee73a 100644 --- a/src/common/host_memory.h +++ b/src/common/host_memory.h @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project +// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project // SPDX-License-Identifier: GPL-3.0-or-later // SPDX-FileCopyrightText: Copyright 2019 yuzu Emulator Project diff --git a/src/common/virtual_buffer.h b/src/common/virtual_buffer.h index af96317288..d6386e2a4d 100644 --- a/src/common/virtual_buffer.h +++ b/src/common/virtual_buffer.h @@ -38,7 +38,8 @@ public: VirtualBuffer& operator=(const VirtualBuffer&) = delete; VirtualBuffer(VirtualBuffer&& other) noexcept - : alloc_size{std::exchange(other.alloc_size, 0)}, base_ptr{std::exchange(other.base_ptr), nullptr} + : alloc_size{std::exchange(other.alloc_size, 0)} + , base_ptr{std::exchange(other.base_ptr, nullptr)} {} VirtualBuffer& operator=(VirtualBuffer&& other) noexcept {