@@ -329,6 +329,9 @@ pub trait Device<A: Api>: WasmNotSendSync {
329
329
unsafe fn create_sampler ( & self , desc : & SamplerDescriptor ) -> Result < A :: Sampler , DeviceError > ;
330
330
unsafe fn destroy_sampler ( & self , sampler : A :: Sampler ) ;
331
331
332
+ /// Create a fresh [`CommandEncoder`].
333
+ ///
334
+ /// The new `CommandEncoder` is in the "closed" state.
332
335
unsafe fn create_command_encoder (
333
336
& self ,
334
337
desc : & CommandEncoderDescriptor < A > ,
@@ -429,19 +432,95 @@ pub trait Queue<A: Api>: WasmNotSendSync {
429
432
unsafe fn get_timestamp_period ( & self ) -> f32 ;
430
433
}
431
434
432
- /// Encoder for commands in command buffers.
433
- /// Serves as a parent for all the encoded command buffers.
434
- /// Works in bursts of action: one or more command buffers are recorded,
435
- /// then submitted to a queue, and then it needs to be `reset_all()`.
435
+ /// Encoder and allocation pool for `CommandBuffer`.
436
+ ///
437
+ /// The life cycle of a `CommandBuffer` is as follows:
438
+ ///
439
+ /// - Call [`Device::create_command_encoder`] to create a new
440
+ /// `CommandEncoder`, in the "closed" state.
441
+ ///
442
+ /// - Call `begin_encoding` on a closed `CommandEncoder` to begin
443
+ /// recording commands. This puts the `CommandEncoder` in the
444
+ /// "recording" state.
445
+ ///
446
+ /// - Call methods like `copy_buffer_to_buffer`, `begin_render_pass`,
447
+ /// etc. on a "recording" `CommandEncoder` to add commands to the
448
+ /// list.
449
+ ///
450
+ /// - Call `end_encoding` on a recording `CommandEncoder` to close the
451
+ /// encoder and construct a fresh `CommandBuffer` consisting of the
452
+ /// list of commands recorded up to that point.
453
+ ///
454
+ /// - Call `discard_encoding` on a recording `CommandEncoder` to drop
455
+ /// the commands recorded thus far and close the encoder.
456
+ ///
457
+ /// - Call `reset_all` on a closed `CommandEncoder`, passing all the
458
+ /// live `CommandBuffers` built from it. All the `CommandBuffer`s
459
+ /// are destroyed, and their resources are freed.
460
+ ///
461
+ /// # Safety
462
+ ///
463
+ /// - The `CommandEncoder` must be in the states described above to
464
+ /// make the given calls.
465
+ ///
466
+ /// - A `CommandBuffer` that has been submitted for execution on the
467
+ /// GPU must live until its execution is complete.
468
+ ///
469
+ /// - A `CommandBuffer` must not outlive the `CommandEncoder` that
470
+ /// built it.
471
+ ///
472
+ /// - A `CommandEncoder` must not outlive its `Device`.
436
473
pub trait CommandEncoder < A : Api > : WasmNotSendSync + fmt:: Debug {
437
474
/// Begin encoding a new command buffer.
475
+ ///
476
+ /// This puts this `CommandEncoder` in the "recording" state.
477
+ ///
478
+ /// # Safety
479
+ ///
480
+ /// This `CommandEncoder` must be in the "closed" state.
438
481
unsafe fn begin_encoding ( & mut self , label : Label ) -> Result < ( ) , DeviceError > ;
439
- /// Discard currently recorded list, if any.
482
+
483
+ /// Discard the command list under construction, if any.
484
+ ///
485
+ /// This puts this `CommandEncoder` in the "closed" state.
486
+ ///
487
+ /// # Safety
488
+ ///
489
+ /// This `CommandEncoder` must be in the "recording" state.
440
490
unsafe fn discard_encoding ( & mut self ) ;
491
+
492
+ /// Return a fresh [`CommandBuffer`] holding the recorded commands.
493
+ ///
494
+ /// The returned [`CommandBuffer`] holds all the commands recorded
495
+ /// on this `CommandEncoder` since the last call to
496
+ /// [`begin_encoding`].
497
+ ///
498
+ /// This puts this `CommandEncoder` in the "closed" state.
499
+ ///
500
+ /// # Safety
501
+ ///
502
+ /// This `CommandEncoder` must be in the "recording" state.
503
+ ///
504
+ /// The returned [`CommandBuffer`] must not outlive this
505
+ /// `CommandEncoder`. Implementations are allowed to build
506
+ /// `CommandBuffer`s that depend on storage owned by this
507
+ /// `CommandEncoder`.
508
+ ///
509
+ /// [`CommandBuffer`]: Api::CommandBuffer
510
+ /// [`begin_encoding`]: CommandEncoder::begin_encoding
441
511
unsafe fn end_encoding ( & mut self ) -> Result < A :: CommandBuffer , DeviceError > ;
442
- /// Reclaims all resources that are allocated for this encoder.
443
- /// Must get all of the produced command buffers back,
444
- /// and they must not be used by GPU at this moment.
512
+
513
+ /// Reclaim all resources belonging to this `CommandEncoder`.
514
+ ///
515
+ /// # Safety
516
+ ///
517
+ /// This `CommandEncoder` must be in the "closed" state.
518
+ ///
519
+ /// The `command_buffers` iterator must produce all the live
520
+ /// [`CommandBuffer`]s built using this `CommandEncoder` --- that
521
+ /// is, every extant `CommandBuffer` returned from `end_encoding`.
522
+ ///
523
+ /// [`CommandBuffer`]: Api::CommandBuffer
445
524
unsafe fn reset_all < I > ( & mut self , command_buffers : I )
446
525
where
447
526
I : Iterator < Item = A :: CommandBuffer > ;
0 commit comments