Skip to content

Commit

Permalink
layers: Add Extension Checks for Layer Extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
spencer-lunarg committed Jan 14, 2025
1 parent 9037216 commit 2219306
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 21 deletions.
38 changes: 32 additions & 6 deletions layers/stateless/sl_instance_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,18 +185,18 @@ bool StatelessValidation::manual_PreCallValidateCreateInstance(const VkInstanceC
}
}

const auto *debug_report_callback = vku::FindStructInPNextChain<VkDebugReportCallbackCreateInfoEXT>(pCreateInfo->pNext);
if (debug_report_callback && !local_instance_extensions.vk_ext_debug_report) {
if (!local_instance_extensions.vk_ext_debug_report &&
vku::FindStructInPNextChain<VkDebugReportCallbackCreateInfoEXT>(pCreateInfo->pNext)) {
skip |= LogError("VUID-VkInstanceCreateInfo-pNext-04925", instance, create_info_loc.dot(Field::ppEnabledExtensionNames),
"does not include VK_EXT_debug_report, but the pNext chain includes VkDebugReportCallbackCreateInfoEXT.");
}
const auto *debug_utils_messenger = vku::FindStructInPNextChain<VkDebugUtilsMessengerCreateInfoEXT>(pCreateInfo->pNext);
if (debug_utils_messenger && !local_instance_extensions.vk_ext_debug_utils) {
if (!local_instance_extensions.vk_ext_debug_utils &&
vku::FindStructInPNextChain<VkDebugUtilsMessengerCreateInfoEXT>(pCreateInfo->pNext)) {
skip |= LogError("VUID-VkInstanceCreateInfo-pNext-04926", instance, create_info_loc.dot(Field::ppEnabledExtensionNames),
"does not include VK_EXT_debug_utils, but the pNext chain includes VkDebugUtilsMessengerCreateInfoEXT.");
}
const auto *direct_driver_loading_list = vku::FindStructInPNextChain<VkDirectDriverLoadingListLUNARG>(pCreateInfo->pNext);
if (direct_driver_loading_list && !local_instance_extensions.vk_lunarg_direct_driver_loading) {
if (!local_instance_extensions.vk_lunarg_direct_driver_loading &&
vku::FindStructInPNextChain<VkDirectDriverLoadingListLUNARG>(pCreateInfo->pNext)) {
skip |= LogError(
"VUID-VkInstanceCreateInfo-pNext-09400", instance, create_info_loc.dot(Field::ppEnabledExtensionNames),
"does not include VK_LUNARG_direct_driver_loading, but the pNext chain includes VkDirectDriverLoadingListLUNARG.");
Expand All @@ -218,6 +218,32 @@ bool StatelessValidation::manual_PreCallValidateCreateInstance(const VkInstanceC
}
#endif // VK_USE_PLATFORM_METAL_EXT

// These were attempted to be turned on, but ran into a series of issues with CI machines. Basically adding these require our
// testing to also include the extension, which in turns will fail on machines with an older loader.
// TODO - Enable these once we have a way to add AddRequiredExtensions(VK_EXT_LAYER_SETTINGS_EXTENSION_NAME); to tests
#if 0
// These are extensions/structs implemented in the Validation Layers itself, in theory, the extension string is not needed, but
// good to have for completeness.
if (!local_instance_extensions.vk_ext_layer_settings &&
vku::FindStructInPNextChain<VkLayerSettingsCreateInfoEXT>(pCreateInfo->pNext)) {
skip |= LogWarning("VUID-VkInstanceCreateInfo-pNext-10242", instance, create_info_loc.dot(Field::ppEnabledExtensionNames),
"does not include VK_EXT_layer_settings, but the pNext chain includes VkLayerSettingsCreateInfoEXT. "
"(Most layers, including Validation, will still work regardless of the extension included)");
}
if (!local_instance_extensions.vk_ext_validation_features &&
vku::FindStructInPNextChain<VkValidationFeaturesEXT>(pCreateInfo->pNext)) {
skip |= LogWarning("VUID-VkInstanceCreateInfo-pNext-10243", instance, create_info_loc.dot(Field::ppEnabledExtensionNames),
"does not include VK_EXT_validation_features, but the pNext chain includes VkValidationFeaturesEXT. "
"(Most layers, including Validation, will still work regardless of the extension included)");
}
if (!local_instance_extensions.vk_ext_validation_flags &&
vku::FindStructInPNextChain<VkValidationFlagsEXT>(pCreateInfo->pNext)) {
skip |= LogWarning("VUID-VkInstanceCreateInfo-pNext-10244", instance, create_info_loc.dot(Field::ppEnabledExtensionNames),
"does not include VK_EXT_validation_flags, but the pNext chain includes VkValidationFlagsEXT. (Most "
"layers, including Validation, will still work regardless of the extension included)");
}
#endif

return skip;
}

Expand Down
8 changes: 4 additions & 4 deletions tests/framework/layer_validation_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*
* Copyright (c) 2015-2024 The Khronos Group Inc.
* Copyright (c) 2015-2024 Valve Corporation
* Copyright (c) 2015-2024 LunarG, Inc.
* Copyright (c) 2015-2023 Google, Inc.
* Copyright (c) 2015-2025 The Khronos Group Inc.
* Copyright (c) 2015-2025 Valve Corporation
* Copyright (c) 2015-2025 LunarG, Inc.
* Copyright (c) 2015-2025 Google, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
13 changes: 7 additions & 6 deletions tests/unit/best_practices.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*
* Copyright (c) 2015-2024 The Khronos Group Inc.
* Copyright (c) 2015-2024 Valve Corporation
* Copyright (c) 2015-2024 LunarG, Inc.
* Copyright (c) 2015-2024 Google, Inc.
* Copyright (c) 2015-2025 The Khronos Group Inc.
* Copyright (c) 2015-2025 Valve Corporation
* Copyright (c) 2015-2025 LunarG, Inc.
* Copyright (c) 2015-2025 Google, Inc.
* Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -103,8 +103,9 @@ TEST_F(VkBestPracticesLayerTest, UseDeprecatedInstanceExtensions) {
// Extra error if VK_EXT_debug_report is used on Android still
m_errorMonitor->SetDesiredWarning("BestPractices-deprecated-extension");
}
m_errorMonitor->SetDesiredWarning("BestPractices-deprecated-extension");
m_errorMonitor->SetDesiredWarning("BestPractices-specialuse-extension");

m_errorMonitor->SetDesiredWarning("BestPractices-deprecated-extension"); // VK_KHR_get_physical_device_properties2,
m_errorMonitor->SetDesiredWarning("BestPractices-specialuse-extension"); // VK_EXT_debug_utils
VkInstance dummy;
auto features = features_;
auto ici = GetInstanceCreateInfo();
Expand Down
13 changes: 8 additions & 5 deletions tests/unit/portability_subset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -608,10 +608,17 @@ TEST_F(VkPortabilitySubsetTest, PortabilitySubsetColorBlendFactor) {

TEST_F(VkPortabilitySubsetTest, InstanceCreateEnumerate) {
TEST_DESCRIPTION("Validate creating instances with VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR.");
std::vector<const char *> enabled_extensions = {VK_EXT_DEBUG_UTILS_EXTENSION_NAME,
VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME};

#ifdef VK_USE_PLATFORM_ANDROID_KHR
GTEST_SKIP() << "Android doesn't support Debug Utils";
#endif

auto ici = GetInstanceCreateInfo();
ici.flags = VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR;
ici.enabledExtensionCount = 1;
ici.ppEnabledExtensionNames = enabled_extensions.data();

VkInstance local_instance;

Expand All @@ -620,11 +627,7 @@ TEST_F(VkPortabilitySubsetTest, InstanceCreateEnumerate) {
m_errorMonitor->VerifyFound();

if (InstanceExtensionSupported(VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME)) {
std::vector<const char *> enabled_extensions = {VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME,
VK_EXT_DEBUG_UTILS_EXTENSION_NAME};
ici.enabledExtensionCount = static_cast<uint32_t>(enabled_extensions.size());
ici.ppEnabledExtensionNames = enabled_extensions.data();

ici.enabledExtensionCount = 2;
ASSERT_EQ(VK_SUCCESS, vk::CreateInstance(&ici, nullptr, &local_instance));
vk::DestroyInstance(local_instance, nullptr);
}
Expand Down

0 comments on commit 2219306

Please sign in to comment.