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
This commit is contained in:
Dzmitry Malyshau 2024-02-03 22:39:44 -08:00
parent d0a0ce1885
commit cf71fe8bf1
5 changed files with 44 additions and 25 deletions

View file

@ -50,7 +50,8 @@ parking_lot.workspace = true
pathfinder_geometry = "0.5" pathfinder_geometry = "0.5"
postage.workspace = true postage.workspace = true
rand.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 refineable.workspace = true
resvg = "0.14" resvg = "0.14"
schemars.workspace = true schemars.workspace = true

View file

@ -1,3 +1,5 @@
#![cfg_attr(not(target_os = "macos"), allow(unused))]
use std::{ use std::{
env, env,
path::{Path, PathBuf}, path::{Path, PathBuf},
@ -6,15 +8,19 @@ use std::{
use cbindgen::Config; use cbindgen::Config;
fn main() { fn main() {
//generate_dispatch_bindings(); #[cfg(target_os = "macos")]
//let header_path = generate_shader_bindings(); generate_dispatch_bindings();
//#[cfg(feature = "runtime_shaders")] #[cfg(target_os = "macos")]
//emit_stitched_shaders(&header_path); let header_path = generate_shader_bindings();
//#[cfg(not(feature = "runtime_shaders"))] #[cfg(target_os = "macos")]
//compile_metal_shaders(&header_path); #[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:rustc-link-lib=framework=System");
println!("cargo:rerun-if-changed=src/platform/mac/dispatch.h"); println!("cargo:rerun-if-changed=src/platform/mac/dispatch.h");
@ -38,7 +44,7 @@ fn _generate_dispatch_bindings() {
.expect("couldn't write 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 output_path = PathBuf::from(env::var("OUT_DIR").unwrap()).join("scene.h");
let crate_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()); let crate_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
let mut config = Config::default(); let mut config = Config::default();
@ -116,7 +122,7 @@ fn emit_stitched_shaders(header_path: &Path) {
println!("cargo:rerun-if-changed={}", &shader_source_path); println!("cargo:rerun-if-changed={}", &shader_source_path);
} }
#[cfg(not(feature = "runtime_shaders"))] #[cfg(not(feature = "runtime_shaders"))]
fn _compile_metal_shaders(header_path: &Path) { fn compile_metal_shaders(header_path: &Path) {
use std::process::{self, Command}; use std::process::{self, Command};
let shader_path = "./src/platform/mac/shaders.metal"; let shader_path = "./src/platform/mac/shaders.metal";
let air_output_path = PathBuf::from(env::var("OUT_DIR").unwrap()).join("shaders.air"); let air_output_path = PathBuf::from(env::var("OUT_DIR").unwrap()).join("shaders.air");

View file

@ -3,8 +3,9 @@
use super::{BladeBelt, BladeBeltDescriptor}; use super::{BladeBelt, BladeBeltDescriptor};
use crate::{ use crate::{
AtlasTextureKind, AtlasTile, BladeAtlas, Bounds, ContentMask, Hsla, Path, PathId, PathVertex, AtlasTextureKind, AtlasTile, BladeAtlas, Bounds, ContentMask, Hsla, MonochromeSprite, Path,
PrimitiveBatch, Quad, ScaledPixels, Scene, Shadow, Underline, MonochromeSprite, PolychromeSprite, PATH_TEXTURE_FORMAT, PathId, PathVertex, PolychromeSprite, PrimitiveBatch, Quad, ScaledPixels, Scene, Shadow,
Underline, PATH_TEXTURE_FORMAT,
}; };
use bytemuck::{Pod, Zeroable}; use bytemuck::{Pod, Zeroable};
use collections::HashMap; use collections::HashMap;
@ -444,7 +445,10 @@ impl BladeRenderer {
); );
encoder.draw(0, 4, 0, underlines.len() as u32); 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 tex_info = self.atlas.get_texture_info(texture_id);
let instance_buf = self.instance_belt.alloc_data(&sprites, &self.gpu); let instance_buf = self.instance_belt.alloc_data(&sprites, &self.gpu);
let mut encoder = pass.with(&self.pipelines.mono_sprites); let mut encoder = pass.with(&self.pipelines.mono_sprites);
@ -459,7 +463,10 @@ impl BladeRenderer {
); );
encoder.draw(0, 4, 0, sprites.len() as u32); 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 tex_info = self.atlas.get_texture_info(texture_id);
let instance_buf = self.instance_belt.alloc_data(&sprites, &self.gpu); let instance_buf = self.instance_belt.alloc_data(&sprites, &self.gpu);
let mut encoder = pass.with(&self.pipelines.poly_sprites); let mut encoder = pass.with(&self.pipelines.poly_sprites);
@ -474,7 +481,7 @@ impl BladeRenderer {
); );
encoder.draw(0, 4, 0, sprites.len() as u32); encoder.draw(0, 4, 0, sprites.len() as u32);
} }
PrimitiveBatch::Surfaces {..} => { PrimitiveBatch::Surfaces { .. } => {
unimplemented!() unimplemented!()
} }
} }

View file

@ -9,6 +9,8 @@ use raw_window_handle as rwh;
use std::{ use std::{
ffi::c_void, ffi::c_void,
mem, mem,
num::NonZeroU32,
ptr::NonNull,
rc::Rc, rc::Rc,
sync::{self, Arc}, sync::{self, Arc},
}; };
@ -71,17 +73,17 @@ pub(crate) struct LinuxWindowState {
#[derive(Clone)] #[derive(Clone)]
pub(crate) struct LinuxWindow(pub(crate) Arc<LinuxWindowState>); pub(crate) struct LinuxWindow(pub(crate) Arc<LinuxWindowState>);
unsafe impl rwh::HasRawWindowHandle for RawWindow { unsafe impl blade_rwh::HasRawWindowHandle for RawWindow {
fn raw_window_handle(&self) -> rwh::RawWindowHandle { fn raw_window_handle(&self) -> blade_rwh::RawWindowHandle {
let mut wh = rwh::XcbWindowHandle::empty(); let mut wh = blade_rwh::XcbWindowHandle::empty();
wh.window = self.window_id; wh.window = self.window_id;
wh.visual_id = self.visual_id; wh.visual_id = self.visual_id;
wh.into() wh.into()
} }
} }
unsafe impl rwh::HasRawDisplayHandle for RawWindow { unsafe impl blade_rwh::HasRawDisplayHandle for RawWindow {
fn raw_display_handle(&self) -> rwh::RawDisplayHandle { fn raw_display_handle(&self) -> blade_rwh::RawDisplayHandle {
let mut dh = rwh::XcbDisplayHandle::empty(); let mut dh = blade_rwh::XcbDisplayHandle::empty();
dh.connection = self.connection; dh.connection = self.connection;
dh.screen = self.screen_id; dh.screen = self.screen_id;
dh.into() dh.into()
@ -91,16 +93,18 @@ unsafe impl rwh::HasRawDisplayHandle for RawWindow {
impl rwh::HasWindowHandle for LinuxWindow { impl rwh::HasWindowHandle for LinuxWindow {
fn window_handle(&self) -> Result<rwh::WindowHandle, rwh::HandleError> { fn window_handle(&self) -> Result<rwh::WindowHandle, rwh::HandleError> {
Ok(unsafe { Ok(unsafe {
let raw_handle = rwh::HasRawWindowHandle::raw_window_handle(&self.0.raw); let non_zero = NonZeroU32::new(self.0.raw.window_id).unwrap();
rwh::WindowHandle::borrow_raw(raw_handle, rwh::ActiveHandle::new()) let handle = rwh::XcbWindowHandle::new(non_zero);
rwh::WindowHandle::borrow_raw(handle.into())
}) })
} }
} }
impl rwh::HasDisplayHandle for LinuxWindow { impl rwh::HasDisplayHandle for LinuxWindow {
fn display_handle(&self) -> Result<rwh::DisplayHandle, rwh::HandleError> { fn display_handle(&self) -> Result<rwh::DisplayHandle, rwh::HandleError> {
Ok(unsafe { Ok(unsafe {
let raw_handle = rwh::HasRawDisplayHandle::raw_display_handle(&self.0.raw); let non_zero = NonNull::new(self.0.raw.connection).unwrap();
rwh::DisplayHandle::borrow_raw(raw_handle) let handle = rwh::XcbDisplayHandle::new(Some(non_zero), self.0.raw.screen_id);
rwh::DisplayHandle::borrow_raw(handle.into())
}) })
} }
} }

View file

@ -174,6 +174,7 @@ impl MetalAtlasTexture {
origin: allocation.rectangle.min.into(), origin: allocation.rectangle.min.into(),
size, size,
}, },
padding: 0,
}; };
Some(tile) Some(tile)
} }