Skip to content

Commit

Permalink
Add D3D11 interop functions
Browse files Browse the repository at this point in the history
  • Loading branch information
BtbN authored and TimoRoth committed Nov 1, 2022
1 parent 924ab9d commit b677175
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
14 changes: 13 additions & 1 deletion include/ffnvcodec/dynlink_cuda.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,13 @@ typedef enum CUeglColorFormat
CU_EGL_COLOR_FORMAT_Y12V12U12_420_SEMIPLANAR = 0x19,
} CUeglColorFormat;

typedef enum CUd3d11DeviceList_enum
{
CU_D3D11_DEVICE_LIST_ALL = 1,
CU_D3D11_DEVICE_LIST_CURRENT_FRAME = 2,
CU_D3D11_DEVICE_LIST_NEXT_FRAME = 3,
} CUd3d11DeviceList;

#ifndef CU_UUID_HAS_BEEN_DEFINED
#define CU_UUID_HAS_BEEN_DEFINED
typedef struct CUuuid_st {
Expand Down Expand Up @@ -442,7 +449,7 @@ typedef CUresult CUDAAPI tcuEventQuery(CUevent hEvent);
typedef CUresult CUDAAPI tcuEventRecord(CUevent hEvent, CUstream hStream);

typedef CUresult CUDAAPI tcuLaunchKernel(CUfunction f, unsigned int gridDimX, unsigned int gridDimY, unsigned int gridDimZ, unsigned int blockDimX, unsigned int blockDimY, unsigned int blockDimZ, unsigned int sharedMemBytes, CUstream hStream, void** kernelParams, void** extra);
typedef CUresult CUDAAPI tcuLinkCreate(unsigned int numOptions, CUjit_option* options, void** optionValues, CUlinkState* stateOut);
typedef CUresult CUDAAPI tcuLinkCreate(unsigned int numOptions, CUjit_option* options, void** optionValues, CUlinkState* stateOut);
typedef CUresult CUDAAPI tcuLinkAddData(CUlinkState state, CUjitInputType type, void* data, size_t size, const char* name, unsigned int numOptions, CUjit_option* options, void** optionValues);
typedef CUresult CUDAAPI tcuLinkComplete(CUlinkState state, void** cubinOut, size_t* sizeOut);
typedef CUresult CUDAAPI tcuLinkDestroy(CUlinkState state);
Expand All @@ -459,6 +466,7 @@ typedef CUresult CUDAAPI tcuGraphicsUnregisterResource(CUgraphicsResource resour
typedef CUresult CUDAAPI tcuGraphicsMapResources(unsigned int count, CUgraphicsResource* resources, CUstream hStream);
typedef CUresult CUDAAPI tcuGraphicsUnmapResources(unsigned int count, CUgraphicsResource* resources, CUstream hStream);
typedef CUresult CUDAAPI tcuGraphicsSubResourceGetMappedArray(CUarray* pArray, CUgraphicsResource resource, unsigned int arrayIndex, unsigned int mipLevel);
typedef CUresult CUDAAPI tcuGraphicsResourceGetMappedPointer(CUdeviceptr *devPtrOut, size_t *sizeOut, CUgraphicsResource resource);

typedef CUresult CUDAAPI tcuImportExternalMemory(CUexternalMemory* extMem_out, const CUDA_EXTERNAL_MEMORY_HANDLE_DESC* memHandleDesc);
typedef CUresult CUDAAPI tcuDestroyExternalMemory(CUexternalMemory extMem);
Expand All @@ -480,4 +488,8 @@ typedef CUresult CUDAAPI tcuEGLStreamProducerDisconnect(CUeglStreamConnection* c
typedef CUresult CUDAAPI tcuEGLStreamConsumerDisconnect(CUeglStreamConnection* conn);
typedef CUresult CUDAAPI tcuEGLStreamProducerPresentFrame(CUeglStreamConnection* conn, CUeglFrame eglframe, CUstream* pStream);
typedef CUresult CUDAAPI tcuEGLStreamProducerReturnFrame(CUeglStreamConnection* conn, CUeglFrame* eglframe, CUstream* pStream);

typedef CUresult CUDAAPI tcuD3D11GetDevice(CUdevice *device, void *dxgiAdapter);
typedef CUresult CUDAAPI tcuD3D11GetDevices(unsigned int *deviceCountOut, CUdevice *devices, unsigned int deviceCount, void *d3d11device, CUd3d11DeviceList listType);
typedef CUresult CUDAAPI tcuGraphicsD3D11RegisterResource(CUgraphicsResource *cudaResourceOut, void *d3d11Resource, unsigned int flags);
#endif
14 changes: 14 additions & 0 deletions include/ffnvcodec/dynlink_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ typedef struct CudaFunctions {
tcuGraphicsMapResources *cuGraphicsMapResources;
tcuGraphicsUnmapResources *cuGraphicsUnmapResources;
tcuGraphicsSubResourceGetMappedArray *cuGraphicsSubResourceGetMappedArray;
tcuGraphicsResourceGetMappedPointer *cuGraphicsResourceGetMappedPointer;

tcuImportExternalMemory *cuImportExternalMemory;
tcuDestroyExternalMemory *cuDestroyExternalMemory;
Expand All @@ -225,6 +226,12 @@ typedef struct CudaFunctions {
tcuEGLStreamProducerPresentFrame *cuEGLStreamProducerPresentFrame;
tcuEGLStreamProducerReturnFrame *cuEGLStreamProducerReturnFrame;

#if defined(_WIN32) || defined(__CYGWIN__)
tcuD3D11GetDevice *cuD3D11GetDevice;
tcuD3D11GetDevices *cuD3D11GetDevices;
tcuGraphicsD3D11RegisterResource *cuGraphicsD3D11RegisterResource;
#endif

FFNV_LIB_HANDLE lib;
} CudaFunctions;
#else
Expand Down Expand Up @@ -356,6 +363,7 @@ static inline int cuda_load_functions(CudaFunctions **functions, void *logctx)
LOAD_SYMBOL(cuGraphicsMapResources, tcuGraphicsMapResources, "cuGraphicsMapResources");
LOAD_SYMBOL(cuGraphicsUnmapResources, tcuGraphicsUnmapResources, "cuGraphicsUnmapResources");
LOAD_SYMBOL(cuGraphicsSubResourceGetMappedArray, tcuGraphicsSubResourceGetMappedArray, "cuGraphicsSubResourceGetMappedArray");
LOAD_SYMBOL(cuGraphicsResourceGetMappedPointer, tcuGraphicsResourceGetMappedPointer, "cuGraphicsResourceGetMappedPointer_v2");

LOAD_SYMBOL_OPT(cuDeviceGetUuid, tcuDeviceGetUuid, "cuDeviceGetUuid");
LOAD_SYMBOL_OPT(cuImportExternalMemory, tcuImportExternalMemory, "cuImportExternalMemory");
Expand All @@ -379,6 +387,12 @@ static inline int cuda_load_functions(CudaFunctions **functions, void *logctx)
LOAD_SYMBOL_OPT(cuEGLStreamProducerPresentFrame, tcuEGLStreamProducerPresentFrame, "cuEGLStreamProducerPresentFrame");
LOAD_SYMBOL_OPT(cuEGLStreamProducerReturnFrame, tcuEGLStreamProducerReturnFrame, "cuEGLStreamProducerReturnFrame");

#if defined(_WIN32) || defined(__CYGWIN__)
LOAD_SYMBOL(cuD3D11GetDevice, tcuD3D11GetDevice, "cuD3D11GetDevice");
LOAD_SYMBOL(cuD3D11GetDevices, tcuD3D11GetDevices, "cuD3D11GetDevices");
LOAD_SYMBOL(cuGraphicsD3D11RegisterResource, tcuGraphicsD3D11RegisterResource, "cuGraphicsD3D11RegisterResource");
#endif

GENERIC_LOAD_FUNC_FINALE(cuda);
}
#endif
Expand Down

0 comments on commit b677175

Please sign in to comment.