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
15#ifndef VULKAN_PLATFORM
16#define VULKAN_PLATFORM
17
18#include <cstddef>
19#include <cstdint>
20#include <type_traits>
21
22template<typename T> class VkNonDispatchableHandle
23{
24public:
25 operator void*() const
26 {
27 static_assert(sizeof(VkNonDispatchableHandle) == sizeof(uint64_t), "Size is not 64 bits!");
28
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
35 return reinterpret_cast<void*>(static_cast<uintptr_t>(handle));
36 }
37
38 void operator=(uint64_t h)
39 {
40 handle = h;
41 }
42
43 uint64_t handle;
44};
45
46#define VK_DEFINE_NON_DISPATCHABLE_HANDLE(object) \
47 typedef struct object##_T *object##Ptr; \
48 typedef VkNonDispatchableHandle<object##Ptr> object; \
49 template class VkNonDispatchableHandle<object##Ptr>;
50
51#include <vulkan/vulkan.h>
52#include <vulkan/vk_ext_provoking_vertex.h>
53
54#ifdef Bool
55#undef Bool // b/127920555
56#undef None
57#endif
58
59#endif // VULKAN_PLATFORM
60