nvvfx-load.h 35 KB

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