Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document random bits and pieces. #2651

Merged
merged 1 commit into from
May 12, 2022
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
11 changes: 9 additions & 2 deletions wgpu/examples/cube/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,13 @@ fn create_texels(size: usize) -> Vec<u8> {
.collect()
}

// This can be done simpler with `FutureExt`, but we don't want to add
// a dependency just for this small case.
/// A wrapper for `pop_error_scope` futures that panics if an error occurs.
///
/// Given a future `inner` of an `Option<E>` for some error type `E`,
/// wait for the future to be ready, and panic if its value is `Some`.
///
/// This can be done simpler with `FutureExt`, but we don't want to add
/// a dependency just for this small case.
struct ErrorFuture<F> {
inner: F,
}
Expand Down Expand Up @@ -389,6 +394,8 @@ impl framework::Example for Example {
}

queue.submit(Some(encoder.finish()));

// If an error occurs, report it and panic.
spawner.spawn_local(ErrorFuture {
inner: device.pop_error_scope(),
});
Expand Down
8 changes: 5 additions & 3 deletions wgpu/src/util/belt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,16 @@ struct Chunk {
/// Staging belt is a machine that uploads data.
///
/// Internally it uses a ring-buffer of staging buffers that are sub-allocated.
/// It has an advantage over `Queue.write_buffer` in a way that it returns a mutable slice,
/// It has an advantage over [`Queue::write_buffer`] in a way that it returns a mutable slice,
/// which you can fill to avoid an extra data copy.
///
/// Using a staging belt is slightly complicated, and generally goes as follows:
/// - Write to buffers that need writing to using `write_buffer`.
/// - Write to buffers that need writing to using [`StagingBelt::write_buffer`].
/// - Call `finish`.
/// - Submit all command encoders used with `write_buffer`.
/// - Submit all command encoders used with `StagingBelt::write_buffer`.
/// - Call `recall`
///
/// [`Queue::write_buffer`]: crate::Queue::write_buffer
pub struct StagingBelt {
chunk_size: BufferAddress,
/// Chunks that we are actively using for pending transfers at this moment.
Expand Down