nvvfx-load.h 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  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. /** Logging support **/
  213. enum {
  214. NVCV_LOG_FATAL, //!< Message to be printed right before aborting due to an unrecoverable error.
  215. NVCV_LOG_ERROR, //!< An operation has failed, but it is not fatal.
  216. NVCV_LOG_WARNING, //!< Something was not quite right, but we fixed it up, perhaps at a loss in performance.
  217. NVCV_LOG_INFO //!< Nothing is wrong, but this information might be of interest.
  218. };
  219. //! Image descriptor.
  220. typedef struct
  221. #ifdef _MSC_VER
  222. __declspec(dllexport)
  223. #endif // _MSC_VER
  224. NvCVImage {
  225. unsigned int width; //!< The number of pixels horizontally in the image.
  226. unsigned int height; //!< The number of pixels vertically in the image.
  227. signed int pitch; //!< The byte stride between pixels vertically.
  228. NvCVImage_PixelFormat pixelFormat; //!< The format of the pixels in the image.
  229. NvCVImage_ComponentType componentType; //!< The data type used to represent each component of the image.
  230. unsigned char pixelBytes; //!< The number of bytes in a chunky pixel.
  231. unsigned char componentBytes; //!< The number of bytes in each pixel component.
  232. unsigned char numComponents; //!< The number of components in each pixel.
  233. unsigned char planar; //!< NVCV_CHUNKY, NVCV_PLANAR, NVCV_UYVY, ....
  234. unsigned char gpuMem; //!< NVCV_CPU, NVCV_CPU_PINNED, NVCV_CUDA, NVCV_GPU
  235. unsigned char colorspace; //!< An OR of colorspace, range and chroma phase.
  236. unsigned char reserved[2]; //!< For structure padding and future expansion. Set to 0.
  237. void *pixels; //!< Pointer to pixel(0,0) in the image.
  238. void *deletePtr; //!< Buffer memory to be deleted (can be NULL).
  239. void (*deleteProc)(void *p); //!< Delete procedure to call rather than free().
  240. unsigned long long bufferBytes; //!< The maximum amount of memory available through pixels.
  241. } NvCVImage;
  242. //! Integer rectangle.
  243. typedef struct NvCVRect2i {
  244. int x; //!< The left edge of the rectangle.
  245. int y; //!< The top edge of the rectangle.
  246. int width; //!< The width of the rectangle.
  247. int height; //!< The height of the rectangle.
  248. } NvCVRect2i;
  249. //! Integer point.
  250. typedef struct NvCVPoint2i {
  251. int x; //!< The horizontal coordinate.
  252. int y; //!< The vertical coordinate
  253. } NvCVPoint2i;
  254. typedef struct CUstream_st *CUstream;
  255. typedef const char *NvVFX_EffectSelector;
  256. typedef const char *NvVFX_ParameterSelector;
  257. typedef void *NvVFX_Handle;
  258. /* requires sdk version >= 0.7.0 */
  259. typedef void *NvVFX_StateObjectHandle;
  260. /* nvvfx functions */
  261. typedef NvCV_Status NvVFX_API (*NvVFX_GetVersion_t)(unsigned int *version);
  262. typedef NvCV_Status NvVFX_API (*NvVFX_CreateEffect_t)(NvVFX_EffectSelector code, NvVFX_Handle *effect);
  263. typedef NvCV_Status NvVFX_API (*NvVFX_DestroyEffect_t)(NvVFX_Handle effect);
  264. typedef NvCV_Status NvVFX_API (*NvVFX_SetU32_t)(NvVFX_Handle effect, NvVFX_ParameterSelector param_name,
  265. unsigned int val);
  266. typedef NvCV_Status NvVFX_API (*NvVFX_SetS32_t)(NvVFX_Handle effect, NvVFX_ParameterSelector param_name, int val);
  267. typedef NvCV_Status NvVFX_API (*NvVFX_SetF32_t)(NvVFX_Handle effect, NvVFX_ParameterSelector param_name, float val);
  268. typedef NvCV_Status NvVFX_API (*NvVFX_SetF64_t)(NvVFX_Handle effect, NvVFX_ParameterSelector param_name, double val);
  269. typedef NvCV_Status NvVFX_API (*NvVFX_SetU64_t)(NvVFX_Handle effect, NvVFX_ParameterSelector param_name,
  270. unsigned long long val);
  271. typedef NvCV_Status NvVFX_API (*NvVFX_SetObject_t)(NvVFX_Handle effect, NvVFX_ParameterSelector param_name, void *ptr);
  272. /* requires sdk version >= 0.7.0 */
  273. typedef NvCV_Status NvVFX_API (*NvVFX_SetStateObjectHandleArray_t)(NvVFX_Handle effect,
  274. NvVFX_ParameterSelector param_name,
  275. NvVFX_StateObjectHandle *handle);
  276. /* ----------------------------- */
  277. typedef NvCV_Status NvVFX_API (*NvVFX_SetCudaStream_t)(NvVFX_Handle effect, NvVFX_ParameterSelector param_name,
  278. CUstream stream);
  279. typedef NvCV_Status NvVFX_API (*NvVFX_SetImage_t)(NvVFX_Handle effect, NvVFX_ParameterSelector param_name,
  280. NvCVImage *im);
  281. typedef NvCV_Status NvVFX_API (*NvVFX_SetString_t)(NvVFX_Handle effect, NvVFX_ParameterSelector param_name,
  282. const char *str);
  283. typedef NvCV_Status NvVFX_API (*NvVFX_GetU32_t)(NvVFX_Handle effect, NvVFX_ParameterSelector param_name,
  284. unsigned int *val);
  285. typedef NvCV_Status NvVFX_API (*NvVFX_GetS32_t)(NvVFX_Handle effect, NvVFX_ParameterSelector param_name, int *val);
  286. typedef NvCV_Status NvVFX_API (*NvVFX_GetF32_t)(NvVFX_Handle effect, NvVFX_ParameterSelector param_name, float *val);
  287. typedef NvCV_Status NvVFX_API (*NvVFX_GetF64_t)(NvVFX_Handle effect, NvVFX_ParameterSelector param_name, double *val);
  288. typedef NvCV_Status NvVFX_API (*NvVFX_GetU64_t)(NvVFX_Handle effect, NvVFX_ParameterSelector param_name,
  289. unsigned long long *val);
  290. typedef NvCV_Status NvVFX_API (*NvVFX_GetObject_t)(NvVFX_Handle effect, NvVFX_ParameterSelector param_name, void **ptr);
  291. typedef NvCV_Status NvVFX_API (*NvVFX_GetCudaStream_t)(NvVFX_Handle effect, NvVFX_ParameterSelector param_name,
  292. CUstream *stream);
  293. typedef NvCV_Status NvVFX_API (*NvVFX_GetImage_t)(NvVFX_Handle effect, NvVFX_ParameterSelector param_name,
  294. NvCVImage *im);
  295. typedef NvCV_Status NvVFX_API (*NvVFX_GetString_t)(NvVFX_Handle effect, NvVFX_ParameterSelector param_name,
  296. const char **str);
  297. typedef NvCV_Status NvVFX_API (*NvVFX_Run_t)(NvVFX_Handle effect, int async);
  298. typedef NvCV_Status NvVFX_API (*NvVFX_Load_t)(NvVFX_Handle effect);
  299. typedef NvCV_Status NvVFX_API (*NvVFX_CudaStreamCreate_t)(CUstream *stream);
  300. typedef NvCV_Status NvVFX_API (*NvVFX_CudaStreamDestroy_t)(CUstream stream);
  301. /* requires SDK version >= 0.7.0 */
  302. typedef NvCV_Status NvVFX_API (*NvVFX_AllocateState_t)(NvVFX_Handle effect, NvVFX_StateObjectHandle *handle);
  303. typedef NvCV_Status NvVFX_API (*NvVFX_DeallocateState_t)(NvVFX_Handle effect, NvVFX_StateObjectHandle handle);
  304. typedef NvCV_Status NvVFX_API (*NvVFX_ResetState_t)(NvVFX_Handle effect, NvVFX_StateObjectHandle handle);
  305. /* requires SDK version >= 0.7.5 */
  306. typedef NvCV_Status NvVFX_API (*NvVFX_ConfigureLogger_t)(int verbosity, const char *file,
  307. void (*cb)(void *, const char *), void *cb_data);
  308. /* NvCVImage functions */
  309. typedef NvCV_Status NvCV_API (*NvCVImage_Init_t)(NvCVImage *im, unsigned width, unsigned height, int pitch,
  310. void *pixels, NvCVImage_PixelFormat format,
  311. NvCVImage_ComponentType type, unsigned layout, unsigned memSpace);
  312. typedef NvCV_Status NvCV_API (*NvCVImage_InitView_t)(NvCVImage *subImg, NvCVImage *fullImg, int x, int y,
  313. unsigned width, unsigned height);
  314. typedef NvCV_Status NvCV_API (*NvCVImage_Alloc_t)(NvCVImage *im, unsigned width, unsigned height,
  315. NvCVImage_PixelFormat format, NvCVImage_ComponentType type,
  316. unsigned layout, unsigned memSpace, unsigned alignment);
  317. typedef NvCV_Status NvCV_API (*NvCVImage_Realloc_t)(NvCVImage *im, unsigned width, unsigned height,
  318. NvCVImage_PixelFormat format, NvCVImage_ComponentType type,
  319. unsigned layout, unsigned memSpace, unsigned alignment);
  320. typedef NvCV_Status NvCV_API (*NvCVImage_Dealloc_t)(NvCVImage *im);
  321. typedef NvCV_Status NvCV_API (*NvCVImage_Create_t)(unsigned width, unsigned height, NvCVImage_PixelFormat format,
  322. NvCVImage_ComponentType type, unsigned layout, unsigned memSpace,
  323. unsigned alignment, NvCVImage **out);
  324. typedef NvCV_Status NvCV_API (*NvCVImage_Destroy_t)(NvCVImage *im);
  325. typedef NvCV_Status NvCV_API (*NvCVImage_ComponentOffsets_t)(NvCVImage_PixelFormat format, int *rOff, int *gOff,
  326. int *bOff, int *aOff, int *yOff);
  327. typedef NvCV_Status NvCV_API (*NvCVImage_Transfer_t)(const NvCVImage *src, NvCVImage *dst, float scale,
  328. struct CUstream_st *stream, NvCVImage *tmp);
  329. typedef NvCV_Status NvCV_API (*NvCVImage_TransferRect_t)(const NvCVImage *src, const NvCVRect2i *srcRect,
  330. NvCVImage *dst, const NvCVPoint2i *dstPt, float scale,
  331. struct CUstream_st *stream, NvCVImage *tmp);
  332. typedef NvCV_Status NvCV_API (*NvCVImage_TransferFromYUV_t)(
  333. const void *y, int yPixBytes, int yPitch, const void *u, const void *v, int uvPixBytes, int uvPitch,
  334. NvCVImage_PixelFormat yuvFormat, NvCVImage_ComponentType yuvType, unsigned yuvColorSpace, unsigned yuvMemSpace,
  335. NvCVImage *dst, const NvCVRect2i *dstRect, float scale, struct CUstream_st *stream, NvCVImage *tmp);
  336. typedef NvCV_Status NvCV_API (*NvCVImage_TransferToYUV_t)(
  337. const NvCVImage *src, const NvCVRect2i *srcRect, const void *y, int yPixBytes, int yPitch, const void *u,
  338. const void *v, int uvPixBytes, int uvPitch, NvCVImage_PixelFormat yuvFormat, NvCVImage_ComponentType yuvType,
  339. unsigned yuvColorSpace, unsigned yuvMemSpace, float scale, struct CUstream_st *stream, NvCVImage *tmp);
  340. typedef NvCV_Status NvCV_API (*NvCVImage_MapResource_t)(NvCVImage *im, struct CUstream_st *stream);
  341. typedef NvCV_Status NvCV_API (*NvCVImage_UnmapResource_t)(NvCVImage *im, struct CUstream_st *stream);
  342. typedef NvCV_Status NvCV_API (*NvCVImage_Composite_t)(const NvCVImage *fg, const NvCVImage *bg, const NvCVImage *mat,
  343. NvCVImage *dst, struct CUstream_st *stream);
  344. typedef NvCV_Status NvCV_API (*NvCVImage_CompositeRect_t)(const NvCVImage *fg, const NvCVPoint2i *fgOrg,
  345. const NvCVImage *bg, const NvCVPoint2i *bgOrg,
  346. const NvCVImage *mat, unsigned mode, NvCVImage *dst,
  347. const NvCVPoint2i *dstOrg, struct CUstream_st *stream);
  348. typedef NvCV_Status NvCV_API (*NvCVImage_CompositeOverConstant_t)(const NvCVImage *src, const NvCVImage *mat,
  349. const void *bgColor, NvCVImage *dst,
  350. struct CUstream_st *stream);
  351. typedef NvCV_Status NvCV_API (*NvCVImage_FlipY_t)(const NvCVImage *src, NvCVImage *dst);
  352. typedef NvCV_Status NvCV_API (*NvCVImage_GetYUVPointers_t)(NvCVImage *im, unsigned char **y, unsigned char **u,
  353. unsigned char **v, int *yPixBytes, int *cPixBytes,
  354. int *yRowBytes, int *cRowBytes);
  355. typedef const char *(*NvCV_GetErrorStringFromCode_t)(NvCV_Status code);
  356. /* beware: this is experimental : D3D functions */
  357. typedef NvCV_Status NvCV_API (*NvCVImage_ToD3DFormat_t)(NvCVImage_PixelFormat format, NvCVImage_ComponentType type,
  358. unsigned layout, DXGI_FORMAT *d3dFormat);
  359. typedef NvCV_Status NvCV_API (*NvCVImage_FromD3DFormat_t)(DXGI_FORMAT d3dFormat, NvCVImage_PixelFormat *format,
  360. NvCVImage_ComponentType *type, unsigned char *layout);
  361. typedef NvCV_Status NvCV_API (*NvCVImage_ToD3DColorSpace_t)(unsigned char nvcvColorSpace,
  362. DXGI_COLOR_SPACE_TYPE *pD3dColorSpace);
  363. typedef NvCV_Status NvCV_API (*NvCVImage_FromD3DColorSpace_t)(DXGI_COLOR_SPACE_TYPE d3dColorSpace,
  364. unsigned char *pNvcvColorSpace);
  365. typedef NvCV_Status NvCV_API (*NvCVImage_InitFromD3D11Texture_t)(NvCVImage *im, struct ID3D11Texture2D *tx);
  366. typedef NvCV_Status NvCV_API (*NvCVImage_InitFromD3DTexture_t)(NvCVImage *im, struct ID3D11Texture2D *tx);
  367. /* cuda runtime */
  368. typedef enum cudaError {
  369. cudaSuccess = 0,
  370. cudaErrorInvalidValue = 1,
  371. cudaErrorMemoryAllocation = 2,
  372. cudaErrorInitializationError = 3,
  373. cudaErrorCudartUnloading = 4,
  374. cudaErrorProfilerDisabled = 5,
  375. cudaErrorProfilerNotInitialized = 6,
  376. cudaErrorProfilerAlreadyStarted = 7,
  377. cudaErrorProfilerAlreadyStopped = 8,
  378. cudaErrorInvalidConfiguration = 9,
  379. cudaErrorInvalidPitchValue = 12,
  380. cudaErrorInvalidSymbol = 13,
  381. cudaErrorInvalidHostPointer = 16,
  382. cudaErrorInvalidDevicePointer = 17,
  383. cudaErrorInvalidTexture = 18,
  384. cudaErrorInvalidTextureBinding = 19,
  385. cudaErrorInvalidChannelDescriptor = 20,
  386. cudaErrorInvalidMemcpyDirection = 21,
  387. cudaErrorAddressOfConstant = 22,
  388. cudaErrorTextureFetchFailed = 23,
  389. cudaErrorTextureNotBound = 24,
  390. cudaErrorSynchronizationError = 25,
  391. cudaErrorInvalidFilterSetting = 26,
  392. cudaErrorInvalidNormSetting = 27,
  393. cudaErrorMixedDeviceExecution = 28,
  394. cudaErrorNotYetImplemented = 31,
  395. cudaErrorMemoryValueTooLarge = 32,
  396. cudaErrorStubLibrary = 34,
  397. cudaErrorInsufficientDriver = 35,
  398. cudaErrorCallRequiresNewerDriver = 36,
  399. cudaErrorInvalidSurface = 37,
  400. cudaErrorDuplicateVariableName = 43,
  401. cudaErrorDuplicateTextureName = 44,
  402. cudaErrorDuplicateSurfaceName = 45,
  403. cudaErrorDevicesUnavailable = 46,
  404. cudaErrorIncompatibleDriverContext = 49,
  405. cudaErrorMissingConfiguration = 52,
  406. cudaErrorPriorLaunchFailure = 53,
  407. cudaErrorLaunchMaxDepthExceeded = 65,
  408. cudaErrorLaunchFileScopedTex = 66,
  409. cudaErrorLaunchFileScopedSurf = 67,
  410. cudaErrorSyncDepthExceeded = 68,
  411. cudaErrorLaunchPendingCountExceeded = 69,
  412. cudaErrorInvalidDeviceFunction = 98,
  413. cudaErrorNoDevice = 100,
  414. cudaErrorInvalidDevice = 101,
  415. cudaErrorDeviceNotLicensed = 102,
  416. cudaErrorSoftwareValidityNotEstablished = 103,
  417. cudaErrorStartupFailure = 127,
  418. cudaErrorInvalidKernelImage = 200,
  419. cudaErrorDeviceUninitialized = 201,
  420. cudaErrorMapBufferObjectFailed = 205,
  421. cudaErrorUnmapBufferObjectFailed = 206,
  422. cudaErrorArrayIsMapped = 207,
  423. cudaErrorAlreadyMapped = 208,
  424. cudaErrorNoKernelImageForDevice = 209,
  425. cudaErrorAlreadyAcquired = 210,
  426. cudaErrorNotMapped = 211,
  427. cudaErrorNotMappedAsArray = 212,
  428. cudaErrorNotMappedAsPointer = 213,
  429. cudaErrorECCUncorrectable = 214,
  430. cudaErrorUnsupportedLimit = 215,
  431. cudaErrorDeviceAlreadyInUse = 216,
  432. cudaErrorPeerAccessUnsupported = 217,
  433. cudaErrorInvalidPtx = 218,
  434. cudaErrorInvalidGraphicsContext = 219,
  435. cudaErrorNvlinkUncorrectable = 220,
  436. cudaErrorJitCompilerNotFound = 221,
  437. cudaErrorUnsupportedPtxVersion = 222,
  438. cudaErrorJitCompilationDisabled = 223,
  439. cudaErrorInvalidSource = 300,
  440. cudaErrorFileNotFound = 301,
  441. cudaErrorSharedObjectSymbolNotFound = 302,
  442. cudaErrorSharedObjectInitFailed = 303,
  443. cudaErrorOperatingSystem = 304,
  444. cudaErrorInvalidResourceHandle = 400,
  445. cudaErrorIllegalState = 401,
  446. cudaErrorSymbolNotFound = 500,
  447. cudaErrorNotReady = 600,
  448. cudaErrorIllegalAddress = 700,
  449. cudaErrorLaunchOutOfResources = 701,
  450. cudaErrorLaunchTimeout = 702,
  451. cudaErrorLaunchIncompatibleTexturing = 703,
  452. cudaErrorPeerAccessAlreadyEnabled = 704,
  453. cudaErrorPeerAccessNotEnabled = 705,
  454. cudaErrorSetOnActiveProcess = 708,
  455. cudaErrorContextIsDestroyed = 709,
  456. cudaErrorAssert = 710,
  457. cudaErrorTooManyPeers = 711,
  458. cudaErrorHostMemoryAlreadyRegistered = 712,
  459. cudaErrorHostMemoryNotRegistered = 713,
  460. cudaErrorHardwareStackError = 714,
  461. cudaErrorIllegalInstruction = 715,
  462. cudaErrorMisalignedAddress = 716,
  463. cudaErrorInvalidAddressSpace = 717,
  464. cudaErrorInvalidPc = 718,
  465. cudaErrorLaunchFailure = 719,
  466. cudaErrorCooperativeLaunchTooLarge = 720,
  467. cudaErrorNotPermitted = 800,
  468. cudaErrorNotSupported = 801,
  469. cudaErrorSystemNotReady = 802,
  470. cudaErrorSystemDriverMismatch = 803,
  471. cudaErrorCompatNotSupportedOnDevice = 804,
  472. cudaErrorStreamCaptureUnsupported = 900,
  473. cudaErrorStreamCaptureInvalidated = 901,
  474. cudaErrorStreamCaptureMerge = 902,
  475. cudaErrorStreamCaptureUnmatched = 903,
  476. cudaErrorStreamCaptureUnjoined = 904,
  477. cudaErrorStreamCaptureIsolation = 905,
  478. cudaErrorStreamCaptureImplicit = 906,
  479. cudaErrorCapturedEvent = 907,
  480. cudaErrorStreamCaptureWrongThread = 908,
  481. cudaErrorTimeout = 909,
  482. cudaErrorGraphExecUpdateFailure = 910,
  483. cudaErrorUnknown = 999,
  484. cudaErrorApiFailureBase = 10000
  485. } cudaError;
  486. typedef enum cudaMemcpyKind {
  487. cudaMemcpyHostToHost = 0, /**< Host -> Host */
  488. cudaMemcpyHostToDevice = 1, /**< Host -> Device */
  489. cudaMemcpyDeviceToHost = 2, /**< Device -> Host */
  490. cudaMemcpyDeviceToDevice = 3, /**< Device -> Device */
  491. cudaMemcpyDefault = 4
  492. } cudaMemcpyKind;
  493. typedef enum cudaError cudaError_t;
  494. typedef cudaError_t CUDARTAPI (*cudaMalloc_t)(void **devPtr, size_t size);
  495. typedef cudaError_t CUDARTAPI (*cudaStreamSynchronize_t)(CUstream stream);
  496. typedef cudaError_t CUDARTAPI (*cudaFree_t)(void *devPtr);
  497. typedef cudaError_t CUDARTAPI (*cudaMemsetAsync_t)(void *devPtr, int value, size_t count, CUstream stream);
  498. typedef cudaError_t CUDARTAPI (*cudaMemcpy_t)(void *dst, const void *src, size_t count, enum cudaMemcpyKind kind);
  499. /* NVVFX */
  500. static NvVFX_GetVersion_t NvVFX_GetVersion = NULL;
  501. static NvVFX_CreateEffect_t NvVFX_CreateEffect = NULL;
  502. static NvVFX_DestroyEffect_t NvVFX_DestroyEffect = NULL;
  503. static NvVFX_SetU32_t NvVFX_SetU32 = NULL;
  504. static NvVFX_SetS32_t NvVFX_SetS32 = NULL;
  505. static NvVFX_SetF32_t NvVFX_SetF32 = NULL;
  506. static NvVFX_SetF64_t NvVFX_SetF64 = NULL;
  507. static NvVFX_SetU64_t NvVFX_SetU64 = NULL;
  508. static NvVFX_SetObject_t NvVFX_SetObject = NULL;
  509. static NvVFX_SetCudaStream_t NvVFX_SetCudaStream = NULL;
  510. static NvVFX_SetImage_t NvVFX_SetImage = NULL;
  511. static NvVFX_SetString_t NvVFX_SetString = NULL;
  512. static NvVFX_GetU32_t NvVFX_GetU32 = NULL;
  513. static NvVFX_GetS32_t NvVFX_GetS32 = NULL;
  514. static NvVFX_GetF32_t NvVFX_GetF32 = NULL;
  515. static NvVFX_GetF64_t NvVFX_GetF64 = NULL;
  516. static NvVFX_GetU64_t NvVFX_GetU64 = NULL;
  517. static NvVFX_GetObject_t NvVFX_GetObject = NULL;
  518. static NvVFX_GetCudaStream_t NvVFX_GetCudaStream = NULL;
  519. static NvVFX_GetImage_t NvVFX_GetImage = NULL;
  520. static NvVFX_GetString_t NvVFX_GetString = NULL;
  521. static NvVFX_Run_t NvVFX_Run = NULL;
  522. static NvVFX_Load_t NvVFX_Load = NULL;
  523. static NvVFX_CudaStreamCreate_t NvVFX_CudaStreamCreate = NULL;
  524. static NvVFX_CudaStreamDestroy_t NvVFX_CudaStreamDestroy = NULL;
  525. /* NVVFX SDK >= 0.7.0 */
  526. static NvVFX_SetStateObjectHandleArray_t NvVFX_SetStateObjectHandleArray = NULL;
  527. static NvVFX_AllocateState_t NvVFX_AllocateState = NULL;
  528. static NvVFX_DeallocateState_t NvVFX_DeallocateState = NULL;
  529. static NvVFX_ResetState_t NvVFX_ResetState = NULL;
  530. /* NVVFX SDK >= 0.7.5 */
  531. static NvVFX_ConfigureLogger_t NvVFX_ConfigureLogger = NULL;
  532. /*nvcvimage */
  533. static NvCVImage_Init_t NvCVImage_Init = NULL;
  534. static NvCVImage_InitView_t NvCVImage_InitView = NULL;
  535. static NvCVImage_Alloc_t NvCVImage_Alloc = NULL;
  536. static NvCVImage_Realloc_t NvCVImage_Realloc = NULL;
  537. static NvCVImage_Dealloc_t NvCVImage_Dealloc = NULL;
  538. static NvCVImage_Create_t NvCVImage_Create = NULL;
  539. static NvCVImage_Destroy_t NvCVImage_Destroy = NULL;
  540. static NvCVImage_ComponentOffsets_t NvCVImage_ComponentOffsets = NULL;
  541. static NvCVImage_Transfer_t NvCVImage_Transfer = NULL;
  542. static NvCVImage_TransferRect_t NvCVImage_TransferRect = NULL;
  543. static NvCVImage_TransferFromYUV_t NvCVImage_TransferFromYUV = NULL;
  544. static NvCVImage_TransferToYUV_t NvCVImage_TransferToYUV = NULL;
  545. static NvCVImage_MapResource_t NvCVImage_MapResource = NULL;
  546. static NvCVImage_UnmapResource_t NvCVImage_UnmapResource = NULL;
  547. static NvCVImage_Composite_t NvCVImage_Composite = NULL;
  548. static NvCVImage_CompositeRect_t NvCVImage_CompositeRect = NULL;
  549. static NvCVImage_CompositeOverConstant_t NvCVImage_CompositeOverConstant = NULL;
  550. static NvCVImage_FlipY_t NvCVImage_FlipY = NULL;
  551. static NvCVImage_GetYUVPointers_t NvCVImage_GetYUVPointers = NULL;
  552. /* nvcvimage D3D*/
  553. static NvCVImage_ToD3DFormat_t NvCVImage_ToD3DFormat = NULL;
  554. static NvCVImage_FromD3DFormat_t NvCVImage_FromD3DFormat = NULL;
  555. static NvCVImage_ToD3DColorSpace_t NvCVImage_ToD3DColorSpace = NULL;
  556. static NvCVImage_FromD3DColorSpace_t NvCVImage_FromD3DColorSpace = NULL;
  557. static NvCVImage_InitFromD3D11Texture_t NvCVImage_InitFromD3D11Texture = NULL;
  558. /* error codes */
  559. static NvCV_GetErrorStringFromCode_t NvCV_GetErrorStringFromCode = NULL;
  560. /* cuda runtime */
  561. static cudaMalloc_t cudaMalloc = NULL;
  562. static cudaStreamSynchronize_t cudaStreamSynchronize = NULL;
  563. static cudaFree_t cudaFree = NULL;
  564. static cudaMemcpy_t cudaMemcpy = NULL;
  565. static cudaMemsetAsync_t cudaMemsetAsync = NULL;
  566. static inline void release_nv_vfx()
  567. {
  568. NvVFX_CreateEffect = NULL;
  569. NvVFX_CudaStreamCreate = NULL;
  570. NvVFX_CudaStreamDestroy = NULL;
  571. NvVFX_DestroyEffect = NULL;
  572. NvVFX_GetCudaStream = NULL;
  573. NvCV_GetErrorStringFromCode = NULL;
  574. NvVFX_GetF32 = NULL;
  575. NvVFX_GetF64 = NULL;
  576. NvVFX_GetImage = NULL;
  577. NvVFX_GetObject = NULL;
  578. NvVFX_GetS32 = NULL;
  579. NvVFX_GetString = NULL;
  580. NvVFX_GetU32 = NULL;
  581. NvVFX_GetU64 = NULL;
  582. NvVFX_GetVersion = NULL;
  583. NvVFX_Load = NULL;
  584. NvVFX_Run = NULL;
  585. NvVFX_SetCudaStream = NULL;
  586. NvVFX_SetF32 = NULL;
  587. NvVFX_SetF64 = NULL;
  588. NvVFX_SetImage = NULL;
  589. NvVFX_SetObject = NULL;
  590. NvVFX_SetS32 = NULL;
  591. NvVFX_SetString = NULL;
  592. NvVFX_SetU32 = NULL;
  593. NvVFX_SetU64 = NULL;
  594. NvVFX_SetStateObjectHandleArray = NULL;
  595. NvVFX_AllocateState = NULL;
  596. NvVFX_DeallocateState = NULL;
  597. NvVFX_ResetState = NULL;
  598. NvVFX_ConfigureLogger = NULL;
  599. if (nv_videofx) {
  600. FreeLibrary(nv_videofx);
  601. nv_videofx = NULL;
  602. }
  603. NvCVImage_Alloc = NULL;
  604. NvCVImage_ComponentOffsets = NULL;
  605. NvCVImage_Composite = NULL;
  606. NvCVImage_CompositeRect = NULL;
  607. NvCVImage_CompositeOverConstant = NULL;
  608. NvCVImage_Create = NULL;
  609. NvCVImage_Dealloc = NULL;
  610. NvCVImage_Destroy = NULL;
  611. NvCVImage_Init = NULL;
  612. NvCVImage_InitView = NULL;
  613. NvCVImage_Realloc = NULL;
  614. NvCVImage_Transfer = NULL;
  615. NvCVImage_TransferRect = NULL;
  616. NvCVImage_TransferFromYUV = NULL;
  617. NvCVImage_TransferToYUV = NULL;
  618. NvCVImage_MapResource = NULL;
  619. NvCVImage_UnmapResource = NULL;
  620. NvCVImage_InitFromD3D11Texture = NULL;
  621. NvCVImage_FlipY = NULL;
  622. NvCVImage_GetYUVPointers = NULL;
  623. NvCVImage_ToD3DFormat = NULL;
  624. NvCVImage_FromD3DFormat = NULL;
  625. NvCVImage_ToD3DColorSpace = NULL;
  626. NvCVImage_FromD3DColorSpace = NULL;
  627. if (nv_cvimage) {
  628. FreeLibrary(nv_cvimage);
  629. nv_cvimage = NULL;
  630. }
  631. }
  632. static inline void nvvfx_get_sdk_path(char *buffer, const size_t len)
  633. {
  634. DWORD ret = GetEnvironmentVariableA("NV_VIDEO_EFFECTS_PATH", buffer, (DWORD)len);
  635. if (!ret || ret >= len - 1) {
  636. char path[MAX_PATH];
  637. GetEnvironmentVariableA("ProgramFiles", path, MAX_PATH);
  638. size_t max_len = sizeof(path) / sizeof(char);
  639. snprintf(buffer, max_len, "%s\\NVIDIA Corporation\\NVIDIA Video Effects", path);
  640. }
  641. }
  642. static inline bool load_nv_vfx_libs()
  643. {
  644. char fullPath[MAX_PATH];
  645. nvvfx_get_sdk_path(fullPath, MAX_PATH);
  646. SetDllDirectoryA(fullPath);
  647. nv_videofx = LoadLibrary(L"NVVideoEffects.dll");
  648. nv_cvimage = LoadLibrary(L"NVCVImage.dll");
  649. SetDllDirectoryA(NULL);
  650. return !!nv_videofx && !!nv_cvimage;
  651. }
  652. static unsigned int get_lib_version(void)
  653. {
  654. static unsigned int version = 0;
  655. static bool version_checked = false;
  656. if (version_checked)
  657. return version;
  658. version_checked = true;
  659. char path[MAX_PATH];
  660. nvvfx_get_sdk_path(path, sizeof(path));
  661. SetDllDirectoryA(path);
  662. struct win_version_info nto_ver = {0};
  663. if (get_dll_ver(L"NVVideoEffects.dll", &nto_ver))
  664. version = nto_ver.major << 24 | nto_ver.minor << 16 | nto_ver.build << 8 | nto_ver.revis << 0;
  665. SetDllDirectoryA(NULL);
  666. return version;
  667. }
  668. #endif
  669. #ifdef __cplusplus
  670. }
  671. #endif // __cplusplus