@@ -1249,42 +1249,51 @@ class CVulkanLogicalDevice final : public ILogicalDevice
1249
1249
uint32_t bindingCount = std::distance (_begin, _end);
1250
1250
assert (bindingCount <= MAX_BINDING_COUNT);
1251
1251
1252
- uint32_t samplerOffset = 0u ;
1253
- VkSampler vk_samplers[MAX_SAMPLER_COUNT_PER_BINDING * MAX_BINDING_COUNT];
1254
- VkDescriptorSetLayoutBinding vk_dsLayoutBindings[MAX_BINDING_COUNT];
1252
+ std::vector<VkSampler> vk_samplers;
1253
+ std::vector<VkDescriptorSetLayoutBinding> vk_dsLayoutBindings;
1255
1254
1256
1255
for (uint32_t b = 0u ; b < bindingCount; ++b)
1257
1256
{
1258
1257
auto binding = _begin + b;
1259
1258
1260
- vk_dsLayoutBindings[b].binding = binding->binding ;
1261
- vk_dsLayoutBindings[b].descriptorType = static_cast <VkDescriptorType>(binding->type );
1262
- vk_dsLayoutBindings[b].descriptorCount = binding->count ;
1263
- vk_dsLayoutBindings[b].stageFlags = static_cast <VkShaderStageFlags>(binding->stageFlags );
1264
- vk_dsLayoutBindings[b].pImmutableSamplers = nullptr ;
1259
+ VkDescriptorSetLayoutBinding vkDescSetLayoutBinding = {};
1260
+ vkDescSetLayoutBinding.binding = binding->binding ;
1261
+ vkDescSetLayoutBinding.descriptorType = static_cast <VkDescriptorType>(binding->type );
1262
+ vkDescSetLayoutBinding.descriptorCount = binding->count ;
1263
+ vkDescSetLayoutBinding.stageFlags = static_cast <VkShaderStageFlags>(binding->stageFlags );
1264
+ vkDescSetLayoutBinding.pImmutableSamplers = nullptr ;
1265
1265
1266
- if (binding->samplers )
1266
+ if (binding->samplers && binding-> count > 0u )
1267
1267
{
1268
+ // If descriptorType is VK_DESCRIPTOR_TYPE_SAMPLER or VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, and descriptorCount is not 0 and pImmutableSamplers is not NULL:
1269
+ // pImmutableSamplers must be a valid pointer to an array of descriptorCount valid VkSampler handles.
1270
+
1268
1271
assert (binding->count <= MAX_SAMPLER_COUNT_PER_BINDING);
1272
+ const uint32_t samplerOffset = vk_samplers.size ();
1269
1273
1270
1274
for (uint32_t i = 0u ; i < binding->count ; ++i)
1271
1275
{
1272
- if (binding->samplers [i]->getAPIType () != EAT_VULKAN)
1276
+ if (binding->samplers [i]->getAPIType () != EAT_VULKAN) {
1277
+ assert (false );
1278
+ vk_samplers.push_back (VK_NULL_HANDLE); // To get validation errors on Release Builds
1273
1279
continue ;
1280
+ }
1274
1281
1275
- vk_samplers[samplerOffset + i] = static_cast <const CVulkanSampler*>(binding->samplers [i].get ())->getInternalObject ();
1282
+ VkSampler vkSampler = static_cast <const CVulkanSampler*>(binding->samplers [i].get ())->getInternalObject ();
1283
+ vk_samplers.push_back (vkSampler);
1276
1284
}
1277
1285
1278
- vk_dsLayoutBindings[b].pImmutableSamplers = vk_samplers + samplerOffset;
1279
- samplerOffset += binding->count ;
1286
+ vkDescSetLayoutBinding.pImmutableSamplers = vk_samplers.data () + samplerOffset;
1280
1287
}
1288
+
1289
+ vk_dsLayoutBindings.push_back (vkDescSetLayoutBinding);
1281
1290
}
1282
1291
1283
1292
VkDescriptorSetLayoutCreateInfo vk_createInfo = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO };
1284
1293
vk_createInfo.pNext = nullptr ; // Each pNext member of any structure (including this one) in the pNext chain must be either NULL or a pointer to a valid instance of VkDescriptorSetLayoutBindingFlagsCreateInfo or VkMutableDescriptorTypeCreateInfoVALVE
1285
1294
vk_createInfo.flags = 0 ; // Todo(achal): I would need to create a IDescriptorSetLayout::SCreationParams for this
1286
- vk_createInfo.bindingCount = bindingCount ;
1287
- vk_createInfo.pBindings = vk_dsLayoutBindings;
1295
+ vk_createInfo.bindingCount = vk_dsLayoutBindings. size () ;
1296
+ vk_createInfo.pBindings = vk_dsLayoutBindings. data () ;
1288
1297
1289
1298
VkDescriptorSetLayout vk_dsLayout;
1290
1299
if (m_devf.vk .vkCreateDescriptorSetLayout (m_vkdev, &vk_createInfo, nullptr , &vk_dsLayout) == VK_SUCCESS)
0 commit comments