[D3D12] Use multimap for pipelines

This commit is contained in:
Triang3l 2019-01-01 23:13:26 +03:00
parent 1cea4062c0
commit a97fc28ee2
2 changed files with 13 additions and 10 deletions

View File

@ -152,13 +152,16 @@ bool PipelineCache::ConfigurePipeline(
// Find an existing pipeline in the cache. // Find an existing pipeline in the cache.
uint64_t hash = XXH64(&description, sizeof(description), 0); uint64_t hash = XXH64(&description, sizeof(description), 0);
auto it = pipelines_.find(hash); auto found_range = pipelines_.equal_range(hash);
if (it != pipelines_.end()) { for (auto iter = found_range.first; iter != found_range.second; ++iter) {
Pipeline* found_pipeline = it->second; Pipeline* found_pipeline = iter->second;
current_pipeline_ = found_pipeline; if (!std::memcmp(&found_pipeline->description, &description,
*pipeline_out = found_pipeline->state; sizeof(description))) {
*root_signature_out = found_pipeline->description.root_signature; current_pipeline_ = found_pipeline;
return true; *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. // 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; Pipeline* new_pipeline = new Pipeline;
new_pipeline->state = new_state; new_pipeline->state = new_state;
std::memcpy(&new_pipeline->description, &description, sizeof(description)); 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()); COUNT_profile_set("gpu/pipeline_cache/pipelines", pipelines_.size());
current_pipeline_ = new_pipeline; current_pipeline_ = new_pipeline;

View File

@ -187,8 +187,8 @@ class PipelineCache {
ID3D12PipelineState* state; ID3D12PipelineState* state;
PipelineDescription description; PipelineDescription description;
}; };
// All previously generated pipelines mapped by hash. // All previously generated pipelines identified by hash and the description.
std::unordered_map<uint64_t, Pipeline*> pipelines_; std::unordered_multimap<uint64_t, Pipeline*> pipelines_;
// Previously used pipeline. This matches our current state settings // Previously used pipeline. This matches our current state settings
// and allows us to quickly(ish) reuse the pipeline if no registers have // and allows us to quickly(ish) reuse the pipeline if no registers have