Avoid broken fallback to cross-adapter NVENC encoding with KMS

This commit is contained in:
Cameron Gutman 2024-03-11 02:42:25 -05:00
commit 91744960c1
2 changed files with 23 additions and 4 deletions

View file

@ -108,6 +108,7 @@ namespace platf {
using obj_prop_t = util::safe_ptr<drmModeObjectProperties, drmModeFreeObjectProperties>;
using prop_t = util::safe_ptr<drmModePropertyRes, drmModeFreeProperty>;
using prop_blob_t = util::safe_ptr<drmModePropertyBlobRes, drmModeFreePropertyBlob>;
using version_t = util::safe_ptr<drmVersion, drmFreeVersion>;
using conn_type_count_t = std::map<std::uint32_t, std::uint32_t>;
@ -364,6 +365,12 @@ namespace platf {
return drmModeGetResources(fd.el);
}
bool
is_nvidia() {
version_t ver { drmGetVersion(fd.el) };
return ver && ver->name && strncmp(ver->name, "nvidia-drm", 10) == 0;
}
bool
is_cursor(std::uint32_t plane_id) {
auto props = plane_props(plane_id);
@ -604,6 +611,12 @@ namespace platf {
continue;
}
// Skip non-Nvidia cards if we're looking for CUDA devices
if (mem_type == mem_type_e::cuda && !card.is_nvidia()) {
BOOST_LOG(debug) << file << " is not a CUDA device"sv;
continue;
}
auto end = std::end(card);
for (auto plane = std::begin(card); plane != end; ++plane) {
// Skip unused planes
@ -1576,7 +1589,7 @@ namespace platf {
// A list of names of displays accepted as display_name
std::vector<std::string>
kms_display_names() {
kms_display_names(mem_type_e hwdevice_type) {
int count = 0;
if (!fs::exists("/dev/dri")) {
@ -1608,6 +1621,12 @@ namespace platf {
continue;
}
// Skip non-Nvidia cards if we're looking for CUDA devices
if (hwdevice_type == mem_type_e::cuda && !card.is_nvidia()) {
BOOST_LOG(debug) << file << " is not a CUDA device"sv;
continue;
}
auto crtc_to_monitor = kms::map_crtc_to_monitor(card.monitors(conn_type_count));
auto end = std::end(card);