layers: Add interface to get descriptor type from layout's global index
authorTobin Ehlis <tobine@google.com>
Tue, 26 Apr 2016 19:09:51 +0000 (13:09 -0600)
committerTobin Ehlis <tobine@google.com>
Tue, 26 Apr 2016 21:57:18 +0000 (15:57 -0600)
We match up dynamic descriptor offsets one at a time so added an interface
to get descriptor type from the global index in addition to the original
pBinding index. This allows us to iterate over all of the descriptors in a
set and easily grab their type.

layers/core_validation.cpp
layers/descriptor_sets.h

index 1b6c9fe..8d4a387 100644 (file)
@@ -7001,7 +7001,7 @@ vkCmdBindDescriptorSets(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipel
                             // Validate Dynamic Offset Minimums
                             uint32_t cur_dyn_offset = totalDynamicDescriptors;
                             for (uint32_t d = 0; d < pSet->descriptorCount; d++) {
-                                if (pSet->p_layout->GetTypeFromIndex(d) == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) {
+                                if (pSet->p_layout->GetTypeFromGlobalIndex(d) == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) {
                                     if (vk_safe_modulo(
                                             pDynamicOffsets[cur_dyn_offset],
                                             dev_data->phys_dev_properties.properties.limits.minUniformBufferOffsetAlignment) != 0) {
@@ -7015,7 +7015,7 @@ vkCmdBindDescriptorSets(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipel
                                             dev_data->phys_dev_properties.properties.limits.minUniformBufferOffsetAlignment);
                                     }
                                     cur_dyn_offset++;
-                                } else if (pSet->p_layout->GetTypeFromIndex(d) == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC) {
+                                } else if (pSet->p_layout->GetTypeFromGlobalIndex(d) == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC) {
                                     if (vk_safe_modulo(
                                             pDynamicOffsets[cur_dyn_offset],
                                             dev_data->phys_dev_properties.properties.limits.minStorageBufferOffsetAlignment) != 0) {
index 8911910..7f0fd4f 100644 (file)
@@ -104,6 +104,7 @@ class DescriptorSetLayout {
     uint32_t GetDescriptorCountFromIndex(const uint32_t);
     VkDescriptorType GetTypeFromBinding(const uint32_t);
     VkDescriptorType GetTypeFromIndex(const uint32_t);
+    VkDescriptorType GetTypeFromGlobalIndex(const uint32_t);
     VkShaderStageFlags GetStageFlagsFromBinding(const uint32_t);
     VkSampler const *GetImmutableSamplerPtrFromBinding(const uint32_t);
     // For a particular binding, get the global index
@@ -191,6 +192,17 @@ VkDescriptorType DescriptorSetLayout::GetTypeFromIndex(const uint32_t index) {
     assert(index < bindings_.size());
     return bindings_[index]->descriptorType;
 }
+// For the given global index, return descriptorType
+//  Currently just counting up through bindings_, may improve this in future
+VkDescriptorType DescriptorSetLayout::GetTypeFromGlobalIndex(const uint32_t index) {
+    auto global_offset = 0;
+    for (auto binding : bindings_) {
+        global_offset += binding->descriptorCount;
+        if (index < global_offset)
+            return binding->descriptorType;
+    }
+    assert(0); // requested global index is out of bounds
+}
 // For the given binding, return stageFlags
 VkShaderStageFlags DescriptorSetLayout::GetStageFlagsFromBinding(const uint32_t binding) {
     assert(binding_to_index_map_.count(binding));