Struct naga::back::spv::selection::Selection

source ·
pub(super) struct Selection<'b, M: MergeTuple> {
    block: &'b mut Block,
    merge_label: Option<Word>,
    values: Vec<(M, Word)>,
    merge_types: M,
}
Expand description

A private struct recording what we know about the selection construct so far.

Fields§

§block: &'b mut Block

The block pointer we’re emitting code into.

§merge_label: Option<Word>

The label of the selection construct’s merge block, or None if we haven’t yet written the OpSelectionMerge merge instruction.

§values: Vec<(M, Word)>

A set of (VALUES, PARENT) pairs, used to build OpPhi instructions in the merge block. Each PARENT is the label of a predecessor block of the merge block. The corresponding VALUES holds the ids of the values that PARENT contributes to the merged values.

We emit all branches to the merge block, so we know all its predecessors. And we refuse to emit a branch unless we’re given the values the branching block contributes to the merge, so we always have everything we need to emit the correct phis, by construction.

§merge_types: M

The types of the values in each element of values.

Implementations§

source§

impl<'b, M: MergeTuple> Selection<'b, M>

source

pub(super) fn start(block: &'b mut Block, merge_types: M) -> Self

Start a new selection construct.

The block argument indicates the selection’s header block.

The merge_types argument should be a Word or tuple of Words, each value being the SPIR-V result type id of an OpPhi instruction that will be written to the selection’s merge block when this selection’s finish method is called. This argument may also be (), for selections that produce no values.

(This function writes no code to block itself; it simply constructs a fresh Selection.)

source

pub(super) fn block(&mut self) -> &mut Block

source

pub(super) fn if_true( &mut self, ctx: &mut BlockContext<'_>, cond: Word, values: M, )

Branch to a successor block if cond is true, otherwise merge.

If cond is false, branch to the merge block, using values as the merged values. Otherwise, proceed to a new block.

The values argument must be the same shape as the merge_types argument passed to Selection::start.

source

pub(super) fn finish(self, ctx: &mut BlockContext<'_>, final_values: M) -> M

Emit an unconditional branch to the merge block, and compute merged values.

Use final_values as the merged values contributed by the current block, and transition to the merge block, emitting OpPhi instructions to produce the merged values. This must be the same shape as the merge_types argument passed to Selection::start.

Return the SPIR-V ids of the merged values. This value has the same shape as the merge_types argument passed to Selection::start.

source

fn make_merge_label(&mut self, ctx: &mut BlockContext<'_>) -> Word

Return the id of the merge block, writing a merge instruction if needed.

Auto Trait Implementations§

§

impl<'b, M> Freeze for Selection<'b, M>
where M: Freeze,

§

impl<'b, M> RefUnwindSafe for Selection<'b, M>
where M: RefUnwindSafe,

§

impl<'b, M> Send for Selection<'b, M>
where M: Send,

§

impl<'b, M> Sync for Selection<'b, M>
where M: Sync,

§

impl<'b, M> Unpin for Selection<'b, M>
where M: Unpin,

§

impl<'b, M> !UnwindSafe for Selection<'b, M>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.