xref: /aosp_15_r20/external/swiftshader/src/Vulkan/VkDeviceMemoryExternalHost.cpp (revision 03ce13f70fcc45d86ee91b7ee4cab1936a95046e)
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 #include "VkDeviceMemoryExternalHost.hpp"
16 
AllocateInfo(const vk::DeviceMemory::ExtendedAllocationInfo & extendedAllocationInfo)17 ExternalMemoryHost::AllocateInfo::AllocateInfo(const vk::DeviceMemory::ExtendedAllocationInfo &extendedAllocationInfo)
18 {
19 	if(extendedAllocationInfo.importMemoryHostPointerInfo)
20 	{
21 		if((extendedAllocationInfo.importMemoryHostPointerInfo->handleType != VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT) &&
22 		   (extendedAllocationInfo.importMemoryHostPointerInfo->handleType != VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_MAPPED_FOREIGN_MEMORY_BIT_EXT))
23 		{
24 			UNSUPPORTED("extendedAllocationInfo.importMemoryHostPointerInfo->handleType, %d",
25 			            int(extendedAllocationInfo.importMemoryHostPointerInfo->handleType));
26 		}
27 		hostPointer = extendedAllocationInfo.importMemoryHostPointerInfo->pHostPointer;
28 		supported = true;
29 	}
30 }
31 
SupportsAllocateInfo(const vk::DeviceMemory::ExtendedAllocationInfo & extendedAllocationInfo)32 bool ExternalMemoryHost::SupportsAllocateInfo(const vk::DeviceMemory::ExtendedAllocationInfo &extendedAllocationInfo)
33 {
34 	AllocateInfo info(extendedAllocationInfo);
35 	return info.supported;
36 }
37 
ExternalMemoryHost(const VkMemoryAllocateInfo * pCreateInfo,void * mem,const DeviceMemory::ExtendedAllocationInfo & extendedAllocationInfo,vk::Device * pDevice)38 ExternalMemoryHost::ExternalMemoryHost(const VkMemoryAllocateInfo *pCreateInfo, void *mem, const DeviceMemory::ExtendedAllocationInfo &extendedAllocationInfo, vk::Device *pDevice)
39     : vk::DeviceMemory(pCreateInfo, extendedAllocationInfo, pDevice)
40     , allocateInfo(extendedAllocationInfo)
41 {}
42 
allocateBuffer()43 VkResult ExternalMemoryHost::allocateBuffer()
44 {
45 	if(allocateInfo.supported)
46 	{
47 		buffer = allocateInfo.hostPointer;
48 		return VK_SUCCESS;
49 	}
50 	return VK_ERROR_INVALID_EXTERNAL_HANDLE;
51 }
52 
freeBuffer()53 void ExternalMemoryHost::freeBuffer()
54 {}
55 
getFlagBit() const56 VkExternalMemoryHandleTypeFlagBits ExternalMemoryHost::getFlagBit() const
57 {
58 	return typeFlagBit;
59 }