rendy_command/buffer/
usage.rs

1use super::SecondaryLevel;
2
3/// Command buffer with this usage flag will move to invalid state after execution.
4/// Resubmitting will require reset and rerecording commands.
5#[derive(Clone, Copy, Debug, Default)]
6pub struct OneShot;
7
8/// Command buffer with this usage flag will move back to executable state after execution.
9#[derive(Clone, Copy, Debug, Default)]
10pub struct MultiShot<S = NoSimultaneousUse>(pub S);
11
12/// Additional flag that allows resubmission of a command buffer while it is still in a pending state.
13/// `Submit<B, SimultaneousUse>` can be submitted more than once.
14#[derive(Clone, Copy, Debug, Default)]
15pub struct SimultaneousUse;
16
17/// Additional flag that disallows resubmission of a command buffer while it is still in a pending state
18/// It must be completed, i.e. a fence must submitted with this buffer or later into the same queue
19/// and be waited on before buffer resubmission.
20/// `Submit<B, NoSimultaneousUse>` cannot be submitted more than once.
21#[derive(Clone, Copy, Debug, Default)]
22pub struct NoSimultaneousUse;
23
24/// Buffers with this usage flag must be secondary buffers executed entirely in render-pass.
25#[derive(Clone, Copy, Debug, Default)]
26pub struct RenderPassContinue;
27
28/// Primary buffers must has this flag as they cannot has `RenderPassContinue` flag.
29/// Secondary buffers with this usage flag cannot be executed as part of render-pass.
30#[derive(Clone, Copy, Debug, Default)]
31pub struct OutsideRenderPass;
32
33/// Type-level usage flags.
34/// It defines if buffer can be resubmitted without reset.
35/// Or even resubmitted while being executed.
36pub trait Usage: Copy + Default + std::fmt::Debug + 'static {
37    /// Flags required to begin command buffer.
38    fn flags(&self) -> rendy_core::hal::command::CommandBufferFlags;
39}
40
41impl Usage for OneShot {
42    fn flags(&self) -> rendy_core::hal::command::CommandBufferFlags {
43        rendy_core::hal::command::CommandBufferFlags::ONE_TIME_SUBMIT
44    }
45}
46
47impl Usage for MultiShot {
48    fn flags(&self) -> rendy_core::hal::command::CommandBufferFlags {
49        rendy_core::hal::command::CommandBufferFlags::empty()
50    }
51}
52
53impl Usage for MultiShot<SimultaneousUse> {
54    fn flags(&self) -> rendy_core::hal::command::CommandBufferFlags {
55        rendy_core::hal::command::CommandBufferFlags::SIMULTANEOUS_USE
56    }
57}
58
59impl Usage for NoSimultaneousUse {
60    fn flags(&self) -> rendy_core::hal::command::CommandBufferFlags {
61        rendy_core::hal::command::CommandBufferFlags::empty()
62    }
63}
64
65/// Trait implemented for type-level render pass relation flags.
66/// `RenderPassContinue` and `OutsideRenderPass`.
67pub trait RenderPassRelation<L>: Copy + Default + std::fmt::Debug + 'static {
68    /// Flags required to begin command buffer.
69    fn flags(&self) -> rendy_core::hal::command::CommandBufferFlags;
70}
71
72impl RenderPassRelation<SecondaryLevel> for RenderPassContinue {
73    fn flags(&self) -> rendy_core::hal::command::CommandBufferFlags {
74        rendy_core::hal::command::CommandBufferFlags::RENDER_PASS_CONTINUE
75    }
76}
77
78impl<L> RenderPassRelation<L> for OutsideRenderPass {
79    fn flags(&self) -> rendy_core::hal::command::CommandBufferFlags {
80        rendy_core::hal::command::CommandBufferFlags::empty()
81    }
82}