Skip to main content

SpriteInstance

Struct SpriteInstance 

Source
#[repr(C)]
pub struct SpriteInstance { pub rect: [f32; 4], pub uv: [f32; 4], pub tint: [f32; 4], pub sheet: [f32; 4], }
Expand description

One sprite, in the byte layout struct SpriteInstance in crates/crcbl-shaders/shaders/sprite.slang declares.

Four [f32; 4]s: 64 bytes, no padding under any layout rule, and every element of the array 16-byte aligned because 64 is a multiple of 16. A [f32; 2] pair here would acquire alignment padding in the shader that this side would have to reproduce exactly, which is a layout that drifts silently.

Public because it is an ABI, and an ABI with one private spelling is an ABI nobody can check.

Fields§

§rect: [f32; 4]

World-space rectangle: [x, y, w, h] with x, y the minimum corner. Y is up.

§uv: [f32; 4]

Normalised sheet UVs: [u0, v0, u1, v1] with u0, v0 the top-left corner, in image order.

§tint: [f32; 4]

Straight-alpha RGBA multiplied into the sampled texel.

§sheet: [f32; 4]

The sheet’s texel size, its sample mode, and this sprite’s rotation: [width, height, mode, radians].

The first three are sheet_lane’s packing; the fourth is Sprite::rotation, stamped on by Sprite::instance because it is the one component of this lane that belongs to the sprite rather than to the sheet.

The size and the mode are properties of the sheet, and they travel per sprite anyway. The shader cannot get them anywhere else: set 1 binds one image and one sampler, and a shader has no way to ask a SamplerState which filter it was created with. See sprite.slang’s SpriteInstance::sheet for the alternatives that were not taken — a third descriptor set, or a second pipeline — and why sixteen bytes on a buffer that is written per frame anyway is the cheaper one.

The fourth component was padding. sprite.slang read sheet.z for the mode and handed sheet.xyz to the fragment stage, and nothing — neither the Slang source, nor the compiled WGSL, nor the compiled SPIR-V, where the only two uses of the loaded lane are a CompositeExtract … 2 and a VectorShuffle … 0 1 2 — ever touched w. So the angle cost no bytes: the instance is still four float4s and still INSTANCE_STRIDE 64.

Trait Implementations§

Source§

impl Clone for SpriteInstance

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 Copy for SpriteInstance

Source§

impl Debug for SpriteInstance

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SpriteInstance

Source§

fn default() -> Self

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

impl PartialEq for SpriteInstance

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Pod for SpriteInstance

Source§

impl StructuralPartialEq for SpriteInstance

Source§

impl Zeroable for SpriteInstance

Source§

fn zeroed() -> Self

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> AnyBitPattern for T
where T: Pod,

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> CheckedBitPattern for T
where T: AnyBitPattern,

Source§

type Bits = T

Self must have the same layout as the specified Bits except for the possible invalid bit patterns being checked during is_valid_bit_pattern.
Source§

fn is_valid_bit_pattern(_bits: &T) -> bool

If this function returns true, then it must be valid to reinterpret bits as &Self.
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> HalThreadSafe for T
where T: Send + Sync,

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> NoUninit for T
where T: Pod,

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.