fix(nvenc): dynamic nv codec sdk selection (#5451)

This commit is contained in:
Dave Lane
2026-07-26 21:06:28 -04:00
committed by GitHub
parent 7cb92071ac
commit fb3d85cff4
32 changed files with 3284 additions and 501 deletions

View File

@@ -24,9 +24,7 @@ extern "C" {
#include "src/config.h"
#include "src/logging.h"
#include "src/nvenc/nvenc_config.h"
#include "src/nvenc/nvenc_d3d11_native.h"
#include "src/nvenc/nvenc_d3d11_on_cuda.h"
#include "src/nvenc/nvenc_utils.h"
#include "src/nvenc/nvenc_dynamic_factory.h"
#include "src/video.h"
#include "utf_utils.h"
@@ -1240,21 +1238,25 @@ namespace platf::dxgi {
* @return True when the D3D11 device resources are initialized.
*/
bool init_device(std::shared_ptr<platf::display_t> display, adapter_t::pointer adapter_p, pix_fmt_e pix_fmt) {
buffer_format = nvenc::nvenc_format_from_sunshine_format(pix_fmt);
if (buffer_format == NV_ENC_BUFFER_FORMAT_UNDEFINED) {
BOOST_LOG(error) << "Unexpected pixel format for NvENC ["sv << from_pix_fmt(pix_fmt) << ']';
return false;
}
if (base.init(display, adapter_p, pix_fmt)) {
return false;
}
if (pix_fmt == pix_fmt_e::yuv444p16) {
nvenc_d3d = std::make_unique<nvenc::nvenc_d3d11_on_cuda>(base.device.get());
} else {
nvenc_d3d = std::make_unique<nvenc::nvenc_d3d11_native>(base.device.get());
auto factory = nvenc::nvenc_dynamic_factory::get();
if (!factory) {
return false;
}
if (pix_fmt == pix_fmt_e::yuv444p16) {
nvenc_d3d = factory->create_nvenc_d3d11_on_cuda(base.device.get());
} else {
nvenc_d3d = factory->create_nvenc_d3d11_native(base.device.get());
}
if (!nvenc_d3d) {
return false;
}
buffer_format = pix_fmt;
nvenc = nvenc_d3d.get();
return true;
@@ -1272,8 +1274,7 @@ namespace platf::dxgi {
return false;
}
auto nvenc_colorspace = nvenc::nvenc_colorspace_from_sunshine_colorspace(colorspace);
if (!nvenc_d3d->create_encoder(config::video.nv, client_config, nvenc_colorspace, buffer_format)) {
if (!nvenc_d3d->create_encoder(config::video.nv, client_config, colorspace, buffer_format)) {
return false;
}
@@ -1293,8 +1294,8 @@ namespace platf::dxgi {
private:
d3d_base_encode_device base;
std::unique_ptr<nvenc::nvenc_d3d11> nvenc_d3d;
NV_ENC_BUFFER_FORMAT buffer_format = NV_ENC_BUFFER_FORMAT_UNDEFINED;
std::unique_ptr<nvenc::nvenc_d3d11_interface> nvenc_d3d;
platf::pix_fmt_e buffer_format = platf::pix_fmt_e::unknown;
};
/**