Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

layers: Add Extension Checks for Layer Extensions #8765

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
33 changes: 27 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,27 @@ bool StatelessValidation::manual_PreCallValidateCreateInstance(const VkInstanceC
}
#endif // VK_USE_PLATFORM_METAL_EXT

// 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)");
}

return skip;
}

Expand Down
1 change: 1 addition & 0 deletions scripts/vk_validation_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@ def main(argv):
layer_source_files = [repo_relative(path) for path in [
'layers/error_message/unimplementable_validation.h',
'layers/state_tracker/video_session_state.cpp',
'layers/layer_options.cpp',
f'layers/{args.api}/generated/stateless_validation_helper.cpp',
f'layers/{args.api}/generated/object_tracker.cpp',
f'layers/{args.api}/generated/spirv_validation_helper.cpp',
Expand Down
4 changes: 4 additions & 0 deletions tests/framework/layer_validation_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,10 @@ void VkLayerTest::Init(VkPhysicalDeviceFeatures *features, VkPhysicalDeviceFeatu
}

VkLayerTest::VkLayerTest() {
// These are extensions enabled by the layer, they can always be on because we know for a fact the Validation Layers will have
// them enabled always
m_instance_extension_names.push_back(VK_EXT_LAYER_SETTINGS_EXTENSION_NAME);
m_instance_extension_names.push_back(VK_EXT_VALIDATION_FEATURES_EXTENSION_NAME);
#if !defined(VK_USE_PLATFORM_ANDROID_KHR)
m_instance_extension_names.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
#else
Expand Down
1 change: 1 addition & 0 deletions tests/framework/render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ bool VkRenderFramework::InstanceExtensionSupported(const char *const extension_n
if (0 == strncmp(extension_name, VK_EXT_DEBUG_UTILS_EXTENSION_NAME, VK_MAX_EXTENSION_NAME_SIZE)) return true;
if (0 == strncmp(extension_name, VK_EXT_DEBUG_REPORT_EXTENSION_NAME, VK_MAX_EXTENSION_NAME_SIZE)) return true;
if (0 == strncmp(extension_name, VK_EXT_VALIDATION_FEATURES_EXTENSION_NAME, VK_MAX_EXTENSION_NAME_SIZE)) return true;
if (0 == strncmp(extension_name, VK_EXT_LAYER_SETTINGS_EXTENSION_NAME, VK_MAX_EXTENSION_NAME_SIZE)) return true;

if (available_extensions_.empty()) {
available_extensions_ = vkt::GetGlobalExtensions();
Expand Down
6 changes: 4 additions & 2 deletions tests/unit/best_practices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,10 @@ 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_EXT_validation_features
m_errorMonitor->SetDesiredWarning("BestPractices-deprecated-extension"); // VK_KHR_get_physical_device_properties2,
m_errorMonitor->SetDesiredWarning("BestPractices-specialuse-extension"); // VK_EXT_validation_features
m_errorMonitor->SetDesiredWarning("BestPractices-specialuse-extension"); // VK_EXT_debug_utils
VkInstance dummy;
auto features = features_;
auto ici = GetInstanceCreateInfo();
Expand Down
15 changes: 0 additions & 15 deletions tests/unit/instanceless.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,21 +337,6 @@ TEST_F(NegativeInstanceless, ExtensionStructsWithoutExtensions) {
m_errorMonitor->SetDesiredError("VUID-VkInstanceCreateInfo-pNext-09400");
vk::CreateInstance(&ici, nullptr, &instance);
m_errorMonitor->VerifyFound();

VkDebugUtilsMessengerCreateInfoEXT debug_utils_messenger = vku::InitStructHelper();
debug_utils_messenger.pNext = m_errorMonitor->GetDebugCreateInfo();
debug_utils_messenger.messageSeverity = VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT;
debug_utils_messenger.messageType = VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT;
debug_utils_messenger.pfnUserCallback = utils_callback;
ici.pNext = &debug_utils_messenger;
// Ignore the first extension which is VK_EXT_debug_utils
ici.enabledExtensionCount = size32(m_instance_extension_names) - 1;
if (ici.enabledExtensionCount > 0) {
ici.ppEnabledExtensionNames = &m_instance_extension_names[1];
}
m_errorMonitor->SetDesiredError("VUID-VkInstanceCreateInfo-pNext-04926");
vk::CreateInstance(&ici, nullptr, &instance);
m_errorMonitor->VerifyFound();
}
#endif

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