DebugUtilsVk.h#

A wrapper providing support for object annotation i.e. naming and tagging via the use of VK_EXT_debug_marker or VK_EXT_debug_utils. PVRVk supports the extensions “VK_EXT_debug_maker” and “VK_EXT_debug_utils” by inheriting from DeviceObjectDebugUtils.

Includes#

  • PVRVk/ForwardDecObjectsVk.h

Included By#

Namespaces#

Classes#

Source Code#

#pragma once
#include "PVRVk/ForwardDecObjectsVk.h"

namespace pvrvk {

struct DebugMarkerMarkerInfo
{
public:
    DebugMarkerMarkerInfo() : _markerName("")
    {
        _color[0] = { 0.0f };
        _color[1] = { 0.0f };
        _color[2] = { 0.0f };
        _color[3] = { 0.0f };
    }

    DebugMarkerMarkerInfo(const std::string& markerName, float colorR = 183.0f / 255.0f, float colorG = 26.0f / 255.0f, float colorB = 139.0f / 255.0f, float colorA = 1.0f)
        : _markerName(markerName)
    {
        _color[0] = colorR;
        _color[1] = colorG;
        _color[2] = colorB;
        _color[3] = colorA;
    }

    const std::string& getMarkerName() const { return _markerName; }

    void setMarkerName(const std::string& markerName) { this->_markerName = markerName; }

    float getR() const { return _color[0]; }

    void setR(const float r) { this->_color[0] = r; }

    float getG() const { return _color[1]; }

    void setG(const float g) { this->_color[1] = g; }

    float getB() const { return _color[2]; }

    void setB(const float b) { this->_color[2] = b; }

    float getA() const { return _color[3]; }

    void setA(const float a) { this->_color[3] = a; }

private:
    std::string _markerName;
    float _color[4];
};

namespace impl {
class DeviceDebugUtilsImpl
{
public:
    template<typename>
    friend class DeviceObjectDebugUtils;

    ~DeviceDebugUtilsImpl() {}

    void setObjectName(const Device_& device, uint64_t vkHandle, ObjectType objectType, const std::string& objectName);

    void setObjectTag(const Device_& device, uint64_t vkHandle, ObjectType objectType, uint64_t tagName, size_t tagSize, const void* tag);

    void resetObjectName(const Device_& device, uint64_t vkHandle, ObjectType objectType) { setObjectName(device, vkHandle, objectType, ""); }

    bool hasName() const { return _objectName.length() > 0; }

    const std::string& getName() const { return _objectName; }

private:
    DeviceDebugUtilsImpl() : _objectName("") {}

    std::string _objectName;
};

template<class PVRVkDeviceObject>
class DeviceObjectDebugUtils
{
public:
    explicit DeviceObjectDebugUtils() : _debugUtils() {}

    void setObjectName(const std::string& objectName)
    {
        _debugUtils.setObjectName(*static_cast<PVRVkDeviceObject&>(*this).getDevice().get(),
            *static_cast<const uint64_t*>(static_cast<const void*>(&static_cast<PVRVkDeviceObject&>(*this).getVkHandle())), static_cast<PVRVkDeviceObject&>(*this).getObjectType(),
            objectName);
    }

    const std::string& getObjectName() const { return _debugUtils.getName(); }

    void resetObjectName()
    {
        _debugUtils.setObjectName(*static_cast<PVRVkDeviceObject&>(*this).getDevice().get(),
            *static_cast<const uint64_t*>(static_cast<const void*>(&static_cast<PVRVkDeviceObject&>(*this).getVkHandle())), static_cast<PVRVkDeviceObject&>(*this).getObjectType(), "");
    }

    void setObjectTag(uint64_t tagName, size_t tagSize, const void* tag)
    {
        _debugUtils.setObjectTag(*static_cast<PVRVkDeviceObject&>(*this).getDevice().get(),
            *static_cast<const uint64_t*>(static_cast<const void*>(&static_cast<PVRVkDeviceObject&>(*this).getVkHandle())), static_cast<PVRVkDeviceObject&>(*this).getObjectType(),
            tagName, tagSize, tag);
    }

private:
    DeviceDebugUtilsImpl _debugUtils;
};
} // namespace impl
} // namespace pvrvk