1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2025-04-01 09:25:24 +02:00

[dxvk] Introduce DxvkGraphicsPipelineHandle

This commit is contained in:
Philip Rebohle 2025-03-21 23:03:19 +01:00
parent 31529b8bab
commit 12c98161ba
3 changed files with 31 additions and 14 deletions

View File

@ -6048,15 +6048,15 @@ namespace dxvk {
// Retrieve and bind actual Vulkan pipeline handle // Retrieve and bind actual Vulkan pipeline handle
auto pipelineInfo = m_state.gp.pipeline->getPipelineHandle(m_state.gp.state); auto pipelineInfo = m_state.gp.pipeline->getPipelineHandle(m_state.gp.state);
if (unlikely(!pipelineInfo.first)) if (unlikely(!pipelineInfo.handle))
return false; return false;
m_cmd->cmdBindPipeline(DxvkCmdBuffer::ExecBuffer, m_cmd->cmdBindPipeline(DxvkCmdBuffer::ExecBuffer,
VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineInfo.first); VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineInfo.handle);
// For pipelines created from graphics pipeline libraries, we need to // For pipelines created from graphics pipeline libraries, we need to
// apply a bunch of dynamic state that is otherwise static or unused // apply a bunch of dynamic state that is otherwise static or unused
if (pipelineInfo.second == DxvkGraphicsPipelineType::BasePipeline) { if (pipelineInfo.type == DxvkGraphicsPipelineType::BasePipeline) {
m_flags.set( m_flags.set(
DxvkContextFlag::GpDynamicDepthStencilState, DxvkContextFlag::GpDynamicDepthStencilState,
DxvkContextFlag::GpDynamicDepthBias, DxvkContextFlag::GpDynamicDepthBias,

View File

@ -1057,14 +1057,14 @@ namespace dxvk {
} }
std::pair<VkPipeline, DxvkGraphicsPipelineType> DxvkGraphicsPipeline::getPipelineHandle( DxvkGraphicsPipelineHandle DxvkGraphicsPipeline::getPipelineHandle(
const DxvkGraphicsPipelineStateInfo& state) { const DxvkGraphicsPipelineStateInfo& state) {
DxvkGraphicsPipelineInstance* instance = this->findInstance(state); DxvkGraphicsPipelineInstance* instance = this->findInstance(state);
if (unlikely(!instance)) { if (unlikely(!instance)) {
// Exit early if the state vector is invalid // Exit early if the state vector is invalid
if (!this->validatePipelineState(state, true)) if (!this->validatePipelineState(state, true))
return std::make_pair(VK_NULL_HANDLE, DxvkGraphicsPipelineType::FastPipeline); return DxvkGraphicsPipelineHandle();
// Prevent other threads from adding new instances and check again // Prevent other threads from adding new instances and check again
std::unique_lock<dxvk::mutex> lock(m_mutex); std::unique_lock<dxvk::mutex> lock(m_mutex);
@ -1091,14 +1091,7 @@ namespace dxvk {
} }
} }
// Find a pipeline handle to use. If no optimized pipeline has return instance->getHandle();
// been compiled yet, use the slower base pipeline instead.
VkPipeline fastHandle = instance->fastHandle.load();
if (likely(fastHandle != VK_NULL_HANDLE))
return std::make_pair(fastHandle, DxvkGraphicsPipelineType::FastPipeline);
return std::make_pair(instance->baseHandle.load(), DxvkGraphicsPipelineType::BasePipeline);
} }

View File

@ -345,6 +345,15 @@ namespace dxvk {
}; };
/**
* \brief Graphics pipeline handle
*/
struct DxvkGraphicsPipelineHandle {
VkPipeline handle = VK_NULL_HANDLE;
DxvkGraphicsPipelineType type = DxvkGraphicsPipelineType::FastPipeline;
};
/** /**
* \brief Graphics pipeline instance * \brief Graphics pipeline instance
* *
@ -366,6 +375,21 @@ namespace dxvk {
std::atomic<VkPipeline> baseHandle = { VK_NULL_HANDLE }; std::atomic<VkPipeline> baseHandle = { VK_NULL_HANDLE };
std::atomic<VkPipeline> fastHandle = { VK_NULL_HANDLE }; std::atomic<VkPipeline> fastHandle = { VK_NULL_HANDLE };
std::atomic<VkBool32> isCompiling = { VK_FALSE }; std::atomic<VkBool32> isCompiling = { VK_FALSE };
DxvkGraphicsPipelineHandle getHandle() const {
// Find a pipeline handle to use. If no optimized pipeline has
// been compiled yet, use the slower base pipeline instead.
DxvkGraphicsPipelineHandle result;
result.handle = fastHandle.load(std::memory_order_acquire);
result.type = DxvkGraphicsPipelineType::FastPipeline;
if (likely(fastHandle))
return result;
result.handle = baseHandle.load(std::memory_order_acquire);
result.type = DxvkGraphicsPipelineType::BasePipeline;
return result;
}
}; };
@ -529,7 +553,7 @@ namespace dxvk {
* \param [in] state Pipeline state vector * \param [in] state Pipeline state vector
* \returns Pipeline handle and handle type * \returns Pipeline handle and handle type
*/ */
std::pair<VkPipeline, DxvkGraphicsPipelineType> getPipelineHandle( DxvkGraphicsPipelineHandle getPipelineHandle(
const DxvkGraphicsPipelineStateInfo& state); const DxvkGraphicsPipelineStateInfo& state);
/** /**