Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 58495f0

Browse files
authored
[Impeller] Add debug names to additional VK objects (#37592)
1 parent b4fd07f commit 58495f0

File tree

4 files changed

+52
-11
lines changed

4 files changed

+52
-11
lines changed

impeller/renderer/backend/vulkan/context_vk.cc

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "impeller/renderer/backend/vulkan/context_vk.h"
88

99
#include <map>
10+
#include <memory>
1011
#include <optional>
1112
#include <set>
1213
#include <string>
@@ -51,6 +52,15 @@ VKAPI_ATTR VkBool32 VKAPI_CALL DebugUtilsMessengerCallback(
5152

5253
namespace impeller {
5354

55+
namespace vk {
56+
57+
bool HasValidationLayers() {
58+
auto capabilities = std::make_unique<CapabilitiesVK>();
59+
return capabilities->HasLayer(kKhronosValidationLayerName);
60+
}
61+
62+
} // namespace vk
63+
5464
static std::set<std::string> kRequiredDeviceExtensions = {
5565
VK_KHR_SWAPCHAIN_EXTENSION_NAME,
5666
#if FML_OS_MACOSX
@@ -316,11 +326,9 @@ ContextVK::ContextVK(
316326
/// Enable any and all validation as well as debug toggles.
317327
///
318328
auto has_debug_utils = false;
319-
constexpr const char* kKhronosValidationLayerName =
320-
"VK_LAYER_KHRONOS_validation";
321-
if (capabilities->HasLayer(kKhronosValidationLayerName)) {
322-
enabled_layers.push_back(kKhronosValidationLayerName);
323-
if (capabilities->HasLayerExtension(kKhronosValidationLayerName,
329+
if (vk::HasValidationLayers()) {
330+
enabled_layers.push_back(vk::kKhronosValidationLayerName);
331+
if (capabilities->HasLayerExtension(vk::kKhronosValidationLayerName,
324332
VK_EXT_DEBUG_UTILS_EXTENSION_NAME)) {
325333
enabled_extensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
326334
has_debug_utils = true;

impeller/renderer/backend/vulkan/context_vk.h

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@
2323

2424
namespace impeller {
2525

26+
namespace vk {
27+
28+
constexpr const char* kKhronosValidationLayerName =
29+
"VK_LAYER_KHRONOS_validation";
30+
31+
bool HasValidationLayers();
32+
33+
} // namespace vk
34+
2635
class ContextVK final : public Context, public BackendCast<ContextVK, Context> {
2736
public:
2837
static std::shared_ptr<ContextVK> Create(
@@ -40,12 +49,23 @@ class ContextVK final : public Context, public BackendCast<ContextVK, Context> {
4049

4150
template <typename T>
4251
bool SetDebugName(T handle, std::string_view label) const {
52+
return SetDebugName(*device_, handle, label);
53+
}
54+
55+
template <typename T>
56+
static bool SetDebugName(vk::Device device,
57+
T handle,
58+
std::string_view label) {
59+
if (!vk::HasValidationLayers()) {
60+
// No-op if validation layers are not enabled.
61+
return true;
62+
}
63+
4364
uint64_t handle_ptr =
4465
reinterpret_cast<uint64_t>(static_cast<typename T::NativeType>(handle));
4566

4667
std::string label_str = std::string(label);
47-
48-
auto ret = device_->setDebugUtilsObjectNameEXT(
68+
auto ret = device.setDebugUtilsObjectNameEXT(
4969
vk::DebugUtilsObjectNameInfoEXT()
5070
.setObjectType(T::objectType)
5171
.setObjectHandle(handle_ptr)

impeller/renderer/backend/vulkan/pipeline_library_vk.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "flutter/fml/trace_event.h"
1111
#include "impeller/base/promise.h"
1212
#include "impeller/base/validation.h"
13+
#include "impeller/renderer/backend/vulkan/context_vk.h"
1314
#include "impeller/renderer/backend/vulkan/formats_vk.h"
1415
#include "impeller/renderer/backend/vulkan/pipeline_vk.h"
1516
#include "impeller/renderer/backend/vulkan/shader_function_vk.h"
@@ -372,6 +373,8 @@ std::unique_ptr<PipelineCreateInfoVK> PipelineLibraryVK::CreatePipeline(
372373

373374
vk::UniqueDescriptorSetLayout descriptor_set_layout =
374375
std::move(descriptor_set_create_res.value);
376+
ContextVK::SetDebugName(device_, descriptor_set_layout.get(),
377+
"descriptor_set_layout_" + desc.GetLabel());
375378

376379
vk::PipelineLayoutCreateInfo pipeline_layout_info;
377380
pipeline_layout_info.setSetLayouts(descriptor_set_layout.get());
@@ -403,6 +406,11 @@ std::unique_ptr<PipelineCreateInfoVK> PipelineLibraryVK::CreatePipeline(
403406
return nullptr;
404407
}
405408

409+
ContextVK::SetDebugName(device_, *pipeline_layout.value,
410+
"pipeline_layout_" + desc.GetLabel());
411+
ContextVK::SetDebugName(device_, *pipeline.value,
412+
"pipeline_" + desc.GetLabel());
413+
406414
return std::make_unique<PipelineCreateInfoVK>(
407415
std::move(pipeline.value), std::move(render_pass.value()),
408416
std::move(pipeline_layout.value), std::move(descriptor_set_layout));

impeller/renderer/backend/vulkan/shader_library_vk.cc

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "flutter/fml/logging.h"
88
#include "flutter/fml/trace_event.h"
99
#include "impeller/blobcat/blob_library.h"
10+
#include "impeller/renderer/backend/vulkan/context_vk.h"
1011
#include "impeller/renderer/backend/vulkan/shader_function_vk.h"
1112

1213
namespace impeller {
@@ -80,11 +81,15 @@ ShaderLibraryVK::ShaderLibraryVK(
8081
const auto stage = ToShaderStage(type);
8182
const auto key_name = VKShaderNameToShaderKeyName(name, stage);
8283

84+
vk::UniqueShaderModule shader_module = std::move(module.value);
85+
ContextVK::SetDebugName(device, *shader_module,
86+
"shader_module_" + key_name);
87+
8388
functions[ShaderKey{key_name, stage}] = std::shared_ptr<ShaderFunctionVK>(
84-
new ShaderFunctionVK(library_id, //
85-
key_name, //
86-
stage, //
87-
std::move(module.value) //
89+
new ShaderFunctionVK(library_id, //
90+
key_name, //
91+
stage, //
92+
std::move(shader_module) //
8893
));
8994

9095
return true;

0 commit comments

Comments
 (0)