From a97fc28ee282644001cac142909cf8dc33a24f77 Mon Sep 17 00:00:00 2001 From: Triang3l Date: Tue, 1 Jan 2019 23:13:26 +0300 Subject: [PATCH] [D3D12] Use multimap for pipelines --- src/xenia/gpu/d3d12/pipeline_cache.cc | 19 +++++++++++-------- src/xenia/gpu/d3d12/pipeline_cache.h | 4 ++-- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/xenia/gpu/d3d12/pipeline_cache.cc b/src/xenia/gpu/d3d12/pipeline_cache.cc index d5ed868ce..561df6abd 100644 --- a/src/xenia/gpu/d3d12/pipeline_cache.cc +++ b/src/xenia/gpu/d3d12/pipeline_cache.cc @@ -152,13 +152,16 @@ bool PipelineCache::ConfigurePipeline( // Find an existing pipeline in the cache. uint64_t hash = XXH64(&description, sizeof(description), 0); - auto it = pipelines_.find(hash); - if (it != pipelines_.end()) { - Pipeline* found_pipeline = it->second; - current_pipeline_ = found_pipeline; - *pipeline_out = found_pipeline->state; - *root_signature_out = found_pipeline->description.root_signature; - return true; + auto found_range = pipelines_.equal_range(hash); + for (auto iter = found_range.first; iter != found_range.second; ++iter) { + Pipeline* found_pipeline = iter->second; + if (!std::memcmp(&found_pipeline->description, &description, + sizeof(description))) { + current_pipeline_ = found_pipeline; + *pipeline_out = found_pipeline->state; + *root_signature_out = found_pipeline->description.root_signature; + return true; + } } // Create a new pipeline if not found and add it to the cache. @@ -182,7 +185,7 @@ bool PipelineCache::ConfigurePipeline( Pipeline* new_pipeline = new Pipeline; new_pipeline->state = new_state; std::memcpy(&new_pipeline->description, &description, sizeof(description)); - pipelines_.insert({hash, new_pipeline}); + pipelines_.insert(std::make_pair(hash, new_pipeline)); COUNT_profile_set("gpu/pipeline_cache/pipelines", pipelines_.size()); current_pipeline_ = new_pipeline; diff --git a/src/xenia/gpu/d3d12/pipeline_cache.h b/src/xenia/gpu/d3d12/pipeline_cache.h index 82baa3427..4df2fe7a3 100644 --- a/src/xenia/gpu/d3d12/pipeline_cache.h +++ b/src/xenia/gpu/d3d12/pipeline_cache.h @@ -187,8 +187,8 @@ class PipelineCache { ID3D12PipelineState* state; PipelineDescription description; }; - // All previously generated pipelines mapped by hash. - std::unordered_map pipelines_; + // All previously generated pipelines identified by hash and the description. + std::unordered_multimap pipelines_; // Previously used pipeline. This matches our current state settings // and allows us to quickly(ish) reuse the pipeline if no registers have