From 6f3f7b4e5a561a02bc0c7cd37260cd7814fba1a9 Mon Sep 17 00:00:00 2001 From: Ryan Foster Date: Wed, 27 Mar 2024 14:20:02 -0400 Subject: [PATCH] obs-ffmpeg: Fix NVENC compatibility hack for old drivers/hardware Add a COMPAT version of NV_ENC_INITIALIZE_PARAMS_VER, which changed between SDK 12.0 and 12.1. If using drivers older than the configured SDK/API requires, fall back to the compatibility version of the API (11.1). An example scenario would be encoding in H.264 on driver version 512.15. SDK 12.1 requires driver version 531.61 on Windows. Currently, in this scenario, OBS will fall back to the FFmpeg encoder path, which will do its own driver check, which will fail on this driver version. With this change, this scenario will instead leverage the existing compatibility hack to fall back to the compatibility version of the API without falling back to FFmpeg. It should be noted that while neat, the compatibility hack that enables Kepler GPUs to continue to be able to use NVENC in this way is expected to be removed at some point. --- plugins/obs-ffmpeg/obs-nvenc.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/plugins/obs-ffmpeg/obs-nvenc.c b/plugins/obs-ffmpeg/obs-nvenc.c index 9d95a2f38..27802a147 100644 --- a/plugins/obs-ffmpeg/obs-nvenc.c +++ b/plugins/obs-ffmpeg/obs-nvenc.c @@ -32,6 +32,8 @@ ((ver) << 16) | (0x7 << 28)) #define NV_ENC_CONFIG_COMPAT_VER (NVENCAPI_STRUCT_VERSION(7) | (1 << 31)) +#define NV_ENC_INITIALIZE_PARAMS_COMPAT_VER \ + (NVENCAPI_STRUCT_VERSION(5) | (1 << 31)) #define NV_ENC_PIC_PARAMS_COMPAT_VER (NVENCAPI_STRUCT_VERSION(4) | (1 << 31)) #define NV_ENC_LOCK_BITSTREAM_COMPAT_VER NVENCAPI_STRUCT_VERSION(1) #define NV_ENC_REGISTER_RESOURCE_COMPAT_VER NVENCAPI_STRUCT_VERSION(3) @@ -387,7 +389,9 @@ static void initialize_params(struct nvenc_data *enc, const GUID *nv_preset, NV_ENC_INITIALIZE_PARAMS *params = &enc->params; memset(params, 0, sizeof(*params)); - params->version = NV_ENC_INITIALIZE_PARAMS_VER; + params->version = enc->needs_compat_ver + ? NV_ENC_INITIALIZE_PARAMS_COMPAT_VER + : NV_ENC_INITIALIZE_PARAMS_VER; params->encodeGUID = enc->codec_guid; params->presetGUID = *nv_preset; params->encodeWidth = width;