UraniumCompute 0.1.0
A GPU accelerated parallel task scheduler
DeviceObjectBase.h
1#pragma once
2#include <UnCompute/Backend/IComputeDevice.h>
3#include <UnCompute/Backend/IDeviceObject.h>
4#include <UnCompute/Memory/Ptr.h>
5
6namespace UN
7{
16 template<class TInterface, std::enable_if_t<std::is_base_of_v<IDeviceObject, TInterface>, bool> = true>
17 class DeviceObjectBase : public Object<TInterface>
18 {
19 public:
20 using DescriptorType = typename TInterface::DescriptorType;
21
22 protected:
23 Ptr<IComputeDevice> m_pDevice;
24 DescriptorType m_Desc;
25 std::string m_Name;
26
31 inline void Init(std::string_view name, const DescriptorType& desc)
32 {
33 m_Name = name;
34 m_Desc = desc;
35 }
36
37 inline explicit DeviceObjectBase(IComputeDevice* pDevice)
38 : m_pDevice(pDevice)
39 {
40 }
41
42 public:
43 inline const DescriptorType& GetDesc() const override
44 {
45 return m_Desc;
46 }
47
48 [[nodiscard]] inline std::string_view GetDebugName() const override
49 {
50 return m_Name;
51 }
52
53 [[nodiscard]] inline IComputeDevice* GetDevice() const override
54 {
55 return m_pDevice.Get();
56 }
57
58 [[nodiscard]] inline UInt32 Release() override
59 {
60 Ptr<IComputeDevice> pDevice;
61 return Object<TInterface>::Release([this, &pDevice] {
62 pDevice = m_pDevice;
63 });
64 }
65 };
66} // namespace UN
Base class for all compute backend objects.
Definition: DeviceObjectBase.h:18
void Init(std::string_view name, const DescriptorType &desc)
Common device object initializer.
Definition: DeviceObjectBase.h:31
Interface for all backend-specific compute devices.
Definition: IComputeDevice.h:38
Base class for dynamic reference counted objects.
Definition: Object.h:51
UInt32 Release() override
Definition: Object.h:82
Shared smart pointer implementation that uses reference counting.
Definition: Ptr.h:44
T * Get() const
Get underlying raw pointer.
Definition: Ptr.h:219