nvvfx-load.h 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736
  1. #pragma once
  2. #include <Windows.h>
  3. #include <stdio.h>
  4. #include <stdbool.h>
  5. #include <stddef.h>
  6. #include <stdint.h>
  7. #include <util/platform.h>
  8. #include <dxgitype.h>
  9. #include <util/windows/win-version.h>
  10. #include "nv_sdk_versions.h"
  11. #ifdef __cplusplus
  12. extern "C" {
  13. #endif // ___cplusplus
  14. #ifndef NvVFX_API
  15. #ifdef _WIN32
  16. #ifdef NVVFX_API_EXPORT
  17. #define NvVFX_API __declspec(dllexport) __cdecl
  18. #else
  19. #define NvVFX_API
  20. #endif
  21. #else //if linux
  22. #define NvVFX_API // TODO: Linux code goes here
  23. #endif // _WIN32 or linux
  24. #endif //NvVFX_API
  25. #ifndef NvCV_API
  26. #ifdef _WIN32
  27. #ifdef NVCV_API_EXPORT
  28. #define NvCV_API __declspec(dllexport) __cdecl
  29. #else
  30. #define NvCV_API
  31. #endif
  32. #else //if linux
  33. #define NvCV_API // TODO: Linux code goes here
  34. #endif // _WIN32 or linux
  35. #endif //NvCV_API
  36. #define CUDARTAPI
  37. #ifdef LIBNVVFX_ENABLED
  38. static HMODULE nv_videofx = NULL;
  39. static HMODULE nv_cvimage = NULL;
  40. static HMODULE nv_cudart = NULL;
  41. static HMODULE nv_cuda = NULL;
  42. //! Status codes returned from APIs.
  43. typedef enum NvCV_Status {
  44. NVCV_SUCCESS = 0, //!< The procedure returned successfully.
  45. NVCV_ERR_GENERAL = -1, //!< An otherwise unspecified error has occurred.
  46. NVCV_ERR_UNIMPLEMENTED = -2, //!< The requested feature is not yet implemented.
  47. NVCV_ERR_MEMORY = -3, //!< There is not enough memory for the requested operation.
  48. NVCV_ERR_EFFECT = -4, //!< An invalid effect handle has been supplied.
  49. NVCV_ERR_SELECTOR = -5, //!< The given parameter selector is not valid in this effect filter.
  50. NVCV_ERR_BUFFER = -6, //!< An image buffer has not been specified.
  51. NVCV_ERR_PARAMETER = -7, //!< An invalid parameter value has been supplied for this effect+selector.
  52. NVCV_ERR_MISMATCH = -8, //!< Some parameters are not appropriately matched.
  53. NVCV_ERR_PIXELFORMAT = -9, //!< The specified pixel format is not accommodated.
  54. NVCV_ERR_MODEL = -10, //!< Error while loading the TRT model.
  55. NVCV_ERR_LIBRARY = -11, //!< Error loading the dynamic library.
  56. NVCV_ERR_INITIALIZATION = -12, //!< The effect has not been properly initialized.
  57. NVCV_ERR_FILE = -13, //!< The file could not be found.
  58. NVCV_ERR_FEATURENOTFOUND = -14, //!< The requested feature was not found
  59. NVCV_ERR_MISSINGINPUT = -15, //!< A required parameter was not set
  60. NVCV_ERR_RESOLUTION = -16, //!< The specified image resolution is not supported.
  61. NVCV_ERR_UNSUPPORTEDGPU = -17, //!< The GPU is not supported
  62. NVCV_ERR_WRONGGPU = -18, //!< The current GPU is not the one selected.
  63. NVCV_ERR_UNSUPPORTEDDRIVER = -19, //!< The currently installed graphics driver is not supported
  64. NVCV_ERR_MODELDEPENDENCIES = -20, //!< There is no model with dependencies that match this system
  65. NVCV_ERR_PARSE = -21, //!< There has been a parsing or syntax error while reading a file
  66. NVCV_ERR_MODELSUBSTITUTION = -22, //!< The specified model does not exist and has been substituted.
  67. NVCV_ERR_READ = -23, //!< An error occurred while reading a file.
  68. NVCV_ERR_WRITE = -24, //!< An error occurred while writing a file.
  69. NVCV_ERR_PARAMREADONLY = -25, //!< The selected parameter is read-only.
  70. NVCV_ERR_TRT_ENQUEUE = -26, //!< TensorRT enqueue failed.
  71. NVCV_ERR_TRT_BINDINGS = -27, //!< Unexpected TensorRT bindings.
  72. NVCV_ERR_TRT_CONTEXT = -28, //!< An error occurred while creating a TensorRT context.
  73. NVCV_ERR_TRT_INFER = -29, ///< The was a problem creating the inference engine.
  74. NVCV_ERR_TRT_ENGINE = -30, ///< There was a problem deserializing the inference runtime engine.
  75. NVCV_ERR_NPP = -31, //!< An error has occurred in the NPP library.
  76. NVCV_ERR_CONFIG = -32, //!< No suitable model exists for the specified parameter configuration.
  77. NVCV_ERR_DIRECT3D = -99, //!< A Direct3D error has occurred.
  78. NVCV_ERR_CUDA_BASE = -100, //!< CUDA errors are offset from this value.
  79. NVCV_ERR_CUDA_VALUE = -101, //!< A CUDA parameter is not within the acceptable range.
  80. NVCV_ERR_CUDA_MEMORY = -102, //!< There is not enough CUDA memory for the requested operation.
  81. NVCV_ERR_CUDA_PITCH = -112, //!< A CUDA pitch is not within the acceptable range.
  82. NVCV_ERR_CUDA_INIT = -127, //!< The CUDA driver and runtime could not be initialized.
  83. NVCV_ERR_CUDA_LAUNCH = -819, //!< The CUDA kernel launch has failed.
  84. NVCV_ERR_CUDA_KERNEL = -309, //!< No suitable kernel image is available for the device.
  85. NVCV_ERR_CUDA_DRIVER = -135, //!< The installed NVIDIA CUDA driver is older than the CUDA runtime library.
  86. NVCV_ERR_CUDA_UNSUPPORTED = -901, //!< The CUDA operation is not supported on the current system or device.
  87. NVCV_ERR_CUDA_ILLEGAL_ADDRESS = -800, //!< CUDA tried to load or store on an invalid memory address.
  88. NVCV_ERR_CUDA = -1099, //!< An otherwise unspecified CUDA error has been reported.
  89. } NvCV_Status;
  90. /** Filter selectors */
  91. #define NVVFX_FX_TRANSFER "Transfer"
  92. #define NVVFX_FX_GREEN_SCREEN "GreenScreen" // Green Screen
  93. #define NVVFX_FX_BGBLUR "BackgroundBlur" // Background blur
  94. #define NVVFX_FX_ARTIFACT_REDUCTION "ArtifactReduction" // Artifact Reduction
  95. #define NVVFX_FX_SUPER_RES "SuperRes" // Super Res
  96. #define NVVFX_FX_SR_UPSCALE "Upscale" // Super Res Upscale
  97. #define NVVFX_FX_DENOISING "Denoising" // Denoising
  98. /** Parameter selectors */
  99. #define NVVFX_INPUT_IMAGE_0 "SrcImage0"
  100. #define NVVFX_INPUT_IMAGE NVVFX_INPUT_IMAGE_0
  101. #define NVVFX_INPUT_IMAGE_1 "SrcImage1"
  102. #define NVVFX_OUTPUT_IMAGE_0 "DstImage0"
  103. #define NVVFX_OUTPUT_IMAGE NVVFX_OUTPUT_IMAGE_0
  104. #define NVVFX_MODEL_DIRECTORY "ModelDir"
  105. #define NVVFX_CUDA_STREAM "CudaStream" //!< The CUDA stream to use
  106. #define NVVFX_CUDA_GRAPH "CudaGraph" //!< Enable CUDA graph to use
  107. #define NVVFX_INFO "Info" //!< Get info about the effects
  108. #define NVVFX_MAX_INPUT_WIDTH "MaxInputWidth" //!< Maximum width of the input supported
  109. #define NVVFX_MAX_INPUT_HEIGHT "MaxInputHeight" //!< Maximum height of the input supported
  110. #define NVVFX_MAX_NUMBER_STREAMS "MaxNumberStreams" //!< Maximum number of concurrent input streams
  111. #define NVVFX_SCALE "Scale" //!< Scale factor
  112. #define NVVFX_STRENGTH "Strength" //!< Strength for different filters
  113. #define NVVFX_STRENGTH_LEVELS "StrengthLevels" //!< Number of strength levels
  114. #define NVVFX_MODE "Mode" //!< Mode for different filters
  115. #define NVVFX_TEMPORAL "Temporal" //!< Temporal mode: 0=image, 1=video
  116. #define NVVFX_GPU "GPU" //!< Preferred GPU (optional)
  117. #define NVVFX_BATCH_SIZE "BatchSize" //!< Batch Size (default 1)
  118. #define NVVFX_MODEL_BATCH "ModelBatch"
  119. #define NVVFX_STATE "State" //!< State variable
  120. #define NVVFX_STATE_SIZE "StateSize" //!< Number of bytes needed to store state
  121. #define NVVFX_STATE_COUNT "NumStateObjects" //!< Number of active state object handles
  122. //! The format of pixels in an image.
  123. typedef enum NvCVImage_PixelFormat {
  124. NVCV_FORMAT_UNKNOWN = 0, //!< Unknown pixel format.
  125. NVCV_Y = 1, //!< Luminance (gray).
  126. NVCV_A = 2, //!< Alpha (opacity)
  127. NVCV_YA = 3, //!< { Luminance, Alpha }
  128. NVCV_RGB = 4, //!< { Red, Green, Blue }
  129. NVCV_BGR = 5, //!< { Red, Green, Blue }
  130. NVCV_RGBA = 6, //!< { Red, Green, Blue, Alpha }
  131. NVCV_BGRA = 7, //!< { Red, Green, Blue, Alpha }
  132. NVCV_ARGB = 8, //!< { Red, Green, Blue, Alpha }
  133. NVCV_ABGR = 9, //!< { Red, Green, Blue, Alpha }
  134. NVCV_YUV420 = 10, //!< Luminance and subsampled Chrominance { Y, Cb, Cr }
  135. NVCV_YUV422 = 11, //!< Luminance and subsampled Chrominance { Y, Cb, Cr }
  136. NVCV_YUV444 = 12, //!< Luminance and full bandwidth Chrominance { Y, Cb, Cr }
  137. } NvCVImage_PixelFormat;
  138. //! The data type used to represent each component of an image.
  139. typedef enum NvCVImage_ComponentType {
  140. NVCV_TYPE_UNKNOWN = 0, //!< Unknown type of component.
  141. NVCV_U8 = 1, //!< Unsigned 8-bit integer.
  142. NVCV_U16 = 2, //!< Unsigned 16-bit integer.
  143. NVCV_S16 = 3, //!< Signed 16-bit integer.
  144. NVCV_F16 = 4, //!< 16-bit floating-point.
  145. NVCV_U32 = 5, //!< Unsigned 32-bit integer.
  146. NVCV_S32 = 6, //!< Signed 32-bit integer.
  147. NVCV_F32 = 7, //!< 32-bit floating-point (float).
  148. NVCV_U64 = 8, //!< Unsigned 64-bit integer.
  149. NVCV_S64 = 9, //!< Signed 64-bit integer.
  150. NVCV_F64 = 10, //!< 64-bit floating-point (double).
  151. } NvCVImage_ComponentType;
  152. //! Value for the planar field or layout argument. Two values are currently accommodated for RGB:
  153. //! Interleaved or chunky storage locates all components of a pixel adjacent in memory,
  154. //! e.g. RGBRGBRGB... (denoted [RGB]).
  155. //! Planar storage locates the same component of all pixels adjacent in memory,
  156. //! e.g. RRRRR...GGGGG...BBBBB... (denoted [R][G][B])
  157. //! YUV has many more variants.
  158. //! 4:2:2 can be chunky, planar or semi-planar, with different orderings.
  159. //! 4:2:0 can be planar or semi-planar, with different orderings.
  160. //! Aliases are provided for FOURCCs defined at fourcc.org.
  161. //! Note: the LSB can be used to distinguish between chunky and planar formats.
  162. #define NVCV_INTERLEAVED 0 //!< All components of pixel(x,y) are adjacent (same as chunky) (default for non-YUV).
  163. #define NVCV_CHUNKY 0 //!< All components of pixel(x,y) are adjacent (same as interleaved).
  164. #define NVCV_PLANAR 1 //!< The same component of all pixels are adjacent.
  165. #define NVCV_UYVY 2 //!< [UYVY] Chunky 4:2:2 (default for 4:2:2)
  166. #define NVCV_VYUY 4 //!< [VYUY] Chunky 4:2:2
  167. #define NVCV_YUYV 6 //!< [YUYV] Chunky 4:2:2
  168. #define NVCV_YVYU 8 //!< [YVYU] Chunky 4:2:2
  169. #define NVCV_CYUV 10 //!< [YUV] Chunky 4:4:4
  170. #define NVCV_CYVU 12 //!< [YVU] Chunky 4:4:4
  171. #define NVCV_YUV 3 //!< [Y][U][V] Planar 4:2:2 or 4:2:0 or 4:4:4
  172. #define NVCV_YVU 5 //!< [Y][V][U] Planar 4:2:2 or 4:2:0 or 4:4:4
  173. #define NVCV_YCUV 7 //!< [Y][UV] Semi-planar 4:2:2 or 4:2:0 (default for 4:2:0)
  174. #define NVCV_YCVU 9 //!< [Y][VU] Semi-planar 4:2:2 or 4:2:0
  175. //! The following are FOURCC aliases for specific layouts. Note that it is still required to specify the format as well
  176. //! as the layout, e.g. NVCV_YUV420 and NVCV_NV12, even though the NV12 layout is only associated with YUV420 sampling.
  177. #define NVCV_I420 NVCV_YUV //!< [Y][U][V] Planar 4:2:0
  178. #define NVCV_IYUV NVCV_YUV //!< [Y][U][V] Planar 4:2:0
  179. #define NVCV_YV12 NVCV_YVU //!< [Y][V][U] Planar 4:2:0
  180. #define NVCV_NV12 NVCV_YCUV //!< [Y][UV] Semi-planar 4:2:0 (default for 4:2:0)
  181. #define NVCV_NV21 NVCV_YCVU //!< [Y][VU] Semi-planar 4:2:0
  182. #define NVCV_YUY2 NVCV_YUYV //!< [YUYV] Chunky 4:2:2
  183. #define NVCV_I444 NVCV_YUV //!< [Y][U][V] Planar 4:4:4
  184. #define NVCV_YM24 NVCV_YUV //!< [Y][U][V] Planar 4:4:4
  185. #define NVCV_YM42 NVCV_YVU //!< [Y][V][U] Planar 4:4:4
  186. #define NVCV_NV24 NVCV_YCUV //!< [Y][UV] Semi-planar 4:4:4
  187. #define NVCV_NV42 NVCV_YCVU //!< [Y][VU] Semi-planar 4:4:4
  188. //! The following are ORed together for the colorspace field for YUV.
  189. //! NVCV_601 and NVCV_709 describe the color axes of YUV.
  190. //! NVCV_VIDEO_RANGE and NVCV_VIDEO_RANGE describe the range, [16, 235] or [0, 255], respectively.
  191. //! NVCV_CHROMA_COSITED and NVCV_CHROMA_INTSTITIAL describe the location of the chroma samples.
  192. #define NVCV_601 0x00 //!< The Rec.601 YUV colorspace, typically used for SD.
  193. #define NVCV_709 0x01 //!< The Rec.709 YUV colorspace, typically used for HD.
  194. #define NVCV_2020 0x02 //!< The Rec.2020 YUV colorspace.
  195. #define NVCV_VIDEO_RANGE 0x00 //!< The video range is [16, 235].
  196. #define NVCV_FULL_RANGE 0x04 //!< The video range is [ 0, 255].
  197. #define NVCV_CHROMA_COSITED 0x00 //!< The chroma is sampled at the same location as the luma samples horizontally.
  198. #define NVCV_CHROMA_INTSTITIAL 0x08 //!< The chroma is sampled between luma samples horizontally.
  199. #define NVCV_CHROMA_TOPLEFT \
  200. 0x10 //!< The chroma is sampled at the same location as the luma samples horizontally and vertically.
  201. #define NVCV_CHROMA_MPEG2 NVCV_CHROMA_COSITED //!< As is most video.
  202. #define NVCV_CHROMA_MPEG1 NVCV_CHROMA_INTSTITIAL
  203. #define NVCV_CHROMA_JPEG NVCV_CHROMA_INTSTITIAL
  204. #define NVCV_CHROMA_H261 NVCV_CHROMA_INTSTITIAL
  205. #define NVCV_CHROMA_INTERSTITIAL NVCV_CHROMA_INTSTITIAL //!< Correct spelling
  206. //! This is the value for the gpuMem field or the memSpace argument.
  207. #define NVCV_CPU 0 //!< The buffer is stored in CPU memory.
  208. #define NVCV_GPU 1 //!< The buffer is stored in CUDA memory.
  209. #define NVCV_CUDA 1 //!< The buffer is stored in CUDA memory.
  210. #define NVCV_CPU_PINNED 2 //!< The buffer is stored in pinned CPU memory.
  211. #define NVCV_CUDA_ARRAY 3 //!< A CUDA array is used for storage.
  212. /** Parameter selectors */
  213. #define NVVFX_INPUT_IMAGE_0 "SrcImage0"
  214. #define NVVFX_INPUT_IMAGE NVVFX_INPUT_IMAGE_0
  215. #define NVVFX_INPUT_IMAGE_1 "SrcImage1"
  216. #define NVVFX_OUTPUT_IMAGE_0 "DstImage0"
  217. #define NVVFX_OUTPUT_IMAGE NVVFX_OUTPUT_IMAGE_0
  218. #define NVVFX_MODEL_DIRECTORY "ModelDir"
  219. #define NVVFX_CUDA_STREAM "CudaStream" //!< The CUDA stream to use
  220. #define NVVFX_CUDA_GRAPH "CudaGraph" //!< Enable CUDA graph to use
  221. #define NVVFX_INFO "Info" //!< Get info about the effects
  222. #define NVVFX_SCALE "Scale" //!< Scale factor
  223. #define NVVFX_STRENGTH "Strength" //!< Strength for different filters
  224. #define NVVFX_STRENGTH_LEVELS "StrengthLevels" //!< Number of strength levels
  225. #define NVVFX_MODE "Mode" //!< Mode for different filters
  226. #define NVVFX_TEMPORAL "Temporal" //!< Temporal mode: 0=image, 1=video
  227. #define NVVFX_GPU "GPU" //!< Preferred GPU (optional)
  228. #define NVVFX_BATCH_SIZE "BatchSize" //!< Batch Size (default 1)
  229. #define NVVFX_MODEL_BATCH "ModelBatch"
  230. #define NVVFX_STATE "State" //!< State variable
  231. #define NVVFX_STATE_SIZE "StateSize" //!< Number of bytes needed to store state
  232. //! Image descriptor.
  233. typedef struct
  234. #ifdef _MSC_VER
  235. __declspec(dllexport)
  236. #endif // _MSC_VER
  237. NvCVImage {
  238. unsigned int width; //!< The number of pixels horizontally in the image.
  239. unsigned int height; //!< The number of pixels vertically in the image.
  240. signed int pitch; //!< The byte stride between pixels vertically.
  241. NvCVImage_PixelFormat pixelFormat; //!< The format of the pixels in the image.
  242. NvCVImage_ComponentType componentType; //!< The data type used to represent each component of the image.
  243. unsigned char pixelBytes; //!< The number of bytes in a chunky pixel.
  244. unsigned char componentBytes; //!< The number of bytes in each pixel component.
  245. unsigned char numComponents; //!< The number of components in each pixel.
  246. unsigned char planar; //!< NVCV_CHUNKY, NVCV_PLANAR, NVCV_UYVY, ....
  247. unsigned char gpuMem; //!< NVCV_CPU, NVCV_CPU_PINNED, NVCV_CUDA, NVCV_GPU
  248. unsigned char colorspace; //!< An OR of colorspace, range and chroma phase.
  249. unsigned char reserved[2]; //!< For structure padding and future expansion. Set to 0.
  250. void *pixels; //!< Pointer to pixel(0,0) in the image.
  251. void *deletePtr; //!< Buffer memory to be deleted (can be NULL).
  252. void (*deleteProc)(void *p); //!< Delete procedure to call rather than free().
  253. unsigned long long bufferBytes; //!< The maximum amount of memory available through pixels.
  254. } NvCVImage;
  255. //! Integer rectangle.
  256. typedef struct NvCVRect2i {
  257. int x; //!< The left edge of the rectangle.
  258. int y; //!< The top edge of the rectangle.
  259. int width; //!< The width of the rectangle.
  260. int height; //!< The height of the rectangle.
  261. } NvCVRect2i;
  262. //! Integer point.
  263. typedef struct NvCVPoint2i {
  264. int x; //!< The horizontal coordinate.
  265. int y; //!< The vertical coordinate
  266. } NvCVPoint2i;
  267. typedef struct CUstream_st *CUstream;
  268. typedef const char *NvVFX_EffectSelector;
  269. typedef const char *NvVFX_ParameterSelector;
  270. typedef void *NvVFX_Handle;
  271. /* requires sdk version >= 0.7.0 */
  272. typedef void *NvVFX_StateObjectHandle;
  273. /* nvvfx functions */
  274. typedef NvCV_Status NvVFX_API (*NvVFX_GetVersion_t)(unsigned int *version);
  275. typedef NvCV_Status NvVFX_API (*NvVFX_CreateEffect_t)(NvVFX_EffectSelector code, NvVFX_Handle *effect);
  276. typedef NvCV_Status NvVFX_API (*NvVFX_DestroyEffect_t)(NvVFX_Handle effect);
  277. typedef NvCV_Status NvVFX_API (*NvVFX_SetU32_t)(NvVFX_Handle effect, NvVFX_ParameterSelector param_name,
  278. unsigned int val);
  279. typedef NvCV_Status NvVFX_API (*NvVFX_SetS32_t)(NvVFX_Handle effect, NvVFX_ParameterSelector param_name, int val);
  280. typedef NvCV_Status NvVFX_API (*NvVFX_SetF32_t)(NvVFX_Handle effect, NvVFX_ParameterSelector param_name, float val);
  281. typedef NvCV_Status NvVFX_API (*NvVFX_SetF64_t)(NvVFX_Handle effect, NvVFX_ParameterSelector param_name, double val);
  282. typedef NvCV_Status NvVFX_API (*NvVFX_SetU64_t)(NvVFX_Handle effect, NvVFX_ParameterSelector param_name,
  283. unsigned long long val);
  284. typedef NvCV_Status NvVFX_API (*NvVFX_SetObject_t)(NvVFX_Handle effect, NvVFX_ParameterSelector param_name, void *ptr);
  285. /* requires sdk version >= 0.7.0 */
  286. typedef NvCV_Status NvVFX_API (*NvVFX_SetStateObjectHandleArray_t)(NvVFX_Handle effect,
  287. NvVFX_ParameterSelector param_name,
  288. NvVFX_StateObjectHandle *handle);
  289. /* ----------------------------- */
  290. typedef NvCV_Status NvVFX_API (*NvVFX_SetCudaStream_t)(NvVFX_Handle effect, NvVFX_ParameterSelector param_name,
  291. CUstream stream);
  292. typedef NvCV_Status NvVFX_API (*NvVFX_SetImage_t)(NvVFX_Handle effect, NvVFX_ParameterSelector param_name,
  293. NvCVImage *im);
  294. typedef NvCV_Status NvVFX_API (*NvVFX_SetString_t)(NvVFX_Handle effect, NvVFX_ParameterSelector param_name,
  295. const char *str);
  296. typedef NvCV_Status NvVFX_API (*NvVFX_GetU32_t)(NvVFX_Handle effect, NvVFX_ParameterSelector param_name,
  297. unsigned int *val);
  298. typedef NvCV_Status NvVFX_API (*NvVFX_GetS32_t)(NvVFX_Handle effect, NvVFX_ParameterSelector param_name, int *val);
  299. typedef NvCV_Status NvVFX_API (*NvVFX_GetF32_t)(NvVFX_Handle effect, NvVFX_ParameterSelector param_name, float *val);
  300. typedef NvCV_Status NvVFX_API (*NvVFX_GetF64_t)(NvVFX_Handle effect, NvVFX_ParameterSelector param_name, double *val);
  301. typedef NvCV_Status NvVFX_API (*NvVFX_GetU64_t)(NvVFX_Handle effect, NvVFX_ParameterSelector param_name,
  302. unsigned long long *val);
  303. typedef NvCV_Status NvVFX_API (*NvVFX_GetObject_t)(NvVFX_Handle effect, NvVFX_ParameterSelector param_name, void **ptr);
  304. typedef NvCV_Status NvVFX_API (*NvVFX_GetCudaStream_t)(NvVFX_Handle effect, NvVFX_ParameterSelector param_name,
  305. CUstream *stream);
  306. typedef NvCV_Status NvVFX_API (*NvVFX_GetImage_t)(NvVFX_Handle effect, NvVFX_ParameterSelector param_name,
  307. NvCVImage *im);
  308. typedef NvCV_Status NvVFX_API (*NvVFX_GetString_t)(NvVFX_Handle effect, NvVFX_ParameterSelector param_name,
  309. const char **str);
  310. typedef NvCV_Status NvVFX_API (*NvVFX_Run_t)(NvVFX_Handle effect, int async);
  311. typedef NvCV_Status NvVFX_API (*NvVFX_Load_t)(NvVFX_Handle effect);
  312. typedef NvCV_Status NvVFX_API (*NvVFX_CudaStreamCreate_t)(CUstream *stream);
  313. typedef NvCV_Status NvVFX_API (*NvVFX_CudaStreamDestroy_t)(CUstream stream);
  314. /* requires sdk version >= 0.7.0 */
  315. typedef NvCV_Status NvVFX_API (*NvVFX_AllocateState_t)(NvVFX_Handle effect, NvVFX_StateObjectHandle *handle);
  316. typedef NvCV_Status NvVFX_API (*NvVFX_DeallocateState_t)(NvVFX_Handle effect, NvVFX_StateObjectHandle handle);
  317. typedef NvCV_Status NvVFX_API (*NvVFX_ResetState_t)(NvVFX_Handle effect, NvVFX_StateObjectHandle handle);
  318. /* NvCVImage functions */
  319. typedef NvCV_Status NvCV_API (*NvCVImage_Init_t)(NvCVImage *im, unsigned width, unsigned height, int pitch,
  320. void *pixels, NvCVImage_PixelFormat format,
  321. NvCVImage_ComponentType type, unsigned layout, unsigned memSpace);
  322. typedef NvCV_Status NvCV_API (*NvCVImage_InitView_t)(NvCVImage *subImg, NvCVImage *fullImg, int x, int y,
  323. unsigned width, unsigned height);
  324. typedef NvCV_Status NvCV_API (*NvCVImage_Alloc_t)(NvCVImage *im, unsigned width, unsigned height,
  325. NvCVImage_PixelFormat format, NvCVImage_ComponentType type,
  326. unsigned layout, unsigned memSpace, unsigned alignment);
  327. typedef NvCV_Status NvCV_API (*NvCVImage_Realloc_t)(NvCVImage *im, unsigned width, unsigned height,
  328. NvCVImage_PixelFormat format, NvCVImage_ComponentType type,
  329. unsigned layout, unsigned memSpace, unsigned alignment);
  330. typedef NvCV_Status NvCV_API (*NvCVImage_Dealloc_t)(NvCVImage *im);
  331. typedef NvCV_Status NvCV_API (*NvCVImage_Create_t)(unsigned width, unsigned height, NvCVImage_PixelFormat format,
  332. NvCVImage_ComponentType type, unsigned layout, unsigned memSpace,
  333. unsigned alignment, NvCVImage **out);
  334. typedef NvCV_Status NvCV_API (*NvCVImage_Destroy_t)(NvCVImage *im);
  335. typedef NvCV_Status NvCV_API (*NvCVImage_ComponentOffsets_t)(NvCVImage_PixelFormat format, int *rOff, int *gOff,
  336. int *bOff, int *aOff, int *yOff);
  337. typedef NvCV_Status NvCV_API (*NvCVImage_Transfer_t)(const NvCVImage *src, NvCVImage *dst, float scale,
  338. struct CUstream_st *stream, NvCVImage *tmp);
  339. typedef NvCV_Status NvCV_API (*NvCVImage_TransferRect_t)(const NvCVImage *src, const NvCVRect2i *srcRect,
  340. NvCVImage *dst, const NvCVPoint2i *dstPt, float scale,
  341. struct CUstream_st *stream, NvCVImage *tmp);
  342. typedef NvCV_Status NvCV_API (*NvCVImage_TransferFromYUV_t)(
  343. const void *y, int yPixBytes, int yPitch, const void *u, const void *v, int uvPixBytes, int uvPitch,
  344. NvCVImage_PixelFormat yuvFormat, NvCVImage_ComponentType yuvType, unsigned yuvColorSpace, unsigned yuvMemSpace,
  345. NvCVImage *dst, const NvCVRect2i *dstRect, float scale, struct CUstream_st *stream, NvCVImage *tmp);
  346. typedef NvCV_Status NvCV_API (*NvCVImage_TransferToYUV_t)(
  347. const NvCVImage *src, const NvCVRect2i *srcRect, const void *y, int yPixBytes, int yPitch, const void *u,
  348. const void *v, int uvPixBytes, int uvPitch, NvCVImage_PixelFormat yuvFormat, NvCVImage_ComponentType yuvType,
  349. unsigned yuvColorSpace, unsigned yuvMemSpace, float scale, struct CUstream_st *stream, NvCVImage *tmp);
  350. typedef NvCV_Status NvCV_API (*NvCVImage_MapResource_t)(NvCVImage *im, struct CUstream_st *stream);
  351. typedef NvCV_Status NvCV_API (*NvCVImage_UnmapResource_t)(NvCVImage *im, struct CUstream_st *stream);
  352. typedef NvCV_Status NvCV_API (*NvCVImage_Composite_t)(const NvCVImage *fg, const NvCVImage *bg, const NvCVImage *mat,
  353. NvCVImage *dst, struct CUstream_st *stream);
  354. typedef NvCV_Status NvCV_API (*NvCVImage_CompositeRect_t)(const NvCVImage *fg, const NvCVPoint2i *fgOrg,
  355. const NvCVImage *bg, const NvCVPoint2i *bgOrg,
  356. const NvCVImage *mat, unsigned mode, NvCVImage *dst,
  357. const NvCVPoint2i *dstOrg, struct CUstream_st *stream);
  358. typedef NvCV_Status NvCV_API (*NvCVImage_CompositeOverConstant_t)(const NvCVImage *src, const NvCVImage *mat,
  359. const void *bgColor, NvCVImage *dst,
  360. struct CUstream_st *stream);
  361. typedef NvCV_Status NvCV_API (*NvCVImage_FlipY_t)(const NvCVImage *src, NvCVImage *dst);
  362. typedef NvCV_Status NvCV_API (*NvCVImage_GetYUVPointers_t)(NvCVImage *im, unsigned char **y, unsigned char **u,
  363. unsigned char **v, int *yPixBytes, int *cPixBytes,
  364. int *yRowBytes, int *cRowBytes);
  365. typedef const char *(*NvCV_GetErrorStringFromCode_t)(NvCV_Status code);
  366. /* beware: this is experimental : D3D functions */
  367. typedef NvCV_Status NvCV_API (*NvCVImage_ToD3DFormat_t)(NvCVImage_PixelFormat format, NvCVImage_ComponentType type,
  368. unsigned layout, DXGI_FORMAT *d3dFormat);
  369. typedef NvCV_Status NvCV_API (*NvCVImage_FromD3DFormat_t)(DXGI_FORMAT d3dFormat, NvCVImage_PixelFormat *format,
  370. NvCVImage_ComponentType *type, unsigned char *layout);
  371. typedef NvCV_Status NvCV_API (*NvCVImage_ToD3DColorSpace_t)(unsigned char nvcvColorSpace,
  372. DXGI_COLOR_SPACE_TYPE *pD3dColorSpace);
  373. typedef NvCV_Status NvCV_API (*NvCVImage_FromD3DColorSpace_t)(DXGI_COLOR_SPACE_TYPE d3dColorSpace,
  374. unsigned char *pNvcvColorSpace);
  375. typedef NvCV_Status NvCV_API (*NvCVImage_InitFromD3D11Texture_t)(NvCVImage *im, struct ID3D11Texture2D *tx);
  376. typedef NvCV_Status NvCV_API (*NvCVImage_InitFromD3DTexture_t)(NvCVImage *im, struct ID3D11Texture2D *tx);
  377. /* cuda runtime */
  378. typedef enum cudaError {
  379. cudaSuccess = 0,
  380. cudaErrorInvalidValue = 1,
  381. cudaErrorMemoryAllocation = 2,
  382. cudaErrorInitializationError = 3,
  383. cudaErrorCudartUnloading = 4,
  384. cudaErrorProfilerDisabled = 5,
  385. cudaErrorProfilerNotInitialized = 6,
  386. cudaErrorProfilerAlreadyStarted = 7,
  387. cudaErrorProfilerAlreadyStopped = 8,
  388. cudaErrorInvalidConfiguration = 9,
  389. cudaErrorInvalidPitchValue = 12,
  390. cudaErrorInvalidSymbol = 13,
  391. cudaErrorInvalidHostPointer = 16,
  392. cudaErrorInvalidDevicePointer = 17,
  393. cudaErrorInvalidTexture = 18,
  394. cudaErrorInvalidTextureBinding = 19,
  395. cudaErrorInvalidChannelDescriptor = 20,
  396. cudaErrorInvalidMemcpyDirection = 21,
  397. cudaErrorAddressOfConstant = 22,
  398. cudaErrorTextureFetchFailed = 23,
  399. cudaErrorTextureNotBound = 24,
  400. cudaErrorSynchronizationError = 25,
  401. cudaErrorInvalidFilterSetting = 26,
  402. cudaErrorInvalidNormSetting = 27,
  403. cudaErrorMixedDeviceExecution = 28,
  404. cudaErrorNotYetImplemented = 31,
  405. cudaErrorMemoryValueTooLarge = 32,
  406. cudaErrorStubLibrary = 34,
  407. cudaErrorInsufficientDriver = 35,
  408. cudaErrorCallRequiresNewerDriver = 36,
  409. cudaErrorInvalidSurface = 37,
  410. cudaErrorDuplicateVariableName = 43,
  411. cudaErrorDuplicateTextureName = 44,
  412. cudaErrorDuplicateSurfaceName = 45,
  413. cudaErrorDevicesUnavailable = 46,
  414. cudaErrorIncompatibleDriverContext = 49,
  415. cudaErrorMissingConfiguration = 52,
  416. cudaErrorPriorLaunchFailure = 53,
  417. cudaErrorLaunchMaxDepthExceeded = 65,
  418. cudaErrorLaunchFileScopedTex = 66,
  419. cudaErrorLaunchFileScopedSurf = 67,
  420. cudaErrorSyncDepthExceeded = 68,
  421. cudaErrorLaunchPendingCountExceeded = 69,
  422. cudaErrorInvalidDeviceFunction = 98,
  423. cudaErrorNoDevice = 100,
  424. cudaErrorInvalidDevice = 101,
  425. cudaErrorDeviceNotLicensed = 102,
  426. cudaErrorSoftwareValidityNotEstablished = 103,
  427. cudaErrorStartupFailure = 127,
  428. cudaErrorInvalidKernelImage = 200,
  429. cudaErrorDeviceUninitialized = 201,
  430. cudaErrorMapBufferObjectFailed = 205,
  431. cudaErrorUnmapBufferObjectFailed = 206,
  432. cudaErrorArrayIsMapped = 207,
  433. cudaErrorAlreadyMapped = 208,
  434. cudaErrorNoKernelImageForDevice = 209,
  435. cudaErrorAlreadyAcquired = 210,
  436. cudaErrorNotMapped = 211,
  437. cudaErrorNotMappedAsArray = 212,
  438. cudaErrorNotMappedAsPointer = 213,
  439. cudaErrorECCUncorrectable = 214,
  440. cudaErrorUnsupportedLimit = 215,
  441. cudaErrorDeviceAlreadyInUse = 216,
  442. cudaErrorPeerAccessUnsupported = 217,
  443. cudaErrorInvalidPtx = 218,
  444. cudaErrorInvalidGraphicsContext = 219,
  445. cudaErrorNvlinkUncorrectable = 220,
  446. cudaErrorJitCompilerNotFound = 221,
  447. cudaErrorUnsupportedPtxVersion = 222,
  448. cudaErrorJitCompilationDisabled = 223,
  449. cudaErrorInvalidSource = 300,
  450. cudaErrorFileNotFound = 301,
  451. cudaErrorSharedObjectSymbolNotFound = 302,
  452. cudaErrorSharedObjectInitFailed = 303,
  453. cudaErrorOperatingSystem = 304,
  454. cudaErrorInvalidResourceHandle = 400,
  455. cudaErrorIllegalState = 401,
  456. cudaErrorSymbolNotFound = 500,
  457. cudaErrorNotReady = 600,
  458. cudaErrorIllegalAddress = 700,
  459. cudaErrorLaunchOutOfResources = 701,
  460. cudaErrorLaunchTimeout = 702,
  461. cudaErrorLaunchIncompatibleTexturing = 703,
  462. cudaErrorPeerAccessAlreadyEnabled = 704,
  463. cudaErrorPeerAccessNotEnabled = 705,
  464. cudaErrorSetOnActiveProcess = 708,
  465. cudaErrorContextIsDestroyed = 709,
  466. cudaErrorAssert = 710,
  467. cudaErrorTooManyPeers = 711,
  468. cudaErrorHostMemoryAlreadyRegistered = 712,
  469. cudaErrorHostMemoryNotRegistered = 713,
  470. cudaErrorHardwareStackError = 714,
  471. cudaErrorIllegalInstruction = 715,
  472. cudaErrorMisalignedAddress = 716,
  473. cudaErrorInvalidAddressSpace = 717,
  474. cudaErrorInvalidPc = 718,
  475. cudaErrorLaunchFailure = 719,
  476. cudaErrorCooperativeLaunchTooLarge = 720,
  477. cudaErrorNotPermitted = 800,
  478. cudaErrorNotSupported = 801,
  479. cudaErrorSystemNotReady = 802,
  480. cudaErrorSystemDriverMismatch = 803,
  481. cudaErrorCompatNotSupportedOnDevice = 804,
  482. cudaErrorStreamCaptureUnsupported = 900,
  483. cudaErrorStreamCaptureInvalidated = 901,
  484. cudaErrorStreamCaptureMerge = 902,
  485. cudaErrorStreamCaptureUnmatched = 903,
  486. cudaErrorStreamCaptureUnjoined = 904,
  487. cudaErrorStreamCaptureIsolation = 905,
  488. cudaErrorStreamCaptureImplicit = 906,
  489. cudaErrorCapturedEvent = 907,
  490. cudaErrorStreamCaptureWrongThread = 908,
  491. cudaErrorTimeout = 909,
  492. cudaErrorGraphExecUpdateFailure = 910,
  493. cudaErrorUnknown = 999,
  494. cudaErrorApiFailureBase = 10000
  495. } cudaError;
  496. typedef enum cudaMemcpyKind {
  497. cudaMemcpyHostToHost = 0, /**< Host -> Host */
  498. cudaMemcpyHostToDevice = 1, /**< Host -> Device */
  499. cudaMemcpyDeviceToHost = 2, /**< Device -> Host */
  500. cudaMemcpyDeviceToDevice = 3, /**< Device -> Device */
  501. cudaMemcpyDefault = 4
  502. } cudaMemcpyKind;
  503. typedef enum cudaError cudaError_t;
  504. typedef cudaError_t CUDARTAPI (*cudaMalloc_t)(void **devPtr, size_t size);
  505. typedef cudaError_t CUDARTAPI (*cudaStreamSynchronize_t)(CUstream stream);
  506. typedef cudaError_t CUDARTAPI (*cudaFree_t)(void *devPtr);
  507. typedef cudaError_t CUDARTAPI (*cudaMemsetAsync_t)(void *devPtr, int value, size_t count, CUstream stream);
  508. typedef cudaError_t CUDARTAPI (*cudaMemcpy_t)(void *dst, const void *src, size_t count, enum cudaMemcpyKind kind);
  509. /* nvvfx */
  510. static NvVFX_GetVersion_t NvVFX_GetVersion = NULL;
  511. static NvVFX_CreateEffect_t NvVFX_CreateEffect = NULL;
  512. static NvVFX_DestroyEffect_t NvVFX_DestroyEffect = NULL;
  513. static NvVFX_SetU32_t NvVFX_SetU32 = NULL;
  514. static NvVFX_SetS32_t NvVFX_SetS32 = NULL;
  515. static NvVFX_SetF32_t NvVFX_SetF32 = NULL;
  516. static NvVFX_SetF64_t NvVFX_SetF64 = NULL;
  517. static NvVFX_SetU64_t NvVFX_SetU64 = NULL;
  518. static NvVFX_SetObject_t NvVFX_SetObject = NULL;
  519. static NvVFX_SetCudaStream_t NvVFX_SetCudaStream = NULL;
  520. static NvVFX_SetImage_t NvVFX_SetImage = NULL;
  521. static NvVFX_SetString_t NvVFX_SetString = NULL;
  522. static NvVFX_GetU32_t NvVFX_GetU32 = NULL;
  523. static NvVFX_GetS32_t NvVFX_GetS32 = NULL;
  524. static NvVFX_GetF32_t NvVFX_GetF32 = NULL;
  525. static NvVFX_GetF64_t NvVFX_GetF64 = NULL;
  526. static NvVFX_GetU64_t NvVFX_GetU64 = NULL;
  527. static NvVFX_GetObject_t NvVFX_GetObject = NULL;
  528. static NvVFX_GetCudaStream_t NvVFX_GetCudaStream = NULL;
  529. static NvVFX_GetImage_t NvVFX_GetImage = NULL;
  530. static NvVFX_GetString_t NvVFX_GetString = NULL;
  531. static NvVFX_Run_t NvVFX_Run = NULL;
  532. static NvVFX_Load_t NvVFX_Load = NULL;
  533. static NvVFX_CudaStreamCreate_t NvVFX_CudaStreamCreate = NULL;
  534. static NvVFX_CudaStreamDestroy_t NvVFX_CudaStreamDestroy = NULL;
  535. /* nvvfx sdk >= 0.7.0 */
  536. static NvVFX_SetStateObjectHandleArray_t NvVFX_SetStateObjectHandleArray = NULL;
  537. static NvVFX_AllocateState_t NvVFX_AllocateState = NULL;
  538. static NvVFX_DeallocateState_t NvVFX_DeallocateState = NULL;
  539. static NvVFX_ResetState_t NvVFX_ResetState = NULL;
  540. /*nvcvimage */
  541. static NvCVImage_Init_t NvCVImage_Init = NULL;
  542. static NvCVImage_InitView_t NvCVImage_InitView = NULL;
  543. static NvCVImage_Alloc_t NvCVImage_Alloc = NULL;
  544. static NvCVImage_Realloc_t NvCVImage_Realloc = NULL;
  545. static NvCVImage_Dealloc_t NvCVImage_Dealloc = NULL;
  546. static NvCVImage_Create_t NvCVImage_Create = NULL;
  547. static NvCVImage_Destroy_t NvCVImage_Destroy = NULL;
  548. static NvCVImage_ComponentOffsets_t NvCVImage_ComponentOffsets = NULL;
  549. static NvCVImage_Transfer_t NvCVImage_Transfer = NULL;
  550. static NvCVImage_TransferRect_t NvCVImage_TransferRect = NULL;
  551. static NvCVImage_TransferFromYUV_t NvCVImage_TransferFromYUV = NULL;
  552. static NvCVImage_TransferToYUV_t NvCVImage_TransferToYUV = NULL;
  553. static NvCVImage_MapResource_t NvCVImage_MapResource = NULL;
  554. static NvCVImage_UnmapResource_t NvCVImage_UnmapResource = NULL;
  555. static NvCVImage_Composite_t NvCVImage_Composite = NULL;
  556. static NvCVImage_CompositeRect_t NvCVImage_CompositeRect = NULL;
  557. static NvCVImage_CompositeOverConstant_t NvCVImage_CompositeOverConstant = NULL;
  558. static NvCVImage_FlipY_t NvCVImage_FlipY = NULL;
  559. static NvCVImage_GetYUVPointers_t NvCVImage_GetYUVPointers = NULL;
  560. /* nvcvimage D3D*/
  561. static NvCVImage_ToD3DFormat_t NvCVImage_ToD3DFormat = NULL;
  562. static NvCVImage_FromD3DFormat_t NvCVImage_FromD3DFormat = NULL;
  563. static NvCVImage_ToD3DColorSpace_t NvCVImage_ToD3DColorSpace = NULL;
  564. static NvCVImage_FromD3DColorSpace_t NvCVImage_FromD3DColorSpace = NULL;
  565. static NvCVImage_InitFromD3D11Texture_t NvCVImage_InitFromD3D11Texture = NULL;
  566. /* error codes */
  567. static NvCV_GetErrorStringFromCode_t NvCV_GetErrorStringFromCode = NULL;
  568. /* cuda runtime */
  569. static cudaMalloc_t cudaMalloc = NULL;
  570. static cudaStreamSynchronize_t cudaStreamSynchronize = NULL;
  571. static cudaFree_t cudaFree = NULL;
  572. static cudaMemcpy_t cudaMemcpy = NULL;
  573. static cudaMemsetAsync_t cudaMemsetAsync = NULL;
  574. static inline void release_nv_vfx()
  575. {
  576. NvVFX_CreateEffect = NULL;
  577. NvVFX_CudaStreamCreate = NULL;
  578. NvVFX_CudaStreamDestroy = NULL;
  579. NvVFX_DestroyEffect = NULL;
  580. NvVFX_GetCudaStream = NULL;
  581. NvCV_GetErrorStringFromCode = NULL;
  582. NvVFX_GetF32 = NULL;
  583. NvVFX_GetF64 = NULL;
  584. NvVFX_GetImage = NULL;
  585. NvVFX_GetObject = NULL;
  586. NvVFX_GetS32 = NULL;
  587. NvVFX_GetString = NULL;
  588. NvVFX_GetU32 = NULL;
  589. NvVFX_GetU64 = NULL;
  590. NvVFX_GetVersion = NULL;
  591. NvVFX_Load = NULL;
  592. NvVFX_Run = NULL;
  593. NvVFX_SetCudaStream = NULL;
  594. NvVFX_SetF32 = NULL;
  595. NvVFX_SetF64 = NULL;
  596. NvVFX_SetImage = NULL;
  597. NvVFX_SetObject = NULL;
  598. NvVFX_SetS32 = NULL;
  599. NvVFX_SetString = NULL;
  600. NvVFX_SetU32 = NULL;
  601. NvVFX_SetU64 = NULL;
  602. NvVFX_SetStateObjectHandleArray = NULL;
  603. NvVFX_AllocateState = NULL;
  604. NvVFX_DeallocateState = NULL;
  605. NvVFX_ResetState = NULL;
  606. if (nv_videofx) {
  607. FreeLibrary(nv_videofx);
  608. nv_videofx = NULL;
  609. }
  610. NvCVImage_Alloc = NULL;
  611. NvCVImage_ComponentOffsets = NULL;
  612. NvCVImage_Composite = NULL;
  613. NvCVImage_CompositeRect = NULL;
  614. NvCVImage_CompositeOverConstant = NULL;
  615. NvCVImage_Create = NULL;
  616. NvCVImage_Dealloc = NULL;
  617. NvCVImage_Destroy = NULL;
  618. NvCVImage_Init = NULL;
  619. NvCVImage_InitView = NULL;
  620. NvCVImage_Realloc = NULL;
  621. NvCVImage_Transfer = NULL;
  622. NvCVImage_TransferRect = NULL;
  623. NvCVImage_TransferFromYUV = NULL;
  624. NvCVImage_TransferToYUV = NULL;
  625. NvCVImage_MapResource = NULL;
  626. NvCVImage_UnmapResource = NULL;
  627. NvCVImage_InitFromD3D11Texture = NULL;
  628. NvCVImage_FlipY = NULL;
  629. NvCVImage_GetYUVPointers = NULL;
  630. NvCVImage_ToD3DFormat = NULL;
  631. NvCVImage_FromD3DFormat = NULL;
  632. NvCVImage_ToD3DColorSpace = NULL;
  633. NvCVImage_FromD3DColorSpace = NULL;
  634. if (nv_cvimage) {
  635. FreeLibrary(nv_cvimage);
  636. nv_cvimage = NULL;
  637. }
  638. cudaMalloc = NULL;
  639. cudaStreamSynchronize = NULL;
  640. cudaFree = NULL;
  641. cudaMemcpy = NULL;
  642. cudaMemsetAsync = NULL;
  643. if (nv_cudart) {
  644. FreeLibrary(nv_cudart);
  645. nv_cudart = NULL;
  646. }
  647. }
  648. static inline void nvvfx_get_sdk_path(char *buffer, const size_t len)
  649. {
  650. DWORD ret = GetEnvironmentVariableA("NV_VIDEO_EFFECTS_PATH", buffer, (DWORD)len);
  651. if (!ret || ret >= len - 1) {
  652. char path[MAX_PATH];
  653. GetEnvironmentVariableA("ProgramFiles", path, MAX_PATH);
  654. size_t max_len = sizeof(path) / sizeof(char);
  655. snprintf(buffer, max_len, "%s\\NVIDIA Corporation\\NVIDIA Video Effects", path);
  656. }
  657. }
  658. static inline bool load_nv_vfx_libs()
  659. {
  660. char fullPath[MAX_PATH];
  661. nvvfx_get_sdk_path(fullPath, MAX_PATH);
  662. SetDllDirectoryA(fullPath);
  663. nv_videofx = LoadLibrary(L"NVVideoEffects.dll");
  664. nv_cvimage = LoadLibrary(L"NVCVImage.dll");
  665. nv_cudart = LoadLibrary(L"cudart64_110.dll");
  666. SetDllDirectoryA(NULL);
  667. return !!nv_videofx && !!nv_cvimage && !!nv_cudart;
  668. }
  669. static unsigned int get_lib_version(void)
  670. {
  671. static unsigned int version = 0;
  672. static bool version_checked = false;
  673. if (version_checked)
  674. return version;
  675. version_checked = true;
  676. char path[MAX_PATH];
  677. nvvfx_get_sdk_path(path, sizeof(path));
  678. SetDllDirectoryA(path);
  679. struct win_version_info nto_ver = {0};
  680. if (get_dll_ver(L"NVVideoEffects.dll", &nto_ver))
  681. version = nto_ver.major << 24 | nto_ver.minor << 16 | nto_ver.build << 8 | nto_ver.revis << 0;
  682. SetDllDirectoryA(NULL);
  683. return version;
  684. }
  685. #endif
  686. #ifdef __cplusplus
  687. }
  688. #endif // __cplusplus