mirror of
https://github.com/italicsjenga/vello.git
synced 2025-01-11 04:51:32 +11:00
f04da3af9d
Adds a new "mux" module which can have multiple backends. As of this commit, it's not wired up at all, but the functionality should be reasonably complete. Minor tweaks to the backend trait to accommodate this, mostly changing Fence and Semaphore to references so they don't need to be Copy. Part of the work toward #95
80 lines
2.3 KiB
Rust
80 lines
2.3 KiB
Rust
// Copyright 2021 The piet-gpu authors.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// https://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
//
|
|
// Also licensed under MIT license, at your choice.
|
|
|
|
//! Macros, mostly to automate backend selection tedium.
|
|
|
|
#[macro_export]
|
|
macro_rules! mux {
|
|
( #[cfg(vk)] $($tokens:tt)* ) => {
|
|
#[cfg(not(target_os="macos"))] $( $tokens )*
|
|
};
|
|
|
|
( #[cfg(dx12)] $($tokens:tt)* ) => {
|
|
#[cfg(target_os="windows")] $( $tokens )*
|
|
};
|
|
}
|
|
|
|
#[macro_export]
|
|
macro_rules! mux_enum {
|
|
( $(#[$outer:meta])* $v:vis enum $name:ident {
|
|
Vk($vk:ty),
|
|
Dx12($dx12:ty),
|
|
} ) => {
|
|
$(#[$outer])* $v enum $name {
|
|
#[cfg(not(target_os="macos"))]
|
|
Vk($vk),
|
|
#[cfg(target_os="windows")]
|
|
Dx12($dx12),
|
|
}
|
|
|
|
impl $name {
|
|
$crate::mux! {
|
|
#[cfg(vk)]
|
|
#[allow(unused)]
|
|
fn vk(&self) -> &$vk {
|
|
match self {
|
|
$name::Vk(x) => x,
|
|
_ => panic!("downcast error")
|
|
}
|
|
}
|
|
}
|
|
|
|
$crate::mux! {
|
|
#[cfg(dx12)]
|
|
#[allow(unused)]
|
|
fn dx12(&self) -> &$dx12 {
|
|
match self {
|
|
$name::Dx12(x) => x,
|
|
_ => panic!("downcast error")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
};
|
|
}
|
|
|
|
macro_rules! mux_device_enum {
|
|
( $(#[$outer:meta])* $assoc_type: ident) => {
|
|
$crate::mux_enum! {
|
|
$(#[$outer])*
|
|
pub enum $assoc_type {
|
|
Vk(<$crate::vulkan::VkDevice as $crate::Device>::$assoc_type),
|
|
Dx12(<$crate::dx12::Dx12Device as $crate::Device>::$assoc_type),
|
|
}
|
|
}
|
|
}
|
|
}
|