@@ -138,7 +138,11 @@ namespace nbl::video
138
138
};
139
139
140
140
141
- if (featuresToEnable.debugUtils )
141
+ if (featuresToEnable.synchronizationValidation /* || other flags taht require VK_EXT_VALIDATION_FEATURES_EXTENSION_NAME */ )
142
+ {
143
+ insertToFeatureSetIfAvailable (VK_EXT_VALIDATION_FEATURES_EXTENSION_NAME, " synchronizationValidation" );
144
+ }
145
+ if (featuresToEnable.debugUtils )
142
146
{
143
147
insertToFeatureSetIfAvailable (VK_EXT_DEBUG_UTILS_EXTENSION_NAME, " debugUtils" );
144
148
}
@@ -161,6 +165,31 @@ namespace nbl::video
161
165
if (!allRequestedFeaturesSupported)
162
166
return nullptr ;
163
167
168
+
169
+ VkBaseInStructure* structsTail = nullptr ;
170
+ VkBaseInStructure* structsHead = nullptr ;
171
+ // Vulkan has problems with having features in the feature chain that have all values set to false.
172
+ // For example having an empty "RayTracingPipelineFeaturesKHR" in the chain will lead to validation errors for RayQueryONLY applications.
173
+ auto addStructToChain = [&structsHead, &structsTail](void * feature) -> void
174
+ {
175
+ VkBaseInStructure* toAdd = reinterpret_cast <VkBaseInStructure*>(feature);
176
+
177
+ // For protecting against duplication of feature structures that may be requested to add to chain twice due to extension requirements
178
+ const bool alreadyAdded = (toAdd->pNext != nullptr || toAdd == structsTail);
179
+
180
+ if (structsHead == nullptr )
181
+ {
182
+ structsHead = toAdd;
183
+ structsTail = toAdd;
184
+ }
185
+ else if (!alreadyAdded)
186
+ {
187
+ structsTail->pNext = toAdd;
188
+ structsTail = toAdd;
189
+ }
190
+ };
191
+
192
+
164
193
std::unique_ptr<CVulkanDebugCallback> debugCallback = nullptr ;
165
194
VkDebugUtilsMessengerCreateInfoEXT debugMessengerCreateInfo = { VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT };
166
195
if (logger && enabledFeatures.debugUtils )
@@ -175,6 +204,21 @@ namespace nbl::video
175
204
debugMessengerCreateInfo.messageType = debugCallbackFlags.second ;
176
205
debugMessengerCreateInfo.pfnUserCallback = CVulkanDebugCallback::defaultCallback;
177
206
debugMessengerCreateInfo.pUserData = debugCallback.get ();
207
+
208
+ addStructToChain (&debugMessengerCreateInfo);
209
+ }
210
+
211
+ VkValidationFeaturesEXT validationFeaturesEXT = { VK_STRUCTURE_TYPE_VALIDATION_FEATURES_EXT };
212
+ VkValidationFeatureEnableEXT validationsEnable[16u ] = {};
213
+ VkValidationFeatureDisableEXT validationsDisable[16u ] = {};
214
+ validationFeaturesEXT.pEnabledValidationFeatures = validationsEnable;
215
+
216
+ // TODO: Do the samefor other validation features as well(?)
217
+ if (enabledFeatures.synchronizationValidation )
218
+ {
219
+ validationsEnable[validationFeaturesEXT.enabledValidationFeatureCount ] = VK_VALIDATION_FEATURE_ENABLE_SYNCHRONIZATION_VALIDATION_EXT;
220
+ validationFeaturesEXT.enabledValidationFeatureCount += 1u ;
221
+ addStructToChain (&validationFeaturesEXT);
178
222
}
179
223
180
224
uint32_t instanceApiVersion = MinimumVulkanApiVersion;
@@ -196,7 +240,7 @@ namespace nbl::video
196
240
applicationInfo.engineVersion = NABLA_VERSION_INTEGER;
197
241
198
242
VkInstanceCreateInfo createInfo = { VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO };
199
- createInfo.pNext = enabledFeatures. debugUtils ? (VkDebugUtilsMessengerCreateInfoEXT*)&debugMessengerCreateInfo : nullptr ;
243
+ createInfo.pNext = structsHead ;
200
244
createInfo.flags = static_cast <VkInstanceCreateFlags>(0 );
201
245
createInfo.pApplicationInfo = &applicationInfo;
202
246
createInfo.enabledLayerCount = requiredLayerNameCount;
0 commit comments