Draw each primitive with its own pipeline, registered rather than declared
The `primitives!` macro, `PrimitiveData`, `PrimitiveVec`, `PrimitiveBuffers`, the `Primitive` trait and the shader's dispatch switch are gone. A primitive is now a registration: its WGSL and, implicitly, the size of the entry that WGSL reads. Everything else -- its instance list, its free list, its buffers, its bind group and its pipeline -- follows from that, so adding one is a `register` call and a shader file, with nothing per-type to remember and no cross-type dispatch to extend. Nothing dispatches dynamically. Push, free, renumber, upload and draw are identical for every primitive; what differs is the entry size and the pipeline, which are data. So `InstanceList` carries a runtime stride and its instances' data as bytes, and one concrete type serves every primitive and the textures. Measured against a typed list it costs 0.2ns per write, where a trait object costs 1.6ns. Because each type has its own list, an instance's index is also its data index: `@builtin(instance_index)` replaces the `idx` field, the `binding` field goes with the switch, and `PrimitiveInstance` drops from 28 bytes to 20. `PrimitiveVec`'s free list merges into the instance list's, so an instance and its data are freed by one `swap_remove` rather than two arenas kept in step. `shader.wgsl` becomes `shader/prelude.wgsl` plus one file per primitive. The prelude carries the window, masks, sampled texture, vertex shader and `masked()`, and is compiled ahead of each primitive's own source -- which is also what a caller's own primitive would be. Masks move back into group 0 beside the window uniform, since every pipeline shares one layout. Within a layer, types now draw in registration order: a rect under a glyph under a texture. Order within a layer was never meaningful -- freeing an instance swaps another into its place -- so this replaces an accident with a defined order, and backgrounds land under their content. Verified with a headless run per case: text over its own rect and an image over its own rect in one layer, a masked stack clipping, the text-layout tab, and adding three images and deleting one.
This commit is contained in:
1 parent
b3d3da5dab
commit
4d9839f380
15 files changed
+614
-620
No files matched your search
@@ -245,7 +245,7 @@ impl UiRenderState {
|
||||
pub fn debug_layers(&self) {
|
||||
for ((idx, depth), draws) in self.layers.iter_depth() {
|
||||
let indent = " ".repeat(depth * 2);
|
||||
let primitives = draws.primitives.instances().len();
|
||||
let primitives: usize = draws.primitives().iter().map(|l| l.instances().len()).sum();
|
||||
let textures = draws.textures.instances().len();
|
||||
println!("{indent}{idx}: {primitives} primitives, {textures} textures");
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user