From cf71fe8bf1945f51d96c977cf717ede69b33c63b Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Sat, 3 Feb 2024 22:39:44 -0800 Subject: [PATCH] fix MacOS build, switch external RWH to 0.6 leaving blade-internal RWH as 0.5 until this is fixed: https://github.com/ash-rs/ash/issues/864 --- crates/gpui/Cargo.toml | 3 ++- crates/gpui/build.rs | 24 ++++++++++++------- .../gpui/src/platform/linux/blade_renderer.rs | 17 +++++++++---- crates/gpui/src/platform/linux/window.rs | 24 +++++++++++-------- crates/gpui/src/platform/mac/metal_atlas.rs | 1 + 5 files changed, 44 insertions(+), 25 deletions(-) diff --git a/crates/gpui/Cargo.toml b/crates/gpui/Cargo.toml index 9a6530eeef..cc14ee4dfe 100644 --- a/crates/gpui/Cargo.toml +++ b/crates/gpui/Cargo.toml @@ -50,7 +50,8 @@ parking_lot.workspace = true pathfinder_geometry = "0.5" postage.workspace = true rand.workspace = true -raw-window-handle = "0.5.0" +raw-window-handle = "0.6" +blade-rwh = { package = "raw-window-handle", version = "0.5" } refineable.workspace = true resvg = "0.14" schemars.workspace = true diff --git a/crates/gpui/build.rs b/crates/gpui/build.rs index 70c3d8d8e4..802185ac85 100644 --- a/crates/gpui/build.rs +++ b/crates/gpui/build.rs @@ -1,3 +1,5 @@ +#![cfg_attr(not(target_os = "macos"), allow(unused))] + use std::{ env, path::{Path, PathBuf}, @@ -6,15 +8,19 @@ use std::{ use cbindgen::Config; fn main() { - //generate_dispatch_bindings(); - //let header_path = generate_shader_bindings(); - //#[cfg(feature = "runtime_shaders")] - //emit_stitched_shaders(&header_path); - //#[cfg(not(feature = "runtime_shaders"))] - //compile_metal_shaders(&header_path); + #[cfg(target_os = "macos")] + generate_dispatch_bindings(); + #[cfg(target_os = "macos")] + let header_path = generate_shader_bindings(); + #[cfg(target_os = "macos")] + #[cfg(feature = "runtime_shaders")] + emit_stitched_shaders(&header_path); + #[cfg(target_os = "macos")] + #[cfg(not(feature = "runtime_shaders"))] + compile_metal_shaders(&header_path); } -fn _generate_dispatch_bindings() { +fn generate_dispatch_bindings() { println!("cargo:rustc-link-lib=framework=System"); println!("cargo:rerun-if-changed=src/platform/mac/dispatch.h"); @@ -38,7 +44,7 @@ fn _generate_dispatch_bindings() { .expect("couldn't write dispatch bindings"); } -fn _generate_shader_bindings() -> PathBuf { +fn generate_shader_bindings() -> PathBuf { let output_path = PathBuf::from(env::var("OUT_DIR").unwrap()).join("scene.h"); let crate_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()); let mut config = Config::default(); @@ -116,7 +122,7 @@ fn emit_stitched_shaders(header_path: &Path) { println!("cargo:rerun-if-changed={}", &shader_source_path); } #[cfg(not(feature = "runtime_shaders"))] -fn _compile_metal_shaders(header_path: &Path) { +fn compile_metal_shaders(header_path: &Path) { use std::process::{self, Command}; let shader_path = "./src/platform/mac/shaders.metal"; let air_output_path = PathBuf::from(env::var("OUT_DIR").unwrap()).join("shaders.air"); diff --git a/crates/gpui/src/platform/linux/blade_renderer.rs b/crates/gpui/src/platform/linux/blade_renderer.rs index 7ac3acda19..1b7db6bcd4 100644 --- a/crates/gpui/src/platform/linux/blade_renderer.rs +++ b/crates/gpui/src/platform/linux/blade_renderer.rs @@ -3,8 +3,9 @@ use super::{BladeBelt, BladeBeltDescriptor}; use crate::{ - AtlasTextureKind, AtlasTile, BladeAtlas, Bounds, ContentMask, Hsla, Path, PathId, PathVertex, - PrimitiveBatch, Quad, ScaledPixels, Scene, Shadow, Underline, MonochromeSprite, PolychromeSprite, PATH_TEXTURE_FORMAT, + AtlasTextureKind, AtlasTile, BladeAtlas, Bounds, ContentMask, Hsla, MonochromeSprite, Path, + PathId, PathVertex, PolychromeSprite, PrimitiveBatch, Quad, ScaledPixels, Scene, Shadow, + Underline, PATH_TEXTURE_FORMAT, }; use bytemuck::{Pod, Zeroable}; use collections::HashMap; @@ -444,7 +445,10 @@ impl BladeRenderer { ); encoder.draw(0, 4, 0, underlines.len() as u32); } - PrimitiveBatch::MonochromeSprites { texture_id, sprites } => { + PrimitiveBatch::MonochromeSprites { + texture_id, + sprites, + } => { let tex_info = self.atlas.get_texture_info(texture_id); let instance_buf = self.instance_belt.alloc_data(&sprites, &self.gpu); let mut encoder = pass.with(&self.pipelines.mono_sprites); @@ -459,7 +463,10 @@ impl BladeRenderer { ); encoder.draw(0, 4, 0, sprites.len() as u32); } - PrimitiveBatch::PolychromeSprites { texture_id, sprites } => { + PrimitiveBatch::PolychromeSprites { + texture_id, + sprites, + } => { let tex_info = self.atlas.get_texture_info(texture_id); let instance_buf = self.instance_belt.alloc_data(&sprites, &self.gpu); let mut encoder = pass.with(&self.pipelines.poly_sprites); @@ -474,7 +481,7 @@ impl BladeRenderer { ); encoder.draw(0, 4, 0, sprites.len() as u32); } - PrimitiveBatch::Surfaces {..} => { + PrimitiveBatch::Surfaces { .. } => { unimplemented!() } } diff --git a/crates/gpui/src/platform/linux/window.rs b/crates/gpui/src/platform/linux/window.rs index 4e136da3d6..3818ec2c65 100644 --- a/crates/gpui/src/platform/linux/window.rs +++ b/crates/gpui/src/platform/linux/window.rs @@ -9,6 +9,8 @@ use raw_window_handle as rwh; use std::{ ffi::c_void, mem, + num::NonZeroU32, + ptr::NonNull, rc::Rc, sync::{self, Arc}, }; @@ -71,17 +73,17 @@ pub(crate) struct LinuxWindowState { #[derive(Clone)] pub(crate) struct LinuxWindow(pub(crate) Arc); -unsafe impl rwh::HasRawWindowHandle for RawWindow { - fn raw_window_handle(&self) -> rwh::RawWindowHandle { - let mut wh = rwh::XcbWindowHandle::empty(); +unsafe impl blade_rwh::HasRawWindowHandle for RawWindow { + fn raw_window_handle(&self) -> blade_rwh::RawWindowHandle { + let mut wh = blade_rwh::XcbWindowHandle::empty(); wh.window = self.window_id; wh.visual_id = self.visual_id; wh.into() } } -unsafe impl rwh::HasRawDisplayHandle for RawWindow { - fn raw_display_handle(&self) -> rwh::RawDisplayHandle { - let mut dh = rwh::XcbDisplayHandle::empty(); +unsafe impl blade_rwh::HasRawDisplayHandle for RawWindow { + fn raw_display_handle(&self) -> blade_rwh::RawDisplayHandle { + let mut dh = blade_rwh::XcbDisplayHandle::empty(); dh.connection = self.connection; dh.screen = self.screen_id; dh.into() @@ -91,16 +93,18 @@ unsafe impl rwh::HasRawDisplayHandle for RawWindow { impl rwh::HasWindowHandle for LinuxWindow { fn window_handle(&self) -> Result { Ok(unsafe { - let raw_handle = rwh::HasRawWindowHandle::raw_window_handle(&self.0.raw); - rwh::WindowHandle::borrow_raw(raw_handle, rwh::ActiveHandle::new()) + let non_zero = NonZeroU32::new(self.0.raw.window_id).unwrap(); + let handle = rwh::XcbWindowHandle::new(non_zero); + rwh::WindowHandle::borrow_raw(handle.into()) }) } } impl rwh::HasDisplayHandle for LinuxWindow { fn display_handle(&self) -> Result { Ok(unsafe { - let raw_handle = rwh::HasRawDisplayHandle::raw_display_handle(&self.0.raw); - rwh::DisplayHandle::borrow_raw(raw_handle) + let non_zero = NonNull::new(self.0.raw.connection).unwrap(); + let handle = rwh::XcbDisplayHandle::new(Some(non_zero), self.0.raw.screen_id); + rwh::DisplayHandle::borrow_raw(handle.into()) }) } } diff --git a/crates/gpui/src/platform/mac/metal_atlas.rs b/crates/gpui/src/platform/mac/metal_atlas.rs index 95f78a4465..7c23fafcba 100644 --- a/crates/gpui/src/platform/mac/metal_atlas.rs +++ b/crates/gpui/src/platform/mac/metal_atlas.rs @@ -174,6 +174,7 @@ impl MetalAtlasTexture { origin: allocation.rectangle.min.into(), size, }, + padding: 0, }; Some(tile) }