cuda-helpers.h 1.9 KB

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