| 195 | } |
| 196 | |
| 197 | void* getSharedDevicePtr(Device::Type deviceType, SharedResourceApiHandle sharedHandle, uint32_t bytes) |
| 198 | { |
| 199 | // No handle? No pointer! |
| 200 | FALCOR_CHECK(sharedHandle, "Texture shared handle creation failed"); |
| 201 | |
| 202 | cudaExternalMemoryHandleDesc externalMemoryDesc = {}; |
| 203 | switch (deviceType) |
| 204 | { |
| 205 | #if FALCOR_WINDOWS |
| 206 | case Device::Type::D3D12: |
| 207 | externalMemoryDesc.type = cudaExternalMemoryHandleTypeD3D12Resource; |
| 208 | externalMemoryDesc.handle.win32.handle = sharedHandle; |
| 209 | break; |
| 210 | case Device::Type::Vulkan: |
| 211 | externalMemoryDesc.type = cudaExternalMemoryHandleTypeOpaqueWin32; |
| 212 | externalMemoryDesc.handle.win32.handle = sharedHandle; |
| 213 | break; |
| 214 | #elif FALCOR_LINUX |
| 215 | case Device::Type::Vulkan: |
| 216 | externalMemoryDesc.type = cudaExternalMemoryHandleTypeOpaqueFd; |
| 217 | externalMemoryDesc.handle.fd = (int)reinterpret_cast<intptr_t>(sharedHandle); |
| 218 | break; |
| 219 | #endif |
| 220 | default: |
| 221 | FALCOR_THROW("Unsupported device type '{}'.", deviceType); |
| 222 | } |
| 223 | |
| 224 | externalMemoryDesc.size = bytes; |
| 225 | externalMemoryDesc.flags = cudaExternalMemoryDedicated; |
| 226 | |
| 227 | // Get a handle to that memory |
| 228 | cudaExternalMemory_t externalMemory; |
| 229 | FALCOR_CUDA_CHECK(cudaImportExternalMemory(&externalMemory, &externalMemoryDesc)); |
| 230 | |
| 231 | // Create a descriptor for our shared buffer pointer |
| 232 | cudaExternalMemoryBufferDesc bufDesc; |
| 233 | memset(&bufDesc, 0, sizeof(bufDesc)); |
| 234 | bufDesc.size = bytes; |
| 235 | |
| 236 | // Actually map the buffer |
| 237 | void* devPtr = nullptr; |
| 238 | FALCOR_CUDA_CHECK(cudaExternalMemoryGetMappedBuffer(&devPtr, externalMemory, &bufDesc)); |
| 239 | |
| 240 | return devPtr; |
| 241 | } |
| 242 | |
| 243 | bool freeSharedDevicePtr(void* ptr) |
| 244 | { |
no outgoing calls
no test coverage detected