diff --git a/impeller/renderer/backend/vulkan/context_vk.cc b/impeller/renderer/backend/vulkan/context_vk.cc index 58508e8793d75..e2002204cd13c 100644 --- a/impeller/renderer/backend/vulkan/context_vk.cc +++ b/impeller/renderer/backend/vulkan/context_vk.cc @@ -7,6 +7,7 @@ #include "impeller/renderer/backend/vulkan/context_vk.h" #include +#include #include #include #include @@ -51,6 +52,15 @@ VKAPI_ATTR VkBool32 VKAPI_CALL DebugUtilsMessengerCallback( namespace impeller { +namespace vk { + +bool HasValidationLayers() { + auto capabilities = std::make_unique(); + return capabilities->HasLayer(kKhronosValidationLayerName); +} + +} // namespace vk + static std::set kRequiredDeviceExtensions = { VK_KHR_SWAPCHAIN_EXTENSION_NAME, #if FML_OS_MACOSX @@ -316,11 +326,9 @@ ContextVK::ContextVK( /// Enable any and all validation as well as debug toggles. /// auto has_debug_utils = false; - constexpr const char* kKhronosValidationLayerName = - "VK_LAYER_KHRONOS_validation"; - if (capabilities->HasLayer(kKhronosValidationLayerName)) { - enabled_layers.push_back(kKhronosValidationLayerName); - if (capabilities->HasLayerExtension(kKhronosValidationLayerName, + if (vk::HasValidationLayers()) { + enabled_layers.push_back(vk::kKhronosValidationLayerName); + if (capabilities->HasLayerExtension(vk::kKhronosValidationLayerName, VK_EXT_DEBUG_UTILS_EXTENSION_NAME)) { enabled_extensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); has_debug_utils = true; diff --git a/impeller/renderer/backend/vulkan/context_vk.h b/impeller/renderer/backend/vulkan/context_vk.h index f99ef0e28d41b..44806548cd5af 100644 --- a/impeller/renderer/backend/vulkan/context_vk.h +++ b/impeller/renderer/backend/vulkan/context_vk.h @@ -23,6 +23,15 @@ namespace impeller { +namespace vk { + +constexpr const char* kKhronosValidationLayerName = + "VK_LAYER_KHRONOS_validation"; + +bool HasValidationLayers(); + +} // namespace vk + class ContextVK final : public Context, public BackendCast { public: static std::shared_ptr Create( @@ -40,12 +49,23 @@ class ContextVK final : public Context, public BackendCast { template bool SetDebugName(T handle, std::string_view label) const { + return SetDebugName(*device_, handle, label); + } + + template + static bool SetDebugName(vk::Device device, + T handle, + std::string_view label) { + if (!vk::HasValidationLayers()) { + // No-op if validation layers are not enabled. + return true; + } + uint64_t handle_ptr = reinterpret_cast(static_cast(handle)); std::string label_str = std::string(label); - - auto ret = device_->setDebugUtilsObjectNameEXT( + auto ret = device.setDebugUtilsObjectNameEXT( vk::DebugUtilsObjectNameInfoEXT() .setObjectType(T::objectType) .setObjectHandle(handle_ptr) diff --git a/impeller/renderer/backend/vulkan/pipeline_library_vk.cc b/impeller/renderer/backend/vulkan/pipeline_library_vk.cc index 0b7ff43b1a7dd..e9008d5c6dba5 100644 --- a/impeller/renderer/backend/vulkan/pipeline_library_vk.cc +++ b/impeller/renderer/backend/vulkan/pipeline_library_vk.cc @@ -10,6 +10,7 @@ #include "flutter/fml/trace_event.h" #include "impeller/base/promise.h" #include "impeller/base/validation.h" +#include "impeller/renderer/backend/vulkan/context_vk.h" #include "impeller/renderer/backend/vulkan/formats_vk.h" #include "impeller/renderer/backend/vulkan/pipeline_vk.h" #include "impeller/renderer/backend/vulkan/shader_function_vk.h" @@ -372,6 +373,8 @@ std::unique_ptr PipelineLibraryVK::CreatePipeline( vk::UniqueDescriptorSetLayout descriptor_set_layout = std::move(descriptor_set_create_res.value); + ContextVK::SetDebugName(device_, descriptor_set_layout.get(), + "descriptor_set_layout_" + desc.GetLabel()); vk::PipelineLayoutCreateInfo pipeline_layout_info; pipeline_layout_info.setSetLayouts(descriptor_set_layout.get()); @@ -403,6 +406,11 @@ std::unique_ptr PipelineLibraryVK::CreatePipeline( return nullptr; } + ContextVK::SetDebugName(device_, *pipeline_layout.value, + "pipeline_layout_" + desc.GetLabel()); + ContextVK::SetDebugName(device_, *pipeline.value, + "pipeline_" + desc.GetLabel()); + return std::make_unique( std::move(pipeline.value), std::move(render_pass.value()), std::move(pipeline_layout.value), std::move(descriptor_set_layout)); diff --git a/impeller/renderer/backend/vulkan/shader_library_vk.cc b/impeller/renderer/backend/vulkan/shader_library_vk.cc index 23f7ad1b9b3c8..df71ece7504f3 100644 --- a/impeller/renderer/backend/vulkan/shader_library_vk.cc +++ b/impeller/renderer/backend/vulkan/shader_library_vk.cc @@ -7,6 +7,7 @@ #include "flutter/fml/logging.h" #include "flutter/fml/trace_event.h" #include "impeller/blobcat/blob_library.h" +#include "impeller/renderer/backend/vulkan/context_vk.h" #include "impeller/renderer/backend/vulkan/shader_function_vk.h" namespace impeller { @@ -80,11 +81,15 @@ ShaderLibraryVK::ShaderLibraryVK( const auto stage = ToShaderStage(type); const auto key_name = VKShaderNameToShaderKeyName(name, stage); + vk::UniqueShaderModule shader_module = std::move(module.value); + ContextVK::SetDebugName(device, *shader_module, + "shader_module_" + key_name); + functions[ShaderKey{key_name, stage}] = std::shared_ptr( - new ShaderFunctionVK(library_id, // - key_name, // - stage, // - std::move(module.value) // + new ShaderFunctionVK(library_id, // + key_name, // + stage, // + std::move(shader_module) // )); return true;