Alexis Hetu | 67cf8a9 | 2019-05-09 17:46:07 -0400 | [diff] [blame] | 1 | // Copyright 2019 The SwiftShader Authors. All Rights Reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
Nicolas Capens | 52b5aae | 2019-05-24 16:27:55 -0400 | [diff] [blame] | 15 | #ifndef VULKAN_PLATFORM |
| 16 | #define VULKAN_PLATFORM |
| 17 | |
Alexis Hetu | 67cf8a9 | 2019-05-09 17:46:07 -0400 | [diff] [blame] | 18 | #include <cstddef> |
| 19 | #include <cstdint> |
Nicolas Capens | 522d512 | 2019-06-21 10:18:10 -0400 | [diff] [blame] | 20 | #include <type_traits> |
Alexis Hetu | 67cf8a9 | 2019-05-09 17:46:07 -0400 | [diff] [blame] | 21 | |
Alexis Hetu | bd4cf81 | 2019-06-14 15:14:07 -0400 | [diff] [blame] | 22 | template<typename T> class VkNonDispatchableHandle |
Alexis Hetu | 67cf8a9 | 2019-05-09 17:46:07 -0400 | [diff] [blame] | 23 | { |
| 24 | public: |
Alexis Hetu | 2d77aea | 2019-06-17 13:43:50 -0400 | [diff] [blame] | 25 | operator void*() const |
Alexis Hetu | f9e9cf6 | 2019-06-05 17:18:40 -0400 | [diff] [blame] | 26 | { |
| 27 | static_assert(sizeof(VkNonDispatchableHandle) == sizeof(uint64_t), "Size is not 64 bits!"); |
Alexis Hetu | bd4cf81 | 2019-06-14 15:14:07 -0400 | [diff] [blame] | 28 | |
Alexis Hetu | 2d77aea | 2019-06-17 13:43:50 -0400 | [diff] [blame] | 29 | // VkNonDispatchabbleHandle must be POD to ensure it gets passed by value the same way as a uint64_t, |
| 30 | // which is the upstream header's handle type when compiled for 32b architectures. On 64b architectures, |
| 31 | // the upstream header's handle type is a pointer type. |
| 32 | static_assert(std::is_trivial<VkNonDispatchableHandle<T>>::value, "VkNonDispatchableHandle<T> is not trivial!"); |
| 33 | static_assert(std::is_standard_layout<VkNonDispatchableHandle<T>>::value, "VkNonDispatchableHandle<T> is not standard layout!"); |
| 34 | |
Alexis Hetu | bd4cf81 | 2019-06-14 15:14:07 -0400 | [diff] [blame] | 35 | return reinterpret_cast<void*>(static_cast<uintptr_t>(handle)); |
| 36 | } |
| 37 | |
Alexis Hetu | 2d77aea | 2019-06-17 13:43:50 -0400 | [diff] [blame] | 38 | void operator=(uint64_t h) |
Alexis Hetu | bd4cf81 | 2019-06-14 15:14:07 -0400 | [diff] [blame] | 39 | { |
Alexis Hetu | 2d77aea | 2019-06-17 13:43:50 -0400 | [diff] [blame] | 40 | handle = h; |
Alexis Hetu | bd4cf81 | 2019-06-14 15:14:07 -0400 | [diff] [blame] | 41 | } |
| 42 | |
Alexis Hetu | bd4cf81 | 2019-06-14 15:14:07 -0400 | [diff] [blame] | 43 | uint64_t handle; |
Alexis Hetu | f9e9cf6 | 2019-06-05 17:18:40 -0400 | [diff] [blame] | 44 | }; |
| 45 | |
Alexis Hetu | 67cf8a9 | 2019-05-09 17:46:07 -0400 | [diff] [blame] | 46 | #define VK_DEFINE_NON_DISPATCHABLE_HANDLE(object) \ |
| 47 | typedef struct object##_T *object##Ptr; \ |
Alexis Hetu | f9e9cf6 | 2019-06-05 17:18:40 -0400 | [diff] [blame] | 48 | typedef VkNonDispatchableHandle<object##Ptr> object; \ |
Nicolas Capens | 522d512 | 2019-06-21 10:18:10 -0400 | [diff] [blame] | 49 | template class VkNonDispatchableHandle<object##Ptr>; |
Alexis Hetu | 67cf8a9 | 2019-05-09 17:46:07 -0400 | [diff] [blame] | 50 | |
| 51 | #include <vulkan/vulkan.h> |
| 52 | |
| 53 | #ifdef Bool |
| 54 | #undef Bool // b/127920555 |
| 55 | #undef None |
| 56 | #endif |
| 57 | |
Nicolas Capens | 52b5aae | 2019-05-24 16:27:55 -0400 | [diff] [blame] | 58 | #endif // VULKAN_PLATFORM |