mirror of
https://github.com/bleackstorm/SteamFrame-FPV-Control-Center.git
synced 2026-12-03 07:31:57 +01:00
fix(gpui): resolve GPU atlas VRAM leak and GStreamer pipeline latency
- Fix unbounded Blade texture atlas allocation in GPUI by recycling textures via window.drop_image() with a 2-frame safety buffer. - Correct RGBA to BGRA color channel order for GPUI polychrome texture atlas. - Optimize GStreamer UDP pipeline: increase socket buffer to 4MB, add rtpjitterbuffer for zero-latency drops, scale before colorspace conversion. - Add log filter controls (All, Warn/Err, Err) to GPUI console drawer. - Benchmark: memory consumption stays completely flat at ~258 MB over time.
This commit is contained in:
1 parent
be48fbdedf
commit
0fbe184716
4 files changed
+105
-18
No files matched your search
@@ -36,6 +36,7 @@ pub struct RuntimeMonitor {
|
|||||||
pub preview_width: u32,
|
pub preview_width: u32,
|
||||||
pub preview_height: u32,
|
pub preview_height: u32,
|
||||||
pub preview_frame_seq: u64,
|
pub preview_frame_seq: u64,
|
||||||
|
#[allow(dead_code)]
|
||||||
pub manual_override_enabled: bool,
|
pub manual_override_enabled: bool,
|
||||||
pub manual_pan_deg: f32,
|
pub manual_pan_deg: f32,
|
||||||
pub manual_tilt_deg: f32,
|
pub manual_tilt_deg: f32,
|
||||||
|
|||||||
+99
-16
@@ -22,7 +22,6 @@ const COLOR_BG_DARK: u32 = 0x090b10;
|
|||||||
const COLOR_SURFACE_CARD: u32 = 0x11151f;
|
const COLOR_SURFACE_CARD: u32 = 0x11151f;
|
||||||
const COLOR_SURFACE_ELEVATED: u32 = 0x181e2b;
|
const COLOR_SURFACE_ELEVATED: u32 = 0x181e2b;
|
||||||
const COLOR_BORDER_SUBTLE: u32 = 0x1f293d;
|
const COLOR_BORDER_SUBTLE: u32 = 0x1f293d;
|
||||||
const COLOR_BORDER_ACCENT: u32 = 0x00e5ff;
|
|
||||||
|
|
||||||
const COLOR_CYAN: u32 = 0x00e5ff;
|
const COLOR_CYAN: u32 = 0x00e5ff;
|
||||||
const COLOR_GREEN: u32 = 0x10b981;
|
const COLOR_GREEN: u32 = 0x10b981;
|
||||||
@@ -37,6 +36,7 @@ pub struct SteamFrameGpuiApp {
|
|||||||
log_buffer: Arc<Mutex<LogBuffer>>,
|
log_buffer: Arc<Mutex<LogBuffer>>,
|
||||||
log_filter: LogFilter,
|
log_filter: LogFilter,
|
||||||
current_render_image: Option<Arc<RenderImage>>,
|
current_render_image: Option<Arc<RenderImage>>,
|
||||||
|
images_to_drop: Vec<Arc<RenderImage>>,
|
||||||
last_frame_seq: u64,
|
last_frame_seq: u64,
|
||||||
// Snapshots pour l'affichage réactif
|
// Snapshots pour l'affichage réactif
|
||||||
usb_status: SubsystemStatus,
|
usb_status: SubsystemStatus,
|
||||||
@@ -64,6 +64,7 @@ impl SteamFrameGpuiApp {
|
|||||||
log_buffer,
|
log_buffer,
|
||||||
log_filter: LogFilter::All,
|
log_filter: LogFilter::All,
|
||||||
current_render_image: None,
|
current_render_image: None,
|
||||||
|
images_to_drop: Vec::new(),
|
||||||
last_frame_seq: 0,
|
last_frame_seq: 0,
|
||||||
usb_status: SubsystemStatus::Starting,
|
usb_status: SubsystemStatus::Starting,
|
||||||
xr_status: SubsystemStatus::Starting,
|
xr_status: SubsystemStatus::Starting,
|
||||||
@@ -80,7 +81,7 @@ impl SteamFrameGpuiApp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Synchronise l'état IHM avec le moteur FPV en tâche de fond
|
/// Synchronise l'état IHM avec le moteur FPV en tâche de fond
|
||||||
fn sync_from_engine(&mut self) {
|
fn sync_from_engine(&mut self, window: &mut Window) {
|
||||||
let mon = self.engine.monitor.lock();
|
let mon = self.engine.monitor.lock();
|
||||||
|
|
||||||
// 1. Mise à jour de la texture vidéo si une nouvelle trame est arrivée
|
// 1. Mise à jour de la texture vidéo si une nouvelle trame est arrivée
|
||||||
@@ -89,14 +90,36 @@ impl SteamFrameGpuiApp {
|
|||||||
&& mon.preview_width > 0
|
&& mon.preview_width > 0
|
||||||
&& mon.preview_height > 0
|
&& mon.preview_height > 0
|
||||||
{
|
{
|
||||||
if let Some(img_buf) = RgbaImage::from_raw(
|
if let Some(mut img_buf) = RgbaImage::from_raw(
|
||||||
mon.preview_width,
|
mon.preview_width,
|
||||||
mon.preview_height,
|
mon.preview_height,
|
||||||
mon.preview_rgba.clone(),
|
mon.preview_rgba.clone(),
|
||||||
) {
|
) {
|
||||||
|
// Conversion RGBA -> BGRA requise par l'atlas polychrome GPUI / Vulkan
|
||||||
|
for pixel in img_buf.chunks_exact_mut(4) {
|
||||||
|
pixel.swap(0, 2);
|
||||||
|
}
|
||||||
let frame = Frame::new(img_buf);
|
let frame = Frame::new(img_buf);
|
||||||
self.current_render_image = Some(Arc::new(RenderImage::new(smallvec![frame])));
|
let new_render_image = Arc::new(RenderImage::new(smallvec![frame]));
|
||||||
|
|
||||||
|
if let Some(old) = self.current_render_image.take() {
|
||||||
|
self.images_to_drop.push(old);
|
||||||
|
}
|
||||||
|
self.current_render_image = Some(new_render_image);
|
||||||
self.last_frame_seq = mon.preview_frame_seq;
|
self.last_frame_seq = mon.preview_frame_seq;
|
||||||
|
|
||||||
|
// Nettoyage de l'atlas texture GPU pour empêcher l'accumulation de VRAM.
|
||||||
|
// On conserve les 2 dernières trames pour garantir que le GPU a fini
|
||||||
|
// de les projeter à l'écran avant destruction de la texture.
|
||||||
|
while self.images_to_drop.len() > 2 {
|
||||||
|
let old_img = self.images_to_drop.remove(0);
|
||||||
|
let _ = window.drop_image(old_img);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if !self.images_to_drop.is_empty() {
|
||||||
|
// Si le flux s'interrompt, purger les anciennes textures en attente
|
||||||
|
for old_img in self.images_to_drop.drain(..) {
|
||||||
|
let _ = window.drop_image(old_img);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -787,6 +810,63 @@ impl SteamFrameGpuiApp {
|
|||||||
div()
|
div()
|
||||||
.flex()
|
.flex()
|
||||||
.gap_2()
|
.gap_2()
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.id("filter_all")
|
||||||
|
.px_2()
|
||||||
|
.py_0p5()
|
||||||
|
.bg(if self.log_filter == LogFilter::All {
|
||||||
|
rgb(0x1e3a5f)
|
||||||
|
} else {
|
||||||
|
rgb(COLOR_SURFACE_ELEVATED)
|
||||||
|
})
|
||||||
|
.rounded_md()
|
||||||
|
.text_xs()
|
||||||
|
.cursor_pointer()
|
||||||
|
.on_click(cx.listener(|this, _, _, cx| {
|
||||||
|
this.log_filter = LogFilter::All;
|
||||||
|
cx.notify();
|
||||||
|
}))
|
||||||
|
.child("Tous"),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.id("filter_warn")
|
||||||
|
.px_2()
|
||||||
|
.py_0p5()
|
||||||
|
.bg(if self.log_filter == LogFilter::WarningsAndErrors {
|
||||||
|
rgb(0x1e3a5f)
|
||||||
|
} else {
|
||||||
|
rgb(COLOR_SURFACE_ELEVATED)
|
||||||
|
})
|
||||||
|
.rounded_md()
|
||||||
|
.text_xs()
|
||||||
|
.cursor_pointer()
|
||||||
|
.on_click(cx.listener(|this, _, _, cx| {
|
||||||
|
this.log_filter = LogFilter::WarningsAndErrors;
|
||||||
|
cx.notify();
|
||||||
|
}))
|
||||||
|
.child("Warn/Err"),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.id("filter_err")
|
||||||
|
.px_2()
|
||||||
|
.py_0p5()
|
||||||
|
.bg(if self.log_filter == LogFilter::ErrorsOnly {
|
||||||
|
rgb(0x1e3a5f)
|
||||||
|
} else {
|
||||||
|
rgb(COLOR_SURFACE_ELEVATED)
|
||||||
|
})
|
||||||
|
.rounded_md()
|
||||||
|
.text_xs()
|
||||||
|
.cursor_pointer()
|
||||||
|
.on_click(cx.listener(|this, _, _, cx| {
|
||||||
|
this.log_filter = LogFilter::ErrorsOnly;
|
||||||
|
cx.notify();
|
||||||
|
}))
|
||||||
|
.child("Err"),
|
||||||
|
)
|
||||||
.child(
|
.child(
|
||||||
div()
|
div()
|
||||||
.id("btn_clear_logs")
|
.id("btn_clear_logs")
|
||||||
@@ -807,15 +887,6 @@ impl SteamFrameGpuiApp {
|
|||||||
cx.notify();
|
cx.notify();
|
||||||
}))
|
}))
|
||||||
.child("Effacer"),
|
.child("Effacer"),
|
||||||
)
|
|
||||||
.child(
|
|
||||||
div()
|
|
||||||
.px_2()
|
|
||||||
.py_0p5()
|
|
||||||
.bg(rgb(COLOR_SURFACE_ELEVATED))
|
|
||||||
.rounded_md()
|
|
||||||
.text_xs()
|
|
||||||
.child("Copier"),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@@ -828,7 +899,19 @@ impl SteamFrameGpuiApp {
|
|||||||
.overflow_scroll()
|
.overflow_scroll()
|
||||||
.px_2()
|
.px_2()
|
||||||
.gap_0p5()
|
.gap_0p5()
|
||||||
.children(self.log_entries.iter().rev().take(40).map(|e| {
|
.children(
|
||||||
|
self.log_entries
|
||||||
|
.iter()
|
||||||
|
.rev()
|
||||||
|
.filter(|e| match self.log_filter {
|
||||||
|
LogFilter::All => true,
|
||||||
|
LogFilter::WarningsAndErrors => {
|
||||||
|
matches!(e.level, log::Level::Warn | log::Level::Error)
|
||||||
|
}
|
||||||
|
LogFilter::ErrorsOnly => matches!(e.level, log::Level::Error),
|
||||||
|
})
|
||||||
|
.take(40)
|
||||||
|
.map(|e| {
|
||||||
let badge_color = match e.level {
|
let badge_color = match e.level {
|
||||||
log::Level::Error => COLOR_RED,
|
log::Level::Error => COLOR_RED,
|
||||||
log::Level::Warn => COLOR_ORANGE,
|
log::Level::Warn => COLOR_ORANGE,
|
||||||
@@ -972,10 +1055,10 @@ pub fn run_gpui_app(cfg: AppConfig, log_buffer: Arc<Mutex<LogBuffer>>) -> Result
|
|||||||
loop {
|
loop {
|
||||||
Timer::after(Duration::from_millis(16)).await;
|
Timer::after(Duration::from_millis(16)).await;
|
||||||
let should_continue = cx
|
let should_continue = cx
|
||||||
.update(|_, cx| {
|
.update(|window, cx| {
|
||||||
if let Some(view) = weak_view.upgrade() {
|
if let Some(view) = weak_view.upgrade() {
|
||||||
view.update(cx, |this, cx| {
|
view.update(cx, |this, cx| {
|
||||||
this.sync_from_engine();
|
this.sync_from_engine(window);
|
||||||
cx.notify();
|
cx.notify();
|
||||||
});
|
});
|
||||||
true
|
true
|
||||||
|
|||||||
+4
-2
@@ -10,6 +10,7 @@ use std::thread;
|
|||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
#[allow(dead_code)]
|
||||||
pub struct VideoFrame {
|
pub struct VideoFrame {
|
||||||
pub width: u32,
|
pub width: u32,
|
||||||
pub height: u32,
|
pub height: u32,
|
||||||
@@ -69,6 +70,7 @@ impl UsbVideoReceiver {
|
|||||||
let depay_and_parse = if stream_transport.eq_ignore_ascii_case("rtp") {
|
let depay_and_parse = if stream_transport.eq_ignore_ascii_case("rtp") {
|
||||||
format!(
|
format!(
|
||||||
"application/x-rtp,media=video,clock-rate=90000,encoding-name={codec_name},payload=96 ! \
|
"application/x-rtp,media=video,clock-rate=90000,encoding-name={codec_name},payload=96 ! \
|
||||||
|
rtpjitterbuffer latency=0 drop-on-latency=true ! \
|
||||||
{depay} ! {parser} config-interval=-1"
|
{depay} ! {parser} config-interval=-1"
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
@@ -81,10 +83,10 @@ impl UsbVideoReceiver {
|
|||||||
);
|
);
|
||||||
|
|
||||||
format!(
|
format!(
|
||||||
"udpsrc address={bind_ip} port={port} buffer-size=524288 retrieve-sender-address=false ! \
|
"udpsrc address={bind_ip} port={port} buffer-size=4194304 retrieve-sender-address=false ! \
|
||||||
{depay_and_parse} ! \
|
{depay_and_parse} ! \
|
||||||
{decoder} ! \
|
{decoder} ! \
|
||||||
videoconvert n-threads=2 ! videoscale method=1 ! \
|
videoscale ! videoconvert ! \
|
||||||
video/x-raw,format=RGBA,width={target_width},height={target_height} ! \
|
video/x-raw,format=RGBA,width={target_width},height={target_height} ! \
|
||||||
appsink name=fpv_sink sync=false max-buffers=1 drop=true emit-signals=true"
|
appsink name=fpv_sink sync=false max-buffers=1 drop=true emit-signals=true"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ use std::ffi::CString;
|
|||||||
|
|
||||||
/// Moteur de rendu OpenXR + Vulkan pour afficher le flux vidéo USB Sphere Link
|
/// Moteur de rendu OpenXR + Vulkan pour afficher le flux vidéo USB Sphere Link
|
||||||
/// dans les couches de composition OpenXR (`Equirect2`, `Cylinder`, ou `Quad`).
|
/// dans les couches de composition OpenXR (`Equirect2`, `Cylinder`, ou `Quad`).
|
||||||
|
#[allow(dead_code)]
|
||||||
pub struct VulkanXrContext {
|
pub struct VulkanXrContext {
|
||||||
pub vk_entry: ash::Entry,
|
pub vk_entry: ash::Entry,
|
||||||
pub vk_instance: ash::Instance,
|
pub vk_instance: ash::Instance,
|
||||||
|
|||||||
Reference in new issue
Block a user