VideoCommon: add hash functions for pipeline uid object

This commit is contained in:
iwubcode 2025-08-05 22:45:09 -05:00
commit c77adc9de8
2 changed files with 33 additions and 1 deletions

View file

@ -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<XXH64_hash_t>(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

View file

@ -3,9 +3,20 @@
#pragma once
#include <xxh3.h>
#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