Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions examples/triangle/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ int main() {

WGPUSwapChainOutput next_texture =
wgpu_swap_chain_get_next_texture(swap_chain);
if (!next_texture.view_id) {
printf("Cannot acquire next swap chain texture");
return 1;
}

WGPUCommandEncoderId cmd_encoder = wgpu_device_create_command_encoder(
device, &(WGPUCommandEncoderDescriptor){.todo = 0});
Expand Down
2 changes: 2 additions & 0 deletions wgpu-native/src/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ type Dummy = crate::backend::Empty;
pub struct Id<T>(u64, PhantomData<T>);

impl<T> Id<T> {
pub const ERROR: Self = Self(0, PhantomData);

pub fn backend(&self) -> Backend {
match self.0 >> (64 - BACKEND_BITS) as u8 {
0 => Backend::Empty,
Expand Down
15 changes: 11 additions & 4 deletions wgpu-native/src/swap_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,16 @@ pub struct SwapChainOutput {
pub view_id: TextureViewId,
}

#[derive(Debug)]
pub enum SwapChainGetNextTextureError {
GpuProcessingTimeout,
}

pub fn swap_chain_get_next_texture<B: GfxBackend>(
global: &Global,
swap_chain_id: SwapChainId,
view_id_in: Input<TextureViewId>,
) -> SwapChainOutput {
) -> Result<SwapChainOutput, SwapChainGetNextTextureError> {
let hub = B::hub(global);
let mut token = Token::root();

Expand All @@ -148,7 +153,7 @@ pub fn swap_chain_get_next_texture<B: GfxBackend>(
match unsafe { suf.acquire_image(FRAME_TIMEOUT_MS * 1_000_000) } {
Ok(surface_image) => surface_image,
Err(hal::window::AcquireError::Timeout) => {
panic!("GPU took too much time processing last frames :(");
return Err(SwapChainGetNextTextureError::GpuProcessingTimeout);
}
Err(e) => {
log::warn!("acquire_image() failed ({:?}), reconfiguring swapchain", e);
Expand Down Expand Up @@ -197,13 +202,15 @@ pub fn swap_chain_get_next_texture<B: GfxBackend>(
ref_count,
});

SwapChainOutput { view_id }
Ok(SwapChainOutput { view_id })
}

#[cfg(feature = "local")]
#[no_mangle]
pub extern "C" fn wgpu_swap_chain_get_next_texture(swap_chain_id: SwapChainId) -> SwapChainOutput {
gfx_select!(swap_chain_id => swap_chain_get_next_texture(&*GLOBAL, swap_chain_id, PhantomData))
gfx_select!(swap_chain_id => swap_chain_get_next_texture(&*GLOBAL, swap_chain_id, PhantomData)).unwrap_or(SwapChainOutput {
view_id: TextureViewId::ERROR,
})
}

pub fn swap_chain_present<B: GfxBackend>(global: &Global, swap_chain_id: SwapChainId) {
Expand Down