1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2024-12-02 01:24:11 +01:00

[dxvk] Move shader set hash/eq functions into respective structs

Makes it easier to use them outside the pipeline manager.
This commit is contained in:
Philip Rebohle 2019-09-30 02:29:54 +02:00
parent ba5f319809
commit 35a8cedbc2
5 changed files with 40 additions and 57 deletions

View File

@ -20,6 +20,14 @@ namespace dxvk {
*/
struct DxvkComputePipelineShaders {
Rc<DxvkShader> cs;
bool eq(const DxvkComputePipelineShaders& other) const {
return cs == other.cs;
}
size_t hash() const {
return DxvkShader::getHash(cs);
}
};

View File

@ -37,6 +37,22 @@ namespace dxvk {
Rc<DxvkShader> tes;
Rc<DxvkShader> gs;
Rc<DxvkShader> fs;
bool eq(const DxvkGraphicsPipelineShaders& other) const {
return vs == other.vs && tcs == other.tcs
&& tes == other.tes && gs == other.gs
&& fs == other.fs;
}
size_t hash() const {
DxvkHashState state;
state.add(DxvkShader::getHash(vs));
state.add(DxvkShader::getHash(tcs));
state.add(DxvkShader::getHash(tes));
state.add(DxvkShader::getHash(gs));
state.add(DxvkShader::getHash(fs));
return state;
}
};
@ -208,7 +224,7 @@ namespace dxvk {
DxvkGraphicsPipelineShaders shaders);
~DxvkGraphicsPipeline();
/**
* \brief Shaders used by the pipeline
* \returns Shaders used by the pipeline

View File

@ -4,44 +4,6 @@
namespace dxvk {
size_t DxvkPipelineKeyHash::operator () (const DxvkComputePipelineShaders& key) const {
std::hash<DxvkShader*> hash;
return hash(key.cs.ptr());
}
size_t DxvkPipelineKeyHash::operator () (const DxvkGraphicsPipelineShaders& key) const {
DxvkHashState state;
state.add(getShaderHash(key.vs));
state.add(getShaderHash(key.tcs));
state.add(getShaderHash(key.tes));
state.add(getShaderHash(key.gs));
state.add(getShaderHash(key.fs));
return state;
}
size_t DxvkPipelineKeyHash::getShaderHash(const Rc<DxvkShader>& shader) {
return shader != nullptr ? shader->getHash() : 0;
}
bool DxvkPipelineKeyEq::operator () (
const DxvkComputePipelineShaders& a,
const DxvkComputePipelineShaders& b) const {
return a.cs == b.cs;
}
bool DxvkPipelineKeyEq::operator () (
const DxvkGraphicsPipelineShaders& a,
const DxvkGraphicsPipelineShaders& b) const {
return a.vs == b.vs && a.tcs == b.tcs
&& a.tes == b.tes && a.gs == b.gs
&& a.fs == b.fs;
}
DxvkPipelineManager::DxvkPipelineManager(
const DxvkDevice* device,
DxvkRenderPassPool* passManager)

View File

@ -23,19 +23,6 @@ namespace dxvk {
};
struct DxvkPipelineKeyHash {
size_t operator () (const DxvkComputePipelineShaders& key) const;
size_t operator () (const DxvkGraphicsPipelineShaders& key) const;
static size_t getShaderHash(const Rc<DxvkShader>& shader);
};
struct DxvkPipelineKeyEq {
bool operator () (const DxvkComputePipelineShaders& a, const DxvkComputePipelineShaders& b) const;
bool operator () (const DxvkGraphicsPipelineShaders& a, const DxvkGraphicsPipelineShaders& b) const;
};
/**
* \brief Pipeline manager
*
@ -117,14 +104,12 @@ namespace dxvk {
std::unordered_map<
DxvkComputePipelineShaders,
DxvkComputePipeline,
DxvkPipelineKeyHash,
DxvkPipelineKeyEq> m_computePipelines;
DxvkHash, DxvkEq> m_computePipelines;
std::unordered_map<
DxvkGraphicsPipelineShaders,
DxvkGraphicsPipeline,
DxvkPipelineKeyHash,
DxvkPipelineKeyEq> m_graphicsPipelines;
DxvkHash, DxvkEq> m_graphicsPipelines;
};

View File

@ -253,6 +253,18 @@ namespace dxvk {
std::string debugName() const {
return m_key.toString();
}
/**
* \brief Get lookup hash for a shader
*
* Convenience method that returns \c 0 for a null
* pointer, and the shader's lookup hash otherwise.
* \param [in] shader The shader
* \returns The shader's lookup hash, or 0
*/
static size_t getHash(const Rc<DxvkShader>& shader) {
return shader != nullptr ? shader->getHash() : 0;
}
private:
@ -271,7 +283,7 @@ namespace dxvk {
size_t m_o1IdxOffset = 0;
size_t m_o1LocOffset = 0;
};