blob: 5bcf9b5c1f410dfe24d17954badc8683739c30ec [file] [log] [blame]
Alexis Hetu67cf8a92019-05-09 17:46:07 -04001// 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 Capens52b5aae2019-05-24 16:27:55 -040015#ifndef VULKAN_PLATFORM
16#define VULKAN_PLATFORM
17
Alexis Hetu67cf8a92019-05-09 17:46:07 -040018#include <cstddef>
19#include <cstdint>
Nicolas Capens522d5122019-06-21 10:18:10 -040020#include <type_traits>
Alexis Hetu67cf8a92019-05-09 17:46:07 -040021
Alexis Hetubd4cf812019-06-14 15:14:07 -040022template<typename T> class VkNonDispatchableHandle
Alexis Hetu67cf8a92019-05-09 17:46:07 -040023{
24public:
Alexis Hetu2d77aea2019-06-17 13:43:50 -040025 operator void*() const
Alexis Hetuf9e9cf62019-06-05 17:18:40 -040026 {
27 static_assert(sizeof(VkNonDispatchableHandle) == sizeof(uint64_t), "Size is not 64 bits!");
Alexis Hetubd4cf812019-06-14 15:14:07 -040028
Alexis Hetu2d77aea2019-06-17 13:43:50 -040029 // 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 Hetubd4cf812019-06-14 15:14:07 -040035 return reinterpret_cast<void*>(static_cast<uintptr_t>(handle));
36 }
37
Alexis Hetu2d77aea2019-06-17 13:43:50 -040038 void operator=(uint64_t h)
Alexis Hetubd4cf812019-06-14 15:14:07 -040039 {
Alexis Hetu2d77aea2019-06-17 13:43:50 -040040 handle = h;
Alexis Hetubd4cf812019-06-14 15:14:07 -040041 }
42
Alexis Hetubd4cf812019-06-14 15:14:07 -040043 uint64_t handle;
Alexis Hetuf9e9cf62019-06-05 17:18:40 -040044};
45
Alexis Hetu67cf8a92019-05-09 17:46:07 -040046#define VK_DEFINE_NON_DISPATCHABLE_HANDLE(object) \
47 typedef struct object##_T *object##Ptr; \
Alexis Hetuf9e9cf62019-06-05 17:18:40 -040048 typedef VkNonDispatchableHandle<object##Ptr> object; \
Nicolas Capens522d5122019-06-21 10:18:10 -040049 template class VkNonDispatchableHandle<object##Ptr>;
Alexis Hetu67cf8a92019-05-09 17:46:07 -040050
51#include <vulkan/vulkan.h>
52
53#ifdef Bool
54#undef Bool // b/127920555
55#undef None
56#endif
57
Nicolas Capens52b5aae2019-05-24 16:27:55 -040058#endif // VULKAN_PLATFORM