pub struct Queue {
pub(crate) context: Arc<dyn DynContext>,
pub(crate) id: ObjectId,
pub(crate) data: Box<dyn Any + Sync + Send>,
}
Expand description
Handle to a command queue on a device.
A Queue
executes recorded CommandBuffer
objects and provides convenience methods
for writing to buffers and textures.
It can be created along with a Device
by calling Adapter::request_device
.
Corresponds to WebGPU GPUQueue
.
Fields§
§context: Arc<dyn DynContext>
§id: ObjectId
§data: Box<dyn Any + Sync + Send>
Implementations§
§impl Queue
impl Queue
pub fn write_buffer(&self, buffer: &Buffer, offset: u64, data: &[u8])
pub fn write_buffer(&self, buffer: &Buffer, offset: u64, data: &[u8])
Schedule a data write into buffer
starting at offset
.
This method fails if data
overruns the size of buffer
starting at offset
.
This does not submit the transfer to the GPU immediately. Calls to
write_buffer
begin execution only on the next call to
Queue::submit
. To get a set of scheduled transfers started
immediately, it’s fine to call submit
with no command buffers at all:
queue.submit([]);
However, data
will be immediately copied into staging memory, so the
caller may discard it any time after this call completes.
If possible, consider using Queue::write_buffer_with
instead. That
method avoids an intermediate copy and is often able to transfer data
more efficiently than this one.
pub fn write_buffer_with<'a>(
&'a self,
buffer: &'a Buffer,
offset: u64,
size: NonZero<u64>
) -> Option<QueueWriteBufferView<'a>>
pub fn write_buffer_with<'a>( &'a self, buffer: &'a Buffer, offset: u64, size: NonZero<u64> ) -> Option<QueueWriteBufferView<'a>>
Write to a buffer via a directly mapped staging buffer.
Return a QueueWriteBufferView
which, when dropped, schedules a copy
of its contents into buffer
at offset
. The returned view
dereferences to a size
-byte long &mut [u8]
, in which you should
store the data you would like written to buffer
.
This method may perform transfers faster than Queue::write_buffer
,
because the returned QueueWriteBufferView
is actually the staging
buffer for the write, mapped into the caller’s address space. Writing
your data directly into this staging buffer avoids the temporary
CPU-side buffer needed by write_buffer
.
Reading from the returned view is slow, and will not yield the current
contents of buffer
.
Note that dropping the QueueWriteBufferView
does not submit the
transfer to the GPU immediately. The transfer begins only on the next
call to Queue::submit
after the view is dropped. To get a set of
scheduled transfers started immediately, it’s fine to call submit
with
no command buffers at all:
queue.submit([]);
This method fails if size
is greater than the size of buffer
starting at offset
.
pub fn write_texture(
&self,
texture: ImageCopyTexture<&Texture>,
data: &[u8],
data_layout: ImageDataLayout,
size: Extent3d
)
pub fn write_texture( &self, texture: ImageCopyTexture<&Texture>, data: &[u8], data_layout: ImageDataLayout, size: Extent3d )
Schedule a write of some data into a texture.
data
contains the texels to be written, which must be in the same format as the texture.data_layout
describes the memory layout ofdata
, which does not necessarily have to have tightly packed rows.texture
specifies the texture to write into, and the location within the texture (coordinate offset, mip level) that will be overwritten.size
is the size, in texels, of the region to be written.
This method fails if size
overruns the size of texture
, or if data
is too short.
This does not submit the transfer to the GPU immediately. Calls to
write_texture
begin execution only on the next call to
Queue::submit
. To get a set of scheduled transfers started
immediately, it’s fine to call submit
with no command buffers at all:
queue.submit([]);
However, data
will be immediately copied into staging memory, so the
caller may discard it any time after this call completes.
pub fn submit<I>(&self, command_buffers: I) -> SubmissionIndexwhere
I: IntoIterator<Item = CommandBuffer>,
pub fn submit<I>(&self, command_buffers: I) -> SubmissionIndexwhere
I: IntoIterator<Item = CommandBuffer>,
Submits a series of finished command buffers for execution.
pub fn get_timestamp_period(&self) -> f32
pub fn get_timestamp_period(&self) -> f32
Gets the amount of nanoseconds each tick of a timestamp query represents.
Returns zero if timestamp queries are unsupported.
Timestamp values are represented in nanosecond values on WebGPU, see <https://gpuweb.github.io/gpuweb/#timestamp>
Therefore, this is always 1.0 on the web, but on wgpu-core a manual conversion is required.
pub fn on_submitted_work_done(&self, callback: impl FnOnce() + Send + 'static)
pub fn on_submitted_work_done(&self, callback: impl FnOnce() + Send + 'static)
Registers a callback when the previous call to submit finishes running on the gpu. This callback being called implies that all mapped buffer callbacks which were registered before this call will have been called.
For the callback to complete, either queue.submit(..)
, instance.poll_all(..)
, or device.poll(..)
must be called elsewhere in the runtime, possibly integrated into an event loop or run on a separate thread.
The callback will be called on the thread that first calls the above functions after the gpu work has completed. There are no restrictions on the code you can run in the callback, however on native the call to the function will not complete until the callback returns, so prefer keeping callbacks short and used to set flags, send messages, etc.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Queue
impl !RefUnwindSafe for Queue
impl Send for Queue
impl Sync for Queue
impl Unpin for Queue
impl !UnwindSafe for Queue
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request