From 8c37cd1af689ce0ff0cd37e4579508a898ea3807 Mon Sep 17 00:00:00 2001 From: ReinUsesLisp Date: Wed, 22 Apr 2020 20:52:29 -0300 Subject: vk_pipeline_cache: Unify pipeline cache keys into a single operation This allows us to call Common::CityHash and std::memcmp only once for GraphicsPipelineCacheKey. While we are at it, do the same for compute. --- src/video_core/renderer_vulkan/vk_pipeline_cache.h | 49 ++++++++++------------ 1 file changed, 22 insertions(+), 27 deletions(-) (limited to 'src/video_core/renderer_vulkan/vk_pipeline_cache.h') diff --git a/src/video_core/renderer_vulkan/vk_pipeline_cache.h b/src/video_core/renderer_vulkan/vk_pipeline_cache.h index 602a0a340..84d26b822 100644 --- a/src/video_core/renderer_vulkan/vk_pipeline_cache.h +++ b/src/video_core/renderer_vulkan/vk_pipeline_cache.h @@ -7,7 +7,6 @@ #include #include #include -#include #include #include #include @@ -51,42 +50,38 @@ using ProgramCode = std::vector; struct GraphicsPipelineCacheKey { FixedPipelineState fixed_state; - std::array shaders; RenderPassParams renderpass_params; + std::array shaders; + u64 padding; // This is necessary for unique object representations - std::size_t Hash() const noexcept { - std::size_t hash = fixed_state.Hash(); - for (const auto& shader : shaders) { - boost::hash_combine(hash, shader); - } - boost::hash_combine(hash, renderpass_params.Hash()); - return hash; - } + std::size_t Hash() const noexcept; + + bool operator==(const GraphicsPipelineCacheKey& rhs) const noexcept; - bool operator==(const GraphicsPipelineCacheKey& rhs) const noexcept { - return std::tie(fixed_state, shaders, renderpass_params) == - std::tie(rhs.fixed_state, rhs.shaders, rhs.renderpass_params); + bool operator!=(const GraphicsPipelineCacheKey& rhs) const noexcept { + return !operator==(rhs); } }; +static_assert(std::has_unique_object_representations_v); +static_assert(std::is_trivially_copyable_v); +static_assert(std::is_trivially_constructible_v); struct ComputePipelineCacheKey { - GPUVAddr shader{}; - u32 shared_memory_size{}; - std::array workgroup_size{}; - - std::size_t Hash() const noexcept { - return static_cast(shader) ^ - ((static_cast(shared_memory_size) >> 7) << 40) ^ - static_cast(workgroup_size[0]) ^ - (static_cast(workgroup_size[1]) << 16) ^ - (static_cast(workgroup_size[2]) << 24); - } + GPUVAddr shader; + u32 shared_memory_size; + std::array workgroup_size; + + std::size_t Hash() const noexcept; + + bool operator==(const ComputePipelineCacheKey& rhs) const noexcept; - bool operator==(const ComputePipelineCacheKey& rhs) const noexcept { - return std::tie(shader, shared_memory_size, workgroup_size) == - std::tie(rhs.shader, rhs.shared_memory_size, rhs.workgroup_size); + bool operator!=(const ComputePipelineCacheKey& rhs) const noexcept { + return !operator==(rhs); } }; +static_assert(std::has_unique_object_representations_v); +static_assert(std::is_trivially_copyable_v); +static_assert(std::is_trivially_constructible_v); } // namespace Vulkan -- cgit v1.2.3