summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/audio_core/time_stretch.cpp6
-rw-r--r--src/core/core.cpp30
-rw-r--r--src/core/core.h31
-rw-r--r--src/core/crypto/key_manager.cpp44
-rw-r--r--src/core/crypto/key_manager.h9
-rw-r--r--src/core/file_sys/content_archive.cpp33
-rw-r--r--src/core/file_sys/content_archive.h7
-rw-r--r--src/core/file_sys/ips_layer.cpp4
-rw-r--r--src/core/file_sys/patch_manager.cpp9
-rw-r--r--src/core/file_sys/registered_cache.cpp62
-rw-r--r--src/core/file_sys/registered_cache.h23
-rw-r--r--src/core/file_sys/vfs.cpp4
-rw-r--r--src/core/file_sys/vfs.h8
-rw-r--r--src/core/file_sys/vfs_offset.cpp4
-rw-r--r--src/core/file_sys/vfs_offset.h2
-rw-r--r--src/core/file_sys/vfs_static.h4
-rw-r--r--src/core/hle/ipc_helpers.h3
-rw-r--r--src/core/hle/kernel/hle_ipc.h8
-rw-r--r--src/core/hle/kernel/kernel.cpp4
-rw-r--r--src/core/hle/kernel/server_session.cpp4
-rw-r--r--src/core/hle/kernel/svc.cpp2
-rw-r--r--src/core/hle/kernel/thread.cpp8
-rw-r--r--src/core/hle/service/acc/profile_manager.cpp2
-rw-r--r--src/core/hle/service/am/am.cpp2
-rw-r--r--src/core/hle/service/nvflinger/buffer_queue.cpp8
-rw-r--r--src/core/hle/service/nvflinger/buffer_queue.h7
-rw-r--r--src/core/hle/service/nvflinger/nvflinger.cpp12
-rw-r--r--src/core/hle/service/vi/vi.cpp9
-rw-r--r--src/core/loader/loader.h5
-rw-r--r--src/core/memory.cpp2
-rw-r--r--src/core/memory_hook.h15
-rw-r--r--src/tests/core/arm/arm_test_common.cpp10
-rw-r--r--src/tests/core/arm/arm_test_common.h10
-rw-r--r--src/video_core/CMakeLists.txt2
-rw-r--r--src/video_core/command_processor.cpp2
-rw-r--r--src/video_core/engines/maxwell_3d.cpp10
-rw-r--r--src/video_core/engines/shader_bytecode.h8
-rw-r--r--src/video_core/macro_interpreter.cpp6
-rw-r--r--src/video_core/macro_interpreter.h5
-rw-r--r--src/video_core/memory_manager.cpp8
-rw-r--r--src/video_core/memory_manager.h7
-rw-r--r--src/video_core/renderer_base.h6
-rw-r--r--src/video_core/renderer_opengl/gl_buffer_cache.cpp2
-rw-r--r--src/video_core/renderer_opengl/gl_primitive_assembler.cpp2
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer.cpp12
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer.h5
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer_cache.cpp243
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer_cache.h89
-rw-r--r--src/video_core/renderer_opengl/gl_shader_cache.cpp5
-rw-r--r--src/video_core/renderer_opengl/gl_shader_decompiler.cpp112
-rw-r--r--src/video_core/renderer_opengl/gl_shader_decompiler.h8
-rw-r--r--src/video_core/renderer_opengl/gl_shader_gen.cpp8
-rw-r--r--src/video_core/renderer_opengl/maxwell_to_gl.h27
-rw-r--r--src/video_core/renderer_opengl/renderer_opengl.cpp11
-rw-r--r--src/video_core/renderer_opengl/renderer_opengl.h3
-rw-r--r--src/video_core/renderer_opengl/utils.cpp38
-rw-r--r--src/video_core/renderer_opengl/utils.h15
-rw-r--r--src/video_core/textures/decoders.h6
-rw-r--r--src/video_core/utils.h26
-rw-r--r--src/yuzu/configuration/configure_input.cpp2
-rw-r--r--src/yuzu/configuration/configure_input.h6
-rw-r--r--src/yuzu/configuration/configure_system.cpp8
-rw-r--r--src/yuzu/debugger/graphics/graphics_surface.cpp4
-rw-r--r--src/yuzu/main.cpp6
-rw-r--r--src/yuzu/main.h5
65 files changed, 657 insertions, 431 deletions
diff --git a/src/audio_core/time_stretch.cpp b/src/audio_core/time_stretch.cpp
index cee8b12dd..2fe0b3aef 100644
--- a/src/audio_core/time_stretch.cpp
+++ b/src/audio_core/time_stretch.cpp
@@ -32,10 +32,10 @@ std::size_t TimeStretcher::Process(const s16* in, std::size_t num_in, s16* out,
32 // We were given actual_samples number of samples, and num_samples were requested from us. 32 // We were given actual_samples number of samples, and num_samples were requested from us.
33 double current_ratio = static_cast<double>(num_in) / static_cast<double>(num_out); 33 double current_ratio = static_cast<double>(num_in) / static_cast<double>(num_out);
34 34
35 const double max_latency = 1.0; // seconds 35 const double max_latency = 0.25; // seconds
36 const double max_backlog = m_sample_rate * max_latency; 36 const double max_backlog = m_sample_rate * max_latency;
37 const double backlog_fullness = m_sound_touch.numSamples() / max_backlog; 37 const double backlog_fullness = m_sound_touch.numSamples() / max_backlog;
38 if (backlog_fullness > 5.0) { 38 if (backlog_fullness > 4.0) {
39 // Too many samples in backlog: Don't push anymore on 39 // Too many samples in backlog: Don't push anymore on
40 num_in = 0; 40 num_in = 0;
41 } 41 }
@@ -49,7 +49,7 @@ std::size_t TimeStretcher::Process(const s16* in, std::size_t num_in, s16* out,
49 49
50 // This low-pass filter smoothes out variance in the calculated stretch ratio. 50 // This low-pass filter smoothes out variance in the calculated stretch ratio.
51 // The time-scale determines how responsive this filter is. 51 // The time-scale determines how responsive this filter is.
52 constexpr double lpf_time_scale = 2.0; // seconds 52 constexpr double lpf_time_scale = 0.712; // seconds
53 const double lpf_gain = 1.0 - std::exp(-time_delta / lpf_time_scale); 53 const double lpf_gain = 1.0 - std::exp(-time_delta / lpf_time_scale);
54 m_stretch_ratio += lpf_gain * (current_ratio - m_stretch_ratio); 54 m_stretch_ratio += lpf_gain * (current_ratio - m_stretch_ratio);
55 55
diff --git a/src/core/core.cpp b/src/core/core.cpp
index 7cb86ed92..6d5b5a2d0 100644
--- a/src/core/core.cpp
+++ b/src/core/core.cpp
@@ -185,7 +185,7 @@ struct System::Impl {
185 LOG_CRITICAL(Core, "Failed to obtain loader for {}!", filepath); 185 LOG_CRITICAL(Core, "Failed to obtain loader for {}!", filepath);
186 return ResultStatus::ErrorGetLoader; 186 return ResultStatus::ErrorGetLoader;
187 } 187 }
188 std::pair<boost::optional<u32>, Loader::ResultStatus> system_mode = 188 std::pair<std::optional<u32>, Loader::ResultStatus> system_mode =
189 app_loader->LoadKernelSystemMode(); 189 app_loader->LoadKernelSystemMode();
190 190
191 if (system_mode.second != Loader::ResultStatus::Success) { 191 if (system_mode.second != Loader::ResultStatus::Success) {
@@ -312,6 +312,10 @@ Cpu& System::CurrentCpuCore() {
312 return impl->CurrentCpuCore(); 312 return impl->CurrentCpuCore();
313} 313}
314 314
315const Cpu& System::CurrentCpuCore() const {
316 return impl->CurrentCpuCore();
317}
318
315System::ResultStatus System::RunLoop(bool tight_loop) { 319System::ResultStatus System::RunLoop(bool tight_loop) {
316 return impl->RunLoop(tight_loop); 320 return impl->RunLoop(tight_loop);
317} 321}
@@ -342,7 +346,11 @@ PerfStatsResults System::GetAndResetPerfStats() {
342 return impl->GetAndResetPerfStats(); 346 return impl->GetAndResetPerfStats();
343} 347}
344 348
345Core::TelemetrySession& System::TelemetrySession() const { 349TelemetrySession& System::TelemetrySession() {
350 return *impl->telemetry_session;
351}
352
353const TelemetrySession& System::TelemetrySession() const {
346 return *impl->telemetry_session; 354 return *impl->telemetry_session;
347} 355}
348 356
@@ -350,7 +358,11 @@ ARM_Interface& System::CurrentArmInterface() {
350 return CurrentCpuCore().ArmInterface(); 358 return CurrentCpuCore().ArmInterface();
351} 359}
352 360
353std::size_t System::CurrentCoreIndex() { 361const ARM_Interface& System::CurrentArmInterface() const {
362 return CurrentCpuCore().ArmInterface();
363}
364
365std::size_t System::CurrentCoreIndex() const {
354 return CurrentCpuCore().CoreIndex(); 366 return CurrentCpuCore().CoreIndex();
355} 367}
356 368
@@ -358,6 +370,10 @@ Kernel::Scheduler& System::CurrentScheduler() {
358 return CurrentCpuCore().Scheduler(); 370 return CurrentCpuCore().Scheduler();
359} 371}
360 372
373const Kernel::Scheduler& System::CurrentScheduler() const {
374 return CurrentCpuCore().Scheduler();
375}
376
361Kernel::Scheduler& System::Scheduler(std::size_t core_index) { 377Kernel::Scheduler& System::Scheduler(std::size_t core_index) {
362 return CpuCore(core_index).Scheduler(); 378 return CpuCore(core_index).Scheduler();
363} 379}
@@ -378,6 +394,10 @@ ARM_Interface& System::ArmInterface(std::size_t core_index) {
378 return CpuCore(core_index).ArmInterface(); 394 return CpuCore(core_index).ArmInterface();
379} 395}
380 396
397const ARM_Interface& System::ArmInterface(std::size_t core_index) const {
398 return CpuCore(core_index).ArmInterface();
399}
400
381Cpu& System::CpuCore(std::size_t core_index) { 401Cpu& System::CpuCore(std::size_t core_index) {
382 ASSERT(core_index < NUM_CPU_CORES); 402 ASSERT(core_index < NUM_CPU_CORES);
383 return *impl->cpu_cores[core_index]; 403 return *impl->cpu_cores[core_index];
@@ -392,6 +412,10 @@ ExclusiveMonitor& System::Monitor() {
392 return *impl->cpu_exclusive_monitor; 412 return *impl->cpu_exclusive_monitor;
393} 413}
394 414
415const ExclusiveMonitor& System::Monitor() const {
416 return *impl->cpu_exclusive_monitor;
417}
418
395Tegra::GPU& System::GPU() { 419Tegra::GPU& System::GPU() {
396 return *impl->gpu_core; 420 return *impl->gpu_core;
397} 421}
diff --git a/src/core/core.h b/src/core/core.h
index 173be45f8..cfacceb81 100644
--- a/src/core/core.h
+++ b/src/core/core.h
@@ -129,11 +129,11 @@ public:
129 */ 129 */
130 bool IsPoweredOn() const; 130 bool IsPoweredOn() const;
131 131
132 /** 132 /// Gets a reference to the telemetry session for this emulation session.
133 * Returns a reference to the telemetry session for this emulation session. 133 Core::TelemetrySession& TelemetrySession();
134 * @returns Reference to the telemetry session. 134
135 */ 135 /// Gets a reference to the telemetry session for this emulation session.
136 Core::TelemetrySession& TelemetrySession() const; 136 const Core::TelemetrySession& TelemetrySession() const;
137 137
138 /// Prepare the core emulation for a reschedule 138 /// Prepare the core emulation for a reschedule
139 void PrepareReschedule(); 139 void PrepareReschedule();
@@ -144,24 +144,36 @@ public:
144 /// Gets an ARM interface to the CPU core that is currently running 144 /// Gets an ARM interface to the CPU core that is currently running
145 ARM_Interface& CurrentArmInterface(); 145 ARM_Interface& CurrentArmInterface();
146 146
147 /// Gets an ARM interface to the CPU core that is currently running
148 const ARM_Interface& CurrentArmInterface() const;
149
147 /// Gets the index of the currently running CPU core 150 /// Gets the index of the currently running CPU core
148 std::size_t CurrentCoreIndex(); 151 std::size_t CurrentCoreIndex() const;
149 152
150 /// Gets the scheduler for the CPU core that is currently running 153 /// Gets the scheduler for the CPU core that is currently running
151 Kernel::Scheduler& CurrentScheduler(); 154 Kernel::Scheduler& CurrentScheduler();
152 155
153 /// Gets an ARM interface to the CPU core with the specified index 156 /// Gets the scheduler for the CPU core that is currently running
157 const Kernel::Scheduler& CurrentScheduler() const;
158
159 /// Gets a reference to an ARM interface for the CPU core with the specified index
154 ARM_Interface& ArmInterface(std::size_t core_index); 160 ARM_Interface& ArmInterface(std::size_t core_index);
155 161
162 /// Gets a const reference to an ARM interface from the CPU core with the specified index
163 const ARM_Interface& ArmInterface(std::size_t core_index) const;
164
156 /// Gets a CPU interface to the CPU core with the specified index 165 /// Gets a CPU interface to the CPU core with the specified index
157 Cpu& CpuCore(std::size_t core_index); 166 Cpu& CpuCore(std::size_t core_index);
158 167
159 /// Gets a CPU interface to the CPU core with the specified index 168 /// Gets a CPU interface to the CPU core with the specified index
160 const Cpu& CpuCore(std::size_t core_index) const; 169 const Cpu& CpuCore(std::size_t core_index) const;
161 170
162 /// Gets the exclusive monitor 171 /// Gets a reference to the exclusive monitor
163 ExclusiveMonitor& Monitor(); 172 ExclusiveMonitor& Monitor();
164 173
174 /// Gets a constant reference to the exclusive monitor
175 const ExclusiveMonitor& Monitor() const;
176
165 /// Gets a mutable reference to the GPU interface 177 /// Gets a mutable reference to the GPU interface
166 Tegra::GPU& GPU(); 178 Tegra::GPU& GPU();
167 179
@@ -230,6 +242,9 @@ private:
230 /// Returns the currently running CPU core 242 /// Returns the currently running CPU core
231 Cpu& CurrentCpuCore(); 243 Cpu& CurrentCpuCore();
232 244
245 /// Returns the currently running CPU core
246 const Cpu& CurrentCpuCore() const;
247
233 /** 248 /**
234 * Initialize the emulated system. 249 * Initialize the emulated system.
235 * @param emu_window Reference to the host-system window used for video output and keyboard 250 * @param emu_window Reference to the host-system window used for video output and keyboard
diff --git a/src/core/crypto/key_manager.cpp b/src/core/crypto/key_manager.cpp
index 89ae79eb3..904afa039 100644
--- a/src/core/crypto/key_manager.cpp
+++ b/src/core/crypto/key_manager.cpp
@@ -141,28 +141,28 @@ Key128 DeriveKeyblobMACKey(const Key128& keyblob_key, const Key128& mac_source)
141 return mac_key; 141 return mac_key;
142} 142}
143 143
144boost::optional<Key128> DeriveSDSeed() { 144std::optional<Key128> DeriveSDSeed() {
145 const FileUtil::IOFile save_43(FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) + 145 const FileUtil::IOFile save_43(FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) +
146 "/system/save/8000000000000043", 146 "/system/save/8000000000000043",
147 "rb+"); 147 "rb+");
148 if (!save_43.IsOpen()) 148 if (!save_43.IsOpen())
149 return boost::none; 149 return {};
150 150
151 const FileUtil::IOFile sd_private( 151 const FileUtil::IOFile sd_private(
152 FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir) + "/Nintendo/Contents/private", "rb+"); 152 FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir) + "/Nintendo/Contents/private", "rb+");
153 if (!sd_private.IsOpen()) 153 if (!sd_private.IsOpen())
154 return boost::none; 154 return {};
155 155
156 std::array<u8, 0x10> private_seed{}; 156 std::array<u8, 0x10> private_seed{};
157 if (sd_private.ReadBytes(private_seed.data(), private_seed.size()) != private_seed.size()) { 157 if (sd_private.ReadBytes(private_seed.data(), private_seed.size()) != private_seed.size()) {
158 return boost::none; 158 return {};
159 } 159 }
160 160
161 std::array<u8, 0x10> buffer{}; 161 std::array<u8, 0x10> buffer{};
162 std::size_t offset = 0; 162 std::size_t offset = 0;
163 for (; offset + 0x10 < save_43.GetSize(); ++offset) { 163 for (; offset + 0x10 < save_43.GetSize(); ++offset) {
164 if (!save_43.Seek(offset, SEEK_SET)) { 164 if (!save_43.Seek(offset, SEEK_SET)) {
165 return boost::none; 165 return {};
166 } 166 }
167 167
168 save_43.ReadBytes(buffer.data(), buffer.size()); 168 save_43.ReadBytes(buffer.data(), buffer.size());
@@ -172,12 +172,12 @@ boost::optional<Key128> DeriveSDSeed() {
172 } 172 }
173 173
174 if (!save_43.Seek(offset + 0x10, SEEK_SET)) { 174 if (!save_43.Seek(offset + 0x10, SEEK_SET)) {
175 return boost::none; 175 return {};
176 } 176 }
177 177
178 Key128 seed{}; 178 Key128 seed{};
179 if (save_43.ReadBytes(seed.data(), seed.size()) != seed.size()) { 179 if (save_43.ReadBytes(seed.data(), seed.size()) != seed.size()) {
180 return boost::none; 180 return {};
181 } 181 }
182 return seed; 182 return seed;
183} 183}
@@ -291,26 +291,26 @@ static std::array<u8, target_size> MGF1(const std::array<u8, in_size>& seed) {
291} 291}
292 292
293template <size_t size> 293template <size_t size>
294static boost::optional<u64> FindTicketOffset(const std::array<u8, size>& data) { 294static std::optional<u64> FindTicketOffset(const std::array<u8, size>& data) {
295 u64 offset = 0; 295 u64 offset = 0;
296 for (size_t i = 0x20; i < data.size() - 0x10; ++i) { 296 for (size_t i = 0x20; i < data.size() - 0x10; ++i) {
297 if (data[i] == 0x1) { 297 if (data[i] == 0x1) {
298 offset = i + 1; 298 offset = i + 1;
299 break; 299 break;
300 } else if (data[i] != 0x0) { 300 } else if (data[i] != 0x0) {
301 return boost::none; 301 return {};
302 } 302 }
303 } 303 }
304 304
305 return offset; 305 return offset;
306} 306}
307 307
308boost::optional<std::pair<Key128, Key128>> ParseTicket(const TicketRaw& ticket, 308std::optional<std::pair<Key128, Key128>> ParseTicket(const TicketRaw& ticket,
309 const RSAKeyPair<2048>& key) { 309 const RSAKeyPair<2048>& key) {
310 u32 cert_authority; 310 u32 cert_authority;
311 std::memcpy(&cert_authority, ticket.data() + 0x140, sizeof(cert_authority)); 311 std::memcpy(&cert_authority, ticket.data() + 0x140, sizeof(cert_authority));
312 if (cert_authority == 0) 312 if (cert_authority == 0)
313 return boost::none; 313 return {};
314 if (cert_authority != Common::MakeMagic('R', 'o', 'o', 't')) { 314 if (cert_authority != Common::MakeMagic('R', 'o', 'o', 't')) {
315 LOG_INFO(Crypto, 315 LOG_INFO(Crypto,
316 "Attempting to parse ticket with non-standard certificate authority {:08X}.", 316 "Attempting to parse ticket with non-standard certificate authority {:08X}.",
@@ -321,7 +321,7 @@ boost::optional<std::pair<Key128, Key128>> ParseTicket(const TicketRaw& ticket,
321 std::memcpy(rights_id.data(), ticket.data() + 0x2A0, sizeof(Key128)); 321 std::memcpy(rights_id.data(), ticket.data() + 0x2A0, sizeof(Key128));
322 322
323 if (rights_id == Key128{}) 323 if (rights_id == Key128{})
324 return boost::none; 324 return {};
325 325
326 Key128 key_temp{}; 326 Key128 key_temp{};
327 327
@@ -356,17 +356,17 @@ boost::optional<std::pair<Key128, Key128>> ParseTicket(const TicketRaw& ticket,
356 std::memcpy(m_2.data(), rsa_step.data() + 0x21, m_2.size()); 356 std::memcpy(m_2.data(), rsa_step.data() + 0x21, m_2.size());
357 357
358 if (m_0 != 0) 358 if (m_0 != 0)
359 return boost::none; 359 return {};
360 360
361 m_1 = m_1 ^ MGF1<0x20>(m_2); 361 m_1 = m_1 ^ MGF1<0x20>(m_2);
362 m_2 = m_2 ^ MGF1<0xDF>(m_1); 362 m_2 = m_2 ^ MGF1<0xDF>(m_1);
363 363
364 const auto offset = FindTicketOffset(m_2); 364 const auto offset = FindTicketOffset(m_2);
365 if (offset == boost::none) 365 if (!offset)
366 return boost::none; 366 return {};
367 ASSERT(offset.get() > 0); 367 ASSERT(*offset > 0);
368 368
369 std::memcpy(key_temp.data(), m_2.data() + offset.get(), key_temp.size()); 369 std::memcpy(key_temp.data(), m_2.data() + *offset, key_temp.size());
370 370
371 return std::make_pair(rights_id, key_temp); 371 return std::make_pair(rights_id, key_temp);
372} 372}
@@ -661,8 +661,8 @@ void KeyManager::DeriveSDSeedLazy() {
661 return; 661 return;
662 662
663 const auto res = DeriveSDSeed(); 663 const auto res = DeriveSDSeed();
664 if (res != boost::none) 664 if (res)
665 SetKey(S128KeyType::SDSeed, res.get()); 665 SetKey(S128KeyType::SDSeed, *res);
666} 666}
667 667
668static Key128 CalculateCMAC(const u8* source, size_t size, const Key128& key) { 668static Key128 CalculateCMAC(const u8* source, size_t size, const Key128& key) {
@@ -889,9 +889,9 @@ void KeyManager::DeriveETicket(PartitionDataManager& data) {
889 889
890 for (const auto& raw : res) { 890 for (const auto& raw : res) {
891 const auto pair = ParseTicket(raw, rsa_key); 891 const auto pair = ParseTicket(raw, rsa_key);
892 if (pair == boost::none) 892 if (!pair)
893 continue; 893 continue;
894 const auto& [rid, key] = pair.value(); 894 const auto& [rid, key] = *pair;
895 u128 rights_id; 895 u128 rights_id;
896 std::memcpy(rights_id.data(), rid.data(), rid.size()); 896 std::memcpy(rights_id.data(), rid.data(), rid.size());
897 SetKey(S128KeyType::Titlekey, key, rights_id[1], rights_id[0]); 897 SetKey(S128KeyType::Titlekey, key, rights_id[1], rights_id[0]);
diff --git a/src/core/crypto/key_manager.h b/src/core/crypto/key_manager.h
index cccb3c0ae..22f268c65 100644
--- a/src/core/crypto/key_manager.h
+++ b/src/core/crypto/key_manager.h
@@ -6,9 +6,10 @@
6 6
7#include <array> 7#include <array>
8#include <map> 8#include <map>
9#include <optional>
9#include <string> 10#include <string>
11
10#include <boost/container/flat_map.hpp> 12#include <boost/container/flat_map.hpp>
11#include <boost/optional.hpp>
12#include <fmt/format.h> 13#include <fmt/format.h>
13#include "common/common_types.h" 14#include "common/common_types.h"
14#include "core/crypto/partition_data_manager.h" 15#include "core/crypto/partition_data_manager.h"
@@ -191,14 +192,14 @@ Key128 DeriveMasterKey(const std::array<u8, 0x90>& keyblob, const Key128& master
191std::array<u8, 0x90> DecryptKeyblob(const std::array<u8, 0xB0>& encrypted_keyblob, 192std::array<u8, 0x90> DecryptKeyblob(const std::array<u8, 0xB0>& encrypted_keyblob,
192 const Key128& key); 193 const Key128& key);
193 194
194boost::optional<Key128> DeriveSDSeed(); 195std::optional<Key128> DeriveSDSeed();
195Loader::ResultStatus DeriveSDKeys(std::array<Key256, 2>& sd_keys, KeyManager& keys); 196Loader::ResultStatus DeriveSDKeys(std::array<Key256, 2>& sd_keys, KeyManager& keys);
196 197
197std::vector<TicketRaw> GetTicketblob(const FileUtil::IOFile& ticket_save); 198std::vector<TicketRaw> GetTicketblob(const FileUtil::IOFile& ticket_save);
198 199
199// Returns a pair of {rights_id, titlekey}. Fails if the ticket has no certificate authority (offset 200// Returns a pair of {rights_id, titlekey}. Fails if the ticket has no certificate authority (offset
200// 0x140-0x144 is zero) 201// 0x140-0x144 is zero)
201boost::optional<std::pair<Key128, Key128>> ParseTicket( 202std::optional<std::pair<Key128, Key128>> ParseTicket(const TicketRaw& ticket,
202 const TicketRaw& ticket, const RSAKeyPair<2048>& eticket_extended_key); 203 const RSAKeyPair<2048>& eticket_extended_key);
203 204
204} // namespace Core::Crypto 205} // namespace Core::Crypto
diff --git a/src/core/file_sys/content_archive.cpp b/src/core/file_sys/content_archive.cpp
index 77e04704e..b46fe893c 100644
--- a/src/core/file_sys/content_archive.cpp
+++ b/src/core/file_sys/content_archive.cpp
@@ -4,10 +4,9 @@
4 4
5#include <algorithm> 5#include <algorithm>
6#include <cstring> 6#include <cstring>
7#include <optional>
7#include <utility> 8#include <utility>
8 9
9#include <boost/optional.hpp>
10
11#include "common/logging/log.h" 10#include "common/logging/log.h"
12#include "core/crypto/aes_util.h" 11#include "core/crypto/aes_util.h"
13#include "core/crypto/ctr_encryption_layer.h" 12#include "core/crypto/ctr_encryption_layer.h"
@@ -306,18 +305,18 @@ bool NCA::ReadRomFSSection(const NCASectionHeader& section, const NCASectionTabl
306 subsection_buckets.back().entries.push_back({section.bktr.relocation.offset, {0}, ctr_low}); 305 subsection_buckets.back().entries.push_back({section.bktr.relocation.offset, {0}, ctr_low});
307 subsection_buckets.back().entries.push_back({size, {0}, 0}); 306 subsection_buckets.back().entries.push_back({size, {0}, 0});
308 307
309 boost::optional<Core::Crypto::Key128> key = boost::none; 308 std::optional<Core::Crypto::Key128> key = {};
310 if (encrypted) { 309 if (encrypted) {
311 if (has_rights_id) { 310 if (has_rights_id) {
312 status = Loader::ResultStatus::Success; 311 status = Loader::ResultStatus::Success;
313 key = GetTitlekey(); 312 key = GetTitlekey();
314 if (key == boost::none) { 313 if (!key) {
315 status = Loader::ResultStatus::ErrorMissingTitlekey; 314 status = Loader::ResultStatus::ErrorMissingTitlekey;
316 return false; 315 return false;
317 } 316 }
318 } else { 317 } else {
319 key = GetKeyAreaKey(NCASectionCryptoType::BKTR); 318 key = GetKeyAreaKey(NCASectionCryptoType::BKTR);
320 if (key == boost::none) { 319 if (!key) {
321 status = Loader::ResultStatus::ErrorMissingKeyAreaKey; 320 status = Loader::ResultStatus::ErrorMissingKeyAreaKey;
322 return false; 321 return false;
323 } 322 }
@@ -332,7 +331,7 @@ bool NCA::ReadRomFSSection(const NCASectionHeader& section, const NCASectionTabl
332 auto bktr = std::make_shared<BKTR>( 331 auto bktr = std::make_shared<BKTR>(
333 bktr_base_romfs, std::make_shared<OffsetVfsFile>(file, romfs_size, base_offset), 332 bktr_base_romfs, std::make_shared<OffsetVfsFile>(file, romfs_size, base_offset),
334 relocation_block, relocation_buckets, subsection_block, subsection_buckets, encrypted, 333 relocation_block, relocation_buckets, subsection_block, subsection_buckets, encrypted,
335 encrypted ? key.get() : Core::Crypto::Key128{}, base_offset, bktr_base_ivfc_offset, 334 encrypted ? *key : Core::Crypto::Key128{}, base_offset, bktr_base_ivfc_offset,
336 section.raw.section_ctr); 335 section.raw.section_ctr);
337 336
338 // BKTR applies to entire IVFC, so make an offset version to level 6 337 // BKTR applies to entire IVFC, so make an offset version to level 6
@@ -388,11 +387,11 @@ u8 NCA::GetCryptoRevision() const {
388 return master_key_id; 387 return master_key_id;
389} 388}
390 389
391boost::optional<Core::Crypto::Key128> NCA::GetKeyAreaKey(NCASectionCryptoType type) const { 390std::optional<Core::Crypto::Key128> NCA::GetKeyAreaKey(NCASectionCryptoType type) const {
392 const auto master_key_id = GetCryptoRevision(); 391 const auto master_key_id = GetCryptoRevision();
393 392
394 if (!keys.HasKey(Core::Crypto::S128KeyType::KeyArea, master_key_id, header.key_index)) 393 if (!keys.HasKey(Core::Crypto::S128KeyType::KeyArea, master_key_id, header.key_index))
395 return boost::none; 394 return {};
396 395
397 std::vector<u8> key_area(header.key_area.begin(), header.key_area.end()); 396 std::vector<u8> key_area(header.key_area.begin(), header.key_area.end());
398 Core::Crypto::AESCipher<Core::Crypto::Key128> cipher( 397 Core::Crypto::AESCipher<Core::Crypto::Key128> cipher(
@@ -416,25 +415,25 @@ boost::optional<Core::Crypto::Key128> NCA::GetKeyAreaKey(NCASectionCryptoType ty
416 return out; 415 return out;
417} 416}
418 417
419boost::optional<Core::Crypto::Key128> NCA::GetTitlekey() { 418std::optional<Core::Crypto::Key128> NCA::GetTitlekey() {
420 const auto master_key_id = GetCryptoRevision(); 419 const auto master_key_id = GetCryptoRevision();
421 420
422 u128 rights_id{}; 421 u128 rights_id{};
423 memcpy(rights_id.data(), header.rights_id.data(), 16); 422 memcpy(rights_id.data(), header.rights_id.data(), 16);
424 if (rights_id == u128{}) { 423 if (rights_id == u128{}) {
425 status = Loader::ResultStatus::ErrorInvalidRightsID; 424 status = Loader::ResultStatus::ErrorInvalidRightsID;
426 return boost::none; 425 return {};
427 } 426 }
428 427
429 auto titlekey = keys.GetKey(Core::Crypto::S128KeyType::Titlekey, rights_id[1], rights_id[0]); 428 auto titlekey = keys.GetKey(Core::Crypto::S128KeyType::Titlekey, rights_id[1], rights_id[0]);
430 if (titlekey == Core::Crypto::Key128{}) { 429 if (titlekey == Core::Crypto::Key128{}) {
431 status = Loader::ResultStatus::ErrorMissingTitlekey; 430 status = Loader::ResultStatus::ErrorMissingTitlekey;
432 return boost::none; 431 return {};
433 } 432 }
434 433
435 if (!keys.HasKey(Core::Crypto::S128KeyType::Titlekek, master_key_id)) { 434 if (!keys.HasKey(Core::Crypto::S128KeyType::Titlekek, master_key_id)) {
436 status = Loader::ResultStatus::ErrorMissingTitlekek; 435 status = Loader::ResultStatus::ErrorMissingTitlekek;
437 return boost::none; 436 return {};
438 } 437 }
439 438
440 Core::Crypto::AESCipher<Core::Crypto::Key128> cipher( 439 Core::Crypto::AESCipher<Core::Crypto::Key128> cipher(
@@ -458,25 +457,25 @@ VirtualFile NCA::Decrypt(const NCASectionHeader& s_header, VirtualFile in, u64 s
458 case NCASectionCryptoType::BKTR: 457 case NCASectionCryptoType::BKTR:
459 LOG_DEBUG(Crypto, "called with mode=CTR, starting_offset={:016X}", starting_offset); 458 LOG_DEBUG(Crypto, "called with mode=CTR, starting_offset={:016X}", starting_offset);
460 { 459 {
461 boost::optional<Core::Crypto::Key128> key = boost::none; 460 std::optional<Core::Crypto::Key128> key = {};
462 if (has_rights_id) { 461 if (has_rights_id) {
463 status = Loader::ResultStatus::Success; 462 status = Loader::ResultStatus::Success;
464 key = GetTitlekey(); 463 key = GetTitlekey();
465 if (key == boost::none) { 464 if (!key) {
466 if (status == Loader::ResultStatus::Success) 465 if (status == Loader::ResultStatus::Success)
467 status = Loader::ResultStatus::ErrorMissingTitlekey; 466 status = Loader::ResultStatus::ErrorMissingTitlekey;
468 return nullptr; 467 return nullptr;
469 } 468 }
470 } else { 469 } else {
471 key = GetKeyAreaKey(NCASectionCryptoType::CTR); 470 key = GetKeyAreaKey(NCASectionCryptoType::CTR);
472 if (key == boost::none) { 471 if (!key) {
473 status = Loader::ResultStatus::ErrorMissingKeyAreaKey; 472 status = Loader::ResultStatus::ErrorMissingKeyAreaKey;
474 return nullptr; 473 return nullptr;
475 } 474 }
476 } 475 }
477 476
478 auto out = std::make_shared<Core::Crypto::CTREncryptionLayer>( 477 auto out = std::make_shared<Core::Crypto::CTREncryptionLayer>(std::move(in), *key,
479 std::move(in), key.value(), starting_offset); 478 starting_offset);
480 std::vector<u8> iv(16); 479 std::vector<u8> iv(16);
481 for (u8 i = 0; i < 8; ++i) 480 for (u8 i = 0; i < 8; ++i)
482 iv[i] = s_header.raw.section_ctr[0x8 - i - 1]; 481 iv[i] = s_header.raw.section_ctr[0x8 - i - 1];
diff --git a/src/core/file_sys/content_archive.h b/src/core/file_sys/content_archive.h
index 211946686..4bba55607 100644
--- a/src/core/file_sys/content_archive.h
+++ b/src/core/file_sys/content_archive.h
@@ -6,9 +6,10 @@
6 6
7#include <array> 7#include <array>
8#include <memory> 8#include <memory>
9#include <optional>
9#include <string> 10#include <string>
10#include <vector> 11#include <vector>
11#include <boost/optional.hpp> 12
12#include "common/common_funcs.h" 13#include "common/common_funcs.h"
13#include "common/common_types.h" 14#include "common/common_types.h"
14#include "common/swap.h" 15#include "common/swap.h"
@@ -111,8 +112,8 @@ private:
111 bool ReadPFS0Section(const NCASectionHeader& section, const NCASectionTableEntry& entry); 112 bool ReadPFS0Section(const NCASectionHeader& section, const NCASectionTableEntry& entry);
112 113
113 u8 GetCryptoRevision() const; 114 u8 GetCryptoRevision() const;
114 boost::optional<Core::Crypto::Key128> GetKeyAreaKey(NCASectionCryptoType type) const; 115 std::optional<Core::Crypto::Key128> GetKeyAreaKey(NCASectionCryptoType type) const;
115 boost::optional<Core::Crypto::Key128> GetTitlekey(); 116 std::optional<Core::Crypto::Key128> GetTitlekey();
116 VirtualFile Decrypt(const NCASectionHeader& header, VirtualFile in, u64 starting_offset); 117 VirtualFile Decrypt(const NCASectionHeader& header, VirtualFile in, u64 starting_offset);
117 118
118 std::vector<VirtualDir> dirs; 119 std::vector<VirtualDir> dirs;
diff --git a/src/core/file_sys/ips_layer.cpp b/src/core/file_sys/ips_layer.cpp
index 999939d5a..485c4913a 100644
--- a/src/core/file_sys/ips_layer.cpp
+++ b/src/core/file_sys/ips_layer.cpp
@@ -103,12 +103,12 @@ VirtualFile PatchIPS(const VirtualFile& in, const VirtualFile& ips) {
103 offset += sizeof(u16); 103 offset += sizeof(u16);
104 104
105 const auto data = ips->ReadByte(offset++); 105 const auto data = ips->ReadByte(offset++);
106 if (data == boost::none) 106 if (!data)
107 return nullptr; 107 return nullptr;
108 108
109 if (real_offset + rle_size > in_data.size()) 109 if (real_offset + rle_size > in_data.size())
110 rle_size = static_cast<u16>(in_data.size() - real_offset); 110 rle_size = static_cast<u16>(in_data.size() - real_offset);
111 std::memset(in_data.data() + real_offset, data.get(), rle_size); 111 std::memset(in_data.data() + real_offset, *data, rle_size);
112 } else { // Standard Patch 112 } else { // Standard Patch
113 auto read = data_size; 113 auto read = data_size;
114 if (real_offset + read > in_data.size()) 114 if (real_offset + read > in_data.size())
diff --git a/src/core/file_sys/patch_manager.cpp b/src/core/file_sys/patch_manager.cpp
index cb457b987..0c1156989 100644
--- a/src/core/file_sys/patch_manager.cpp
+++ b/src/core/file_sys/patch_manager.cpp
@@ -65,7 +65,7 @@ VirtualDir PatchManager::PatchExeFS(VirtualDir exefs) const {
65 if (update != nullptr && update->GetExeFS() != nullptr && 65 if (update != nullptr && update->GetExeFS() != nullptr &&
66 update->GetStatus() == Loader::ResultStatus::ErrorMissingBKTRBaseRomFS) { 66 update->GetStatus() == Loader::ResultStatus::ErrorMissingBKTRBaseRomFS) {
67 LOG_INFO(Loader, " ExeFS: Update ({}) applied successfully", 67 LOG_INFO(Loader, " ExeFS: Update ({}) applied successfully",
68 FormatTitleVersion(installed->GetEntryVersion(update_tid).get_value_or(0))); 68 FormatTitleVersion(installed->GetEntryVersion(update_tid).value_or(0)));
69 exefs = update->GetExeFS(); 69 exefs = update->GetExeFS();
70 } 70 }
71 71
@@ -236,7 +236,7 @@ VirtualFile PatchManager::PatchRomFS(VirtualFile romfs, u64 ivfc_offset, Content
236 if (new_nca->GetStatus() == Loader::ResultStatus::Success && 236 if (new_nca->GetStatus() == Loader::ResultStatus::Success &&
237 new_nca->GetRomFS() != nullptr) { 237 new_nca->GetRomFS() != nullptr) {
238 LOG_INFO(Loader, " RomFS: Update ({}) applied successfully", 238 LOG_INFO(Loader, " RomFS: Update ({}) applied successfully",
239 FormatTitleVersion(installed->GetEntryVersion(update_tid).get_value_or(0))); 239 FormatTitleVersion(installed->GetEntryVersion(update_tid).value_or(0)));
240 romfs = new_nca->GetRomFS(); 240 romfs = new_nca->GetRomFS();
241 } 241 }
242 } else if (update_raw != nullptr) { 242 } else if (update_raw != nullptr) {
@@ -280,12 +280,11 @@ std::map<std::string, std::string, std::less<>> PatchManager::GetPatchVersionNam
280 } else { 280 } else {
281 if (installed->HasEntry(update_tid, ContentRecordType::Program)) { 281 if (installed->HasEntry(update_tid, ContentRecordType::Program)) {
282 const auto meta_ver = installed->GetEntryVersion(update_tid); 282 const auto meta_ver = installed->GetEntryVersion(update_tid);
283 if (meta_ver == boost::none || meta_ver.get() == 0) { 283 if (meta_ver.value_or(0) == 0) {
284 out.insert_or_assign("Update", ""); 284 out.insert_or_assign("Update", "");
285 } else { 285 } else {
286 out.insert_or_assign( 286 out.insert_or_assign(
287 "Update", 287 "Update", FormatTitleVersion(*meta_ver, TitleVersionFormat::ThreeElements));
288 FormatTitleVersion(meta_ver.get(), TitleVersionFormat::ThreeElements));
289 } 288 }
290 } else if (update_raw != nullptr) { 289 } else if (update_raw != nullptr) {
291 out.insert_or_assign("Update", "PACKED"); 290 out.insert_or_assign("Update", "PACKED");
diff --git a/src/core/file_sys/registered_cache.cpp b/src/core/file_sys/registered_cache.cpp
index 29b100414..96302a241 100644
--- a/src/core/file_sys/registered_cache.cpp
+++ b/src/core/file_sys/registered_cache.cpp
@@ -159,28 +159,28 @@ VirtualFile RegisteredCache::GetFileAtID(NcaID id) const {
159 return file; 159 return file;
160} 160}
161 161
162static boost::optional<NcaID> CheckMapForContentRecord( 162static std::optional<NcaID> CheckMapForContentRecord(
163 const boost::container::flat_map<u64, CNMT>& map, u64 title_id, ContentRecordType type) { 163 const boost::container::flat_map<u64, CNMT>& map, u64 title_id, ContentRecordType type) {
164 if (map.find(title_id) == map.end()) 164 if (map.find(title_id) == map.end())
165 return boost::none; 165 return {};
166 166
167 const auto& cnmt = map.at(title_id); 167 const auto& cnmt = map.at(title_id);
168 168
169 const auto iter = std::find_if(cnmt.GetContentRecords().begin(), cnmt.GetContentRecords().end(), 169 const auto iter = std::find_if(cnmt.GetContentRecords().begin(), cnmt.GetContentRecords().end(),
170 [type](const ContentRecord& rec) { return rec.type == type; }); 170 [type](const ContentRecord& rec) { return rec.type == type; });
171 if (iter == cnmt.GetContentRecords().end()) 171 if (iter == cnmt.GetContentRecords().end())
172 return boost::none; 172 return {};
173 173
174 return boost::make_optional(iter->nca_id); 174 return std::make_optional(iter->nca_id);
175} 175}
176 176
177boost::optional<NcaID> RegisteredCache::GetNcaIDFromMetadata(u64 title_id, 177std::optional<NcaID> RegisteredCache::GetNcaIDFromMetadata(u64 title_id,
178 ContentRecordType type) const { 178 ContentRecordType type) const {
179 if (type == ContentRecordType::Meta && meta_id.find(title_id) != meta_id.end()) 179 if (type == ContentRecordType::Meta && meta_id.find(title_id) != meta_id.end())
180 return meta_id.at(title_id); 180 return meta_id.at(title_id);
181 181
182 const auto res1 = CheckMapForContentRecord(yuzu_meta, title_id, type); 182 const auto res1 = CheckMapForContentRecord(yuzu_meta, title_id, type);
183 if (res1 != boost::none) 183 if (res1)
184 return res1; 184 return res1;
185 return CheckMapForContentRecord(meta, title_id, type); 185 return CheckMapForContentRecord(meta, title_id, type);
186} 186}
@@ -283,17 +283,14 @@ bool RegisteredCache::HasEntry(RegisteredCacheEntry entry) const {
283 283
284VirtualFile RegisteredCache::GetEntryUnparsed(u64 title_id, ContentRecordType type) const { 284VirtualFile RegisteredCache::GetEntryUnparsed(u64 title_id, ContentRecordType type) const {
285 const auto id = GetNcaIDFromMetadata(title_id, type); 285 const auto id = GetNcaIDFromMetadata(title_id, type);
286 if (id == boost::none) 286 return id ? GetFileAtID(*id) : nullptr;
287 return nullptr;
288
289 return GetFileAtID(id.get());
290} 287}
291 288
292VirtualFile RegisteredCache::GetEntryUnparsed(RegisteredCacheEntry entry) const { 289VirtualFile RegisteredCache::GetEntryUnparsed(RegisteredCacheEntry entry) const {
293 return GetEntryUnparsed(entry.title_id, entry.type); 290 return GetEntryUnparsed(entry.title_id, entry.type);
294} 291}
295 292
296boost::optional<u32> RegisteredCache::GetEntryVersion(u64 title_id) const { 293std::optional<u32> RegisteredCache::GetEntryVersion(u64 title_id) const {
297 const auto meta_iter = meta.find(title_id); 294 const auto meta_iter = meta.find(title_id);
298 if (meta_iter != meta.end()) 295 if (meta_iter != meta.end())
299 return meta_iter->second.GetTitleVersion(); 296 return meta_iter->second.GetTitleVersion();
@@ -302,15 +299,12 @@ boost::optional<u32> RegisteredCache::GetEntryVersion(u64 title_id) const {
302 if (yuzu_meta_iter != yuzu_meta.end()) 299 if (yuzu_meta_iter != yuzu_meta.end())
303 return yuzu_meta_iter->second.GetTitleVersion(); 300 return yuzu_meta_iter->second.GetTitleVersion();
304 301
305 return boost::none; 302 return {};
306} 303}
307 304
308VirtualFile RegisteredCache::GetEntryRaw(u64 title_id, ContentRecordType type) const { 305VirtualFile RegisteredCache::GetEntryRaw(u64 title_id, ContentRecordType type) const {
309 const auto id = GetNcaIDFromMetadata(title_id, type); 306 const auto id = GetNcaIDFromMetadata(title_id, type);
310 if (id == boost::none) 307 return id ? parser(GetFileAtID(*id), *id) : nullptr;
311 return nullptr;
312
313 return parser(GetFileAtID(id.get()), id.get());
314} 308}
315 309
316VirtualFile RegisteredCache::GetEntryRaw(RegisteredCacheEntry entry) const { 310VirtualFile RegisteredCache::GetEntryRaw(RegisteredCacheEntry entry) const {
@@ -364,8 +358,8 @@ std::vector<RegisteredCacheEntry> RegisteredCache::ListEntries() const {
364} 358}
365 359
366std::vector<RegisteredCacheEntry> RegisteredCache::ListEntriesFilter( 360std::vector<RegisteredCacheEntry> RegisteredCache::ListEntriesFilter(
367 boost::optional<TitleType> title_type, boost::optional<ContentRecordType> record_type, 361 std::optional<TitleType> title_type, std::optional<ContentRecordType> record_type,
368 boost::optional<u64> title_id) const { 362 std::optional<u64> title_id) const {
369 std::vector<RegisteredCacheEntry> out; 363 std::vector<RegisteredCacheEntry> out;
370 IterateAllMetadata<RegisteredCacheEntry>( 364 IterateAllMetadata<RegisteredCacheEntry>(
371 out, 365 out,
@@ -373,11 +367,11 @@ std::vector<RegisteredCacheEntry> RegisteredCache::ListEntriesFilter(
373 return RegisteredCacheEntry{c.GetTitleID(), r.type}; 367 return RegisteredCacheEntry{c.GetTitleID(), r.type};
374 }, 368 },
375 [&title_type, &record_type, &title_id](const CNMT& c, const ContentRecord& r) { 369 [&title_type, &record_type, &title_id](const CNMT& c, const ContentRecord& r) {
376 if (title_type != boost::none && title_type.get() != c.GetType()) 370 if (title_type && *title_type != c.GetType())
377 return false; 371 return false;
378 if (record_type != boost::none && record_type.get() != r.type) 372 if (record_type && *record_type != r.type)
379 return false; 373 return false;
380 if (title_id != boost::none && title_id.get() != c.GetTitleID()) 374 if (title_id && *title_id != c.GetTitleID())
381 return false; 375 return false;
382 return true; 376 return true;
383 }); 377 });
@@ -459,7 +453,7 @@ InstallResult RegisteredCache::InstallEntry(std::shared_ptr<NCA> nca, TitleType
459 453
460InstallResult RegisteredCache::RawInstallNCA(std::shared_ptr<NCA> nca, const VfsCopyFunction& copy, 454InstallResult RegisteredCache::RawInstallNCA(std::shared_ptr<NCA> nca, const VfsCopyFunction& copy,
461 bool overwrite_if_exists, 455 bool overwrite_if_exists,
462 boost::optional<NcaID> override_id) { 456 std::optional<NcaID> override_id) {
463 const auto in = nca->GetBaseFile(); 457 const auto in = nca->GetBaseFile();
464 Core::Crypto::SHA256Hash hash{}; 458 Core::Crypto::SHA256Hash hash{};
465 459
@@ -468,12 +462,12 @@ InstallResult RegisteredCache::RawInstallNCA(std::shared_ptr<NCA> nca, const Vfs
468 // game is massive), we're going to cheat and only hash the first MB of the NCA. 462 // game is massive), we're going to cheat and only hash the first MB of the NCA.
469 // Also, for XCIs the NcaID matters, so if the override id isn't none, use that. 463 // Also, for XCIs the NcaID matters, so if the override id isn't none, use that.
470 NcaID id{}; 464 NcaID id{};
471 if (override_id == boost::none) { 465 if (override_id) {
466 id = *override_id;
467 } else {
472 const auto& data = in->ReadBytes(0x100000); 468 const auto& data = in->ReadBytes(0x100000);
473 mbedtls_sha256(data.data(), data.size(), hash.data(), 0); 469 mbedtls_sha256(data.data(), data.size(), hash.data(), 0);
474 memcpy(id.data(), hash.data(), 16); 470 memcpy(id.data(), hash.data(), 16);
475 } else {
476 id = override_id.get();
477 } 471 }
478 472
479 std::string path = GetRelativePathFromNcaID(id, false, true); 473 std::string path = GetRelativePathFromNcaID(id, false, true);
@@ -543,14 +537,14 @@ bool RegisteredCacheUnion::HasEntry(RegisteredCacheEntry entry) const {
543 return HasEntry(entry.title_id, entry.type); 537 return HasEntry(entry.title_id, entry.type);
544} 538}
545 539
546boost::optional<u32> RegisteredCacheUnion::GetEntryVersion(u64 title_id) const { 540std::optional<u32> RegisteredCacheUnion::GetEntryVersion(u64 title_id) const {
547 for (const auto& c : caches) { 541 for (const auto& c : caches) {
548 const auto res = c->GetEntryVersion(title_id); 542 const auto res = c->GetEntryVersion(title_id);
549 if (res != boost::none) 543 if (res)
550 return res; 544 return res;
551 } 545 }
552 546
553 return boost::none; 547 return {};
554} 548}
555 549
556VirtualFile RegisteredCacheUnion::GetEntryUnparsed(u64 title_id, ContentRecordType type) const { 550VirtualFile RegisteredCacheUnion::GetEntryUnparsed(u64 title_id, ContentRecordType type) const {
@@ -609,8 +603,8 @@ std::vector<RegisteredCacheEntry> RegisteredCacheUnion::ListEntries() const {
609} 603}
610 604
611std::vector<RegisteredCacheEntry> RegisteredCacheUnion::ListEntriesFilter( 605std::vector<RegisteredCacheEntry> RegisteredCacheUnion::ListEntriesFilter(
612 boost::optional<TitleType> title_type, boost::optional<ContentRecordType> record_type, 606 std::optional<TitleType> title_type, std::optional<ContentRecordType> record_type,
613 boost::optional<u64> title_id) const { 607 std::optional<u64> title_id) const {
614 std::vector<RegisteredCacheEntry> out; 608 std::vector<RegisteredCacheEntry> out;
615 for (const auto& c : caches) { 609 for (const auto& c : caches) {
616 c->IterateAllMetadata<RegisteredCacheEntry>( 610 c->IterateAllMetadata<RegisteredCacheEntry>(
@@ -619,11 +613,11 @@ std::vector<RegisteredCacheEntry> RegisteredCacheUnion::ListEntriesFilter(
619 return RegisteredCacheEntry{c.GetTitleID(), r.type}; 613 return RegisteredCacheEntry{c.GetTitleID(), r.type};
620 }, 614 },
621 [&title_type, &record_type, &title_id](const CNMT& c, const ContentRecord& r) { 615 [&title_type, &record_type, &title_id](const CNMT& c, const ContentRecord& r) {
622 if (title_type != boost::none && title_type.get() != c.GetType()) 616 if (title_type && *title_type != c.GetType())
623 return false; 617 return false;
624 if (record_type != boost::none && record_type.get() != r.type) 618 if (record_type && *record_type != r.type)
625 return false; 619 return false;
626 if (title_id != boost::none && title_id.get() != c.GetTitleID()) 620 if (title_id && *title_id != c.GetTitleID())
627 return false; 621 return false;
628 return true; 622 return true;
629 }); 623 });
diff --git a/src/core/file_sys/registered_cache.h b/src/core/file_sys/registered_cache.h
index 5beceffb3..6cfb16017 100644
--- a/src/core/file_sys/registered_cache.h
+++ b/src/core/file_sys/registered_cache.h
@@ -84,7 +84,7 @@ public:
84 bool HasEntry(u64 title_id, ContentRecordType type) const; 84 bool HasEntry(u64 title_id, ContentRecordType type) const;
85 bool HasEntry(RegisteredCacheEntry entry) const; 85 bool HasEntry(RegisteredCacheEntry entry) const;
86 86
87 boost::optional<u32> GetEntryVersion(u64 title_id) const; 87 std::optional<u32> GetEntryVersion(u64 title_id) const;
88 88
89 VirtualFile GetEntryUnparsed(u64 title_id, ContentRecordType type) const; 89 VirtualFile GetEntryUnparsed(u64 title_id, ContentRecordType type) const;
90 VirtualFile GetEntryUnparsed(RegisteredCacheEntry entry) const; 90 VirtualFile GetEntryUnparsed(RegisteredCacheEntry entry) const;
@@ -96,11 +96,10 @@ public:
96 std::unique_ptr<NCA> GetEntry(RegisteredCacheEntry entry) const; 96 std::unique_ptr<NCA> GetEntry(RegisteredCacheEntry entry) const;
97 97
98 std::vector<RegisteredCacheEntry> ListEntries() const; 98 std::vector<RegisteredCacheEntry> ListEntries() const;
99 // If a parameter is not boost::none, it will be filtered for from all entries. 99 // If a parameter is not std::nullopt, it will be filtered for from all entries.
100 std::vector<RegisteredCacheEntry> ListEntriesFilter( 100 std::vector<RegisteredCacheEntry> ListEntriesFilter(
101 boost::optional<TitleType> title_type = boost::none, 101 std::optional<TitleType> title_type = {}, std::optional<ContentRecordType> record_type = {},
102 boost::optional<ContentRecordType> record_type = boost::none, 102 std::optional<u64> title_id = {}) const;
103 boost::optional<u64> title_id = boost::none) const;
104 103
105 // Raw copies all the ncas from the xci/nsp to the csache. Does some quick checks to make sure 104 // Raw copies all the ncas from the xci/nsp to the csache. Does some quick checks to make sure
106 // there is a meta NCA and all of them are accessible. 105 // there is a meta NCA and all of them are accessible.
@@ -125,12 +124,11 @@ private:
125 std::vector<NcaID> AccumulateFiles() const; 124 std::vector<NcaID> AccumulateFiles() const;
126 void ProcessFiles(const std::vector<NcaID>& ids); 125 void ProcessFiles(const std::vector<NcaID>& ids);
127 void AccumulateYuzuMeta(); 126 void AccumulateYuzuMeta();
128 boost::optional<NcaID> GetNcaIDFromMetadata(u64 title_id, ContentRecordType type) const; 127 std::optional<NcaID> GetNcaIDFromMetadata(u64 title_id, ContentRecordType type) const;
129 VirtualFile GetFileAtID(NcaID id) const; 128 VirtualFile GetFileAtID(NcaID id) const;
130 VirtualFile OpenFileOrDirectoryConcat(const VirtualDir& dir, std::string_view path) const; 129 VirtualFile OpenFileOrDirectoryConcat(const VirtualDir& dir, std::string_view path) const;
131 InstallResult RawInstallNCA(std::shared_ptr<NCA> nca, const VfsCopyFunction& copy, 130 InstallResult RawInstallNCA(std::shared_ptr<NCA> nca, const VfsCopyFunction& copy,
132 bool overwrite_if_exists, 131 bool overwrite_if_exists, std::optional<NcaID> override_id = {});
133 boost::optional<NcaID> override_id = boost::none);
134 bool RawInstallYuzuMeta(const CNMT& cnmt); 132 bool RawInstallYuzuMeta(const CNMT& cnmt);
135 133
136 VirtualDir dir; 134 VirtualDir dir;
@@ -153,7 +151,7 @@ public:
153 bool HasEntry(u64 title_id, ContentRecordType type) const; 151 bool HasEntry(u64 title_id, ContentRecordType type) const;
154 bool HasEntry(RegisteredCacheEntry entry) const; 152 bool HasEntry(RegisteredCacheEntry entry) const;
155 153
156 boost::optional<u32> GetEntryVersion(u64 title_id) const; 154 std::optional<u32> GetEntryVersion(u64 title_id) const;
157 155
158 VirtualFile GetEntryUnparsed(u64 title_id, ContentRecordType type) const; 156 VirtualFile GetEntryUnparsed(u64 title_id, ContentRecordType type) const;
159 VirtualFile GetEntryUnparsed(RegisteredCacheEntry entry) const; 157 VirtualFile GetEntryUnparsed(RegisteredCacheEntry entry) const;
@@ -165,11 +163,10 @@ public:
165 std::unique_ptr<NCA> GetEntry(RegisteredCacheEntry entry) const; 163 std::unique_ptr<NCA> GetEntry(RegisteredCacheEntry entry) const;
166 164
167 std::vector<RegisteredCacheEntry> ListEntries() const; 165 std::vector<RegisteredCacheEntry> ListEntries() const;
168 // If a parameter is not boost::none, it will be filtered for from all entries. 166 // If a parameter is not std::nullopt, it will be filtered for from all entries.
169 std::vector<RegisteredCacheEntry> ListEntriesFilter( 167 std::vector<RegisteredCacheEntry> ListEntriesFilter(
170 boost::optional<TitleType> title_type = boost::none, 168 std::optional<TitleType> title_type = {}, std::optional<ContentRecordType> record_type = {},
171 boost::optional<ContentRecordType> record_type = boost::none, 169 std::optional<u64> title_id = {}) const;
172 boost::optional<u64> title_id = boost::none) const;
173 170
174private: 171private:
175 std::vector<RegisteredCache*> caches; 172 std::vector<RegisteredCache*> caches;
diff --git a/src/core/file_sys/vfs.cpp b/src/core/file_sys/vfs.cpp
index 3824c74e0..7b584de7f 100644
--- a/src/core/file_sys/vfs.cpp
+++ b/src/core/file_sys/vfs.cpp
@@ -167,13 +167,13 @@ std::string VfsFile::GetExtension() const {
167 167
168VfsDirectory::~VfsDirectory() = default; 168VfsDirectory::~VfsDirectory() = default;
169 169
170boost::optional<u8> VfsFile::ReadByte(std::size_t offset) const { 170std::optional<u8> VfsFile::ReadByte(std::size_t offset) const {
171 u8 out{}; 171 u8 out{};
172 std::size_t size = Read(&out, 1, offset); 172 std::size_t size = Read(&out, 1, offset);
173 if (size == 1) 173 if (size == 1)
174 return out; 174 return out;
175 175
176 return boost::none; 176 return {};
177} 177}
178 178
179std::vector<u8> VfsFile::ReadBytes(std::size_t size, std::size_t offset) const { 179std::vector<u8> VfsFile::ReadBytes(std::size_t size, std::size_t offset) const {
diff --git a/src/core/file_sys/vfs.h b/src/core/file_sys/vfs.h
index 09dc9f288..002f99d4e 100644
--- a/src/core/file_sys/vfs.h
+++ b/src/core/file_sys/vfs.h
@@ -4,13 +4,15 @@
4 4
5#pragma once 5#pragma once
6 6
7#include <functional>
7#include <map> 8#include <map>
8#include <memory> 9#include <memory>
10#include <optional>
9#include <string> 11#include <string>
10#include <string_view> 12#include <string_view>
11#include <type_traits> 13#include <type_traits>
12#include <vector> 14#include <vector>
13#include <boost/optional.hpp> 15
14#include "common/common_types.h" 16#include "common/common_types.h"
15#include "core/file_sys/vfs_types.h" 17#include "core/file_sys/vfs_types.h"
16 18
@@ -103,8 +105,8 @@ public:
103 // into file. Returns number of bytes successfully written. 105 // into file. Returns number of bytes successfully written.
104 virtual std::size_t Write(const u8* data, std::size_t length, std::size_t offset = 0) = 0; 106 virtual std::size_t Write(const u8* data, std::size_t length, std::size_t offset = 0) = 0;
105 107
106 // Reads exactly one byte at the offset provided, returning boost::none on error. 108 // Reads exactly one byte at the offset provided, returning std::nullopt on error.
107 virtual boost::optional<u8> ReadByte(std::size_t offset = 0) const; 109 virtual std::optional<u8> ReadByte(std::size_t offset = 0) const;
108 // Reads size bytes starting at offset in file into a vector. 110 // Reads size bytes starting at offset in file into a vector.
109 virtual std::vector<u8> ReadBytes(std::size_t size, std::size_t offset = 0) const; 111 virtual std::vector<u8> ReadBytes(std::size_t size, std::size_t offset = 0) const;
110 // Reads all the bytes from the file into a vector. Equivalent to 'file->Read(file->GetSize(), 112 // Reads all the bytes from the file into a vector. Equivalent to 'file->Read(file->GetSize(),
diff --git a/src/core/file_sys/vfs_offset.cpp b/src/core/file_sys/vfs_offset.cpp
index a4c6719a0..c96f88488 100644
--- a/src/core/file_sys/vfs_offset.cpp
+++ b/src/core/file_sys/vfs_offset.cpp
@@ -57,11 +57,11 @@ std::size_t OffsetVfsFile::Write(const u8* data, std::size_t length, std::size_t
57 return file->Write(data, TrimToFit(length, r_offset), offset + r_offset); 57 return file->Write(data, TrimToFit(length, r_offset), offset + r_offset);
58} 58}
59 59
60boost::optional<u8> OffsetVfsFile::ReadByte(std::size_t r_offset) const { 60std::optional<u8> OffsetVfsFile::ReadByte(std::size_t r_offset) const {
61 if (r_offset < size) 61 if (r_offset < size)
62 return file->ReadByte(offset + r_offset); 62 return file->ReadByte(offset + r_offset);
63 63
64 return boost::none; 64 return {};
65} 65}
66 66
67std::vector<u8> OffsetVfsFile::ReadBytes(std::size_t r_size, std::size_t r_offset) const { 67std::vector<u8> OffsetVfsFile::ReadBytes(std::size_t r_size, std::size_t r_offset) const {
diff --git a/src/core/file_sys/vfs_offset.h b/src/core/file_sys/vfs_offset.h
index 8062702a7..f7b7a3256 100644
--- a/src/core/file_sys/vfs_offset.h
+++ b/src/core/file_sys/vfs_offset.h
@@ -29,7 +29,7 @@ public:
29 bool IsReadable() const override; 29 bool IsReadable() const override;
30 std::size_t Read(u8* data, std::size_t length, std::size_t offset) const override; 30 std::size_t Read(u8* data, std::size_t length, std::size_t offset) const override;
31 std::size_t Write(const u8* data, std::size_t length, std::size_t offset) override; 31 std::size_t Write(const u8* data, std::size_t length, std::size_t offset) override;
32 boost::optional<u8> ReadByte(std::size_t offset) const override; 32 std::optional<u8> ReadByte(std::size_t offset) const override;
33 std::vector<u8> ReadBytes(std::size_t size, std::size_t offset) const override; 33 std::vector<u8> ReadBytes(std::size_t size, std::size_t offset) const override;
34 std::vector<u8> ReadAllBytes() const override; 34 std::vector<u8> ReadAllBytes() const override;
35 bool WriteByte(u8 data, std::size_t offset) override; 35 bool WriteByte(u8 data, std::size_t offset) override;
diff --git a/src/core/file_sys/vfs_static.h b/src/core/file_sys/vfs_static.h
index 44fab51d1..9f5a90b1b 100644
--- a/src/core/file_sys/vfs_static.h
+++ b/src/core/file_sys/vfs_static.h
@@ -53,10 +53,10 @@ public:
53 return 0; 53 return 0;
54 } 54 }
55 55
56 boost::optional<u8> ReadByte(std::size_t offset) const override { 56 std::optional<u8> ReadByte(std::size_t offset) const override {
57 if (offset < size) 57 if (offset < size)
58 return value; 58 return value;
59 return boost::none; 59 return {};
60 } 60 }
61 61
62 std::vector<u8> ReadBytes(std::size_t length, std::size_t offset) const override { 62 std::vector<u8> ReadBytes(std::size_t length, std::size_t offset) const override {
diff --git a/src/core/hle/ipc_helpers.h b/src/core/hle/ipc_helpers.h
index a4bfe2eb0..0a7142ada 100644
--- a/src/core/hle/ipc_helpers.h
+++ b/src/core/hle/ipc_helpers.h
@@ -117,8 +117,7 @@ public:
117 117
118 AlignWithPadding(); 118 AlignWithPadding();
119 119
120 const bool request_has_domain_header{context.GetDomainMessageHeader() != nullptr}; 120 if (context.Session()->IsDomain() && context.HasDomainMessageHeader()) {
121 if (context.Session()->IsDomain() && request_has_domain_header) {
122 IPC::DomainMessageHeader domain_header{}; 121 IPC::DomainMessageHeader domain_header{};
123 domain_header.num_objects = num_domain_objects; 122 domain_header.num_objects = num_domain_objects;
124 PushRaw(domain_header); 123 PushRaw(domain_header);
diff --git a/src/core/hle/kernel/hle_ipc.h b/src/core/hle/kernel/hle_ipc.h
index f01491daa..a38e34b74 100644
--- a/src/core/hle/kernel/hle_ipc.h
+++ b/src/core/hle/kernel/hle_ipc.h
@@ -161,8 +161,12 @@ public:
161 return buffer_c_desciptors; 161 return buffer_c_desciptors;
162 } 162 }
163 163
164 const std::shared_ptr<IPC::DomainMessageHeader>& GetDomainMessageHeader() const { 164 const IPC::DomainMessageHeader* GetDomainMessageHeader() const {
165 return domain_message_header; 165 return domain_message_header.get();
166 }
167
168 bool HasDomainMessageHeader() const {
169 return domain_message_header != nullptr;
166 } 170 }
167 171
168 /// Helper function to read a buffer using the appropriate buffer descriptor 172 /// Helper function to read a buffer using the appropriate buffer descriptor
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp
index 4b6b32dd5..1fd4ba5d2 100644
--- a/src/core/hle/kernel/kernel.cpp
+++ b/src/core/hle/kernel/kernel.cpp
@@ -32,7 +32,7 @@ namespace Kernel {
32 */ 32 */
33static void ThreadWakeupCallback(u64 thread_handle, [[maybe_unused]] int cycles_late) { 33static void ThreadWakeupCallback(u64 thread_handle, [[maybe_unused]] int cycles_late) {
34 const auto proper_handle = static_cast<Handle>(thread_handle); 34 const auto proper_handle = static_cast<Handle>(thread_handle);
35 auto& system = Core::System::GetInstance(); 35 const auto& system = Core::System::GetInstance();
36 36
37 // Lock the global kernel mutex when we enter the kernel HLE. 37 // Lock the global kernel mutex when we enter the kernel HLE.
38 std::lock_guard<std::recursive_mutex> lock(HLE::g_hle_lock); 38 std::lock_guard<std::recursive_mutex> lock(HLE::g_hle_lock);
@@ -90,7 +90,7 @@ static void ThreadWakeupCallback(u64 thread_handle, [[maybe_unused]] int cycles_
90/// The timer callback event, called when a timer is fired 90/// The timer callback event, called when a timer is fired
91static void TimerCallback(u64 timer_handle, int cycles_late) { 91static void TimerCallback(u64 timer_handle, int cycles_late) {
92 const auto proper_handle = static_cast<Handle>(timer_handle); 92 const auto proper_handle = static_cast<Handle>(timer_handle);
93 auto& system = Core::System::GetInstance(); 93 const auto& system = Core::System::GetInstance();
94 SharedPtr<Timer> timer = system.Kernel().RetrieveTimerFromCallbackHandleTable(proper_handle); 94 SharedPtr<Timer> timer = system.Kernel().RetrieveTimerFromCallbackHandleTable(proper_handle);
95 95
96 if (timer == nullptr) { 96 if (timer == nullptr) {
diff --git a/src/core/hle/kernel/server_session.cpp b/src/core/hle/kernel/server_session.cpp
index 5fc320403..80897f3a4 100644
--- a/src/core/hle/kernel/server_session.cpp
+++ b/src/core/hle/kernel/server_session.cpp
@@ -63,7 +63,7 @@ void ServerSession::Acquire(Thread* thread) {
63} 63}
64 64
65ResultCode ServerSession::HandleDomainSyncRequest(Kernel::HLERequestContext& context) { 65ResultCode ServerSession::HandleDomainSyncRequest(Kernel::HLERequestContext& context) {
66 auto& domain_message_header = context.GetDomainMessageHeader(); 66 auto* const domain_message_header = context.GetDomainMessageHeader();
67 if (domain_message_header) { 67 if (domain_message_header) {
68 // Set domain handlers in HLE context, used for domain objects (IPC interfaces) as inputs 68 // Set domain handlers in HLE context, used for domain objects (IPC interfaces) as inputs
69 context.SetDomainRequestHandlers(domain_request_handlers); 69 context.SetDomainRequestHandlers(domain_request_handlers);
@@ -111,7 +111,7 @@ ResultCode ServerSession::HandleSyncRequest(SharedPtr<Thread> thread) {
111 111
112 ResultCode result = RESULT_SUCCESS; 112 ResultCode result = RESULT_SUCCESS;
113 // If the session has been converted to a domain, handle the domain request 113 // If the session has been converted to a domain, handle the domain request
114 if (IsDomain() && context.GetDomainMessageHeader()) { 114 if (IsDomain() && context.HasDomainMessageHeader()) {
115 result = HandleDomainSyncRequest(context); 115 result = HandleDomainSyncRequest(context);
116 // If there is no domain header, the regular session handler is used 116 // If there is no domain header, the regular session handler is used
117 } else if (hle_handler != nullptr) { 117 } else if (hle_handler != nullptr) {
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp
index 4e490e2b5..c7c579aaf 100644
--- a/src/core/hle/kernel/svc.cpp
+++ b/src/core/hle/kernel/svc.cpp
@@ -572,7 +572,7 @@ static ResultCode GetInfo(u64* result, u64 info_id, u64 handle, u64 info_sub_id)
572 return ERR_INVALID_HANDLE; 572 return ERR_INVALID_HANDLE;
573 } 573 }
574 574
575 auto& system = Core::System::GetInstance(); 575 const auto& system = Core::System::GetInstance();
576 const auto& scheduler = system.CurrentScheduler(); 576 const auto& scheduler = system.CurrentScheduler();
577 const auto* const current_thread = scheduler.GetCurrentThread(); 577 const auto* const current_thread = scheduler.GetCurrentThread();
578 const bool same_thread = current_thread == thread; 578 const bool same_thread = current_thread == thread;
diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp
index 59bc9e0af..dd5cd9ced 100644
--- a/src/core/hle/kernel/thread.cpp
+++ b/src/core/hle/kernel/thread.cpp
@@ -4,9 +4,9 @@
4 4
5#include <algorithm> 5#include <algorithm>
6#include <cinttypes> 6#include <cinttypes>
7#include <optional>
7#include <vector> 8#include <vector>
8 9
9#include <boost/optional.hpp>
10#include <boost/range/algorithm_ext/erase.hpp> 10#include <boost/range/algorithm_ext/erase.hpp>
11 11
12#include "common/assert.h" 12#include "common/assert.h"
@@ -94,7 +94,7 @@ void Thread::CancelWakeupTimer() {
94 CoreTiming::UnscheduleEventThreadsafe(kernel.ThreadWakeupCallbackEventType(), callback_handle); 94 CoreTiming::UnscheduleEventThreadsafe(kernel.ThreadWakeupCallbackEventType(), callback_handle);
95} 95}
96 96
97static boost::optional<s32> GetNextProcessorId(u64 mask) { 97static std::optional<s32> GetNextProcessorId(u64 mask) {
98 for (s32 index = 0; index < Core::NUM_CPU_CORES; ++index) { 98 for (s32 index = 0; index < Core::NUM_CPU_CORES; ++index) {
99 if (mask & (1ULL << index)) { 99 if (mask & (1ULL << index)) {
100 if (!Core::System::GetInstance().Scheduler(index).GetCurrentThread()) { 100 if (!Core::System::GetInstance().Scheduler(index).GetCurrentThread()) {
@@ -142,7 +142,7 @@ void Thread::ResumeFromWait() {
142 142
143 status = ThreadStatus::Ready; 143 status = ThreadStatus::Ready;
144 144
145 boost::optional<s32> new_processor_id = GetNextProcessorId(affinity_mask); 145 std::optional<s32> new_processor_id = GetNextProcessorId(affinity_mask);
146 if (!new_processor_id) { 146 if (!new_processor_id) {
147 new_processor_id = processor_id; 147 new_processor_id = processor_id;
148 } 148 }
@@ -369,7 +369,7 @@ void Thread::ChangeCore(u32 core, u64 mask) {
369 return; 369 return;
370 } 370 }
371 371
372 boost::optional<s32> new_processor_id{GetNextProcessorId(affinity_mask)}; 372 std::optional<s32> new_processor_id{GetNextProcessorId(affinity_mask)};
373 373
374 if (!new_processor_id) { 374 if (!new_processor_id) {
375 new_processor_id = processor_id; 375 new_processor_id = processor_id;
diff --git a/src/core/hle/service/acc/profile_manager.cpp b/src/core/hle/service/acc/profile_manager.cpp
index 3cac1b4ff..c08394e4c 100644
--- a/src/core/hle/service/acc/profile_manager.cpp
+++ b/src/core/hle/service/acc/profile_manager.cpp
@@ -195,7 +195,7 @@ std::size_t ProfileManager::GetOpenUserCount() const {
195 195
196/// Checks if a user id exists in our profile manager 196/// Checks if a user id exists in our profile manager
197bool ProfileManager::UserExists(UUID uuid) const { 197bool ProfileManager::UserExists(UUID uuid) const {
198 return GetUserIndex(uuid) != std::nullopt; 198 return GetUserIndex(uuid).has_value();
199} 199}
200 200
201bool ProfileManager::UserExistsIndex(std::size_t index) const { 201bool ProfileManager::UserExistsIndex(std::size_t index) const {
diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp
index 59aafd616..ac3ff9f20 100644
--- a/src/core/hle/service/am/am.cpp
+++ b/src/core/hle/service/am/am.cpp
@@ -743,7 +743,7 @@ void IApplicationFunctions::PopLaunchParameter(Kernel::HLERequestContext& ctx) {
743 743
744 Account::ProfileManager profile_manager{}; 744 Account::ProfileManager profile_manager{};
745 const auto uuid = profile_manager.GetUser(Settings::values.current_user); 745 const auto uuid = profile_manager.GetUser(Settings::values.current_user);
746 ASSERT(uuid != std::nullopt); 746 ASSERT(uuid);
747 params.current_user = uuid->uuid; 747 params.current_user = uuid->uuid;
748 748
749 IPC::ResponseBuilder rb{ctx, 2, 0, 1}; 749 IPC::ResponseBuilder rb{ctx, 2, 0, 1};
diff --git a/src/core/hle/service/nvflinger/buffer_queue.cpp b/src/core/hle/service/nvflinger/buffer_queue.cpp
index fd98d541d..630ebbfc7 100644
--- a/src/core/hle/service/nvflinger/buffer_queue.cpp
+++ b/src/core/hle/service/nvflinger/buffer_queue.cpp
@@ -31,7 +31,7 @@ void BufferQueue::SetPreallocatedBuffer(u32 slot, const IGBPBuffer& igbp_buffer)
31 buffer_wait_event->Signal(); 31 buffer_wait_event->Signal();
32} 32}
33 33
34boost::optional<u32> BufferQueue::DequeueBuffer(u32 width, u32 height) { 34std::optional<u32> BufferQueue::DequeueBuffer(u32 width, u32 height) {
35 auto itr = std::find_if(queue.begin(), queue.end(), [&](const Buffer& buffer) { 35 auto itr = std::find_if(queue.begin(), queue.end(), [&](const Buffer& buffer) {
36 // Only consider free buffers. Buffers become free once again after they've been Acquired 36 // Only consider free buffers. Buffers become free once again after they've been Acquired
37 // and Released by the compositor, see the NVFlinger::Compose method. 37 // and Released by the compositor, see the NVFlinger::Compose method.
@@ -44,7 +44,7 @@ boost::optional<u32> BufferQueue::DequeueBuffer(u32 width, u32 height) {
44 }); 44 });
45 45
46 if (itr == queue.end()) { 46 if (itr == queue.end()) {
47 return boost::none; 47 return {};
48 } 48 }
49 49
50 itr->status = Buffer::Status::Dequeued; 50 itr->status = Buffer::Status::Dequeued;
@@ -70,12 +70,12 @@ void BufferQueue::QueueBuffer(u32 slot, BufferTransformFlags transform,
70 itr->crop_rect = crop_rect; 70 itr->crop_rect = crop_rect;
71} 71}
72 72
73boost::optional<const BufferQueue::Buffer&> BufferQueue::AcquireBuffer() { 73std::optional<std::reference_wrapper<const BufferQueue::Buffer>> BufferQueue::AcquireBuffer() {
74 auto itr = std::find_if(queue.begin(), queue.end(), [](const Buffer& buffer) { 74 auto itr = std::find_if(queue.begin(), queue.end(), [](const Buffer& buffer) {
75 return buffer.status == Buffer::Status::Queued; 75 return buffer.status == Buffer::Status::Queued;
76 }); 76 });
77 if (itr == queue.end()) 77 if (itr == queue.end())
78 return boost::none; 78 return {};
79 itr->status = Buffer::Status::Acquired; 79 itr->status = Buffer::Status::Acquired;
80 return *itr; 80 return *itr;
81} 81}
diff --git a/src/core/hle/service/nvflinger/buffer_queue.h b/src/core/hle/service/nvflinger/buffer_queue.h
index 50b767732..2fe81a560 100644
--- a/src/core/hle/service/nvflinger/buffer_queue.h
+++ b/src/core/hle/service/nvflinger/buffer_queue.h
@@ -4,8 +4,9 @@
4 4
5#pragma once 5#pragma once
6 6
7#include <optional>
7#include <vector> 8#include <vector>
8#include <boost/optional.hpp> 9
9#include "common/common_funcs.h" 10#include "common/common_funcs.h"
10#include "common/math_util.h" 11#include "common/math_util.h"
11#include "common/swap.h" 12#include "common/swap.h"
@@ -73,11 +74,11 @@ public:
73 }; 74 };
74 75
75 void SetPreallocatedBuffer(u32 slot, const IGBPBuffer& igbp_buffer); 76 void SetPreallocatedBuffer(u32 slot, const IGBPBuffer& igbp_buffer);
76 boost::optional<u32> DequeueBuffer(u32 width, u32 height); 77 std::optional<u32> DequeueBuffer(u32 width, u32 height);
77 const IGBPBuffer& RequestBuffer(u32 slot) const; 78 const IGBPBuffer& RequestBuffer(u32 slot) const;
78 void QueueBuffer(u32 slot, BufferTransformFlags transform, 79 void QueueBuffer(u32 slot, BufferTransformFlags transform,
79 const MathUtil::Rectangle<int>& crop_rect); 80 const MathUtil::Rectangle<int>& crop_rect);
80 boost::optional<const Buffer&> AcquireBuffer(); 81 std::optional<std::reference_wrapper<const Buffer>> AcquireBuffer();
81 void ReleaseBuffer(u32 slot); 82 void ReleaseBuffer(u32 slot);
82 u32 Query(QueryType type); 83 u32 Query(QueryType type);
83 84
diff --git a/src/core/hle/service/nvflinger/nvflinger.cpp b/src/core/hle/service/nvflinger/nvflinger.cpp
index d47b6f659..214e6d1b3 100644
--- a/src/core/hle/service/nvflinger/nvflinger.cpp
+++ b/src/core/hle/service/nvflinger/nvflinger.cpp
@@ -3,7 +3,7 @@
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include <algorithm> 5#include <algorithm>
6#include <boost/optional.hpp> 6#include <optional>
7 7
8#include "common/alignment.h" 8#include "common/alignment.h"
9#include "common/assert.h" 9#include "common/assert.h"
@@ -134,7 +134,7 @@ void NVFlinger::Compose() {
134 134
135 MicroProfileFlip(); 135 MicroProfileFlip();
136 136
137 if (buffer == boost::none) { 137 if (!buffer) {
138 auto& system_instance = Core::System::GetInstance(); 138 auto& system_instance = Core::System::GetInstance();
139 139
140 // There was no queued buffer to draw, render previous frame 140 // There was no queued buffer to draw, render previous frame
@@ -143,7 +143,7 @@ void NVFlinger::Compose() {
143 continue; 143 continue;
144 } 144 }
145 145
146 auto& igbp_buffer = buffer->igbp_buffer; 146 auto& igbp_buffer = buffer->get().igbp_buffer;
147 147
148 // Now send the buffer to the GPU for drawing. 148 // Now send the buffer to the GPU for drawing.
149 // TODO(Subv): Support more than just disp0. The display device selection is probably based 149 // TODO(Subv): Support more than just disp0. The display device selection is probably based
@@ -152,10 +152,10 @@ void NVFlinger::Compose() {
152 ASSERT(nvdisp); 152 ASSERT(nvdisp);
153 153
154 nvdisp->flip(igbp_buffer.gpu_buffer_id, igbp_buffer.offset, igbp_buffer.format, 154 nvdisp->flip(igbp_buffer.gpu_buffer_id, igbp_buffer.offset, igbp_buffer.format,
155 igbp_buffer.width, igbp_buffer.height, igbp_buffer.stride, buffer->transform, 155 igbp_buffer.width, igbp_buffer.height, igbp_buffer.stride,
156 buffer->crop_rect); 156 buffer->get().transform, buffer->get().crop_rect);
157 157
158 buffer_queue->ReleaseBuffer(buffer->slot); 158 buffer_queue->ReleaseBuffer(buffer->get().slot);
159 } 159 }
160} 160}
161 161
diff --git a/src/core/hle/service/vi/vi.cpp b/src/core/hle/service/vi/vi.cpp
index 184537daa..d764b2406 100644
--- a/src/core/hle/service/vi/vi.cpp
+++ b/src/core/hle/service/vi/vi.cpp
@@ -6,9 +6,10 @@
6#include <array> 6#include <array>
7#include <cstring> 7#include <cstring>
8#include <memory> 8#include <memory>
9#include <optional>
9#include <type_traits> 10#include <type_traits>
10#include <utility> 11#include <utility>
11#include <boost/optional.hpp> 12
12#include "common/alignment.h" 13#include "common/alignment.h"
13#include "common/assert.h" 14#include "common/assert.h"
14#include "common/common_funcs.h" 15#include "common/common_funcs.h"
@@ -506,9 +507,9 @@ private:
506 IGBPDequeueBufferRequestParcel request{ctx.ReadBuffer()}; 507 IGBPDequeueBufferRequestParcel request{ctx.ReadBuffer()};
507 const u32 width{request.data.width}; 508 const u32 width{request.data.width};
508 const u32 height{request.data.height}; 509 const u32 height{request.data.height};
509 boost::optional<u32> slot = buffer_queue->DequeueBuffer(width, height); 510 std::optional<u32> slot = buffer_queue->DequeueBuffer(width, height);
510 511
511 if (slot != boost::none) { 512 if (slot) {
512 // Buffer is available 513 // Buffer is available
513 IGBPDequeueBufferResponseParcel response{*slot}; 514 IGBPDequeueBufferResponseParcel response{*slot};
514 ctx.WriteBuffer(response.Serialize()); 515 ctx.WriteBuffer(response.Serialize());
@@ -520,7 +521,7 @@ private:
520 Kernel::ThreadWakeupReason reason) { 521 Kernel::ThreadWakeupReason reason) {
521 // Repeat TransactParcel DequeueBuffer when a buffer is available 522 // Repeat TransactParcel DequeueBuffer when a buffer is available
522 auto buffer_queue = nv_flinger->GetBufferQueue(id); 523 auto buffer_queue = nv_flinger->GetBufferQueue(id);
523 boost::optional<u32> slot = buffer_queue->DequeueBuffer(width, height); 524 std::optional<u32> slot = buffer_queue->DequeueBuffer(width, height);
524 IGBPDequeueBufferResponseParcel response{*slot}; 525 IGBPDequeueBufferResponseParcel response{*slot};
525 ctx.WriteBuffer(response.Serialize()); 526 ctx.WriteBuffer(response.Serialize());
526 IPC::ResponseBuilder rb{ctx, 2}; 527 IPC::ResponseBuilder rb{ctx, 2};
diff --git a/src/core/loader/loader.h b/src/core/loader/loader.h
index e562b3a04..7686634bf 100644
--- a/src/core/loader/loader.h
+++ b/src/core/loader/loader.h
@@ -6,10 +6,11 @@
6 6
7#include <iosfwd> 7#include <iosfwd>
8#include <memory> 8#include <memory>
9#include <optional>
9#include <string> 10#include <string>
10#include <utility> 11#include <utility>
11#include <vector> 12#include <vector>
12#include <boost/optional.hpp> 13
13#include "common/common_types.h" 14#include "common/common_types.h"
14#include "core/file_sys/vfs.h" 15#include "core/file_sys/vfs.h"
15 16
@@ -145,7 +146,7 @@ public:
145 * information. 146 * information.
146 * @returns A pair with the optional system mode, and and the status. 147 * @returns A pair with the optional system mode, and and the status.
147 */ 148 */
148 virtual std::pair<boost::optional<u32>, ResultStatus> LoadKernelSystemMode() { 149 virtual std::pair<std::optional<u32>, ResultStatus> LoadKernelSystemMode() {
149 // 96MB allocated to the application. 150 // 96MB allocated to the application.
150 return std::make_pair(2, ResultStatus::Success); 151 return std::make_pair(2, ResultStatus::Success);
151 } 152 }
diff --git a/src/core/memory.cpp b/src/core/memory.cpp
index 014298ed6..70abd856a 100644
--- a/src/core/memory.cpp
+++ b/src/core/memory.cpp
@@ -4,9 +4,9 @@
4 4
5#include <algorithm> 5#include <algorithm>
6#include <cstring> 6#include <cstring>
7#include <optional>
7#include <utility> 8#include <utility>
8 9
9#include <boost/optional.hpp>
10#include "common/assert.h" 10#include "common/assert.h"
11#include "common/common_types.h" 11#include "common/common_types.h"
12#include "common/logging/log.h" 12#include "common/logging/log.h"
diff --git a/src/core/memory_hook.h b/src/core/memory_hook.h
index 0269c7ff1..940777107 100644
--- a/src/core/memory_hook.h
+++ b/src/core/memory_hook.h
@@ -5,7 +5,8 @@
5#pragma once 5#pragma once
6 6
7#include <memory> 7#include <memory>
8#include <boost/optional.hpp> 8#include <optional>
9
9#include "common/common_types.h" 10#include "common/common_types.h"
10 11
11namespace Memory { 12namespace Memory {
@@ -18,19 +19,19 @@ namespace Memory {
18 * 19 *
19 * A hook may be mapped to multiple regions of memory. 20 * A hook may be mapped to multiple regions of memory.
20 * 21 *
21 * If a boost::none or false is returned from a function, the read/write request is passed through 22 * If a std::nullopt or false is returned from a function, the read/write request is passed through
22 * to the underlying memory region. 23 * to the underlying memory region.
23 */ 24 */
24class MemoryHook { 25class MemoryHook {
25public: 26public:
26 virtual ~MemoryHook(); 27 virtual ~MemoryHook();
27 28
28 virtual boost::optional<bool> IsValidAddress(VAddr addr) = 0; 29 virtual std::optional<bool> IsValidAddress(VAddr addr) = 0;
29 30
30 virtual boost::optional<u8> Read8(VAddr addr) = 0; 31 virtual std::optional<u8> Read8(VAddr addr) = 0;
31 virtual boost::optional<u16> Read16(VAddr addr) = 0; 32 virtual std::optional<u16> Read16(VAddr addr) = 0;
32 virtual boost::optional<u32> Read32(VAddr addr) = 0; 33 virtual std::optional<u32> Read32(VAddr addr) = 0;
33 virtual boost::optional<u64> Read64(VAddr addr) = 0; 34 virtual std::optional<u64> Read64(VAddr addr) = 0;
34 35
35 virtual bool ReadBlock(VAddr src_addr, void* dest_buffer, std::size_t size) = 0; 36 virtual bool ReadBlock(VAddr src_addr, void* dest_buffer, std::size_t size) = 0;
36 37
diff --git a/src/tests/core/arm/arm_test_common.cpp b/src/tests/core/arm/arm_test_common.cpp
index 37e15bad0..9b8a44fa1 100644
--- a/src/tests/core/arm/arm_test_common.cpp
+++ b/src/tests/core/arm/arm_test_common.cpp
@@ -64,11 +64,11 @@ void TestEnvironment::ClearWriteRecords() {
64 64
65TestEnvironment::TestMemory::~TestMemory() {} 65TestEnvironment::TestMemory::~TestMemory() {}
66 66
67boost::optional<bool> TestEnvironment::TestMemory::IsValidAddress(VAddr addr) { 67std::optional<bool> TestEnvironment::TestMemory::IsValidAddress(VAddr addr) {
68 return true; 68 return true;
69} 69}
70 70
71boost::optional<u8> TestEnvironment::TestMemory::Read8(VAddr addr) { 71std::optional<u8> TestEnvironment::TestMemory::Read8(VAddr addr) {
72 const auto iter = data.find(addr); 72 const auto iter = data.find(addr);
73 73
74 if (iter == data.end()) { 74 if (iter == data.end()) {
@@ -79,15 +79,15 @@ boost::optional<u8> TestEnvironment::TestMemory::Read8(VAddr addr) {
79 return iter->second; 79 return iter->second;
80} 80}
81 81
82boost::optional<u16> TestEnvironment::TestMemory::Read16(VAddr addr) { 82std::optional<u16> TestEnvironment::TestMemory::Read16(VAddr addr) {
83 return *Read8(addr) | static_cast<u16>(*Read8(addr + 1)) << 8; 83 return *Read8(addr) | static_cast<u16>(*Read8(addr + 1)) << 8;
84} 84}
85 85
86boost::optional<u32> TestEnvironment::TestMemory::Read32(VAddr addr) { 86std::optional<u32> TestEnvironment::TestMemory::Read32(VAddr addr) {
87 return *Read16(addr) | static_cast<u32>(*Read16(addr + 2)) << 16; 87 return *Read16(addr) | static_cast<u32>(*Read16(addr + 2)) << 16;
88} 88}
89 89
90boost::optional<u64> TestEnvironment::TestMemory::Read64(VAddr addr) { 90std::optional<u64> TestEnvironment::TestMemory::Read64(VAddr addr) {
91 return *Read32(addr) | static_cast<u64>(*Read32(addr + 4)) << 32; 91 return *Read32(addr) | static_cast<u64>(*Read32(addr + 4)) << 32;
92} 92}
93 93
diff --git a/src/tests/core/arm/arm_test_common.h b/src/tests/core/arm/arm_test_common.h
index 5de8dab4e..0b7539601 100644
--- a/src/tests/core/arm/arm_test_common.h
+++ b/src/tests/core/arm/arm_test_common.h
@@ -64,12 +64,12 @@ private:
64 64
65 ~TestMemory() override; 65 ~TestMemory() override;
66 66
67 boost::optional<bool> IsValidAddress(VAddr addr) override; 67 std::optional<bool> IsValidAddress(VAddr addr) override;
68 68
69 boost::optional<u8> Read8(VAddr addr) override; 69 std::optional<u8> Read8(VAddr addr) override;
70 boost::optional<u16> Read16(VAddr addr) override; 70 std::optional<u16> Read16(VAddr addr) override;
71 boost::optional<u32> Read32(VAddr addr) override; 71 std::optional<u32> Read32(VAddr addr) override;
72 boost::optional<u64> Read64(VAddr addr) override; 72 std::optional<u64> Read64(VAddr addr) override;
73 73
74 bool ReadBlock(VAddr src_addr, void* dest_buffer, std::size_t size) override; 74 bool ReadBlock(VAddr src_addr, void* dest_buffer, std::size_t size) override;
75 75
diff --git a/src/video_core/CMakeLists.txt b/src/video_core/CMakeLists.txt
index 09ecc5bad..c5f7128ec 100644
--- a/src/video_core/CMakeLists.txt
+++ b/src/video_core/CMakeLists.txt
@@ -51,6 +51,8 @@ add_library(video_core STATIC
51 renderer_opengl/maxwell_to_gl.h 51 renderer_opengl/maxwell_to_gl.h
52 renderer_opengl/renderer_opengl.cpp 52 renderer_opengl/renderer_opengl.cpp
53 renderer_opengl/renderer_opengl.h 53 renderer_opengl/renderer_opengl.h
54 renderer_opengl/utils.cpp
55 renderer_opengl/utils.h
54 textures/astc.cpp 56 textures/astc.cpp
55 textures/astc.h 57 textures/astc.h
56 textures/decoders.cpp 58 textures/decoders.cpp
diff --git a/src/video_core/command_processor.cpp b/src/video_core/command_processor.cpp
index f1aa6091b..28e8c13aa 100644
--- a/src/video_core/command_processor.cpp
+++ b/src/video_core/command_processor.cpp
@@ -81,7 +81,7 @@ void GPU::ProcessCommandLists(const std::vector<CommandListHeader>& commands) {
81 for (auto entry : commands) { 81 for (auto entry : commands) {
82 Tegra::GPUVAddr address = entry.Address(); 82 Tegra::GPUVAddr address = entry.Address();
83 u32 size = entry.sz; 83 u32 size = entry.sz;
84 const boost::optional<VAddr> head_address = memory_manager->GpuToCpuAddress(address); 84 const std::optional<VAddr> head_address = memory_manager->GpuToCpuAddress(address);
85 VAddr current_addr = *head_address; 85 VAddr current_addr = *head_address;
86 while (current_addr < *head_address + size * sizeof(CommandHeader)) { 86 while (current_addr < *head_address + size * sizeof(CommandHeader)) {
87 const CommandHeader header = {Memory::Read32(current_addr)}; 87 const CommandHeader header = {Memory::Read32(current_addr)};
diff --git a/src/video_core/engines/maxwell_3d.cpp b/src/video_core/engines/maxwell_3d.cpp
index 27ef865a2..7357d20d1 100644
--- a/src/video_core/engines/maxwell_3d.cpp
+++ b/src/video_core/engines/maxwell_3d.cpp
@@ -167,7 +167,7 @@ void Maxwell3D::ProcessQueryGet() {
167 GPUVAddr sequence_address = regs.query.QueryAddress(); 167 GPUVAddr sequence_address = regs.query.QueryAddress();
168 // Since the sequence address is given as a GPU VAddr, we have to convert it to an application 168 // Since the sequence address is given as a GPU VAddr, we have to convert it to an application
169 // VAddr before writing. 169 // VAddr before writing.
170 boost::optional<VAddr> address = memory_manager.GpuToCpuAddress(sequence_address); 170 std::optional<VAddr> address = memory_manager.GpuToCpuAddress(sequence_address);
171 171
172 // TODO(Subv): Support the other query units. 172 // TODO(Subv): Support the other query units.
173 ASSERT_MSG(regs.query.query_get.unit == Regs::QueryUnit::Crop, 173 ASSERT_MSG(regs.query.query_get.unit == Regs::QueryUnit::Crop,
@@ -285,7 +285,7 @@ void Maxwell3D::ProcessCBData(u32 value) {
285 // Don't allow writing past the end of the buffer. 285 // Don't allow writing past the end of the buffer.
286 ASSERT(regs.const_buffer.cb_pos + sizeof(u32) <= regs.const_buffer.cb_size); 286 ASSERT(regs.const_buffer.cb_pos + sizeof(u32) <= regs.const_buffer.cb_size);
287 287
288 boost::optional<VAddr> address = 288 std::optional<VAddr> address =
289 memory_manager.GpuToCpuAddress(buffer_address + regs.const_buffer.cb_pos); 289 memory_manager.GpuToCpuAddress(buffer_address + regs.const_buffer.cb_pos);
290 290
291 Memory::Write32(*address, value); 291 Memory::Write32(*address, value);
@@ -298,7 +298,7 @@ Texture::TICEntry Maxwell3D::GetTICEntry(u32 tic_index) const {
298 GPUVAddr tic_base_address = regs.tic.TICAddress(); 298 GPUVAddr tic_base_address = regs.tic.TICAddress();
299 299
300 GPUVAddr tic_address_gpu = tic_base_address + tic_index * sizeof(Texture::TICEntry); 300 GPUVAddr tic_address_gpu = tic_base_address + tic_index * sizeof(Texture::TICEntry);
301 boost::optional<VAddr> tic_address_cpu = memory_manager.GpuToCpuAddress(tic_address_gpu); 301 std::optional<VAddr> tic_address_cpu = memory_manager.GpuToCpuAddress(tic_address_gpu);
302 302
303 Texture::TICEntry tic_entry; 303 Texture::TICEntry tic_entry;
304 Memory::ReadBlock(*tic_address_cpu, &tic_entry, sizeof(Texture::TICEntry)); 304 Memory::ReadBlock(*tic_address_cpu, &tic_entry, sizeof(Texture::TICEntry));
@@ -322,7 +322,7 @@ Texture::TSCEntry Maxwell3D::GetTSCEntry(u32 tsc_index) const {
322 GPUVAddr tsc_base_address = regs.tsc.TSCAddress(); 322 GPUVAddr tsc_base_address = regs.tsc.TSCAddress();
323 323
324 GPUVAddr tsc_address_gpu = tsc_base_address + tsc_index * sizeof(Texture::TSCEntry); 324 GPUVAddr tsc_address_gpu = tsc_base_address + tsc_index * sizeof(Texture::TSCEntry);
325 boost::optional<VAddr> tsc_address_cpu = memory_manager.GpuToCpuAddress(tsc_address_gpu); 325 std::optional<VAddr> tsc_address_cpu = memory_manager.GpuToCpuAddress(tsc_address_gpu);
326 326
327 Texture::TSCEntry tsc_entry; 327 Texture::TSCEntry tsc_entry;
328 Memory::ReadBlock(*tsc_address_cpu, &tsc_entry, sizeof(Texture::TSCEntry)); 328 Memory::ReadBlock(*tsc_address_cpu, &tsc_entry, sizeof(Texture::TSCEntry));
@@ -386,7 +386,7 @@ Texture::FullTextureInfo Maxwell3D::GetStageTexture(Regs::ShaderStage stage,
386 386
387 ASSERT(tex_info_address < tex_info_buffer.address + tex_info_buffer.size); 387 ASSERT(tex_info_address < tex_info_buffer.address + tex_info_buffer.size);
388 388
389 boost::optional<VAddr> tex_address_cpu = memory_manager.GpuToCpuAddress(tex_info_address); 389 std::optional<VAddr> tex_address_cpu = memory_manager.GpuToCpuAddress(tex_info_address);
390 Texture::TextureHandle tex_handle{Memory::Read32(*tex_address_cpu)}; 390 Texture::TextureHandle tex_handle{Memory::Read32(*tex_address_cpu)};
391 391
392 Texture::FullTextureInfo tex_info{}; 392 Texture::FullTextureInfo tex_info{};
diff --git a/src/video_core/engines/shader_bytecode.h b/src/video_core/engines/shader_bytecode.h
index 141b9159b..b84da512f 100644
--- a/src/video_core/engines/shader_bytecode.h
+++ b/src/video_core/engines/shader_bytecode.h
@@ -5,12 +5,11 @@
5#pragma once 5#pragma once
6 6
7#include <bitset> 7#include <bitset>
8#include <optional>
8#include <string> 9#include <string>
9#include <tuple> 10#include <tuple>
10#include <vector> 11#include <vector>
11 12
12#include <boost/optional.hpp>
13
14#include "common/assert.h" 13#include "common/assert.h"
15#include "common/bit_field.h" 14#include "common/bit_field.h"
16#include "common/common_types.h" 15#include "common/common_types.h"
@@ -1456,7 +1455,7 @@ public:
1456 Type type; 1455 Type type;
1457 }; 1456 };
1458 1457
1459 static boost::optional<const Matcher&> Decode(Instruction instr) { 1458 static std::optional<std::reference_wrapper<const Matcher>> Decode(Instruction instr) {
1460 static const auto table{GetDecodeTable()}; 1459 static const auto table{GetDecodeTable()};
1461 1460
1462 const auto matches_instruction = [instr](const auto& matcher) { 1461 const auto matches_instruction = [instr](const auto& matcher) {
@@ -1464,7 +1463,8 @@ public:
1464 }; 1463 };
1465 1464
1466 auto iter = std::find_if(table.begin(), table.end(), matches_instruction); 1465 auto iter = std::find_if(table.begin(), table.end(), matches_instruction);
1467 return iter != table.end() ? boost::optional<const Matcher&>(*iter) : boost::none; 1466 return iter != table.end() ? std::optional<std::reference_wrapper<const Matcher>>(*iter)
1467 : std::nullopt;
1468 } 1468 }
1469 1469
1470private: 1470private:
diff --git a/src/video_core/macro_interpreter.cpp b/src/video_core/macro_interpreter.cpp
index 377bd66ab..f6af132fb 100644
--- a/src/video_core/macro_interpreter.cpp
+++ b/src/video_core/macro_interpreter.cpp
@@ -29,7 +29,7 @@ void MacroInterpreter::Execute(const std::vector<u32>& code, std::vector<u32> pa
29void MacroInterpreter::Reset() { 29void MacroInterpreter::Reset() {
30 registers = {}; 30 registers = {};
31 pc = 0; 31 pc = 0;
32 delayed_pc = boost::none; 32 delayed_pc = {};
33 method_address.raw = 0; 33 method_address.raw = 0;
34 parameters.clear(); 34 parameters.clear();
35 // The next parameter index starts at 1, because $r1 already has the value of the first 35 // The next parameter index starts at 1, because $r1 already has the value of the first
@@ -44,10 +44,10 @@ bool MacroInterpreter::Step(const std::vector<u32>& code, bool is_delay_slot) {
44 pc += 4; 44 pc += 4;
45 45
46 // Update the program counter if we were delayed 46 // Update the program counter if we were delayed
47 if (delayed_pc != boost::none) { 47 if (delayed_pc) {
48 ASSERT(is_delay_slot); 48 ASSERT(is_delay_slot);
49 pc = *delayed_pc; 49 pc = *delayed_pc;
50 delayed_pc = boost::none; 50 delayed_pc = {};
51 } 51 }
52 52
53 switch (opcode.operation) { 53 switch (opcode.operation) {
diff --git a/src/video_core/macro_interpreter.h b/src/video_core/macro_interpreter.h
index cee0baaf3..773684bde 100644
--- a/src/video_core/macro_interpreter.h
+++ b/src/video_core/macro_interpreter.h
@@ -5,8 +5,9 @@
5#pragma once 5#pragma once
6 6
7#include <array> 7#include <array>
8#include <optional>
8#include <vector> 9#include <vector>
9#include <boost/optional.hpp> 10
10#include "common/bit_field.h" 11#include "common/bit_field.h"
11#include "common/common_types.h" 12#include "common/common_types.h"
12 13
@@ -149,7 +150,7 @@ private:
149 Engines::Maxwell3D& maxwell3d; 150 Engines::Maxwell3D& maxwell3d;
150 151
151 u32 pc; ///< Current program counter 152 u32 pc; ///< Current program counter
152 boost::optional<u32> 153 std::optional<u32>
153 delayed_pc; ///< Program counter to execute at after the delay slot is executed. 154 delayed_pc; ///< Program counter to execute at after the delay slot is executed.
154 155
155 static constexpr std::size_t NumMacroRegisters = 8; 156 static constexpr std::size_t NumMacroRegisters = 8;
diff --git a/src/video_core/memory_manager.cpp b/src/video_core/memory_manager.cpp
index 022d4ab74..90a8e825d 100644
--- a/src/video_core/memory_manager.cpp
+++ b/src/video_core/memory_manager.cpp
@@ -9,7 +9,7 @@
9namespace Tegra { 9namespace Tegra {
10 10
11GPUVAddr MemoryManager::AllocateSpace(u64 size, u64 align) { 11GPUVAddr MemoryManager::AllocateSpace(u64 size, u64 align) {
12 boost::optional<GPUVAddr> gpu_addr = FindFreeBlock(size, align); 12 std::optional<GPUVAddr> gpu_addr = FindFreeBlock(size, align);
13 ASSERT(gpu_addr); 13 ASSERT(gpu_addr);
14 14
15 for (u64 offset = 0; offset < size; offset += PAGE_SIZE) { 15 for (u64 offset = 0; offset < size; offset += PAGE_SIZE) {
@@ -34,7 +34,7 @@ GPUVAddr MemoryManager::AllocateSpace(GPUVAddr gpu_addr, u64 size, u64 align) {
34} 34}
35 35
36GPUVAddr MemoryManager::MapBufferEx(VAddr cpu_addr, u64 size) { 36GPUVAddr MemoryManager::MapBufferEx(VAddr cpu_addr, u64 size) {
37 boost::optional<GPUVAddr> gpu_addr = FindFreeBlock(size, PAGE_SIZE); 37 std::optional<GPUVAddr> gpu_addr = FindFreeBlock(size, PAGE_SIZE);
38 ASSERT(gpu_addr); 38 ASSERT(gpu_addr);
39 39
40 for (u64 offset = 0; offset < size; offset += PAGE_SIZE) { 40 for (u64 offset = 0; offset < size; offset += PAGE_SIZE) {
@@ -97,7 +97,7 @@ GPUVAddr MemoryManager::GetRegionEnd(GPUVAddr region_start) const {
97 return {}; 97 return {};
98} 98}
99 99
100boost::optional<GPUVAddr> MemoryManager::FindFreeBlock(u64 size, u64 align) { 100std::optional<GPUVAddr> MemoryManager::FindFreeBlock(u64 size, u64 align) {
101 GPUVAddr gpu_addr = 0; 101 GPUVAddr gpu_addr = 0;
102 u64 free_space = 0; 102 u64 free_space = 0;
103 align = (align + PAGE_MASK) & ~PAGE_MASK; 103 align = (align + PAGE_MASK) & ~PAGE_MASK;
@@ -118,7 +118,7 @@ boost::optional<GPUVAddr> MemoryManager::FindFreeBlock(u64 size, u64 align) {
118 return {}; 118 return {};
119} 119}
120 120
121boost::optional<VAddr> MemoryManager::GpuToCpuAddress(GPUVAddr gpu_addr) { 121std::optional<VAddr> MemoryManager::GpuToCpuAddress(GPUVAddr gpu_addr) {
122 VAddr base_addr = PageSlot(gpu_addr); 122 VAddr base_addr = PageSlot(gpu_addr);
123 123
124 if (base_addr == static_cast<u64>(PageStatus::Allocated) || 124 if (base_addr == static_cast<u64>(PageStatus::Allocated) ||
diff --git a/src/video_core/memory_manager.h b/src/video_core/memory_manager.h
index caf80093f..b1255fd56 100644
--- a/src/video_core/memory_manager.h
+++ b/src/video_core/memory_manager.h
@@ -6,10 +6,9 @@
6 6
7#include <array> 7#include <array>
8#include <memory> 8#include <memory>
9#include <optional>
9#include <vector> 10#include <vector>
10 11
11#include <boost/optional.hpp>
12
13#include "common/common_types.h" 12#include "common/common_types.h"
14 13
15namespace Tegra { 14namespace Tegra {
@@ -27,7 +26,7 @@ public:
27 GPUVAddr MapBufferEx(VAddr cpu_addr, GPUVAddr gpu_addr, u64 size); 26 GPUVAddr MapBufferEx(VAddr cpu_addr, GPUVAddr gpu_addr, u64 size);
28 GPUVAddr UnmapBuffer(GPUVAddr gpu_addr, u64 size); 27 GPUVAddr UnmapBuffer(GPUVAddr gpu_addr, u64 size);
29 GPUVAddr GetRegionEnd(GPUVAddr region_start) const; 28 GPUVAddr GetRegionEnd(GPUVAddr region_start) const;
30 boost::optional<VAddr> GpuToCpuAddress(GPUVAddr gpu_addr); 29 std::optional<VAddr> GpuToCpuAddress(GPUVAddr gpu_addr);
31 std::vector<GPUVAddr> CpuToGpuAddress(VAddr cpu_addr) const; 30 std::vector<GPUVAddr> CpuToGpuAddress(VAddr cpu_addr) const;
32 31
33 static constexpr u64 PAGE_BITS = 16; 32 static constexpr u64 PAGE_BITS = 16;
@@ -35,7 +34,7 @@ public:
35 static constexpr u64 PAGE_MASK = PAGE_SIZE - 1; 34 static constexpr u64 PAGE_MASK = PAGE_SIZE - 1;
36 35
37private: 36private:
38 boost::optional<GPUVAddr> FindFreeBlock(u64 size, u64 align = 1); 37 std::optional<GPUVAddr> FindFreeBlock(u64 size, u64 align = 1);
39 bool IsPageMapped(GPUVAddr gpu_addr); 38 bool IsPageMapped(GPUVAddr gpu_addr);
40 VAddr& PageSlot(GPUVAddr gpu_addr); 39 VAddr& PageSlot(GPUVAddr gpu_addr);
41 40
diff --git a/src/video_core/renderer_base.h b/src/video_core/renderer_base.h
index 2cd0738ff..669e26e15 100644
--- a/src/video_core/renderer_base.h
+++ b/src/video_core/renderer_base.h
@@ -6,7 +6,8 @@
6 6
7#include <atomic> 7#include <atomic>
8#include <memory> 8#include <memory>
9#include <boost/optional.hpp> 9#include <optional>
10
10#include "common/common_types.h" 11#include "common/common_types.h"
11#include "video_core/gpu.h" 12#include "video_core/gpu.h"
12#include "video_core/rasterizer_interface.h" 13#include "video_core/rasterizer_interface.h"
@@ -28,7 +29,8 @@ public:
28 virtual ~RendererBase(); 29 virtual ~RendererBase();
29 30
30 /// Swap buffers (render frame) 31 /// Swap buffers (render frame)
31 virtual void SwapBuffers(boost::optional<const Tegra::FramebufferConfig&> framebuffer) = 0; 32 virtual void SwapBuffers(
33 std::optional<std::reference_wrapper<const Tegra::FramebufferConfig>> framebuffer) = 0;
32 34
33 /// Initialize the renderer 35 /// Initialize the renderer
34 virtual bool Init() = 0; 36 virtual bool Init() = 0;
diff --git a/src/video_core/renderer_opengl/gl_buffer_cache.cpp b/src/video_core/renderer_opengl/gl_buffer_cache.cpp
index c142095c5..41a54b3e7 100644
--- a/src/video_core/renderer_opengl/gl_buffer_cache.cpp
+++ b/src/video_core/renderer_opengl/gl_buffer_cache.cpp
@@ -17,7 +17,7 @@ OGLBufferCache::OGLBufferCache(std::size_t size) : stream_buffer(GL_ARRAY_BUFFER
17GLintptr OGLBufferCache::UploadMemory(Tegra::GPUVAddr gpu_addr, std::size_t size, 17GLintptr OGLBufferCache::UploadMemory(Tegra::GPUVAddr gpu_addr, std::size_t size,
18 std::size_t alignment, bool cache) { 18 std::size_t alignment, bool cache) {
19 auto& memory_manager = Core::System::GetInstance().GPU().MemoryManager(); 19 auto& memory_manager = Core::System::GetInstance().GPU().MemoryManager();
20 const boost::optional<VAddr> cpu_addr{memory_manager.GpuToCpuAddress(gpu_addr)}; 20 const std::optional<VAddr> cpu_addr{memory_manager.GpuToCpuAddress(gpu_addr)};
21 21
22 // Cache management is a big overhead, so only cache entries with a given size. 22 // Cache management is a big overhead, so only cache entries with a given size.
23 // TODO: Figure out which size is the best for given games. 23 // TODO: Figure out which size is the best for given games.
diff --git a/src/video_core/renderer_opengl/gl_primitive_assembler.cpp b/src/video_core/renderer_opengl/gl_primitive_assembler.cpp
index ee1d9601b..741f14bc3 100644
--- a/src/video_core/renderer_opengl/gl_primitive_assembler.cpp
+++ b/src/video_core/renderer_opengl/gl_primitive_assembler.cpp
@@ -45,7 +45,7 @@ GLintptr PrimitiveAssembler::MakeQuadIndexed(Tegra::GPUVAddr gpu_addr, std::size
45 auto [dst_pointer, index_offset] = buffer_cache.ReserveMemory(map_size); 45 auto [dst_pointer, index_offset] = buffer_cache.ReserveMemory(map_size);
46 46
47 auto& memory_manager = Core::System::GetInstance().GPU().MemoryManager(); 47 auto& memory_manager = Core::System::GetInstance().GPU().MemoryManager();
48 const boost::optional<VAddr> cpu_addr{memory_manager.GpuToCpuAddress(gpu_addr)}; 48 const std::optional<VAddr> cpu_addr{memory_manager.GpuToCpuAddress(gpu_addr)};
49 const u8* source{Memory::GetPointer(*cpu_addr)}; 49 const u8* source{Memory::GetPointer(*cpu_addr)};
50 50
51 for (u32 primitive = 0; primitive < count / 4; ++primitive) { 51 for (u32 primitive = 0; primitive < count / 4; ++primitive) {
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp
index cb180b93c..bf381271e 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer.cpp
+++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp
@@ -401,7 +401,7 @@ void RasterizerOpenGL::UpdatePagesCachedCount(VAddr addr, u64 size, int delta) {
401 401
402void RasterizerOpenGL::ConfigureFramebuffers(bool using_color_fb, bool using_depth_fb, 402void RasterizerOpenGL::ConfigureFramebuffers(bool using_color_fb, bool using_depth_fb,
403 bool preserve_contents, 403 bool preserve_contents,
404 boost::optional<std::size_t> single_color_target) { 404 std::optional<std::size_t> single_color_target) {
405 MICROPROFILE_SCOPE(OpenGL_Framebuffer); 405 MICROPROFILE_SCOPE(OpenGL_Framebuffer);
406 const auto& regs = Core::System::GetInstance().GPU().Maxwell3D().regs; 406 const auto& regs = Core::System::GetInstance().GPU().Maxwell3D().regs;
407 407
@@ -731,11 +731,15 @@ void RasterizerOpenGL::SamplerInfo::SyncWithConfig(const Tegra::Texture::TSCEntr
731 731
732 if (mag_filter != config.mag_filter) { 732 if (mag_filter != config.mag_filter) {
733 mag_filter = config.mag_filter; 733 mag_filter = config.mag_filter;
734 glSamplerParameteri(s, GL_TEXTURE_MAG_FILTER, MaxwellToGL::TextureFilterMode(mag_filter)); 734 glSamplerParameteri(
735 s, GL_TEXTURE_MAG_FILTER,
736 MaxwellToGL::TextureFilterMode(mag_filter, Tegra::Texture::TextureMipmapFilter::None));
735 } 737 }
736 if (min_filter != config.min_filter) { 738 if (min_filter != config.min_filter || mip_filter != config.mip_filter) {
737 min_filter = config.min_filter; 739 min_filter = config.min_filter;
738 glSamplerParameteri(s, GL_TEXTURE_MIN_FILTER, MaxwellToGL::TextureFilterMode(min_filter)); 740 mip_filter = config.mip_filter;
741 glSamplerParameteri(s, GL_TEXTURE_MIN_FILTER,
742 MaxwellToGL::TextureFilterMode(min_filter, mip_filter));
739 } 743 }
740 744
741 if (wrap_u != config.wrap_u) { 745 if (wrap_u != config.wrap_u) {
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.h b/src/video_core/renderer_opengl/gl_rasterizer.h
index 5020a5392..47097c569 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer.h
+++ b/src/video_core/renderer_opengl/gl_rasterizer.h
@@ -8,12 +8,12 @@
8#include <cstddef> 8#include <cstddef>
9#include <map> 9#include <map>
10#include <memory> 10#include <memory>
11#include <optional>
11#include <tuple> 12#include <tuple>
12#include <utility> 13#include <utility>
13#include <vector> 14#include <vector>
14 15
15#include <boost/icl/interval_map.hpp> 16#include <boost/icl/interval_map.hpp>
16#include <boost/optional.hpp>
17#include <boost/range/iterator_range.hpp> 17#include <boost/range/iterator_range.hpp>
18#include <glad/glad.h> 18#include <glad/glad.h>
19 19
@@ -93,6 +93,7 @@ private:
93 private: 93 private:
94 Tegra::Texture::TextureFilter mag_filter; 94 Tegra::Texture::TextureFilter mag_filter;
95 Tegra::Texture::TextureFilter min_filter; 95 Tegra::Texture::TextureFilter min_filter;
96 Tegra::Texture::TextureMipmapFilter mip_filter;
96 Tegra::Texture::WrapMode wrap_u; 97 Tegra::Texture::WrapMode wrap_u;
97 Tegra::Texture::WrapMode wrap_v; 98 Tegra::Texture::WrapMode wrap_v;
98 Tegra::Texture::WrapMode wrap_p; 99 Tegra::Texture::WrapMode wrap_p;
@@ -110,7 +111,7 @@ private:
110 */ 111 */
111 void ConfigureFramebuffers(bool use_color_fb = true, bool using_depth_fb = true, 112 void ConfigureFramebuffers(bool use_color_fb = true, bool using_depth_fb = true,
112 bool preserve_contents = true, 113 bool preserve_contents = true,
113 boost::optional<std::size_t> single_color_target = {}); 114 std::optional<std::size_t> single_color_target = {});
114 115
115 /* 116 /*
116 * Configures the current constbuffers to use for the draw command. 117 * Configures the current constbuffers to use for the draw command.
diff --git a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp
index b057e2efa..1d43a419d 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp
+++ b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp
@@ -16,6 +16,7 @@
16#include "core/settings.h" 16#include "core/settings.h"
17#include "video_core/engines/maxwell_3d.h" 17#include "video_core/engines/maxwell_3d.h"
18#include "video_core/renderer_opengl/gl_rasterizer_cache.h" 18#include "video_core/renderer_opengl/gl_rasterizer_cache.h"
19#include "video_core/renderer_opengl/utils.h"
19#include "video_core/textures/astc.h" 20#include "video_core/textures/astc.h"
20#include "video_core/textures/decoders.h" 21#include "video_core/textures/decoders.h"
21#include "video_core/utils.h" 22#include "video_core/utils.h"
@@ -90,27 +91,36 @@ void SurfaceParams::InitCacheParameters(Tegra::GPUVAddr gpu_addr_) {
90 } 91 }
91} 92}
92 93
93std::size_t SurfaceParams::InnerMemorySize(bool layer_only) const { 94std::size_t SurfaceParams::InnerMipmapMemorySize(u32 mip_level, bool force_gl, bool layer_only,
95 bool uncompressed) const {
94 const u32 compression_factor{GetCompressionFactor(pixel_format)}; 96 const u32 compression_factor{GetCompressionFactor(pixel_format)};
95 const u32 bytes_per_pixel{GetBytesPerPixel(pixel_format)}; 97 const u32 bytes_per_pixel{GetBytesPerPixel(pixel_format)};
96 u32 m_depth = (layer_only ? 1U : depth); 98 u32 m_depth = (layer_only ? 1U : depth);
97 u32 m_width = std::max(1U, width / compression_factor); 99 u32 m_width = MipWidth(mip_level);
98 u32 m_height = std::max(1U, height / compression_factor); 100 u32 m_height = MipHeight(mip_level);
99 std::size_t size = Tegra::Texture::CalculateSize(is_tiled, bytes_per_pixel, m_width, m_height, 101 m_width = uncompressed ? m_width
100 m_depth, block_height, block_depth); 102 : std::max(1U, (m_width + compression_factor - 1) / compression_factor);
101 u32 m_block_height = block_height; 103 m_height = uncompressed
102 u32 m_block_depth = block_depth; 104 ? m_height
103 std::size_t block_size_bytes = 512 * block_height * block_depth; // 512 is GOB size 105 : std::max(1U, (m_height + compression_factor - 1) / compression_factor);
104 for (u32 i = 1; i < max_mip_level; i++) { 106 m_depth = std::max(1U, m_depth >> mip_level);
105 m_width = std::max(1U, m_width / 2); 107 u32 m_block_height = MipBlockHeight(mip_level);
106 m_height = std::max(1U, m_height / 2); 108 u32 m_block_depth = MipBlockDepth(mip_level);
107 m_depth = std::max(1U, m_depth / 2); 109 return Tegra::Texture::CalculateSize(force_gl ? false : is_tiled, bytes_per_pixel, m_width,
108 m_block_height = std::max(1U, m_block_height / 2); 110 m_height, m_depth, m_block_height, m_block_depth);
109 m_block_depth = std::max(1U, m_block_depth / 2); 111}
110 size += Tegra::Texture::CalculateSize(is_tiled, bytes_per_pixel, m_width, m_height, m_depth, 112
111 m_block_height, m_block_depth); 113std::size_t SurfaceParams::InnerMemorySize(bool force_gl, bool layer_only,
114 bool uncompressed) const {
115 std::size_t block_size_bytes = Tegra::Texture::GetGOBSize() * block_height * block_depth;
116 std::size_t size = 0;
117 for (u32 i = 0; i < max_mip_level; i++) {
118 size += InnerMipmapMemorySize(i, force_gl, layer_only, uncompressed);
119 }
120 if (!force_gl && is_tiled) {
121 size = Common::AlignUp(size, block_size_bytes);
112 } 122 }
113 return is_tiled ? Common::AlignUp(size, block_size_bytes) : size; 123 return size;
114} 124}
115 125
116/*static*/ SurfaceParams SurfaceParams::CreateForTexture( 126/*static*/ SurfaceParams SurfaceParams::CreateForTexture(
@@ -188,7 +198,7 @@ std::size_t SurfaceParams::InnerMemorySize(bool layer_only) const {
188 params.unaligned_height = config.height; 198 params.unaligned_height = config.height;
189 params.target = SurfaceTarget::Texture2D; 199 params.target = SurfaceTarget::Texture2D;
190 params.depth = 1; 200 params.depth = 1;
191 params.max_mip_level = 0; 201 params.max_mip_level = 1;
192 params.is_layered = false; 202 params.is_layered = false;
193 203
194 // Render target specific parameters, not used for caching 204 // Render target specific parameters, not used for caching
@@ -222,7 +232,7 @@ std::size_t SurfaceParams::InnerMemorySize(bool layer_only) const {
222 params.unaligned_height = zeta_height; 232 params.unaligned_height = zeta_height;
223 params.target = SurfaceTarget::Texture2D; 233 params.target = SurfaceTarget::Texture2D;
224 params.depth = 1; 234 params.depth = 1;
225 params.max_mip_level = 0; 235 params.max_mip_level = 1;
226 params.is_layered = false; 236 params.is_layered = false;
227 params.rt = {}; 237 params.rt = {};
228 238
@@ -249,7 +259,7 @@ std::size_t SurfaceParams::InnerMemorySize(bool layer_only) const {
249 params.unaligned_height = config.height; 259 params.unaligned_height = config.height;
250 params.target = SurfaceTarget::Texture2D; 260 params.target = SurfaceTarget::Texture2D;
251 params.depth = 1; 261 params.depth = 1;
252 params.max_mip_level = 0; 262 params.max_mip_level = 1;
253 params.rt = {}; 263 params.rt = {};
254 264
255 params.InitCacheParameters(config.Address()); 265 params.InitCacheParameters(config.Address());
@@ -273,7 +283,7 @@ static constexpr std::array<FormatTuple, SurfaceParams::MaxPixelFormat> tex_form
273 {GL_R11F_G11F_B10F, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV, ComponentType::Float, 283 {GL_R11F_G11F_B10F, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV, ComponentType::Float,
274 false}, // R11FG11FB10F 284 false}, // R11FG11FB10F
275 {GL_RGBA32UI, GL_RGBA_INTEGER, GL_UNSIGNED_INT, ComponentType::UInt, false}, // RGBA32UI 285 {GL_RGBA32UI, GL_RGBA_INTEGER, GL_UNSIGNED_INT, ComponentType::UInt, false}, // RGBA32UI
276 {GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_RGB, GL_UNSIGNED_INT_8_8_8_8, ComponentType::UNorm, 286 {GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, ComponentType::UNorm,
277 true}, // DXT1 287 true}, // DXT1
278 {GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, ComponentType::UNorm, 288 {GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, ComponentType::UNorm,
279 true}, // DXT23 289 true}, // DXT23
@@ -318,7 +328,7 @@ static constexpr std::array<FormatTuple, SurfaceParams::MaxPixelFormat> tex_form
318 {GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, ComponentType::UNorm, false}, // ASTC_2D_5X4 328 {GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, ComponentType::UNorm, false}, // ASTC_2D_5X4
319 {GL_SRGB8_ALPHA8, GL_BGRA, GL_UNSIGNED_BYTE, ComponentType::UNorm, false}, // BGRA8 329 {GL_SRGB8_ALPHA8, GL_BGRA, GL_UNSIGNED_BYTE, ComponentType::UNorm, false}, // BGRA8
320 // Compressed sRGB formats 330 // Compressed sRGB formats
321 {GL_COMPRESSED_SRGB_S3TC_DXT1_EXT, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, ComponentType::UNorm, 331 {GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, ComponentType::UNorm,
322 true}, // DXT1_SRGB 332 true}, // DXT1_SRGB
323 {GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, ComponentType::UNorm, 333 {GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, ComponentType::UNorm,
324 true}, // DXT23_SRGB 334 true}, // DXT23_SRGB
@@ -373,13 +383,13 @@ static const FormatTuple& GetFormatTuple(PixelFormat pixel_format, ComponentType
373 return format; 383 return format;
374} 384}
375 385
376MathUtil::Rectangle<u32> SurfaceParams::GetRect() const { 386MathUtil::Rectangle<u32> SurfaceParams::GetRect(u32 mip_level) const {
377 u32 actual_height{unaligned_height}; 387 u32 actual_height{std::max(1U, unaligned_height >> mip_level)};
378 if (IsPixelFormatASTC(pixel_format)) { 388 if (IsPixelFormatASTC(pixel_format)) {
379 // ASTC formats must stop at the ATSC block size boundary 389 // ASTC formats must stop at the ATSC block size boundary
380 actual_height = Common::AlignDown(actual_height, GetASTCBlockSize(pixel_format).second); 390 actual_height = Common::AlignDown(actual_height, GetASTCBlockSize(pixel_format).second);
381 } 391 }
382 return {0, actual_height, width, 0}; 392 return {0, actual_height, MipWidth(mip_level), 0};
383} 393}
384 394
385/// Returns true if the specified PixelFormat is a BCn format, e.g. DXT or DXN 395/// Returns true if the specified PixelFormat is a BCn format, e.g. DXT or DXN
@@ -563,28 +573,31 @@ static constexpr GLConversionArray gl_to_morton_fns = {
563}; 573};
564 574
565void SwizzleFunc(const GLConversionArray& functions, const SurfaceParams& params, 575void SwizzleFunc(const GLConversionArray& functions, const SurfaceParams& params,
566 std::vector<u8>& gl_buffer) { 576 std::vector<u8>& gl_buffer, u32 mip_level) {
567 u32 depth = params.depth; 577 u32 depth = params.MipDepth(mip_level);
568 if (params.target == SurfaceParams::SurfaceTarget::Texture2D) { 578 if (params.target == SurfaceParams::SurfaceTarget::Texture2D) {
569 // TODO(Blinkhawk): Eliminate this condition once all texture types are implemented. 579 // TODO(Blinkhawk): Eliminate this condition once all texture types are implemented.
570 depth = 1U; 580 depth = 1U;
571 } 581 }
572 if (params.is_layered) { 582 if (params.is_layered) {
573 u64 offset = 0; 583 u64 offset = params.GetMipmapLevelOffset(mip_level);
574 u64 offset_gl = 0; 584 u64 offset_gl = 0;
575 u64 layer_size = params.LayerMemorySize(); 585 u64 layer_size = params.LayerMemorySize();
576 u64 gl_size = params.LayerSizeGL(); 586 u64 gl_size = params.LayerSizeGL(mip_level);
577 for (u32 i = 0; i < depth; i++) { 587 for (u32 i = 0; i < params.depth; i++) {
578 functions[static_cast<std::size_t>(params.pixel_format)]( 588 functions[static_cast<std::size_t>(params.pixel_format)](
579 params.width, params.block_height, params.height, params.block_depth, 1, 589 params.MipWidth(mip_level), params.MipBlockHeight(mip_level),
590 params.MipHeight(mip_level), params.MipBlockDepth(mip_level), 1,
580 gl_buffer.data() + offset_gl, gl_size, params.addr + offset); 591 gl_buffer.data() + offset_gl, gl_size, params.addr + offset);
581 offset += layer_size; 592 offset += layer_size;
582 offset_gl += gl_size; 593 offset_gl += gl_size;
583 } 594 }
584 } else { 595 } else {
596 u64 offset = params.GetMipmapLevelOffset(mip_level);
585 functions[static_cast<std::size_t>(params.pixel_format)]( 597 functions[static_cast<std::size_t>(params.pixel_format)](
586 params.width, params.block_height, params.height, params.block_depth, depth, 598 params.MipWidth(mip_level), params.MipBlockHeight(mip_level),
587 gl_buffer.data(), gl_buffer.size(), params.addr); 599 params.MipHeight(mip_level), params.MipBlockDepth(mip_level), depth, gl_buffer.data(),
600 gl_buffer.size(), params.addr + offset);
588 } 601 }
589} 602}
590 603
@@ -839,34 +852,41 @@ CachedSurface::CachedSurface(const SurfaceParams& params)
839 // Only pre-create the texture for non-compressed textures. 852 // Only pre-create the texture for non-compressed textures.
840 switch (params.target) { 853 switch (params.target) {
841 case SurfaceParams::SurfaceTarget::Texture1D: 854 case SurfaceParams::SurfaceTarget::Texture1D:
842 glTexStorage1D(SurfaceTargetToGL(params.target), 1, format_tuple.internal_format, 855 glTexStorage1D(SurfaceTargetToGL(params.target), params.max_mip_level,
843 rect.GetWidth()); 856 format_tuple.internal_format, rect.GetWidth());
844 break; 857 break;
845 case SurfaceParams::SurfaceTarget::Texture2D: 858 case SurfaceParams::SurfaceTarget::Texture2D:
846 case SurfaceParams::SurfaceTarget::TextureCubemap: 859 case SurfaceParams::SurfaceTarget::TextureCubemap:
847 glTexStorage2D(SurfaceTargetToGL(params.target), 1, format_tuple.internal_format, 860 glTexStorage2D(SurfaceTargetToGL(params.target), params.max_mip_level,
848 rect.GetWidth(), rect.GetHeight()); 861 format_tuple.internal_format, rect.GetWidth(), rect.GetHeight());
849 break; 862 break;
850 case SurfaceParams::SurfaceTarget::Texture3D: 863 case SurfaceParams::SurfaceTarget::Texture3D:
851 case SurfaceParams::SurfaceTarget::Texture2DArray: 864 case SurfaceParams::SurfaceTarget::Texture2DArray:
852 glTexStorage3D(SurfaceTargetToGL(params.target), 1, format_tuple.internal_format, 865 glTexStorage3D(SurfaceTargetToGL(params.target), params.max_mip_level,
853 rect.GetWidth(), rect.GetHeight(), params.depth); 866 format_tuple.internal_format, rect.GetWidth(), rect.GetHeight(),
867 params.depth);
854 break; 868 break;
855 default: 869 default:
856 LOG_CRITICAL(Render_OpenGL, "Unimplemented surface target={}", 870 LOG_CRITICAL(Render_OpenGL, "Unimplemented surface target={}",
857 static_cast<u32>(params.target)); 871 static_cast<u32>(params.target));
858 UNREACHABLE(); 872 UNREACHABLE();
859 glTexStorage2D(GL_TEXTURE_2D, 1, format_tuple.internal_format, rect.GetWidth(), 873 glTexStorage2D(GL_TEXTURE_2D, params.max_mip_level, format_tuple.internal_format,
860 rect.GetHeight()); 874 rect.GetWidth(), rect.GetHeight());
861 } 875 }
862 } 876 }
863 877
864 glTexParameteri(SurfaceTargetToGL(params.target), GL_TEXTURE_MIN_FILTER, GL_LINEAR); 878 glTexParameteri(SurfaceTargetToGL(params.target), GL_TEXTURE_MIN_FILTER, GL_LINEAR);
879 glTexParameteri(SurfaceTargetToGL(params.target), GL_TEXTURE_MAG_FILTER, GL_LINEAR);
865 glTexParameteri(SurfaceTargetToGL(params.target), GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 880 glTexParameteri(SurfaceTargetToGL(params.target), GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
866 glTexParameteri(SurfaceTargetToGL(params.target), GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 881 glTexParameteri(SurfaceTargetToGL(params.target), GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
882 glTexParameteri(SurfaceTargetToGL(params.target), GL_TEXTURE_MAX_LEVEL,
883 params.max_mip_level - 1);
884 if (params.max_mip_level == 1) {
885 glTexParameterf(SurfaceTargetToGL(params.target), GL_TEXTURE_LOD_BIAS, 1000.0);
886 }
867 887
868 VideoCore::LabelGLObject(GL_TEXTURE, texture.handle, params.addr, 888 LabelGLObject(GL_TEXTURE, texture.handle, params.addr,
869 SurfaceParams::SurfaceTargetName(params.target)); 889 SurfaceParams::SurfaceTargetName(params.target));
870 890
871 // Clamp size to mapped GPU memory region 891 // Clamp size to mapped GPU memory region
872 // TODO(bunnei): Super Mario Odyssey maps a 0x40000 byte region and then uses it for a 0x80000 892 // TODO(bunnei): Super Mario Odyssey maps a 0x40000 byte region and then uses it for a 0x80000
@@ -992,20 +1012,22 @@ static void ConvertFormatAsNeeded_FlushGLBuffer(std::vector<u8>& data, PixelForm
992MICROPROFILE_DEFINE(OpenGL_SurfaceLoad, "OpenGL", "Surface Load", MP_RGB(128, 64, 192)); 1012MICROPROFILE_DEFINE(OpenGL_SurfaceLoad, "OpenGL", "Surface Load", MP_RGB(128, 64, 192));
993void CachedSurface::LoadGLBuffer() { 1013void CachedSurface::LoadGLBuffer() {
994 MICROPROFILE_SCOPE(OpenGL_SurfaceLoad); 1014 MICROPROFILE_SCOPE(OpenGL_SurfaceLoad);
995 1015 gl_buffer.resize(params.max_mip_level);
996 gl_buffer.resize(params.size_in_bytes_gl); 1016 for (u32 i = 0; i < params.max_mip_level; i++)
1017 gl_buffer[i].resize(params.GetMipmapSizeGL(i));
997 if (params.is_tiled) { 1018 if (params.is_tiled) {
998 ASSERT_MSG(params.block_width == 1, "Block width is defined as {} on texture type {}", 1019 ASSERT_MSG(params.block_width == 1, "Block width is defined as {} on texture type {}",
999 params.block_width, static_cast<u32>(params.target)); 1020 params.block_width, static_cast<u32>(params.target));
1000 1021 for (u32 i = 0; i < params.max_mip_level; i++)
1001 SwizzleFunc(morton_to_gl_fns, params, gl_buffer); 1022 SwizzleFunc(morton_to_gl_fns, params, gl_buffer[i], i);
1002 } else { 1023 } else {
1003 const auto texture_src_data{Memory::GetPointer(params.addr)}; 1024 const auto texture_src_data{Memory::GetPointer(params.addr)};
1004 const auto texture_src_data_end{texture_src_data + params.size_in_bytes_gl}; 1025 const auto texture_src_data_end{texture_src_data + params.size_in_bytes_gl};
1005 gl_buffer.assign(texture_src_data, texture_src_data_end); 1026 gl_buffer[0].assign(texture_src_data, texture_src_data_end);
1006 } 1027 }
1007 1028 for (u32 i = 0; i < params.max_mip_level; i++)
1008 ConvertFormatAsNeeded_LoadGLBuffer(gl_buffer, params.pixel_format, params.width, params.height); 1029 ConvertFormatAsNeeded_LoadGLBuffer(gl_buffer[i], params.pixel_format, params.MipWidth(i),
1030 params.MipHeight(i));
1009} 1031}
1010 1032
1011MICROPROFILE_DEFINE(OpenGL_SurfaceFlush, "OpenGL", "Surface Flush", MP_RGB(128, 192, 64)); 1033MICROPROFILE_DEFINE(OpenGL_SurfaceFlush, "OpenGL", "Surface Flush", MP_RGB(128, 192, 64));
@@ -1015,7 +1037,8 @@ void CachedSurface::FlushGLBuffer() {
1015 ASSERT_MSG(!IsPixelFormatASTC(params.pixel_format), "Unimplemented"); 1037 ASSERT_MSG(!IsPixelFormatASTC(params.pixel_format), "Unimplemented");
1016 1038
1017 // OpenGL temporary buffer needs to be big enough to store raw texture size 1039 // OpenGL temporary buffer needs to be big enough to store raw texture size
1018 gl_buffer.resize(GetSizeInBytes()); 1040 gl_buffer.resize(1);
1041 gl_buffer[0].resize(GetSizeInBytes());
1019 1042
1020 const FormatTuple& tuple = GetFormatTuple(params.pixel_format, params.component_type); 1043 const FormatTuple& tuple = GetFormatTuple(params.pixel_format, params.component_type);
1021 // Ensure no bad interactions with GL_UNPACK_ALIGNMENT 1044 // Ensure no bad interactions with GL_UNPACK_ALIGNMENT
@@ -1024,9 +1047,9 @@ void CachedSurface::FlushGLBuffer() {
1024 ASSERT(!tuple.compressed); 1047 ASSERT(!tuple.compressed);
1025 glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); 1048 glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
1026 glGetTextureImage(texture.handle, 0, tuple.format, tuple.type, 1049 glGetTextureImage(texture.handle, 0, tuple.format, tuple.type,
1027 static_cast<GLsizei>(gl_buffer.size()), gl_buffer.data()); 1050 static_cast<GLsizei>(gl_buffer[0].size()), gl_buffer[0].data());
1028 glPixelStorei(GL_PACK_ROW_LENGTH, 0); 1051 glPixelStorei(GL_PACK_ROW_LENGTH, 0);
1029 ConvertFormatAsNeeded_FlushGLBuffer(gl_buffer, params.pixel_format, params.width, 1052 ConvertFormatAsNeeded_FlushGLBuffer(gl_buffer[0], params.pixel_format, params.width,
1030 params.height); 1053 params.height);
1031 ASSERT(params.type != SurfaceType::Fill); 1054 ASSERT(params.type != SurfaceType::Fill);
1032 const u8* const texture_src_data = Memory::GetPointer(params.addr); 1055 const u8* const texture_src_data = Memory::GetPointer(params.addr);
@@ -1035,26 +1058,21 @@ void CachedSurface::FlushGLBuffer() {
1035 ASSERT_MSG(params.block_width == 1, "Block width is defined as {} on texture type {}", 1058 ASSERT_MSG(params.block_width == 1, "Block width is defined as {} on texture type {}",
1036 params.block_width, static_cast<u32>(params.target)); 1059 params.block_width, static_cast<u32>(params.target));
1037 1060
1038 SwizzleFunc(gl_to_morton_fns, params, gl_buffer); 1061 SwizzleFunc(gl_to_morton_fns, params, gl_buffer[0], 0);
1039 } else { 1062 } else {
1040 std::memcpy(Memory::GetPointer(GetAddr()), gl_buffer.data(), GetSizeInBytes()); 1063 std::memcpy(Memory::GetPointer(GetAddr()), gl_buffer[0].data(), GetSizeInBytes());
1041 } 1064 }
1042} 1065}
1043 1066
1044MICROPROFILE_DEFINE(OpenGL_TextureUL, "OpenGL", "Texture Upload", MP_RGB(128, 64, 192)); 1067void CachedSurface::UploadGLMipmapTexture(u32 mip_map, GLuint read_fb_handle,
1045void CachedSurface::UploadGLTexture(GLuint read_fb_handle, GLuint draw_fb_handle) { 1068 GLuint draw_fb_handle) {
1046 if (params.type == SurfaceType::Fill) 1069 const auto& rect{params.GetRect(mip_map)};
1047 return;
1048
1049 MICROPROFILE_SCOPE(OpenGL_TextureUL);
1050
1051 const auto& rect{params.GetRect()};
1052 1070
1053 // Load data from memory to the surface 1071 // Load data from memory to the surface
1054 const GLint x0 = static_cast<GLint>(rect.left); 1072 const GLint x0 = static_cast<GLint>(rect.left);
1055 const GLint y0 = static_cast<GLint>(rect.bottom); 1073 const GLint y0 = static_cast<GLint>(rect.bottom);
1056 std::size_t buffer_offset = 1074 std::size_t buffer_offset =
1057 static_cast<std::size_t>(static_cast<std::size_t>(y0) * params.width + 1075 static_cast<std::size_t>(static_cast<std::size_t>(y0) * params.MipWidth(mip_map) +
1058 static_cast<std::size_t>(x0)) * 1076 static_cast<std::size_t>(x0)) *
1059 SurfaceParams::GetBytesPerPixel(params.pixel_format); 1077 SurfaceParams::GetBytesPerPixel(params.pixel_format);
1060 1078
@@ -1072,88 +1090,117 @@ void CachedSurface::UploadGLTexture(GLuint read_fb_handle, GLuint draw_fb_handle
1072 cur_state.Apply(); 1090 cur_state.Apply();
1073 1091
1074 // Ensure no bad interactions with GL_UNPACK_ALIGNMENT 1092 // Ensure no bad interactions with GL_UNPACK_ALIGNMENT
1075 ASSERT(params.width * SurfaceParams::GetBytesPerPixel(params.pixel_format) % 4 == 0); 1093 ASSERT(params.MipWidth(mip_map) * SurfaceParams::GetBytesPerPixel(params.pixel_format) % 4 ==
1076 glPixelStorei(GL_UNPACK_ROW_LENGTH, static_cast<GLint>(params.width)); 1094 0);
1095 glPixelStorei(GL_UNPACK_ROW_LENGTH, static_cast<GLint>(params.MipWidth(mip_map)));
1077 1096
1097 GLsizei image_size = static_cast<GLsizei>(params.GetMipmapSizeGL(mip_map, false));
1078 glActiveTexture(GL_TEXTURE0); 1098 glActiveTexture(GL_TEXTURE0);
1079 if (tuple.compressed) { 1099 if (tuple.compressed) {
1080 switch (params.target) { 1100 switch (params.target) {
1081 case SurfaceParams::SurfaceTarget::Texture2D: 1101 case SurfaceParams::SurfaceTarget::Texture2D:
1082 glCompressedTexImage2D( 1102 glCompressedTexImage2D(SurfaceTargetToGL(params.target), mip_map, tuple.internal_format,
1083 SurfaceTargetToGL(params.target), 0, tuple.internal_format, 1103 static_cast<GLsizei>(params.MipWidth(mip_map)),
1084 static_cast<GLsizei>(params.width), static_cast<GLsizei>(params.height), 0, 1104 static_cast<GLsizei>(params.MipHeight(mip_map)), 0, image_size,
1085 static_cast<GLsizei>(params.size_in_bytes_gl), &gl_buffer[buffer_offset]); 1105 &gl_buffer[mip_map][buffer_offset]);
1086 break; 1106 break;
1087 case SurfaceParams::SurfaceTarget::Texture3D: 1107 case SurfaceParams::SurfaceTarget::Texture3D:
1108 glCompressedTexImage3D(SurfaceTargetToGL(params.target), mip_map, tuple.internal_format,
1109 static_cast<GLsizei>(params.MipWidth(mip_map)),
1110 static_cast<GLsizei>(params.MipHeight(mip_map)),
1111 static_cast<GLsizei>(params.MipDepth(mip_map)), 0, image_size,
1112 &gl_buffer[mip_map][buffer_offset]);
1113 break;
1088 case SurfaceParams::SurfaceTarget::Texture2DArray: 1114 case SurfaceParams::SurfaceTarget::Texture2DArray:
1089 glCompressedTexImage3D( 1115 glCompressedTexImage3D(SurfaceTargetToGL(params.target), mip_map, tuple.internal_format,
1090 SurfaceTargetToGL(params.target), 0, tuple.internal_format, 1116 static_cast<GLsizei>(params.MipWidth(mip_map)),
1091 static_cast<GLsizei>(params.width), static_cast<GLsizei>(params.height), 1117 static_cast<GLsizei>(params.MipHeight(mip_map)),
1092 static_cast<GLsizei>(params.depth), 0, 1118 static_cast<GLsizei>(params.depth), 0, image_size,
1093 static_cast<GLsizei>(params.size_in_bytes_gl), &gl_buffer[buffer_offset]); 1119 &gl_buffer[mip_map][buffer_offset]);
1094 break; 1120 break;
1095 case SurfaceParams::SurfaceTarget::TextureCubemap: 1121 case SurfaceParams::SurfaceTarget::TextureCubemap: {
1122 GLsizei layer_size = static_cast<GLsizei>(params.LayerSizeGL(mip_map));
1096 for (std::size_t face = 0; face < params.depth; ++face) { 1123 for (std::size_t face = 0; face < params.depth; ++face) {
1097 glCompressedTexImage2D(static_cast<GLenum>(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face), 1124 glCompressedTexImage2D(static_cast<GLenum>(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face),
1098 0, tuple.internal_format, static_cast<GLsizei>(params.width), 1125 mip_map, tuple.internal_format,
1099 static_cast<GLsizei>(params.height), 0, 1126 static_cast<GLsizei>(params.MipWidth(mip_map)),
1100 static_cast<GLsizei>(params.SizeInBytesCubeFaceGL()), 1127 static_cast<GLsizei>(params.MipHeight(mip_map)), 0,
1101 &gl_buffer[buffer_offset]); 1128 layer_size, &gl_buffer[mip_map][buffer_offset]);
1102 buffer_offset += params.SizeInBytesCubeFace(); 1129 buffer_offset += layer_size;
1103 } 1130 }
1104 break; 1131 break;
1132 }
1105 default: 1133 default:
1106 LOG_CRITICAL(Render_OpenGL, "Unimplemented surface target={}", 1134 LOG_CRITICAL(Render_OpenGL, "Unimplemented surface target={}",
1107 static_cast<u32>(params.target)); 1135 static_cast<u32>(params.target));
1108 UNREACHABLE(); 1136 UNREACHABLE();
1109 glCompressedTexImage2D( 1137 glCompressedTexImage2D(GL_TEXTURE_2D, mip_map, tuple.internal_format,
1110 GL_TEXTURE_2D, 0, tuple.internal_format, static_cast<GLsizei>(params.width), 1138 static_cast<GLsizei>(params.MipWidth(mip_map)),
1111 static_cast<GLsizei>(params.height), 0, 1139 static_cast<GLsizei>(params.MipHeight(mip_map)), 0,
1112 static_cast<GLsizei>(params.size_in_bytes_gl), &gl_buffer[buffer_offset]); 1140 static_cast<GLsizei>(params.size_in_bytes_gl),
1141 &gl_buffer[mip_map][buffer_offset]);
1113 } 1142 }
1114 } else { 1143 } else {
1115 1144
1116 switch (params.target) { 1145 switch (params.target) {
1117 case SurfaceParams::SurfaceTarget::Texture1D: 1146 case SurfaceParams::SurfaceTarget::Texture1D:
1118 glTexSubImage1D(SurfaceTargetToGL(params.target), 0, x0, 1147 glTexSubImage1D(SurfaceTargetToGL(params.target), mip_map, x0,
1119 static_cast<GLsizei>(rect.GetWidth()), tuple.format, tuple.type, 1148 static_cast<GLsizei>(rect.GetWidth()), tuple.format, tuple.type,
1120 &gl_buffer[buffer_offset]); 1149 &gl_buffer[mip_map][buffer_offset]);
1121 break; 1150 break;
1122 case SurfaceParams::SurfaceTarget::Texture2D: 1151 case SurfaceParams::SurfaceTarget::Texture2D:
1123 glTexSubImage2D(SurfaceTargetToGL(params.target), 0, x0, y0, 1152 glTexSubImage2D(SurfaceTargetToGL(params.target), mip_map, x0, y0,
1124 static_cast<GLsizei>(rect.GetWidth()), 1153 static_cast<GLsizei>(rect.GetWidth()),
1125 static_cast<GLsizei>(rect.GetHeight()), tuple.format, tuple.type, 1154 static_cast<GLsizei>(rect.GetHeight()), tuple.format, tuple.type,
1126 &gl_buffer[buffer_offset]); 1155 &gl_buffer[mip_map][buffer_offset]);
1127 break; 1156 break;
1128 case SurfaceParams::SurfaceTarget::Texture3D: 1157 case SurfaceParams::SurfaceTarget::Texture3D:
1158 glTexSubImage3D(SurfaceTargetToGL(params.target), mip_map, x0, y0, 0,
1159 static_cast<GLsizei>(rect.GetWidth()),
1160 static_cast<GLsizei>(rect.GetHeight()), params.MipDepth(mip_map),
1161 tuple.format, tuple.type, &gl_buffer[mip_map][buffer_offset]);
1162 break;
1129 case SurfaceParams::SurfaceTarget::Texture2DArray: 1163 case SurfaceParams::SurfaceTarget::Texture2DArray:
1130 glTexSubImage3D(SurfaceTargetToGL(params.target), 0, x0, y0, 0, 1164 glTexSubImage3D(SurfaceTargetToGL(params.target), mip_map, x0, y0, 0,
1131 static_cast<GLsizei>(rect.GetWidth()), 1165 static_cast<GLsizei>(rect.GetWidth()),
1132 static_cast<GLsizei>(rect.GetHeight()), params.depth, tuple.format, 1166 static_cast<GLsizei>(rect.GetHeight()), params.depth, tuple.format,
1133 tuple.type, &gl_buffer[buffer_offset]); 1167 tuple.type, &gl_buffer[mip_map][buffer_offset]);
1134 break; 1168 break;
1135 case SurfaceParams::SurfaceTarget::TextureCubemap: 1169 case SurfaceParams::SurfaceTarget::TextureCubemap: {
1170 std::size_t start = buffer_offset;
1136 for (std::size_t face = 0; face < params.depth; ++face) { 1171 for (std::size_t face = 0; face < params.depth; ++face) {
1137 glTexSubImage2D(static_cast<GLenum>(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face), 0, x0, 1172 glTexSubImage2D(static_cast<GLenum>(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face), mip_map,
1138 y0, static_cast<GLsizei>(rect.GetWidth()), 1173 x0, y0, static_cast<GLsizei>(rect.GetWidth()),
1139 static_cast<GLsizei>(rect.GetHeight()), tuple.format, tuple.type, 1174 static_cast<GLsizei>(rect.GetHeight()), tuple.format, tuple.type,
1140 &gl_buffer[buffer_offset]); 1175 &gl_buffer[mip_map][buffer_offset]);
1141 buffer_offset += params.SizeInBytesCubeFace(); 1176 buffer_offset += params.LayerSizeGL(mip_map);
1142 } 1177 }
1143 break; 1178 break;
1179 }
1144 default: 1180 default:
1145 LOG_CRITICAL(Render_OpenGL, "Unimplemented surface target={}", 1181 LOG_CRITICAL(Render_OpenGL, "Unimplemented surface target={}",
1146 static_cast<u32>(params.target)); 1182 static_cast<u32>(params.target));
1147 UNREACHABLE(); 1183 UNREACHABLE();
1148 glTexSubImage2D(GL_TEXTURE_2D, 0, x0, y0, static_cast<GLsizei>(rect.GetWidth()), 1184 glTexSubImage2D(GL_TEXTURE_2D, mip_map, x0, y0, static_cast<GLsizei>(rect.GetWidth()),
1149 static_cast<GLsizei>(rect.GetHeight()), tuple.format, tuple.type, 1185 static_cast<GLsizei>(rect.GetHeight()), tuple.format, tuple.type,
1150 &gl_buffer[buffer_offset]); 1186 &gl_buffer[mip_map][buffer_offset]);
1151 } 1187 }
1152 } 1188 }
1153 1189
1154 glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); 1190 glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
1155} 1191}
1156 1192
1193MICROPROFILE_DEFINE(OpenGL_TextureUL, "OpenGL", "Texture Upload", MP_RGB(128, 64, 192));
1194void CachedSurface::UploadGLTexture(GLuint read_fb_handle, GLuint draw_fb_handle) {
1195 if (params.type == SurfaceType::Fill)
1196 return;
1197
1198 MICROPROFILE_SCOPE(OpenGL_TextureUL);
1199
1200 for (u32 i = 0; i < params.max_mip_level; i++)
1201 UploadGLMipmapTexture(i, read_fb_handle, draw_fb_handle);
1202}
1203
1157RasterizerCacheOpenGL::RasterizerCacheOpenGL() { 1204RasterizerCacheOpenGL::RasterizerCacheOpenGL() {
1158 read_framebuffer.Create(); 1205 read_framebuffer.Create();
1159 draw_framebuffer.Create(); 1206 draw_framebuffer.Create();
diff --git a/src/video_core/renderer_opengl/gl_rasterizer_cache.h b/src/video_core/renderer_opengl/gl_rasterizer_cache.h
index b4701a616..e72f4f2d2 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer_cache.h
+++ b/src/video_core/renderer_opengl/gl_rasterizer_cache.h
@@ -395,7 +395,7 @@ struct SurfaceParams {
395 64, // RG32UI 395 64, // RG32UI
396 32, // R32UI 396 32, // R32UI
397 16, // ASTC_2D_8X8 397 16, // ASTC_2D_8X8
398 32, // ASTC_2D_8X5 398 16, // ASTC_2D_8X5
399 32, // ASTC_2D_5X4 399 32, // ASTC_2D_5X4
400 32, // BGRA8_SRGB 400 32, // BGRA8_SRGB
401 64, // DXT1_SRGB 401 64, // DXT1_SRGB
@@ -404,7 +404,7 @@ struct SurfaceParams {
404 128, // BC7U 404 128, // BC7U
405 32, // ASTC_2D_4X4_SRGB 405 32, // ASTC_2D_4X4_SRGB
406 16, // ASTC_2D_8X8_SRGB 406 16, // ASTC_2D_8X8_SRGB
407 32, // ASTC_2D_8X5_SRGB 407 16, // ASTC_2D_8X5_SRGB
408 32, // ASTC_2D_5X4_SRGB 408 32, // ASTC_2D_5X4_SRGB
409 32, // Z32F 409 32, // Z32F
410 16, // Z16 410 16, // Z16
@@ -834,7 +834,7 @@ struct SurfaceParams {
834 } 834 }
835 835
836 /// Returns the rectangle corresponding to this surface 836 /// Returns the rectangle corresponding to this surface
837 MathUtil::Rectangle<u32> GetRect() const; 837 MathUtil::Rectangle<u32> GetRect(u32 mip_level = 0) const;
838 838
839 /// Returns the total size of this surface in bytes, adjusted for compression 839 /// Returns the total size of this surface in bytes, adjusted for compression
840 std::size_t SizeInBytesRaw(bool ignore_tiled = false) const { 840 std::size_t SizeInBytesRaw(bool ignore_tiled = false) const {
@@ -865,7 +865,7 @@ struct SurfaceParams {
865 865
866 /// Returns the exact size of memory occupied by the texture in VRAM, including mipmaps. 866 /// Returns the exact size of memory occupied by the texture in VRAM, including mipmaps.
867 std::size_t MemorySize() const { 867 std::size_t MemorySize() const {
868 std::size_t size = InnerMemorySize(is_layered); 868 std::size_t size = InnerMemorySize(false, is_layered);
869 if (is_layered) 869 if (is_layered)
870 return size * depth; 870 return size * depth;
871 return size; 871 return size;
@@ -874,12 +874,78 @@ struct SurfaceParams {
874 /// Returns the exact size of the memory occupied by a layer in a texture in VRAM, including 874 /// Returns the exact size of the memory occupied by a layer in a texture in VRAM, including
875 /// mipmaps. 875 /// mipmaps.
876 std::size_t LayerMemorySize() const { 876 std::size_t LayerMemorySize() const {
877 return InnerMemorySize(true); 877 return InnerMemorySize(false, true);
878 } 878 }
879 879
880 /// Returns the size of a layer of this surface in OpenGL. 880 /// Returns the size of a layer of this surface in OpenGL.
881 std::size_t LayerSizeGL() const { 881 std::size_t LayerSizeGL(u32 mip_level) const {
882 return SizeInBytesRaw(true) / depth; 882 return InnerMipmapMemorySize(mip_level, true, is_layered, false);
883 }
884
885 std::size_t GetMipmapSizeGL(u32 mip_level, bool ignore_compressed = true) const {
886 std::size_t size = InnerMipmapMemorySize(mip_level, true, is_layered, ignore_compressed);
887 if (is_layered)
888 return size * depth;
889 return size;
890 }
891
892 std::size_t GetMipmapLevelOffset(u32 mip_level) const {
893 std::size_t offset = 0;
894 for (u32 i = 0; i < mip_level; i++)
895 offset += InnerMipmapMemorySize(i, false, is_layered);
896 return offset;
897 }
898
899 std::size_t GetMipmapLevelOffsetGL(u32 mip_level) const {
900 std::size_t offset = 0;
901 for (u32 i = 0; i < mip_level; i++)
902 offset += InnerMipmapMemorySize(i, true, is_layered);
903 return offset;
904 }
905
906 u32 MipWidth(u32 mip_level) const {
907 return std::max(1U, width >> mip_level);
908 }
909
910 u32 MipHeight(u32 mip_level) const {
911 return std::max(1U, height >> mip_level);
912 }
913
914 u32 MipDepth(u32 mip_level) const {
915 return std::max(1U, depth >> mip_level);
916 }
917
918 // Auto block resizing algorithm from:
919 // https://cgit.freedesktop.org/mesa/mesa/tree/src/gallium/drivers/nouveau/nv50/nv50_miptree.c
920 u32 MipBlockHeight(u32 mip_level) const {
921 if (mip_level == 0)
922 return block_height;
923 u32 alt_height = MipHeight(mip_level);
924 u32 h = GetDefaultBlockHeight(pixel_format);
925 u32 blocks_in_y = (alt_height + h - 1) / h;
926 u32 bh = 16;
927 while (bh > 1 && blocks_in_y <= bh * 4) {
928 bh >>= 1;
929 }
930 return bh;
931 }
932
933 u32 MipBlockDepth(u32 mip_level) const {
934 if (mip_level == 0)
935 return block_depth;
936 if (is_layered)
937 return 1;
938 u32 depth = MipDepth(mip_level);
939 u32 bd = 32;
940 while (bd > 1 && depth * 2 <= bd) {
941 bd >>= 1;
942 }
943 if (bd == 32) {
944 u32 bh = MipBlockHeight(mip_level);
945 if (bh >= 4)
946 return 16;
947 }
948 return bd;
883 } 949 }
884 950
885 /// Creates SurfaceParams from a texture configuration 951 /// Creates SurfaceParams from a texture configuration
@@ -940,7 +1006,10 @@ struct SurfaceParams {
940 } rt; 1006 } rt;
941 1007
942private: 1008private:
943 std::size_t InnerMemorySize(bool layer_only = false) const; 1009 std::size_t InnerMipmapMemorySize(u32 mip_level, bool force_gl = false, bool layer_only = false,
1010 bool uncompressed = false) const;
1011 std::size_t InnerMemorySize(bool force_gl = false, bool layer_only = false,
1012 bool uncompressed = false) const;
944}; 1013};
945 1014
946}; // namespace OpenGL 1015}; // namespace OpenGL
@@ -1002,8 +1071,10 @@ public:
1002 void UploadGLTexture(GLuint read_fb_handle, GLuint draw_fb_handle); 1071 void UploadGLTexture(GLuint read_fb_handle, GLuint draw_fb_handle);
1003 1072
1004private: 1073private:
1074 void UploadGLMipmapTexture(u32 mip_map, GLuint read_fb_handle, GLuint draw_fb_handle);
1075
1005 OGLTexture texture; 1076 OGLTexture texture;
1006 std::vector<u8> gl_buffer; 1077 std::vector<std::vector<u8>> gl_buffer;
1007 SurfaceParams params; 1078 SurfaceParams params;
1008 GLenum gl_target; 1079 GLenum gl_target;
1009 std::size_t cached_size_in_bytes; 1080 std::size_t cached_size_in_bytes;
diff --git a/src/video_core/renderer_opengl/gl_shader_cache.cpp b/src/video_core/renderer_opengl/gl_shader_cache.cpp
index 1a03a677f..9522fd344 100644
--- a/src/video_core/renderer_opengl/gl_shader_cache.cpp
+++ b/src/video_core/renderer_opengl/gl_shader_cache.cpp
@@ -8,6 +8,7 @@
8#include "video_core/engines/maxwell_3d.h" 8#include "video_core/engines/maxwell_3d.h"
9#include "video_core/renderer_opengl/gl_shader_cache.h" 9#include "video_core/renderer_opengl/gl_shader_cache.h"
10#include "video_core/renderer_opengl/gl_shader_manager.h" 10#include "video_core/renderer_opengl/gl_shader_manager.h"
11#include "video_core/renderer_opengl/utils.h"
11#include "video_core/utils.h" 12#include "video_core/utils.h"
12 13
13namespace OpenGL { 14namespace OpenGL {
@@ -89,7 +90,7 @@ CachedShader::CachedShader(VAddr addr, Maxwell::ShaderProgram program_type)
89 shader.Create(program_result.first.c_str(), gl_type); 90 shader.Create(program_result.first.c_str(), gl_type);
90 program.Create(true, shader.handle); 91 program.Create(true, shader.handle);
91 SetShaderUniformBlockBindings(program.handle); 92 SetShaderUniformBlockBindings(program.handle);
92 VideoCore::LabelGLObject(GL_PROGRAM, program.handle, addr); 93 LabelGLObject(GL_PROGRAM, program.handle, addr);
93 } else { 94 } else {
94 // Store shader's code to lazily build it on draw 95 // Store shader's code to lazily build it on draw
95 geometry_programs.code = program_result.first; 96 geometry_programs.code = program_result.first;
@@ -130,7 +131,7 @@ GLuint CachedShader::LazyGeometryProgram(OGLProgram& target_program,
130 shader.Create(source.c_str(), GL_GEOMETRY_SHADER); 131 shader.Create(source.c_str(), GL_GEOMETRY_SHADER);
131 target_program.Create(true, shader.handle); 132 target_program.Create(true, shader.handle);
132 SetShaderUniformBlockBindings(target_program.handle); 133 SetShaderUniformBlockBindings(target_program.handle);
133 VideoCore::LabelGLObject(GL_PROGRAM, target_program.handle, addr, debug_name); 134 LabelGLObject(GL_PROGRAM, target_program.handle, addr, debug_name);
134 return target_program.handle; 135 return target_program.handle;
135}; 136};
136 137
diff --git a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp
index dcf6941b0..d1f6ffe40 100644
--- a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp
+++ b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp
@@ -3,12 +3,12 @@
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include <map> 5#include <map>
6#include <optional>
6#include <set> 7#include <set>
7#include <string> 8#include <string>
8#include <string_view> 9#include <string_view>
9#include <unordered_set> 10#include <unordered_set>
10 11
11#include <boost/optional.hpp>
12#include <fmt/format.h> 12#include <fmt/format.h>
13 13
14#include "common/assert.h" 14#include "common/assert.h"
@@ -144,7 +144,7 @@ private:
144 for (u32 offset = begin; offset != end && offset != PROGRAM_END; ++offset) { 144 for (u32 offset = begin; offset != end && offset != PROGRAM_END; ++offset) {
145 const Instruction instr = {program_code[offset]}; 145 const Instruction instr = {program_code[offset]};
146 if (const auto opcode = OpCode::Decode(instr)) { 146 if (const auto opcode = OpCode::Decode(instr)) {
147 switch (opcode->GetId()) { 147 switch (opcode->get().GetId()) {
148 case OpCode::Id::EXIT: { 148 case OpCode::Id::EXIT: {
149 // The EXIT instruction can be predicated, which means that the shader can 149 // The EXIT instruction can be predicated, which means that the shader can
150 // conditionally end on this instruction. We have to consider the case where the 150 // conditionally end on this instruction. We have to consider the case where the
@@ -430,7 +430,7 @@ public:
430 */ 430 */
431 void SetRegisterToInputAttibute(const Register& reg, u64 elem, Attribute::Index attribute, 431 void SetRegisterToInputAttibute(const Register& reg, u64 elem, Attribute::Index attribute,
432 const Tegra::Shader::IpaMode& input_mode, 432 const Tegra::Shader::IpaMode& input_mode,
433 boost::optional<Register> vertex = {}) { 433 std::optional<Register> vertex = {}) {
434 const std::string dest = GetRegisterAsFloat(reg); 434 const std::string dest = GetRegisterAsFloat(reg);
435 const std::string src = GetInputAttribute(attribute, input_mode, vertex) + GetSwizzle(elem); 435 const std::string src = GetInputAttribute(attribute, input_mode, vertex) + GetSwizzle(elem);
436 shader.AddLine(dest + " = " + src + ';'); 436 shader.AddLine(dest + " = " + src + ';');
@@ -807,10 +807,10 @@ private:
807 /// Generates code representing an input attribute register. 807 /// Generates code representing an input attribute register.
808 std::string GetInputAttribute(Attribute::Index attribute, 808 std::string GetInputAttribute(Attribute::Index attribute,
809 const Tegra::Shader::IpaMode& input_mode, 809 const Tegra::Shader::IpaMode& input_mode,
810 boost::optional<Register> vertex = {}) { 810 std::optional<Register> vertex = {}) {
811 auto GeometryPass = [&](const std::string& name) { 811 auto GeometryPass = [&](const std::string& name) {
812 if (stage == Maxwell3D::Regs::ShaderStage::Geometry && vertex) { 812 if (stage == Maxwell3D::Regs::ShaderStage::Geometry && vertex) {
813 return "gs_" + name + '[' + GetRegisterAsInteger(vertex.value(), 0, false) + ']'; 813 return "gs_" + name + '[' + GetRegisterAsInteger(*vertex, 0, false) + ']';
814 } 814 }
815 return name; 815 return name;
816 }; 816 };
@@ -1465,7 +1465,7 @@ private:
1465 } 1465 }
1466 1466
1467 shader.AddLine( 1467 shader.AddLine(
1468 fmt::format("// {}: {} (0x{:016x})", offset, opcode->GetName(), instr.value)); 1468 fmt::format("// {}: {} (0x{:016x})", offset, opcode->get().GetName(), instr.value));
1469 1469
1470 using Tegra::Shader::Pred; 1470 using Tegra::Shader::Pred;
1471 ASSERT_MSG(instr.pred.full_pred != Pred::NeverExecute, 1471 ASSERT_MSG(instr.pred.full_pred != Pred::NeverExecute,
@@ -1473,7 +1473,7 @@ private:
1473 1473
1474 // Some instructions (like SSY) don't have a predicate field, they are always 1474 // Some instructions (like SSY) don't have a predicate field, they are always
1475 // unconditionally executed. 1475 // unconditionally executed.
1476 bool can_be_predicated = OpCode::IsPredicatedInstruction(opcode->GetId()); 1476 bool can_be_predicated = OpCode::IsPredicatedInstruction(opcode->get().GetId());
1477 1477
1478 if (can_be_predicated && instr.pred.pred_index != static_cast<u64>(Pred::UnusedIndex)) { 1478 if (can_be_predicated && instr.pred.pred_index != static_cast<u64>(Pred::UnusedIndex)) {
1479 shader.AddLine("if (" + 1479 shader.AddLine("if (" +
@@ -1483,7 +1483,7 @@ private:
1483 ++shader.scope; 1483 ++shader.scope;
1484 } 1484 }
1485 1485
1486 switch (opcode->GetType()) { 1486 switch (opcode->get().GetType()) {
1487 case OpCode::Type::Arithmetic: { 1487 case OpCode::Type::Arithmetic: {
1488 std::string op_a = regs.GetRegisterAsFloat(instr.gpr8); 1488 std::string op_a = regs.GetRegisterAsFloat(instr.gpr8);
1489 1489
@@ -1500,7 +1500,7 @@ private:
1500 } 1500 }
1501 } 1501 }
1502 1502
1503 switch (opcode->GetId()) { 1503 switch (opcode->get().GetId()) {
1504 case OpCode::Id::MOV_C: 1504 case OpCode::Id::MOV_C:
1505 case OpCode::Id::MOV_R: { 1505 case OpCode::Id::MOV_R: {
1506 // MOV does not have neither 'abs' nor 'neg' bits. 1506 // MOV does not have neither 'abs' nor 'neg' bits.
@@ -1600,14 +1600,15 @@ private:
1600 break; 1600 break;
1601 } 1601 }
1602 default: { 1602 default: {
1603 LOG_CRITICAL(HW_GPU, "Unhandled arithmetic instruction: {}", opcode->GetName()); 1603 LOG_CRITICAL(HW_GPU, "Unhandled arithmetic instruction: {}",
1604 opcode->get().GetName());
1604 UNREACHABLE(); 1605 UNREACHABLE();
1605 } 1606 }
1606 } 1607 }
1607 break; 1608 break;
1608 } 1609 }
1609 case OpCode::Type::ArithmeticImmediate: { 1610 case OpCode::Type::ArithmeticImmediate: {
1610 switch (opcode->GetId()) { 1611 switch (opcode->get().GetId()) {
1611 case OpCode::Id::MOV32_IMM: { 1612 case OpCode::Id::MOV32_IMM: {
1612 regs.SetRegisterToFloat(instr.gpr0, 0, GetImmediate32(instr), 1, 1); 1613 regs.SetRegisterToFloat(instr.gpr0, 0, GetImmediate32(instr), 1, 1);
1613 break; 1614 break;
@@ -1651,7 +1652,7 @@ private:
1651 std::string op_a = instr.bfe.negate_a ? "-" : ""; 1652 std::string op_a = instr.bfe.negate_a ? "-" : "";
1652 op_a += regs.GetRegisterAsInteger(instr.gpr8); 1653 op_a += regs.GetRegisterAsInteger(instr.gpr8);
1653 1654
1654 switch (opcode->GetId()) { 1655 switch (opcode->get().GetId()) {
1655 case OpCode::Id::BFE_IMM: { 1656 case OpCode::Id::BFE_IMM: {
1656 std::string inner_shift = 1657 std::string inner_shift =
1657 '(' + op_a + " << " + std::to_string(instr.bfe.GetLeftShiftValue()) + ')'; 1658 '(' + op_a + " << " + std::to_string(instr.bfe.GetLeftShiftValue()) + ')';
@@ -1663,7 +1664,7 @@ private:
1663 break; 1664 break;
1664 } 1665 }
1665 default: { 1666 default: {
1666 LOG_CRITICAL(HW_GPU, "Unhandled BFE instruction: {}", opcode->GetName()); 1667 LOG_CRITICAL(HW_GPU, "Unhandled BFE instruction: {}", opcode->get().GetName());
1667 UNREACHABLE(); 1668 UNREACHABLE();
1668 } 1669 }
1669 } 1670 }
@@ -1685,7 +1686,7 @@ private:
1685 } 1686 }
1686 } 1687 }
1687 1688
1688 switch (opcode->GetId()) { 1689 switch (opcode->get().GetId()) {
1689 case OpCode::Id::SHR_C: 1690 case OpCode::Id::SHR_C:
1690 case OpCode::Id::SHR_R: 1691 case OpCode::Id::SHR_R:
1691 case OpCode::Id::SHR_IMM: { 1692 case OpCode::Id::SHR_IMM: {
@@ -1705,7 +1706,7 @@ private:
1705 regs.SetRegisterToInteger(instr.gpr0, true, 0, op_a + " << " + op_b, 1, 1); 1706 regs.SetRegisterToInteger(instr.gpr0, true, 0, op_a + " << " + op_b, 1, 1);
1706 break; 1707 break;
1707 default: { 1708 default: {
1708 LOG_CRITICAL(HW_GPU, "Unhandled shift instruction: {}", opcode->GetName()); 1709 LOG_CRITICAL(HW_GPU, "Unhandled shift instruction: {}", opcode->get().GetName());
1709 UNREACHABLE(); 1710 UNREACHABLE();
1710 } 1711 }
1711 } 1712 }
@@ -1715,7 +1716,7 @@ private:
1715 std::string op_a = regs.GetRegisterAsInteger(instr.gpr8); 1716 std::string op_a = regs.GetRegisterAsInteger(instr.gpr8);
1716 std::string op_b = std::to_string(instr.alu.imm20_32.Value()); 1717 std::string op_b = std::to_string(instr.alu.imm20_32.Value());
1717 1718
1718 switch (opcode->GetId()) { 1719 switch (opcode->get().GetId()) {
1719 case OpCode::Id::IADD32I: 1720 case OpCode::Id::IADD32I:
1720 if (instr.iadd32i.negate_a) 1721 if (instr.iadd32i.negate_a)
1721 op_a = "-(" + op_a + ')'; 1722 op_a = "-(" + op_a + ')';
@@ -1737,7 +1738,7 @@ private:
1737 } 1738 }
1738 default: { 1739 default: {
1739 LOG_CRITICAL(HW_GPU, "Unhandled ArithmeticIntegerImmediate instruction: {}", 1740 LOG_CRITICAL(HW_GPU, "Unhandled ArithmeticIntegerImmediate instruction: {}",
1740 opcode->GetName()); 1741 opcode->get().GetName());
1741 UNREACHABLE(); 1742 UNREACHABLE();
1742 } 1743 }
1743 } 1744 }
@@ -1757,7 +1758,7 @@ private:
1757 } 1758 }
1758 } 1759 }
1759 1760
1760 switch (opcode->GetId()) { 1761 switch (opcode->get().GetId()) {
1761 case OpCode::Id::IADD_C: 1762 case OpCode::Id::IADD_C:
1762 case OpCode::Id::IADD_R: 1763 case OpCode::Id::IADD_R:
1763 case OpCode::Id::IADD_IMM: { 1764 case OpCode::Id::IADD_IMM: {
@@ -1793,7 +1794,7 @@ private:
1793 } 1794 }
1794 }; 1795 };
1795 1796
1796 if (opcode->GetId() == OpCode::Id::IADD3_R) { 1797 if (opcode->get().GetId() == OpCode::Id::IADD3_R) {
1797 apply_height(instr.iadd3.height_a, op_a); 1798 apply_height(instr.iadd3.height_a, op_a);
1798 apply_height(instr.iadd3.height_b, op_b); 1799 apply_height(instr.iadd3.height_b, op_b);
1799 apply_height(instr.iadd3.height_c, op_c); 1800 apply_height(instr.iadd3.height_c, op_c);
@@ -1809,7 +1810,7 @@ private:
1809 op_c = "-(" + op_c + ')'; 1810 op_c = "-(" + op_c + ')';
1810 1811
1811 std::string result; 1812 std::string result;
1812 if (opcode->GetId() == OpCode::Id::IADD3_R) { 1813 if (opcode->get().GetId() == OpCode::Id::IADD3_R) {
1813 switch (instr.iadd3.mode) { 1814 switch (instr.iadd3.mode) {
1814 case Tegra::Shader::IAdd3Mode::RightShift: 1815 case Tegra::Shader::IAdd3Mode::RightShift:
1815 // TODO(tech4me): According to 1816 // TODO(tech4me): According to
@@ -1884,7 +1885,7 @@ private:
1884 const std::string op_c = regs.GetRegisterAsInteger(instr.gpr39); 1885 const std::string op_c = regs.GetRegisterAsInteger(instr.gpr39);
1885 std::string lut; 1886 std::string lut;
1886 1887
1887 if (opcode->GetId() == OpCode::Id::LOP3_R) { 1888 if (opcode->get().GetId() == OpCode::Id::LOP3_R) {
1888 lut = '(' + std::to_string(instr.alu.lop3.GetImmLut28()) + ')'; 1889 lut = '(' + std::to_string(instr.alu.lop3.GetImmLut28()) + ')';
1889 } else { 1890 } else {
1890 lut = '(' + std::to_string(instr.alu.lop3.GetImmLut48()) + ')'; 1891 lut = '(' + std::to_string(instr.alu.lop3.GetImmLut48()) + ')';
@@ -1914,7 +1915,7 @@ private:
1914 case OpCode::Id::LEA_HI: { 1915 case OpCode::Id::LEA_HI: {
1915 std::string op_c; 1916 std::string op_c;
1916 1917
1917 switch (opcode->GetId()) { 1918 switch (opcode->get().GetId()) {
1918 case OpCode::Id::LEA_R2: { 1919 case OpCode::Id::LEA_R2: {
1919 op_a = regs.GetRegisterAsInteger(instr.gpr20); 1920 op_a = regs.GetRegisterAsInteger(instr.gpr20);
1920 op_b = regs.GetRegisterAsInteger(instr.gpr39); 1921 op_b = regs.GetRegisterAsInteger(instr.gpr39);
@@ -1959,7 +1960,8 @@ private:
1959 op_b = regs.GetRegisterAsInteger(instr.gpr8); 1960 op_b = regs.GetRegisterAsInteger(instr.gpr8);
1960 op_a = std::to_string(instr.lea.imm.entry_a); 1961 op_a = std::to_string(instr.lea.imm.entry_a);
1961 op_c = std::to_string(instr.lea.imm.entry_b); 1962 op_c = std::to_string(instr.lea.imm.entry_b);
1962 LOG_CRITICAL(HW_GPU, "Unhandled LEA subinstruction: {}", opcode->GetName()); 1963 LOG_CRITICAL(HW_GPU, "Unhandled LEA subinstruction: {}",
1964 opcode->get().GetName());
1963 UNREACHABLE(); 1965 UNREACHABLE();
1964 } 1966 }
1965 } 1967 }
@@ -1974,7 +1976,7 @@ private:
1974 } 1976 }
1975 default: { 1977 default: {
1976 LOG_CRITICAL(HW_GPU, "Unhandled ArithmeticInteger instruction: {}", 1978 LOG_CRITICAL(HW_GPU, "Unhandled ArithmeticInteger instruction: {}",
1977 opcode->GetName()); 1979 opcode->get().GetName());
1978 UNREACHABLE(); 1980 UNREACHABLE();
1979 } 1981 }
1980 } 1982 }
@@ -1982,20 +1984,21 @@ private:
1982 break; 1984 break;
1983 } 1985 }
1984 case OpCode::Type::ArithmeticHalf: { 1986 case OpCode::Type::ArithmeticHalf: {
1985 if (opcode->GetId() == OpCode::Id::HADD2_C || opcode->GetId() == OpCode::Id::HADD2_R) { 1987 if (opcode->get().GetId() == OpCode::Id::HADD2_C ||
1988 opcode->get().GetId() == OpCode::Id::HADD2_R) {
1986 ASSERT_MSG(instr.alu_half.ftz == 0, "Unimplemented"); 1989 ASSERT_MSG(instr.alu_half.ftz == 0, "Unimplemented");
1987 } 1990 }
1988 const bool negate_a = 1991 const bool negate_a =
1989 opcode->GetId() != OpCode::Id::HMUL2_R && instr.alu_half.negate_a != 0; 1992 opcode->get().GetId() != OpCode::Id::HMUL2_R && instr.alu_half.negate_a != 0;
1990 const bool negate_b = 1993 const bool negate_b =
1991 opcode->GetId() != OpCode::Id::HMUL2_C && instr.alu_half.negate_b != 0; 1994 opcode->get().GetId() != OpCode::Id::HMUL2_C && instr.alu_half.negate_b != 0;
1992 1995
1993 const std::string op_a = 1996 const std::string op_a =
1994 GetHalfFloat(regs.GetRegisterAsInteger(instr.gpr8, 0, false), instr.alu_half.type_a, 1997 GetHalfFloat(regs.GetRegisterAsInteger(instr.gpr8, 0, false), instr.alu_half.type_a,
1995 instr.alu_half.abs_a != 0, negate_a); 1998 instr.alu_half.abs_a != 0, negate_a);
1996 1999
1997 std::string op_b; 2000 std::string op_b;
1998 switch (opcode->GetId()) { 2001 switch (opcode->get().GetId()) {
1999 case OpCode::Id::HADD2_C: 2002 case OpCode::Id::HADD2_C:
2000 case OpCode::Id::HMUL2_C: 2003 case OpCode::Id::HMUL2_C:
2001 op_b = regs.GetUniform(instr.cbuf34.index, instr.cbuf34.offset, 2004 op_b = regs.GetUniform(instr.cbuf34.index, instr.cbuf34.offset,
@@ -2013,7 +2016,7 @@ private:
2013 op_b = GetHalfFloat(op_b, instr.alu_half.type_b, instr.alu_half.abs_b != 0, negate_b); 2016 op_b = GetHalfFloat(op_b, instr.alu_half.type_b, instr.alu_half.abs_b != 0, negate_b);
2014 2017
2015 const std::string result = [&]() { 2018 const std::string result = [&]() {
2016 switch (opcode->GetId()) { 2019 switch (opcode->get().GetId()) {
2017 case OpCode::Id::HADD2_C: 2020 case OpCode::Id::HADD2_C:
2018 case OpCode::Id::HADD2_R: 2021 case OpCode::Id::HADD2_R:
2019 return '(' + op_a + " + " + op_b + ')'; 2022 return '(' + op_a + " + " + op_b + ')';
@@ -2021,7 +2024,8 @@ private:
2021 case OpCode::Id::HMUL2_R: 2024 case OpCode::Id::HMUL2_R:
2022 return '(' + op_a + " * " + op_b + ')'; 2025 return '(' + op_a + " * " + op_b + ')';
2023 default: 2026 default:
2024 LOG_CRITICAL(HW_GPU, "Unhandled half float instruction: {}", opcode->GetName()); 2027 LOG_CRITICAL(HW_GPU, "Unhandled half float instruction: {}",
2028 opcode->get().GetName());
2025 UNREACHABLE(); 2029 UNREACHABLE();
2026 return std::string("0"); 2030 return std::string("0");
2027 } 2031 }
@@ -2032,7 +2036,7 @@ private:
2032 break; 2036 break;
2033 } 2037 }
2034 case OpCode::Type::ArithmeticHalfImmediate: { 2038 case OpCode::Type::ArithmeticHalfImmediate: {
2035 if (opcode->GetId() == OpCode::Id::HADD2_IMM) { 2039 if (opcode->get().GetId() == OpCode::Id::HADD2_IMM) {
2036 ASSERT_MSG(instr.alu_half_imm.ftz == 0, "Unimplemented"); 2040 ASSERT_MSG(instr.alu_half_imm.ftz == 0, "Unimplemented");
2037 } else { 2041 } else {
2038 ASSERT_MSG(instr.alu_half_imm.precision == Tegra::Shader::HalfPrecision::None, 2042 ASSERT_MSG(instr.alu_half_imm.precision == Tegra::Shader::HalfPrecision::None,
@@ -2046,7 +2050,7 @@ private:
2046 const std::string op_b = UnpackHalfImmediate(instr, true); 2050 const std::string op_b = UnpackHalfImmediate(instr, true);
2047 2051
2048 const std::string result = [&]() { 2052 const std::string result = [&]() {
2049 switch (opcode->GetId()) { 2053 switch (opcode->get().GetId()) {
2050 case OpCode::Id::HADD2_IMM: 2054 case OpCode::Id::HADD2_IMM:
2051 return op_a + " + " + op_b; 2055 return op_a + " + " + op_b;
2052 case OpCode::Id::HMUL2_IMM: 2056 case OpCode::Id::HMUL2_IMM:
@@ -2072,7 +2076,7 @@ private:
2072 ASSERT_MSG(instr.ffma.tab5980_1 == 0, "FFMA tab5980_1({}) not implemented", 2076 ASSERT_MSG(instr.ffma.tab5980_1 == 0, "FFMA tab5980_1({}) not implemented",
2073 instr.ffma.tab5980_1.Value()); 2077 instr.ffma.tab5980_1.Value());
2074 2078
2075 switch (opcode->GetId()) { 2079 switch (opcode->get().GetId()) {
2076 case OpCode::Id::FFMA_CR: { 2080 case OpCode::Id::FFMA_CR: {
2077 op_b += regs.GetUniform(instr.cbuf34.index, instr.cbuf34.offset, 2081 op_b += regs.GetUniform(instr.cbuf34.index, instr.cbuf34.offset,
2078 GLSLRegister::Type::Float); 2082 GLSLRegister::Type::Float);
@@ -2096,7 +2100,7 @@ private:
2096 break; 2100 break;
2097 } 2101 }
2098 default: { 2102 default: {
2099 LOG_CRITICAL(HW_GPU, "Unhandled FFMA instruction: {}", opcode->GetName()); 2103 LOG_CRITICAL(HW_GPU, "Unhandled FFMA instruction: {}", opcode->get().GetName());
2100 UNREACHABLE(); 2104 UNREACHABLE();
2101 } 2105 }
2102 } 2106 }
@@ -2107,14 +2111,14 @@ private:
2107 break; 2111 break;
2108 } 2112 }
2109 case OpCode::Type::Hfma2: { 2113 case OpCode::Type::Hfma2: {
2110 if (opcode->GetId() == OpCode::Id::HFMA2_RR) { 2114 if (opcode->get().GetId() == OpCode::Id::HFMA2_RR) {
2111 ASSERT_MSG(instr.hfma2.rr.precision == Tegra::Shader::HalfPrecision::None, 2115 ASSERT_MSG(instr.hfma2.rr.precision == Tegra::Shader::HalfPrecision::None,
2112 "Unimplemented"); 2116 "Unimplemented");
2113 } else { 2117 } else {
2114 ASSERT_MSG(instr.hfma2.precision == Tegra::Shader::HalfPrecision::None, 2118 ASSERT_MSG(instr.hfma2.precision == Tegra::Shader::HalfPrecision::None,
2115 "Unimplemented"); 2119 "Unimplemented");
2116 } 2120 }
2117 const bool saturate = opcode->GetId() == OpCode::Id::HFMA2_RR 2121 const bool saturate = opcode->get().GetId() == OpCode::Id::HFMA2_RR
2118 ? instr.hfma2.rr.saturate != 0 2122 ? instr.hfma2.rr.saturate != 0
2119 : instr.hfma2.saturate != 0; 2123 : instr.hfma2.saturate != 0;
2120 2124
@@ -2122,7 +2126,7 @@ private:
2122 GetHalfFloat(regs.GetRegisterAsInteger(instr.gpr8, 0, false), instr.hfma2.type_a); 2126 GetHalfFloat(regs.GetRegisterAsInteger(instr.gpr8, 0, false), instr.hfma2.type_a);
2123 std::string op_b, op_c; 2127 std::string op_b, op_c;
2124 2128
2125 switch (opcode->GetId()) { 2129 switch (opcode->get().GetId()) {
2126 case OpCode::Id::HFMA2_CR: 2130 case OpCode::Id::HFMA2_CR:
2127 op_b = GetHalfFloat(regs.GetUniform(instr.cbuf34.index, instr.cbuf34.offset, 2131 op_b = GetHalfFloat(regs.GetUniform(instr.cbuf34.index, instr.cbuf34.offset,
2128 GLSLRegister::Type::UnsignedInteger), 2132 GLSLRegister::Type::UnsignedInteger),
@@ -2160,7 +2164,7 @@ private:
2160 break; 2164 break;
2161 } 2165 }
2162 case OpCode::Type::Conversion: { 2166 case OpCode::Type::Conversion: {
2163 switch (opcode->GetId()) { 2167 switch (opcode->get().GetId()) {
2164 case OpCode::Id::I2I_R: { 2168 case OpCode::Id::I2I_R: {
2165 ASSERT_MSG(!instr.conversion.selector, "Unimplemented"); 2169 ASSERT_MSG(!instr.conversion.selector, "Unimplemented");
2166 2170
@@ -2298,14 +2302,15 @@ private:
2298 break; 2302 break;
2299 } 2303 }
2300 default: { 2304 default: {
2301 LOG_CRITICAL(HW_GPU, "Unhandled conversion instruction: {}", opcode->GetName()); 2305 LOG_CRITICAL(HW_GPU, "Unhandled conversion instruction: {}",
2306 opcode->get().GetName());
2302 UNREACHABLE(); 2307 UNREACHABLE();
2303 } 2308 }
2304 } 2309 }
2305 break; 2310 break;
2306 } 2311 }
2307 case OpCode::Type::Memory: { 2312 case OpCode::Type::Memory: {
2308 switch (opcode->GetId()) { 2313 switch (opcode->get().GetId()) {
2309 case OpCode::Id::LD_A: { 2314 case OpCode::Id::LD_A: {
2310 // Note: Shouldn't this be interp mode flat? As in no interpolation made. 2315 // Note: Shouldn't this be interp mode flat? As in no interpolation made.
2311 ASSERT_MSG(instr.gpr8.Value() == Register::ZeroIndex, 2316 ASSERT_MSG(instr.gpr8.Value() == Register::ZeroIndex,
@@ -2949,7 +2954,7 @@ private:
2949 break; 2954 break;
2950 } 2955 }
2951 default: { 2956 default: {
2952 LOG_CRITICAL(HW_GPU, "Unhandled memory instruction: {}", opcode->GetName()); 2957 LOG_CRITICAL(HW_GPU, "Unhandled memory instruction: {}", opcode->get().GetName());
2953 UNREACHABLE(); 2958 UNREACHABLE();
2954 } 2959 }
2955 } 2960 }
@@ -3043,7 +3048,7 @@ private:
3043 instr.hsetp2.abs_a, instr.hsetp2.negate_a); 3048 instr.hsetp2.abs_a, instr.hsetp2.negate_a);
3044 3049
3045 const std::string op_b = [&]() { 3050 const std::string op_b = [&]() {
3046 switch (opcode->GetId()) { 3051 switch (opcode->get().GetId()) {
3047 case OpCode::Id::HSETP2_R: 3052 case OpCode::Id::HSETP2_R:
3048 return GetHalfFloat(regs.GetRegisterAsInteger(instr.gpr20, 0, false), 3053 return GetHalfFloat(regs.GetRegisterAsInteger(instr.gpr20, 0, false),
3049 instr.hsetp2.type_b, instr.hsetp2.abs_a, 3054 instr.hsetp2.type_b, instr.hsetp2.abs_a,
@@ -3105,7 +3110,7 @@ private:
3105 break; 3110 break;
3106 } 3111 }
3107 case OpCode::Type::PredicateSetPredicate: { 3112 case OpCode::Type::PredicateSetPredicate: {
3108 switch (opcode->GetId()) { 3113 switch (opcode->get().GetId()) {
3109 case OpCode::Id::PSETP: { 3114 case OpCode::Id::PSETP: {
3110 const std::string op_a = 3115 const std::string op_a =
3111 GetPredicateCondition(instr.psetp.pred12, instr.psetp.neg_pred12 != 0); 3116 GetPredicateCondition(instr.psetp.pred12, instr.psetp.neg_pred12 != 0);
@@ -3151,7 +3156,8 @@ private:
3151 break; 3156 break;
3152 } 3157 }
3153 default: { 3158 default: {
3154 LOG_CRITICAL(HW_GPU, "Unhandled predicate instruction: {}", opcode->GetName()); 3159 LOG_CRITICAL(HW_GPU, "Unhandled predicate instruction: {}",
3160 opcode->get().GetName());
3155 UNREACHABLE(); 3161 UNREACHABLE();
3156 } 3162 }
3157 } 3163 }
@@ -3239,7 +3245,7 @@ private:
3239 instr.hset2.abs_a != 0, instr.hset2.negate_a != 0); 3245 instr.hset2.abs_a != 0, instr.hset2.negate_a != 0);
3240 3246
3241 const std::string op_b = [&]() { 3247 const std::string op_b = [&]() {
3242 switch (opcode->GetId()) { 3248 switch (opcode->get().GetId()) {
3243 case OpCode::Id::HSET2_R: 3249 case OpCode::Id::HSET2_R:
3244 return GetHalfFloat(regs.GetRegisterAsInteger(instr.gpr20, 0, false), 3250 return GetHalfFloat(regs.GetRegisterAsInteger(instr.gpr20, 0, false),
3245 instr.hset2.type_b, instr.hset2.abs_b != 0, 3251 instr.hset2.type_b, instr.hset2.abs_b != 0,
@@ -3288,7 +3294,7 @@ private:
3288 const bool is_signed{instr.xmad.sign_a == 1}; 3294 const bool is_signed{instr.xmad.sign_a == 1};
3289 3295
3290 bool is_merge{}; 3296 bool is_merge{};
3291 switch (opcode->GetId()) { 3297 switch (opcode->get().GetId()) {
3292 case OpCode::Id::XMAD_CR: { 3298 case OpCode::Id::XMAD_CR: {
3293 is_merge = instr.xmad.merge_56; 3299 is_merge = instr.xmad.merge_56;
3294 op_b += regs.GetUniform(instr.cbuf34.index, instr.cbuf34.offset, 3300 op_b += regs.GetUniform(instr.cbuf34.index, instr.cbuf34.offset,
@@ -3317,7 +3323,7 @@ private:
3317 break; 3323 break;
3318 } 3324 }
3319 default: { 3325 default: {
3320 LOG_CRITICAL(HW_GPU, "Unhandled XMAD instruction: {}", opcode->GetName()); 3326 LOG_CRITICAL(HW_GPU, "Unhandled XMAD instruction: {}", opcode->get().GetName());
3321 UNREACHABLE(); 3327 UNREACHABLE();
3322 } 3328 }
3323 } 3329 }
@@ -3369,7 +3375,7 @@ private:
3369 break; 3375 break;
3370 } 3376 }
3371 default: { 3377 default: {
3372 switch (opcode->GetId()) { 3378 switch (opcode->get().GetId()) {
3373 case OpCode::Id::EXIT: { 3379 case OpCode::Id::EXIT: {
3374 if (stage == Maxwell3D::Regs::ShaderStage::Fragment) { 3380 if (stage == Maxwell3D::Regs::ShaderStage::Fragment) {
3375 EmitFragmentOutputsWrite(); 3381 EmitFragmentOutputsWrite();
@@ -3564,7 +3570,7 @@ private:
3564 break; 3570 break;
3565 } 3571 }
3566 default: { 3572 default: {
3567 LOG_CRITICAL(HW_GPU, "Unhandled instruction: {}", opcode->GetName()); 3573 LOG_CRITICAL(HW_GPU, "Unhandled instruction: {}", opcode->get().GetName());
3568 UNREACHABLE(); 3574 UNREACHABLE();
3569 } 3575 }
3570 } 3576 }
@@ -3705,9 +3711,9 @@ std::string GetCommonDeclarations() {
3705 RasterizerOpenGL::MaxConstbufferSize / sizeof(GLvec4)); 3711 RasterizerOpenGL::MaxConstbufferSize / sizeof(GLvec4));
3706} 3712}
3707 3713
3708boost::optional<ProgramResult> DecompileProgram(const ProgramCode& program_code, u32 main_offset, 3714std::optional<ProgramResult> DecompileProgram(const ProgramCode& program_code, u32 main_offset,
3709 Maxwell3D::Regs::ShaderStage stage, 3715 Maxwell3D::Regs::ShaderStage stage,
3710 const std::string& suffix) { 3716 const std::string& suffix) {
3711 try { 3717 try {
3712 const auto subroutines = 3718 const auto subroutines =
3713 ControlFlowAnalyzer(program_code, main_offset, suffix).GetSubroutines(); 3719 ControlFlowAnalyzer(program_code, main_offset, suffix).GetSubroutines();
@@ -3716,7 +3722,7 @@ boost::optional<ProgramResult> DecompileProgram(const ProgramCode& program_code,
3716 } catch (const DecompileFail& exception) { 3722 } catch (const DecompileFail& exception) {
3717 LOG_ERROR(HW_GPU, "Shader decompilation failed: {}", exception.what()); 3723 LOG_ERROR(HW_GPU, "Shader decompilation failed: {}", exception.what());
3718 } 3724 }
3719 return boost::none; 3725 return {};
3720} 3726}
3721 3727
3722} // namespace OpenGL::GLShader::Decompiler 3728} // namespace OpenGL::GLShader::Decompiler
diff --git a/src/video_core/renderer_opengl/gl_shader_decompiler.h b/src/video_core/renderer_opengl/gl_shader_decompiler.h
index b20cc4bfa..d01a4a7ee 100644
--- a/src/video_core/renderer_opengl/gl_shader_decompiler.h
+++ b/src/video_core/renderer_opengl/gl_shader_decompiler.h
@@ -6,8 +6,8 @@
6 6
7#include <array> 7#include <array>
8#include <functional> 8#include <functional>
9#include <optional>
9#include <string> 10#include <string>
10#include <boost/optional.hpp>
11#include "common/common_types.h" 11#include "common/common_types.h"
12#include "video_core/engines/maxwell_3d.h" 12#include "video_core/engines/maxwell_3d.h"
13#include "video_core/renderer_opengl/gl_shader_gen.h" 13#include "video_core/renderer_opengl/gl_shader_gen.h"
@@ -18,8 +18,8 @@ using Tegra::Engines::Maxwell3D;
18 18
19std::string GetCommonDeclarations(); 19std::string GetCommonDeclarations();
20 20
21boost::optional<ProgramResult> DecompileProgram(const ProgramCode& program_code, u32 main_offset, 21std::optional<ProgramResult> DecompileProgram(const ProgramCode& program_code, u32 main_offset,
22 Maxwell3D::Regs::ShaderStage stage, 22 Maxwell3D::Regs::ShaderStage stage,
23 const std::string& suffix); 23 const std::string& suffix);
24 24
25} // namespace OpenGL::GLShader::Decompiler 25} // namespace OpenGL::GLShader::Decompiler
diff --git a/src/video_core/renderer_opengl/gl_shader_gen.cpp b/src/video_core/renderer_opengl/gl_shader_gen.cpp
index dfb562706..9d17edd63 100644
--- a/src/video_core/renderer_opengl/gl_shader_gen.cpp
+++ b/src/video_core/renderer_opengl/gl_shader_gen.cpp
@@ -37,7 +37,7 @@ layout(std140) uniform vs_config {
37 ProgramResult program = 37 ProgramResult program =
38 Decompiler::DecompileProgram(setup.program.code, PROGRAM_OFFSET, 38 Decompiler::DecompileProgram(setup.program.code, PROGRAM_OFFSET,
39 Maxwell3D::Regs::ShaderStage::Vertex, "vertex") 39 Maxwell3D::Regs::ShaderStage::Vertex, "vertex")
40 .get_value_or({}); 40 .value_or(ProgramResult());
41 41
42 out += program.first; 42 out += program.first;
43 43
@@ -45,7 +45,7 @@ layout(std140) uniform vs_config {
45 ProgramResult program_b = 45 ProgramResult program_b =
46 Decompiler::DecompileProgram(setup.program.code_b, PROGRAM_OFFSET, 46 Decompiler::DecompileProgram(setup.program.code_b, PROGRAM_OFFSET,
47 Maxwell3D::Regs::ShaderStage::Vertex, "vertex_b") 47 Maxwell3D::Regs::ShaderStage::Vertex, "vertex_b")
48 .get_value_or({}); 48 .value_or(ProgramResult());
49 out += program_b.first; 49 out += program_b.first;
50 } 50 }
51 51
@@ -90,7 +90,7 @@ ProgramResult GenerateGeometryShader(const ShaderSetup& setup) {
90 ProgramResult program = 90 ProgramResult program =
91 Decompiler::DecompileProgram(setup.program.code, PROGRAM_OFFSET, 91 Decompiler::DecompileProgram(setup.program.code, PROGRAM_OFFSET,
92 Maxwell3D::Regs::ShaderStage::Geometry, "geometry") 92 Maxwell3D::Regs::ShaderStage::Geometry, "geometry")
93 .get_value_or({}); 93 .value_or(ProgramResult());
94 out += R"( 94 out += R"(
95out gl_PerVertex { 95out gl_PerVertex {
96 vec4 gl_Position; 96 vec4 gl_Position;
@@ -124,7 +124,7 @@ ProgramResult GenerateFragmentShader(const ShaderSetup& setup) {
124 ProgramResult program = 124 ProgramResult program =
125 Decompiler::DecompileProgram(setup.program.code, PROGRAM_OFFSET, 125 Decompiler::DecompileProgram(setup.program.code, PROGRAM_OFFSET,
126 Maxwell3D::Regs::ShaderStage::Fragment, "fragment") 126 Maxwell3D::Regs::ShaderStage::Fragment, "fragment")
127 .get_value_or({}); 127 .value_or(ProgramResult());
128 out += R"( 128 out += R"(
129layout(location = 0) out vec4 FragColor0; 129layout(location = 0) out vec4 FragColor0;
130layout(location = 1) out vec4 FragColor1; 130layout(location = 1) out vec4 FragColor1;
diff --git a/src/video_core/renderer_opengl/maxwell_to_gl.h b/src/video_core/renderer_opengl/maxwell_to_gl.h
index 0f6dcab2b..87d511c38 100644
--- a/src/video_core/renderer_opengl/maxwell_to_gl.h
+++ b/src/video_core/renderer_opengl/maxwell_to_gl.h
@@ -135,12 +135,29 @@ inline GLenum PrimitiveTopology(Maxwell::PrimitiveTopology topology) {
135 return {}; 135 return {};
136} 136}
137 137
138inline GLenum TextureFilterMode(Tegra::Texture::TextureFilter filter_mode) { 138inline GLenum TextureFilterMode(Tegra::Texture::TextureFilter filter_mode,
139 Tegra::Texture::TextureMipmapFilter mip_filter_mode) {
139 switch (filter_mode) { 140 switch (filter_mode) {
140 case Tegra::Texture::TextureFilter::Linear: 141 case Tegra::Texture::TextureFilter::Linear: {
141 return GL_LINEAR; 142 switch (mip_filter_mode) {
142 case Tegra::Texture::TextureFilter::Nearest: 143 case Tegra::Texture::TextureMipmapFilter::None:
143 return GL_NEAREST; 144 return GL_LINEAR;
145 case Tegra::Texture::TextureMipmapFilter::Nearest:
146 return GL_NEAREST_MIPMAP_LINEAR;
147 case Tegra::Texture::TextureMipmapFilter::Linear:
148 return GL_LINEAR_MIPMAP_LINEAR;
149 }
150 }
151 case Tegra::Texture::TextureFilter::Nearest: {
152 switch (mip_filter_mode) {
153 case Tegra::Texture::TextureMipmapFilter::None:
154 return GL_NEAREST;
155 case Tegra::Texture::TextureMipmapFilter::Nearest:
156 return GL_NEAREST_MIPMAP_NEAREST;
157 case Tegra::Texture::TextureMipmapFilter::Linear:
158 return GL_LINEAR_MIPMAP_NEAREST;
159 }
160 }
144 } 161 }
145 LOG_CRITICAL(Render_OpenGL, "Unimplemented texture filter mode={}", 162 LOG_CRITICAL(Render_OpenGL, "Unimplemented texture filter mode={}",
146 static_cast<u32>(filter_mode)); 163 static_cast<u32>(filter_mode));
diff --git a/src/video_core/renderer_opengl/renderer_opengl.cpp b/src/video_core/renderer_opengl/renderer_opengl.cpp
index 90b68943d..ea38da932 100644
--- a/src/video_core/renderer_opengl/renderer_opengl.cpp
+++ b/src/video_core/renderer_opengl/renderer_opengl.cpp
@@ -115,7 +115,8 @@ RendererOpenGL::RendererOpenGL(Core::Frontend::EmuWindow& window)
115RendererOpenGL::~RendererOpenGL() = default; 115RendererOpenGL::~RendererOpenGL() = default;
116 116
117/// Swap buffers (render frame) 117/// Swap buffers (render frame)
118void RendererOpenGL::SwapBuffers(boost::optional<const Tegra::FramebufferConfig&> framebuffer) { 118void RendererOpenGL::SwapBuffers(
119 std::optional<std::reference_wrapper<const Tegra::FramebufferConfig>> framebuffer) {
119 ScopeAcquireGLContext acquire_context{render_window}; 120 ScopeAcquireGLContext acquire_context{render_window};
120 121
121 Core::System::GetInstance().GetPerfStats().EndSystemFrame(); 122 Core::System::GetInstance().GetPerfStats().EndSystemFrame();
@@ -124,11 +125,11 @@ void RendererOpenGL::SwapBuffers(boost::optional<const Tegra::FramebufferConfig&
124 OpenGLState prev_state = OpenGLState::GetCurState(); 125 OpenGLState prev_state = OpenGLState::GetCurState();
125 state.Apply(); 126 state.Apply();
126 127
127 if (framebuffer != boost::none) { 128 if (framebuffer) {
128 // If framebuffer is provided, reload it from memory to a texture 129 // If framebuffer is provided, reload it from memory to a texture
129 if (screen_info.texture.width != (GLsizei)framebuffer->width || 130 if (screen_info.texture.width != (GLsizei)framebuffer->get().width ||
130 screen_info.texture.height != (GLsizei)framebuffer->height || 131 screen_info.texture.height != (GLsizei)framebuffer->get().height ||
131 screen_info.texture.pixel_format != framebuffer->pixel_format) { 132 screen_info.texture.pixel_format != framebuffer->get().pixel_format) {
132 // Reallocate texture if the framebuffer size has changed. 133 // Reallocate texture if the framebuffer size has changed.
133 // This is expected to not happen very often and hence should not be a 134 // This is expected to not happen very often and hence should not be a
134 // performance problem. 135 // performance problem.
diff --git a/src/video_core/renderer_opengl/renderer_opengl.h b/src/video_core/renderer_opengl/renderer_opengl.h
index 961467a62..c0868c0e4 100644
--- a/src/video_core/renderer_opengl/renderer_opengl.h
+++ b/src/video_core/renderer_opengl/renderer_opengl.h
@@ -51,7 +51,8 @@ public:
51 ~RendererOpenGL() override; 51 ~RendererOpenGL() override;
52 52
53 /// Swap buffers (render frame) 53 /// Swap buffers (render frame)
54 void SwapBuffers(boost::optional<const Tegra::FramebufferConfig&> framebuffer) override; 54 void SwapBuffers(
55 std::optional<std::reference_wrapper<const Tegra::FramebufferConfig>> framebuffer) override;
55 56
56 /// Initialize the renderer 57 /// Initialize the renderer
57 bool Init() override; 58 bool Init() override;
diff --git a/src/video_core/renderer_opengl/utils.cpp b/src/video_core/renderer_opengl/utils.cpp
new file mode 100644
index 000000000..d84634cb3
--- /dev/null
+++ b/src/video_core/renderer_opengl/utils.cpp
@@ -0,0 +1,38 @@
1// Copyright 2014 Citra Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#include <string>
6#include <fmt/format.h>
7#include <glad/glad.h>
8#include "common/common_types.h"
9#include "video_core/renderer_opengl/utils.h"
10
11namespace OpenGL {
12
13void LabelGLObject(GLenum identifier, GLuint handle, VAddr addr, std::string extra_info) {
14 if (!GLAD_GL_KHR_debug) {
15 return; // We don't need to throw an error as this is just for debugging
16 }
17 const std::string nice_addr = fmt::format("0x{:016x}", addr);
18 std::string object_label;
19
20 if (extra_info.empty()) {
21 switch (identifier) {
22 case GL_TEXTURE:
23 object_label = "Texture@" + nice_addr;
24 break;
25 case GL_PROGRAM:
26 object_label = "Shader@" + nice_addr;
27 break;
28 default:
29 object_label = fmt::format("Object(0x{:x})@{}", identifier, nice_addr);
30 break;
31 }
32 } else {
33 object_label = extra_info + '@' + nice_addr;
34 }
35 glObjectLabel(identifier, handle, -1, static_cast<const GLchar*>(object_label.c_str()));
36}
37
38} // namespace OpenGL \ No newline at end of file
diff --git a/src/video_core/renderer_opengl/utils.h b/src/video_core/renderer_opengl/utils.h
new file mode 100644
index 000000000..1fcb6fc11
--- /dev/null
+++ b/src/video_core/renderer_opengl/utils.h
@@ -0,0 +1,15 @@
1// Copyright 2014 Citra Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include <string>
8#include <glad/glad.h>
9#include "common/common_types.h"
10
11namespace OpenGL {
12
13void LabelGLObject(GLenum identifier, GLuint handle, VAddr addr, std::string extra_info = "");
14
15} // namespace OpenGL \ No newline at end of file
diff --git a/src/video_core/textures/decoders.h b/src/video_core/textures/decoders.h
index 4726f54a5..b390219e4 100644
--- a/src/video_core/textures/decoders.h
+++ b/src/video_core/textures/decoders.h
@@ -10,6 +10,12 @@
10 10
11namespace Tegra::Texture { 11namespace Tegra::Texture {
12 12
13// GOBSize constant. Calculated by 64 bytes in x multiplied by 8 y coords, represents
14// an small rect of (64/bytes_per_pixel)X8.
15inline std::size_t GetGOBSize() {
16 return 512;
17}
18
13/** 19/**
14 * Unswizzles a swizzled texture without changing its format. 20 * Unswizzles a swizzled texture without changing its format.
15 */ 21 */
diff --git a/src/video_core/utils.h b/src/video_core/utils.h
index 237cc1307..e0a14d48f 100644
--- a/src/video_core/utils.h
+++ b/src/video_core/utils.h
@@ -161,30 +161,4 @@ static inline void MortonCopyPixels128(u32 width, u32 height, u32 bytes_per_pixe
161 } 161 }
162} 162}
163 163
164static void LabelGLObject(GLenum identifier, GLuint handle, VAddr addr,
165 std::string extra_info = "") {
166 if (!GLAD_GL_KHR_debug) {
167 return; // We don't need to throw an error as this is just for debugging
168 }
169 const std::string nice_addr = fmt::format("0x{:016x}", addr);
170 std::string object_label;
171
172 if (extra_info.empty()) {
173 switch (identifier) {
174 case GL_TEXTURE:
175 object_label = "Texture@" + nice_addr;
176 break;
177 case GL_PROGRAM:
178 object_label = "Shader@" + nice_addr;
179 break;
180 default:
181 object_label = fmt::format("Object(0x{:x})@{}", identifier, nice_addr);
182 break;
183 }
184 } else {
185 object_label = extra_info + '@' + nice_addr;
186 }
187 glObjectLabel(identifier, handle, -1, static_cast<const GLchar*>(object_label.c_str()));
188}
189
190} // namespace VideoCore 164} // namespace VideoCore
diff --git a/src/yuzu/configuration/configure_input.cpp b/src/yuzu/configuration/configure_input.cpp
index 94789c064..42a7beac6 100644
--- a/src/yuzu/configuration/configure_input.cpp
+++ b/src/yuzu/configuration/configure_input.cpp
@@ -322,7 +322,7 @@ void ConfigureInput::setPollingResult(const Common::ParamPackage& params, bool a
322 } 322 }
323 323
324 updateButtonLabels(); 324 updateButtonLabels();
325 input_setter = boost::none; 325 input_setter = {};
326} 326}
327 327
328void ConfigureInput::keyPressEvent(QKeyEvent* event) { 328void ConfigureInput::keyPressEvent(QKeyEvent* event) {
diff --git a/src/yuzu/configuration/configure_input.h b/src/yuzu/configuration/configure_input.h
index d1198db81..32c7183f9 100644
--- a/src/yuzu/configuration/configure_input.h
+++ b/src/yuzu/configuration/configure_input.h
@@ -7,11 +7,13 @@
7#include <array> 7#include <array>
8#include <functional> 8#include <functional>
9#include <memory> 9#include <memory>
10#include <optional>
10#include <string> 11#include <string>
11#include <unordered_map> 12#include <unordered_map>
13
12#include <QKeyEvent> 14#include <QKeyEvent>
13#include <QWidget> 15#include <QWidget>
14#include <boost/optional.hpp> 16
15#include "common/param_package.h" 17#include "common/param_package.h"
16#include "core/settings.h" 18#include "core/settings.h"
17#include "input_common/main.h" 19#include "input_common/main.h"
@@ -41,7 +43,7 @@ private:
41 std::unique_ptr<QTimer> poll_timer; 43 std::unique_ptr<QTimer> poll_timer;
42 44
43 /// This will be the the setting function when an input is awaiting configuration. 45 /// This will be the the setting function when an input is awaiting configuration.
44 boost::optional<std::function<void(const Common::ParamPackage&)>> input_setter; 46 std::optional<std::function<void(const Common::ParamPackage&)>> input_setter;
45 47
46 std::array<Common::ParamPackage, Settings::NativeButton::NumButtons> buttons_param; 48 std::array<Common::ParamPackage, Settings::NativeButton::NumButtons> buttons_param;
47 std::array<Common::ParamPackage, Settings::NativeAnalog::NumAnalogs> analogs_param; 49 std::array<Common::ParamPackage, Settings::NativeAnalog::NumAnalogs> analogs_param;
diff --git a/src/yuzu/configuration/configure_system.cpp b/src/yuzu/configuration/configure_system.cpp
index acb458001..1b8aa7de2 100644
--- a/src/yuzu/configuration/configure_system.cpp
+++ b/src/yuzu/configuration/configure_system.cpp
@@ -173,7 +173,7 @@ void ConfigureSystem::UpdateCurrentUser() {
173 ui->pm_add->setEnabled(profile_manager->GetUserCount() < Service::Account::MAX_USERS); 173 ui->pm_add->setEnabled(profile_manager->GetUserCount() < Service::Account::MAX_USERS);
174 174
175 const auto& current_user = profile_manager->GetUser(Settings::values.current_user); 175 const auto& current_user = profile_manager->GetUser(Settings::values.current_user);
176 ASSERT(current_user != std::nullopt); 176 ASSERT(current_user);
177 const auto username = GetAccountUsername(*profile_manager, *current_user); 177 const auto username = GetAccountUsername(*profile_manager, *current_user);
178 178
179 scene->clear(); 179 scene->clear();
@@ -261,7 +261,7 @@ void ConfigureSystem::AddUser() {
261void ConfigureSystem::RenameUser() { 261void ConfigureSystem::RenameUser() {
262 const auto user = tree_view->currentIndex().row(); 262 const auto user = tree_view->currentIndex().row();
263 const auto uuid = profile_manager->GetUser(user); 263 const auto uuid = profile_manager->GetUser(user);
264 ASSERT(uuid != std::nullopt); 264 ASSERT(uuid);
265 265
266 Service::Account::ProfileBase profile; 266 Service::Account::ProfileBase profile;
267 if (!profile_manager->GetProfileBase(*uuid, profile)) 267 if (!profile_manager->GetProfileBase(*uuid, profile))
@@ -297,7 +297,7 @@ void ConfigureSystem::RenameUser() {
297void ConfigureSystem::DeleteUser() { 297void ConfigureSystem::DeleteUser() {
298 const auto index = tree_view->currentIndex().row(); 298 const auto index = tree_view->currentIndex().row();
299 const auto uuid = profile_manager->GetUser(index); 299 const auto uuid = profile_manager->GetUser(index);
300 ASSERT(uuid != std::nullopt); 300 ASSERT(uuid);
301 const auto username = GetAccountUsername(*profile_manager, *uuid); 301 const auto username = GetAccountUsername(*profile_manager, *uuid);
302 302
303 const auto confirm = QMessageBox::question( 303 const auto confirm = QMessageBox::question(
@@ -324,7 +324,7 @@ void ConfigureSystem::DeleteUser() {
324void ConfigureSystem::SetUserImage() { 324void ConfigureSystem::SetUserImage() {
325 const auto index = tree_view->currentIndex().row(); 325 const auto index = tree_view->currentIndex().row();
326 const auto uuid = profile_manager->GetUser(index); 326 const auto uuid = profile_manager->GetUser(index);
327 ASSERT(uuid != std::nullopt); 327 ASSERT(uuid);
328 328
329 const auto file = QFileDialog::getOpenFileName(this, tr("Select User Image"), QString(), 329 const auto file = QFileDialog::getOpenFileName(this, tr("Select User Image"), QString(),
330 tr("JPEG Images (*.jpg *.jpeg)")); 330 tr("JPEG Images (*.jpg *.jpeg)"));
diff --git a/src/yuzu/debugger/graphics/graphics_surface.cpp b/src/yuzu/debugger/graphics/graphics_surface.cpp
index 44d423da2..0adbab27d 100644
--- a/src/yuzu/debugger/graphics/graphics_surface.cpp
+++ b/src/yuzu/debugger/graphics/graphics_surface.cpp
@@ -382,7 +382,7 @@ void GraphicsSurfaceWidget::OnUpdate() {
382 // TODO: Implement a good way to visualize alpha components! 382 // TODO: Implement a good way to visualize alpha components!
383 383
384 QImage decoded_image(surface_width, surface_height, QImage::Format_ARGB32); 384 QImage decoded_image(surface_width, surface_height, QImage::Format_ARGB32);
385 boost::optional<VAddr> address = gpu.MemoryManager().GpuToCpuAddress(surface_address); 385 std::optional<VAddr> address = gpu.MemoryManager().GpuToCpuAddress(surface_address);
386 386
387 // TODO(bunnei): Will not work with BCn formats that swizzle 4x4 tiles. 387 // TODO(bunnei): Will not work with BCn formats that swizzle 4x4 tiles.
388 // Needs to be fixed if we plan to use this feature more, otherwise we may remove it. 388 // Needs to be fixed if we plan to use this feature more, otherwise we may remove it.
@@ -444,7 +444,7 @@ void GraphicsSurfaceWidget::SaveSurface() {
444 pixmap->save(&file, "PNG"); 444 pixmap->save(&file, "PNG");
445 } else if (selectedFilter == bin_filter) { 445 } else if (selectedFilter == bin_filter) {
446 auto& gpu = Core::System::GetInstance().GPU(); 446 auto& gpu = Core::System::GetInstance().GPU();
447 boost::optional<VAddr> address = gpu.MemoryManager().GpuToCpuAddress(surface_address); 447 std::optional<VAddr> address = gpu.MemoryManager().GpuToCpuAddress(surface_address);
448 448
449 const u8* buffer = Memory::GetPointer(*address); 449 const u8* buffer = Memory::GetPointer(*address);
450 ASSERT_MSG(buffer != nullptr, "Memory not accessible"); 450 ASSERT_MSG(buffer != nullptr, "Memory not accessible");
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp
index b5bfa6741..c5a56cbfd 100644
--- a/src/yuzu/main.cpp
+++ b/src/yuzu/main.cpp
@@ -786,7 +786,7 @@ void GMainWindow::OnGameListOpenFolder(u64 program_id, GameListOpenTarget target
786 ASSERT(index != -1 && index < 8); 786 ASSERT(index != -1 && index < 8);
787 787
788 const auto user_id = manager.GetUser(index); 788 const auto user_id = manager.GetUser(index);
789 ASSERT(user_id != std::nullopt); 789 ASSERT(user_id);
790 path = nand_dir + FileSys::SaveDataFactory::GetFullPath(FileSys::SaveDataSpaceId::NandUser, 790 path = nand_dir + FileSys::SaveDataFactory::GetFullPath(FileSys::SaveDataSpaceId::NandUser,
791 FileSys::SaveDataType::SaveData, 791 FileSys::SaveDataType::SaveData,
792 program_id, user_id->uuid, 0); 792 program_id, user_id->uuid, 0);
@@ -1560,7 +1560,7 @@ void GMainWindow::OnReinitializeKeys(ReinitializeKeyBehavior behavior) {
1560 } 1560 }
1561} 1561}
1562 1562
1563boost::optional<u64> GMainWindow::SelectRomFSDumpTarget( 1563std::optional<u64> GMainWindow::SelectRomFSDumpTarget(
1564 const FileSys::RegisteredCacheUnion& installed, u64 program_id) { 1564 const FileSys::RegisteredCacheUnion& installed, u64 program_id) {
1565 const auto dlc_entries = 1565 const auto dlc_entries =
1566 installed.ListEntriesFilter(FileSys::TitleType::AOC, FileSys::ContentRecordType::Data); 1566 installed.ListEntriesFilter(FileSys::TitleType::AOC, FileSys::ContentRecordType::Data);
@@ -1587,7 +1587,7 @@ boost::optional<u64> GMainWindow::SelectRomFSDumpTarget(
1587 this, tr("Select RomFS Dump Target"), 1587 this, tr("Select RomFS Dump Target"),
1588 tr("Please select which RomFS you would like to dump."), list, 0, false, &ok); 1588 tr("Please select which RomFS you would like to dump."), list, 0, false, &ok);
1589 if (!ok) { 1589 if (!ok) {
1590 return boost::none; 1590 return {};
1591 } 1591 }
1592 1592
1593 return romfs_tids[list.indexOf(res)]; 1593 return romfs_tids[list.indexOf(res)];
diff --git a/src/yuzu/main.h b/src/yuzu/main.h
index 7c7c223e1..af637d89e 100644
--- a/src/yuzu/main.h
+++ b/src/yuzu/main.h
@@ -5,12 +5,12 @@
5#pragma once 5#pragma once
6 6
7#include <memory> 7#include <memory>
8#include <optional>
8#include <unordered_map> 9#include <unordered_map>
9 10
10#include <QMainWindow> 11#include <QMainWindow>
11#include <QTimer> 12#include <QTimer>
12 13
13#include <boost/optional.hpp>
14#include "common/common_types.h" 14#include "common/common_types.h"
15#include "core/core.h" 15#include "core/core.h"
16#include "ui_main.h" 16#include "ui_main.h"
@@ -178,8 +178,7 @@ private slots:
178 void OnReinitializeKeys(ReinitializeKeyBehavior behavior); 178 void OnReinitializeKeys(ReinitializeKeyBehavior behavior);
179 179
180private: 180private:
181 boost::optional<u64> SelectRomFSDumpTarget(const FileSys::RegisteredCacheUnion&, 181 std::optional<u64> SelectRomFSDumpTarget(const FileSys::RegisteredCacheUnion&, u64 program_id);
182 u64 program_id);
183 void UpdateStatusBar(); 182 void UpdateStatusBar();
184 183
185 Ui::MainWindow ui; 184 Ui::MainWindow ui;