Skip to content

Commit 52a8bf6

Browse files
updated bindless logic
1 parent 6dec311 commit 52a8bf6

3 files changed

Lines changed: 38 additions & 15 deletions

File tree

ZEngine/ZEngine/Hardwares/VulkanDevice.cpp

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,18 @@ namespace ZEngine::Hardwares
207207
PhysicalDeviceProperties = physical_device_properties;
208208
PhysicalDeviceDescriptorIndexingProperties = indexing_properties;
209209
PhysicalDeviceFeature = physical_device_feature;
210-
PhysicalDeviceSupportDescriptorUpdateAfterBind = (descriptor_indexing_features.descriptorBindingSampledImageUpdateAfterBind == VK_TRUE && descriptor_indexing_features.descriptorBindingPartiallyBound == VK_TRUE && descriptor_indexing_features.descriptorBindingUpdateUnusedWhilePending == VK_TRUE);
210+
PhysicalDeviceSupportSampledImageBindless = (
211+
descriptor_indexing_features.runtimeDescriptorArray == VK_TRUE &&
212+
descriptor_indexing_features.descriptorBindingSampledImageUpdateAfterBind == VK_TRUE &&
213+
descriptor_indexing_features.descriptorBindingPartiallyBound == VK_TRUE &&
214+
descriptor_indexing_features.descriptorBindingUpdateUnusedWhilePending == VK_TRUE &&
215+
descriptor_indexing_features.descriptorIndexing == VK_TRUE
216+
);
217+
PhysicalDeviceSupportStorageBufferBindless = (
218+
descriptor_indexing_features.runtimeDescriptorArray == VK_TRUE &&
219+
descriptor_indexing_features.descriptorBindingPartiallyBound == VK_TRUE &&
220+
descriptor_indexing_features.descriptorIndexing == VK_TRUE
221+
);
211222
vkGetPhysicalDeviceMemoryProperties(PhysicalDevice, &PhysicalDeviceMemoryProperties);
212223
break;
213224
}
@@ -312,13 +323,19 @@ namespace ZEngine::Hardwares
312323
device_features_2.features.multiDrawIndirect = PhysicalDeviceFeature.features.multiDrawIndirect;
313324
device_features_2.features.samplerAnisotropy = PhysicalDeviceFeature.features.samplerAnisotropy;
314325
device_features_2.features.shaderInt64 = PhysicalDeviceFeature.features.shaderInt64;
315-
if (PhysicalDeviceSupportDescriptorUpdateAfterBind)
326+
327+
if (PhysicalDeviceSupportSampledImageBindless || PhysicalDeviceSupportStorageBufferBindless)
316328
{
317-
physical_device_descriptor_indexing_features.shaderSampledImageArrayNonUniformIndexing = VK_TRUE;
318-
physical_device_descriptor_indexing_features.descriptorBindingSampledImageUpdateAfterBind = VK_TRUE;
319-
physical_device_descriptor_indexing_features.descriptorBindingUpdateUnusedWhilePending = VK_TRUE;
329+
if (PhysicalDeviceSupportSampledImageBindless)
330+
{
331+
physical_device_descriptor_indexing_features.descriptorBindingUpdateUnusedWhilePending = VK_TRUE;
332+
physical_device_descriptor_indexing_features.shaderSampledImageArrayNonUniformIndexing = VK_TRUE;
333+
physical_device_descriptor_indexing_features.descriptorBindingSampledImageUpdateAfterBind = VK_TRUE;
334+
}
335+
320336
physical_device_descriptor_indexing_features.descriptorBindingPartiallyBound = VK_TRUE;
321337
physical_device_descriptor_indexing_features.runtimeDescriptorArray = VK_TRUE;
338+
physical_device_descriptor_indexing_features.descriptorIndexing = VK_TRUE;
322339

323340
device_features_2.pNext = &physical_device_descriptor_indexing_features;
324341
}

ZEngine/ZEngine/Hardwares/VulkanDevice.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,8 @@ namespace ZEngine::Hardwares
535535
struct VulkanDevice
536536
{
537537
bool HasSeperateTransfertQueueFamily = false;
538-
bool PhysicalDeviceSupportDescriptorUpdateAfterBind = false;
538+
bool PhysicalDeviceSupportSampledImageBindless = false;
539+
bool PhysicalDeviceSupportStorageBufferBindless = false;
539540
const char* ApplicationName = "Tetragrama";
540541
const char* EngineName = "ZEngine";
541542
uint32_t SwapchainImageCount = 3;

ZEngine/ZEngine/Rendering/Shaders/Shader.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ namespace ZEngine::Rendering::Shaders
220220
* Unsized arrays require descriptor update-after-bind support
221221
* If device doesn't support it, we fall back to a reasonable maximum
222222
*/
223-
if (m_device->PhysicalDeviceSupportDescriptorUpdateAfterBind)
223+
if (m_device->PhysicalDeviceSupportSampledImageBindless)
224224
{
225225
count = m_device->PhysicalDeviceDescriptorIndexingProperties.maxPerStageDescriptorUpdateAfterBindSamplers - 1;
226226
}
@@ -319,14 +319,15 @@ namespace ZEngine::Rendering::Shaders
319319
binding_flags_collection.init(&LocalArena, layout_binding_collection.size(), layout_binding_collection.size());
320320
for (uint32_t i = 0; i < layout_binding_collection.size(); ++i)
321321
{
322-
if (m_device->PhysicalDeviceSupportDescriptorUpdateAfterBind)
322+
if (m_device->PhysicalDeviceSupportSampledImageBindless
323+
&& ((layout_binding_collection[i].descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER) || (layout_binding_collection[i].descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE)))
323324
{
324-
if ((layout_binding_collection[i].descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER) || (layout_binding_collection[i].descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE))
325-
{
326325
binding_flags_collection[i] = VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT | VK_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT | VK_DESCRIPTOR_BINDING_UPDATE_UNUSED_WHILE_PENDING_BIT;
327326
continue;
328-
}
329-
binding_flags_collection[i] = VK_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT | VK_DESCRIPTOR_BINDING_UPDATE_UNUSED_WHILE_PENDING_BIT;
327+
}
328+
else if (m_device->PhysicalDeviceSupportStorageBufferBindless && (layout_binding_collection[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER))
329+
{
330+
binding_flags_collection[i] = VK_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT;
330331
}
331332
else
332333
{
@@ -346,8 +347,12 @@ namespace ZEngine::Rendering::Shaders
346347
descriptor_set_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
347348
descriptor_set_layout_create_info.bindingCount = layout_binding_collection.size();
348349
descriptor_set_layout_create_info.pBindings = layout_binding_collection.data();
349-
descriptor_set_layout_create_info.flags = m_device->PhysicalDeviceSupportDescriptorUpdateAfterBind ? VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT : 0;
350-
descriptor_set_layout_create_info.pNext = &binding_flags_create_info;
350+
351+
if (m_device->PhysicalDeviceSupportSampledImageBindless)
352+
{
353+
descriptor_set_layout_create_info.flags = VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT;
354+
descriptor_set_layout_create_info.pNext = &binding_flags_create_info;
355+
}
351356

352357
VkDescriptorSetLayout descriptor_set_layout = VK_NULL_HANDLE;
353358
ZENGINE_VALIDATE_ASSERT(vkCreateDescriptorSetLayout(m_device->LogicalDevice, &descriptor_set_layout_create_info, nullptr, &descriptor_set_layout) == VK_SUCCESS, "Failed to create DescriptorSetLayout")
@@ -386,7 +391,7 @@ namespace ZEngine::Rendering::Shaders
386391

387392
VkDescriptorPoolCreateInfo pool_info = {};
388393
pool_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
389-
pool_info.flags = m_device->PhysicalDeviceSupportDescriptorUpdateAfterBind ? VK_DESCRIPTOR_POOL_CREATE_UPDATE_AFTER_BIND_BIT : 0;
394+
pool_info.flags = m_device->PhysicalDeviceSupportSampledImageBindless ? VK_DESCRIPTOR_POOL_CREATE_UPDATE_AFTER_BIND_BIT : 0;
390395
pool_info.maxSets = m_device->SwapchainImageCount * pool_size_collection.size() * m_specification.OverloadMaxSet;
391396
pool_info.poolSizeCount = pool_size_collection.size();
392397
pool_info.pPoolSizes = pool_size_collection.data();

0 commit comments

Comments
 (0)