MCPcopy Create free account
hub / github.com/NVIDIAGameWorks/Falcor / importExternalMemory

Function importExternalMemory

Source/Falcor/Utils/CudaUtils.cpp:92–126  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

90}
91
92cudaExternalMemory_t importExternalMemory(const Buffer* buffer)
93{
94 FALCOR_CHECK(buffer, "'buffer' is nullptr.");
95 FALCOR_CHECK(is_set(buffer->getBindFlags(), ResourceBindFlags::Shared), "Buffer must be created with ResourceBindFlags::Shared.");
96 SharedResourceApiHandle sharedHandle = buffer->getSharedApiHandle();
97 FALCOR_CHECK(sharedHandle, "Buffer shared handle creation failed.");
98
99 cudaExternalMemoryHandleDesc desc = {};
100 switch (buffer->getDevice()->getType())
101 {
102#if FALCOR_WINDOWS
103 case Device::Type::D3D12:
104 desc.type = cudaExternalMemoryHandleTypeD3D12Resource;
105 desc.handle.win32.handle = sharedHandle;
106 break;
107 case Device::Type::Vulkan:
108 desc.type = cudaExternalMemoryHandleTypeOpaqueWin32;
109 desc.handle.win32.handle = sharedHandle;
110 break;
111#elif FALCOR_LINUX
112 case Device::Type::Vulkan:
113 desc.type = cudaExternalMemoryHandleTypeOpaqueFd;
114 desc.handle.fd = (int)reinterpret_cast<intptr_t>(sharedHandle);
115 break;
116#endif
117 default:
118 FALCOR_THROW("Unsupported device type '{}'.", buffer->getDevice()->getType());
119 }
120 desc.size = buffer->getSize();
121 desc.flags = cudaExternalMemoryDedicated;
122
123 cudaExternalMemory_t extMem;
124 FALCOR_CUDA_CHECK(cudaImportExternalMemory(&extMem, &desc));
125 return extMem;
126}
127
128void destroyExternalMemory(cudaExternalMemory_t extMem)
129{

Callers 1

ExternalMemoryMethod · 0.85

Calls 4

getSharedApiHandleMethod · 0.45
getTypeMethod · 0.45
getDeviceMethod · 0.45
getSizeMethod · 0.45

Tested by

no test coverage detected