shader_environment.cpp 20 KB

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