Skip to main content

PageDesc

Struct PageDesc 

Source
pub struct PageDesc<'a> { /* private fields */ }
Expand description

§3.2’s texture side: one D2Array image per PageKind, whose layers a material row selects with that kind’s own texture column.

One image with a layer per texture rather than an array of descriptors — ArrayPages rather than Bindless — because a layer index needs nothing of a device where a descriptor array needs DESCRIPTOR_INDEXING, which crcbl-mtl withdraws.

§A table over the kinds, each with an extent of its own

set_extent sizes one kind and push_layer appends into it, so a 512² normal page beside a 2048² base-colour page is two calls rather than a resample of one onto the other’s size. A kind nothing names is left alone: it holds no layers, extent reports zero for it, and the renderer creates a single placeholder texel in its place rather than an extent² image nobody samples.

§Layer 0 is an ordinary layer, and where its old invariant went

Until topic 43 §2’s row (d) this type burned layer 0 on both pages — an all-white texel on the base-colour page, the neutral normal on the other — because NO_PAGE was zero and a material naming no texture sampled it. Two arms of check existed to hold that: layer 0 is white, layer 0 is neutral.

NO_PAGE is 0xFFFF now and mesh.slang tests it, so the neutral value is a literal in the fragment stage rather than a texel in an image, and both arms are gone with the layers they guarded. That is a trade, and it is worth writing down which way it runs. What it bought: a page nothing names costs one texel rather than extent² × 4 bytes and a third again for its chain, on every scene in the tree; a producer numbers its layers from zero like any other array; and the two pages stopped having to be one size. What it sold: the invariant is no longer checkable on the host at all. A fragment that read a page for a row carrying NO_PAGE used to find white and draw the right frame anyway, and now it finds whatever the placeholder holds — which nothing but a picture can report. So crate::forward’s PAGE_PLACEHOLDER_TEXEL is magenta rather than white or black: the mistake this type used to absorb silently is one a golden now shows loudly.

Implementations§

Source§

impl<'a> PageDesc<'a>

Source

pub const WHITE: u8 = 0xFF

The texel an all-white base-colour layer is filled with.

The page is Rgba8UnormSrgb and 0xFF is the one value that encoding leaves alone, so the sampler returns exactly 1.0 — the same product a material was shaded by before there was a page at all.

Nothing needs such a layer any more. A material naming no texture carries mesh::GpuMaterial::NO_PAGE, which is out of band, and the fragment stage multiplies by the literal 1.0 instead of by this. The constant stays for the callers that want a white layer deliberately — crcbl/tests/mesh_e2e/base_color_page.rs is the one that measured, on a device, that the two routes shade a surface to the same bits, and crcbl/src/screenshot.rs’s alpha mask keeps this RGB under a cut alpha.

Source

pub const NEUTRAL_NORMAL: [u8; 4]

The neutral tangent-space normal texel: (0.5, 0.5, 1.0) in RGBA8, which is topic 43 §2’s neutral normal.

§It is not exactly flat, and the shader is what makes “no map” exact

An eight-bit unorm channel has no 0.5: 0x80 decodes to 128 / 255, and t * 2 - 1 turns that into 1 / 255 rather than zero — a tangent space normal about a fifth of a degree off vertical. That is small and it is not nothing, and this engine compares its goldens across four backends with no tolerance, so a material sampling this texel and perturbing by it would move every frame in the tree that draws a lit surface. mesh.slang’s shading_normal_of therefore tests the layer index against mesh::GpuMaterial::NO_PAGE and returns the surface normal untouched; crcbl_shaders::mesh::a_neutral_normal_texel_is_not_exactly_flat measures the error this constant would otherwise introduce.

So what a layer of this is for is the material that names it explicitly and the read that runs off the end of an authored layer’s edge — a neutral texel is what those must find, rather than the (0, 0, 0) an unwritten image holds, which decodes to a normal pointing straight backwards.

Source

pub fn empty() -> Self

A description that names no page at all: every kind empty, and nothing but one placeholder texel apiece allocated on the device.

A caller adds a page by sizing it with set_extent and pushing layers into it with push_layer. A scene whose every material row carries NO_PAGE — apps/alcove and apps/sundial are both such scenes — stops here.

Source

pub fn set_extent(&mut self, kind: PageKind, extent: u32)

Sizes kind’s page: texels a side, square.

Every layer of that kind is then exactly extent² × 4 bytes, which check is what enforces. The kinds are separate device images and each carries its own number, so sizing one says nothing about the other.

§Panics

If extent is zero, which is an image no device will create, or if kind already holds a layer — those layers were authored against the extent that was in force when they were pushed, and moving it under them would refuse every one of them at check with a byte count nobody wrote.

Source

pub fn push_layer( &mut self, kind: PageKind, texels: impl Into<Cow<'a, [u8]>>, ) -> u32

Appends a layer to kind and returns its index — the number the material row’s own texture column carries.

texels is RGBA8, row-major, and exactly extent² × 4 bytes, which ForwardRenderer::with_scene checks before it uploads anything. What the bytes mean is the kind’s, and the four differ: a BaseColor layer and an Emissive one are sRGB-encoded, because both are colours and that is what glTF defines those two textures to be, and the renderer creates their images as Rgba8UnormSrgb so the sampler decodes them; a Normal layer and a MetallicRoughnessOcclusion one are linear numbers — a tangent-space normal encoded as n * 0.5 + 0.5 per channel, and glTF’s packed occlusion, roughness and metallic in r, g and b — and their images are Rgba8Unorm so nothing decodes them at all. See each kind’s own arm of PageKind::format and topic 44’s rung 2.

§Panics

If kind has no extent yet: a layer’s length is only meaningful against one, so set_extent comes first.

Source

pub const fn extent(&self, kind: PageKind) -> u32

kind’s texels a side, or zero when nothing has named that page.

Source

pub fn layers(&self, kind: PageKind) -> &[Cow<'a, [u8]>]

Every layer of kind, in order: element n is layer n.

Trait Implementations§

Source§

impl<'a> Clone for PageDesc<'a>

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<'a> Debug for PageDesc<'a>

Source§

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

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

impl<'a> Default for PageDesc<'a>

Source§

fn default() -> Self

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

impl<'a> Eq for PageDesc<'a>

Source§

impl<'a> PartialEq for PageDesc<'a>

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<'a> StructuralPartialEq for PageDesc<'a>

Auto Trait Implementations§

§

impl<'a> Forget for PageDesc<'a>

§

impl<'a> Freeze for PageDesc<'a>

§

impl<'a> Move for PageDesc<'a>

§

impl<'a> RefUnwindSafe for PageDesc<'a>

§

impl<'a> Send for PageDesc<'a>

§

impl<'a> Sync for PageDesc<'a>

§

impl<'a> Unpin for PageDesc<'a>

§

impl<'a> UnsafeUnpin for PageDesc<'a>

§

impl<'a> UnwindSafe for PageDesc<'a>

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> 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> 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.