1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2024-12-14 18:23:52 +01:00

[dxvk] Use native integer size for DxvkBindingSet

May make things a tad faster in 64-bit applications.
This commit is contained in:
Philip Rebohle 2022-06-15 16:37:29 +02:00
parent 16eba45987
commit 955e0cca62
No known key found for this signature in database
GPG Key ID: C8CC613427A31C99

View File

@ -1,5 +1,7 @@
#pragma once #pragma once
#include <type_traits>
#include "dxvk_buffer.h" #include "dxvk_buffer.h"
#include "dxvk_descriptor.h" #include "dxvk_descriptor.h"
#include "dxvk_image.h" #include "dxvk_image.h"
@ -18,7 +20,12 @@ namespace dxvk {
*/ */
template<uint32_t BindingCount> template<uint32_t BindingCount>
class DxvkBindingSet { class DxvkBindingSet {
constexpr static uint32_t BitCount = 32; using MaskType = std::conditional_t<(BindingCount > 32), uintptr_t, uint32_t>;
constexpr static MaskType SetBit = MaskType(1u);
constexpr static MaskType SetMask = ~MaskType(0u);
constexpr static uint32_t BitCount = 8 * sizeof(MaskType);
constexpr static uint32_t IntCount = (BindingCount + BitCount - 1) / BitCount; constexpr static uint32_t IntCount = (BindingCount + BitCount - 1) / BitCount;
public: public:
@ -29,9 +36,9 @@ namespace dxvk {
* \returns \c true if the binding is active * \returns \c true if the binding is active
*/ */
bool test(uint32_t slot) const { bool test(uint32_t slot) const {
const uint32_t intId = slot / BitCount; const uint32_t intId = computeIntId(slot);
const uint32_t bitId = slot % BitCount; const uint32_t bitId = computeBitId(slot);
const uint32_t bitMask = 1u << bitId; const MaskType bitMask = SetBit << bitId;
return (m_slots[intId] & bitMask) != 0; return (m_slots[intId] & bitMask) != 0;
} }
@ -43,12 +50,12 @@ namespace dxvk {
* \returns \c true if the state has changed * \returns \c true if the state has changed
*/ */
bool set(uint32_t slot, bool value) { bool set(uint32_t slot, bool value) {
const uint32_t intId = slot / BitCount; const uint32_t intId = computeIntId(slot);
const uint32_t bitId = slot % BitCount; const uint32_t bitId = computeBitId(slot);
const uint32_t bitMask = 1u << bitId; const MaskType bitMask = SetBit << bitId;
const uint32_t prev = m_slots[intId]; const MaskType prev = m_slots[intId];
const uint32_t next = value const MaskType next = value
? prev | bitMask ? prev | bitMask
: prev & ~bitMask; : prev & ~bitMask;
m_slots[intId] = next; m_slots[intId] = next;
@ -97,22 +104,22 @@ namespace dxvk {
if (!count) if (!count)
return; return;
uint32_t firstInt = first / BitCount; uint32_t firstInt = computeIntId(first);
uint32_t firstBit = first % BitCount; uint32_t firstBit = computeBitId(first);
uint32_t lastInt = (first + count - 1) / BitCount; uint32_t lastInt = computeIntId(first + count - 1);
uint32_t lastBit = (first + count - 1) % BitCount + 1; uint32_t lastBit = computeBitId(first + count - 1) + 1;
if (firstInt == lastInt) { if (firstInt == lastInt) {
m_slots[firstInt] |= (count < BitCount) m_slots[firstInt] |= (count < BitCount)
? ((1u << count) - 1) << firstBit ? ((SetBit << count) - 1) << firstBit
: ~0u; : (SetMask);
} else { } else {
m_slots[firstInt] |= ~0u << firstBit; m_slots[firstInt] |= SetMask << firstBit;
m_slots[lastInt] |= ~0u >> (BitCount - lastBit); m_slots[lastInt] |= SetMask >> (BitCount - lastBit);
for (uint32_t i = firstInt + 1; i < lastInt; i++) for (uint32_t i = firstInt + 1; i < lastInt; i++)
m_slots[i] = ~0u; m_slots[i] = SetMask;
} }
} }
@ -126,10 +133,10 @@ namespace dxvk {
if (unlikely(first >= BindingCount)) if (unlikely(first >= BindingCount))
return -1; return -1;
uint32_t intId = first / BitCount; uint32_t intId = computeIntId(first);
uint32_t bitId = first % BitCount; uint32_t bitId = computeBitId(first);
auto mask = m_slots[intId] & ~((1 << bitId) - 1); MaskType mask = m_slots[intId] & ~((SetBit << bitId) - 1);
while (!mask && ++intId < IntCount) while (!mask && ++intId < IntCount)
mask = m_slots[intId]; mask = m_slots[intId];
@ -153,7 +160,21 @@ namespace dxvk {
private: private:
uint32_t m_slots[IntCount]; MaskType m_slots[IntCount];
static uint32_t computeIntId(uint32_t slot) {
if constexpr (IntCount > 1)
return slot / BitCount;
else
return 0;
}
static uint32_t computeBitId(uint32_t slot) {
if constexpr (IntCount > 1)
return slot % BitCount;
else
return slot;
}
}; };