From 2a5b3aa6956c758640a9a6541de0aed959e70ebc Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sat, 23 Sep 2023 13:38:27 +1000 Subject: [PATCH] OpenGLDevice: Fix reused pipeline creation failing without cache --- src/util/opengl_pipeline.cpp | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/util/opengl_pipeline.cpp b/src/util/opengl_pipeline.cpp index c6cc5b9a0..0677a0a3e 100644 --- a/src/util/opengl_pipeline.cpp +++ b/src/util/opengl_pipeline.cpp @@ -290,21 +290,23 @@ GLuint OpenGLDevice::LookupProgramCache(const OpenGLPipeline::ProgramCacheKey& k return it->second.program_id; } + const GLuint program_id = CompileProgram(plconfig); + if (program_id == 0) + { + // Compile failed, don't add to map, it just gets confusing. + return 0; + } + OpenGLPipeline::ProgramCacheItem item; - item.program_id = CompileProgram(plconfig); - item.reference_count = 0; + item.program_id = program_id; + item.reference_count = 1; item.file_format = 0; item.file_offset = 0; item.file_uncompressed_size = 0; item.file_compressed_size = 0; - if (item.program_id != 0) - { - if (m_pipeline_disk_cache_file) - AddToPipelineCache(&item); - item.reference_count++; - } + if (m_pipeline_disk_cache_file) + AddToPipelineCache(&item); - // Insert into cache even if we failed, so we don't compile it again, but don't increment reference count. m_program_cache.emplace(key, item); return item.program_id; } @@ -443,6 +445,10 @@ void OpenGLDevice::UnrefProgram(const OpenGLPipeline::ProgramCacheKey& key) glDeleteProgram(it->second.program_id); it->second.program_id = 0; + + // If it's not in the pipeline cache, we need to remove it completely, otherwise we won't recreate it. + if (it->second.file_uncompressed_size == 0) + m_program_cache.erase(it); } GLuint OpenGLDevice::LookupVAOCache(const OpenGLPipeline::VertexArrayCacheKey& key)