mirror of
				https://git.suyu.dev/suyu/suyu
				synced 2025-10-30 23:49:01 -05:00 
			
		
		
		
	gl_shader_disk_cache: Make use of std::nullopt where applicable
Allows the compiler to avoid unnecessarily zeroing out the internal buffer of std::optional on some implementations.
This commit is contained in:
		| @@ -214,20 +214,20 @@ std::optional<std::vector<ShaderDiskCacheEntry>> ShaderDiskCacheOpenGL::LoadTran | |||||||
|     // Skip games without title id |     // Skip games without title id | ||||||
|     const bool has_title_id = system.CurrentProcess()->GetTitleID() != 0; |     const bool has_title_id = system.CurrentProcess()->GetTitleID() != 0; | ||||||
|     if (!Settings::values.use_disk_shader_cache.GetValue() || !has_title_id) { |     if (!Settings::values.use_disk_shader_cache.GetValue() || !has_title_id) { | ||||||
|         return {}; |         return std::nullopt; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     FileUtil::IOFile file(GetTransferablePath(), "rb"); |     FileUtil::IOFile file(GetTransferablePath(), "rb"); | ||||||
|     if (!file.IsOpen()) { |     if (!file.IsOpen()) { | ||||||
|         LOG_INFO(Render_OpenGL, "No transferable shader cache found"); |         LOG_INFO(Render_OpenGL, "No transferable shader cache found"); | ||||||
|         is_usable = true; |         is_usable = true; | ||||||
|         return {}; |         return std::nullopt; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     u32 version{}; |     u32 version{}; | ||||||
|     if (file.ReadBytes(&version, sizeof(version)) != sizeof(version)) { |     if (file.ReadBytes(&version, sizeof(version)) != sizeof(version)) { | ||||||
|         LOG_ERROR(Render_OpenGL, "Failed to get transferable cache version, skipping it"); |         LOG_ERROR(Render_OpenGL, "Failed to get transferable cache version, skipping it"); | ||||||
|         return {}; |         return std::nullopt; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     if (version < NativeVersion) { |     if (version < NativeVersion) { | ||||||
| @@ -235,12 +235,12 @@ std::optional<std::vector<ShaderDiskCacheEntry>> ShaderDiskCacheOpenGL::LoadTran | |||||||
|         file.Close(); |         file.Close(); | ||||||
|         InvalidateTransferable(); |         InvalidateTransferable(); | ||||||
|         is_usable = true; |         is_usable = true; | ||||||
|         return {}; |         return std::nullopt; | ||||||
|     } |     } | ||||||
|     if (version > NativeVersion) { |     if (version > NativeVersion) { | ||||||
|         LOG_WARNING(Render_OpenGL, "Transferable shader cache was generated with a newer version " |         LOG_WARNING(Render_OpenGL, "Transferable shader cache was generated with a newer version " | ||||||
|                                    "of the emulator, skipping"); |                                    "of the emulator, skipping"); | ||||||
|         return {}; |         return std::nullopt; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     // Version is valid, load the shaders |     // Version is valid, load the shaders | ||||||
| @@ -249,7 +249,7 @@ std::optional<std::vector<ShaderDiskCacheEntry>> ShaderDiskCacheOpenGL::LoadTran | |||||||
|         ShaderDiskCacheEntry& entry = entries.emplace_back(); |         ShaderDiskCacheEntry& entry = entries.emplace_back(); | ||||||
|         if (!entry.Load(file)) { |         if (!entry.Load(file)) { | ||||||
|             LOG_ERROR(Render_OpenGL, "Failed to load transferable raw entry, skipping"); |             LOG_ERROR(Render_OpenGL, "Failed to load transferable raw entry, skipping"); | ||||||
|             return {}; |             return std::nullopt; | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -290,12 +290,12 @@ std::optional<std::vector<ShaderDiskCachePrecompiled>> ShaderDiskCacheOpenGL::Lo | |||||||
|     ShaderCacheVersionHash file_hash{}; |     ShaderCacheVersionHash file_hash{}; | ||||||
|     if (!LoadArrayFromPrecompiled(file_hash.data(), file_hash.size())) { |     if (!LoadArrayFromPrecompiled(file_hash.data(), file_hash.size())) { | ||||||
|         precompiled_cache_virtual_file_offset = 0; |         precompiled_cache_virtual_file_offset = 0; | ||||||
|         return {}; |         return std::nullopt; | ||||||
|     } |     } | ||||||
|     if (GetShaderCacheVersionHash() != file_hash) { |     if (GetShaderCacheVersionHash() != file_hash) { | ||||||
|         LOG_INFO(Render_OpenGL, "Precompiled cache is from another version of the emulator"); |         LOG_INFO(Render_OpenGL, "Precompiled cache is from another version of the emulator"); | ||||||
|         precompiled_cache_virtual_file_offset = 0; |         precompiled_cache_virtual_file_offset = 0; | ||||||
|         return {}; |         return std::nullopt; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     std::vector<ShaderDiskCachePrecompiled> entries; |     std::vector<ShaderDiskCachePrecompiled> entries; | ||||||
| @@ -305,15 +305,16 @@ std::optional<std::vector<ShaderDiskCachePrecompiled>> ShaderDiskCacheOpenGL::Lo | |||||||
|         if (!LoadObjectFromPrecompiled(entry.unique_identifier) || |         if (!LoadObjectFromPrecompiled(entry.unique_identifier) || | ||||||
|             !LoadObjectFromPrecompiled(entry.binary_format) || |             !LoadObjectFromPrecompiled(entry.binary_format) || | ||||||
|             !LoadObjectFromPrecompiled(binary_size)) { |             !LoadObjectFromPrecompiled(binary_size)) { | ||||||
|             return {}; |             return std::nullopt; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         entry.binary.resize(binary_size); |         entry.binary.resize(binary_size); | ||||||
|         if (!LoadArrayFromPrecompiled(entry.binary.data(), entry.binary.size())) { |         if (!LoadArrayFromPrecompiled(entry.binary.data(), entry.binary.size())) { | ||||||
|             return {}; |             return std::nullopt; | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|     return entries; |  | ||||||
|  |     return std::move(entries); | ||||||
| } | } | ||||||
|  |  | ||||||
| void ShaderDiskCacheOpenGL::InvalidateTransferable() { | void ShaderDiskCacheOpenGL::InvalidateTransferable() { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Lioncash
					Lioncash