From d6253aeae6a413028f69ed7ad01c6ac977c65a6e Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Tue, 9 Aug 2022 02:39:21 +0200 Subject: [PATCH] [dxvk] Order descriptors by type and binding Reduces the number of unique descriptor set layouts further, which may help with descriptor pool usage, and also makes branching more predictable for the CPU. --- src/dxvk/dxvk_pipelayout.cpp | 27 +++++++-------------------- src/dxvk/dxvk_pipelayout.h | 20 ++++---------------- 2 files changed, 11 insertions(+), 36 deletions(-) diff --git a/src/dxvk/dxvk_pipelayout.cpp b/src/dxvk/dxvk_pipelayout.cpp index e112ea78..ff3b097e 100644 --- a/src/dxvk/dxvk_pipelayout.cpp +++ b/src/dxvk/dxvk_pipelayout.cpp @@ -25,19 +25,8 @@ namespace dxvk { } - bool DxvkBindingInfo::canMerge(const DxvkBindingInfo& binding) const { - if ((stages & VK_SHADER_STAGE_FRAGMENT_BIT) != (binding.stages & VK_SHADER_STAGE_FRAGMENT_BIT)) - return false; - - return descriptorType == binding.descriptorType - && resourceBinding == binding.resourceBinding - && viewType == binding.viewType; - } - - - void DxvkBindingInfo::merge(const DxvkBindingInfo& binding) { - stages |= binding.stages; - access |= binding.access; + uint32_t DxvkBindingInfo::value() const { + return (uint32_t(descriptorType) << 24) | resourceBinding; } @@ -72,14 +61,12 @@ namespace dxvk { void DxvkBindingList::addBinding(const DxvkBindingInfo& binding) { - for (auto& b : m_bindings) { - if (b.canMerge(binding)) { - b.merge(binding); - return; - } - } + auto iter = m_bindings.begin(); - m_bindings.push_back(binding); + while (iter != m_bindings.end() && iter->value() <= binding.value()) + iter++; + + m_bindings.insert(iter, binding); } diff --git a/src/dxvk/dxvk_pipelayout.h b/src/dxvk/dxvk_pipelayout.h index 1e8aa121..f559e6c0 100644 --- a/src/dxvk/dxvk_pipelayout.h +++ b/src/dxvk/dxvk_pipelayout.h @@ -43,24 +43,12 @@ namespace dxvk { uint32_t computeSetIndex() const; /** - * \brief Checks whether bindings can be merged + * \brief Numeric value of the binding * - * Bindings can be merged if they access the same resource with - * the same view and descriptor type and are part of the same - * descriptor set. - * \param [in] binding The binding to probe - * \returns \c true if the bindings can be merged + * Used when sorting bindings. + * \returns Numeric value */ - bool canMerge(const DxvkBindingInfo& binding) const; - - /** - * \brief Merges bindings - * - * Merges the stage and access flags of two - * otherwise identical binding declarations. - * \param [in] binding The binding to merge - */ - void merge(const DxvkBindingInfo& binding); + uint32_t value() const; /** * \brief Checks for equality