From 095c8fa19b25c7d548e51f290bf7db045cf36125 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Mon, 24 Aug 2015 20:27:42 +0200 Subject: [PATCH] RSX/D3D12: Improve shader lookup performance --- rpcs3/Emu/RSX/Common/ProgramStateCache.h | 2 ++ rpcs3/Emu/RSX/D3D12/D3D12PipelineState.h | 27 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/rpcs3/Emu/RSX/Common/ProgramStateCache.h b/rpcs3/Emu/RSX/Common/ProgramStateCache.h index 6a732e7bd7..3c1f85bae3 100644 --- a/rpcs3/Emu/RSX/Common/ProgramStateCache.h +++ b/rpcs3/Emu/RSX/Common/ProgramStateCache.h @@ -223,6 +223,8 @@ private: { size_t hashValue = 0; hashValue ^= std::hash()(key.vpIdx); + hashValue ^= std::hash()(key.fpIdx); + hashValue ^= std::hash()(key.properties); return hashValue; } }; diff --git a/rpcs3/Emu/RSX/D3D12/D3D12PipelineState.h b/rpcs3/Emu/RSX/D3D12/D3D12PipelineState.h index 38566e5ecc..d264b7ae28 100644 --- a/rpcs3/Emu/RSX/D3D12/D3D12PipelineState.h +++ b/rpcs3/Emu/RSX/D3D12/D3D12PipelineState.h @@ -47,6 +47,33 @@ struct D3D12PipelineProperties } }; +template +size_t hashStructContent(const T& structure) +{ + char *data = (char*)(&structure); + size_t result = 0; + for (unsigned i = 0; i < sizeof(T); i++) + result ^= std::hash()(data[i]); + return result; +} + +namespace std +{ + template <> + struct hash { + size_t operator()(const D3D12PipelineProperties &pipelineProperties) const { + size_t seed = hash()(pipelineProperties.DepthStencilFormat) ^ + (hash()(pipelineProperties.RenderTargetsFormat) << 2) ^ + (hash()(pipelineProperties.Topology) << 2) ^ + (hash()(pipelineProperties.numMRT) << 4); + seed ^= hashStructContent(pipelineProperties.Blend); + seed ^= hashStructContent(pipelineProperties.DepthStencil); + seed ^= hashStructContent(pipelineProperties.Rasterization); + return hash()(seed); + } + }; +} + /** Storage for a shader * Embeds the D3DBlob */