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"
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

View file

@ -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");

View file

@ -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!()
}
}

View file

@ -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<LinuxWindowState>);
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<rwh::WindowHandle, rwh::HandleError> {
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<rwh::DisplayHandle, rwh::HandleError> {
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())
})
}
}

View file

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