From 038ee0416d340b949163ec2f140c3f98b32e203a Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Wed, 15 Jun 2022 15:58:16 +0200 Subject: [PATCH] [dxvk] Add setRange method to DxvkBindingSet --- src/dxvk/dxvk_bind_mask.h | 29 ++++++++++++++++++++++++----- src/dxvk/dxvk_context.cpp | 3 ++- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/dxvk/dxvk_bind_mask.h b/src/dxvk/dxvk_bind_mask.h index b45b9b66..219a7016 100644 --- a/src/dxvk/dxvk_bind_mask.h +++ b/src/dxvk/dxvk_bind_mask.h @@ -88,12 +88,31 @@ namespace dxvk { /** * \brief Enables multiple bindings - * \param [in] n Number of bindings + * + * Leaves bindings outside of this range unaffected. + * \param [in] first First binding to enable + * \param [in] count Number of bindings to enable */ - void setFirst(uint32_t n) { - for (uint32_t i = 0; i < IntCount; i++) { - m_slots[i] = n >= BitCount ? ~0u : ~(~0u << n); - n = n >= BitCount ? n - BitCount : 0; + void setRange(uint32_t first, uint32_t count) { + if (!count) + return; + + uint32_t firstInt = first / BitCount; + uint32_t firstBit = first % BitCount; + + uint32_t lastInt = (first + count - 1) / BitCount; + uint32_t lastBit = (first + count - 1) % BitCount + 1; + + if (firstInt == lastInt) { + m_slots[firstInt] |= (count < BitCount) + ? ((1u << count) - 1) << firstBit + : ~0u; + } else { + m_slots[firstInt] |= ~0u << firstBit; + m_slots[lastInt] |= ~0u >> (BitCount - lastBit); + + for (uint32_t i = firstInt + 1; i < lastInt; i++) + m_slots[i] = ~0u; } } diff --git a/src/dxvk/dxvk_context.cpp b/src/dxvk/dxvk_context.cpp index 2d78c907..b4091d8c 100644 --- a/src/dxvk/dxvk_context.cpp +++ b/src/dxvk/dxvk_context.cpp @@ -4187,7 +4187,8 @@ namespace dxvk { // Assume that all bindings are active as a fast path DxvkBindingMask bindMask; - bindMask.setFirst(layout->bindingCount()); + bindMask.clear(); + bindMask.setRange(0, layout->bindingCount()); for (uint32_t i = 0; i < layout->bindingCount(); i++) { const auto& binding = layout->binding(i);