mirror of
https://github.com/italicsjenga/vello.git
synced 2025-01-10 20:51:29 +11:00
Add capability to function as a guest in Metal
WIP
This commit is contained in:
parent
41c7118e91
commit
5e221d2e91
|
@ -16,7 +16,7 @@ mod macros;
|
||||||
mod mux;
|
mod mux;
|
||||||
|
|
||||||
pub use crate::mux::{
|
pub use crate::mux::{
|
||||||
DescriptorSet, Fence, Instance, Pipeline, QueryPool, Sampler, Semaphore, ShaderCode, Surface,
|
DescriptorSet, Device, Fence, Instance, Pipeline, QueryPool, Sampler, Semaphore, ShaderCode, Surface,
|
||||||
Swapchain,
|
Swapchain,
|
||||||
};
|
};
|
||||||
pub use bufwrite::BufWrite;
|
pub use bufwrite::BufWrite;
|
||||||
|
|
|
@ -153,6 +153,33 @@ impl MtlInstance {
|
||||||
pub fn device(&self, _surface: Option<&MtlSurface>) -> Result<MtlDevice, Error> {
|
pub fn device(&self, _surface: Option<&MtlSurface>) -> Result<MtlDevice, Error> {
|
||||||
if let Some(device) = metal::Device::system_default() {
|
if let Some(device) = metal::Device::system_default() {
|
||||||
let cmd_queue = device.new_command_queue();
|
let cmd_queue = device.new_command_queue();
|
||||||
|
Ok(MtlDevice::new_from_raw_mtl(device, cmd_queue))
|
||||||
|
} else {
|
||||||
|
Err("can't create system default Metal device".into())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn swapchain(
|
||||||
|
&self,
|
||||||
|
_width: usize,
|
||||||
|
_height: usize,
|
||||||
|
device: &MtlDevice,
|
||||||
|
surface: &MtlSurface,
|
||||||
|
) -> Result<MtlSwapchain, Error> {
|
||||||
|
surface.layer.set_device(&device.device);
|
||||||
|
let n_drawables = surface.layer.maximum_drawable_count() as usize;
|
||||||
|
Ok(MtlSwapchain {
|
||||||
|
layer: surface.layer.to_owned(),
|
||||||
|
cmd_queue: device.cmd_queue.clone(),
|
||||||
|
drawable: Default::default(),
|
||||||
|
n_drawables,
|
||||||
|
drawable_ix: 0,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MtlDevice {
|
||||||
|
pub fn new_from_raw_mtl(device: metal::Device, cmd_queue: metal::CommandQueue) -> MtlDevice {
|
||||||
let is_mac = device.supports_feature_set(MTLFeatureSet::macOS_GPUFamily1_v1);
|
let is_mac = device.supports_feature_set(MTLFeatureSet::macOS_GPUFamily1_v1);
|
||||||
let is_ios = device.supports_feature_set(MTLFeatureSet::iOS_GPUFamily1_v1);
|
let is_ios = device.supports_feature_set(MTLFeatureSet::iOS_GPUFamily1_v1);
|
||||||
let version = NSOperatingSystemVersion::get();
|
let version = NSOperatingSystemVersion::get();
|
||||||
|
@ -182,34 +209,13 @@ impl MtlInstance {
|
||||||
let helpers = Arc::new(Helpers {
|
let helpers = Arc::new(Helpers {
|
||||||
clear_pipeline: clear::make_clear_pipeline(&device),
|
clear_pipeline: clear::make_clear_pipeline(&device),
|
||||||
});
|
});
|
||||||
Ok(MtlDevice {
|
MtlDevice {
|
||||||
device,
|
device,
|
||||||
cmd_queue: Arc::new(Mutex::new(cmd_queue)),
|
cmd_queue: Arc::new(Mutex::new(cmd_queue)),
|
||||||
gpu_info,
|
gpu_info,
|
||||||
helpers,
|
helpers,
|
||||||
})
|
|
||||||
} else {
|
|
||||||
Err("can't create system default Metal device".into())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn swapchain(
|
|
||||||
&self,
|
|
||||||
_width: usize,
|
|
||||||
_height: usize,
|
|
||||||
device: &MtlDevice,
|
|
||||||
surface: &MtlSurface,
|
|
||||||
) -> Result<MtlSwapchain, Error> {
|
|
||||||
surface.layer.set_device(&device.device);
|
|
||||||
let n_drawables = surface.layer.maximum_drawable_count() as usize;
|
|
||||||
Ok(MtlSwapchain {
|
|
||||||
layer: surface.layer.to_owned(),
|
|
||||||
cmd_queue: device.cmd_queue.clone(),
|
|
||||||
drawable: Default::default(),
|
|
||||||
n_drawables,
|
|
||||||
drawable_ix: 0,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl crate::backend::Device for MtlDevice {
|
impl crate::backend::Device for MtlDevice {
|
||||||
|
|
|
@ -208,6 +208,11 @@ impl Instance {
|
||||||
// but not doing so lets us diverge more easily (at the moment, the divergence is
|
// but not doing so lets us diverge more easily (at the moment, the divergence is
|
||||||
// missing functionality).
|
// missing functionality).
|
||||||
impl Device {
|
impl Device {
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
pub fn new_from_raw_mtl(device: &::metal::DeviceRef, queue: &::metal::CommandQueueRef) -> Device {
|
||||||
|
Device::Mtl(metal::MtlDevice::new_from_raw_mtl(device.to_owned(), queue.to_owned()))
|
||||||
|
}
|
||||||
|
|
||||||
pub fn query_gpu_info(&self) -> GpuInfo {
|
pub fn query_gpu_info(&self) -> GpuInfo {
|
||||||
mux_match! { self;
|
mux_match! { self;
|
||||||
Device::Vk(d) => d.query_gpu_info(),
|
Device::Vk(d) => d.query_gpu_info(),
|
||||||
|
|
Loading…
Reference in a new issue