mirror of
https://github.com/doitsujin/dxvk.git
synced 2025-03-14 04:29:15 +01:00
[dxvk] Simplified state-based pipeline lookup
This commit is contained in:
parent
9c90c1ac00
commit
ed642a57a7
@ -22,17 +22,13 @@ namespace dxvk {
|
||||
}
|
||||
|
||||
|
||||
size_t DxvkGraphicsPipelineStateHash::operator () (
|
||||
const DxvkGraphicsPipelineStateInfo& state) const {
|
||||
// TODO implement hash
|
||||
return 0;
|
||||
bool DxvkGraphicsPipelineStateInfo::operator == (const DxvkGraphicsPipelineStateInfo& other) const {
|
||||
return std::memcmp(this, &other, sizeof(DxvkGraphicsPipelineStateInfo)) == 0;
|
||||
}
|
||||
|
||||
|
||||
size_t DxvkGraphicsPipelineStateEq::operator () (
|
||||
const DxvkGraphicsPipelineStateInfo& a,
|
||||
const DxvkGraphicsPipelineStateInfo& b) const {
|
||||
return std::memcmp(&a, &b, sizeof(DxvkGraphicsPipelineStateInfo)) == 0;
|
||||
bool DxvkGraphicsPipelineStateInfo::operator != (const DxvkGraphicsPipelineStateInfo& other) const {
|
||||
return std::memcmp(this, &other, sizeof(DxvkGraphicsPipelineStateInfo)) != 0;
|
||||
}
|
||||
|
||||
|
||||
@ -72,12 +68,13 @@ namespace dxvk {
|
||||
const DxvkGraphicsPipelineStateInfo& state) {
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
|
||||
auto pair = m_pipelines.find(state);
|
||||
if (pair != m_pipelines.end())
|
||||
return pair->second;
|
||||
for (const PipelineStruct& pair : m_pipelines) {
|
||||
if (pair.stateVector == state)
|
||||
return pair.pipeline;
|
||||
}
|
||||
|
||||
VkPipeline pipeline = this->compilePipeline(state);
|
||||
m_pipelines.insert(std::make_pair(state, pipeline));
|
||||
m_pipelines.push_back({ state, pipeline });
|
||||
return pipeline;
|
||||
}
|
||||
|
||||
@ -227,10 +224,8 @@ namespace dxvk {
|
||||
|
||||
|
||||
void DxvkGraphicsPipeline::destroyPipelines() {
|
||||
for (const auto& pair : m_pipelines) {
|
||||
m_vkd->vkDestroyPipeline(
|
||||
m_vkd->device(), pair.second, nullptr);
|
||||
}
|
||||
for (const PipelineStruct& pair : m_pipelines)
|
||||
m_vkd->vkDestroyPipeline(m_vkd->device(), pair.pipeline, nullptr);
|
||||
}
|
||||
|
||||
}
|
@ -28,6 +28,9 @@ namespace dxvk {
|
||||
DxvkGraphicsPipelineStateInfo& operator = (
|
||||
const DxvkGraphicsPipelineStateInfo& other);
|
||||
|
||||
bool operator == (const DxvkGraphicsPipelineStateInfo& other) const;
|
||||
bool operator != (const DxvkGraphicsPipelineStateInfo& other) const;
|
||||
|
||||
DxvkBindingState bsBindingState;
|
||||
|
||||
VkPrimitiveTopology iaPrimitiveTopology;
|
||||
@ -73,18 +76,6 @@ namespace dxvk {
|
||||
};
|
||||
|
||||
|
||||
struct DxvkGraphicsPipelineStateHash {
|
||||
size_t operator () (const DxvkGraphicsPipelineStateInfo& state) const;
|
||||
};
|
||||
|
||||
|
||||
struct DxvkGraphicsPipelineStateEq {
|
||||
size_t operator () (
|
||||
const DxvkGraphicsPipelineStateInfo& a,
|
||||
const DxvkGraphicsPipelineStateInfo& b) const;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* \brief Graphics pipeline
|
||||
*
|
||||
@ -126,6 +117,11 @@ namespace dxvk {
|
||||
|
||||
private:
|
||||
|
||||
struct PipelineStruct {
|
||||
DxvkGraphicsPipelineStateInfo stateVector;
|
||||
VkPipeline pipeline;
|
||||
};
|
||||
|
||||
Rc<vk::DeviceFn> m_vkd;
|
||||
Rc<DxvkBindingLayout> m_layout;
|
||||
|
||||
@ -135,13 +131,8 @@ namespace dxvk {
|
||||
Rc<DxvkShaderModule> m_gs;
|
||||
Rc<DxvkShaderModule> m_fs;
|
||||
|
||||
std::mutex m_mutex;
|
||||
|
||||
std::unordered_map<
|
||||
DxvkGraphicsPipelineStateInfo,
|
||||
VkPipeline,
|
||||
DxvkGraphicsPipelineStateHash,
|
||||
DxvkGraphicsPipelineStateEq> m_pipelines;
|
||||
std::mutex m_mutex;
|
||||
std::vector<PipelineStruct> m_pipelines;
|
||||
|
||||
VkPipeline compilePipeline(
|
||||
const DxvkGraphicsPipelineStateInfo& state) const;
|
||||
|
Loading…
x
Reference in New Issue
Block a user