[gnome-remote-desktop] rdp-nvenc: Add APIs to push and pop current CUDA context



commit 1e8f1a2b905faf599fc1b1ea2a65455d412f6827
Author: Pascal Nowack <Pascal Nowack gmx de>
Date:   Thu Aug 26 15:12:43 2021 +0200

    rdp-nvenc: Add APIs to push and pop current CUDA context
    
    In order to allow CUDA function correctly, the current CUDA context
    needs to be pushed for its calling thread.
    Since all graphics operations will happen in the future in a different
    thread, add APIs to set these threads correctly up.

 src/grd-rdp-nvenc.c | 15 +++++++++++++++
 src/grd-rdp-nvenc.h |  4 ++++
 2 files changed, 19 insertions(+)
---
diff --git a/src/grd-rdp-nvenc.c b/src/grd-rdp-nvenc.c
index 89fb374..d32f188 100644
--- a/src/grd-rdp-nvenc.c
+++ b/src/grd-rdp-nvenc.c
@@ -55,6 +55,21 @@ struct _GrdRdpNvenc
 
 G_DEFINE_TYPE (GrdRdpNvenc, grd_rdp_nvenc, G_TYPE_OBJECT);
 
+void
+grd_rdp_nvenc_push_cuda_context (GrdRdpNvenc *rdp_nvenc)
+{
+  if (rdp_nvenc->cuda_funcs->cuCtxPushCurrent (rdp_nvenc->cu_context) != CUDA_SUCCESS)
+    g_error ("[HWAccel.CUDA] Failed to push CUDA context");
+}
+
+void
+grd_rdp_nvenc_pop_cuda_context (GrdRdpNvenc *rdp_nvenc)
+{
+  CUcontext cu_context;
+
+  rdp_nvenc->cuda_funcs->cuCtxPopCurrent (&cu_context);
+}
+
 static uint32_t
 get_next_free_encode_session_id (GrdRdpNvenc *rdp_nvenc)
 {
diff --git a/src/grd-rdp-nvenc.h b/src/grd-rdp-nvenc.h
index 483bf3d..4640132 100644
--- a/src/grd-rdp-nvenc.h
+++ b/src/grd-rdp-nvenc.h
@@ -29,6 +29,10 @@ G_DECLARE_FINAL_TYPE (GrdRdpNvenc, grd_rdp_nvenc,
 
 GrdRdpNvenc *grd_rdp_nvenc_new (void);
 
+void grd_rdp_nvenc_push_cuda_context (GrdRdpNvenc *rdp_nvenc);
+
+void grd_rdp_nvenc_pop_cuda_context (GrdRdpNvenc *rdp_nvenc);
+
 gboolean grd_rdp_nvenc_create_encode_session (GrdRdpNvenc *rdp_nvenc,
                                               uint32_t    *encode_session_id,
                                               uint16_t     surface_width,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]