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.
24 #pragma GCC diagnostic push
25 #pragma GCC diagnostic ignored "-Wfloat-equal"
26 #include <vulkan/vulkan.hpp>
27 #pragma GCC diagnostic pop
31 #include <unordered_map>
33 #ifndef VULKAN_HPP_NO_EXCEPTIONS
34 #define VULKAN_HPP_NO_EXCEPTIONS
42 template< typename T, typename... Args >
43 std::unique_ptr< T > MakeUnique(Args&&... args)
45 return std::unique_ptr< T >(new T(std::forward< Args >(args)...));
52 * Forward class declarations
66 * Unique pointers to Vulkan types
68 using UniqueSurface = std::unique_ptr< Surface >;
69 using UniqueCommandBuffer = std::unique_ptr< CommandBuffer >;
70 using UniqueCommandPool = std::unique_ptr< CommandPool >;
71 using UniqueQueue = std::unique_ptr< Queue >;
72 using UniqueFence = std::unique_ptr< Fence >;
73 using UniqueDeviceMemory = std::unique_ptr< DeviceMemory >;
74 using UniqueBuffer = std::unique_ptr< Buffer >;
75 using UniqueImage = std::unique_ptr< Image >;
76 using UniqueImageView = std::unique_ptr< ImageView >;
81 using CommandBufferRef = std::reference_wrapper< CommandBuffer >;
82 using QueueRef = std::reference_wrapper< Queue >;
83 using FenceRef = std::reference_wrapper< Fence >;
84 using SurfaceRef = std::reference_wrapper< Surface >;
88 template< typename T >
89 T VkAssert(const vk::ResultValue< T >& result, vk::Result expected = vk::Result::eSuccess)
91 assert(result.result == expected);
95 inline vk::Result VkAssert(vk::Result result, vk::Result expected = vk::Result::eSuccess)
97 assert(result == expected);
101 inline vk::Result VkTest(vk::Result result, vk::Result expected = vk::Result::eSuccess)
103 // todo: log if result different than expected?
107 template< typename T >
108 inline uint32_t U32(T value)
110 return static_cast< uint32_t >(value);
116 Resource() : mUserCount{0u} {}
117 virtual ~Resource() = default;
119 void IncreaseUserCount()
124 void DecreaseUserCount()
129 uint32_t GetUserCount() const
136 std::atomic<uint32_t> mUserCount;
139 template< typename T>
144 ResourceRef( T& object )
147 mObject->IncreaseUserCount();
150 ResourceRef( ResourceRef& object )
154 mObject->DecreaseUserCount();
157 mObject = object.mObject;
158 mObject->IncreaseUserCount();
161 ResourceRef operator=(ResourceRef& object )
165 mObject->DecreaseUserCount();
168 mObject = object.mObject;
169 mObject->IncreaseUserCount();
176 mObject->DecreaseUserCount();
180 T& GetResource() const
190 using FBID = uint32_t;
192 #define NotImplemented() \
194 printf("Function %s isn't implemented!\n", __FUNCTION__);\
195 assert( "Function no implemented" );\
199 #pragma GCC diagnostic push
200 #pragma GCC diagnostic ignored "-Wframe-larger-than="
201 #pragma GCC diagnostic pop
203 } // namespace Vulkan
204 } // namespace Graphics
207 #endif // DALI_GRAPHICS_VULKAN_TYPES_H