Diligent Engine  v.2.4.g
ManagedVulkanObject.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2019-2021 Diligent Graphics LLC
3  * Copyright 2015-2019 Egor Yusov
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * In no event and under no legal theory, whether in tort (including negligence),
18  * contract, or otherwise, unless required by applicable law (such as deliberate
19  * and grossly negligent acts) or agreed to in writing, shall any Contributor be
20  * liable for any damages, including any direct, indirect, special, incidental,
21  * or consequential damages of any character arising as a result of this License or
22  * out of the use or inability to use the software (including but not limited to damages
23  * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
24  * all other commercial damages or losses), even if such Contributor has been advised
25  * of the possibility of such damages.
26  */
27 
28 #pragma once
29 
30 #include "DeviceObjectBase.hpp"
32 #include "RenderDeviceVkImpl.hpp" // Required by by ~ManagedVulkanObject()
33 
34 namespace Diligent
35 {
36 
37 template <typename VulkanObjectWrapperType>
38 class ManagedVulkanObject : public DeviceObjectBase<IDeviceObject, RenderDeviceVkImpl, DeviceObjectAttribs>
39 {
40 public:
42 
44  RenderDeviceVkImpl* pDevice,
45  const DeviceObjectAttribs& ObjDesc,
46  VulkanObjectWrapperType&& ObjectWrapper,
47  bool bIsDeviceInternal = false) :
48  TDeviceObjectBase{pRefCounters, pDevice, ObjDesc, bIsDeviceInternal},
49  m_VkObject{std::move(ObjectWrapper)}
50  {
51  }
52 
54  {
55  m_pDevice->SafeReleaseDeviceObject(std::move(m_VkObject), ~Uint64{0});
56  }
57 
58  static void Create(RenderDeviceVkImpl* pDevice,
59  VulkanObjectWrapperType&& ObjectWrapper,
60  const char* Name,
61  ManagedVulkanObject** ppManagedObject)
62  {
64  Desc.Name = Name;
65  auto* pObj(NEW_RC_OBJ(GetRawAllocator(), "ManagedVulkanObject instance", ManagedVulkanObject)(pDevice, Desc, std::move(ObjectWrapper)));
66  pObj->QueryInterface(IID_DeviceObject, reinterpret_cast<IObject**>(ppManagedObject));
67  }
68 
69  typename VulkanObjectWrapperType::VkObjectType Get() const
70  {
71  return m_VkObject;
72  }
73 
74 private:
75  VulkanObjectWrapperType m_VkObject;
76 };
77 
79 
80 } // namespace Diligent
VulkanLogicalDevice.hpp
Diligent::IReferenceCounters
Base interface for a reference counter object that stores the number of strong and weak references an...
Definition: ReferenceCounters.h:44
Diligent::RenderDeviceVkImpl
Render device implementation in Vulkan backend.
Definition: RenderDeviceVkImpl.hpp:58
Diligent::DeviceObjectBase< IDeviceObject, RenderDeviceVkImpl, DeviceObjectAttribs >::m_pDevice
RenderDeviceVkImpl *const m_pDevice
Pointer to the device.
Definition: DeviceObjectBase.hpp:179
DeviceObjectBase.hpp
Diligent::IObject
Base interface for all dynamic objects in the engine.
Definition: Object.h:41
Diligent::Uint64
uint64_t Uint64
64-bit unsigned integer
Definition: BasicTypes.h:50
Diligent::ManagedVulkanObject
Definition: ManagedVulkanObject.hpp:38
Diligent::ManagedVulkanObject::~ManagedVulkanObject
~ManagedVulkanObject()
Definition: ManagedVulkanObject.hpp:53
Diligent::DeviceObjectAttribs
Describes common device object attributes.
Definition: GraphicsTypes.h:1196
Diligent::GetRawAllocator
IMemoryAllocator & GetRawAllocator()
Returns raw memory allocator.
Definition: EngineMemory.cpp:51
Diligent::RenderDeviceNextGenBase::SafeReleaseDeviceObject
void SafeReleaseDeviceObject(ObjectType &&Object, Uint64 QueueMask)
Definition: RenderDeviceNextGenBase.hpp:98
Diligent::ManagedVulkanObject::Get
VulkanObjectWrapperType::VkObjectType Get() const
Definition: ManagedVulkanObject.hpp:69
Diligent::ManagedVulkanObject::ManagedVulkanObject
ManagedVulkanObject(IReferenceCounters *pRefCounters, RenderDeviceVkImpl *pDevice, const DeviceObjectAttribs &ObjDesc, VulkanObjectWrapperType &&ObjectWrapper, bool bIsDeviceInternal=false)
Definition: ManagedVulkanObject.hpp:43
Diligent::ManagedVulkanObject::Create
static void Create(RenderDeviceVkImpl *pDevice, VulkanObjectWrapperType &&ObjectWrapper, const char *Name, ManagedVulkanObject **ppManagedObject)
Definition: ManagedVulkanObject.hpp:58
RenderDeviceVkImpl.hpp
NEW_RC_OBJ
#define NEW_RC_OBJ(Allocator, Desc, Type,...)
Definition: RefCountedObjectImpl.hpp:698
Diligent::DeviceObjectAttribs::Name
const Char * Name
Object name.
Definition: GraphicsTypes.h:1199
Diligent::DeviceObjectBase
Template class implementing base functionality of the device object.
Definition: DeviceObjectBase.hpp:45
Diligent
The library uses Direct3D-style math:
Definition: AdvancedMath.hpp:37