1 #ifndef DALI_GRAPHICS_VULKAN_TYPES_H
2 #define DALI_GRAPHICS_VULKAN_TYPES_H
5 * Copyright (c) 2017 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
57 * Unique pointers to Vulkan types
59 using UniqueSurface = std::unique_ptr< Surface >;
60 using UniqueCommandBuffer = std::unique_ptr< CommandBuffer >;
61 using UniqueCommandPool = std::unique_ptr< CommandPool >;
62 using UniqueQueue = std::unique_ptr< Queue >;
63 using UniqueFence = std::unique_ptr< Fence >;
64 using UniqueDeviceMemory = std::unique_ptr< DeviceMemory >;
65 using UniqueBuffer = std::unique_ptr< Buffer >;
66 using UniqueImage = std::unique_ptr< Image >;
67 using UniqueImageView = std::unique_ptr< ImageView >;
72 using CommandBufferRef = std::reference_wrapper< CommandBuffer >;
73 using QueueRef = std::reference_wrapper< Queue >;
74 using FenceRef = std::reference_wrapper< Fence >;
75 using SurfaceRef = std::reference_wrapper< Surface >;
79 template< typename T >
80 T VkAssert(const vk::ResultValue< T >& result, vk::Result expected = vk::Result::eSuccess)
82 assert(result.result == expected);
86 inline vk::Result VkAssert(vk::Result result, vk::Result expected = vk::Result::eSuccess)
88 assert(result == expected);
92 inline vk::Result VkTest(vk::Result result, vk::Result expected = vk::Result::eSuccess)
94 // todo: log if result different than expected?
98 template< typename T >
99 inline uint32_t U32(T value)
101 return static_cast< uint32_t >(value);
107 Resource() : mUserCount{0u} {}
108 virtual ~Resource() = default;
110 void IncreaseUserCount()
115 void DecreaseUserCount()
120 uint32_t GetUserCount() const
127 std::atomic<uint32_t> mUserCount;
130 template< typename T>
135 ResourceRef( T& object )
138 mObject->IncreaseUserCount();
141 ResourceRef( ResourceRef& object )
145 mObject->DecreaseUserCount();
148 mObject = object.mObject;
149 mObject->IncreaseUserCount();
152 ResourceRef operator=(ResourceRef& object )
156 mObject->DecreaseUserCount();
159 mObject = object.mObject;
160 mObject->IncreaseUserCount();
167 mObject->DecreaseUserCount();
171 T& GetResource() const
181 using FBID = uint32_t;
183 #define NotImplemented() \
185 printf("Function %s isn't implemented!\n", __FUNCTION__);\
186 assert( "Function no implemented" );\
190 #pragma GCC diagnostic push
191 #pragma GCC diagnostic ignored "-Wframe-larger-than="
192 #pragma GCC diagnostic pop
194 } // namespace Vulkan
195 } // namespace Graphics
198 #endif // DALI_GRAPHICS_VULKAN_TYPES_H