From 2e997c8124557f3c31ba55f9b582db0377ee6ba3 Mon Sep 17 00:00:00 2001 From: MaranBr Date: Fri, 15 Aug 2025 20:59:44 -0400 Subject: [PATCH] Add toggle to force GPU to only use safe reads --- src/common/settings.h | 2 +- src/video_core/dma_pusher.cpp | 27 ++++++++----------- src/video_core/dma_pusher.h | 5 +++- src/yuzu/configuration/shared_translation.cpp | 7 +++-- 4 files changed, 19 insertions(+), 22 deletions(-) diff --git a/src/common/settings.h b/src/common/settings.h index faf7210f5d..4f8417bbbb 100644 --- a/src/common/settings.h +++ b/src/common/settings.h @@ -466,7 +466,7 @@ struct Values { true, true}; #endif - + SwitchableSetting force_safe_reads{linkage, false, "force_safe_reads", Category::RendererAdvanced}; SwitchableSetting async_presentation{linkage, #ifdef ANDROID true, diff --git a/src/video_core/dma_pusher.cpp b/src/video_core/dma_pusher.cpp index c2c07deb9b..27d14e1de7 100644 --- a/src/video_core/dma_pusher.cpp +++ b/src/video_core/dma_pusher.cpp @@ -1,7 +1,7 @@ // SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project // SPDX-License-Identifier: GPL-3.0-or-later -// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project +// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later #include "common/cityhash.h" @@ -17,12 +17,6 @@ namespace Tegra { constexpr u32 MacroRegistersStart = 0xE00; constexpr u32 ComputeInline = 0x6D; -//start on PR#76 of Eden this is a unused variable in android (need to investigate) - -// Dummy function that uses ComputeInline -constexpr void UseComputeInline() { - static_cast(ComputeInline); // Suppress unused variable error -} DmaPusher::DmaPusher(Core::System& system_, GPU& gpu_, MemoryManager& memory_manager_, Control::ChannelState& channel_state_) @@ -102,22 +96,23 @@ bool DmaPusher::Step() { &command_headers); ProcessCommands(headers); }; - - // Only use unsafe reads for non-compute macro operations + if (Settings::values.force_safe_reads.GetValue()) { + safe_process(); + return true; + } if (Settings::IsGPULevelHigh()) { - const bool is_compute = (subchannel_type[dma_state.subchannel] == - Engines::EngineTypes::KeplerCompute); - - if (dma_state.method >= MacroRegistersStart && !is_compute) { + if (dma_state.method >= MacroRegistersStart) { + unsafe_process(); + return true; + } + if (subchannel_type[dma_state.subchannel] == Engines::EngineTypes::KeplerCompute && + dma_state.method == ComputeInline) { unsafe_process(); return true; } - - // Always use safe reads for compute operations safe_process(); return true; } - unsafe_process(); } return true; diff --git a/src/video_core/dma_pusher.h b/src/video_core/dma_pusher.h index e46a8fa5c6..f8198bee3e 100644 --- a/src/video_core/dma_pusher.h +++ b/src/video_core/dma_pusher.h @@ -1,4 +1,7 @@ -// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project +// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + +// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later #pragma once diff --git a/src/yuzu/configuration/shared_translation.cpp b/src/yuzu/configuration/shared_translation.cpp index 6010f5805f..0707c6b87f 100644 --- a/src/yuzu/configuration/shared_translation.cpp +++ b/src/yuzu/configuration/shared_translation.cpp @@ -1,10 +1,7 @@ // SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project // SPDX-License-Identifier: GPL-3.0-or-later -// SPDX-FileCopyrightText: Copyright 2024 Torzu Emulator Project -// SPDX-License-Identifier: GPL-3.0-or-later - -// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project +// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later #include "yuzu/configuration/shared_translation.h" @@ -269,6 +266,8 @@ std::unique_ptr InitializeTranslations(QWidget* parent) INSERT(Settings, bg_blue, QString(), QString()); // Renderer (Advanced Graphics) + INSERT(Settings, force_safe_reads, tr("Force GPU to only use safe reads"), + tr("Prevents potential memory corruption issues that could lead to invalid dispatch parameters.\nThis can reduce performance in some cases.")); INSERT(Settings, async_presentation, tr("Enable asynchronous presentation (Vulkan only)"),