From 96aa762d1ee5bd0294da80ac049a9fcd99032f2a Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sat, 20 Apr 2019 12:51:04 +1000 Subject: [PATCH 1/2] PixelShaderGen: Don't emit bounding box shader code for old UIDs when disabled If bounding box is enabled when a UID cache is created, then later disabled, we shouldn't emit the bounding box portion of the shader. Fixes pipeline creation errors on D3D12 backend for this case. --- Source/Core/VideoCommon/PixelShaderGen.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Source/Core/VideoCommon/PixelShaderGen.cpp b/Source/Core/VideoCommon/PixelShaderGen.cpp index 7064552e7d..c5d7086ef7 100644 --- a/Source/Core/VideoCommon/PixelShaderGen.cpp +++ b/Source/Core/VideoCommon/PixelShaderGen.cpp @@ -347,6 +347,10 @@ void ClearUnusedPixelShaderUidBits(APIType ApiType, const ShaderHostConfig& host // uint output when logic op is not supported (i.e. driver/device does not support D3D11.1). if (ApiType != APIType::D3D || !host_config.backend_logic_op) uid_data->uint_output = 0; + + // If bounding box is enabled when a UID cache is created, then later disabled, we shouldn't + // emit the bounding box portion of the shader. + uid_data->bounding_box &= host_config.bounding_box; } void WritePixelShaderCommonHeader(ShaderCode& out, APIType ApiType, u32 num_texgens, From c6b45c5ca9ea80a4190db98858e186996d4827af Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sat, 20 Apr 2019 23:15:25 +1000 Subject: [PATCH 2/2] ShaderCache: Fix crash if pipeline from uid cache fails creation --- Source/Core/VideoCommon/ShaderCache.cpp | 36 ++++++++++++++----------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/Source/Core/VideoCommon/ShaderCache.cpp b/Source/Core/VideoCommon/ShaderCache.cpp index e1712ec8f3..3e4ed24662 100644 --- a/Source/Core/VideoCommon/ShaderCache.cpp +++ b/Source/Core/VideoCommon/ShaderCache.cpp @@ -641,17 +641,19 @@ const AbstractPipeline* ShaderCache::InsertGXPipeline(const GXPipelineUid& confi auto& entry = m_gx_pipeline_cache[config]; entry.second = false; if (!entry.first && pipeline) + { entry.first = std::move(pipeline); - if (g_ActiveConfig.bShaderCache) - { - auto cache_data = entry.first->GetCacheData(); - if (!cache_data.empty()) + if (g_ActiveConfig.bShaderCache) { - SerializedGXPipelineUid disk_uid; - SerializePipelineUid(config, disk_uid); - m_gx_pipeline_disk_cache.Append(disk_uid, cache_data.data(), - static_cast(cache_data.size())); + auto cache_data = entry.first->GetCacheData(); + if (!cache_data.empty()) + { + SerializedGXPipelineUid disk_uid; + SerializePipelineUid(config, disk_uid); + m_gx_pipeline_disk_cache.Append(disk_uid, cache_data.data(), + static_cast(cache_data.size())); + } } } @@ -665,17 +667,19 @@ ShaderCache::InsertGXUberPipeline(const GXUberPipelineUid& config, auto& entry = m_gx_uber_pipeline_cache[config]; entry.second = false; if (!entry.first && pipeline) + { entry.first = std::move(pipeline); - if (g_ActiveConfig.bShaderCache) - { - auto cache_data = entry.first->GetCacheData(); - if (!cache_data.empty()) + if (g_ActiveConfig.bShaderCache) { - SerializedGXUberPipelineUid disk_uid; - SerializePipelineUid(config, disk_uid); - m_gx_uber_pipeline_disk_cache.Append(disk_uid, cache_data.data(), - static_cast(cache_data.size())); + auto cache_data = entry.first->GetCacheData(); + if (!cache_data.empty()) + { + SerializedGXUberPipelineUid disk_uid; + SerializePipelineUid(config, disk_uid); + m_gx_uber_pipeline_disk_cache.Append(disk_uid, cache_data.data(), + static_cast(cache_data.size())); + } } }