cuda-helpers.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #pragma once
  2. #include <obs-module.h>
  3. #include <ffnvcodec/dynlink_cuda.h>
  4. /* Missing from FFmpeg headers */
  5. typedef CUresult CUDAAPI tcuMemHostRegister(void *p, size_t bytesize, unsigned int Flags);
  6. typedef CUresult CUDAAPI tcuMemHostUnregister(void *p);
  7. #define CUDA_ERROR_INVALID_GRAPHICS_CONTEXT 219
  8. #define CUDA_ARRAY3D_SURFACE_LDST 0x02
  9. typedef struct CudaFunctions {
  10. tcuInit *cuInit;
  11. tcuDeviceGetCount *cuDeviceGetCount;
  12. tcuDeviceGet *cuDeviceGet;
  13. tcuDeviceGetAttribute *cuDeviceGetAttribute;
  14. tcuCtxCreate_v2 *cuCtxCreate;
  15. tcuCtxDestroy_v2 *cuCtxDestroy;
  16. tcuCtxPushCurrent_v2 *cuCtxPushCurrent;
  17. tcuCtxPopCurrent_v2 *cuCtxPopCurrent;
  18. tcuArray3DCreate *cuArray3DCreate;
  19. tcuArrayDestroy *cuArrayDestroy;
  20. tcuMemcpy2D_v2 *cuMemcpy2D;
  21. tcuGetErrorName *cuGetErrorName;
  22. tcuGetErrorString *cuGetErrorString;
  23. tcuMemHostRegister *cuMemHostRegister;
  24. tcuMemHostUnregister *cuMemHostUnregister;
  25. #ifndef _WIN32
  26. tcuGLGetDevices_v2 *cuGLGetDevices;
  27. tcuGraphicsGLRegisterImage *cuGraphicsGLRegisterImage;
  28. tcuGraphicsUnregisterResource *cuGraphicsUnregisterResource;
  29. tcuGraphicsMapResources *cuGraphicsMapResources;
  30. tcuGraphicsUnmapResources *cuGraphicsUnmapResources;
  31. tcuGraphicsSubResourceGetMappedArray *cuGraphicsSubResourceGetMappedArray;
  32. #endif
  33. } CudaFunctions;
  34. extern CudaFunctions *cu;
  35. bool init_cuda(obs_encoder_t *encoder);
  36. bool cuda_get_error_desc(CUresult res, const char **name, const char **desc);
  37. struct nvenc_data;
  38. bool cuda_error_check(struct nvenc_data *enc, CUresult res, const char *func, const char *call);
  39. /* CUDA error handling */
  40. #define CU_FAILED(call) \
  41. if (!cuda_error_check(enc, call, __FUNCTION__, #call)) \
  42. return false;
  43. #define CU_CHECK(call) \
  44. if (!cuda_error_check(enc, call, __FUNCTION__, #call)) { \
  45. success = false; \
  46. goto unmap; \
  47. }