summaryrefslogtreecommitdiff
path: root/Source/Core/VideoCommon/ShaderCache.cpp
diff options
context:
space:
mode:
authorSintendo <3380580+Sintendo@users.noreply.github.com>2025-07-06 08:41:12 +0200
committerSintendo <3380580+Sintendo@users.noreply.github.com>2025-07-08 06:53:42 +0200
commitf2392e4048ce977bad2227d08f3a042526f7c4da (patch)
tree1ff5cd55011aa8503f504eefc57e49a7c35985a8 /Source/Core/VideoCommon/ShaderCache.cpp
parenta5e85caf0af66fec07b476718a69519b06e6a69f (diff)
Avoid map/set double lookups
Fix some common anti-patterns with these data structures. - You can dereference the iterator returned by `find` to access the underlying value directly, without an extra `operator[]`/`at`. - Rather than checking for an element before insertion/deletion, you can just do the operation and if needed check the return value to determine if the insertion/deletion succeeded.
Diffstat (limited to 'Source/Core/VideoCommon/ShaderCache.cpp')
-rw-r--r--Source/Core/VideoCommon/ShaderCache.cpp29
1 files changed, 9 insertions, 20 deletions
diff --git a/Source/Core/VideoCommon/ShaderCache.cpp b/Source/Core/VideoCommon/ShaderCache.cpp
index 0e5cc141a1..84b21f8e3d 100644
--- a/Source/Core/VideoCommon/ShaderCache.cpp
+++ b/Source/Core/VideoCommon/ShaderCache.cpp
@@ -1535,26 +1535,21 @@ const AbstractPipeline* ShaderCache::GetTextureReinterpretPipeline(TextureFormat
TextureFormat to_format)
{
const auto key = std::make_pair(from_format, to_format);
- auto iter = m_texture_reinterpret_pipelines.find(key);
- if (iter != m_texture_reinterpret_pipelines.end())
+ const auto [iter, inserted] = m_texture_reinterpret_pipelines.emplace(key, nullptr);
+
+ if (!inserted)
return iter->second.get();
std::string shader_source =
FramebufferShaderGen::GenerateTextureReinterpretShader(from_format, to_format);
if (shader_source.empty())
- {
- m_texture_reinterpret_pipelines.emplace(key, nullptr);
return nullptr;
- }
std::unique_ptr<AbstractShader> shader = g_gfx->CreateShaderFromSource(
ShaderStage::Pixel, shader_source,
fmt::format("Texture reinterpret pixel shader: {} to {}", from_format, to_format));
if (!shader)
- {
- m_texture_reinterpret_pipelines.emplace(key, nullptr);
return nullptr;
- }
AbstractPipelineConfig config;
config.vertex_format = nullptr;
@@ -1566,8 +1561,8 @@ const AbstractPipeline* ShaderCache::GetTextureReinterpretPipeline(TextureFormat
config.blending_state = RenderState::GetNoBlendingBlendState();
config.framebuffer_state = RenderState::GetRGBA8FramebufferState();
config.usage = AbstractPipelineUsage::Utility;
- auto iiter = m_texture_reinterpret_pipelines.emplace(key, g_gfx->CreatePipeline(config));
- return iiter.first->second.get();
+ iter->second = g_gfx->CreatePipeline(config);
+ return iter->second.get();
}
const AbstractShader*
@@ -1576,17 +1571,14 @@ ShaderCache::GetTextureDecodingShader(TextureFormat format,
{
const auto key = std::make_pair(static_cast<u32>(format),
static_cast<u32>(palette_format.value_or(TLUTFormat::IA8)));
- const auto iter = m_texture_decoding_shaders.find(key);
- if (iter != m_texture_decoding_shaders.end())
+ const auto [iter, inserted] = m_texture_decoding_shaders.emplace(key, nullptr);
+ if (!inserted)
return iter->second.get();
const std::string shader_source =
TextureConversionShaderTiled::GenerateDecodingShader(format, palette_format, APIType::OpenGL);
if (shader_source.empty())
- {
- m_texture_decoding_shaders.emplace(key, nullptr);
return nullptr;
- }
const std::string name =
palette_format.has_value() ?
@@ -1596,12 +1588,9 @@ ShaderCache::GetTextureDecodingShader(TextureFormat format,
std::unique_ptr<AbstractShader> shader =
g_gfx->CreateShaderFromSource(ShaderStage::Compute, shader_source, name);
if (!shader)
- {
- m_texture_decoding_shaders.emplace(key, nullptr);
return nullptr;
- }
- const auto iiter = m_texture_decoding_shaders.emplace(key, std::move(shader));
- return iiter.first->second.get();
+ iter->second = std::move(shader);
+ return iter->second.get();
}
} // namespace VideoCommon