shader_environment.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  1. // SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include <algorithm>
  4. #include <filesystem>
  5. #include <fstream>
  6. #include <memory>
  7. #include <optional>
  8. #include <utility>
  9. #include "common/assert.h"
  10. #include "common/cityhash.h"
  11. #include "common/common_types.h"
  12. #include "common/div_ceil.h"
  13. #include "common/fs/fs.h"
  14. #include "common/fs/path_util.h"
  15. #include "common/logging/log.h"
  16. #include "shader_recompiler/environment.h"
  17. #include "video_core/engines/kepler_compute.h"
  18. #include "video_core/memory_manager.h"
  19. #include "video_core/shader_environment.h"
  20. #include "video_core/textures/texture.h"
  21. namespace VideoCommon {
  22. constexpr std::array<char, 8> MAGIC_NUMBER{'y', 'u', 'z', 'u', 'c', 'a', 'c', 'h'};
  23. constexpr size_t INST_SIZE = sizeof(u64);
  24. using Maxwell = Tegra::Engines::Maxwell3D::Regs;
  25. static u64 MakeCbufKey(u32 index, u32 offset) {
  26. return (static_cast<u64>(index) << 32) | offset;
  27. }
  28. static Shader::TextureType ConvertType(const Tegra::Texture::TICEntry& entry) {
  29. switch (entry.texture_type) {
  30. case Tegra::Texture::TextureType::Texture1D:
  31. return Shader::TextureType::Color1D;
  32. case Tegra::Texture::TextureType::Texture2D:
  33. case Tegra::Texture::TextureType::Texture2DNoMipmap:
  34. return Shader::TextureType::Color2D;
  35. case Tegra::Texture::TextureType::Texture3D:
  36. return Shader::TextureType::Color3D;
  37. case Tegra::Texture::TextureType::TextureCubemap:
  38. return Shader::TextureType::ColorCube;
  39. case Tegra::Texture::TextureType::Texture1DArray:
  40. return Shader::TextureType::ColorArray1D;
  41. case Tegra::Texture::TextureType::Texture2DArray:
  42. return Shader::TextureType::ColorArray2D;
  43. case Tegra::Texture::TextureType::Texture1DBuffer:
  44. return Shader::TextureType::Buffer;
  45. case Tegra::Texture::TextureType::TextureCubeArray:
  46. return Shader::TextureType::ColorArrayCube;
  47. default:
  48. throw Shader::NotImplementedException("Unknown texture type");
  49. }
  50. }
  51. static std::string_view StageToPrefix(Shader::Stage stage) {
  52. switch (stage) {
  53. case Shader::Stage::VertexB:
  54. return "VB";
  55. case Shader::Stage::TessellationControl:
  56. return "TC";
  57. case Shader::Stage::TessellationEval:
  58. return "TE";
  59. case Shader::Stage::Geometry:
  60. return "GS";
  61. case Shader::Stage::Fragment:
  62. return "FS";
  63. case Shader::Stage::Compute:
  64. return "CS";
  65. case Shader::Stage::VertexA:
  66. return "VA";
  67. default:
  68. return "UK";
  69. }
  70. }
  71. static void DumpImpl(u64 hash, const u64* code, u32 read_highest, u32 read_lowest,
  72. u32 initial_offset, Shader::Stage stage) {
  73. const auto shader_dir{Common::FS::GetYuzuPath(Common::FS::YuzuPath::DumpDir)};
  74. const auto base_dir{shader_dir / "shaders"};
  75. if (!Common::FS::CreateDir(shader_dir) || !Common::FS::CreateDir(base_dir)) {
  76. LOG_ERROR(Common_Filesystem, "Failed to create shader dump directories");
  77. return;
  78. }
  79. const auto prefix = StageToPrefix(stage);
  80. const auto name{base_dir / fmt::format("{}{:016x}.ash", prefix, hash)};
  81. const size_t real_size = read_highest - read_lowest + initial_offset;
  82. const size_t padding_needed = ((32 - (real_size % 32)) % 32);
  83. std::fstream shader_file(name, std::ios::out | std::ios::binary);
  84. const size_t jump_index = initial_offset / sizeof(u64);
  85. shader_file.write(reinterpret_cast<const char*>(code + jump_index), real_size);
  86. for (size_t i = 0; i < padding_needed; i++) {
  87. shader_file.put(0);
  88. }
  89. }
  90. GenericEnvironment::GenericEnvironment(Tegra::MemoryManager& gpu_memory_, GPUVAddr program_base_,
  91. u32 start_address_)
  92. : gpu_memory{&gpu_memory_}, program_base{program_base_} {
  93. start_address = start_address_;
  94. }
  95. GenericEnvironment::~GenericEnvironment() = default;
  96. u32 GenericEnvironment::TextureBoundBuffer() const {
  97. return texture_bound;
  98. }
  99. u32 GenericEnvironment::LocalMemorySize() const {
  100. return local_memory_size;
  101. }
  102. u32 GenericEnvironment::SharedMemorySize() const {
  103. return shared_memory_size;
  104. }
  105. std::array<u32, 3> GenericEnvironment::WorkgroupSize() const {
  106. return workgroup_size;
  107. }
  108. u64 GenericEnvironment::ReadInstruction(u32 address) {
  109. read_lowest = std::min(read_lowest, address);
  110. read_highest = std::max(read_highest, address);
  111. if (address >= cached_lowest && address < cached_highest) {
  112. return code[(address - cached_lowest) / INST_SIZE];
  113. }
  114. has_unbound_instructions = true;
  115. return gpu_memory->Read<u64>(program_base + address);
  116. }
  117. std::optional<u64> GenericEnvironment::Analyze() {
  118. const std::optional<u64> size{TryFindSize()};
  119. if (!size) {
  120. return std::nullopt;
  121. }
  122. cached_lowest = start_address;
  123. cached_highest = start_address + static_cast<u32>(*size);
  124. return Common::CityHash64(reinterpret_cast<const char*>(code.data()), *size);
  125. }
  126. void GenericEnvironment::SetCachedSize(size_t size_bytes) {
  127. cached_lowest = start_address;
  128. cached_highest = start_address + static_cast<u32>(size_bytes);
  129. code.resize(CachedSize());
  130. gpu_memory->ReadBlock(program_base + cached_lowest, code.data(), code.size() * sizeof(u64));
  131. }
  132. size_t GenericEnvironment::CachedSize() const noexcept {
  133. return cached_highest - cached_lowest + INST_SIZE;
  134. }
  135. size_t GenericEnvironment::ReadSize() const noexcept {
  136. return read_highest - read_lowest + INST_SIZE;
  137. }
  138. bool GenericEnvironment::CanBeSerialized() const noexcept {
  139. return !has_unbound_instructions;
  140. }
  141. u64 GenericEnvironment::CalculateHash() const {
  142. const size_t size{ReadSize()};
  143. const auto data{std::make_unique<char[]>(size)};
  144. gpu_memory->ReadBlock(program_base + read_lowest, data.get(), size);
  145. return Common::CityHash64(data.get(), size);
  146. }
  147. void GenericEnvironment::Dump(u64 hash) {
  148. DumpImpl(hash, code.data(), read_highest, read_lowest, initial_offset, stage);
  149. }
  150. void GenericEnvironment::Serialize(std::ofstream& file) const {
  151. const u64 code_size{static_cast<u64>(CachedSize())};
  152. const u64 num_texture_types{static_cast<u64>(texture_types.size())};
  153. const u64 num_cbuf_values{static_cast<u64>(cbuf_values.size())};
  154. file.write(reinterpret_cast<const char*>(&code_size), sizeof(code_size))
  155. .write(reinterpret_cast<const char*>(&num_texture_types), sizeof(num_texture_types))
  156. .write(reinterpret_cast<const char*>(&num_cbuf_values), sizeof(num_cbuf_values))
  157. .write(reinterpret_cast<const char*>(&local_memory_size), sizeof(local_memory_size))
  158. .write(reinterpret_cast<const char*>(&texture_bound), sizeof(texture_bound))
  159. .write(reinterpret_cast<const char*>(&start_address), sizeof(start_address))
  160. .write(reinterpret_cast<const char*>(&cached_lowest), sizeof(cached_lowest))
  161. .write(reinterpret_cast<const char*>(&cached_highest), sizeof(cached_highest))
  162. .write(reinterpret_cast<const char*>(&stage), sizeof(stage))
  163. .write(reinterpret_cast<const char*>(code.data()), code_size);
  164. for (const auto& [key, type] : texture_types) {
  165. file.write(reinterpret_cast<const char*>(&key), sizeof(key))
  166. .write(reinterpret_cast<const char*>(&type), sizeof(type));
  167. }
  168. for (const auto& [key, type] : cbuf_values) {
  169. file.write(reinterpret_cast<const char*>(&key), sizeof(key))
  170. .write(reinterpret_cast<const char*>(&type), sizeof(type));
  171. }
  172. if (stage == Shader::Stage::Compute) {
  173. file.write(reinterpret_cast<const char*>(&workgroup_size), sizeof(workgroup_size))
  174. .write(reinterpret_cast<const char*>(&shared_memory_size), sizeof(shared_memory_size));
  175. } else {
  176. file.write(reinterpret_cast<const char*>(&sph), sizeof(sph));
  177. if (stage == Shader::Stage::Geometry) {
  178. file.write(reinterpret_cast<const char*>(&gp_passthrough_mask),
  179. sizeof(gp_passthrough_mask));
  180. }
  181. }
  182. }
  183. std::optional<u64> GenericEnvironment::TryFindSize() {
  184. static constexpr size_t BLOCK_SIZE = 0x1000;
  185. static constexpr size_t MAXIMUM_SIZE = 0x100000;
  186. static constexpr u64 SELF_BRANCH_A = 0xE2400FFFFF87000FULL;
  187. static constexpr u64 SELF_BRANCH_B = 0xE2400FFFFF07000FULL;
  188. GPUVAddr guest_addr{program_base + start_address};
  189. size_t offset{0};
  190. size_t size{BLOCK_SIZE};
  191. while (size <= MAXIMUM_SIZE) {
  192. code.resize(size / INST_SIZE);
  193. u64* const data = code.data() + offset / INST_SIZE;
  194. gpu_memory->ReadBlock(guest_addr, data, BLOCK_SIZE);
  195. for (size_t index = 0; index < BLOCK_SIZE; index += INST_SIZE) {
  196. const u64 inst = data[index / INST_SIZE];
  197. if (inst == SELF_BRANCH_A || inst == SELF_BRANCH_B) {
  198. return offset + index;
  199. }
  200. }
  201. guest_addr += BLOCK_SIZE;
  202. size += BLOCK_SIZE;
  203. offset += BLOCK_SIZE;
  204. }
  205. return std::nullopt;
  206. }
  207. Shader::TextureType GenericEnvironment::ReadTextureTypeImpl(GPUVAddr tic_addr, u32 tic_limit,
  208. bool via_header_index, u32 raw) {
  209. const auto handle{Tegra::Texture::TexturePair(raw, via_header_index)};
  210. const GPUVAddr descriptor_addr{tic_addr + handle.first * sizeof(Tegra::Texture::TICEntry)};
  211. Tegra::Texture::TICEntry entry;
  212. gpu_memory->ReadBlock(descriptor_addr, &entry, sizeof(entry));
  213. const Shader::TextureType result{ConvertType(entry)};
  214. texture_types.emplace(raw, result);
  215. return result;
  216. }
  217. GraphicsEnvironment::GraphicsEnvironment(Tegra::Engines::Maxwell3D& maxwell3d_,
  218. Tegra::MemoryManager& gpu_memory_,
  219. Maxwell::ShaderProgram program, GPUVAddr program_base_,
  220. u32 start_address_)
  221. : GenericEnvironment{gpu_memory_, program_base_, start_address_}, maxwell3d{&maxwell3d_} {
  222. gpu_memory->ReadBlock(program_base + start_address, &sph, sizeof(sph));
  223. initial_offset = sizeof(sph);
  224. gp_passthrough_mask = maxwell3d->regs.gp_passthrough_mask;
  225. switch (program) {
  226. case Maxwell::ShaderProgram::VertexA:
  227. stage = Shader::Stage::VertexA;
  228. stage_index = 0;
  229. break;
  230. case Maxwell::ShaderProgram::VertexB:
  231. stage = Shader::Stage::VertexB;
  232. stage_index = 0;
  233. break;
  234. case Maxwell::ShaderProgram::TesselationControl:
  235. stage = Shader::Stage::TessellationControl;
  236. stage_index = 1;
  237. break;
  238. case Maxwell::ShaderProgram::TesselationEval:
  239. stage = Shader::Stage::TessellationEval;
  240. stage_index = 2;
  241. break;
  242. case Maxwell::ShaderProgram::Geometry:
  243. stage = Shader::Stage::Geometry;
  244. stage_index = 3;
  245. break;
  246. case Maxwell::ShaderProgram::Fragment:
  247. stage = Shader::Stage::Fragment;
  248. stage_index = 4;
  249. break;
  250. default:
  251. ASSERT_MSG(false, "Invalid program={}", program);
  252. break;
  253. }
  254. const u64 local_size{sph.LocalMemorySize()};
  255. ASSERT(local_size <= std::numeric_limits<u32>::max());
  256. local_memory_size = static_cast<u32>(local_size) + sph.common3.shader_local_memory_crs_size;
  257. texture_bound = maxwell3d->regs.tex_cb_index;
  258. }
  259. u32 GraphicsEnvironment::ReadCbufValue(u32 cbuf_index, u32 cbuf_offset) {
  260. const auto& cbuf{maxwell3d->state.shader_stages[stage_index].const_buffers[cbuf_index]};
  261. ASSERT(cbuf.enabled);
  262. u32 value{};
  263. if (cbuf_offset < cbuf.size) {
  264. value = gpu_memory->Read<u32>(cbuf.address + cbuf_offset);
  265. }
  266. cbuf_values.emplace(MakeCbufKey(cbuf_index, cbuf_offset), value);
  267. return value;
  268. }
  269. Shader::TextureType GraphicsEnvironment::ReadTextureType(u32 handle) {
  270. const auto& regs{maxwell3d->regs};
  271. const bool via_header_index{regs.sampler_index == Maxwell::SamplerIndex::ViaHeaderIndex};
  272. return ReadTextureTypeImpl(regs.tic.Address(), regs.tic.limit, via_header_index, handle);
  273. }
  274. ComputeEnvironment::ComputeEnvironment(Tegra::Engines::KeplerCompute& kepler_compute_,
  275. Tegra::MemoryManager& gpu_memory_, GPUVAddr program_base_,
  276. u32 start_address_)
  277. : GenericEnvironment{gpu_memory_, program_base_, start_address_}, kepler_compute{
  278. &kepler_compute_} {
  279. const auto& qmd{kepler_compute->launch_description};
  280. stage = Shader::Stage::Compute;
  281. local_memory_size = qmd.local_pos_alloc + qmd.local_crs_alloc;
  282. texture_bound = kepler_compute->regs.tex_cb_index;
  283. shared_memory_size = qmd.shared_alloc;
  284. workgroup_size = {qmd.block_dim_x, qmd.block_dim_y, qmd.block_dim_z};
  285. }
  286. u32 ComputeEnvironment::ReadCbufValue(u32 cbuf_index, u32 cbuf_offset) {
  287. const auto& qmd{kepler_compute->launch_description};
  288. ASSERT(((qmd.const_buffer_enable_mask.Value() >> cbuf_index) & 1) != 0);
  289. const auto& cbuf{qmd.const_buffer_config[cbuf_index]};
  290. u32 value{};
  291. if (cbuf_offset < cbuf.size) {
  292. value = gpu_memory->Read<u32>(cbuf.Address() + cbuf_offset);
  293. }
  294. cbuf_values.emplace(MakeCbufKey(cbuf_index, cbuf_offset), value);
  295. return value;
  296. }
  297. Shader::TextureType ComputeEnvironment::ReadTextureType(u32 handle) {
  298. const auto& regs{kepler_compute->regs};
  299. const auto& qmd{kepler_compute->launch_description};
  300. return ReadTextureTypeImpl(regs.tic.Address(), regs.tic.limit, qmd.linked_tsc != 0, handle);
  301. }
  302. void FileEnvironment::Deserialize(std::ifstream& file) {
  303. u64 code_size{};
  304. u64 num_texture_types{};
  305. u64 num_cbuf_values{};
  306. file.read(reinterpret_cast<char*>(&code_size), sizeof(code_size))
  307. .read(reinterpret_cast<char*>(&num_texture_types), sizeof(num_texture_types))
  308. .read(reinterpret_cast<char*>(&num_cbuf_values), sizeof(num_cbuf_values))
  309. .read(reinterpret_cast<char*>(&local_memory_size), sizeof(local_memory_size))
  310. .read(reinterpret_cast<char*>(&texture_bound), sizeof(texture_bound))
  311. .read(reinterpret_cast<char*>(&start_address), sizeof(start_address))
  312. .read(reinterpret_cast<char*>(&read_lowest), sizeof(read_lowest))
  313. .read(reinterpret_cast<char*>(&read_highest), sizeof(read_highest))
  314. .read(reinterpret_cast<char*>(&stage), sizeof(stage));
  315. code = std::make_unique<u64[]>(Common::DivCeil(code_size, sizeof(u64)));
  316. file.read(reinterpret_cast<char*>(code.get()), code_size);
  317. for (size_t i = 0; i < num_texture_types; ++i) {
  318. u32 key;
  319. Shader::TextureType type;
  320. file.read(reinterpret_cast<char*>(&key), sizeof(key))
  321. .read(reinterpret_cast<char*>(&type), sizeof(type));
  322. texture_types.emplace(key, type);
  323. }
  324. for (size_t i = 0; i < num_cbuf_values; ++i) {
  325. u64 key;
  326. u32 value;
  327. file.read(reinterpret_cast<char*>(&key), sizeof(key))
  328. .read(reinterpret_cast<char*>(&value), sizeof(value));
  329. cbuf_values.emplace(key, value);
  330. }
  331. if (stage == Shader::Stage::Compute) {
  332. file.read(reinterpret_cast<char*>(&workgroup_size), sizeof(workgroup_size))
  333. .read(reinterpret_cast<char*>(&shared_memory_size), sizeof(shared_memory_size));
  334. initial_offset = 0;
  335. } else {
  336. file.read(reinterpret_cast<char*>(&sph), sizeof(sph));
  337. initial_offset = sizeof(sph);
  338. if (stage == Shader::Stage::Geometry) {
  339. file.read(reinterpret_cast<char*>(&gp_passthrough_mask), sizeof(gp_passthrough_mask));
  340. }
  341. }
  342. }
  343. void FileEnvironment::Dump(u64 hash) {
  344. DumpImpl(hash, code.get(), read_highest, read_lowest, initial_offset, stage);
  345. }
  346. u64 FileEnvironment::ReadInstruction(u32 address) {
  347. if (address < read_lowest || address > read_highest) {
  348. throw Shader::LogicError("Out of bounds address {}", address);
  349. }
  350. return code[(address - read_lowest) / sizeof(u64)];
  351. }
  352. u32 FileEnvironment::ReadCbufValue(u32 cbuf_index, u32 cbuf_offset) {
  353. const auto it{cbuf_values.find(MakeCbufKey(cbuf_index, cbuf_offset))};
  354. if (it == cbuf_values.end()) {
  355. throw Shader::LogicError("Uncached read texture type");
  356. }
  357. return it->second;
  358. }
  359. Shader::TextureType FileEnvironment::ReadTextureType(u32 handle) {
  360. const auto it{texture_types.find(handle)};
  361. if (it == texture_types.end()) {
  362. throw Shader::LogicError("Uncached read texture type");
  363. }
  364. return it->second;
  365. }
  366. u32 FileEnvironment::LocalMemorySize() const {
  367. return local_memory_size;
  368. }
  369. u32 FileEnvironment::SharedMemorySize() const {
  370. return shared_memory_size;
  371. }
  372. u32 FileEnvironment::TextureBoundBuffer() const {
  373. return texture_bound;
  374. }
  375. std::array<u32, 3> FileEnvironment::WorkgroupSize() const {
  376. return workgroup_size;
  377. }
  378. void SerializePipeline(std::span<const char> key, std::span<const GenericEnvironment* const> envs,
  379. const std::filesystem::path& filename, u32 cache_version) try {
  380. std::ofstream file(filename, std::ios::binary | std::ios::ate | std::ios::app);
  381. file.exceptions(std::ifstream::failbit);
  382. if (!file.is_open()) {
  383. LOG_ERROR(Common_Filesystem, "Failed to open pipeline cache file {}",
  384. Common::FS::PathToUTF8String(filename));
  385. return;
  386. }
  387. if (file.tellp() == 0) {
  388. // Write header
  389. file.write(MAGIC_NUMBER.data(), MAGIC_NUMBER.size())
  390. .write(reinterpret_cast<const char*>(&cache_version), sizeof(cache_version));
  391. }
  392. if (!std::ranges::all_of(envs, &GenericEnvironment::CanBeSerialized)) {
  393. return;
  394. }
  395. const u32 num_envs{static_cast<u32>(envs.size())};
  396. file.write(reinterpret_cast<const char*>(&num_envs), sizeof(num_envs));
  397. for (const GenericEnvironment* const env : envs) {
  398. env->Serialize(file);
  399. }
  400. file.write(key.data(), key.size_bytes());
  401. } catch (const std::ios_base::failure& e) {
  402. LOG_ERROR(Common_Filesystem, "{}", e.what());
  403. if (!Common::FS::RemoveFile(filename)) {
  404. LOG_ERROR(Common_Filesystem, "Failed to delete pipeline cache file {}",
  405. Common::FS::PathToUTF8String(filename));
  406. }
  407. }
  408. void LoadPipelines(
  409. std::stop_token stop_loading, const std::filesystem::path& filename, u32 expected_cache_version,
  410. Common::UniqueFunction<void, std::ifstream&, FileEnvironment> load_compute,
  411. Common::UniqueFunction<void, std::ifstream&, std::vector<FileEnvironment>> load_graphics) try {
  412. std::ifstream file(filename, std::ios::binary | std::ios::ate);
  413. if (!file.is_open()) {
  414. return;
  415. }
  416. file.exceptions(std::ifstream::failbit);
  417. const auto end{file.tellg()};
  418. file.seekg(0, std::ios::beg);
  419. std::array<char, 8> magic_number;
  420. u32 cache_version;
  421. file.read(magic_number.data(), magic_number.size())
  422. .read(reinterpret_cast<char*>(&cache_version), sizeof(cache_version));
  423. if (magic_number != MAGIC_NUMBER || cache_version != expected_cache_version) {
  424. file.close();
  425. if (Common::FS::RemoveFile(filename)) {
  426. if (magic_number != MAGIC_NUMBER) {
  427. LOG_ERROR(Common_Filesystem, "Invalid pipeline cache file");
  428. }
  429. if (cache_version != expected_cache_version) {
  430. LOG_INFO(Common_Filesystem, "Deleting old pipeline cache");
  431. }
  432. } else {
  433. LOG_ERROR(Common_Filesystem,
  434. "Invalid pipeline cache file and failed to delete it in \"{}\"",
  435. Common::FS::PathToUTF8String(filename));
  436. }
  437. return;
  438. }
  439. while (file.tellg() != end) {
  440. if (stop_loading.stop_requested()) {
  441. return;
  442. }
  443. u32 num_envs{};
  444. file.read(reinterpret_cast<char*>(&num_envs), sizeof(num_envs));
  445. std::vector<FileEnvironment> envs(num_envs);
  446. for (FileEnvironment& env : envs) {
  447. env.Deserialize(file);
  448. }
  449. if (envs.front().ShaderStage() == Shader::Stage::Compute) {
  450. load_compute(file, std::move(envs.front()));
  451. } else {
  452. load_graphics(file, std::move(envs));
  453. }
  454. }
  455. } catch (const std::ios_base::failure& e) {
  456. LOG_ERROR(Common_Filesystem, "{}", e.what());
  457. if (!Common::FS::RemoveFile(filename)) {
  458. LOG_ERROR(Common_Filesystem, "Failed to delete pipeline cache file {}",
  459. Common::FS::PathToUTF8String(filename));
  460. }
  461. }
  462. } // namespace VideoCommon