Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/vsg/vk/Instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ namespace vsg
/// return names of layers that are supported from the desired list.
extern VSG_DECLSPEC Names validateInstanceLayerNames(const Names& names);

/// return true if the specified layer name exists in the list.
extern VSG_DECLSPEC bool containsInstanceLayerName(const Names& names, const char* layerName);

/// Instance encapsulates the VkInstance.
class VSG_DECLSPEC Instance : public Inherit<Object, Instance>
{
Expand Down
25 changes: 24 additions & 1 deletion src/vsg/vk/Instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@ Names vsg::validateInstanceLayerNames(const Names& names)
return validatedNames;
}

bool vsg::containsInstanceLayerName(const Names& names, const char* layerName)
{
if (!layerName) return false;

auto cmpFunc = [&](const char* name) {
return strcmp(name, layerName) == 0;
};
return std::find_if(names.begin(), names.end(), cmpFunc) != names.end();
}

static VKAPI_ATTR VkBool32 VKAPI_CALL debugUtilsMessengerCallback(
VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
VkDebugUtilsMessageTypeFlagsEXT /*messageType*/,
Expand Down Expand Up @@ -143,7 +153,20 @@ Instance::Instance(Names instanceExtensions, Names layers, uint32_t vulkanApiVer
createInfo.enabledLayerCount = static_cast<uint32_t>(layers.size());
createInfo.ppEnabledLayerNames = layers.empty() ? nullptr : layers.data();

createInfo.pNext = nullptr;
// enable synchronization validation feature if requested
VkValidationFeatureEnableEXT validationFeature = VK_VALIDATION_FEATURE_ENABLE_SYNCHRONIZATION_VALIDATION_EXT;
VkValidationFeaturesEXT validationFeatures{};
if (containsInstanceLayerName(layers, "VK_LAYER_KHRONOS_synchronization2"))
{
validationFeatures.sType = VK_STRUCTURE_TYPE_VALIDATION_FEATURES_EXT;
validationFeatures.enabledValidationFeatureCount = 1;
validationFeatures.pEnabledValidationFeatures = &validationFeature;
createInfo.pNext = &validationFeatures;
}
else
{
createInfo.pNext = nullptr;
}

VkInstance instance;
VkResult result = vkCreateInstance(&createInfo, allocator, &instance);
Expand Down
Loading