DebugUtilsMessengerVk.h#

The PVRVk DebugUtilsMessenger class.

Includes#

  • PVRVk/PVRVkObjectBaseVk.h

  • PVRVk/TypesVk.h

Included By#

Namespaces#

Classes#

Source Code#

#pragma once
#include "PVRVk/PVRVkObjectBaseVk.h"
#include "PVRVk/TypesVk.h"

namespace pvrvk {
struct DebugUtilsObjectNameInfo
{
public:
    DebugUtilsObjectNameInfo() : _objectType(ObjectType::e_UNKNOWN), _objectHandle(static_cast<uint64_t>(-1)), _objectName("") {}

    DebugUtilsObjectNameInfo(ObjectType objectType, uint64_t objectHandle, const std::string& objectName)
        : _objectType(objectType), _objectHandle(objectHandle), _objectName(objectName)
    {}

    ObjectType getObjectType() const { return _objectType; }

    void setObjectType(ObjectType objectType) { this->_objectType = objectType; }

    uint64_t getObjectHandle() const { return _objectHandle; }

    void setObjectHandle(uint64_t objectHandle) { this->_objectHandle = objectHandle; }

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

    void setObjectName(const std::string& objectName) { this->_objectName = objectName; }

private:
    ObjectType _objectType;
    uint64_t _objectHandle;
    std::string _objectName;
};

struct DebugUtilsObjectTagInfo
{
public:
    DebugUtilsObjectTagInfo() : _objectType(ObjectType::e_UNKNOWN), _objectHandle(static_cast<uint64_t>(-1)), _tagName(static_cast<uint64_t>(-1)), _tagSize(0), _tag(nullptr) {}

    DebugUtilsObjectTagInfo(ObjectType objectType, uint64_t objectHandle, uint64_t tagName, size_t tagSize, const void* pTag)
        : _objectType(objectType), _objectHandle(objectHandle), _tagName(tagName), _tagSize(tagSize), _tag(pTag)
    {}

    ObjectType getObjectType() const { return _objectType; }

    void setObjectType(ObjectType objectType) { this->_objectType = objectType; }

    uint64_t getObjectHandle() const { return _objectHandle; }

    void setObjectHandle(uint64_t objectHandle) { this->_objectHandle = objectHandle; }

    uint64_t getTagName() const { return _tagName; }

    void setTagName(uint64_t tagName) { this->_tagName = tagName; }

    size_t getTagSize() const { return this->_tagSize; }

    void setTagSize(size_t tagSize) { this->_tagSize = tagSize; }

    const void* getTag() const { return _tag; }

    void setTag(const void* tag) { this->_tag = tag; }

private:
    ObjectType _objectType;
    uint64_t _objectHandle;
    uint64_t _tagName;
    size_t _tagSize;
    const void* _tag;
};

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

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

    const std::string& getLabelName() const { return _labelName; }

    void setLabelName(const std::string& labelName) { this->_labelName = labelName; }

    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 _labelName;
    float _color[4];
};

struct DebugUtilsMessengerCallbackData
{
public:
    DebugUtilsMessengerCallbackData()
        : _flags(DebugUtilsMessengerCallbackDataFlagsEXT::e_NONE), _messageIdName(""), _messageIdNumber(-1), _message(""), _queueLabels(std::vector<DebugUtilsLabel>()),
          _cmdBufLabels(std::vector<DebugUtilsLabel>()), _objects(std::vector<DebugUtilsObjectNameInfo>())
    {}

    DebugUtilsMessengerCallbackData(DebugUtilsMessengerCallbackDataFlagsEXT flags, const std::string& messageIdName, int32_t messageIdNumber, const std::string& message,
        std::vector<DebugUtilsLabel>& queueLabels, std::vector<DebugUtilsLabel>& cmdBufLabels, std::vector<DebugUtilsObjectNameInfo>& objects)
        : _flags(flags), _messageIdName(messageIdName), _messageIdNumber(messageIdNumber), _message(message), _queueLabels(queueLabels), _cmdBufLabels(cmdBufLabels), _objects(objects)
    {}

    DebugUtilsMessengerCallbackDataFlagsEXT getFlags() const { return _flags; }

    void setFlags(DebugUtilsMessengerCallbackDataFlagsEXT flags) { this->_flags = flags; }

    const std::string& getMessageIdName() const { return _messageIdName; }

    void setMessageIdName(const std::string& messageIdName) { this->_messageIdName = messageIdName; }

    int32_t getMessageIdNumber() const { return _messageIdNumber; }

    void setMessageIdName(int32_t messageIdNumber) { this->_messageIdNumber = messageIdNumber; }

    const std::string& getMessage() const { return _message; }

    void setMessage(const std::string& message) { this->_message = message; }

    inline uint32_t getNumQueueLabels() const { return static_cast<uint32_t>(_queueLabels.size()); }
    inline const std::vector<DebugUtilsLabel>& getQueueLabels() const { return _queueLabels; }
    inline const DebugUtilsLabel& getQueueLabel(uint32_t index) const { return _queueLabels[index]; }
    inline void setQueueLabels(const std::vector<DebugUtilsLabel>& queueLabels)
    {
        this->_queueLabels.resize(queueLabels.size());
        std::copy(queueLabels.begin(), queueLabels.end(), this->_queueLabels.begin());
    }
    inline void addQueueLabel(const DebugUtilsLabel& queueLabel) { this->_queueLabels.emplace_back(queueLabel); }

    inline uint32_t getNumCmdBufLabels() const { return static_cast<uint32_t>(_cmdBufLabels.size()); }
    inline const std::vector<DebugUtilsLabel>& getCmdBufLabels() const { return _cmdBufLabels; }
    inline const DebugUtilsLabel& getCmdBufLabel(uint32_t index) const { return _cmdBufLabels[index]; }
    inline void setCmdBufLabels(const std::vector<DebugUtilsLabel>& cmdBufLabels)
    {
        this->_cmdBufLabels.resize(cmdBufLabels.size());
        std::copy(cmdBufLabels.begin(), cmdBufLabels.end(), this->_cmdBufLabels.begin());
    }
    inline void addCmdBufLabel(const DebugUtilsLabel& cmdBufLabel) { this->_cmdBufLabels.emplace_back(cmdBufLabel); }

    inline uint32_t getNumObjects() const { return static_cast<uint32_t>(_objects.size()); }
    inline const std::vector<DebugUtilsObjectNameInfo>& getObjects() const { return _objects; }
    inline const DebugUtilsObjectNameInfo& getObject(uint32_t index) const { return _objects[index]; }
    inline void setObjects(const std::vector<DebugUtilsObjectNameInfo>& objects)
    {
        this->_objects.resize(objects.size());
        std::copy(objects.begin(), objects.end(), this->_objects.begin());
    }
    inline void addCmdBufLabel(const DebugUtilsObjectNameInfo& cmdBufLabel) { this->_objects.emplace_back(cmdBufLabel); }

private:
    DebugUtilsMessengerCallbackDataFlagsEXT _flags;
    std::string _messageIdName;
    int32_t _messageIdNumber;
    std::string _message;
    std::vector<DebugUtilsLabel> _queueLabels;
    std::vector<DebugUtilsLabel> _cmdBufLabels;
    std::vector<DebugUtilsObjectNameInfo> _objects;
};

struct DebugUtilsMessengerCreateInfo
{
public:
    DebugUtilsMessengerCreateInfo()
        : _flags(DebugUtilsMessengerCreateFlagsEXT::e_NONE), _messageSeverity(DebugUtilsMessageSeverityFlagsEXT::e_NONE), _messageType(DebugUtilsMessageTypeFlagsEXT::e_NONE),
          _callback(nullptr), _userData(nullptr)
    {}

    DebugUtilsMessengerCreateInfo(DebugUtilsMessageSeverityFlagsEXT messageSeverity, DebugUtilsMessageTypeFlagsEXT messageType, PFN_vkDebugUtilsMessengerCallbackEXT callback,
        void* pUserData = nullptr, DebugUtilsMessengerCreateFlagsEXT flags = DebugUtilsMessengerCreateFlagsEXT::e_NONE)
        : _flags(flags), _messageSeverity(messageSeverity), _messageType(messageType), _callback(callback), _userData(pUserData)
    {}

    DebugUtilsMessengerCreateFlagsEXT getFlags() const { return _flags; }

    DebugUtilsMessengerCreateInfo& setFlags(const DebugUtilsMessengerCreateFlagsEXT& flags)
    {
        this->_flags = flags;
        return *this;
    }

    DebugUtilsMessageSeverityFlagsEXT getMessageSeverity() const { return _messageSeverity; }

    DebugUtilsMessengerCreateInfo& setMessageSeverity(const DebugUtilsMessageSeverityFlagsEXT& messageSeverity)
    {
        this->_messageSeverity = messageSeverity;
        return *this;
    }

    DebugUtilsMessageTypeFlagsEXT getMessageType() const { return _messageType; }

    DebugUtilsMessengerCreateInfo& setMessageType(const DebugUtilsMessageTypeFlagsEXT& messageType)
    {
        this->_messageType = messageType;
        return *this;
    }

    PFN_vkDebugUtilsMessengerCallbackEXT getCallback() const { return _callback; }

    DebugUtilsMessengerCreateInfo& setCallback(const PFN_vkDebugUtilsMessengerCallbackEXT& callback)
    {
        this->_callback = callback;
        return *this;
    }

    inline void* getPUserData() const { return _userData; }

    inline void setPUserData(void* pUserData) { this->_userData = pUserData; }

private:
    DebugUtilsMessengerCreateFlagsEXT _flags;
    DebugUtilsMessageSeverityFlagsEXT _messageSeverity;
    DebugUtilsMessageTypeFlagsEXT _messageType;
    PFN_vkDebugUtilsMessengerCallbackEXT _callback;
    void* _userData;
};

namespace impl {
class DebugUtilsMessenger_ : public PVRVkInstanceObjectBase<VkDebugUtilsMessengerEXT, ObjectType::e_DEBUG_UTILS_MESSENGER_EXT>
{
private:
    friend class Instance_;

    class make_shared_enabler
    {
    protected:
        make_shared_enabler() = default;
        friend class DebugUtilsMessenger_;
    };

    static DebugUtilsMessenger constructShared(Instance& instance, const DebugUtilsMessengerCreateInfo& createInfo)
    {
        return std::make_shared<DebugUtilsMessenger_>(make_shared_enabler{}, instance, createInfo);
    }

public:
    DECLARE_NO_COPY_SEMANTICS(DebugUtilsMessenger_)
    ~DebugUtilsMessenger_();
    DebugUtilsMessenger_(make_shared_enabler, Instance& instance, const DebugUtilsMessengerCreateInfo& createInfo);
};
} // namespace impl
} // namespace pvrvk