#[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
impl Clone for SpriteInstance
impl Copy for SpriteInstance
Source§impl Debug for SpriteInstance
impl Debug for SpriteInstance
Source§impl Default for SpriteInstance
impl Default for SpriteInstance
Source§impl PartialEq for SpriteInstance
impl PartialEq for SpriteInstance
impl Pod for SpriteInstance
impl StructuralPartialEq for SpriteInstance
Auto Trait Implementations§
impl Freeze for SpriteInstance
impl RefUnwindSafe for SpriteInstance
impl Send for SpriteInstance
impl Sync for SpriteInstance
impl Unpin for SpriteInstance
impl UnsafeUnpin for SpriteInstance
impl UnwindSafe for SpriteInstance
Blanket Implementations§
impl<T> AnyBitPattern for Twhere
T: Pod,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CheckedBitPattern for Twhere
T: AnyBitPattern,
impl<T> CheckedBitPattern for Twhere
T: AnyBitPattern,
Source§type Bits = T
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
fn is_valid_bit_pattern(_bits: &T) -> bool
bits
as &Self.