GpuMemoryBufferCudaHandle.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #include "pch.h"
  2. #include "GpuMemoryBufferCudaHandle.h"
  3. namespace unity
  4. {
  5. namespace webrtc
  6. {
  7. GpuMemoryBufferCudaHandle::GpuMemoryBufferCudaHandle()
  8. : context(nullptr)
  9. , array(nullptr)
  10. , mappedArray(nullptr)
  11. , mappedPtr(0)
  12. , resource(nullptr)
  13. , externalMemory(nullptr)
  14. {
  15. }
  16. GpuMemoryBufferCudaHandle::GpuMemoryBufferCudaHandle(GpuMemoryBufferCudaHandle&& other) = default;
  17. GpuMemoryBufferCudaHandle& GpuMemoryBufferCudaHandle::operator=(GpuMemoryBufferCudaHandle&& other) = default;
  18. GpuMemoryBufferCudaHandle::~GpuMemoryBufferCudaHandle()
  19. {
  20. cuCtxPushCurrent(context);
  21. CUresult result;
  22. if (externalMemory != nullptr)
  23. {
  24. result = cuDestroyExternalMemory(externalMemory);
  25. if (result != CUDA_SUCCESS)
  26. {
  27. RTC_LOG(LS_ERROR) << "faild cuDestroyExternalMemory CUresult: " << result;
  28. }
  29. }
  30. if (resource != nullptr)
  31. {
  32. result = cuGraphicsUnmapResources(1, &resource, nullptr);
  33. if (result != CUDA_SUCCESS)
  34. {
  35. RTC_LOG(LS_ERROR) << "faild cuGraphicsUnmapResources CUresult: " << result;
  36. }
  37. result = cuGraphicsUnregisterResource(resource);
  38. if (result != CUDA_SUCCESS)
  39. {
  40. RTC_LOG(LS_ERROR) << "faild cuGraphicsUnregisterResource CUresult: " << result;
  41. }
  42. }
  43. if (array != nullptr)
  44. {
  45. result = cuArrayDestroy(array);
  46. if (result != CUDA_SUCCESS)
  47. {
  48. RTC_LOG(LS_ERROR) << "faild cuArrayDestroy CUresult: " << result;
  49. }
  50. }
  51. cuCtxPopCurrent(nullptr);
  52. }
  53. }
  54. }