summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Lioncash2020-09-22 17:31:53 -0400
committerGravatar Lioncash2020-09-22 17:32:33 -0400
commitff45c3957858cdf189b73e11550da06fe4337b8e (patch)
tree288ff1cc4677d6511ed8cc7e1b0db20ce2d2590f /src
parentMerge pull request #4697 from lioncash/copy5 (diff)
downloadyuzu-ff45c3957858cdf189b73e11550da06fe4337b8e.tar.gz
yuzu-ff45c3957858cdf189b73e11550da06fe4337b8e.tar.xz
yuzu-ff45c3957858cdf189b73e11550da06fe4337b8e.zip
General: Make use of std::nullopt where applicable
Allows some implementations to avoid completely zeroing out the internal buffer of the optional, and instead only set the validity byte within the structure. This also makes it consistent how we return empty optionals.
Diffstat (limited to 'src')
-rw-r--r--src/core/arm/dynarmic/arm_dynarmic_cp15.cpp6
-rw-r--r--src/core/file_sys/content_archive.cpp10
-rw-r--r--src/core/file_sys/vfs.cpp7
-rw-r--r--src/core/file_sys/vfs_offset.cpp7
-rw-r--r--src/core/file_sys/vfs_static.h8
-rw-r--r--src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp4
-rw-r--r--src/core/hle/service/nvdrv/nvdrv.h2
-rw-r--r--src/core/hle/service/nvflinger/nvflinger.cpp6
-rw-r--r--src/core/hle/service/sockets/bsd.cpp2
-rw-r--r--src/core/loader/nso.cpp6
-rw-r--r--src/video_core/engines/maxwell_3d.cpp2
-rw-r--r--src/video_core/macro/macro.cpp2
-rw-r--r--src/video_core/memory_manager.cpp6
-rw-r--r--src/video_core/renderer_opengl/gl_shader_decompiler.cpp12
-rw-r--r--src/video_core/shader/ast.h25
-rw-r--r--src/video_core/shader/track.cpp4
-rw-r--r--src/video_core/texture_cache/surface_base.cpp10
17 files changed, 60 insertions, 59 deletions
diff --git a/src/core/arm/dynarmic/arm_dynarmic_cp15.cpp b/src/core/arm/dynarmic/arm_dynarmic_cp15.cpp
index 54556e0f9..caefc09f4 100644
--- a/src/core/arm/dynarmic/arm_dynarmic_cp15.cpp
+++ b/src/core/arm/dynarmic/arm_dynarmic_cp15.cpp
@@ -34,7 +34,7 @@ std::optional<Callback> DynarmicCP15::CompileInternalOperation(bool two, unsigne
34 CoprocReg CRm, unsigned opc2) { 34 CoprocReg CRm, unsigned opc2) {
35 LOG_CRITICAL(Core_ARM, "CP15: cdp{} p15, {}, {}, {}, {}, {}", two ? "2" : "", opc1, CRd, CRn, 35 LOG_CRITICAL(Core_ARM, "CP15: cdp{} p15, {}, {}, {}, {}, {}", two ? "2" : "", opc1, CRd, CRn,
36 CRm, opc2); 36 CRm, opc2);
37 return {}; 37 return std::nullopt;
38} 38}
39 39
40CallbackOrAccessOneWord DynarmicCP15::CompileSendOneWord(bool two, unsigned opc1, CoprocReg CRn, 40CallbackOrAccessOneWord DynarmicCP15::CompileSendOneWord(bool two, unsigned opc1, CoprocReg CRn,
@@ -115,7 +115,7 @@ std::optional<Callback> DynarmicCP15::CompileLoadWords(bool two, bool long_trans
115 LOG_CRITICAL(Core_ARM, "CP15: mrrc{}{} p15, {}, [...]", two ? "2" : "", 115 LOG_CRITICAL(Core_ARM, "CP15: mrrc{}{} p15, {}, [...]", two ? "2" : "",
116 long_transfer ? "l" : "", CRd); 116 long_transfer ? "l" : "", CRd);
117 } 117 }
118 return {}; 118 return std::nullopt;
119} 119}
120 120
121std::optional<Callback> DynarmicCP15::CompileStoreWords(bool two, bool long_transfer, CoprocReg CRd, 121std::optional<Callback> DynarmicCP15::CompileStoreWords(bool two, bool long_transfer, CoprocReg CRd,
@@ -127,7 +127,7 @@ std::optional<Callback> DynarmicCP15::CompileStoreWords(bool two, bool long_tran
127 LOG_CRITICAL(Core_ARM, "CP15: mrrc{}{} p15, {}, [...]", two ? "2" : "", 127 LOG_CRITICAL(Core_ARM, "CP15: mrrc{}{} p15, {}, [...]", two ? "2" : "",
128 long_transfer ? "l" : "", CRd); 128 long_transfer ? "l" : "", CRd);
129 } 129 }
130 return {}; 130 return std::nullopt;
131} 131}
132 132
133} // namespace Core 133} // namespace Core
diff --git a/src/core/file_sys/content_archive.cpp b/src/core/file_sys/content_archive.cpp
index 426fb6bb5..76af47ff9 100644
--- a/src/core/file_sys/content_archive.cpp
+++ b/src/core/file_sys/content_archive.cpp
@@ -323,7 +323,7 @@ bool NCA::ReadRomFSSection(const NCASectionHeader& section, const NCASectionTabl
323 subsection_buckets.back().entries.push_back({section.bktr.relocation.offset, {0}, ctr_low}); 323 subsection_buckets.back().entries.push_back({section.bktr.relocation.offset, {0}, ctr_low});
324 subsection_buckets.back().entries.push_back({size, {0}, 0}); 324 subsection_buckets.back().entries.push_back({size, {0}, 0});
325 325
326 std::optional<Core::Crypto::Key128> key = {}; 326 std::optional<Core::Crypto::Key128> key;
327 if (encrypted) { 327 if (encrypted) {
328 if (has_rights_id) { 328 if (has_rights_id) {
329 status = Loader::ResultStatus::Success; 329 status = Loader::ResultStatus::Success;
@@ -442,18 +442,18 @@ std::optional<Core::Crypto::Key128> NCA::GetTitlekey() {
442 memcpy(rights_id.data(), header.rights_id.data(), 16); 442 memcpy(rights_id.data(), header.rights_id.data(), 16);
443 if (rights_id == u128{}) { 443 if (rights_id == u128{}) {
444 status = Loader::ResultStatus::ErrorInvalidRightsID; 444 status = Loader::ResultStatus::ErrorInvalidRightsID;
445 return {}; 445 return std::nullopt;
446 } 446 }
447 447
448 auto titlekey = keys.GetKey(Core::Crypto::S128KeyType::Titlekey, rights_id[1], rights_id[0]); 448 auto titlekey = keys.GetKey(Core::Crypto::S128KeyType::Titlekey, rights_id[1], rights_id[0]);
449 if (titlekey == Core::Crypto::Key128{}) { 449 if (titlekey == Core::Crypto::Key128{}) {
450 status = Loader::ResultStatus::ErrorMissingTitlekey; 450 status = Loader::ResultStatus::ErrorMissingTitlekey;
451 return {}; 451 return std::nullopt;
452 } 452 }
453 453
454 if (!keys.HasKey(Core::Crypto::S128KeyType::Titlekek, master_key_id)) { 454 if (!keys.HasKey(Core::Crypto::S128KeyType::Titlekek, master_key_id)) {
455 status = Loader::ResultStatus::ErrorMissingTitlekek; 455 status = Loader::ResultStatus::ErrorMissingTitlekek;
456 return {}; 456 return std::nullopt;
457 } 457 }
458 458
459 Core::Crypto::AESCipher<Core::Crypto::Key128> cipher( 459 Core::Crypto::AESCipher<Core::Crypto::Key128> cipher(
@@ -477,7 +477,7 @@ VirtualFile NCA::Decrypt(const NCASectionHeader& s_header, VirtualFile in, u64 s
477 case NCASectionCryptoType::BKTR: 477 case NCASectionCryptoType::BKTR:
478 LOG_TRACE(Crypto, "called with mode=CTR, starting_offset={:016X}", starting_offset); 478 LOG_TRACE(Crypto, "called with mode=CTR, starting_offset={:016X}", starting_offset);
479 { 479 {
480 std::optional<Core::Crypto::Key128> key = {}; 480 std::optional<Core::Crypto::Key128> key;
481 if (has_rights_id) { 481 if (has_rights_id) {
482 status = Loader::ResultStatus::Success; 482 status = Loader::ResultStatus::Success;
483 key = GetTitlekey(); 483 key = GetTitlekey();
diff --git a/src/core/file_sys/vfs.cpp b/src/core/file_sys/vfs.cpp
index a4c3f67c4..b2f026b6d 100644
--- a/src/core/file_sys/vfs.cpp
+++ b/src/core/file_sys/vfs.cpp
@@ -169,11 +169,12 @@ VfsDirectory::~VfsDirectory() = default;
169 169
170std::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 const std::size_t size = Read(&out, sizeof(u8), offset);
173 if (size == 1) 173 if (size == 1) {
174 return out; 174 return out;
175 }
175 176
176 return {}; 177 return std::nullopt;
177} 178}
178 179
179std::vector<u8> VfsFile::ReadBytes(std::size_t size, std::size_t offset) const { 180std::vector<u8> VfsFile::ReadBytes(std::size_t size, std::size_t offset) const {
diff --git a/src/core/file_sys/vfs_offset.cpp b/src/core/file_sys/vfs_offset.cpp
index c96f88488..7714d3de5 100644
--- a/src/core/file_sys/vfs_offset.cpp
+++ b/src/core/file_sys/vfs_offset.cpp
@@ -58,10 +58,11 @@ std::size_t OffsetVfsFile::Write(const u8* data, std::size_t length, std::size_t
58} 58}
59 59
60std::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 std::nullopt;
63 }
63 64
64 return {}; 65 return file->ReadByte(offset + r_offset);
65} 66}
66 67
67std::vector<u8> OffsetVfsFile::ReadBytes(std::size_t r_size, std::size_t r_offset) const { 68std::vector<u8> OffsetVfsFile::ReadBytes(std::size_t r_size, std::size_t r_offset) const {
diff --git a/src/core/file_sys/vfs_static.h b/src/core/file_sys/vfs_static.h
index 9f5a90b1b..8b27c30fa 100644
--- a/src/core/file_sys/vfs_static.h
+++ b/src/core/file_sys/vfs_static.h
@@ -54,9 +54,11 @@ public:
54 } 54 }
55 55
56 std::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 std::nullopt;
59 return {}; 59 }
60
61 return value;
60 } 62 }
61 63
62 std::vector<u8> ReadBytes(std::size_t length, std::size_t offset) const override { 64 std::vector<u8> ReadBytes(std::size_t length, std::size_t offset) const override {
diff --git a/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp b/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp
index d4ba88147..39bd2a45b 100644
--- a/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp
+++ b/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp
@@ -265,7 +265,7 @@ std::optional<nvhost_as_gpu::BufferMap> nvhost_as_gpu::FindBufferMap(GPUVAddr gp
265 } 265 }
266 } 266 }
267 267
268 return {}; 268 return std::nullopt;
269} 269}
270 270
271void nvhost_as_gpu::AddBufferMap(GPUVAddr gpu_addr, std::size_t size, VAddr cpu_addr, 271void nvhost_as_gpu::AddBufferMap(GPUVAddr gpu_addr, std::size_t size, VAddr cpu_addr,
@@ -286,7 +286,7 @@ std::optional<std::size_t> nvhost_as_gpu::RemoveBufferMap(GPUVAddr gpu_addr) {
286 return size; 286 return size;
287 } 287 }
288 288
289 return {}; 289 return std::nullopt;
290} 290}
291 291
292} // namespace Service::Nvidia::Devices 292} // namespace Service::Nvidia::Devices
diff --git a/src/core/hle/service/nvdrv/nvdrv.h b/src/core/hle/service/nvdrv/nvdrv.h
index d7a1bef91..7706a5590 100644
--- a/src/core/hle/service/nvdrv/nvdrv.h
+++ b/src/core/hle/service/nvdrv/nvdrv.h
@@ -54,7 +54,7 @@ struct EventInterface {
54 } 54 }
55 mask = mask >> 1; 55 mask = mask >> 1;
56 } 56 }
57 return {}; 57 return std::nullopt;
58 } 58 }
59 void SetEventStatus(const u32 event_id, EventState new_status) { 59 void SetEventStatus(const u32 event_id, EventState new_status) {
60 EventState old_status = status[event_id]; 60 EventState old_status = status[event_id];
diff --git a/src/core/hle/service/nvflinger/nvflinger.cpp b/src/core/hle/service/nvflinger/nvflinger.cpp
index f644a460d..c64673dba 100644
--- a/src/core/hle/service/nvflinger/nvflinger.cpp
+++ b/src/core/hle/service/nvflinger/nvflinger.cpp
@@ -114,7 +114,7 @@ std::optional<u64> NVFlinger::OpenDisplay(std::string_view name) {
114 [&](const VI::Display& display) { return display.GetName() == name; }); 114 [&](const VI::Display& display) { return display.GetName() == name; });
115 115
116 if (itr == displays.end()) { 116 if (itr == displays.end()) {
117 return {}; 117 return std::nullopt;
118 } 118 }
119 119
120 return itr->GetID(); 120 return itr->GetID();
@@ -124,7 +124,7 @@ std::optional<u64> NVFlinger::CreateLayer(u64 display_id) {
124 auto* const display = FindDisplay(display_id); 124 auto* const display = FindDisplay(display_id);
125 125
126 if (display == nullptr) { 126 if (display == nullptr) {
127 return {}; 127 return std::nullopt;
128 } 128 }
129 129
130 const u64 layer_id = next_layer_id++; 130 const u64 layer_id = next_layer_id++;
@@ -144,7 +144,7 @@ std::optional<u32> NVFlinger::FindBufferQueueId(u64 display_id, u64 layer_id) co
144 const auto* const layer = FindLayer(display_id, layer_id); 144 const auto* const layer = FindLayer(display_id, layer_id);
145 145
146 if (layer == nullptr) { 146 if (layer == nullptr) {
147 return {}; 147 return std::nullopt;
148 } 148 }
149 149
150 return layer->GetBufferQueue().GetId(); 150 return layer->GetBufferQueue().GetId();
diff --git a/src/core/hle/service/sockets/bsd.cpp b/src/core/hle/service/sockets/bsd.cpp
index 7b9dd42d8..a74be9370 100644
--- a/src/core/hle/service/sockets/bsd.cpp
+++ b/src/core/hle/service/sockets/bsd.cpp
@@ -497,7 +497,7 @@ std::pair<s32, Errno> BSD::PollImpl(std::vector<u8>& write_buffer, std::vector<u
497 return {0, Errno::SUCCESS}; 497 return {0, Errno::SUCCESS};
498 } 498 }
499 499
500 std::optional<FileDescriptor>& descriptor = file_descriptors[pollfd.fd]; 500 const std::optional<FileDescriptor>& descriptor = file_descriptors[pollfd.fd];
501 if (!descriptor) { 501 if (!descriptor) {
502 LOG_ERROR(Service, "File descriptor handle={} is not allocated", pollfd.fd); 502 LOG_ERROR(Service, "File descriptor handle={} is not allocated", pollfd.fd);
503 pollfd.revents = POLL_NVAL; 503 pollfd.revents = POLL_NVAL;
diff --git a/src/core/loader/nso.cpp b/src/core/loader/nso.cpp
index 60373cc5f..1e70f6e11 100644
--- a/src/core/loader/nso.cpp
+++ b/src/core/loader/nso.cpp
@@ -76,16 +76,16 @@ std::optional<VAddr> AppLoader_NSO::LoadModule(Kernel::Process& process, Core::S
76 bool should_pass_arguments, bool load_into_process, 76 bool should_pass_arguments, bool load_into_process,
77 std::optional<FileSys::PatchManager> pm) { 77 std::optional<FileSys::PatchManager> pm) {
78 if (file.GetSize() < sizeof(NSOHeader)) { 78 if (file.GetSize() < sizeof(NSOHeader)) {
79 return {}; 79 return std::nullopt;
80 } 80 }
81 81
82 NSOHeader nso_header{}; 82 NSOHeader nso_header{};
83 if (sizeof(NSOHeader) != file.ReadObject(&nso_header)) { 83 if (sizeof(NSOHeader) != file.ReadObject(&nso_header)) {
84 return {}; 84 return std::nullopt;
85 } 85 }
86 86
87 if (nso_header.magic != Common::MakeMagic('N', 'S', 'O', '0')) { 87 if (nso_header.magic != Common::MakeMagic('N', 'S', 'O', '0')) {
88 return {}; 88 return std::nullopt;
89 } 89 }
90 90
91 // Build program image 91 // Build program image
diff --git a/src/video_core/engines/maxwell_3d.cpp b/src/video_core/engines/maxwell_3d.cpp
index 33854445f..57ebc785f 100644
--- a/src/video_core/engines/maxwell_3d.cpp
+++ b/src/video_core/engines/maxwell_3d.cpp
@@ -597,7 +597,7 @@ std::optional<u64> Maxwell3D::GetQueryResult() {
597 // Deferred. 597 // Deferred.
598 rasterizer->Query(regs.query.QueryAddress(), VideoCore::QueryType::SamplesPassed, 598 rasterizer->Query(regs.query.QueryAddress(), VideoCore::QueryType::SamplesPassed,
599 system.GPU().GetTicks()); 599 system.GPU().GetTicks());
600 return {}; 600 return std::nullopt;
601 default: 601 default:
602 LOG_DEBUG(HW_GPU, "Unimplemented query select type {}", 602 LOG_DEBUG(HW_GPU, "Unimplemented query select type {}",
603 static_cast<u32>(regs.query.query_get.select.Value())); 603 static_cast<u32>(regs.query.query_get.select.Value()));
diff --git a/src/video_core/macro/macro.cpp b/src/video_core/macro/macro.cpp
index a50e7b4e0..cd21a2112 100644
--- a/src/video_core/macro/macro.cpp
+++ b/src/video_core/macro/macro.cpp
@@ -36,7 +36,7 @@ void MacroEngine::Execute(Engines::Maxwell3D& maxwell3d, u32 method,
36 } 36 }
37 } else { 37 } else {
38 // Macro not compiled, check if it's uploaded and if so, compile it 38 // Macro not compiled, check if it's uploaded and if so, compile it
39 std::optional<u32> mid_method = std::nullopt; 39 std::optional<u32> mid_method;
40 const auto macro_code = uploaded_macro_code.find(method); 40 const auto macro_code = uploaded_macro_code.find(method);
41 if (macro_code == uploaded_macro_code.end()) { 41 if (macro_code == uploaded_macro_code.end()) {
42 for (const auto& [method_base, code] : uploaded_macro_code) { 42 for (const auto& [method_base, code] : uploaded_macro_code) {
diff --git a/src/video_core/memory_manager.cpp b/src/video_core/memory_manager.cpp
index 16b2aaa27..02cf53d15 100644
--- a/src/video_core/memory_manager.cpp
+++ b/src/video_core/memory_manager.cpp
@@ -58,7 +58,7 @@ void MemoryManager::Unmap(GPUVAddr gpu_addr, std::size_t size) {
58std::optional<GPUVAddr> MemoryManager::AllocateFixed(GPUVAddr gpu_addr, std::size_t size) { 58std::optional<GPUVAddr> MemoryManager::AllocateFixed(GPUVAddr gpu_addr, std::size_t size) {
59 for (u64 offset{}; offset < size; offset += page_size) { 59 for (u64 offset{}; offset < size; offset += page_size) {
60 if (!GetPageEntry(gpu_addr + offset).IsUnmapped()) { 60 if (!GetPageEntry(gpu_addr + offset).IsUnmapped()) {
61 return {}; 61 return std::nullopt;
62 } 62 }
63 } 63 }
64 64
@@ -135,13 +135,13 @@ std::optional<GPUVAddr> MemoryManager::FindFreeRange(std::size_t size, std::size
135 } 135 }
136 } 136 }
137 137
138 return {}; 138 return std::nullopt;
139} 139}
140 140
141std::optional<VAddr> MemoryManager::GpuToCpuAddress(GPUVAddr gpu_addr) const { 141std::optional<VAddr> MemoryManager::GpuToCpuAddress(GPUVAddr gpu_addr) const {
142 const auto page_entry{GetPageEntry(gpu_addr)}; 142 const auto page_entry{GetPageEntry(gpu_addr)};
143 if (!page_entry.IsValid()) { 143 if (!page_entry.IsValid()) {
144 return {}; 144 return std::nullopt;
145 } 145 }
146 146
147 return page_entry.ToAddress() + (gpu_addr & page_mask); 147 return page_entry.ToAddress() + (gpu_addr & page_mask);
diff --git a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp
index ce3a65122..bbb8fb095 100644
--- a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp
+++ b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp
@@ -813,7 +813,7 @@ private:
813 const u8 location = static_cast<u8>(static_cast<u32>(index) * 4 + element); 813 const u8 location = static_cast<u8>(static_cast<u32>(index) * 4 + element);
814 const auto it = transform_feedback.find(location); 814 const auto it = transform_feedback.find(location);
815 if (it == transform_feedback.end()) { 815 if (it == transform_feedback.end()) {
816 return {}; 816 return std::nullopt;
817 } 817 }
818 return it->second.components; 818 return it->second.components;
819 } 819 }
@@ -1295,21 +1295,21 @@ private:
1295 switch (element) { 1295 switch (element) {
1296 case 0: 1296 case 0:
1297 UNIMPLEMENTED(); 1297 UNIMPLEMENTED();
1298 return {}; 1298 return std::nullopt;
1299 case 1: 1299 case 1:
1300 if (stage == ShaderType::Vertex && !device.HasVertexViewportLayer()) { 1300 if (stage == ShaderType::Vertex && !device.HasVertexViewportLayer()) {
1301 return {}; 1301 return std::nullopt;
1302 } 1302 }
1303 return {{"gl_Layer", Type::Int}}; 1303 return {{"gl_Layer", Type::Int}};
1304 case 2: 1304 case 2:
1305 if (stage == ShaderType::Vertex && !device.HasVertexViewportLayer()) { 1305 if (stage == ShaderType::Vertex && !device.HasVertexViewportLayer()) {
1306 return {}; 1306 return std::nullopt;
1307 } 1307 }
1308 return {{"gl_ViewportIndex", Type::Int}}; 1308 return {{"gl_ViewportIndex", Type::Int}};
1309 case 3: 1309 case 3:
1310 return {{"gl_PointSize", Type::Float}}; 1310 return {{"gl_PointSize", Type::Float}};
1311 } 1311 }
1312 return {}; 1312 return std::nullopt;
1313 case Attribute::Index::FrontColor: 1313 case Attribute::Index::FrontColor:
1314 return {{"gl_FrontColor"s + GetSwizzle(element), Type::Float}}; 1314 return {{"gl_FrontColor"s + GetSwizzle(element), Type::Float}};
1315 case Attribute::Index::FrontSecondaryColor: 1315 case Attribute::Index::FrontSecondaryColor:
@@ -1332,7 +1332,7 @@ private:
1332 Type::Float}}; 1332 Type::Float}};
1333 } 1333 }
1334 UNIMPLEMENTED_MSG("Unhandled output attribute: {}", static_cast<u32>(attribute)); 1334 UNIMPLEMENTED_MSG("Unhandled output attribute: {}", static_cast<u32>(attribute));
1335 return {}; 1335 return std::nullopt;
1336 } 1336 }
1337 } 1337 }
1338 1338
diff --git a/src/video_core/shader/ast.h b/src/video_core/shader/ast.h
index cca13bcde..8e5a22ab3 100644
--- a/src/video_core/shader/ast.h
+++ b/src/video_core/shader/ast.h
@@ -199,55 +199,48 @@ public:
199 } 199 }
200 200
201 std::optional<u32> GetGotoLabel() const { 201 std::optional<u32> GetGotoLabel() const {
202 auto inner = std::get_if<ASTGoto>(&data); 202 if (const auto* inner = std::get_if<ASTGoto>(&data)) {
203 if (inner) {
204 return {inner->label}; 203 return {inner->label};
205 } 204 }
206 return {}; 205 return std::nullopt;
207 } 206 }
208 207
209 Expr GetGotoCondition() const { 208 Expr GetGotoCondition() const {
210 auto inner = std::get_if<ASTGoto>(&data); 209 if (const auto* inner = std::get_if<ASTGoto>(&data)) {
211 if (inner) {
212 return inner->condition; 210 return inner->condition;
213 } 211 }
214 return nullptr; 212 return nullptr;
215 } 213 }
216 214
217 void MarkLabelUnused() { 215 void MarkLabelUnused() {
218 auto inner = std::get_if<ASTLabel>(&data); 216 if (auto* inner = std::get_if<ASTLabel>(&data)) {
219 if (inner) {
220 inner->unused = true; 217 inner->unused = true;
221 } 218 }
222 } 219 }
223 220
224 bool IsLabelUnused() const { 221 bool IsLabelUnused() const {
225 auto inner = std::get_if<ASTLabel>(&data); 222 if (const auto* inner = std::get_if<ASTLabel>(&data)) {
226 if (inner) {
227 return inner->unused; 223 return inner->unused;
228 } 224 }
229 return true; 225 return true;
230 } 226 }
231 227
232 std::optional<u32> GetLabelIndex() const { 228 std::optional<u32> GetLabelIndex() const {
233 auto inner = std::get_if<ASTLabel>(&data); 229 if (const auto* inner = std::get_if<ASTLabel>(&data)) {
234 if (inner) {
235 return {inner->index}; 230 return {inner->index};
236 } 231 }
237 return {}; 232 return std::nullopt;
238 } 233 }
239 234
240 Expr GetIfCondition() const { 235 Expr GetIfCondition() const {
241 auto inner = std::get_if<ASTIfThen>(&data); 236 if (const auto* inner = std::get_if<ASTIfThen>(&data)) {
242 if (inner) {
243 return inner->condition; 237 return inner->condition;
244 } 238 }
245 return nullptr; 239 return nullptr;
246 } 240 }
247 241
248 void SetGotoCondition(Expr new_condition) { 242 void SetGotoCondition(Expr new_condition) {
249 auto inner = std::get_if<ASTGoto>(&data); 243 if (auto* inner = std::get_if<ASTGoto>(&data)) {
250 if (inner) {
251 inner->condition = std::move(new_condition); 244 inner->condition = std::move(new_condition);
252 } 245 }
253 } 246 }
diff --git a/src/video_core/shader/track.cpp b/src/video_core/shader/track.cpp
index d5ed81442..6be3ea92b 100644
--- a/src/video_core/shader/track.cpp
+++ b/src/video_core/shader/track.cpp
@@ -205,12 +205,12 @@ std::optional<u32> ShaderIR::TrackImmediate(Node tracked, const NodeBlock& code,
205 const auto result = TrackRegister(&std::get<GprNode>(*tracked), code, cursor - 1); 205 const auto result = TrackRegister(&std::get<GprNode>(*tracked), code, cursor - 1);
206 const auto& found = result.first; 206 const auto& found = result.first;
207 if (!found) { 207 if (!found) {
208 return {}; 208 return std::nullopt;
209 } 209 }
210 if (const auto immediate = std::get_if<ImmediateNode>(&*found)) { 210 if (const auto immediate = std::get_if<ImmediateNode>(&*found)) {
211 return immediate->GetValue(); 211 return immediate->GetValue();
212 } 212 }
213 return {}; 213 return std::nullopt;
214} 214}
215 215
216std::pair<Node, s64> ShaderIR::TrackRegister(const GprNode* tracked, const NodeBlock& code, 216std::pair<Node, s64> ShaderIR::TrackRegister(const GprNode* tracked, const NodeBlock& code,
diff --git a/src/video_core/texture_cache/surface_base.cpp b/src/video_core/texture_cache/surface_base.cpp
index dfcf36e0b..b44c09d71 100644
--- a/src/video_core/texture_cache/surface_base.cpp
+++ b/src/video_core/texture_cache/surface_base.cpp
@@ -115,20 +115,24 @@ std::optional<std::pair<u32, u32>> SurfaceBaseImpl::GetLayerMipmap(
115 if (gpu_addr == candidate_gpu_addr) { 115 if (gpu_addr == candidate_gpu_addr) {
116 return {{0, 0}}; 116 return {{0, 0}};
117 } 117 }
118
118 if (candidate_gpu_addr < gpu_addr) { 119 if (candidate_gpu_addr < gpu_addr) {
119 return {}; 120 return std::nullopt;
120 } 121 }
122
121 const auto relative_address{static_cast<GPUVAddr>(candidate_gpu_addr - gpu_addr)}; 123 const auto relative_address{static_cast<GPUVAddr>(candidate_gpu_addr - gpu_addr)};
122 const auto layer{static_cast<u32>(relative_address / layer_size)}; 124 const auto layer{static_cast<u32>(relative_address / layer_size)};
123 if (layer >= params.depth) { 125 if (layer >= params.depth) {
124 return {}; 126 return std::nullopt;
125 } 127 }
128
126 const GPUVAddr mipmap_address = relative_address - layer_size * layer; 129 const GPUVAddr mipmap_address = relative_address - layer_size * layer;
127 const auto mipmap_it = 130 const auto mipmap_it =
128 Common::BinaryFind(mipmap_offsets.begin(), mipmap_offsets.end(), mipmap_address); 131 Common::BinaryFind(mipmap_offsets.begin(), mipmap_offsets.end(), mipmap_address);
129 if (mipmap_it == mipmap_offsets.end()) { 132 if (mipmap_it == mipmap_offsets.end()) {
130 return {}; 133 return std::nullopt;
131 } 134 }
135
132 const auto level{static_cast<u32>(std::distance(mipmap_offsets.begin(), mipmap_it))}; 136 const auto level{static_cast<u32>(std::distance(mipmap_offsets.begin(), mipmap_it))};
133 return std::make_pair(layer, level); 137 return std::make_pair(layer, level);
134} 138}