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>
impl<'a> PageDesc<'a>
Sourcepub const WHITE: u8 = 0xFF
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.
Sourcepub const NEUTRAL_NORMAL: [u8; 4]
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.
Sourcepub fn empty() -> Self
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.
Sourcepub fn set_extent(&mut self, kind: PageKind, extent: u32)
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.
Sourcepub fn push_layer(
&mut self,
kind: PageKind,
texels: impl Into<Cow<'a, [u8]>>,
) -> u32
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.