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