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

shader_debugprintf: support new VVL-DEBUG-PRINTF message and fix VVL version check for API selection #1187

Merged
merged 18 commits into from
Feb 25, 2025
Merged
Changes from 2 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
8c00ce4
shader_debugprintf: support new VVL-DEBUG-PRINTF message and fix VVL …
SRSaunders Oct 9, 2024
0dc4963
Incorporate review feedback: update comments and simpify code
SRSaunders Oct 22, 2024
4f53d15
Add VK_EXT_validation_features and move VK_EXT_layer_settings extensi…
SRSaunders Oct 23, 2024
5fca9a6
Fix VK_EXT_layer_settings string comparison in [HPP]Instance::[HPP]In…
SRSaunders Oct 23, 2024
badd409
When VK_EXT_layer_settings extension is available don't enable it dur…
SRSaunders Oct 24, 2024
918cef1
Check for VK_EXT_layer_settings available vs. enabled in [HPP]Instanc…
SRSaunders Oct 24, 2024
61c2d81
Use vk::ExtensionProperties vs. VkExtensionProperties in HPPInstance:…
SRSaunders Oct 24, 2024
e23c4e5
Update comments and explicitly request required GPU features for debu…
SRSaunders Oct 25, 2024
bf7c37d
Check for defined layer settings before chaining-in layerSettingsCrea…
SRSaunders Oct 30, 2024
7484c6b
Check VVL instance extensions for VK_EXT_layer_settings and use #defi…
SRSaunders Oct 30, 2024
6b7f548
Merge branch 'main' into debugprintf-2
SRSaunders Nov 18, 2024
6b9329a
Merge branch 'KhronosGroup:main' into debugprintf-2
SRSaunders Nov 18, 2024
37d3dc6
Check for required GPU features otherwise throw exception with error …
SRSaunders Feb 7, 2025
cbe92fc
Update copyright year for all affected files
SRSaunders Feb 7, 2025
2969e5b
Merge branch 'main'
SRSaunders Feb 25, 2025
fc26c16
Review: Remove shaderInt64 feature request, Use %v3f shader print format
SRSaunders Feb 25, 2025
00d0408
Fix copyright dates in updated shaders
SRSaunders Feb 25, 2025
839291f
Update hwcpipe submodule to match main branch
SRSaunders Feb 25, 2025
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
32 changes: 23 additions & 9 deletions samples/extensions/shader_debugprintf/shader_debugprintf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ VKAPI_ATTR VkBool32 VKAPI_CALL ShaderDebugPrintf::debug_utils_message_callback(
const VkDebugUtilsMessengerCallbackDataEXT *pCallbackData,
void *pUserData)
{
// Look for Validation Layer message id names: WARNING-DEBUG-PRINTF or UNASSIGNED-DEBUG-PRINTF (have observed UNASSIGNED with older Vulkan SDKs)
if (strcmp(pCallbackData->pMessageIdName, "WARNING-DEBUG-PRINTF") == 0 || strcmp(pCallbackData->pMessageIdName, "UNASSIGNED-DEBUG-PRINTF") == 0)
// Look for Validation Layer message id names: VVL-DEBUG-PRINTF or WARNING-DEBUG-PRINTF or UNASSIGNED-DEBUG-PRINTF (have observed WARNING and UNASSIGNED with older Vulkan SDKs)
if (strcmp(pCallbackData->pMessageIdName, "VVL-DEBUG-PRINTF") == 0 || strcmp(pCallbackData->pMessageIdName, "WARNING-DEBUG-PRINTF") == 0 || strcmp(pCallbackData->pMessageIdName, "UNASSIGNED-DEBUG-PRINTF") == 0)
{
// Validation messages are a bit verbose, but we only want the text from the shader, so we cut off everything before the first word from the shader message
// See scene.vert: debugPrintfEXT("Position = %v4f", outPos);
Expand Down Expand Up @@ -433,23 +433,37 @@ const std::vector<const char *> ShaderDebugPrintf::get_validation_layers()
// This sample overrides the instance creation part of the framework to chain in additional structures
std::unique_ptr<vkb::Instance> ShaderDebugPrintf::create_instance(bool headless)
{
uint32_t instanceApiVersion;
VK_CHECK(vkEnumerateInstanceVersion(&instanceApiVersion));
// Enumerate all instance layer properties so we can find and use the validation layer (VVL) version in subsequent steps
// The VVL version is needed to work around validation layer performance issues when running with Vulkan SDKs <= 1.3.290
uint32_t layer_property_count;
VK_CHECK(vkEnumerateInstanceLayerProperties(&layer_property_count, nullptr));
std::vector<VkLayerProperties> layer_properties(layer_property_count);
VK_CHECK(vkEnumerateInstanceLayerProperties(&layer_property_count, layer_properties.data()));

const auto vvl_properties = std::find_if(layer_properties.begin(),
layer_properties.end(),
[](VkLayerProperties const &properties) { return strcmp(properties.layerName, "VK_LAYER_KHRONOS_validation") == 0; });

// debugPrintfEXT layer feature requires Vulkan API 1.1, but override with API 1.2 for Vulkan SDKs <= 1.3.290 to work around VVL performance defect
// See VVL issue https://github.com/KhronosGroup/Vulkan-ValidationLayers/issues/7562 for defect and fix information (fix available in SDK 1.3.296)
auto debugprintf_api_version = VK_API_VERSION_1_1;
if (vvl_properties != layer_properties.end() && vvl_properties->specVersion <= VK_MAKE_API_VERSION(0, 1, 3, 290))
{
debugprintf_api_version = VK_API_VERSION_1_2;
}

uint32_t instance_extension_count;
VK_CHECK(vkEnumerateInstanceExtensionProperties(nullptr, &instance_extension_count, nullptr));
std::vector<VkExtensionProperties> available_instance_extensions(instance_extension_count);
VK_CHECK(vkEnumerateInstanceExtensionProperties(nullptr, &instance_extension_count, available_instance_extensions.data()));

// When VK_EXT_layer_settings is available at runtime, the debugPrintfEXT layer feature is enabled using the standard framework
// For backwards compatibility with SDKs < 1.3.272 without VK_EXT_layer_settings, the remainder of this custom override is required
// For this case set Vulkan API version and return via base class, otherwise the remainder of this custom override is required
if (std::any_of(available_instance_extensions.begin(),
available_instance_extensions.end(),
[](VkExtensionProperties const &extension) { return strcmp(extension.extensionName, VK_EXT_LAYER_SETTINGS_EXTENSION_NAME) == 0; }))
{
// debugPrintfEXT layer feature requires Vulkan API 1.1, but use API 1.2 until VVL performance fix is available in SDKs > 1.3.290
// See VVL issue https://github.com/KhronosGroup/Vulkan-ValidationLayers/issues/7562 for defect and fix information
set_api_version(instanceApiVersion <= VK_MAKE_API_VERSION(0, 1, 3, 290) ? VK_API_VERSION_1_2 : VK_API_VERSION_1_1);
set_api_version(debugprintf_api_version);

// Run standard create_instance() from framework (with set_api_version and layer settings support) and return
return VulkanSample::create_instance(headless);
Expand Down Expand Up @@ -480,7 +494,7 @@ std::unique_ptr<vkb::Instance> ShaderDebugPrintf::create_instance(bool headless)
VkApplicationInfo app_info{VK_STRUCTURE_TYPE_APPLICATION_INFO};
app_info.pApplicationName = "Shader debugprintf";
app_info.pEngineName = "Vulkan Samples";
app_info.apiVersion = instanceApiVersion <= VK_MAKE_API_VERSION(0, 1, 3, 290) ? VK_API_VERSION_1_2 : VK_API_VERSION_1_1;
app_info.apiVersion = debugprintf_api_version;

// Shader printf is a feature of the validation layers that needs to be enabled
std::vector<VkValidationFeatureEnableEXT> validation_feature_enables = {VK_VALIDATION_FEATURE_ENABLE_DEBUG_PRINTF_EXT};
Expand Down
Loading