1 #ifndef DALI_GRAPHICS_VULKAN_TYPES
2 #define DALI_GRAPHICS_VULKAN_TYPES
5 * Copyright (c) 2018 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
23 #include <unordered_map>
26 #include <dali/integration-api/graphics/vulkan/vulkan-hpp-wrapper.h>
33 template< typename T, typename... Args >
34 std::unique_ptr< T > MakeUnique(Args&&... args)
36 return std::unique_ptr< T >(new T(std::forward< Args >(args)...));
43 * Forward class declarations
50 * Unique pointers to Vulkan types
52 using UniqueSurface = std::unique_ptr< Surface >;
53 using UniqueQueue = std::unique_ptr< Queue >;
58 using QueueRef = std::reference_wrapper< Queue >;
59 using SurfaceRef = std::reference_wrapper< Surface >;
62 template< typename T >
63 T VkAssert(const vk::ResultValue< T >& result, vk::Result expected = vk::Result::eSuccess)
65 assert(result.result == expected);
69 inline vk::Result VkAssert(vk::Result result, vk::Result expected = vk::Result::eSuccess)
71 assert(result == expected);
75 inline vk::Result VkTest(vk::Result result, vk::Result expected = vk::Result::eSuccess)
77 // todo: log if result different than expected?
81 template< typename T >
82 inline uint32_t U32(T value)
84 return static_cast< uint32_t >(value);
90 Resource() : mUserCount{0u} {}
91 virtual ~Resource() = default;
93 void IncreaseUserCount()
98 void DecreaseUserCount()
103 uint32_t GetUserCount() const
110 std::atomic<uint32_t> mUserCount;
114 * Vulkan object handle
123 explicit Handle(T* object );
124 Handle( const Handle& handle);
125 Handle& operator=( const Handle& handle );
126 Handle& operator=( Handle&& handle );
127 Handle( Handle&& handle ) noexcept;
130 operator bool() const;
132 T* operator->() const
137 uint32_t GetRefCount() const
139 return mObject->GetRefCount();
148 Handle<K> StaticCast()
150 return Handle<K>(static_cast<K*>(mObject));
154 bool operator==( const Handle<K>& object ) const
156 return mObject == &*object;
160 Handle<K> DynamicCast();
173 T* mObject { nullptr };
176 template <class K, class T>
177 static Handle<K> VkTypeCast( const Handle<T>& inval )
179 return Handle<K>(static_cast<K*>(&*inval));
183 Handle<T>::Handle(T* object)
199 Handle<T>::Handle(const Handle& handle)
201 mObject = handle.mObject;
209 Handle<T>::Handle( Handle&& handle ) noexcept
211 mObject = handle.mObject;
212 handle.mObject = nullptr;
216 Handle<T>::operator bool() const
218 return mObject != nullptr;
222 Handle<T>& Handle<T>::operator=( Handle&& handle )
224 mObject = handle.mObject;
225 handle.mObject = nullptr;
230 Handle<T>& Handle<T>::operator=( const Handle<T>& handle )
232 mObject = handle.mObject;
251 Handle<K> Handle<T>::DynamicCast()
253 auto val = dynamic_cast<K*>(mObject);
256 return Handle<K>(val);
261 template< typename T, typename... Args >
262 Handle< T > MakeRef(Args&&... args)
264 return Handle< T >(new T(std::forward< Args >(args)...));
271 VkManaged() = default;
272 virtual ~VkManaged() = default;
276 OnRelease(--mRefCount);
289 OnRetain(++mRefCount);
292 uint32_t GetRefCount()
302 virtual void OnRetain( uint32_t refcount ) {};
304 virtual void OnRelease( uint32_t refcount ) {};
306 virtual bool OnDestroy() { return false; };
310 std::atomic_uint mRefCount { 0u };
313 using FBID = uint32_t;
315 #define NotImplemented() \
317 printf("Function %s isn't implemented!\n", __FUNCTION__);\
318 assert( "Function no implemented" );\
322 * Forward declarations of reference types
324 using ShaderRef = Handle<class Shader>;
325 using PipelineRef = Handle<class Pipeline>;
326 using FenceRef = Handle<class Fence>;
327 using BufferRef = Handle<class Buffer>;
328 using FramebufferRef = Handle<class Framebuffer>;
329 using ImageRef = Handle<class Image>;
330 using ImageViewRef = Handle<class ImageView>;
331 using DescriptorPoolRef = Handle<class DescriptorPool>;
332 using CommandPoolRef = Handle<class CommandPool>;
333 using CommandBufferRef = Handle<class CommandBuffer>;
336 #pragma GCC diagnostic push
337 #pragma GCC diagnostic ignored "-Wframe-larger-than="
338 #pragma GCC diagnostic pop
340 } // namespace Vulkan
341 } // namespace Graphics
344 #endif // DALI_GRAPHICS_VULKAN_TYPES