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

[Impeller] Add debug names to additional VK objects #37592

Merged
merged 2 commits into from
Nov 15, 2022
Merged
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
18 changes: 13 additions & 5 deletions impeller/renderer/backend/vulkan/context_vk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "impeller/renderer/backend/vulkan/context_vk.h"

#include <map>
#include <memory>
#include <optional>
#include <set>
#include <string>
Expand Down Expand Up @@ -51,6 +52,15 @@ VKAPI_ATTR VkBool32 VKAPI_CALL DebugUtilsMessengerCallback(

namespace impeller {

namespace vk {

bool HasValidationLayers() {
auto capabilities = std::make_unique<CapabilitiesVK>();
return capabilities->HasLayer(kKhronosValidationLayerName);
}

} // namespace vk

static std::set<std::string> kRequiredDeviceExtensions = {
VK_KHR_SWAPCHAIN_EXTENSION_NAME,
#if FML_OS_MACOSX
Expand Down Expand Up @@ -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;
Expand Down
24 changes: 22 additions & 2 deletions impeller/renderer/backend/vulkan/context_vk.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<ContextVK, Context> {
public:
static std::shared_ptr<ContextVK> Create(
Expand All @@ -40,12 +49,23 @@ class ContextVK final : public Context, public BackendCast<ContextVK, Context> {

template <typename T>
bool SetDebugName(T handle, std::string_view label) const {
return SetDebugName(*device_, handle, label);
}

template <typename T>
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<uint64_t>(static_cast<typename T::NativeType>(handle));

std::string label_str = std::string(label);

auto ret = device_->setDebugUtilsObjectNameEXT(
auto ret = device.setDebugUtilsObjectNameEXT(
vk::DebugUtilsObjectNameInfoEXT()
.setObjectType(T::objectType)
.setObjectHandle(handle_ptr)
Expand Down
8 changes: 8 additions & 0 deletions impeller/renderer/backend/vulkan/pipeline_library_vk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -372,6 +373,8 @@ std::unique_ptr<PipelineCreateInfoVK> 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());
Expand Down Expand Up @@ -403,6 +406,11 @@ std::unique_ptr<PipelineCreateInfoVK> 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<PipelineCreateInfoVK>(
std::move(pipeline.value), std::move(render_pass.value()),
std::move(pipeline_layout.value), std::move(descriptor_set_layout));
Expand Down
13 changes: 9 additions & 4 deletions impeller/renderer/backend/vulkan/shader_library_vk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<ShaderFunctionVK>(
new ShaderFunctionVK(library_id, //
key_name, //
stage, //
std::move(module.value) //
new ShaderFunctionVK(library_id, //
key_name, //
stage, //
std::move(shader_module) //
));

return true;
Expand Down