MCPcopy Create free account
hub / github.com/PCSX2/pcsx2 / GetComputeProgram

Method GetComputeProgram

pcsx2/GS/Renderers/OpenGL/GLShaderCache.cpp:446–495  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

444}
445
446std::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
497bool GLShaderCache::GetComputeProgram(
498 GLProgram* out_program, const std::string_view glsl, const PreLinkCallback& callback)

Callers 1

CreateCASProgramsMethod · 0.80

Calls 9

GetTimeMillisecondsMethod · 0.80
CreateFromBinaryMethod · 0.80
WriteLnMethod · 0.45
findMethod · 0.45
endMethod · 0.45
dataMethod · 0.45
ErrorMethod · 0.45
sizeMethod · 0.45
WarningMethod · 0.45

Tested by

no test coverage detected