A texture you draw into, such as an or a depth buffer, has only its first level. Sampling it small needs the smaller levels averaged from it, and an occlusion test needs each level to keep the farthest depth under it, so one answers for a whole block of the screen. mipmaps.create fills the levels from your 'use gpu' function of each 2×2 block, in the encoder or compute pass of your .
A depth texture's mip levels, each texel combining a 2×2 block of the level before
combine
Try Tap a texel, or use the arrow keys, to light the 2×2 block it combines and what that block covers in the levels before. Then switch to mean, which blurs the box and the pole into what is behind them. largest keeps each block's farthest depth, so the pole is gone by level 1 and the box by level 2.
Creates what fills a texture's mip levels, every array layer of each, from the level above. A
level of odd size leaves the last texels of the one above out.
@owns ― a pipeline, a bind group per level: the kernel or the draw that fills a level, and the
views each level reads and writes
@records ― record after whatever writes level 0 or source, before what reads the levels
@param ― texture a 2D float colour texture with storage or render usage, and sampled usage
@returns ― mipmaps that record into the texture
create(
constroot:TgpuRoot
root,
constfarthest:TgpuTexture<{
size:[1024,512];
format:"r32float";
mipLevelCount:11;
}>&SampledFlag&StorageFlag
farthest,{
Options.combine: mipmaps.Combine
Combines a 2×2 block of the level above into one texel.
@gpu
combine:
import mipmaps
mipmaps.
constlargest:mipmaps.Combine
Keeps the largest of the four per channel, such as the farthest depth over a block.
Fills level 0 from this texture's 2×2 blocks too, such as the depth a pyramid of farthest
depths starts from. It has as many array layers, and blocks past its edge repeat its last
texels. Default leaving level 0 to you.
Records a frame into one encoder and submits once, with a clock. Borrows the root. The
synchronous recorder borrows each frame's encoder.
@submits ― always once a frame after your recorder returns, and again at each frame.submit()
@param ― record your frame, recorded into each frame's encoder
@returns ― a loop you run with each frame's time and destroy
create(
constroot:TgpuRoot
root,(
frame:frames.Frame
frame)=>{
// ... the depth prepass
const
constcompute:TgpuComputePass
compute=
frame:frames.Frame
frame.
Frame.encoder: TgpuCommandEncoder
Records commands for submission after the recorder returns. submit() replaces this encoder.
Read it at each call instead of keeping it, and let the frame submit it.
Records the levels in order. A texture with storage usage fills in a compute pass, the
pass given or one of its own on the encoder. Another fills in render passes on the encoder.
Level 0 is yours to draw or write, and record fills level 1 and on from it. With source, record fills level 0 too, from that texture’s blocks. A source larger than two texels per texel of level 0 leaves its far part out; one smaller repeats its last row and column.
Levels fill as a baker’s texture does: one per level for a texture with storage usage, and otherwise a render pass per level and array layer, such as for the rgba8unorm-srgb atlas of impostors. Both fill every array layer of a level.
create makes a per level of its texture. of(texture, source) fills another texture of the same format and usage through the same pipeline, with bind groups of its own, such as the other texture of a pair. For a target that a resize replaces, call of through memo with the current texture, so a resize makes bind groups and no pipeline.
The texture and source are single-sampled 2D textures with sampled usage that hold floats, and source has the texture’s array layers. A depth source reads its depth. create and of throw on another, naming the property.
A level of odd size leaves the last row or column of the level above out. Size the texture in powers of two for blocks that cover every texel.
atlasAn atlas is one texture that holds many small pictures side by side, such as every glyph of a font or every view of a model.Words →
texelA texel is one cell of a texture, as a pixel is one cell of the screen.Words →
frameA frame is one turn of the loop, and the object your function gets for it, which holds the encoder, the time and the time since the last frame.You own the frame →
moduleA module is one piece of GPU work, made by a factory that borrows your root and returns resources, shader functions and methods that record into your frame.A module borrows →
dispatchA dispatch runs a kernel once over a number of threads, inside a compute pass.Words →
bind groupA bind group is a set of buffers, textures and samplers that a pipeline reads, and a pipeline has room for four.Words →
Returns mipmaps of another texture of this one's format and usage, filled through the same pipeline from its own source or level 0, with their bind groups made now: the other texture of a pair, or the one a resize puts in this one's place.