Skip to main content

IntGraph

Struct IntGraph 

Source
pub struct IntGraph { /* private fields */ }
Expand description

Integer expression graph with structural interning.

Implementations§

Source§

impl IntGraph

Source

pub fn to_wgsl_body( &self, outputs: &[IId], params: &[&str], dests: &[&str], depth: usize, ) -> String

WGSL statements computing outputs: param i reads the expression params[i], output k is assigned to dests[k]. Needs WGSL_PRELUDE in the module when the graph uses MulHi; buffers are referenced by their declared names.

Source

pub fn to_wgsl_body_guarded( &self, outputs: &[IId], params: &[&str], dests: &[&str], depth: usize, ) -> String

Self::to_wgsl_body with every load bounds-checked against arrayLength (out of bounds reads 0, as in Program). For untrusted graphs; buffers must be runtime-sized storage arrays.

Source

pub fn to_wgsl_fn(&self, name: &str, outputs: &[IId]) -> String

A WGSL function fn name(p0: T0, …) -> name_out returning a struct of the outputs (o0, o1, …).

Source

pub fn to_rust(&self, name: &str, outputs: &[IId]) -> String

A Rust function fn name(p0: T0, …, buf: &[u32], …) -> [T; N] (or a tuple when the output types differ); buffers take u32 words (8-bit elements packed little endian).

Source§

impl IntGraph

Source

pub fn eval(&self, outputs: &[IId], params: &[u32], bufs: &[&[u32]]) -> Vec<u32>

Evaluate outputs once (compiles a Program; reuse one for speed).

Source§

impl IntGraph

Source

pub fn to_bytes(&self, outputs: &[IId]) -> Vec<u8> ⓘ

Serialize the whole graph with outputs (see the module docs). Buffers are not named on the wire; the reader supplies the ABI.

Source

pub fn from_bytes( bytes: &[u8], params: &[IType], bufs: &[(&str, Elem)], outs: &[IType], lim: &Limits, ) -> Result<(IntGraph, Vec<IId>), WireError>

Read and verify an untrusted graph (see the module docs). params gives the type of each parameter, bufs the name and element type of each buffer, outs the output types. Returns the graph and its outputs.

Source

pub fn from_bytes_rw( bytes: &[u8], params: &[IType], bufs: &[(&str, Elem)], rw: &[(&str, Elem, u32, &str)], outs: &[IType], lim: &Limits, ) -> Result<(IntGraph, Vec<IId>), WireError>

Self::from_bytes with scratch buffers after the read-only ones: (name, elem, length, WGSL base expression) each, all from the caller.

Source§

impl IntGraph

Source

pub fn new() -> Self

Empty graph.

Source

pub fn len(&self) -> usize

Number of nodes.

Source

pub fn is_empty(&self) -> bool

Whether the graph has no nodes.

Source

pub fn node(&self, id: IId) -> INode

Node of id.

Source

pub fn ty(&self, id: IId) -> IType

Type of id.

Source

pub fn loop_(&self, l: u32) -> &Loop

Loop l.

Source

pub fn buffers(&self) -> &[Buffer]

Declared buffers.

Source

pub fn i32(&mut self, v: i32) -> IId

i32 constant.

Source

pub fn u32(&mut self, v: u32) -> IId

u32 constant.

Source

pub fn bool(&mut self, v: bool) -> IId

bool constant.

Source

pub fn param(&mut self, i: u16, t: IType) -> IId

Function input i of type t.

Source

pub fn buffer(&mut self, name: &str, elem: Elem) -> u16

Declare a read-only buffer; returns its index for load.

Source

pub fn buffer_rw(&mut self, name: &str, elem: Elem, len: u32, base: &str) -> u16

Declare a scratch buffer of len 32-bit elements (elem is I32 or U32), at name[base + i] in WGSL.

Source

pub fn token(&mut self) -> IId

The initial effect token.

Source

pub fn load_rw(&mut self, buf: u16, index: IId, tok: IId) -> IId

buf[index] of a scratch buffer as of effect token tok.

Source

pub fn store(&mut self, buf: u16, index: IId, value: IId, tok: IId) -> IId

buf[index] = value after tok; returns the next token.

Source

pub fn load(&mut self, buf: u16, index: IId) -> IId

buf[index], widened per Elem.

Source

pub fn bin(&mut self, op: BinOp, a: IId, b: IId) -> IId

Binary op.

Source

pub fn add(&mut self, a: IId, b: IId) -> IId

Wrapping a + b.

Source

pub fn sub(&mut self, a: IId, b: IId) -> IId

Wrapping a − b.

Source

pub fn mul(&mut self, a: IId, b: IId) -> IId

Wrapping a × b.

Source

pub fn mul_wide(&mut self, a: IId, b: IId) -> (IId, IId)

Exact 64-bit product as (lo, hi).

Source

pub fn and(&mut self, a: IId, b: IId) -> IId

a & b.

Source

pub fn or(&mut self, a: IId, b: IId) -> IId

a | b.

Source

pub fn xor(&mut self, a: IId, b: IId) -> IId

a ^ b.

Source

pub fn shl(&mut self, a: IId, b: IId) -> IId

a << (b mod 32).

Source

pub fn shr(&mut self, a: IId, b: IId) -> IId

a >> (b mod 32), arithmetic for i32.

Source

pub fn min(&mut self, a: IId, b: IId) -> IId

min(a, b).

Source

pub fn max(&mut self, a: IId, b: IId) -> IId

max(a, b).

Source

pub fn clamp(&mut self, x: IId, lo: IId, hi: IId) -> IId

min(max(x, lo), hi).

Source

pub fn neg(&mut self, a: IId) -> IId

Wrapping −a.

Source

pub fn not(&mut self, a: IId) -> IId

!a (bitwise on integers).

Source

pub fn clz(&mut self, a: IId) -> IId

Leading zero bits of a (firstLeadingBit(a) = 31 − clz(a) for a > 0).

Source

pub fn cmp(&mut self, op: CmpOp, a: IId, b: IId) -> IId

Comparison.

Source

pub fn eq(&mut self, a: IId, b: IId) -> IId

a == b.

Source

pub fn lt(&mut self, a: IId, b: IId) -> IId

a < b.

Source

pub fn le(&mut self, a: IId, b: IId) -> IId

a <= b.

Source

pub fn select(&mut self, c: IId, a: IId, b: IId) -> IId

if c { a } else { b }.

Source

pub fn bitcast(&mut self, t: IType, a: IId) -> IId

Reinterpret as t.

Source

pub fn while_loop( &mut self, init: &[IId], body: impl FnOnce(&mut Self, &[IId]) -> (IId, Vec<IId>), ) -> Vec<IId>

s = init; while cond(s) { s = next(s) }; returns the final states.

body gets the state nodes and returns (cond, next).

Source

pub fn cap_loop(&mut self, out: IId, cap: u32)

Cap the trip count of the loop that produced out (a loop result).

Source

pub fn div(&mut self, a: IId, b: IId) -> IId

Unsigned / signed division (WGSL semantics, see BinOp::Div).

Source

pub fn rem(&mut self, a: IId, b: IId) -> IId

Remainder (WGSL semantics, see BinOp::Rem).

Source

pub fn for_range( &mut self, n: IId, init: &[IId], body: impl FnOnce(&mut Self, IId, &[IId]) -> Vec<IId>, ) -> Vec<IId>

for i in 0..n (n: u32) over states; body(g, i, s) returns next states.

Trait Implementations§

Source§

impl Clone for IntGraph

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for IntGraph

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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.