Skip to content

Commit

Permalink
RSX/D3D12: Improve shader lookup performance
Browse files Browse the repository at this point in the history
  • Loading branch information
vlj committed Aug 26, 2015
1 parent 9c24bb9 commit 095c8fa
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions rpcs3/Emu/RSX/Common/ProgramStateCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ class ProgramStateCache
{
size_t hashValue = 0;
hashValue ^= std::hash<unsigned>()(key.vpIdx);
hashValue ^= std::hash<unsigned>()(key.fpIdx);
hashValue ^= std::hash<typename BackendTraits::PipelineProperties>()(key.properties);
return hashValue;
}
};
Expand Down
27 changes: 27 additions & 0 deletions rpcs3/Emu/RSX/D3D12/D3D12PipelineState.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,33 @@ struct D3D12PipelineProperties
}
};

template<typename T>
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<char>()(data[i]);
return result;
}

namespace std
{
template <>
struct hash<D3D12PipelineProperties> {
size_t operator()(const D3D12PipelineProperties &pipelineProperties) const {
size_t seed = hash<unsigned>()(pipelineProperties.DepthStencilFormat) ^
(hash<unsigned>()(pipelineProperties.RenderTargetsFormat) << 2) ^
(hash<unsigned>()(pipelineProperties.Topology) << 2) ^
(hash<unsigned>()(pipelineProperties.numMRT) << 4);
seed ^= hashStructContent(pipelineProperties.Blend);
seed ^= hashStructContent(pipelineProperties.DepthStencil);
seed ^= hashStructContent(pipelineProperties.Rasterization);
return hash<size_t>()(seed);
}
};
}

/** Storage for a shader
* Embeds the D3DBlob
*/
Expand Down

0 comments on commit 095c8fa

Please sign in to comment.