From 0f279c54bc53d33ba715960cd97a94021aee6f69 Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Thu, 2 Apr 2020 00:27:43 -0400 Subject: [PATCH] [rs] Update to latest wgpu, duplicate RequestAdapterOptions --- wgpu/Cargo.toml | 23 ++++++++++++++++------- wgpu/examples/capture/main.rs | 1 + wgpu/examples/describe/main.rs | 1 + wgpu/examples/framework.rs | 1 + wgpu/examples/hello-compute/main.rs | 1 + wgpu/examples/hello-triangle/main.rs | 1 + wgpu/src/lib.rs | 20 ++++++++++++++++---- 7 files changed, 37 insertions(+), 11 deletions(-) diff --git a/wgpu/Cargo.toml b/wgpu/Cargo.toml index 17409a3285..a9491492c9 100644 --- a/wgpu/Cargo.toml +++ b/wgpu/Cargo.toml @@ -27,19 +27,19 @@ vulkan = ["wgn/vulkan-portability"] package = "wgpu-native" version = "0.4" git = "https://github.com/gfx-rs/wgpu" -rev = "306554600ab7479ec3e54d0c076c71f02474237a" +rev = "05ba7a50b4645f6ac6c65edbae295a31c0d7ebef" [dependencies.wgc] package = "wgpu-core" version = "0.1" git = "https://github.com/gfx-rs/wgpu" -rev = "306554600ab7479ec3e54d0c076c71f02474237a" +rev = "05ba7a50b4645f6ac6c65edbae295a31c0d7ebef" [dependencies.wgt] package = "wgpu-types" version = "0.1" git = "https://github.com/gfx-rs/wgpu" -rev = "306554600ab7479ec3e54d0c076c71f02474237a" +rev = "05ba7a50b4645f6ac6c65edbae295a31c0d7ebef" [dependencies] arrayvec = "0.5" @@ -58,12 +58,21 @@ rand = "0.7.2" zerocopy = "0.3" futures = "0.3" +[[example]] +name="hello-compute" +path="examples/hello-compute/main.rs" +test = true + #[patch."https://github.com/gfx-rs/wgpu"] #wgc = { version = "0.1.0", package = "wgpu-core", path = "../wgpu/wgpu-core" } #wgt = { version = "0.1.0", package = "wgpu-types", path = "../wgpu/wgpu-types" } #wgn = { version = "0.4.0", package = "wgpu-native", path = "../wgpu/wgpu-native" } -[[example]] -name="hello-compute" -path="examples/hello-compute/main.rs" -test = true +#[patch.crates-io] +#gfx-hal = { version = "0.5.0", path = "../gfx/src/hal" } +#gfx-backend-empty = { version = "0.5.0", path = "../gfx/src/backend/empty" } +#gfx-backend-vulkan = { version = "0.5.0", path = "../gfx/src/backend/vulkan" } +#gfx-backend-dx12 = { version = "0.5.0", path = "../gfx/src/backend/dx12" } +#gfx-backend-dx11 = { version = "0.5.0", path = "../gfx/src/backend/dx11" } +#gfx-descriptor = { version = "0.1.0", path = "../gfx-extras/gfx-descriptor" } +#gfx-memory = { version = "0.1.0", path = "../gfx-extras/gfx-memory" } diff --git a/wgpu/examples/capture/main.rs b/wgpu/examples/capture/main.rs index 613556d6c3..dc151e9197 100644 --- a/wgpu/examples/capture/main.rs +++ b/wgpu/examples/capture/main.rs @@ -8,6 +8,7 @@ async fn run() { let adapter = wgpu::Adapter::request( &wgpu::RequestAdapterOptions { power_preference: wgpu::PowerPreference::Default, + compatible_surface: None, }, wgpu::BackendBit::PRIMARY, ) diff --git a/wgpu/examples/describe/main.rs b/wgpu/examples/describe/main.rs index 131621ae1f..72e40493a6 100644 --- a/wgpu/examples/describe/main.rs +++ b/wgpu/examples/describe/main.rs @@ -8,6 +8,7 @@ async fn run() { let adapter = wgpu::Adapter::request( &wgpu::RequestAdapterOptions { power_preference: wgpu::PowerPreference::Default, + compatible_surface: None, }, wgpu::BackendBit::PRIMARY, ) diff --git a/wgpu/examples/framework.rs b/wgpu/examples/framework.rs index 6a33a0222b..15a540200d 100644 --- a/wgpu/examples/framework.rs +++ b/wgpu/examples/framework.rs @@ -102,6 +102,7 @@ async fn run_async(title: &str) { let adapter = wgpu::Adapter::request( &wgpu::RequestAdapterOptions { power_preference: wgpu::PowerPreference::Default, + compatible_surface: Some(&surface), }, wgpu::BackendBit::PRIMARY, ) diff --git a/wgpu/examples/hello-compute/main.rs b/wgpu/examples/hello-compute/main.rs index 75a9508220..97b87aa5df 100644 --- a/wgpu/examples/hello-compute/main.rs +++ b/wgpu/examples/hello-compute/main.rs @@ -24,6 +24,7 @@ async fn execute_gpu(numbers: Vec) -> Vec { let adapter = wgpu::Adapter::request( &wgpu::RequestAdapterOptions { power_preference: wgpu::PowerPreference::Default, + compatible_surface: None, }, wgpu::BackendBit::PRIMARY, ) diff --git a/wgpu/examples/hello-triangle/main.rs b/wgpu/examples/hello-triangle/main.rs index aa25890586..705f461c38 100644 --- a/wgpu/examples/hello-triangle/main.rs +++ b/wgpu/examples/hello-triangle/main.rs @@ -11,6 +11,7 @@ async fn run(event_loop: EventLoop<()>, window: Window) { let adapter = wgpu::Adapter::request( &wgpu::RequestAdapterOptions { power_preference: wgpu::PowerPreference::Default, + compatible_surface: Some(&surface), }, wgpu::BackendBit::PRIMARY, ) diff --git a/wgpu/src/lib.rs b/wgpu/src/lib.rs index caec30f40b..22dd210650 100644 --- a/wgpu/src/lib.rs +++ b/wgpu/src/lib.rs @@ -49,7 +49,6 @@ pub use wgt::{ PresentMode, PrimitiveTopology, RasterizationStateDescriptor, - RequestAdapterOptions, SamplerDescriptor, ShaderLocation, ShaderStage, @@ -79,7 +78,7 @@ pub use wgc::instance::{ #[derive(Default, Debug)] struct Temp { //bind_group_descriptors: Vec, -//vertex_buffers: Vec, + //vertex_buffers: Vec, } /// A handle to a physical graphics and/or compute device. @@ -91,6 +90,15 @@ pub struct Adapter { id: wgc::id::AdapterId, } +/// Options for requesting adapter. +#[derive(Clone, Debug)] +pub struct RequestAdapterOptions<'a> { + /// Power preference for the adapter. + pub power_preference: PowerPreference, + /// Surface that is required to be presentable with the requested adapter. + pub compatible_surface: Option<&'a Surface>, +} + /// An open connection to a graphics and/or compute device. /// /// The `Device` is the responsible for the creation of most rendering and compute resources, as @@ -613,7 +621,7 @@ impl Adapter { /// Some options are "soft", so treated as non-mandatory. Others are "hard". /// /// If no adapters are found that suffice all the "hard" options, `None` is returned. - pub async fn request(options: &RequestAdapterOptions, backends: BackendBit) -> Option { + pub async fn request(options: &RequestAdapterOptions<'_>, backends: BackendBit) -> Option { unsafe extern "C" fn adapter_callback( id: wgc::id::AdapterId, user_data: *mut std::ffi::c_void, @@ -624,7 +632,11 @@ impl Adapter { let mut id = wgc::id::AdapterId::ERROR; unsafe { wgn::wgpu_request_adapter_async( - Some(options), + Some(&wgc::instance::RequestAdapterOptions { + power_preference: options.power_preference, + compatible_surface: options.compatible_surface + .map_or(wgc::id::SurfaceId::ERROR, |surface| surface.id), + }), backends, adapter_callback, &mut id as *mut _ as *mut std::ffi::c_void,