1 // Copyright 2021 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 VK_DEVICE_MEMORY_EXTERNAL_HOST_HPP_ 16 #define VK_DEVICE_MEMORY_EXTERNAL_HOST_HPP_ 17 18 #include "VkDeviceMemory.hpp" 19 20 // Host-allocated memory and host-mapped foreign memory 21 class ExternalMemoryHost : public vk::DeviceMemory, public vk::ObjectBase<ExternalMemoryHost, VkDeviceMemory> 22 { 23 public: 24 struct AllocateInfo 25 { 26 bool supported = false; 27 void *hostPointer = nullptr; 28 29 AllocateInfo() = default; 30 31 AllocateInfo(const vk::DeviceMemory::ExtendedAllocationInfo &extendedAllocationInfo); 32 }; 33 34 static const VkExternalMemoryHandleTypeFlagBits typeFlagBit = (VkExternalMemoryHandleTypeFlagBits)(VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT | VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_MAPPED_FOREIGN_MEMORY_BIT_EXT); 35 36 static bool SupportsAllocateInfo(const vk::DeviceMemory::ExtendedAllocationInfo &extendedAllocationInfo); 37 38 explicit ExternalMemoryHost(const VkMemoryAllocateInfo *pCreateInfo, void *mem, const DeviceMemory::ExtendedAllocationInfo &extendedAllocationInfo, vk::Device *pDevice); 39 40 VkResult allocateBuffer() override; 41 void freeBuffer() override; 42 VkExternalMemoryHandleTypeFlagBits getFlagBit() const override; 43 44 private: 45 AllocateInfo allocateInfo; 46 }; 47 48 #endif // VK_DEVICE_MEMORY_EXTERNAL_HOST_HPP_ 49