1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2024-12-13 16:08:50 +01:00

[dxvk] Optimize descriptor set binding further

This commit is contained in:
Philip Rebohle 2022-06-16 15:13:14 +02:00
parent f9e6d8e23a
commit 15cf130369
No known key found for this signature in database
GPG Key ID: C8CC613427A31C99

View File

@ -4161,24 +4161,27 @@ namespace dxvk {
DxvkBindingMask newBindMask = refBindMask; DxvkBindingMask newBindMask = refBindMask;
uint32_t layoutSetMask = layout->getSetMask();
uint32_t dirtySetMask = BindPoint == VK_PIPELINE_BIND_POINT_GRAPHICS uint32_t dirtySetMask = BindPoint == VK_PIPELINE_BIND_POINT_GRAPHICS
? m_descriptorState.getDirtyGraphicsSets() ? m_descriptorState.getDirtyGraphicsSets()
: m_descriptorState.getDirtyComputeSets(); : m_descriptorState.getDirtyComputeSets();
dirtySetMask &= layoutSetMask;
uint32_t bindingIndex = 0; uint32_t firstUpdated = bit::tzcnt(dirtySetMask);
uint32_t firstUpdated = DxvkDescriptorSets::SetCount;
while (dirtySetMask) {
uint32_t setIndex = bit::tzcnt(dirtySetMask);
for (uint32_t i = 0; i < DxvkDescriptorSets::SetCount; i++) {
// Initialize binding mask for the current set, only // Initialize binding mask for the current set, only
// clear bits if certain resources are actually unbound. // clear bits if certain resources are actually unbound.
uint32_t bindingCount = bindings.getBindingCount(i); uint32_t bindingIndex = layout->getFirstBinding(setIndex);
uint32_t bindingCount = bindings.getBindingCount(setIndex);
if ((dirtySetMask & (1u << i)) || !m_descriptorState.getSet<BindPoint>(i)) {
firstUpdated = std::min(firstUpdated, i);
newBindMask.setRange(bindingIndex, bindingCount); newBindMask.setRange(bindingIndex, bindingCount);
for (uint32_t j = 0; j < bindingCount; j++) { for (uint32_t j = 0; j < bindingCount; j++) {
const auto& binding = bindings.getBinding(i, j); const auto& binding = bindings.getBinding(setIndex, j);
switch (binding.descriptorType) { switch (binding.descriptorType) {
case VK_DESCRIPTOR_TYPE_SAMPLER: { case VK_DESCRIPTOR_TYPE_SAMPLER: {
@ -4319,26 +4322,29 @@ namespace dxvk {
} }
// Create and populate descriptor set with the given descriptors // Create and populate descriptor set with the given descriptors
VkDescriptorSet& set = m_descriptorState.getSet<BindPoint>(i); VkDescriptorSet& set = m_descriptorState.getSet<BindPoint>(setIndex);
set = allocateDescriptorSet(layout->getSetLayout(i)); set = allocateDescriptorSet(layout->getSetLayout(setIndex));
if (bindingCount) {
m_cmd->updateDescriptorSetWithTemplate(set, m_cmd->updateDescriptorSetWithTemplate(set,
layout->getSetUpdateTemplate(i), descriptors.data()); layout->getSetUpdateTemplate(setIndex), descriptors.data());
}
dirtySetMask &= dirtySetMask - 1;
} }
bindingIndex += bindingCount; // Bind all descriptor sets that need updating
} uint32_t bindSetMask = layoutSetMask & ~((1u << firstUpdated) - 1);
// Bind all updated descriptor sets while (bindSetMask) {
uint32_t setCount = DxvkDescriptorSets::SetCount - firstUpdated; uint32_t setIndex = bit::tzcnt(bindSetMask);
const VkDescriptorSet* setData = &m_descriptorState.getSet<BindPoint>(firstUpdated);
VkDescriptorSet& set = m_descriptorState.getSet<BindPoint>(setIndex);
m_cmd->cmdBindDescriptorSets(BindPoint, m_cmd->cmdBindDescriptorSets(BindPoint,
layout->getPipelineLayout(), layout->getPipelineLayout(),
firstUpdated, setCount, setData, setIndex, 1, &set, 0, nullptr);
0, nullptr);
bindSetMask &= bindSetMask - 1;
}
// Update pipeline if there are unbound resources // Update pipeline if there are unbound resources
if (refBindMask != newBindMask) { if (refBindMask != newBindMask) {