| 444 | } |
| 445 | |
| 446 | std::optional<GLProgram> GLShaderCache::GetComputeProgram(const std::string_view glsl, const PreLinkCallback& callback) |
| 447 | { |
| 448 | if (!m_program_binary_supported || !m_blob_file) |
| 449 | { |
| 450 | #ifdef PCSX2_DEVBUILD |
| 451 | Common::Timer timer; |
| 452 | #endif |
| 453 | |
| 454 | std::optional<GLProgram> res = CompileComputeProgram(glsl, callback, false); |
| 455 | |
| 456 | #ifdef PCSX2_DEVBUILD |
| 457 | Console.WriteLn("Time to compile shader without caching: %.2fms", timer.GetTimeMilliseconds()); |
| 458 | #endif |
| 459 | return res; |
| 460 | } |
| 461 | |
| 462 | const auto key = GetCacheKey(glsl, std::string_view()); |
| 463 | auto iter = m_index.find(key); |
| 464 | if (iter == m_index.end()) |
| 465 | return CompileAndAddComputeProgram(key, glsl, callback); |
| 466 | |
| 467 | std::vector<u8> data(iter->second.blob_size); |
| 468 | if (std::fseek(m_blob_file, iter->second.file_offset, SEEK_SET) != 0 || |
| 469 | std::fread(data.data(), 1, iter->second.blob_size, m_blob_file) != iter->second.blob_size) |
| 470 | { |
| 471 | Console.Error("Read blob from file failed"); |
| 472 | return {}; |
| 473 | } |
| 474 | |
| 475 | #ifdef PCSX2_DEVBUILD |
| 476 | Common::Timer timer; |
| 477 | #endif |
| 478 | |
| 479 | GLProgram prog; |
| 480 | if (prog.CreateFromBinary(data.data(), static_cast<u32>(data.size()), iter->second.blob_format)) |
| 481 | { |
| 482 | #ifdef PCSX2_DEVBUILD |
| 483 | Console.WriteLn("Time to create program from binary: %.2fms", timer.GetTimeMilliseconds()); |
| 484 | #endif |
| 485 | |
| 486 | return std::optional<GLProgram>(std::move(prog)); |
| 487 | } |
| 488 | |
| 489 | Console.Warning( |
| 490 | "Failed to create program from binary, this may be due to a driver or GPU Change. Recreating cache."); |
| 491 | if (!Recreate()) |
| 492 | return CompileComputeProgram(glsl, callback, false); |
| 493 | else |
| 494 | return CompileAndAddComputeProgram(key, glsl, callback); |
| 495 | } |
| 496 | |
| 497 | bool GLShaderCache::GetComputeProgram( |
| 498 | GLProgram* out_program, const std::string_view glsl, const PreLinkCallback& callback) |
no test coverage detected