Files
test/source/blender/gpu/vulkan/vk_debug.hh
Hans Goudey 9b97ba1462 Cleanup: GPU: Avoid raw pointers for shader API strings
Avoid measuring the length of strings repeatedly by passing their
length along with their data with `StringRefNull`. Null termination
seems to be necessary still for passing the shader sources to OpenGL.
Though I doubt this is a bottleneck, it's still nice to avoid overhead from
string operations and this helps move in that direction.

Pull Request: https://projects.blender.org/blender/blender/pulls/127702
2024-11-01 20:00:31 +01:00

63 lines
1.7 KiB
C++

/* SPDX-FileCopyrightText: 2023 Blender Authors All rights reserved.
*
* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup gpu
*/
#pragma once
#include "BKE_global.hh"
#include "BLI_compiler_attrs.h"
#include "BLI_set.hh"
#include "BLI_string.h"
#include "vk_common.hh"
#include <typeindex>
namespace blender::gpu {
class VKContext;
class VKDevice;
namespace debug {
class VKDebuggingTools {
public:
void init(VkInstance vk_instance);
void deinit(VkInstance vk_instance);
void init_messenger(VkInstance vk_instance);
void destroy_messenger(VkInstance vk_instance);
void print_labels(const VkDebugUtilsMessengerCallbackDataEXT *callback_data);
private:
VkDebugUtilsMessengerEXT vk_debug_utils_messenger = nullptr;
};
void object_label(VkObjectType vk_object_type, uint64_t object_handle, const char *name);
template<typename T> void object_label(T vk_object_type, const StringRefNull name)
{
if (!(G.debug & G_DEBUG_GPU)) {
return;
}
const size_t label_size = 64;
char label[label_size];
memset(label, 0, label_size);
static int stats = 0;
SNPRINTF(label, "%s_%d", name.c_str(), stats++);
object_label(to_vk_object_type(vk_object_type), (uint64_t)vk_object_type, (const char *)label);
};
/**
* How to use:
* \code{.cc}
* debug::raise_message(0xB41ca2, VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT,
* "This is a raise message. %llx", (uintptr_t)vk_object);
* \endcode
*/
void raise_message(int32_t id_number,
VkDebugUtilsMessageSeverityFlagBitsEXT vk_severity_flag_bits,
const char *fmt,
...) ATTR_PRINTF_FORMAT(3, 4);
} // namespace debug
} // namespace blender::gpu