From c77adc9de86a340f7c2818852a5f39623bf23bf2 Mon Sep 17 00:00:00 2001 From: iwubcode Date: Tue, 5 Aug 2025 22:45:09 -0500 Subject: [PATCH] VideoCommon: add hash functions for pipeline uid object --- Source/Core/VideoCommon/ShaderCacheUtils.cpp | 21 ++++++++++++++++++++ Source/Core/VideoCommon/ShaderCacheUtils.h | 13 +++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/Source/Core/VideoCommon/ShaderCacheUtils.cpp b/Source/Core/VideoCommon/ShaderCacheUtils.cpp index 352bfff8a0..6f737898fe 100644 --- a/Source/Core/VideoCommon/ShaderCacheUtils.cpp +++ b/Source/Core/VideoCommon/ShaderCacheUtils.cpp @@ -148,4 +148,25 @@ GXPipelineUid ApplyDriverBugs(const GXPipelineUid& in) return out; } + +std::size_t PipelineToHash(const GXPipelineUid& in) +{ + XXH3_state_t pipeline_hash_state; + XXH3_INITSTATE(&pipeline_hash_state); + XXH3_64bits_reset_withSeed(&pipeline_hash_state, static_cast(1)); + UpdateHashWithPipeline(in, &pipeline_hash_state); + return XXH3_64bits_digest(&pipeline_hash_state); +} + +void UpdateHashWithPipeline(const GXPipelineUid& in, XXH3_state_t* hash_state) +{ + XXH3_64bits_update(hash_state, &in.vertex_format->GetVertexDeclaration(), + sizeof(PortableVertexDeclaration)); + XXH3_64bits_update(hash_state, &in.blending_state, sizeof(BlendingState)); + XXH3_64bits_update(hash_state, &in.depth_state, sizeof(DepthState)); + XXH3_64bits_update(hash_state, &in.rasterization_state, sizeof(RasterizationState)); + XXH3_64bits_update(hash_state, &in.gs_uid, sizeof(GeometryShaderUid)); + XXH3_64bits_update(hash_state, &in.ps_uid, sizeof(PixelShaderUid)); + XXH3_64bits_update(hash_state, &in.vs_uid, sizeof(VertexShaderUid)); +} } // namespace VideoCommon diff --git a/Source/Core/VideoCommon/ShaderCacheUtils.h b/Source/Core/VideoCommon/ShaderCacheUtils.h index ffea798b9f..4a9b7b1696 100644 --- a/Source/Core/VideoCommon/ShaderCacheUtils.h +++ b/Source/Core/VideoCommon/ShaderCacheUtils.h @@ -3,9 +3,20 @@ #pragma once +#include + #include "VideoCommon/GXPipelineTypes.h" namespace VideoCommon { GXPipelineUid ApplyDriverBugs(const GXPipelineUid& in); -} + +// Returns a hash of the pipeline, hashing the +// vertex declarations instead of the native vertex format +// object +std::size_t PipelineToHash(const GXPipelineUid& in); + +// Updates an existing hash with the hash of the pipeline +void UpdateHashWithPipeline(const GXPipelineUid& in, XXH3_state_t* hash_state); + +} // namespace VideoCommon