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

Rework CMake validation layer options and add flags for best practices and sync validation #737

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,5 +170,4 @@ Also see [CONTRIBUTING](CONTRIBUTING.md) for contribution guidelines.

## Related resources

- [Mali GPU Best Practices](https://developer.arm.com/documentation/101897/latest/): A document with recommendations for efficient API usage
- [PerfDoc](https://github.com/ARM-software/perfdoc): A Vulkan layer which aims to validate applications against Mali GPU Best Practices
- [Mali GPU Best Practices](https://developer.arm.com/documentation/101897/latest/): A document with recommendations for efficient API usage
1 change: 1 addition & 0 deletions bldsys/cmake/global_options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ endif()
set(VKB_WARNINGS_AS_ERRORS ON CACHE BOOL "Enable Warnings as Errors")
set(VKB_VALIDATION_LAYERS OFF CACHE BOOL "Enable validation layers for every application.")
set(VKB_VALIDATION_LAYERS_GPU_ASSISTED OFF CACHE BOOL "Enable GPU assisted validation layers for every application.")
set(VKB_VALIDATION_LAYERS_BEST_PRACTICES OFF CACHE BOOL "Enable best practices validation layers for every application.")
SaschaWillems marked this conversation as resolved.
Show resolved Hide resolved
set(VKB_VULKAN_DEBUG ON CACHE BOOL "Enable VK_EXT_debug_utils or VK_EXT_debug_marker if supported.")
set(VKB_BUILD_SAMPLES ON CACHE BOOL "Enable generation and building of Vulkan best practice samples.")
set(VKB_BUILD_TESTS OFF CACHE BOOL "Enable generation and building of Vulkan best practice tests.")
Expand Down
10 changes: 10 additions & 0 deletions docs/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@ Enable GPU assisted Validation Layers, used primarily for VK_EXT_descriptor_inde

**Default:** `OFF`

**Note:** Only works with `VKB_VALIDATION_LAYERS` enabled

### VKB_VALIDATION_LAYERS_BEST_PRACTICES

Enable [best practices Validation Layers](https://github.com/KhronosGroup/Vulkan-ValidationLayers/blob/main/docs/best_practices.md).

**Default:** `OFF`

**Note:** Only works with `VKB_VALIDATION_LAYERS` enabled
SaschaWillems marked this conversation as resolved.
Show resolved Hide resolved

### VKB_VULKAN_DEBUG

Enable VK_EXT_debug_utils or VK_EXT_debug_marker, if supported.
Expand Down
4 changes: 4 additions & 0 deletions framework/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,10 @@ if(${VKB_VALIDATION_LAYERS_GPU_ASSISTED})
endif()
endif()

if(${VKB_VALIDATION_LAYERS_BEST_PRACTICES})
SaschaWillems marked this conversation as resolved.
Show resolved Hide resolved
target_compile_definitions(${PROJECT_NAME} PUBLIC VKB_VALIDATION_LAYERS_BEST_PRACTICES)
endif()

if(${VKB_VULKAN_DEBUG})
target_compile_definitions(${PROJECT_NAME} PUBLIC VKB_VULKAN_DEBUG)
endif()
Expand Down
16 changes: 11 additions & 5 deletions framework/core/hpp_instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ HPPInstance::HPPInstance(const std::string &applicati
enable_extension(VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME, available_instance_extensions, enabled_extensions);
#endif

#if (defined(VKB_DEBUG) || defined(VKB_VALIDATION_LAYERS)) && defined(VKB_VALIDATION_LAYERS_GPU_ASSISTED)
#if (defined(VKB_DEBUG) || defined(VKB_VALIDATION_LAYERS)) && (defined(VKB_VALIDATION_LAYERS_GPU_ASSISTED) || defined(VKB_VALIDATION_LAYERS_BEST_PRACTICES))
SaschaWillems marked this conversation as resolved.
Show resolved Hide resolved
bool validation_features = false;
{
std::vector<vk::ExtensionProperties> available_layer_instance_extensions = vk::enumerateInstanceExtensionProperties(std::string("VK_LAYER_KHRONOS_validation"));
Expand Down Expand Up @@ -319,12 +319,18 @@ HPPInstance::HPPInstance(const std::string &applicati
instance_info.flags |= vk::InstanceCreateFlagBits::eEnumeratePortabilityKHR;
#endif

#if (defined(VKB_DEBUG) || defined(VKB_VALIDATION_LAYERS)) && defined(VKB_VALIDATION_LAYERS_GPU_ASSISTED)
vk::ValidationFeaturesEXT validation_features_info;
#if (defined(VKB_DEBUG) || defined(VKB_VALIDATION_LAYERS)) && (defined(VKB_VALIDATION_LAYERS_GPU_ASSISTED) || defined(VKB_VALIDATION_LAYERS_BEST_PRACTICES))
vk::ValidationFeaturesEXT validation_features_info;
std::vector<vk::ValidationFeatureEnableEXT> enable_features{};
if (validation_features)
{
static const std::array<vk::ValidationFeatureEnableEXT, 2> enable_features = {{vk::ValidationFeatureEnableEXT::eGpuAssistedReserveBindingSlot,
vk::ValidationFeatureEnableEXT::eGpuAssisted}};
# if defined(VKB_VALIDATION_LAYERS_GPU_ASSISTED)
enable_features.push_back(vk::ValidationFeatureEnableEXT::eGpuAssistedReserveBindingSlot);
enable_features.push_back(vk::ValidationFeatureEnableEXT::eGpuAssisted);
# endif
# if defined(VKB_VALIDATION_LAYERS_BEST_PRACTICES)
enable_features.push_back(vk::ValidationFeatureEnableEXT::eBestPractices);
# endif
validation_features_info.setEnabledValidationFeatures(enable_features);
validation_features_info.pNext = instance_info.pNext;
instance_info.pNext = &validation_features_info;
Expand Down
23 changes: 14 additions & 9 deletions framework/core/instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ Instance::Instance(const std::string &application_nam
enable_extension(VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME, available_instance_extensions, enabled_extensions);
#endif

#if (defined(VKB_DEBUG) || defined(VKB_VALIDATION_LAYERS)) && defined(VKB_VALIDATION_LAYERS_GPU_ASSISTED)
#if (defined(VKB_DEBUG) || defined(VKB_VALIDATION_LAYERS)) && (defined(VKB_VALIDATION_LAYERS_GPU_ASSISTED) || defined(VKB_VALIDATION_LAYERS_BEST_PRACTICES))
bool validation_features = false;
{
uint32_t layer_instance_extension_count;
Expand Down Expand Up @@ -342,16 +342,21 @@ Instance::Instance(const std::string &application_nam
instance_info.flags |= VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR;
#endif

#if (defined(VKB_DEBUG) || defined(VKB_VALIDATION_LAYERS)) && defined(VKB_VALIDATION_LAYERS_GPU_ASSISTED)
VkValidationFeaturesEXT validation_features_info = {VK_STRUCTURE_TYPE_VALIDATION_FEATURES_EXT};
// If GPU assisted validation or best practices validation are enabled, we need to pass additional information to instance creation
#if (defined(VKB_DEBUG) || defined(VKB_VALIDATION_LAYERS)) && (defined(VKB_VALIDATION_LAYERS_GPU_ASSISTED) || defined(VKB_VALIDATION_LAYERS_BEST_PRACTICES))
VkValidationFeaturesEXT validation_features_info = {VK_STRUCTURE_TYPE_VALIDATION_FEATURES_EXT};
std::vector<VkValidationFeatureEnableEXT> enable_features{};
if (validation_features)
{
static const VkValidationFeatureEnableEXT enable_features[2] = {
VK_VALIDATION_FEATURE_ENABLE_GPU_ASSISTED_RESERVE_BINDING_SLOT_EXT,
VK_VALIDATION_FEATURE_ENABLE_GPU_ASSISTED_EXT,
};
validation_features_info.enabledValidationFeatureCount = 2;
validation_features_info.pEnabledValidationFeatures = enable_features;
# if defined(VKB_VALIDATION_LAYERS_GPU_ASSISTED)
enable_features.push_back(VK_VALIDATION_FEATURE_ENABLE_GPU_ASSISTED_RESERVE_BINDING_SLOT_EXT);
enable_features.push_back(VK_VALIDATION_FEATURE_ENABLE_GPU_ASSISTED_EXT);
# endif
# if defined(VKB_VALIDATION_LAYERS_BEST_PRACTICES)
enable_features.push_back(VK_VALIDATION_FEATURE_ENABLE_BEST_PRACTICES_EXT);
# endif
validation_features_info.enabledValidationFeatureCount = static_cast<uint32_t>(enable_features.size());
validation_features_info.pEnabledValidationFeatures = enable_features.data();
validation_features_info.pNext = instance_info.pNext;
instance_info.pNext = &validation_features_info;
}
Expand Down
Loading