[rs] Move backends: BackendBit paramter to Instance::new()

This commit is contained in:
Marvin Löbel
2020-06-17 21:18:10 +02:00
parent 581d725856
commit 3404a12b76
9 changed files with 23 additions and 35 deletions

View File

@@ -28,14 +28,14 @@ vulkan = ["wgc/gfx-backend-vulkan"]
package = "wgpu-core"
version = "0.5"
git = "https://github.com/gfx-rs/wgpu"
rev = "6bca38feed155aa80776ae5e7dfa4769c655b638"
rev = "a02a56684114da702a64e30af49d0167e273402b"
features = ["raw-window-handle"]
[dependencies.wgt]
package = "wgpu-types"
version = "0.5"
git = "https://github.com/gfx-rs/wgpu"
rev = "6bca38feed155aa80776ae5e7dfa4769c655b638"
rev = "a02a56684114da702a64e30af49d0167e273402b"
[dependencies]
arrayvec = "0.5"

View File

@@ -7,14 +7,13 @@ use std::io::Write;
use std::mem::size_of;
async fn run() {
let adapter = wgpu::Instance::new()
let adapter = wgpu::Instance::new(wgpu::BackendBit::PRIMARY)
.request_adapter(
&wgpu::RequestAdapterOptions {
power_preference: wgpu::PowerPreference::Default,
compatible_surface: None,
},
wgpu::UnsafeExtensions::disallow(),
wgpu::BackendBit::PRIMARY,
)
.await
.unwrap();

View File

@@ -56,7 +56,7 @@ pub trait Example: 'static + Sized {
async fn run_async<E: Example>(event_loop: EventLoop<()>, window: Window) {
log::info!("Initializing the surface...");
let instance = wgpu::Instance::new();
let instance = wgpu::Instance::new(wgpu::BackendBit::PRIMARY);
let (size, surface) = unsafe {
let size = window.inner_size();
let surface = instance.create_surface(&window);
@@ -72,7 +72,6 @@ async fn run_async<E: Example>(event_loop: EventLoop<()>, window: Window) {
compatible_surface: Some(&surface),
},
unsafe_extensions,
wgpu::BackendBit::PRIMARY,
)
.await
.unwrap();

View File

@@ -22,7 +22,7 @@ async fn execute_gpu(numbers: Vec<u32>) -> Vec<u32> {
let slice_size = numbers.len() * std::mem::size_of::<u32>();
let size = slice_size as wgpu::BufferAddress;
let instance = wgpu::Instance::new();
let instance = wgpu::Instance::new(wgpu::BackendBit::PRIMARY);
let adapter = instance
.request_adapter(
&wgpu::RequestAdapterOptions {
@@ -30,7 +30,6 @@ async fn execute_gpu(numbers: Vec<u32>) -> Vec<u32> {
compatible_surface: None,
},
wgpu::UnsafeExtensions::disallow(),
wgpu::BackendBit::PRIMARY,
)
.await
.unwrap();

View File

@@ -6,7 +6,7 @@ use winit::{
async fn run(event_loop: EventLoop<()>, window: Window, swapchain_format: wgpu::TextureFormat) {
let size = window.inner_size();
let instance = wgpu::Instance::new();
let instance = wgpu::Instance::new(wgpu::BackendBit::PRIMARY);
let surface = unsafe { instance.create_surface(&window) };
let adapter = instance
.request_adapter(
@@ -15,7 +15,6 @@ async fn run(event_loop: EventLoop<()>, window: Window, swapchain_format: wgpu::
compatible_surface: Some(&surface),
},
wgpu::UnsafeExtensions::disallow(),
wgpu::BackendBit::PRIMARY,
)
.await
.unwrap();

View File

@@ -1,13 +1,12 @@
/// This example shows how to describe the adapter in use.
async fn run() {
let adapter = wgpu::Instance::new()
let adapter = wgpu::Instance::new(wgpu::BackendBit::PRIMARY)
.request_adapter(
&wgpu::RequestAdapterOptions {
power_preference: wgpu::PowerPreference::Default,
compatible_surface: None,
},
unsafe { wgpu::UnsafeExtensions::allow() },
wgpu::BackendBit::PRIMARY,
)
.await
.unwrap();

View File

@@ -329,8 +329,8 @@ impl crate::Context for Context {
Ready<Result<(Self::DeviceId, Self::QueueId), crate::RequestDeviceError>>;
type MapAsyncFuture = native_gpu_future::GpuFuture<Result<(), crate::BufferAsyncError>>;
fn init() -> Self {
wgc::hub::Global::new("wgpu", wgc::hub::IdentityManagerFactory)
fn init(backends: wgt::BackendBit) -> Self {
wgc::hub::Global::new("wgpu", wgc::hub::IdentityManagerFactory, backends)
}
fn instance_create_surface(
@@ -344,7 +344,6 @@ impl crate::Context for Context {
&self,
options: &crate::RequestAdapterOptions<'_>,
unsafe_extensions: wgt::UnsafeExtensions,
backends: wgt::BackendBit,
) -> Self::RequestAdapterFuture {
let id = self.pick_adapter(
&wgc::instance::RequestAdapterOptions {
@@ -352,7 +351,7 @@ impl crate::Context for Context {
compatible_surface: options.compatible_surface.map(|surface| surface.id),
},
unsafe_extensions,
wgc::instance::AdapterInputs::Mask(backends, |_| PhantomData),
wgc::instance::AdapterInputs::Mask(wgt::BackendBit::all(), |_| PhantomData),
);
ready(id)
}

View File

@@ -649,7 +649,7 @@ impl crate::Context for Context {
>;
type MapAsyncFuture = MakeSendFuture<MapFuture<()>>;
fn init() -> Self {
fn init(_backends: wgt::BackendBit) -> Self {
Sendable(web_sys::window().unwrap().navigator().gpu())
}
@@ -682,7 +682,6 @@ impl crate::Context for Context {
&self,
options: &crate::RequestAdapterOptions<'_>,
_unsafe_extensions: wgt::UnsafeExtensions,
_backends: wgt::BackendBit,
) -> Self::RequestAdapterFuture {
//TODO: support this check, return `None` if the flag is not set.
// It's not trivial, since we need the Future logic to have this check,

View File

@@ -130,7 +130,7 @@ trait Context: Sized {
+ Send;
type MapAsyncFuture: Future<Output = Result<(), BufferAsyncError>> + Send;
fn init() -> Self;
fn init(backends: BackendBit) -> Self;
fn instance_create_surface(
&self,
handle: &impl raw_window_handle::HasRawWindowHandle,
@@ -139,7 +139,6 @@ trait Context: Sized {
&self,
options: &RequestAdapterOptions<'_>,
unsafe_extensions: UnsafeExtensions,
backends: BackendBit,
) -> Self::RequestAdapterFuture;
fn adapter_request_device(
&self,
@@ -981,10 +980,11 @@ pub struct TextureCopyView<'a> {
}
impl Instance {
/// Create an new instance of wgpu.
pub fn new() -> Self {
/// Create an new instance of wgpu. The `backends` parameter controls
/// among which backends wgpu will decide during instantiation.
pub fn new(backends: BackendBit) -> Self {
Instance {
context: Arc::new(C::init()),
context: Arc::new(C::init(backends)),
}
}
@@ -1029,16 +1029,12 @@ impl Instance {
) -> Surface {
let surface = wgc::instance::Surface {
#[cfg(feature = "vulkan-portability")]
vulkan: self
.context
.instance
.vulkan
.create_surface_from_layer(layer as *mut _, cfg!(debug_assertions)),
metal: self
.context
.instance
.metal
.create_surface_from_layer(layer as *mut _, cfg!(debug_assertions)),
vulkan: self.context.instance.vulkan.as_ref().map(|inst| {
inst.create_surface_from_layer(layer as *mut _, cfg!(debug_assertions))
}),
metal: self.context.instance.metal.as_ref().map(|inst| {
inst.create_surface_from_layer(layer as *mut _, cfg!(debug_assertions))
}),
};
crate::Surface {
@@ -1059,11 +1055,10 @@ impl Instance {
&self,
options: &RequestAdapterOptions<'_>,
unsafe_extensions: UnsafeExtensions,
backends: BackendBit,
) -> impl Future<Output = Option<Adapter>> + Send {
let context = Arc::clone(&self.context);
self.context
.instance_request_adapter(options, unsafe_extensions, backends)
.instance_request_adapter(options, unsafe_extensions)
.map(|option| option.map(|id| Adapter { context, id }))
}
}