StructureID separate from chunk 'anchor'

This commit is contained in:
2026-11-09 11:44:13 +01:00
parent e855ccd904
commit b6f4a9c432
19 changed files with 944 additions and 136 deletions
+53 -26
View File
@@ -68,14 +68,19 @@ For `N = 4`, a pointer page is `8 + 64*4 = 264` bytes.
```rust
struct LocationPage {
structure_id: u32, // which structure (world chunk, etc.)
structure_id: u32, // stable tree identity
node_id: u32, // application-defined locator within that structure
producer_id: u32, // producer that owns the node
anchor: StructureAnchor, // opaque, table-defined content identity
}
```
The cache never interprets these values; they are copied from insertion data and
returned in requests so the producer knows which node is missing. In the demo,
`node_id` is an `NTreeNodeLocator` and `structure_id` is a toroidal table slot.
`node_id` is an `NTreeNodeLocator`, `structure_id` is a stable per-producer tree
id, and `anchor` is the toroidal table's world position plus a version word.
Child requests inherit the anchor from their parent page, so producers never need
a host-side `StructureId -> anchor` directory. `LocationPage` is 28 bytes.
### 2.3 Depth page
@@ -266,10 +271,12 @@ pub trait CacheInvalidable<const N: usize> {
```
`validate_insertion` runs before page allocation: the table checks that each
external root's slot is still `subdividable, unavailable` and compacts the valid
entries. This prevents a stale root response from consuming a page, and lets a
slot be reused (toroidal move) without accepting a response for its old world
position.
external root's named slot still carries the same `anchor` and `structure_id`
and is still `subdividable, unavailable`, then compacts the valid entries. This
prevents a stale root response from consuming a page, and lets a slot be reused
(toroidal move) without accepting a response for its old world position. The
anchor/id check is what makes host queue invalidation a cancellation hint rather
than a correctness requirement.
### 4.3 Insertion data
@@ -306,9 +313,18 @@ struct InsertionParent {
structure_id: u32, // structure the parent belongs to
node_id: u32, // locator of the parent (0 for an external root)
producer_id: u32, // producer that owns the parent
anchor: StructureAnchor, // content identity of the structure
table_slot: u32, // external root placement, 0xFFFFFFFF internally
}
```
For an internal insertion, validation requires the parent page's
`LocationPage` to match `structure_id`, `node_id`, `producer_id`, and `anchor`.
For an external insertion, validation requires the slot indexed by `table_slot`
to currently hold the parent's `structure_id` and `anchor`. `write_pointers.wgsl`
repeats the internal check before linking, and the table insertion pass repeats
the external check after page allocation.
A batch no longer has to be ordered like the request buffer. The host may
reorder, filter, or produce entries on different frames; the GPU validates each
entry independently.
@@ -370,11 +386,13 @@ flowchart LR
```rust
struct RequestInformation {
structure_id: u32, // from LocationPage
structure_id: u32, // from LocationPage (stable tree identity)
node_id: u32, // from LocationPage (the parent node)
children_index: u32, // requested child
producer_id: u32, // from LocationPage
demand: u32, // request counter for this slot this frame
anchor: StructureAnchor, // from LocationPage (content identity)
table_slot: u32, // 0xFFFFFFFF internally; external root placement
}
struct RequestMeta {
@@ -386,7 +404,8 @@ struct RequestMeta {
`producer_id` lets a cache mix several producers and lets the host queue route
requests without guessing. `demand` is the raw request counter; the queue uses it
as the primary priority key.
as the primary priority key. `anchor` lets producers stay stateless and lets the
queue key roots by content identity instead of table placement.
The external-root marker is `RequestMeta.page_index == 0xFFFFFFFF`, **not**
`node_id == 0`. Both an external root and child 0 of the root carry
@@ -412,20 +431,22 @@ The callback is asynchronous by API, but the demo blocks on it with a
For an **internal** request:
- `structure_id` and `node_id` identify the **parent** node.
- `structure_id`, `node_id`, and `anchor` identify the **parent** node.
- `children_index` identifies which child is missing.
- The producer must generate that child node and emit a `LocationPage` for the
child (typically `parent_locator.child(x, y, z)`).
child (typically `parent_locator.child(x, y, z)`) with the same anchor.
- It must also emit an internal `InsertionParent` carrying the parent page,
child index, depth, and parent identity.
child index, depth, parent identity, and anchor.
For an **external** (structure-table) request:
- `structure_id` is the table slot.
- `structure_id` is the stable tree id and `anchor` is the table-defined content
identity; `table_slot` is where the table currently points.
- `node_id` and `children_index` are 0, and `RequestMeta.page_index` is
`0xFFFFFFFF`.
- The producer must generate a chunk root and emit its `LocationPage` plus an
external `InsertionParent`.
external `InsertionParent` with `structure_id`, `producer_id`, `anchor`, and
`table_slot`.
There is no output-order requirement. Each insertion is attached to its parent
by its own `InsertionParent`.
@@ -467,10 +488,12 @@ first, with deeper pages first among equal timestamps. See §7.
Before any page is allocated, each batch is validated:
- **Internal** (`insertion.wgsl`, `validate_internal`): the parent page must
still have the same `structure_id`, `node_id`, `producer_id`, and depth, and
the requested child pointer must still be `subdividable, unavailable`.
- **External** (`fixed_table/validate_insertion.wgsl`): the table slot must still
be `subdividable, unavailable`.
still have the same `structure_id`, `node_id`, `producer_id`, anchor, and
depth, and the requested child pointer must still be `subdividable,
unavailable`.
- **External** (`fixed_table/validate_insertion.wgsl`): the named table slot
must still carry the same `structure_id` and `anchor`, and must still be
`subdividable, unavailable`.
Valid entries are compacted into `valid_indices` and counted in `valid_count`.
The validation pass resets every `destination_indices` entry to `0xFFFFFFFF`,
@@ -610,15 +633,19 @@ The table is dense: allocation is `slot_count * 4` bytes for pointers plus
- `extent = (x, y, z)` chunk counts.
- Slot index from local coordinates:
`x + z*extent.x + y*extent.x*extent.z` (shader) — note the y/z order.
- `move_position` computes a new integer offset around the camera and runs
`terrain/shaders/toroidal_structure.wgsl`: any slot whose world position
changed is reset to `subdividable, unavailable`, so it will be re-requested.
It also returns the list of changed slot ids on the CPU. The host must feed
that list to the request queue (`invalidate_structure`) before batching
insertions, otherwise a response produced for the slot's old position could
be accepted after the toroidal move.
- `get_request_position(structure_id)` maps a slot back to an absolute chunk
coordinate using the current offset and `rem_euclid`.
- `move_position(queue, encoder, position)` computes a new integer offset,
reassigns every slot's anchor through `FixedStructureTable::reassign_slots`,
and runs `terrain/shaders/toroidal_structure.wgsl`: any slot whose world
position changed is reset to `subdividable, unavailable`, so it will be
re-requested.
- Slot identity is preserved across the move: anchors that stay in view keep
their `StructureId` even if they change slot, anchors that enter get fresh
monotonic ids, and anchors that leave retire their id (never reused).
`reassign_slots` returns the retired ids so the host can cancel speculative
queue work; correctness does not depend on it because the GPU validates
`anchor`/`structure_id`/slot before linking a root.
- `position_for_anchor(anchor)` decodes a table anchor back to an absolute
chunk coordinate.
- Everything else delegates to the fixed table.
The Slang module `toroidal_structure_table.slang` mirrors this indexing and walks