summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/common/CMakeLists.txt1
-rw-r--r--src/common/bit_set.h244
-rw-r--r--src/common/thread.cpp35
-rw-r--r--src/common/thread.h20
-rw-r--r--src/core/CMakeLists.txt2
-rw-r--r--src/core/core.cpp119
-rw-r--r--src/core/cpu_core_manager.cpp142
-rw-r--r--src/core/cpu_core_manager.h59
-rw-r--r--src/core/hle/kernel/handle_table.cpp11
-rw-r--r--src/core/hle/kernel/handle_table.h15
-rw-r--r--src/core/hle/service/audio/audout_u.cpp28
-rw-r--r--src/core/hle/service/audio/audout_u.h3
-rw-r--r--src/core/hle/service/hid/controllers/debug_pad.cpp5
-rw-r--r--src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.cpp13
-rw-r--r--src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.h6
-rw-r--r--src/video_core/engines/maxwell_3d.h7
-rw-r--r--src/video_core/engines/shader_bytecode.h1
-rw-r--r--src/video_core/macro_interpreter.cpp29
-rw-r--r--src/video_core/macro_interpreter.h4
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer_cache.cpp31
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer_cache.h1
-rw-r--r--src/video_core/renderer_opengl/gl_shader_decompiler.cpp169
-rw-r--r--src/video_core/renderer_opengl/maxwell_to_gl.h5
23 files changed, 467 insertions, 483 deletions
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt
index 895ee53f1..a5e71d879 100644
--- a/src/common/CMakeLists.txt
+++ b/src/common/CMakeLists.txt
@@ -44,7 +44,6 @@ add_library(common STATIC
detached_tasks.cpp
detached_tasks.h
bit_field.h
- bit_set.h
cityhash.cpp
cityhash.h
color.h
diff --git a/src/common/bit_set.h b/src/common/bit_set.h
deleted file mode 100644
index 5cd1352b2..000000000
--- a/src/common/bit_set.h
+++ /dev/null
@@ -1,244 +0,0 @@
-// This file is under the public domain.
-
-#pragma once
-
-#include <cstddef>
-#ifdef _WIN32
-#include <intrin.h>
-#endif
-#include <initializer_list>
-#include <new>
-#include <type_traits>
-#include "common/common_types.h"
-
-// namespace avoids conflict with OS X Carbon; don't use BitSet<T> directly
-namespace Common {
-
-// Helper functions:
-
-#ifdef _MSC_VER
-template <typename T>
-static inline int CountSetBits(T v) {
- // from https://graphics.stanford.edu/~seander/bithacks.html
- // GCC has this built in, but MSVC's intrinsic will only emit the actual
- // POPCNT instruction, which we're not depending on
- v = v - ((v >> 1) & (T) ~(T)0 / 3);
- v = (v & (T) ~(T)0 / 15 * 3) + ((v >> 2) & (T) ~(T)0 / 15 * 3);
- v = (v + (v >> 4)) & (T) ~(T)0 / 255 * 15;
- return (T)(v * ((T) ~(T)0 / 255)) >> (sizeof(T) - 1) * 8;
-}
-static inline int LeastSignificantSetBit(u8 val) {
- unsigned long index;
- _BitScanForward(&index, val);
- return (int)index;
-}
-static inline int LeastSignificantSetBit(u16 val) {
- unsigned long index;
- _BitScanForward(&index, val);
- return (int)index;
-}
-static inline int LeastSignificantSetBit(u32 val) {
- unsigned long index;
- _BitScanForward(&index, val);
- return (int)index;
-}
-static inline int LeastSignificantSetBit(u64 val) {
- unsigned long index;
- _BitScanForward64(&index, val);
- return (int)index;
-}
-#else
-static inline int CountSetBits(u8 val) {
- return __builtin_popcount(val);
-}
-static inline int CountSetBits(u16 val) {
- return __builtin_popcount(val);
-}
-static inline int CountSetBits(u32 val) {
- return __builtin_popcount(val);
-}
-static inline int CountSetBits(u64 val) {
- return __builtin_popcountll(val);
-}
-static inline int LeastSignificantSetBit(u8 val) {
- return __builtin_ctz(val);
-}
-static inline int LeastSignificantSetBit(u16 val) {
- return __builtin_ctz(val);
-}
-static inline int LeastSignificantSetBit(u32 val) {
- return __builtin_ctz(val);
-}
-static inline int LeastSignificantSetBit(u64 val) {
- return __builtin_ctzll(val);
-}
-#endif
-
-// Similar to std::bitset, this is a class which encapsulates a bitset, i.e.
-// using the set bits of an integer to represent a set of integers. Like that
-// class, it acts like an array of bools:
-// BitSet32 bs;
-// bs[1] = true;
-// but also like the underlying integer ([0] = least significant bit):
-// BitSet32 bs2 = ...;
-// bs = (bs ^ bs2) & BitSet32(0xffff);
-// The following additional functionality is provided:
-// - Construction using an initializer list.
-// BitSet bs { 1, 2, 4, 8 };
-// - Efficiently iterating through the set bits:
-// for (int i : bs)
-// [i is the *index* of a set bit]
-// (This uses the appropriate CPU instruction to find the next set bit in one
-// operation.)
-// - Counting set bits using .Count() - see comment on that method.
-
-// TODO: use constexpr when MSVC gets out of the Dark Ages
-
-template <typename IntTy>
-class BitSet {
- static_assert(!std::is_signed_v<IntTy>, "BitSet should not be used with signed types");
-
-public:
- // A reference to a particular bit, returned from operator[].
- class Ref {
- public:
- Ref(Ref&& other) : m_bs(other.m_bs), m_mask(other.m_mask) {}
- Ref(BitSet* bs, IntTy mask) : m_bs(bs), m_mask(mask) {}
- operator bool() const {
- return (m_bs->m_val & m_mask) != 0;
- }
- bool operator=(bool set) {
- m_bs->m_val = (m_bs->m_val & ~m_mask) | (set ? m_mask : 0);
- return set;
- }
-
- private:
- BitSet* m_bs;
- IntTy m_mask;
- };
-
- // A STL-like iterator is required to be able to use range-based for loops.
- class Iterator {
- public:
- Iterator(const Iterator& other) : m_val(other.m_val), m_bit(other.m_bit) {}
- Iterator(IntTy val) : m_val(val), m_bit(0) {}
- Iterator& operator=(Iterator other) {
- new (this) Iterator(other);
- return *this;
- }
- int operator*() {
- return m_bit + ComputeLsb();
- }
- Iterator& operator++() {
- int lsb = ComputeLsb();
- m_val >>= lsb + 1;
- m_bit += lsb + 1;
- m_has_lsb = false;
- return *this;
- }
- Iterator operator++(int _) {
- Iterator other(*this);
- ++*this;
- return other;
- }
- bool operator==(Iterator other) const {
- return m_val == other.m_val;
- }
- bool operator!=(Iterator other) const {
- return m_val != other.m_val;
- }
-
- private:
- int ComputeLsb() {
- if (!m_has_lsb) {
- m_lsb = LeastSignificantSetBit(m_val);
- m_has_lsb = true;
- }
- return m_lsb;
- }
- IntTy m_val;
- int m_bit;
- int m_lsb = -1;
- bool m_has_lsb = false;
- };
-
- BitSet() : m_val(0) {}
- explicit BitSet(IntTy val) : m_val(val) {}
- BitSet(std::initializer_list<int> init) {
- m_val = 0;
- for (int bit : init)
- m_val |= (IntTy)1 << bit;
- }
-
- static BitSet AllTrue(std::size_t count) {
- return BitSet(count == sizeof(IntTy) * 8 ? ~(IntTy)0 : (((IntTy)1 << count) - 1));
- }
-
- Ref operator[](std::size_t bit) {
- return Ref(this, (IntTy)1 << bit);
- }
- const Ref operator[](std::size_t bit) const {
- return (*const_cast<BitSet*>(this))[bit];
- }
- bool operator==(BitSet other) const {
- return m_val == other.m_val;
- }
- bool operator!=(BitSet other) const {
- return m_val != other.m_val;
- }
- bool operator<(BitSet other) const {
- return m_val < other.m_val;
- }
- bool operator>(BitSet other) const {
- return m_val > other.m_val;
- }
- BitSet operator|(BitSet other) const {
- return BitSet(m_val | other.m_val);
- }
- BitSet operator&(BitSet other) const {
- return BitSet(m_val & other.m_val);
- }
- BitSet operator^(BitSet other) const {
- return BitSet(m_val ^ other.m_val);
- }
- BitSet operator~() const {
- return BitSet(~m_val);
- }
- BitSet& operator|=(BitSet other) {
- return *this = *this | other;
- }
- BitSet& operator&=(BitSet other) {
- return *this = *this & other;
- }
- BitSet& operator^=(BitSet other) {
- return *this = *this ^ other;
- }
- operator u32() = delete;
- operator bool() {
- return m_val != 0;
- }
-
- // Warning: Even though on modern CPUs this is a single fast instruction,
- // Dolphin's official builds do not currently assume POPCNT support on x86,
- // so slower explicit bit twiddling is generated. Still should generally
- // be faster than a loop.
- unsigned int Count() const {
- return CountSetBits(m_val);
- }
-
- Iterator begin() const {
- return Iterator(m_val);
- }
- Iterator end() const {
- return Iterator(0);
- }
-
- IntTy m_val;
-};
-
-} // namespace Common
-
-typedef Common::BitSet<u8> BitSet8;
-typedef Common::BitSet<u16> BitSet16;
-typedef Common::BitSet<u32> BitSet32;
-typedef Common::BitSet<u64> BitSet64;
diff --git a/src/common/thread.cpp b/src/common/thread.cpp
index 9e207118f..5144c0d9f 100644
--- a/src/common/thread.cpp
+++ b/src/common/thread.cpp
@@ -25,23 +25,6 @@
namespace Common {
-int CurrentThreadId() {
-#ifdef _MSC_VER
- return GetCurrentThreadId();
-#elif defined __APPLE__
- return mach_thread_self();
-#else
- return 0;
-#endif
-}
-
-#ifdef _WIN32
-// Supporting functions
-void SleepCurrentThread(int ms) {
- Sleep(ms);
-}
-#endif
-
#ifdef _MSC_VER
void SetThreadAffinity(std::thread::native_handle_type thread, u32 mask) {
@@ -62,7 +45,7 @@ void SwitchCurrentThread() {
// This is implemented much nicer in upcoming msvc++, see:
// http://msdn.microsoft.com/en-us/library/xcb2z8hs(VS.100).aspx
-void SetCurrentThreadName(const char* szThreadName) {
+void SetCurrentThreadName(const char* name) {
static const DWORD MS_VC_EXCEPTION = 0x406D1388;
#pragma pack(push, 8)
@@ -75,7 +58,7 @@ void SetCurrentThreadName(const char* szThreadName) {
#pragma pack(pop)
info.dwType = 0x1000;
- info.szName = szThreadName;
+ info.szName = name;
info.dwThreadID = -1; // dwThreadID;
info.dwFlags = 0;
@@ -107,10 +90,6 @@ void SetCurrentThreadAffinity(u32 mask) {
}
#ifndef _WIN32
-void SleepCurrentThread(int ms) {
- usleep(1000 * ms);
-}
-
void SwitchCurrentThread() {
usleep(1000 * 1);
}
@@ -118,15 +97,15 @@ void SwitchCurrentThread() {
// MinGW with the POSIX threading model does not support pthread_setname_np
#if !defined(_WIN32) || defined(_MSC_VER)
-void SetCurrentThreadName(const char* szThreadName) {
+void SetCurrentThreadName(const char* name) {
#ifdef __APPLE__
- pthread_setname_np(szThreadName);
+ pthread_setname_np(name);
#elif defined(__Bitrig__) || defined(__DragonFly__) || defined(__FreeBSD__) || defined(__OpenBSD__)
- pthread_set_name_np(pthread_self(), szThreadName);
+ pthread_set_name_np(pthread_self(), name);
#elif defined(__NetBSD__)
- pthread_setname_np(pthread_self(), "%s", (void*)szThreadName);
+ pthread_setname_np(pthread_self(), "%s", (void*)name);
#else
- pthread_setname_np(pthread_self(), szThreadName);
+ pthread_setname_np(pthread_self(), name);
#endif
}
#endif
diff --git a/src/common/thread.h b/src/common/thread.h
index 6cbdb96a3..2cf74452d 100644
--- a/src/common/thread.h
+++ b/src/common/thread.h
@@ -13,15 +13,8 @@
namespace Common {
-int CurrentThreadId();
-
-void SetThreadAffinity(std::thread::native_handle_type thread, u32 mask);
-void SetCurrentThreadAffinity(u32 mask);
-
class Event {
public:
- Event() : is_set(false) {}
-
void Set() {
std::lock_guard<std::mutex> lk(mutex);
if (!is_set) {
@@ -53,14 +46,14 @@ public:
}
private:
- bool is_set;
+ bool is_set = false;
std::condition_variable condvar;
std::mutex mutex;
};
class Barrier {
public:
- explicit Barrier(std::size_t count_) : count(count_), waiting(0), generation(0) {}
+ explicit Barrier(std::size_t count_) : count(count_) {}
/// Blocks until all "count" threads have called Sync()
void Sync() {
@@ -80,12 +73,13 @@ public:
private:
std::condition_variable condvar;
std::mutex mutex;
- const std::size_t count;
- std::size_t waiting;
- std::size_t generation; // Incremented once each time the barrier is used
+ std::size_t count;
+ std::size_t waiting = 0;
+ std::size_t generation = 0; // Incremented once each time the barrier is used
};
-void SleepCurrentThread(int ms);
+void SetThreadAffinity(std::thread::native_handle_type thread, u32 mask);
+void SetCurrentThreadAffinity(u32 mask);
void SwitchCurrentThread(); // On Linux, this is equal to sleep 1ms
void SetCurrentThreadName(const char* name);
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt
index c100340d0..e1f21a764 100644
--- a/src/core/CMakeLists.txt
+++ b/src/core/CMakeLists.txt
@@ -12,6 +12,8 @@ add_library(core STATIC
core_timing.h
core_timing_util.cpp
core_timing_util.h
+ cpu_core_manager.cpp
+ cpu_core_manager.h
crypto/aes_util.cpp
crypto/aes_util.h
crypto/encryption_layer.cpp
diff --git a/src/core/core.cpp b/src/core/core.cpp
index 6c72fdf4a..795fabc65 100644
--- a/src/core/core.cpp
+++ b/src/core/core.cpp
@@ -14,6 +14,7 @@
#include "core/core.h"
#include "core/core_cpu.h"
#include "core/core_timing.h"
+#include "core/cpu_core_manager.h"
#include "core/file_sys/mode.h"
#include "core/file_sys/vfs_concat.h"
#include "core/file_sys/vfs_real.h"
@@ -28,7 +29,6 @@
#include "core/hle/service/sm/sm.h"
#include "core/loader/loader.h"
#include "core/perf_stats.h"
-#include "core/settings.h"
#include "core/telemetry_session.h"
#include "frontend/applets/software_keyboard.h"
#include "video_core/debug_utils/debug_utils.h"
@@ -71,64 +71,22 @@ FileSys::VirtualFile GetGameFileFromPath(const FileSys::VirtualFilesystem& vfs,
return vfs->OpenFile(path, FileSys::Mode::Read);
}
-
-/// Runs a CPU core while the system is powered on
-void RunCpuCore(Cpu& cpu_state) {
- while (Core::System::GetInstance().IsPoweredOn()) {
- cpu_state.RunLoop(true);
- }
-}
} // Anonymous namespace
struct System::Impl {
Cpu& CurrentCpuCore() {
- if (Settings::values.use_multi_core) {
- const auto& search = thread_to_cpu.find(std::this_thread::get_id());
- ASSERT(search != thread_to_cpu.end());
- ASSERT(search->second);
- return *search->second;
- }
-
- // Otherwise, use single-threaded mode active_core variable
- return *cpu_cores[active_core];
+ return cpu_core_manager.GetCurrentCore();
}
ResultStatus RunLoop(bool tight_loop) {
status = ResultStatus::Success;
- // Update thread_to_cpu in case Core 0 is run from a different host thread
- thread_to_cpu[std::this_thread::get_id()] = cpu_cores[0].get();
-
- if (GDBStub::IsServerEnabled()) {
- GDBStub::HandlePacket();
-
- // If the loop is halted and we want to step, use a tiny (1) number of instructions to
- // execute. Otherwise, get out of the loop function.
- if (GDBStub::GetCpuHaltFlag()) {
- if (GDBStub::GetCpuStepFlag()) {
- tight_loop = false;
- } else {
- return ResultStatus::Success;
- }
- }
- }
-
- for (active_core = 0; active_core < NUM_CPU_CORES; ++active_core) {
- cpu_cores[active_core]->RunLoop(tight_loop);
- if (Settings::values.use_multi_core) {
- // Cores 1-3 are run on other threads in this mode
- break;
- }
- }
-
- if (GDBStub::IsServerEnabled()) {
- GDBStub::SetCpuStepFlag(false);
- }
+ cpu_core_manager.RunLoop(tight_loop);
return status;
}
- ResultStatus Init(Frontend::EmuWindow& emu_window) {
+ ResultStatus Init(System& system, Frontend::EmuWindow& emu_window) {
LOG_DEBUG(HW_Memory, "initialized OK");
CoreTiming::Init();
@@ -145,12 +103,6 @@ struct System::Impl {
auto main_process = Kernel::Process::Create(kernel, "main");
kernel.MakeCurrentProcess(main_process.get());
- cpu_barrier = std::make_unique<CpuBarrier>();
- cpu_exclusive_monitor = Cpu::MakeExclusiveMonitor(cpu_cores.size());
- for (std::size_t index = 0; index < cpu_cores.size(); ++index) {
- cpu_cores[index] = std::make_unique<Cpu>(*cpu_exclusive_monitor, *cpu_barrier, index);
- }
-
telemetry_session = std::make_unique<Core::TelemetrySession>();
service_manager = std::make_shared<Service::SM::ServiceManager>();
@@ -164,17 +116,8 @@ struct System::Impl {
gpu_core = std::make_unique<Tegra::GPU>(renderer->Rasterizer());
- // Create threads for CPU cores 1-3, and build thread_to_cpu map
- // CPU core 0 is run on the main thread
- thread_to_cpu[std::this_thread::get_id()] = cpu_cores[0].get();
- if (Settings::values.use_multi_core) {
- for (std::size_t index = 0; index < cpu_core_threads.size(); ++index) {
- cpu_core_threads[index] =
- std::make_unique<std::thread>(RunCpuCore, std::ref(*cpu_cores[index + 1]));
- thread_to_cpu[cpu_core_threads[index]->get_id()] = cpu_cores[index + 1].get();
- }
- }
-
+ cpu_core_manager.Initialize(system);
+ is_powered_on = true;
LOG_DEBUG(Core, "Initialized OK");
// Reset counters and set time origin to current frame
@@ -184,7 +127,8 @@ struct System::Impl {
return ResultStatus::Success;
}
- ResultStatus Load(Frontend::EmuWindow& emu_window, const std::string& filepath) {
+ ResultStatus Load(System& system, Frontend::EmuWindow& emu_window,
+ const std::string& filepath) {
app_loader = Loader::GetLoader(GetGameFileFromPath(virtual_filesystem, filepath));
if (!app_loader) {
@@ -201,7 +145,7 @@ struct System::Impl {
return ResultStatus::ErrorSystemMode;
}
- ResultStatus init_result{Init(emu_window)};
+ ResultStatus init_result{Init(system, emu_window)};
if (init_result != ResultStatus::Success) {
LOG_CRITICAL(Core, "Failed to initialize system (Error {})!",
static_cast<int>(init_result));
@@ -231,6 +175,8 @@ struct System::Impl {
Telemetry().AddField(Telemetry::FieldType::Performance, "Shutdown_Frametime",
perf_results.frametime * 1000.0);
+ is_powered_on = false;
+
// Shutdown emulation session
renderer.reset();
GDBStub::Shutdown();
@@ -240,19 +186,7 @@ struct System::Impl {
gpu_core.reset();
// Close all CPU/threading state
- cpu_barrier->NotifyEnd();
- if (Settings::values.use_multi_core) {
- for (auto& thread : cpu_core_threads) {
- thread->join();
- thread.reset();
- }
- }
- thread_to_cpu.clear();
- for (auto& cpu_core : cpu_cores) {
- cpu_core.reset();
- }
- cpu_exclusive_monitor.reset();
- cpu_barrier.reset();
+ cpu_core_manager.Shutdown();
// Shutdown kernel and core timing
kernel.Shutdown();
@@ -289,11 +223,8 @@ struct System::Impl {
std::unique_ptr<VideoCore::RendererBase> renderer;
std::unique_ptr<Tegra::GPU> gpu_core;
std::shared_ptr<Tegra::DebugContext> debug_context;
- std::unique_ptr<ExclusiveMonitor> cpu_exclusive_monitor;
- std::unique_ptr<CpuBarrier> cpu_barrier;
- std::array<std::unique_ptr<Cpu>, NUM_CPU_CORES> cpu_cores;
- std::array<std::unique_ptr<std::thread>, NUM_CPU_CORES - 1> cpu_core_threads;
- std::size_t active_core{}; ///< Active core, only used in single thread mode
+ CpuCoreManager cpu_core_manager;
+ bool is_powered_on = false;
/// Frontend applets
std::unique_ptr<Core::Frontend::SoftwareKeyboardApplet> software_keyboard;
@@ -307,9 +238,6 @@ struct System::Impl {
ResultStatus status = ResultStatus::Success;
std::string status_details = "";
- /// Map of guest threads to CPU cores
- std::map<std::thread::id, Cpu*> thread_to_cpu;
-
Core::PerfStats perf_stats;
Core::FrameLimiter frame_limiter;
};
@@ -334,17 +262,15 @@ System::ResultStatus System::SingleStep() {
}
void System::InvalidateCpuInstructionCaches() {
- for (auto& cpu : impl->cpu_cores) {
- cpu->ArmInterface().ClearInstructionCache();
- }
+ impl->cpu_core_manager.InvalidateAllInstructionCaches();
}
System::ResultStatus System::Load(Frontend::EmuWindow& emu_window, const std::string& filepath) {
- return impl->Load(emu_window, filepath);
+ return impl->Load(*this, emu_window, filepath);
}
bool System::IsPoweredOn() const {
- return impl->cpu_barrier && impl->cpu_barrier->IsAlive();
+ return impl->is_powered_on;
}
void System::PrepareReschedule() {
@@ -408,21 +334,20 @@ const ARM_Interface& System::ArmInterface(std::size_t core_index) const {
}
Cpu& System::CpuCore(std::size_t core_index) {
- ASSERT(core_index < NUM_CPU_CORES);
- return *impl->cpu_cores[core_index];
+ return impl->cpu_core_manager.GetCore(core_index);
}
const Cpu& System::CpuCore(std::size_t core_index) const {
ASSERT(core_index < NUM_CPU_CORES);
- return *impl->cpu_cores[core_index];
+ return impl->cpu_core_manager.GetCore(core_index);
}
ExclusiveMonitor& System::Monitor() {
- return *impl->cpu_exclusive_monitor;
+ return impl->cpu_core_manager.GetExclusiveMonitor();
}
const ExclusiveMonitor& System::Monitor() const {
- return *impl->cpu_exclusive_monitor;
+ return impl->cpu_core_manager.GetExclusiveMonitor();
}
Tegra::GPU& System::GPU() {
@@ -506,7 +431,7 @@ const Core::Frontend::SoftwareKeyboardApplet& System::GetSoftwareKeyboard() cons
}
System::ResultStatus System::Init(Frontend::EmuWindow& emu_window) {
- return impl->Init(emu_window);
+ return impl->Init(*this, emu_window);
}
void System::Shutdown() {
diff --git a/src/core/cpu_core_manager.cpp b/src/core/cpu_core_manager.cpp
new file mode 100644
index 000000000..769a6fefa
--- /dev/null
+++ b/src/core/cpu_core_manager.cpp
@@ -0,0 +1,142 @@
+// Copyright 2018 yuzu emulator team
+// Licensed under GPLv2 or any later version
+// Refer to the license.txt file included.
+
+#include "common/assert.h"
+#include "core/arm/exclusive_monitor.h"
+#include "core/core.h"
+#include "core/core_cpu.h"
+#include "core/cpu_core_manager.h"
+#include "core/gdbstub/gdbstub.h"
+#include "core/settings.h"
+
+namespace Core {
+namespace {
+void RunCpuCore(const System& system, Cpu& cpu_state) {
+ while (system.IsPoweredOn()) {
+ cpu_state.RunLoop(true);
+ }
+}
+} // Anonymous namespace
+
+CpuCoreManager::CpuCoreManager() = default;
+CpuCoreManager::~CpuCoreManager() = default;
+
+void CpuCoreManager::Initialize(System& system) {
+ barrier = std::make_unique<CpuBarrier>();
+ exclusive_monitor = Cpu::MakeExclusiveMonitor(cores.size());
+
+ for (std::size_t index = 0; index < cores.size(); ++index) {
+ cores[index] = std::make_unique<Cpu>(*exclusive_monitor, *barrier, index);
+ }
+
+ // Create threads for CPU cores 1-3, and build thread_to_cpu map
+ // CPU core 0 is run on the main thread
+ thread_to_cpu[std::this_thread::get_id()] = cores[0].get();
+ if (!Settings::values.use_multi_core) {
+ return;
+ }
+
+ for (std::size_t index = 0; index < core_threads.size(); ++index) {
+ core_threads[index] = std::make_unique<std::thread>(RunCpuCore, std::cref(system),
+ std::ref(*cores[index + 1]));
+ thread_to_cpu[core_threads[index]->get_id()] = cores[index + 1].get();
+ }
+}
+
+void CpuCoreManager::Shutdown() {
+ barrier->NotifyEnd();
+ if (Settings::values.use_multi_core) {
+ for (auto& thread : core_threads) {
+ thread->join();
+ thread.reset();
+ }
+ }
+
+ thread_to_cpu.clear();
+ for (auto& cpu_core : cores) {
+ cpu_core.reset();
+ }
+
+ exclusive_monitor.reset();
+ barrier.reset();
+}
+
+Cpu& CpuCoreManager::GetCore(std::size_t index) {
+ return *cores.at(index);
+}
+
+const Cpu& CpuCoreManager::GetCore(std::size_t index) const {
+ return *cores.at(index);
+}
+
+ExclusiveMonitor& CpuCoreManager::GetExclusiveMonitor() {
+ return *exclusive_monitor;
+}
+
+const ExclusiveMonitor& CpuCoreManager::GetExclusiveMonitor() const {
+ return *exclusive_monitor;
+}
+
+Cpu& CpuCoreManager::GetCurrentCore() {
+ if (Settings::values.use_multi_core) {
+ const auto& search = thread_to_cpu.find(std::this_thread::get_id());
+ ASSERT(search != thread_to_cpu.end());
+ ASSERT(search->second);
+ return *search->second;
+ }
+
+ // Otherwise, use single-threaded mode active_core variable
+ return *cores[active_core];
+}
+
+const Cpu& CpuCoreManager::GetCurrentCore() const {
+ if (Settings::values.use_multi_core) {
+ const auto& search = thread_to_cpu.find(std::this_thread::get_id());
+ ASSERT(search != thread_to_cpu.end());
+ ASSERT(search->second);
+ return *search->second;
+ }
+
+ // Otherwise, use single-threaded mode active_core variable
+ return *cores[active_core];
+}
+
+void CpuCoreManager::RunLoop(bool tight_loop) {
+ // Update thread_to_cpu in case Core 0 is run from a different host thread
+ thread_to_cpu[std::this_thread::get_id()] = cores[0].get();
+
+ if (GDBStub::IsServerEnabled()) {
+ GDBStub::HandlePacket();
+
+ // If the loop is halted and we want to step, use a tiny (1) number of instructions to
+ // execute. Otherwise, get out of the loop function.
+ if (GDBStub::GetCpuHaltFlag()) {
+ if (GDBStub::GetCpuStepFlag()) {
+ tight_loop = false;
+ } else {
+ return;
+ }
+ }
+ }
+
+ for (active_core = 0; active_core < NUM_CPU_CORES; ++active_core) {
+ cores[active_core]->RunLoop(tight_loop);
+ if (Settings::values.use_multi_core) {
+ // Cores 1-3 are run on other threads in this mode
+ break;
+ }
+ }
+
+ if (GDBStub::IsServerEnabled()) {
+ GDBStub::SetCpuStepFlag(false);
+ }
+}
+
+void CpuCoreManager::InvalidateAllInstructionCaches() {
+ for (auto& cpu : cores) {
+ cpu->ArmInterface().ClearInstructionCache();
+ }
+}
+
+} // namespace Core
diff --git a/src/core/cpu_core_manager.h b/src/core/cpu_core_manager.h
new file mode 100644
index 000000000..a4d70ec56
--- /dev/null
+++ b/src/core/cpu_core_manager.h
@@ -0,0 +1,59 @@
+// Copyright 2018 yuzu emulator team
+// Licensed under GPLv2 or any later version
+// Refer to the license.txt file included.
+
+#pragma once
+
+#include <array>
+#include <map>
+#include <memory>
+#include <thread>
+
+namespace Core {
+
+class Cpu;
+class CpuBarrier;
+class ExclusiveMonitor;
+class System;
+
+class CpuCoreManager {
+public:
+ CpuCoreManager();
+ CpuCoreManager(const CpuCoreManager&) = delete;
+ CpuCoreManager(CpuCoreManager&&) = delete;
+
+ ~CpuCoreManager();
+
+ CpuCoreManager& operator=(const CpuCoreManager&) = delete;
+ CpuCoreManager& operator=(CpuCoreManager&&) = delete;
+
+ void Initialize(System& system);
+ void Shutdown();
+
+ Cpu& GetCore(std::size_t index);
+ const Cpu& GetCore(std::size_t index) const;
+
+ Cpu& GetCurrentCore();
+ const Cpu& GetCurrentCore() const;
+
+ ExclusiveMonitor& GetExclusiveMonitor();
+ const ExclusiveMonitor& GetExclusiveMonitor() const;
+
+ void RunLoop(bool tight_loop);
+
+ void InvalidateAllInstructionCaches();
+
+private:
+ static constexpr std::size_t NUM_CPU_CORES = 4;
+
+ std::unique_ptr<ExclusiveMonitor> exclusive_monitor;
+ std::unique_ptr<CpuBarrier> barrier;
+ std::array<std::unique_ptr<Cpu>, NUM_CPU_CORES> cores;
+ std::array<std::unique_ptr<std::thread>, NUM_CPU_CORES - 1> core_threads;
+ std::size_t active_core{}; ///< Active core, only used in single thread mode
+
+ /// Map of guest threads to CPU cores
+ std::map<std::thread::id, Cpu*> thread_to_cpu;
+};
+
+} // namespace Core
diff --git a/src/core/hle/kernel/handle_table.cpp b/src/core/hle/kernel/handle_table.cpp
index 5ee5c05e3..1bf79b692 100644
--- a/src/core/hle/kernel/handle_table.cpp
+++ b/src/core/hle/kernel/handle_table.cpp
@@ -12,12 +12,23 @@
#include "core/hle/kernel/thread.h"
namespace Kernel {
+namespace {
+constexpr u16 GetSlot(Handle handle) {
+ return handle >> 15;
+}
+
+constexpr u16 GetGeneration(Handle handle) {
+ return handle & 0x7FFF;
+}
+} // Anonymous namespace
HandleTable::HandleTable() {
next_generation = 1;
Clear();
}
+HandleTable::~HandleTable() = default;
+
ResultVal<Handle> HandleTable::Create(SharedPtr<Object> obj) {
DEBUG_ASSERT(obj != nullptr);
diff --git a/src/core/hle/kernel/handle_table.h b/src/core/hle/kernel/handle_table.h
index 9e2f33e8a..e3f3e3fb8 100644
--- a/src/core/hle/kernel/handle_table.h
+++ b/src/core/hle/kernel/handle_table.h
@@ -43,6 +43,7 @@ enum KernelHandle : Handle {
class HandleTable final : NonCopyable {
public:
HandleTable();
+ ~HandleTable();
/**
* Allocates a handle for the given object.
@@ -89,18 +90,8 @@ public:
void Clear();
private:
- /**
- * This is the maximum limit of handles allowed per process in CTR-OS. It can be further
- * reduced by ExHeader values, but this is not emulated here.
- */
- static const std::size_t MAX_COUNT = 4096;
-
- static u16 GetSlot(Handle handle) {
- return handle >> 15;
- }
- static u16 GetGeneration(Handle handle) {
- return handle & 0x7FFF;
- }
+ /// This is the maximum limit of handles allowed per process in Horizon
+ static constexpr std::size_t MAX_COUNT = 1024;
/// Stores the Object referenced by the handle or null if the slot is empty.
std::array<SharedPtr<Object>, MAX_COUNT> objects;
diff --git a/src/core/hle/service/audio/audout_u.cpp b/src/core/hle/service/audio/audout_u.cpp
index ff1edefbb..23e1f1165 100644
--- a/src/core/hle/service/audio/audout_u.cpp
+++ b/src/core/hle/service/audio/audout_u.cpp
@@ -44,8 +44,10 @@ enum class AudioState : u32 {
class IAudioOut final : public ServiceFramework<IAudioOut> {
public:
- IAudioOut(AudoutParams audio_params, AudioCore::AudioOut& audio_core)
- : ServiceFramework("IAudioOut"), audio_core(audio_core), audio_params(audio_params) {
+ IAudioOut(AudoutParams audio_params, AudioCore::AudioOut& audio_core, std::string&& device_name,
+ std::string&& unique_name)
+ : ServiceFramework("IAudioOut"), audio_core(audio_core), audio_params(audio_params),
+ device_name(std::move(device_name)) {
static const FunctionInfo functions[] = {
{0, &IAudioOut::GetAudioOutState, "GetAudioOutState"},
@@ -69,7 +71,7 @@ public:
Kernel::Event::Create(kernel, Kernel::ResetType::Sticky, "IAudioOutBufferReleased");
stream = audio_core.OpenStream(audio_params.sample_rate, audio_params.channel_count,
- "IAudioOut", [=]() { buffer_event->Signal(); });
+ std::move(unique_name), [=]() { buffer_event->Signal(); });
}
private:
@@ -177,6 +179,7 @@ private:
AudioCore::AudioOut& audio_core;
AudioCore::StreamPtr stream;
+ std::string device_name;
AudoutParams audio_params{};
@@ -199,7 +202,15 @@ void AudOutU::ListAudioOutsImpl(Kernel::HLERequestContext& ctx) {
void AudOutU::OpenAudioOutImpl(Kernel::HLERequestContext& ctx) {
LOG_DEBUG(Service_Audio, "called");
- ctx.WriteBuffer(DefaultDevice);
+ const auto device_name_data{ctx.ReadBuffer()};
+ std::string device_name;
+ if (device_name_data[0] != '\0') {
+ device_name.assign(device_name_data.begin(), device_name_data.end());
+ } else {
+ device_name.assign(DefaultDevice.begin(), DefaultDevice.end());
+ }
+ ctx.WriteBuffer(device_name);
+
IPC::RequestParser rp{ctx};
auto params{rp.PopRaw<AudoutParams>()};
if (params.channel_count <= 2) {
@@ -212,10 +223,9 @@ void AudOutU::OpenAudioOutImpl(Kernel::HLERequestContext& ctx) {
params.sample_rate = DefaultSampleRate;
}
- // TODO(bunnei): Support more than one IAudioOut interface. When we add this, ListAudioOutsImpl
- // will likely need to be updated as well.
- ASSERT_MSG(!audio_out_interface, "Unimplemented");
- audio_out_interface = std::make_shared<IAudioOut>(params, *audio_core);
+ std::string unique_name{fmt::format("{}-{}", device_name, audio_out_interfaces.size())};
+ auto audio_out_interface = std::make_shared<IAudioOut>(
+ params, *audio_core, std::move(device_name), std::move(unique_name));
IPC::ResponseBuilder rb{ctx, 6, 0, 1};
rb.Push(RESULT_SUCCESS);
@@ -224,6 +234,8 @@ void AudOutU::OpenAudioOutImpl(Kernel::HLERequestContext& ctx) {
rb.Push<u32>(static_cast<u32>(AudioCore::Codec::PcmFormat::Int16));
rb.Push<u32>(static_cast<u32>(AudioState::Stopped));
rb.PushIpcInterface<Audio::IAudioOut>(audio_out_interface);
+
+ audio_out_interfaces.push_back(std::move(audio_out_interface));
}
AudOutU::AudOutU() : ServiceFramework("audout:u") {
diff --git a/src/core/hle/service/audio/audout_u.h b/src/core/hle/service/audio/audout_u.h
index dcaf64708..aed4c43b2 100644
--- a/src/core/hle/service/audio/audout_u.h
+++ b/src/core/hle/service/audio/audout_u.h
@@ -4,6 +4,7 @@
#pragma once
+#include <vector>
#include "core/hle/service/service.h"
namespace AudioCore {
@@ -24,7 +25,7 @@ public:
~AudOutU() override;
private:
- std::shared_ptr<IAudioOut> audio_out_interface;
+ std::vector<std::shared_ptr<IAudioOut>> audio_out_interfaces;
std::unique_ptr<AudioCore::AudioOut> audio_core;
void ListAudioOutsImpl(Kernel::HLERequestContext& ctx);
diff --git a/src/core/hle/service/hid/controllers/debug_pad.cpp b/src/core/hle/service/hid/controllers/debug_pad.cpp
index e76c83aee..c22357d8c 100644
--- a/src/core/hle/service/hid/controllers/debug_pad.cpp
+++ b/src/core/hle/service/hid/controllers/debug_pad.cpp
@@ -71,8 +71,9 @@ void Controller_DebugPad::OnUpdate(u8* data, std::size_t size) {
void Controller_DebugPad::OnLoadInputDevices() {
std::transform(Settings::values.debug_pad_buttons.begin(),
- Settings::values.debug_pad_buttons.end(), buttons.begin(),
- Input::CreateDevice<Input::ButtonDevice>);
+ Settings::values.debug_pad_buttons.begin() +
+ Settings::NativeButton::NUM_BUTTONS_HID,
+ buttons.begin(), Input::CreateDevice<Input::ButtonDevice>);
std::transform(Settings::values.debug_pad_analogs.begin(),
Settings::values.debug_pad_analogs.end(), analogs.begin(),
Input::CreateDevice<Input::AnalogDevice>);
diff --git a/src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.cpp b/src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.cpp
index 7a88ae029..792d26e52 100644
--- a/src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.cpp
+++ b/src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.cpp
@@ -5,6 +5,8 @@
#include <cstring>
#include "common/assert.h"
#include "common/logging/log.h"
+#include "core/core_timing.h"
+#include "core/core_timing_util.h"
#include "core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.h"
namespace Service::Nvidia::Devices {
@@ -33,6 +35,8 @@ u32 nvhost_ctrl_gpu::ioctl(Ioctl command, const std::vector<u8>& input, std::vec
return ZBCQueryTable(input, output);
case IoctlCommand::IocFlushL2:
return FlushL2(input, output);
+ case IoctlCommand::IocGetGpuTime:
+ return GetGpuTime(input, output);
}
UNIMPLEMENTED_MSG("Unimplemented ioctl");
return 0;
@@ -169,4 +173,13 @@ u32 nvhost_ctrl_gpu::FlushL2(const std::vector<u8>& input, std::vector<u8>& outp
return 0;
}
+u32 nvhost_ctrl_gpu::GetGpuTime(const std::vector<u8>& input, std::vector<u8>& output) {
+ LOG_DEBUG(Service_NVDRV, "called");
+ IoctlGetGpuTime params{};
+ std::memcpy(&params, input.data(), input.size());
+ params.gpu_time = CoreTiming::cyclesToNs(CoreTiming::GetTicks());
+ std::memcpy(output.data(), &params, output.size());
+ return 0;
+}
+
} // namespace Service::Nvidia::Devices
diff --git a/src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.h b/src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.h
index 3bbf028ad..240435eea 100644
--- a/src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.h
+++ b/src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.h
@@ -156,6 +156,11 @@ private:
};
static_assert(sizeof(IoctlFlushL2) == 8, "IoctlFlushL2 is incorrect size");
+ struct IoctlGetGpuTime {
+ u64_le gpu_time;
+ };
+ static_assert(sizeof(IoctlGetGpuTime) == 8, "IoctlGetGpuTime is incorrect size");
+
u32 GetCharacteristics(const std::vector<u8>& input, std::vector<u8>& output);
u32 GetTPCMasks(const std::vector<u8>& input, std::vector<u8>& output);
u32 GetActiveSlotMask(const std::vector<u8>& input, std::vector<u8>& output);
@@ -164,6 +169,7 @@ private:
u32 ZBCSetTable(const std::vector<u8>& input, std::vector<u8>& output);
u32 ZBCQueryTable(const std::vector<u8>& input, std::vector<u8>& output);
u32 FlushL2(const std::vector<u8>& input, std::vector<u8>& output);
+ u32 GetGpuTime(const std::vector<u8>& input, std::vector<u8>& output);
};
} // namespace Service::Nvidia::Devices
diff --git a/src/video_core/engines/maxwell_3d.h b/src/video_core/engines/maxwell_3d.h
index 9e480dc39..eff6abd55 100644
--- a/src/video_core/engines/maxwell_3d.h
+++ b/src/video_core/engines/maxwell_3d.h
@@ -389,6 +389,13 @@ public:
ReverseSubtract = 3,
Min = 4,
Max = 5,
+
+ // These values are used by Nouveau and some games.
+ AddGL = 0x8006,
+ SubtractGL = 0x8007,
+ ReverseSubtractGL = 0x8008,
+ MinGL = 0x800a,
+ MaxGL = 0x800b
};
enum class Factor : u32 {
diff --git a/src/video_core/engines/shader_bytecode.h b/src/video_core/engines/shader_bytecode.h
index 83a6fd875..c5f502ce1 100644
--- a/src/video_core/engines/shader_bytecode.h
+++ b/src/video_core/engines/shader_bytecode.h
@@ -153,6 +153,7 @@ enum class PredCondition : u64 {
NotEqual = 5,
GreaterEqual = 6,
LessThanWithNan = 9,
+ LessEqualWithNan = 11,
GreaterThanWithNan = 12,
NotEqualWithNan = 13,
GreaterEqualWithNan = 14,
diff --git a/src/video_core/macro_interpreter.cpp b/src/video_core/macro_interpreter.cpp
index 335a8d407..2b0dea5cd 100644
--- a/src/video_core/macro_interpreter.cpp
+++ b/src/video_core/macro_interpreter.cpp
@@ -35,6 +35,7 @@ void MacroInterpreter::Reset() {
// The next parameter index starts at 1, because $r1 already has the value of the first
// parameter.
next_parameter_index = 1;
+ carry_flag = false;
}
bool MacroInterpreter::Step(u32 offset, bool is_delay_slot) {
@@ -135,14 +136,28 @@ MacroInterpreter::Opcode MacroInterpreter::GetOpcode(u32 offset) const {
return {macro_memory[offset + pc / sizeof(u32)]};
}
-u32 MacroInterpreter::GetALUResult(ALUOperation operation, u32 src_a, u32 src_b) const {
+u32 MacroInterpreter::GetALUResult(ALUOperation operation, u32 src_a, u32 src_b) {
switch (operation) {
- case ALUOperation::Add:
- return src_a + src_b;
- // TODO(Subv): Implement AddWithCarry
- case ALUOperation::Subtract:
- return src_a - src_b;
- // TODO(Subv): Implement SubtractWithBorrow
+ case ALUOperation::Add: {
+ const u64 result{static_cast<u64>(src_a) + src_b};
+ carry_flag = result > 0xffffffff;
+ return static_cast<u32>(result);
+ }
+ case ALUOperation::AddWithCarry: {
+ const u64 result{static_cast<u64>(src_a) + src_b + (carry_flag ? 1ULL : 0ULL)};
+ carry_flag = result > 0xffffffff;
+ return static_cast<u32>(result);
+ }
+ case ALUOperation::Subtract: {
+ const u64 result{static_cast<u64>(src_a) - src_b};
+ carry_flag = result < 0x100000000;
+ return static_cast<u32>(result);
+ }
+ case ALUOperation::SubtractWithBorrow: {
+ const u64 result{static_cast<u64>(src_a) - src_b - (carry_flag ? 0ULL : 1ULL)};
+ carry_flag = result < 0x100000000;
+ return static_cast<u32>(result);
+ }
case ALUOperation::Xor:
return src_a ^ src_b;
case ALUOperation::Or:
diff --git a/src/video_core/macro_interpreter.h b/src/video_core/macro_interpreter.h
index 62d1ce289..cde360288 100644
--- a/src/video_core/macro_interpreter.h
+++ b/src/video_core/macro_interpreter.h
@@ -117,7 +117,7 @@ private:
bool Step(u32 offset, bool is_delay_slot);
/// Calculates the result of an ALU operation. src_a OP src_b;
- u32 GetALUResult(ALUOperation operation, u32 src_a, u32 src_b) const;
+ u32 GetALUResult(ALUOperation operation, u32 src_a, u32 src_b);
/// Performs the result operation on the input result and stores it in the specified register
/// (if necessary).
@@ -165,5 +165,7 @@ private:
std::vector<u32> parameters;
/// Index of the next parameter that will be fetched by the 'parm' instruction.
u32 next_parameter_index = 0;
+
+ bool carry_flag{};
};
} // namespace Tegra
diff --git a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp
index 9ca82c06c..b994e89dd 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp
+++ b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp
@@ -1275,6 +1275,31 @@ Surface RasterizerCacheOpenGL::GetUncachedSurface(const SurfaceParams& params) {
return surface;
}
+void RasterizerCacheOpenGL::FastLayeredCopySurface(const Surface& src_surface,
+ const Surface& dst_surface) {
+ const auto& init_params{src_surface->GetSurfaceParams()};
+ const auto& dst_params{dst_surface->GetSurfaceParams()};
+ VAddr address = init_params.addr;
+ const std::size_t layer_size = dst_params.LayerMemorySize();
+ for (u32 layer = 0; layer < dst_params.depth; layer++) {
+ for (u32 mipmap = 0; mipmap < dst_params.max_mip_level; mipmap++) {
+ const VAddr sub_address = address + dst_params.GetMipmapLevelOffset(mipmap);
+ const Surface& copy = TryGet(sub_address);
+ if (!copy)
+ continue;
+ const auto& src_params{copy->GetSurfaceParams()};
+ const u32 width{std::min(src_params.width, dst_params.MipWidth(mipmap))};
+ const u32 height{std::min(src_params.height, dst_params.MipHeight(mipmap))};
+
+ glCopyImageSubData(copy->Texture().handle, SurfaceTargetToGL(src_params.target), 0, 0,
+ 0, 0, dst_surface->Texture().handle,
+ SurfaceTargetToGL(dst_params.target), mipmap, 0, 0, layer, width,
+ height, 1);
+ }
+ address += layer_size;
+ }
+}
+
void RasterizerCacheOpenGL::FermiCopySurface(
const Tegra::Engines::Fermi2D::Regs::Surface& src_config,
const Tegra::Engines::Fermi2D::Regs::Surface& dst_config) {
@@ -1340,11 +1365,13 @@ Surface RasterizerCacheOpenGL::RecreateSurface(const Surface& old_surface,
CopySurface(old_surface, new_surface, copy_pbo.handle);
}
break;
- case SurfaceTarget::TextureCubemap:
case SurfaceTarget::Texture3D:
+ AccurateCopySurface(old_surface, new_surface);
+ break;
+ case SurfaceTarget::TextureCubemap:
case SurfaceTarget::Texture2DArray:
case SurfaceTarget::TextureCubeArray:
- AccurateCopySurface(old_surface, new_surface);
+ FastLayeredCopySurface(old_surface, new_surface);
break;
default:
LOG_CRITICAL(Render_OpenGL, "Unimplemented surface target={}",
diff --git a/src/video_core/renderer_opengl/gl_rasterizer_cache.h b/src/video_core/renderer_opengl/gl_rasterizer_cache.h
index 494f6b903..9ac79c5a4 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer_cache.h
+++ b/src/video_core/renderer_opengl/gl_rasterizer_cache.h
@@ -350,6 +350,7 @@ private:
/// Performs a slow but accurate surface copy, flushing to RAM and reinterpreting the data
void AccurateCopySurface(const Surface& src_surface, const Surface& dst_surface);
+ void FastLayeredCopySurface(const Surface& src_surface, const Surface& dst_surface);
/// The surface reserve is a "backup" cache, this is where we put unique surfaces that have
/// previously been used. This is to prevent surfaces from being constantly created and
diff --git a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp
index 90a88b91a..ba80e5832 100644
--- a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp
+++ b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp
@@ -1059,11 +1059,17 @@ private:
const std::string& op_a, const std::string& op_b) const {
using Tegra::Shader::PredCondition;
static const std::unordered_map<PredCondition, const char*> PredicateComparisonStrings = {
- {PredCondition::LessThan, "<"}, {PredCondition::Equal, "=="},
- {PredCondition::LessEqual, "<="}, {PredCondition::GreaterThan, ">"},
- {PredCondition::NotEqual, "!="}, {PredCondition::GreaterEqual, ">="},
- {PredCondition::LessThanWithNan, "<"}, {PredCondition::NotEqualWithNan, "!="},
- {PredCondition::GreaterThanWithNan, ">"}, {PredCondition::GreaterEqualWithNan, ">="}};
+ {PredCondition::LessThan, "<"},
+ {PredCondition::Equal, "=="},
+ {PredCondition::LessEqual, "<="},
+ {PredCondition::GreaterThan, ">"},
+ {PredCondition::NotEqual, "!="},
+ {PredCondition::GreaterEqual, ">="},
+ {PredCondition::LessThanWithNan, "<"},
+ {PredCondition::NotEqualWithNan, "!="},
+ {PredCondition::LessEqualWithNan, "<="},
+ {PredCondition::GreaterThanWithNan, ">"},
+ {PredCondition::GreaterEqualWithNan, ">="}};
const auto& comparison{PredicateComparisonStrings.find(condition)};
UNIMPLEMENTED_IF_MSG(comparison == PredicateComparisonStrings.end(),
@@ -1072,6 +1078,7 @@ private:
std::string predicate{'(' + op_a + ") " + comparison->second + " (" + op_b + ')'};
if (condition == PredCondition::LessThanWithNan ||
condition == PredCondition::NotEqualWithNan ||
+ condition == PredCondition::LessEqualWithNan ||
condition == PredCondition::GreaterThanWithNan ||
condition == PredCondition::GreaterEqualWithNan) {
predicate += " || isnan(" + op_a + ") || isnan(" + op_b + ')';
@@ -1243,14 +1250,7 @@ private:
regs.SetRegisterToInteger(dest, true, 0, result, 1, 1);
}
- void WriteTexsInstruction(const Instruction& instr, const std::string& coord,
- const std::string& texture) {
- // Add an extra scope and declare the texture coords inside to prevent
- // overwriting them in case they are used as outputs of the texs instruction.
- shader.AddLine('{');
- ++shader.scope;
- shader.AddLine(coord);
-
+ void WriteTexsInstruction(const Instruction& instr, const std::string& texture) {
// TEXS has two destination registers and a swizzle. The first two elements in the swizzle
// go into gpr0+0 and gpr0+1, and the rest goes into gpr28+0 and gpr28+1
@@ -1273,9 +1273,6 @@ private:
++written_components;
}
-
- --shader.scope;
- shader.AddLine('}');
}
static u32 TextureCoordinates(Tegra::Shader::TextureType texture_type) {
@@ -2563,7 +2560,6 @@ private:
}
// TODO: make sure coordinates are always indexed to gpr8 and gpr20 is always bias
// or lod.
- std::string op_c;
const std::string sampler =
GetSampler(instr.sampler, texture_type, is_array, depth_compare);
@@ -2586,27 +2582,35 @@ private:
}
case Tegra::Shader::TextureProcessMode::LB:
case Tegra::Shader::TextureProcessMode::LBA: {
- if (depth_compare) {
- if (is_array)
- op_c = regs.GetRegisterAsFloat(instr.gpr20.Value() + 2);
- else
- op_c = regs.GetRegisterAsFloat(instr.gpr20.Value() + 1);
- } else {
- op_c = regs.GetRegisterAsFloat(instr.gpr20);
- }
+ const std::string bias = [&]() {
+ if (depth_compare) {
+ if (is_array)
+ return regs.GetRegisterAsFloat(instr.gpr20.Value() + 2);
+ else
+ return regs.GetRegisterAsFloat(instr.gpr20.Value() + 1);
+ } else {
+ return regs.GetRegisterAsFloat(instr.gpr20);
+ }
+ }();
+ shader.AddLine("float bias = " + bias + ';');
+
// TODO: Figure if A suffix changes the equation at all.
- texture = "texture(" + sampler + ", coords, " + op_c + ')';
+ texture = "texture(" + sampler + ", coords, bias)";
break;
}
case Tegra::Shader::TextureProcessMode::LL:
case Tegra::Shader::TextureProcessMode::LLA: {
- if (num_coordinates <= 2) {
- op_c = regs.GetRegisterAsFloat(instr.gpr20);
- } else {
- op_c = regs.GetRegisterAsFloat(instr.gpr20.Value() + 1);
- }
+ const std::string lod = [&]() {
+ if (num_coordinates <= 2) {
+ return regs.GetRegisterAsFloat(instr.gpr20);
+ } else {
+ return regs.GetRegisterAsFloat(instr.gpr20.Value() + 1);
+ }
+ }();
+ shader.AddLine("float lod = " + lod + ';');
+
// TODO: Figure if A suffix changes the equation at all.
- texture = "textureLod(" + sampler + ", coords, " + op_c + ')';
+ texture = "textureLod(" + sampler + ", coords, lod)";
break;
}
default: {
@@ -2633,7 +2637,6 @@ private:
break;
}
case OpCode::Id::TEXS: {
- std::string coord;
Tegra::Shader::TextureType texture_type{instr.texs.GetTextureType()};
bool is_array{instr.texs.IsArrayTexture()};
@@ -2646,17 +2649,21 @@ private:
if (depth_compare)
num_coordinates += 1;
+ // Scope to avoid variable name overlaps.
+ shader.AddLine('{');
+ ++shader.scope;
+
switch (num_coordinates) {
case 2: {
if (is_array) {
const std::string index = regs.GetRegisterAsInteger(instr.gpr8);
const std::string x = regs.GetRegisterAsFloat(instr.gpr8.Value() + 1);
const std::string y = regs.GetRegisterAsFloat(instr.gpr20);
- coord = "vec3 coords = vec3(" + x + ", " + y + ", " + index + ");";
+ shader.AddLine("vec3 coords = vec3(" + x + ", " + y + ", " + index + ");");
} else {
const std::string x = regs.GetRegisterAsFloat(instr.gpr8);
const std::string y = regs.GetRegisterAsFloat(instr.gpr20);
- coord = "vec2 coords = vec2(" + x + ", " + y + ");";
+ shader.AddLine("vec2 coords = vec2(" + x + ", " + y + ");");
}
break;
}
@@ -2666,13 +2673,13 @@ private:
const std::string x = regs.GetRegisterAsFloat(instr.gpr8.Value() + 1);
const std::string y = regs.GetRegisterAsFloat(instr.gpr8.Value() + 2);
const std::string z = regs.GetRegisterAsFloat(instr.gpr20);
- coord =
- "vec4 coords = vec4(" + x + ", " + y + ", " + z + ", " + index + ");";
+ shader.AddLine("vec4 coords = vec4(" + x + ", " + y + ", " + z + ", " +
+ index + ");");
} else {
const std::string x = regs.GetRegisterAsFloat(instr.gpr8);
const std::string y = regs.GetRegisterAsFloat(instr.gpr8.Value() + 1);
const std::string z = regs.GetRegisterAsFloat(instr.gpr20);
- coord = "vec3 coords = vec3(" + x + ", " + y + ", " + z + ");";
+ shader.AddLine("vec3 coords = vec3(" + x + ", " + y + ", " + z + ");");
}
break;
}
@@ -2683,7 +2690,7 @@ private:
// Fallback to interpreting as a 2D texture for now
const std::string x = regs.GetRegisterAsFloat(instr.gpr8);
const std::string y = regs.GetRegisterAsFloat(instr.gpr20);
- coord = "vec2 coords = vec2(" + x + ", " + y + ");";
+ shader.AddLine("vec2 coords = vec2(" + x + ", " + y + ");");
texture_type = Tegra::Shader::TextureType::Texture2D;
is_array = false;
}
@@ -2715,14 +2722,16 @@ private:
}
}
if (!depth_compare) {
- WriteTexsInstruction(instr, coord, texture);
+ WriteTexsInstruction(instr, texture);
} else {
- WriteTexsInstruction(instr, coord, "vec4(" + texture + ')');
+ WriteTexsInstruction(instr, "vec4(" + texture + ')');
}
+
+ shader.AddLine('}');
+ --shader.scope;
break;
}
case OpCode::Id::TLDS: {
- std::string coord;
const Tegra::Shader::TextureType texture_type{instr.tlds.GetTextureType()};
const bool is_array{instr.tlds.IsArrayTexture()};
@@ -2736,12 +2745,16 @@ private:
UNIMPLEMENTED_IF_MSG(instr.tlds.UsesMiscMode(Tegra::Shader::TextureMiscMode::MZ),
"MZ is not implemented");
- u32 op_c_offset = 0;
+ u32 extra_op_offset = 0;
+
+ // Scope to avoid variable name overlaps.
+ shader.AddLine('{');
+ ++shader.scope;
switch (texture_type) {
case Tegra::Shader::TextureType::Texture1D: {
const std::string x = regs.GetRegisterAsInteger(instr.gpr8);
- coord = "int coords = " + x + ';';
+ shader.AddLine("int coords = " + x + ';');
break;
}
case Tegra::Shader::TextureType::Texture2D: {
@@ -2749,8 +2762,8 @@ private:
const std::string x = regs.GetRegisterAsInteger(instr.gpr8);
const std::string y = regs.GetRegisterAsInteger(instr.gpr20);
- coord = "ivec2 coords = ivec2(" + x + ", " + y + ");";
- op_c_offset = 1;
+ shader.AddLine("ivec2 coords = ivec2(" + x + ", " + y + ");");
+ extra_op_offset = 1;
break;
}
default:
@@ -2765,9 +2778,10 @@ private:
break;
}
case Tegra::Shader::TextureProcessMode::LL: {
- const std::string op_c =
- regs.GetRegisterAsInteger(instr.gpr20.Value() + op_c_offset);
- texture = "texelFetch(" + sampler + ", coords, " + op_c + ')';
+ shader.AddLine(
+ "float lod = " +
+ regs.GetRegisterAsInteger(instr.gpr20.Value() + extra_op_offset) + ';');
+ texture = "texelFetch(" + sampler + ", coords, lod)";
break;
}
default: {
@@ -2776,7 +2790,10 @@ private:
static_cast<u32>(instr.tlds.GetTextureProcessMode()));
}
}
- WriteTexsInstruction(instr, coord, texture);
+ WriteTexsInstruction(instr, texture);
+
+ --shader.scope;
+ shader.AddLine('}');
break;
}
case OpCode::Id::TLD4: {
@@ -2799,18 +2816,23 @@ private:
if (depth_compare)
num_coordinates += 1;
+ // Add an extra scope and declare the texture coords inside to prevent
+ // overwriting them in case they are used as outputs of the texs instruction.
+ shader.AddLine('{');
+ ++shader.scope;
+
switch (num_coordinates) {
case 2: {
const std::string x = regs.GetRegisterAsFloat(instr.gpr8);
const std::string y = regs.GetRegisterAsFloat(instr.gpr8.Value() + 1);
- coord = "vec2 coords = vec2(" + x + ", " + y + ");";
+ shader.AddLine("vec2 coords = vec2(" + x + ", " + y + ");");
break;
}
case 3: {
const std::string x = regs.GetRegisterAsFloat(instr.gpr8);
const std::string y = regs.GetRegisterAsFloat(instr.gpr8.Value() + 1);
const std::string z = regs.GetRegisterAsFloat(instr.gpr8.Value() + 2);
- coord = "vec3 coords = vec3(" + x + ", " + y + ", " + z + ");";
+ shader.AddLine("vec3 coords = vec3(" + x + ", " + y + ", " + z + ");");
break;
}
default:
@@ -2818,17 +2840,13 @@ private:
static_cast<u32>(num_coordinates));
const std::string x = regs.GetRegisterAsFloat(instr.gpr8);
const std::string y = regs.GetRegisterAsFloat(instr.gpr8.Value() + 1);
- coord = "vec2 coords = vec2(" + x + ", " + y + ");";
+ shader.AddLine("vec2 coords = vec2(" + x + ", " + y + ");");
texture_type = Tegra::Shader::TextureType::Texture2D;
}
const std::string sampler =
GetSampler(instr.sampler, texture_type, false, depth_compare);
- // Add an extra scope and declare the texture coords inside to prevent
- // overwriting them in case they are used as outputs of the texs instruction.
- shader.AddLine("{");
- ++shader.scope;
- shader.AddLine(coord);
+
const std::string texture = "textureGather(" + sampler + ", coords, " +
std::to_string(instr.tld4.component) + ')';
if (!depth_compare) {
@@ -2845,7 +2863,7 @@ private:
regs.SetRegisterToFloat(instr.gpr0, 0, texture, 1, 1, false);
}
--shader.scope;
- shader.AddLine("}");
+ shader.AddLine('}');
break;
}
case OpCode::Id::TLD4S: {
@@ -2856,6 +2874,10 @@ private:
instr.tld4s.UsesMiscMode(Tegra::Shader::TextureMiscMode::AOFFI),
"AOFFI is not implemented");
+ // Scope to avoid variable name overlaps.
+ shader.AddLine('{');
+ ++shader.scope;
+
const bool depth_compare =
instr.tld4s.UsesMiscMode(Tegra::Shader::TextureMiscMode::DC);
const std::string op_a = regs.GetRegisterAsFloat(instr.gpr8);
@@ -2863,28 +2885,33 @@ private:
// TODO(Subv): Figure out how the sampler type is encoded in the TLD4S instruction.
const std::string sampler = GetSampler(
instr.sampler, Tegra::Shader::TextureType::Texture2D, false, depth_compare);
- std::string coord;
if (!depth_compare) {
- coord = "vec2 coords = vec2(" + op_a + ", " + op_b + ");";
+ shader.AddLine("vec2 coords = vec2(" + op_a + ", " + op_b + ");");
} else {
// Note: TLD4S coordinate encoding works just like TEXS's
- const std::string op_c = regs.GetRegisterAsFloat(instr.gpr8.Value() + 1);
- coord = "vec3 coords = vec3(" + op_a + ", " + op_c + ", " + op_b + ");";
+ shader.AddLine(
+ "float op_y = " + regs.GetRegisterAsFloat(instr.gpr8.Value() + 1) + ';');
+ shader.AddLine("vec3 coords = vec3(" + op_a + ", op_y, " + op_b + ");");
}
const std::string texture = "textureGather(" + sampler + ", coords, " +
std::to_string(instr.tld4s.component) + ')';
if (!depth_compare) {
- WriteTexsInstruction(instr, coord, texture);
+ WriteTexsInstruction(instr, texture);
} else {
- WriteTexsInstruction(instr, coord, "vec4(" + texture + ')');
+ WriteTexsInstruction(instr, "vec4(" + texture + ')');
}
+
+ --shader.scope;
+ shader.AddLine('}');
break;
}
case OpCode::Id::TXQ: {
UNIMPLEMENTED_IF_MSG(instr.txq.UsesMiscMode(Tegra::Shader::TextureMiscMode::NODEP),
"NODEP is not implemented");
+ ++shader.scope;
+ shader.AddLine('{');
// TODO: the new commits on the texture refactor, change the way samplers work.
// Sadly, not all texture instructions specify the type of texture their sampler
// uses. This must be fixed at a later instance.
@@ -2892,8 +2919,14 @@ private:
GetSampler(instr.sampler, Tegra::Shader::TextureType::Texture2D, false, false);
switch (instr.txq.query_type) {
case Tegra::Shader::TextureQueryType::Dimension: {
- const std::string texture = "textureQueryLevels(" + sampler + ')';
- regs.SetRegisterToInteger(instr.gpr0, true, 0, texture, 1, 1);
+ const std::string texture = "textureSize(" + sampler + ", " +
+ regs.GetRegisterAsInteger(instr.gpr8) + ')';
+ const std::string mip_level = "textureQueryLevels(" + sampler + ')';
+ shader.AddLine("ivec2 sizes = " + texture + ';');
+ regs.SetRegisterToInteger(instr.gpr0, true, 0, "sizes.x", 1, 1);
+ regs.SetRegisterToInteger(instr.gpr0.Value() + 1, true, 0, "sizes.y", 1, 1);
+ regs.SetRegisterToInteger(instr.gpr0.Value() + 2, true, 0, "0", 1, 1);
+ regs.SetRegisterToInteger(instr.gpr0.Value() + 3, true, 0, mip_level, 1, 1);
break;
}
default: {
@@ -2901,6 +2934,8 @@ private:
static_cast<u32>(instr.txq.query_type.Value()));
}
}
+ --shader.scope;
+ shader.AddLine('}');
break;
}
case OpCode::Id::TMML: {
diff --git a/src/video_core/renderer_opengl/maxwell_to_gl.h b/src/video_core/renderer_opengl/maxwell_to_gl.h
index 065b3929c..a8833c06e 100644
--- a/src/video_core/renderer_opengl/maxwell_to_gl.h
+++ b/src/video_core/renderer_opengl/maxwell_to_gl.h
@@ -218,14 +218,19 @@ inline GLenum DepthCompareFunc(Tegra::Texture::DepthCompareFunc func) {
inline GLenum BlendEquation(Maxwell::Blend::Equation equation) {
switch (equation) {
case Maxwell::Blend::Equation::Add:
+ case Maxwell::Blend::Equation::AddGL:
return GL_FUNC_ADD;
case Maxwell::Blend::Equation::Subtract:
+ case Maxwell::Blend::Equation::SubtractGL:
return GL_FUNC_SUBTRACT;
case Maxwell::Blend::Equation::ReverseSubtract:
+ case Maxwell::Blend::Equation::ReverseSubtractGL:
return GL_FUNC_REVERSE_SUBTRACT;
case Maxwell::Blend::Equation::Min:
+ case Maxwell::Blend::Equation::MinGL:
return GL_MIN;
case Maxwell::Blend::Equation::Max:
+ case Maxwell::Blend::Equation::MaxGL:
return GL_MAX;
}
LOG_ERROR(Render_OpenGL, "Unimplemented blend equation={}", static_cast<u32>(equation));