[Vulkan] Basic Vulkan backend
[platform/core/uifw/dali-core.git] / dali / graphics / vulkan / gpu-memory / vulkan-gpu-memory-allocator.h
1 #ifndef DALI_GRAPHICS_VULKAN_GPU_MEMORY_ALLOCATOR
2 #define DALI_GRAPHICS_VULKAN_GPU_MEMORY_ALLOCATOR
3
4 /*
5  * Copyright (c) 2018 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20 #include <dali/graphics/vulkan/vulkan-types.h>
21 #include <dali/graphics/vulkan/gpu-memory/vulkan-gpu-memory-handle.h>
22 namespace Dali
23 {
24 namespace Graphics
25 {
26 namespace Vulkan
27 {
28 class Buffer;
29 class Image;
30 class GpuMemoryBlock;
31 /**
32  * Interface to Gpu memory allocation, must be overriden.
33  */
34 using GpuMemoryAllocationData = void*;
35
36 class GpuMemoryAllocator
37 {
38 public:
39
40   GpuMemoryAllocator() = default;
41
42   /**
43    *
44    */
45   virtual ~GpuMemoryAllocator() = default;
46
47   /**
48    *
49    * @param requirements
50    * @param memoryProperties
51    * @return
52    */
53   virtual GpuMemoryBlockHandle Allocate( const vk::MemoryRequirements& requirements, vk::MemoryPropertyFlags memoryProperties ) = 0;
54
55   /**
56    *
57    * @param buffer
58    * @param memoryProperties
59    * @return
60    */
61   virtual GpuMemoryBlockHandle Allocate( const Handle<Buffer>& buffer, vk::MemoryPropertyFlags memoryProperties ) = 0;
62
63   /**
64    *
65    * @param buffer
66    * @param memoryProperties
67    * @return
68    */
69   virtual GpuMemoryBlockHandle Allocate( Image& buffer, vk::MemoryPropertyFlags memoryProperties ) = 0;
70
71   // refcounting managed via allocator which ownes all the blocks, allocator may
72   // implement this feature any way ( or simply ignore it )
73   /**
74    *
75    * @param allocationId
76    */
77   virtual void Retain( GpuMemoryBlock& allocationId ) {}
78
79   /**
80    *
81    * @param allocationId
82    */
83   virtual void Release( GpuMemoryBlock& allocationId ) {}
84
85   /**
86    *
87    * @param allocationId
88    */
89   virtual uint32_t GetRefCount( GpuMemoryBlock& allocationId )
90   {
91     return 0u;
92   }
93
94   // Garbage collection
95   /**
96    *
97    * @param userdata
98    */
99   virtual void GC( void* userdata ) = 0;
100
101   // Retrieve Vulkan object for this allocation
102   /**
103    *
104    * @return
105    */
106   virtual vk::DeviceMemory GetVkDeviceMemory( GpuMemoryBlock& allocationId ) const = 0;
107
108   /**
109    * Memory mapping
110    * @param allocationId
111    * @param offset
112    * @param size
113    * @return
114    */
115   virtual void* Map( GpuMemoryBlock& allocationId, uint32_t offset, uint32_t size ) = 0;
116
117   /**
118    * Memory mapping
119    * @param allocationId
120    * @param offset
121    * @param size
122    * @return
123    */
124   virtual void Unmap( GpuMemoryBlock& allocationId ) = 0;
125
126   /**
127    *
128    * @param allocationId
129    */
130   virtual void Flush( GpuMemoryBlock& allocationId ) = 0;
131 };
132
133 } // Namespace Vulkan
134
135 } // namespace Graphics
136
137 } // Namespace Dali
138
139 #endif // DALI_GRAPHICS_VULKAN_GPU_MEMORY_ALLOCATOR