Introduce a new ToggleGraphicsProfiler
command (#7607)
On macOS, this will enable or disable the Metal HUD at runtime. Note that this only works when Zed is bundled because it requires to set the `MetalHudEnabled` key in the Info.plist. Release Notes: - Added a new `ToggleGraphicsProfiler` command that can be used as an action (or via the `Help -> Toggle Graphics Profiler` menu) to investigate graphics performance.
This commit is contained in:
parent
04e1641a29
commit
0cebf68306
9 changed files with 53 additions and 6 deletions
|
@ -182,8 +182,8 @@ pub(crate) trait PlatformWindow: HasWindowHandle + HasDisplayHandle {
|
||||||
fn on_appearance_changed(&self, callback: Box<dyn FnMut()>);
|
fn on_appearance_changed(&self, callback: Box<dyn FnMut()>);
|
||||||
fn is_topmost_for_position(&self, position: Point<Pixels>) -> bool;
|
fn is_topmost_for_position(&self, position: Point<Pixels>) -> bool;
|
||||||
fn draw(&self, scene: &Scene);
|
fn draw(&self, scene: &Scene);
|
||||||
|
|
||||||
fn sprite_atlas(&self) -> Arc<dyn PlatformAtlas>;
|
fn sprite_atlas(&self) -> Arc<dyn PlatformAtlas>;
|
||||||
|
fn set_graphics_profiler_enabled(&self, enabled: bool);
|
||||||
|
|
||||||
#[cfg(any(test, feature = "test-support"))]
|
#[cfg(any(test, feature = "test-support"))]
|
||||||
fn as_test(&mut self) -> Option<&mut TestWindow> {
|
fn as_test(&mut self) -> Option<&mut TestWindow> {
|
||||||
|
|
|
@ -428,4 +428,8 @@ impl PlatformWindow for LinuxWindow {
|
||||||
let inner = self.0.inner.lock();
|
let inner = self.0.inner.lock();
|
||||||
inner.renderer.atlas().clone()
|
inner.renderer.atlas().clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn set_graphics_profiler_enabled(&self, enabled: bool) {
|
||||||
|
todo!("linux")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
point, size, AtlasTextureId, AtlasTextureKind, AtlasTile, Bounds, ContentMask, DevicePixels,
|
platform::mac::ns_string, point, size, AtlasTextureId, AtlasTextureKind, AtlasTile, Bounds,
|
||||||
Hsla, MetalAtlas, MonochromeSprite, Path, PathId, PathVertex, PolychromeSprite, PrimitiveBatch,
|
ContentMask, DevicePixels, Hsla, MetalAtlas, MonochromeSprite, Path, PathId, PathVertex,
|
||||||
Quad, ScaledPixels, Scene, Shadow, Size, Surface, Underline,
|
PolychromeSprite, PrimitiveBatch, Quad, ScaledPixels, Scene, Shadow, Size, Surface, Underline,
|
||||||
};
|
};
|
||||||
use block::ConcreteBlock;
|
use block::ConcreteBlock;
|
||||||
use cocoa::{
|
use cocoa::{
|
||||||
base::{NO, YES},
|
base::{nil, NO, YES},
|
||||||
foundation::NSUInteger,
|
foundation::{NSDictionary, NSUInteger},
|
||||||
quartzcore::AutoresizingMask,
|
quartzcore::AutoresizingMask,
|
||||||
};
|
};
|
||||||
use collections::HashMap;
|
use collections::HashMap;
|
||||||
|
@ -200,6 +200,23 @@ impl MetalRenderer {
|
||||||
&self.sprite_atlas
|
&self.sprite_atlas
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Enables or disables the Metal HUD for debugging purposes. Note that this only works
|
||||||
|
/// when the app is bundled and it has the `MetalHudEnabled` key set to true in Info.plist.
|
||||||
|
pub fn set_hud_enabled(&mut self, enabled: bool) {
|
||||||
|
unsafe {
|
||||||
|
if enabled {
|
||||||
|
let hud_properties = NSDictionary::dictionaryWithObject_forKey_(
|
||||||
|
nil,
|
||||||
|
ns_string("default"),
|
||||||
|
ns_string("mode"),
|
||||||
|
);
|
||||||
|
let _: () = msg_send![&*self.layer, setDeveloperHUDProperties: hud_properties];
|
||||||
|
} else {
|
||||||
|
let _: () = msg_send![&*self.layer, setDeveloperHUDProperties: NSDictionary::dictionary(nil)];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn set_presents_with_transaction(&mut self, presents_with_transaction: bool) {
|
pub fn set_presents_with_transaction(&mut self, presents_with_transaction: bool) {
|
||||||
self.presents_with_transaction = presents_with_transaction;
|
self.presents_with_transaction = presents_with_transaction;
|
||||||
self.layer
|
self.layer
|
||||||
|
|
|
@ -1021,6 +1021,12 @@ impl PlatformWindow for MacWindow {
|
||||||
fn sprite_atlas(&self) -> Arc<dyn PlatformAtlas> {
|
fn sprite_atlas(&self) -> Arc<dyn PlatformAtlas> {
|
||||||
self.0.lock().renderer.sprite_atlas().clone()
|
self.0.lock().renderer.sprite_atlas().clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Enables or disables the Metal HUD for debugging purposes. Note that this only works
|
||||||
|
/// when the app is bundled and it has the `MetalHudEnabled` key set to true in Info.plist.
|
||||||
|
fn set_graphics_profiler_enabled(&self, enabled: bool) {
|
||||||
|
self.0.lock().renderer.set_hud_enabled(enabled);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HasWindowHandle for MacWindow {
|
impl HasWindowHandle for MacWindow {
|
||||||
|
|
|
@ -288,6 +288,8 @@ impl PlatformWindow for TestWindow {
|
||||||
self.0.lock().sprite_atlas.clone()
|
self.0.lock().sprite_atlas.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn set_graphics_profiler_enabled(&self, _enabled: bool) {}
|
||||||
|
|
||||||
fn as_test(&mut self) -> Option<&mut TestWindow> {
|
fn as_test(&mut self) -> Option<&mut TestWindow> {
|
||||||
Some(self)
|
Some(self)
|
||||||
}
|
}
|
||||||
|
|
|
@ -279,6 +279,7 @@ pub struct Window {
|
||||||
pub(crate) focus: Option<FocusId>,
|
pub(crate) focus: Option<FocusId>,
|
||||||
focus_enabled: bool,
|
focus_enabled: bool,
|
||||||
pending_input: Option<PendingInput>,
|
pending_input: Option<PendingInput>,
|
||||||
|
graphics_profiler_enabled: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default, Debug)]
|
#[derive(Default, Debug)]
|
||||||
|
@ -462,6 +463,7 @@ impl Window {
|
||||||
focus: None,
|
focus: None,
|
||||||
focus_enabled: true,
|
focus_enabled: true,
|
||||||
pending_input: None,
|
pending_input: None,
|
||||||
|
graphics_profiler_enabled: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn new_focus_listener(
|
fn new_focus_listener(
|
||||||
|
@ -1461,6 +1463,14 @@ impl<'a> WindowContext<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Toggle the graphics profiler to debug your application's rendering performance.
|
||||||
|
pub fn toggle_graphics_profiler(&mut self) {
|
||||||
|
self.window.graphics_profiler_enabled = !self.window.graphics_profiler_enabled;
|
||||||
|
self.window
|
||||||
|
.platform_window
|
||||||
|
.set_graphics_profiler_enabled(self.window.graphics_profiler_enabled);
|
||||||
|
}
|
||||||
|
|
||||||
/// Register the given handler to be invoked whenever the global of the given type
|
/// Register the given handler to be invoked whenever the global of the given type
|
||||||
/// is updated.
|
/// is updated.
|
||||||
pub fn observe_global<G: Global>(
|
pub fn observe_global<G: Global>(
|
||||||
|
|
|
@ -118,6 +118,7 @@ actions!(
|
||||||
ToggleRightDock,
|
ToggleRightDock,
|
||||||
ToggleBottomDock,
|
ToggleBottomDock,
|
||||||
CloseAllDocks,
|
CloseAllDocks,
|
||||||
|
ToggleGraphicsProfiler,
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -3395,6 +3396,7 @@ impl Workspace {
|
||||||
workspace.reopen_closed_item(cx).detach();
|
workspace.reopen_closed_item(cx).detach();
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
.on_action(|_: &ToggleGraphicsProfiler, cx| cx.toggle_graphics_profiler())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(test, feature = "test-support"))]
|
#[cfg(any(test, feature = "test-support"))]
|
||||||
|
|
|
@ -22,3 +22,5 @@
|
||||||
<string>An application in Zed wants to use speech recognition.</string>
|
<string>An application in Zed wants to use speech recognition.</string>
|
||||||
<key>NSRemindersUsageDescription</key>
|
<key>NSRemindersUsageDescription</key>
|
||||||
<string>An application in Zed wants to use your reminders.</string>
|
<string>An application in Zed wants to use your reminders.</string>
|
||||||
|
<key>MetalHudEnabled</key>
|
||||||
|
<true />
|
||||||
|
|
|
@ -155,6 +155,10 @@ pub fn app_menus() -> Vec<Menu<'static>> {
|
||||||
MenuItem::action("View Telemetry", crate::OpenTelemetryLog),
|
MenuItem::action("View Telemetry", crate::OpenTelemetryLog),
|
||||||
MenuItem::action("View Dependency Licenses", crate::OpenLicenses),
|
MenuItem::action("View Dependency Licenses", crate::OpenLicenses),
|
||||||
MenuItem::action("Show Welcome", workspace::Welcome),
|
MenuItem::action("Show Welcome", workspace::Welcome),
|
||||||
|
MenuItem::action(
|
||||||
|
"Toggle Graphics Profiler",
|
||||||
|
workspace::ToggleGraphicsProfiler,
|
||||||
|
),
|
||||||
MenuItem::separator(),
|
MenuItem::separator(),
|
||||||
MenuItem::separator(),
|
MenuItem::separator(),
|
||||||
MenuItem::action(
|
MenuItem::action(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue