1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2025-01-31 14:52:11 +01:00

[dxvk] Introduce DxvkComputePipelineInstance

Same as the graphics pipeline equivalent.
This commit is contained in:
Philip Rebohle 2019-07-30 11:07:07 +02:00
parent 20b0cbdfb6
commit 3dc33c64a9
No known key found for this signature in database
GPG Key ID: C8CC613427A31C99
2 changed files with 60 additions and 23 deletions

View File

@ -37,7 +37,7 @@ namespace dxvk {
DxvkComputePipeline::~DxvkComputePipeline() {
for (const auto& instance : m_pipelines)
this->destroyPipeline(instance.pipeline);
this->destroyPipeline(instance.pipeline());
}
@ -47,15 +47,17 @@ namespace dxvk {
{ std::lock_guard<sync::Spinlock> lock(m_mutex);
if (this->findPipeline(state, newPipelineHandle))
return newPipelineHandle;
auto instance = this->findInstance(state);
if (instance)
return instance->pipeline();
// If no pipeline instance exists with the given state
// vector, create a new one and add it to the list.
newPipelineHandle = this->createPipeline(state);
// Add new pipeline to the set
m_pipelines.push_back({ state, newPipelineHandle });
m_pipelines.emplace_back(state, newPipelineHandle);
m_pipeMgr->m_numComputePipelines += 1;
}
@ -66,17 +68,14 @@ namespace dxvk {
}
bool DxvkComputePipeline::findPipeline(
const DxvkComputePipelineStateInfo& state,
VkPipeline& pipeline) const {
for (const PipelineStruct& pair : m_pipelines) {
if (pair.stateVector == state) {
pipeline = pair.pipeline;
return true;
}
const DxvkComputePipelineInstance* DxvkComputePipeline::findInstance(
const DxvkComputePipelineStateInfo& state) const {
for (const auto& instance : m_pipelines) {
if (instance.isCompatible(state))
return &instance;
}
return false;
return nullptr;
}

View File

@ -32,6 +32,50 @@ namespace dxvk {
DxvkBindingMask bsBindingMask;
};
/**
* \brief Compute pipeline instance
*/
class DxvkComputePipelineInstance {
public:
DxvkComputePipelineInstance()
: m_stateVector (),
m_pipeline (VK_NULL_HANDLE) { }
DxvkComputePipelineInstance(
const DxvkComputePipelineStateInfo& state,
VkPipeline pipe)
: m_stateVector (state),
m_pipeline (pipe) { }
/**
* \brief Checks for matching pipeline state
*
* \param [in] stateVector Graphics pipeline state
* \param [in] renderPass Render pass handle
* \returns \c true if the specialization is compatible
*/
bool isCompatible(const DxvkComputePipelineStateInfo& state) const {
return m_stateVector == state;
}
/**
* \brief Retrieves pipeline
* \returns The pipeline handle
*/
VkPipeline pipeline() const {
return m_pipeline;
}
private:
DxvkComputePipelineStateInfo m_stateVector;
VkPipeline m_pipeline;
};
/**
@ -75,11 +119,6 @@ namespace dxvk {
private:
struct PipelineStruct {
DxvkComputePipelineStateInfo stateVector;
VkPipeline pipeline;
};
Rc<vk::DeviceFn> m_vkd;
DxvkPipelineManager* m_pipeMgr;
@ -88,12 +127,11 @@ namespace dxvk {
Rc<DxvkPipelineLayout> m_layout;
sync::Spinlock m_mutex;
std::vector<PipelineStruct> m_pipelines;
sync::Spinlock m_mutex;
std::vector<DxvkComputePipelineInstance> m_pipelines;
bool findPipeline(
const DxvkComputePipelineStateInfo& state,
VkPipeline& pipeline) const;
const DxvkComputePipelineInstance* findInstance(
const DxvkComputePipelineStateInfo& state) const;
VkPipeline createPipeline(
const DxvkComputePipelineStateInfo& state) const;