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 
22 template<typename T>
23 class VkNonDispatchableHandle
24 {
25 public:
operator void*() const26 	operator void *() const
27 	{
28 		static_assert(sizeof(VkNonDispatchableHandle) == sizeof(uint64_t), "Size is not 64 bits!");
29 
30 		// VkNonDispatchableHandle must be POD to ensure it gets passed by value the same way as a uint64_t,
31 		// which is the upstream header's handle type when compiled for 32-bit architectures. On 64-bit architectures,
32 		// the upstream header's handle type is a pointer type.
33 		static_assert(std::is_trivial<VkNonDispatchableHandle<T>>::value, "VkNonDispatchableHandle<T> is not trivial!");
34 		static_assert(std::is_standard_layout<VkNonDispatchableHandle<T>>::value, "VkNonDispatchableHandle<T> is not standard layout!");
35 
36 		return reinterpret_cast<void *>(static_cast<uintptr_t>(handle));
37 	}
38 
operator =(uint64_t h)39 	void operator=(uint64_t h)
40 	{
41 		handle = h;
42 	}
43 
44 	uint64_t handle;
45 };
46 
47 #define VK_DEFINE_NON_DISPATCHABLE_HANDLE(object)        \
48 	typedef struct object##_T *object##Ptr;              \
49 	typedef VkNonDispatchableHandle<object##Ptr> object; \
50 	template class VkNonDispatchableHandle<object##Ptr>;
51 
52 #include <vulkan/vk_ext_provoking_vertex.h>
53 #include <vulkan/vk_google_filtering_precision.h>
54 #include <vulkan/vulkan_core.h>
55 
56 namespace vk {
57 // Here we define constants that used to be in the Vulkan headers, but are not part of the spec.
58 // See: https://github.com/KhronosGroup/Vulkan-Docs/issues/1230
59 
60 // When updating the Vulkan Headers we use, go through each constant below and make sure they are valid.
61 // Once that's done, update SwiftShaderVulkanHeaderVersion.
62 constexpr int SwiftShaderVulkanHeaderVersion = 160;
63 static_assert(SwiftShaderVulkanHeaderVersion == VK_HEADER_VERSION, "Please validate/update constants below upon upgrading Vulkan headers");
64 
65 constexpr auto VK_PIPELINE_BIND_POINT_RANGE_SIZE = (VK_PIPELINE_BIND_POINT_COMPUTE - VK_PIPELINE_BIND_POINT_GRAPHICS + 1);
66 constexpr auto VK_IMAGE_VIEW_TYPE_END_RANGE = VK_IMAGE_VIEW_TYPE_CUBE_ARRAY;
67 
68 }  // namespace vk
69 
70 #endif  // VULKAN_PLATFORM
71