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 UniqueQueue = std::unique_ptr< Queue >;
57 using QueueRef = std::reference_wrapper< Queue >;
59 template< typename T >
60 T VkAssert(const vk::ResultValue< T >& result, vk::Result expected = vk::Result::eSuccess)
62 assert(result.result == expected);
66 inline vk::Result VkAssert(vk::Result result, vk::Result expected = vk::Result::eSuccess)
68 assert(result == expected);
72 inline vk::Result VkTest(vk::Result result, vk::Result expected = vk::Result::eSuccess)
74 // todo: log if result different than expected?
78 template< typename T >
79 inline uint32_t U32(T value)
81 return static_cast< uint32_t >(value);
87 Resource() : mUserCount{0u} {}
88 virtual ~Resource() = default;
90 void IncreaseUserCount()
95 void DecreaseUserCount()
100 uint32_t GetUserCount() const
107 std::atomic<uint32_t> mUserCount;
111 * Vulkan object handle
120 explicit Handle(T* object );
121 Handle( const Handle& handle);
122 Handle& operator=( const Handle& handle );
123 Handle& operator=( Handle&& handle );
124 Handle( Handle&& handle ) noexcept;
127 operator bool() const;
129 T* operator->() const
134 uint32_t GetRefCount() const
136 return mObject->GetRefCount();
145 Handle<K> StaticCast()
147 return Handle<K>(static_cast<K*>(mObject));
151 bool operator==( const Handle<K>& object ) const
153 return mObject == &*object;
157 Handle<K> DynamicCast();
170 T* mObject { nullptr };
173 template <class K, class T>
174 static Handle<K> VkTypeCast( const Handle<T>& inval )
176 return Handle<K>(static_cast<K*>(&*inval));
180 Handle<T>::Handle(T* object)
196 Handle<T>::Handle(const Handle& handle)
198 mObject = handle.mObject;
206 Handle<T>::Handle( Handle&& handle ) noexcept
208 mObject = handle.mObject;
209 handle.mObject = nullptr;
213 Handle<T>::operator bool() const
215 return mObject != nullptr;
219 Handle<T>& Handle<T>::operator=( Handle&& handle )
221 mObject = handle.mObject;
222 handle.mObject = nullptr;
227 Handle<T>& Handle<T>::operator=( const Handle<T>& handle )
229 mObject = handle.mObject;
248 Handle<K> Handle<T>::DynamicCast()
250 auto val = dynamic_cast<K*>(mObject);
253 return Handle<K>(val);
258 template< typename T, typename... Args >
259 Handle< T > MakeRef(Args&&... args)
261 return Handle< T >(new T(std::forward< Args >(args)...));
264 template< typename T, typename... Args >
265 Handle< T > NewRef(Args&&... args)
267 return Handle< T >(T::New(std::forward< Args >(args)...));
272 typename T::Impl& GetImpl( Handle<T>& object )
274 return static_cast<typename T::Impl&>(*object->mImpl);
281 VkManaged() = default;
282 virtual ~VkManaged() = default;
286 OnRelease(--mRefCount);
299 OnRetain(++mRefCount);
302 uint32_t GetRefCount()
312 virtual void OnRetain( uint32_t refcount ) {};
314 virtual void OnRelease( uint32_t refcount ) {};
316 virtual bool OnDestroy() { return false; };
320 std::atomic_uint mRefCount { 0u };
323 using FBID = int32_t;
325 #define NotImplemented() \
327 printf("Function %s isn't implemented!\n", __FUNCTION__);\
328 assert( "Function no implemented" );\
332 * Forward declarations of reference types
334 using ShaderRef = Handle<class Shader>;
335 using PipelineRef = Handle<class Pipeline>;
336 using FenceRef = Handle<class Fence>;
337 using BufferRef = Handle<class Buffer>;
338 using FramebufferRef = Handle<class Framebuffer>;
339 using ImageRef = Handle<class Image>;
340 using ImageViewRef = Handle<class ImageView>;
341 using DescriptorPoolRef = Handle<class DescriptorPool>;
342 using CommandPoolRef = Handle<class CommandPool>;
343 using CommandBufferRef = Handle<class CommandBuffer>;
344 using GpuMemoryBlockRef = Handle<class GpuMemoryBlock>;
345 using DescriptorSetRef = Handle<class DescriptorSet>;
346 using SwapchainRef = Handle<class Swapchain>;
347 using SurfaceRef = Handle<class Surface>;
350 #pragma GCC diagnostic push
351 #pragma GCC diagnostic ignored "-Wframe-larger-than="
352 #pragma GCC diagnostic pop
354 } // namespace Vulkan
355 } // namespace Graphics
358 #endif // DALI_GRAPHICS_VULKAN_TYPES