Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
gpui_platform: Expose headless renderer through bench support (#63244)
Anthony Eidfecc3273ed32
diff --git a/crates/benchmarks/Cargo.toml b/crates/benchmarks/Cargo.tomlindex f046d8596d7..95756c7d1c1 100644--- a/crates/benchmarks/Cargo.toml+++ b/crates/benchmarks/Cargo.toml@@ -24,7 +24,7 @@ criterion.workspace = trueeditor = { workspace = true, features = ["test-support"] }futures.workspace = truegpui = { workspace = true, features = ["bench-support"] }-gpui_platform = { workspace = true, features = ["test-support", "font-kit"] }+gpui_platform = { workspace = true, features = ["bench-support", "font-kit"] }itertools.workspace = truelanguage = { workspace = true, features = ["test-support"] }language_model = { workspace = true, features = ["test-support"] }diff --git a/crates/gpui_apple/Cargo.toml b/crates/gpui_apple/Cargo.tomlindex fb5f07a2cda..1d8db9b4f00 100644--- a/crates/gpui_apple/Cargo.toml+++ b/crates/gpui_apple/Cargo.toml@@ -13,6 +13,7 @@ path = "src/gpui_apple.rs"[features]default = []+bench-support = ["gpui/bench-support"]test-support = ["gpui/test-support"]runtime_shaders = []diff --git a/crates/gpui_apple/src/metal_renderer.rs b/crates/gpui_apple/src/metal_renderer.rsindex 0f41297297c..112717b2348 100644--- a/crates/gpui_apple/src/metal_renderer.rs+++ b/crates/gpui_apple/src/metal_renderer.rs@@ -10,7 +10,7 @@ use gpui::{AtlasTextureId, Background, Bounds, ContentMask, DevicePixels, PaintSurface, Path, Point,PrimitiveBatch, ScaledPixels, Scene, Size, point, size,};-#[cfg(any(test, feature = "test-support"))]+#[cfg(any(test, feature = "bench-support", feature = "test-support"))]use image::RgbaImage;use core_foundation::base::TCFType;@@ -136,7 +136,7 @@ pub struct MetalRenderer {path_sample_count: u32,/// Offscreen render target reused across `render_scene` calls when/// rendering headlessly without reading pixels back.- #[cfg(any(test, feature = "test-support"))]+ #[cfg(any(test, feature = "bench-support", feature = "test-support"))]headless_render_target: Option<metal::Texture>,}@@ -180,7 +180,7 @@ impl MetalRenderer {////// This renderer can render scenes to images without requiring a CAMetalLayer,/// window, or AppKit. Use `render_scene_to_image()` to render scenes.- #[cfg(any(test, feature = "test-support"))]+ #[cfg(any(test, feature = "bench-support", feature = "test-support"))]pub fn new_headless(instance_buffer_pool: Arc<Mutex<InstanceBufferPool>>) -> Self {let device = Self::create_device();Self::new_internal(device, None, true, instance_buffer_pool)@@ -352,7 +352,7 @@ impl MetalRenderer {path_intermediate_texture: None,path_intermediate_msaa_texture: None,path_sample_count: PATH_SAMPLE_COUNT,- #[cfg(any(test, feature = "test-support"))]+ #[cfg(any(test, feature = "bench-support", feature = "test-support"))]headless_render_target: None,}}@@ -565,7 +565,7 @@ impl MetalRenderer {////// This is the primary method for headless rendering. It creates an offscreen/// texture, renders the scene to it, and returns the pixel data as an RGBA image.- #[cfg(any(test, feature = "test-support"))]+ #[cfg(any(test, feature = "bench-support", feature = "test-support"))]pub fn render_scene_to_image(&mut self,scene: &Scene,@@ -613,7 +613,7 @@ impl MetalRenderer {/// encoding, instance buffer writes, command submission) and is used by/// headless benchmark rendering, where the produced pixels are never/// inspected.- #[cfg(any(test, feature = "test-support"))]+ #[cfg(any(test, feature = "bench-support", feature = "test-support"))]pub fn render_scene(&mut self, scene: &Scene, size: Size<DevicePixels>) -> Result<()> {if size.width.0 <= 0 || size.height.0 <= 0 {anyhow::bail!("Invalid size for render_scene: {:?}", size);@@ -1236,7 +1236,7 @@ fn new_command_encoder_for_texture<'a>(command_encoder}-#[cfg(any(test, feature = "test-support"))]+#[cfg(any(test, feature = "bench-support", feature = "test-support"))]fn read_texture_to_image(texture: &metal::TextureRef) -> Result<RgbaImage> {let width = texture.width() as u32;let height = texture.height() as u32;@@ -1592,12 +1592,12 @@ pub struct SurfaceBounds {pub content_mask: ContentMask<ScaledPixels>,}-#[cfg(any(test, feature = "test-support"))]+#[cfg(any(test, feature = "bench-support", feature = "test-support"))]pub struct MetalHeadlessRenderer {renderer: MetalRenderer,}-#[cfg(any(test, feature = "test-support"))]+#[cfg(any(test, feature = "bench-support", feature = "test-support"))]impl MetalHeadlessRenderer {pub fn new() -> Self {let instance_buffer_pool = Arc::new(Mutex::new(InstanceBufferPool::default()));@@ -1606,7 +1606,7 @@ impl MetalHeadlessRenderer {}}-#[cfg(any(test, feature = "test-support"))]+#[cfg(any(test, feature = "bench-support", feature = "test-support"))]impl gpui::PlatformHeadlessRenderer for MetalHeadlessRenderer {fn render_scene_to_image(&mut self,diff --git a/crates/gpui_macos/Cargo.toml b/crates/gpui_macos/Cargo.tomlindex ff10902a37c..22bc2ab6854 100644--- a/crates/gpui_macos/Cargo.toml+++ b/crates/gpui_macos/Cargo.toml@@ -13,6 +13,7 @@ path = "src/gpui_macos.rs"[features]default = ["gpui/default"]+bench-support = ["gpui/bench-support", "gpui_apple/bench-support"]test-support = ["gpui/test-support", "gpui_apple/test-support"]runtime_shaders = ["gpui_apple/runtime_shaders"]font-kit = ["dep:font-kit"]diff --git a/crates/gpui_macos/src/gpui_macos.rs b/crates/gpui_macos/src/gpui_macos.rsindex 1ee18729944..1e393e48759 100644--- a/crates/gpui_macos/src/gpui_macos.rs+++ b/crates/gpui_macos/src/gpui_macos.rs@@ -20,7 +20,7 @@ use gpui_apple::metal_renderer as renderer;pub mod metal_renderer {pub use gpui_apple::metal_renderer::{PathRasterizationVertex, PathSprite, SurfaceBounds};- #[cfg(any(test, feature = "test-support"))]+ #[cfg(any(test, feature = "bench-support", feature = "test-support"))]pub use gpui_apple::metal_renderer::MetalHeadlessRenderer;}diff --git a/crates/gpui_platform/Cargo.toml b/crates/gpui_platform/Cargo.tomlindex a502ff138d6..57629a79935 100644--- a/crates/gpui_platform/Cargo.toml+++ b/crates/gpui_platform/Cargo.toml@@ -13,6 +13,7 @@ path = "src/gpui_platform.rs"[features]default = []+bench-support = ["gpui/bench-support", "gpui_macos/bench-support"]font-kit = ["gpui_macos/font-kit"]test-support = ["gpui/test-support", "gpui_macos/test-support", "gpui_windows/test-support"]screen-capture = ["gpui/screen-capture", "gpui_macos/screen-capture", "gpui_windows/screen-capture", "gpui_linux/screen-capture"]diff --git a/crates/gpui_platform/src/gpui_platform.rs b/crates/gpui_platform/src/gpui_platform.rsindex 91d336ad169..b95e6098368 100644--- a/crates/gpui_platform/src/gpui_platform.rs+++ b/crates/gpui_platform/src/gpui_platform.rs@@ -81,7 +81,7 @@ pub fn current_platform(headless: bool) -> Rc<dyn Platform> {}/// Returns a new [`HeadlessRenderer`] for the current platform, if available.-#[cfg(feature = "test-support")]+#[cfg(any(feature = "bench-support", feature = "test-support"))]pub fn current_headless_renderer() -> Option<Box<dyn gpui::PlatformHeadlessRenderer>> {#[cfg(target_os = "macos")]{