Skip to content
This repository was archived by the owner on Jun 18, 2021. It is now read-only.

Commit 0751806

Browse files
bors[bot]kvark
andauthored
Merge #236
236: Update to wgpu-core with Option<Id> r=kvark a=kvark Co-authored-by: Dzmitry Malyshau <[email protected]>
2 parents e198d63 + 0f71647 commit 0751806

File tree

2 files changed

+22
-24
lines changed

2 files changed

+22
-24
lines changed

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,19 @@ vulkan = ["wgn/vulkan-portability"]
2727
package = "wgpu-native"
2828
version = "0.4"
2929
git = "https://github.com/gfx-rs/wgpu"
30-
rev = "05ba7a50b4645f6ac6c65edbae295a31c0d7ebef"
30+
rev = "902a0ebca397ee0414130b5b48e8126c2b437597"
3131

3232
[dependencies.wgc]
3333
package = "wgpu-core"
3434
version = "0.1"
3535
git = "https://github.com/gfx-rs/wgpu"
36-
rev = "05ba7a50b4645f6ac6c65edbae295a31c0d7ebef"
36+
rev = "902a0ebca397ee0414130b5b48e8126c2b437597"
3737

3838
[dependencies.wgt]
3939
package = "wgpu-types"
4040
version = "0.1"
4141
git = "https://github.com/gfx-rs/wgpu"
42-
rev = "05ba7a50b4645f6ac6c65edbae295a31c0d7ebef"
42+
rev = "902a0ebca397ee0414130b5b48e8126c2b437597"
4343

4444
[dependencies]
4545
arrayvec = "0.5"

src/lib.rs

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ pub struct ComputePipelineDescriptor<'a> {
446446
}
447447

448448
pub type RenderPassColorAttachmentDescriptor<'a> =
449-
wgt::RenderPassColorAttachmentDescriptorBase<&'a TextureView, Option<&'a TextureView>>;
449+
wgt::RenderPassColorAttachmentDescriptorBase<&'a TextureView>;
450450
pub type RenderPassDepthStencilAttachmentDescriptor<'a> =
451451
wgt::RenderPassDepthStencilAttachmentDescriptorBase<&'a TextureView>;
452452

@@ -623,26 +623,26 @@ impl Adapter {
623623
/// If no adapters are found that suffice all the "hard" options, `None` is returned.
624624
pub async fn request(options: &RequestAdapterOptions<'_>, backends: BackendBit) -> Option<Self> {
625625
unsafe extern "C" fn adapter_callback(
626-
id: wgc::id::AdapterId,
626+
id: Option<wgc::id::AdapterId>,
627627
user_data: *mut std::ffi::c_void,
628628
) {
629-
*(user_data as *mut wgc::id::AdapterId) = id;
629+
*(user_data as *mut Option<wgc::id::AdapterId>) = id;
630630
}
631631

632-
let mut id = wgc::id::AdapterId::ERROR;
632+
let mut id_maybe = None;
633633
unsafe {
634634
wgn::wgpu_request_adapter_async(
635635
Some(&wgc::instance::RequestAdapterOptions {
636636
power_preference: options.power_preference,
637637
compatible_surface: options.compatible_surface
638-
.map_or(wgc::id::SurfaceId::ERROR, |surface| surface.id),
638+
.map(|surface| surface.id),
639639
}),
640640
backends,
641641
adapter_callback,
642-
&mut id as *mut _ as *mut std::ffi::c_void,
642+
&mut id_maybe as *mut _ as *mut std::ffi::c_void,
643643
)
644644
};
645-
Some(Adapter { id })
645+
id_maybe.map(|id| Adapter { id })
646646
}
647647

648648
/// Requests a connection to a physical device, creating a logical device.
@@ -1228,7 +1228,7 @@ impl CommandEncoder {
12281228
.iter()
12291229
.map(|ca| wgc::command::RenderPassColorAttachmentDescriptor {
12301230
attachment: ca.attachment.id,
1231-
resolve_target: ca.resolve_target.map(|rt| &rt.id),
1231+
resolve_target: ca.resolve_target.map(|rt| rt.id),
12321232
load_op: ca.load_op,
12331233
store_op: ca.store_op,
12341234
clear_color: ca.clear_color,
@@ -1633,26 +1633,24 @@ impl Drop for SwapChainOutput {
16331633
}
16341634
}
16351635

1636+
/// The GPU timed out when attempting to acquire the next texture or if a
1637+
/// previous output is still alive.
1638+
#[derive(Clone, Debug)]
1639+
pub struct TimeOut;
1640+
16361641
impl SwapChain {
16371642
/// Returns the next texture to be presented by the swapchain for drawing.
16381643
///
16391644
/// When the [`SwapChainOutput`] returned by this method is dropped, the swapchain will present
16401645
/// the texture to the associated [`Surface`].
1641-
///
1642-
/// Returns an `Err` if the GPU timed out when attempting to acquire the next texture or if a
1643-
/// previous output is still alive.
1644-
pub fn get_next_texture(&mut self) -> Result<SwapChainOutput, ()> {
1646+
pub fn get_next_texture(&mut self) -> Result<SwapChainOutput, TimeOut> {
16451647
let output = wgn::wgpu_swap_chain_get_next_texture(self.id);
1646-
if output.view_id == wgc::id::Id::ERROR {
1647-
Err(())
1648-
} else {
1649-
Ok(SwapChainOutput {
1650-
view: TextureView {
1651-
id: output.view_id,
1652-
owned: false,
1653-
},
1648+
match output.view_id {
1649+
Some(id) => Ok(SwapChainOutput {
1650+
view: TextureView { id, owned: false },
16541651
swap_chain_id: self.id,
1655-
})
1652+
}),
1653+
None => Err(TimeOut),
16561654
}
16571655
}
16581656
}

0 commit comments

Comments
 (0)