Skip to content

Commit

Permalink
feat!(mmserver): officially support nvidia proprietary
Browse files Browse the repository at this point in the history
  • Loading branch information
colinmarc committed Dec 11, 2024
1 parent 0d2baba commit 956ef44
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 8 deletions.
18 changes: 15 additions & 3 deletions mm-server/src/compositor/video/vulkan_encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use super::begin_cb;
use crate::codec::VideoCodec;
use crate::compositor::{CompositorEvent, CompositorHandle, VideoStreamParams, EPOCH};
use crate::vulkan::video::VideoQueueExt;
use crate::vulkan::*;
use crate::vulkan::{self, *};

mod dpb;
mod gop_structure;
Expand Down Expand Up @@ -989,11 +989,23 @@ fn default_hdr10_profile(op: vk::VideoCodecOperationFlagsKHR) -> vk::VideoProfil
.luma_bit_depth(vk::VideoComponentBitDepthFlagsKHR::TYPE_10)
}

fn default_encode_usage() -> vk::VideoEncodeUsageInfoKHR<'static> {
fn default_encode_usage(
driver_version: vulkan::DriverVersion,
) -> vk::VideoEncodeUsageInfoKHR<'static> {
// Nvidia chokes on "ULTRA LOW" for some reason.
let tuning_mode = if matches!(
driver_version,
vulkan::DriverVersion::NvidiaProprietary { .. }
) {
vk::VideoEncodeTuningModeKHR::LOW_LATENCY
} else {
vk::VideoEncodeTuningModeKHR::ULTRA_LOW_LATENCY
};

vk::VideoEncodeUsageInfoKHR::default()
.video_usage_hints(vk::VideoEncodeUsageFlagsKHR::STREAMING)
.video_content_hints(vk::VideoEncodeContentFlagsKHR::RENDERED)
.tuning_mode(vk::VideoEncodeTuningModeKHR::ULTRA_LOW_LATENCY)
.tuning_mode(tuning_mode)
}

fn single_profile_list_info<'a>(
Expand Down
7 changes: 5 additions & 2 deletions mm-server/src/compositor/video/vulkan_encode/h264.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,11 @@ impl H264Encoder {
let h264_profile_info =
vk::VideoEncodeH264ProfileInfoEXT::default().std_profile_idc(profile_idc);

let mut profile =
H264EncodeProfile::new(profile, super::default_encode_usage(), h264_profile_info);
let mut profile = H264EncodeProfile::new(
profile,
super::default_encode_usage(vk.device_info.driver_version.clone()),
h264_profile_info,
);

let mut caps = H264EncodeCapabilities::default();

Expand Down
7 changes: 5 additions & 2 deletions mm-server/src/compositor/video/vulkan_encode/h265.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,11 @@ impl H265Encoder {
let h265_profile_info =
vk::VideoEncodeH265ProfileInfoEXT::default().std_profile_idc(profile_idc);

let mut profile =
H265EncodeProfile::new(profile, super::default_encode_usage(), h265_profile_info);
let mut profile = H265EncodeProfile::new(
profile,
super::default_encode_usage(vk.device_info.driver_version.clone()),
h265_profile_info,
);

let mut caps = H265EncodeCapabilities::default();

Expand Down
5 changes: 5 additions & 0 deletions mm-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,11 @@ fn preflight_checks(cfg: &config::Config, vk: &vulkan::VkContext) -> anyhow::Res
bail!("mesa >= 24.3 required, have {major}.{minor}.{patch}");
}
}
vulkan::DriverVersion::NvidiaProprietary { major, minor } => {
if major < 550 {
bail!("driver version >= 550.x required, have {major}.{minor}");
}
}
vulkan::DriverVersion::Other(ref driver) => {
warn!(driver, "using potentially unsupported vulkan driver")
}
Expand Down
6 changes: 5 additions & 1 deletion mm-server/src/vulkan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub enum Vendor {
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum DriverVersion {
MesaRadv { major: u32, minor: u32, patch: u32 },
// TODO nvidia proprietary is also supported
NvidiaProprietary { major: u32, minor: u32 },
Other(String),
}

Expand Down Expand Up @@ -162,6 +162,10 @@ impl VkDeviceInfo {
minor: vk::api_version_minor(version),
patch: vk::api_version_patch(version),
},
vk::DriverId::NVIDIA_PROPRIETARY => DriverVersion::NvidiaProprietary {
major: (version >> 22) & 0x3ff,
minor: (version >> 14) & 0x0ff,
},
_ => DriverVersion::Other(
CStr::from_bytes_with_nul(&driver_props.driver_info.map(|x| x as u8)[..])
.unwrap_or(c"unknown")
Expand Down

0 comments on commit 956ef44

Please sign in to comment.