Foray Library
rapid prototyping framework for crossplatform development of vulkan hardware ray tracing applications
Loading...
Searching...
No Matches
foray_managedresource.hpp
Go to the documentation of this file.
1#pragma once
2#include "../foray_basics.hpp"
3#include "../foray_vulkan.hpp"
4#include <unordered_set>
5#include <spdlog/spdlog.h>
6
7namespace foray::core {
8
11 {
13 static inline std::unordered_set<ManagedResource*> sAllocatedRessources{};
14
15 public:
18 static void sPrintAllocatedResources(bool printAsWarning);
19 static const std::unordered_set<ManagedResource*>* GetTotalAllocatedResources() { return &sAllocatedRessources; }
20
23 virtual std::string_view GetTypeName() const;
26 virtual bool Exists() const = 0;
30 virtual void Destroy() = 0;
31
35 explicit ManagedResource(std::string_view name);
38
40 std::string_view GetName() const { return mName; }
42 virtual void SetName(std::string_view name);
43
45 std::string Print() const;
46
47 protected:
49 std::string mName;
50 };
51
53 std::string_view PrintVkObjectType(VkObjectType objecType);
54
57 template <VkObjectType OBJECT_TYPE>
59 {
60 public:
62 inline explicit VulkanResource(std::string_view name) : ManagedResource(name) {}
63
65 inline virtual std::string_view GetTypeName() const;
66
67 protected:
73 inline virtual void SetObjectName(core::Context* context, const void* handle, std::string_view name, bool updateResourceName = true);
74 };
75
76 template <VkObjectType OBJECT_TYPE>
77 inline std::string_view VulkanResource<OBJECT_TYPE>::GetTypeName() const
78 {
79 return PrintVkObjectType(OBJECT_TYPE);
80 }
81
82 template <VkObjectType OBJECT_TYPE>
83 inline void VulkanResource<OBJECT_TYPE>::SetObjectName(core::Context* context, const void* handle, std::string_view name, bool updateResourceName)
84 {
85#ifdef FORAY_DEBUG
86 SetVulkanObjectName(context, OBJECT_TYPE, handle, name);
87#endif
88 if(updateResourceName)
89 {
91 }
92 }
93
94} // namespace foray::core
Simple types for supressing automatic definition of duplicating move constructors & operator.
Definition foray_basics.hpp:19
Base class enforcing common interface for all classes wrapping a device resource.
Definition foray_managedresource.hpp:11
virtual void Destroy()=0
Destroy the resource.
virtual ~ManagedResource()
Unregisters the resource.
ManagedResource(std::string_view name)
Registers the resource and sets its name.
virtual bool Exists() const =0
Return true, if the managed resource is allocated.
std::string Print() const
Print name and type in one string.
static void sPrintAllocatedResources(bool printAsWarning)
Print a list of all registered existing resources.
static const std::unordered_set< ManagedResource * > * GetTotalAllocatedResources()
Definition foray_managedresource.hpp:19
std::string mName
This objects custom name.
Definition foray_managedresource.hpp:49
virtual std::string_view GetTypeName() const
Return a hint for the type of resource managed by the instantiation.
virtual void SetName(std::string_view name)
Set a custom name for the object.
ManagedResource()
Default constructor registers the resource.
std::string_view GetName() const
Return a custom name for the object.
Definition foray_managedresource.hpp:40
ManagedResource variant which automates GetTypeName() overloading by returning a stringified version ...
Definition foray_managedresource.hpp:59
virtual std::string_view GetTypeName() const
Returns <OBJECT_TYPE> stringified.
Definition foray_managedresource.hpp:77
VulkanResource(std::string_view name)
Definition foray_managedresource.hpp:62
virtual void SetObjectName(core::Context *context, const void *handle, std::string_view name, bool updateResourceName=true)
Set the object name. Sets both ManagedResource::mName aswell as vulkan debug object name.
Definition foray_managedresource.hpp:83
VulkanResource()
Definition foray_managedresource.hpp:61
Definition foray_commandbuffer.hpp:6
std::string_view PrintVkObjectType(VkObjectType objecType)
Uses nameof.hpp's NAMEOF_ENUM function to stringify VkObjectType.
void SetVulkanObjectName(core::Context *context, VkObjectType objectType, const void *objectHandle, std::string_view name)
Set a vulkan object name (Will show up in validation errors, NSight, RenderDoc, .....
Non owning context object.
Definition foray_context.hpp:16