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_google_filtering_precision.h> 53 #include <vulkan/vulkan_core.h> 54 55 #endif // VULKAN_PLATFORM 56