Share CUDA context between all nvenc encoder instances

This commit is contained in:
Kierek
2025-07-27 23:32:41 +02:00
committed by xytovl
parent 25ca41cfcf
commit e5ba1f7394
5 changed files with 217 additions and 104 deletions
+3 -11
View File
@@ -20,6 +20,7 @@
#pragma once
#include "video_encoder.h"
#include "video_encoder_nvenc_shared_state.h"
#include <array>
#include <ffnvcodec/dynlink_cuda.h>
#include <ffnvcodec/dynlink_loader.h>
@@ -31,22 +32,13 @@ namespace wivrn
class video_encoder_nvenc : public video_encoder
{
public:
struct deleter
{
void operator()(CudaFunctions * fn);
void operator()(NvencFunctions * fn);
};
private:
wivrn_vk_bundle & vk;
// relevant part of the input image to encode
vk::Rect2D rect;
std::unique_ptr<CudaFunctions, deleter> cuda_fn;
std::unique_ptr<NvencFunctions, deleter> nvenc_fn;
NV_ENCODE_API_FUNCTION_LIST fn;
CUcontext cuda;
std::shared_ptr<video_encoder_nvenc_shared_state> shared_state;
void * session_handle = nullptr;
NV_ENC_OUTPUT_PTR bitstreamBuffer;