cuda: Remove GST_CUDA_HAS_D3D define from header
authorSeungha Yang <seungha@centricular.com>
Mon, 12 Sep 2022 16:02:50 +0000 (01:02 +0900)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Tue, 13 Sep 2022 16:40:51 +0000 (16:40 +0000)
... and fix d3d11 specific enum type name

GST_CUDA_HAS_D3D is a build time define which indicates whether
GstD3D11 library is available or not, but DirectX SDK headers
must be available on the build system already.

Expose Direct3D related symbols if the build target is Windows
(i.e., if G_OS_WIN32 is defined)

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3018>

subprojects/gst-plugins-bad/gst-libs/gst/cuda/cuda-gst.h
subprojects/gst-plugins-bad/gst-libs/gst/cuda/gstcudacontext.c
subprojects/gst-plugins-bad/gst-libs/gst/cuda/gstcudaloader.c
subprojects/gst-plugins-bad/gst-libs/gst/cuda/gstcudautils.c
subprojects/gst-plugins-bad/gst-libs/gst/cuda/gstcudautils.h
subprojects/gst-plugins-bad/gst-libs/gst/cuda/meson.build
subprojects/gst-plugins-bad/gst-libs/gst/cuda/stub/cuda.h
subprojects/gst-plugins-bad/gst-libs/gst/cuda/stub/cudaD3D11.h [new file with mode: 0644]

index 37bb4f9..381264a 100644 (file)
@@ -4,6 +4,16 @@
 #include <cuda.h>
 #include <cudaGL.h>
 
+#ifdef G_OS_WIN32
+#ifndef INITGUID
+#include <initguid.h>
+#endif /* INITGUID */
+
+#include <d3d11.h>
+#include <dxgi.h>
+#include <cudaD3D11.h>
+#endif /* G_OS_WIN32 */
+
 G_BEGIN_DECLS
 
 /* cuda.h */
@@ -182,23 +192,23 @@ CUresult CUDAAPI CuGLGetDevices (unsigned int * pCudaDeviceCount,
                                  CUGLDeviceList deviceList);
 
 
-#ifdef GST_CUDA_HAS_D3D
+#ifdef G_OS_WIN32
 /* cudaD3D11.h */
 GST_CUDA_API
 CUresult CUDAAPI CuGraphicsD3D11RegisterResource(CUgraphicsResource * pCudaResource,
-                                                 gpointer pD3DResource,
+                                                 ID3D11Resource * pD3DResource,
                                                  unsigned int Flags);
 
 GST_CUDA_API
 CUresult CUDAAPI CuD3D11GetDevice(CUdevice * device,
-                                  gpointer pAdapter);
+                                  IDXGIAdapter * pAdapter);
 
 GST_CUDA_API
 CUresult CUDAAPI CuD3D11GetDevices(unsigned int * pCudaDeviceCount,
                                    CUdevice* pCudaDevices,
                                    unsigned int cudaDeviceCount,
-                                   gpointer pD3D11Device,
-                                   CUD3D11DeviceList deviceList);
+                                   ID3D11Device * pD3D11Device,
+                                   CUd3d11DeviceList deviceList);
 #endif
 
 G_END_DECLS
index bd611dc..aed158a 100644 (file)
@@ -182,7 +182,7 @@ gst_cuda_context_find_dxgi_adapter_luid (CUdevice cuda_device)
       continue;
     }
 
-    cuda_ret = CuD3D11GetDevice (&other_dev, adapter);
+    cuda_ret = CuD3D11GetDevice (&other_dev, (IDXGIAdapter *) adapter);
     IDXGIAdapter1_Release (adapter);
 
     if (cuda_ret == CUDA_SUCCESS && other_dev == cuda_device) {
index 064987f..fffcbef 100644 (file)
@@ -123,13 +123,15 @@ typedef struct _GstNvCodecCudaVTable
       CUdevice * pCudaDevices, unsigned int cudaDeviceCount,
       CUGLDeviceList deviceList);
 
+#ifdef G_OS_WIN32
   CUresult (CUDAAPI * CuGraphicsD3D11RegisterResource) (CUgraphicsResource *
-      pCudaResource, gpointer pD3DResource, unsigned int Flags);
+      pCudaResource, ID3D11Resource * pD3DResource, unsigned int Flags);
   CUresult (CUDAAPI * CuD3D11GetDevice) (CUdevice * device,
-      gpointer pAdapter);
+      IDXGIAdapter * pAdapter);
   CUresult (CUDAAPI * CuD3D11GetDevices) (unsigned int *pCudaDeviceCount,
       CUdevice * pCudaDevices, unsigned int cudaDeviceCount,
-      gpointer pD3D11Device, CUD3D11DeviceList deviceList);
+      ID3D11Device * pD3D11Device, CUd3d11DeviceList deviceList);
+#endif
 } GstNvCodecCudaVTable;
 /* *INDENT-ON* */
 
@@ -223,7 +225,7 @@ gst_cuda_load_library (void)
   LOAD_SYMBOL (cuGraphicsGLRegisterBuffer, CuGraphicsGLRegisterBuffer);
   LOAD_SYMBOL (cuGLGetDevices, CuGLGetDevices);
 
-#ifdef GST_CUDA_HAS_D3D
+#ifdef G_OS_WIN32
   /* cudaD3D11.h */
   LOAD_SYMBOL (cuGraphicsD3D11RegisterResource,
       CuGraphicsD3D11RegisterResource);
@@ -590,10 +592,10 @@ CuGLGetDevices (unsigned int *pCudaDeviceCount, CUdevice * pCudaDevices,
 }
 
 /* cudaD3D11.h */
-#ifdef GST_CUDA_HAS_D3D
+#ifdef G_OS_WIN32
 CUresult CUDAAPI
 CuGraphicsD3D11RegisterResource (CUgraphicsResource * pCudaResource,
-    gpointer pD3DResource, unsigned int Flags)
+    ID3D11Resource * pD3DResource, unsigned int Flags)
 {
   g_assert (gst_cuda_vtable.CuGraphicsD3D11RegisterResource != NULL);
 
@@ -602,7 +604,7 @@ CuGraphicsD3D11RegisterResource (CUgraphicsResource * pCudaResource,
 }
 
 CUresult CUDAAPI
-CuD3D11GetDevice (CUdevice * device, gpointer pAdapter)
+CuD3D11GetDevice (CUdevice * device, IDXGIAdapter * pAdapter)
 {
   g_assert (gst_cuda_vtable.CuD3D11GetDevice != NULL);
 
@@ -611,9 +613,8 @@ CuD3D11GetDevice (CUdevice * device, gpointer pAdapter)
 
 CUresult CUDAAPI
 CuD3D11GetDevices (unsigned int *pCudaDeviceCount,
-    CUdevice * pCudaDevices,
-    unsigned int cudaDeviceCount,
-    gpointer pD3D11Device, CUD3D11DeviceList deviceList)
+    CUdevice * pCudaDevices, unsigned int cudaDeviceCount,
+    ID3D11Device * pD3D11Device, CUd3d11DeviceList deviceList)
 {
   g_assert (gst_cuda_vtable.CuD3D11GetDevices != NULL);
 
index 43e5974..9dfb0f7 100644 (file)
@@ -495,7 +495,7 @@ gst_cuda_graphics_resource_register_gl_buffer (GstCudaGraphicsResource *
   return TRUE;
 }
 
-#ifdef GST_CUDA_HAS_D3D
+#ifdef G_OS_WIN32
 /**
  * gst_cuda_graphics_resource_register_d3d11_resource: (skip)
  * @resource a #GstCudaGraphicsResource
@@ -512,7 +512,7 @@ gst_cuda_graphics_resource_register_gl_buffer (GstCudaGraphicsResource *
  */
 gboolean
 gst_cuda_graphics_resource_register_d3d11_resource (GstCudaGraphicsResource *
-    resource, gpointer d3d11_resource, CUgraphicsRegisterFlags flags)
+    resource, ID3D11Resource * d3d11_resource, CUgraphicsRegisterFlags flags)
 {
   CUresult cuda_ret;
 
index 8ade84d..8bccb8f 100644 (file)
@@ -162,10 +162,10 @@ gboolean        gst_cuda_graphics_resource_register_gl_buffer (GstCudaGraphicsRe
                                                                guint buffer,
                                                                CUgraphicsRegisterFlags flags);
 
-#ifdef GST_CUDA_HAS_D3D
+#ifdef G_OS_WIN32
 GST_CUDA_API
 gboolean        gst_cuda_graphics_resource_register_d3d11_resource (GstCudaGraphicsResource * resource,
-                                                                    gpointer d3d11_resource,
+                                                                    ID3D11Resource * d3d11_resource,
                                                                     CUgraphicsRegisterFlags flags);
 #endif
 
index 5c39b35..00ebdbc 100644 (file)
@@ -23,6 +23,20 @@ if host_system not in ['windows', 'linux']
   subdir_done()
 endif
 
+cuda_win32_headers = [
+  'initguid.h',
+  'd3d11.h',
+  'dxgi.h',
+]
+
+if host_system == 'windows'
+  foreach h : cuda_win32_headers
+    if not cc.has_header(h)
+      subdir_done()
+    endif
+  endforeach
+endif
+
 cuda_stubinc = include_directories('./stub')
 extra_c_args = ['-DGST_USE_UNSTABLE_API']
 
index 8455a68..1d37813 100644 (file)
@@ -132,13 +132,6 @@ typedef struct
   gsize Height;
 } CUDA_MEMCPY2D;
 
-typedef enum
-{
-  CU_D3D11_DEVICE_LIST_ALL = 0x01,
-  CU_D3D11_DEVICE_LIST_CURRENT_FRAME = 0x02,
-  CU_D3D11_DEVICE_LIST_NEXT_FRAME = 0x03,
-} CUD3D11DeviceList;
-
 typedef struct
 {
   CUaddress_mode addressMode[3];
diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/cuda/stub/cudaD3D11.h b/subprojects/gst-plugins-bad/gst-libs/gst/cuda/stub/cudaD3D11.h
new file mode 100644 (file)
index 0000000..26c38f7
--- /dev/null
@@ -0,0 +1,14 @@
+#pragma once
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+typedef enum
+{
+  CU_D3D11_DEVICE_LIST_ALL = 0x01,
+  CU_D3D11_DEVICE_LIST_CURRENT_FRAME = 0x02,
+  CU_D3D11_DEVICE_LIST_NEXT_FRAME = 0x03,
+} CUd3d11DeviceList;
+
+G_END_DECLS