refactor: Removing structureID, keep structure anchor as id
This commit is contained in:
@@ -29,8 +29,8 @@ sequenceDiagram
|
||||
Note over C,T: end of draw
|
||||
C->>C: top-K + gather + descending radix sort
|
||||
T->>T: top-K + gather + descending radix sort
|
||||
C-->>H: request buffer (structure_id, anchor, node_id, child, producer, demand)
|
||||
T-->>H: table request buffer (structure_id, anchor, slot, 0, producer, demand)
|
||||
C-->>H: request buffer (anchor, node_id, child, producer, demand)
|
||||
T-->>H: table request buffer (anchor, slot, 0, producer, demand)
|
||||
H->>H: queue + produce one node per request (parallel, possibly across frames)
|
||||
H->>I: upload CacheInsertionData (info, location, parent, attributes, count)
|
||||
I->>C: validate/compact, recycle pages, write pages, invalidate stale pointers
|
||||
@@ -51,19 +51,18 @@ response to frame N are first visible in frame N+1.
|
||||
|
||||
```rust
|
||||
struct RequestInformation {
|
||||
structure_id: u32, // stable tree identity (per producer)
|
||||
node_id: u32, // locator of the *parent* node
|
||||
children_index: u32, // which child is missing
|
||||
producer_id: u32, // owner of the parent node
|
||||
demand: u32, // request counter for this slot this frame
|
||||
anchor: StructureAnchor, // opaque, table-defined content identity
|
||||
table_slot: u32, // external root placement, NO_TABLE_SLOT internally
|
||||
}
|
||||
|
||||
struct RequestMeta {
|
||||
page_index: u32, // parent page (internal) or 0xFFFFFFFF (external)
|
||||
children_index: u32,
|
||||
depth: u32, // parent depth
|
||||
table_slot: u32, // external root placement, NO_TABLE_SLOT internally
|
||||
}
|
||||
```
|
||||
|
||||
@@ -71,22 +70,19 @@ struct RequestMeta {
|
||||
build the insertion's `InsertionParent` without referring back to a request
|
||||
buffer.
|
||||
- For external requests from a structure table: `RequestMeta.page_index =
|
||||
0xFFFFFFFF`, `node_id = 0`, `children_index = 0`, `structure_id` is the stable
|
||||
tree id, `anchor` is the table-defined content identity, and `table_slot` is
|
||||
the current placement.
|
||||
0xFFFFFFFF`, `node_id = 0`, `children_index = 0`, `anchor` is the table-defined
|
||||
content identity, and `RequestMeta.table_slot` is the current placement.
|
||||
- The root/child distinction must use `RequestMeta.page_index == 0xFFFFFFFF`,
|
||||
**not** `node_id == 0`: child 0 of the root also has `node_id = 0`.
|
||||
- Requests are sorted by demand (highest counter first) and capped at
|
||||
`max_requests`.
|
||||
- `producer_id` and `demand` are on the wire so the host queue can deduplicate
|
||||
and prioritise without guessing.
|
||||
- `structure_id`, `anchor`, and `table_slot` are three different things:
|
||||
- `StructureId` is stable tree identity, monotonic per producer, never reused
|
||||
for another anchor;
|
||||
- `StructureAnchor` is the table-defined content identity (for the toroidal
|
||||
table, world position plus a version word);
|
||||
- `table_slot` is table-private placement and may change while the id and
|
||||
anchor stay the same. It is deliberately not part of a request key.
|
||||
- `anchor` and `table_slot` are two different things:
|
||||
- `StructureAnchor` is the table-defined content identity and the structure
|
||||
identity (for the toroidal table, world position plus a version word);
|
||||
- `table_slot` is table-private placement and may change while the anchor
|
||||
stays the same. It is deliberately not part of a request key.
|
||||
|
||||
### 2.2 Response
|
||||
|
||||
@@ -99,7 +95,6 @@ struct InsertionInformation<N> {
|
||||
}
|
||||
|
||||
struct LocationPage {
|
||||
structure_id: u32,
|
||||
node_id: u32, // locator of the node itself
|
||||
producer_id: u32,
|
||||
anchor: StructureAnchor,
|
||||
@@ -110,7 +105,6 @@ struct InsertionParent {
|
||||
page_index: u32, // parent page, or 0xFFFFFFFF for an external root
|
||||
children_index: u32,
|
||||
depth: u32, // parent depth, or 0xFFFFFFFF
|
||||
structure_id: u32,
|
||||
node_id: u32, // parent locator (0 for an external root)
|
||||
producer_id: u32,
|
||||
anchor: StructureAnchor,
|
||||
@@ -123,11 +117,10 @@ Plus one attribute payload per entry (color and normal in the demo).
|
||||
Before allocating pages, the cache validates every entry against the current
|
||||
parent:
|
||||
|
||||
- internal: the parent page must still have the same structure id, producer,
|
||||
locator, **and anchor**, and the child slot must still be
|
||||
`subdividable, unavailable`;
|
||||
- external: the named table slot must still carry the same anchor and structure
|
||||
id, and its pointer must still be `subdividable, unavailable`.
|
||||
- internal: the parent page must still have the same producer, locator, **and
|
||||
anchor**, and the child slot must still be `subdividable, unavailable`;
|
||||
- external: the named table slot must still carry the same anchor, and its
|
||||
pointer must still be `subdividable, unavailable`.
|
||||
|
||||
Valid entries are compacted into `valid_indices`/`valid_count`; only those
|
||||
consume eviction pages. The cache fills `destination_indices[i]` with the page
|
||||
@@ -199,7 +192,7 @@ The demo's `fullfill_request` (`src/main.rs`) does:
|
||||
2. Add the playground offset `+5000` to x and z and take `abs()` of y.
|
||||
3. If `request_meta.page_index == 0xFFFFFFFF` (an external table request),
|
||||
produce the chunk root at depth 0, emit the root locator, and emit
|
||||
`InsertionParent::external(structure_id, producer_id, anchor, table_slot)`.
|
||||
`InsertionParent::external(producer_id, anchor, table_slot)`.
|
||||
4. Otherwise (an internal child request):
|
||||
- decode the parent `NTreeNodeLocator<4>` from `node_id`;
|
||||
- decode `children_index` into `(child_x, child_y, child_z)` with x fastest;
|
||||
@@ -207,8 +200,7 @@ The demo's `fullfill_request` (`src/main.rs`) does:
|
||||
- produce the child node at `parent_depth + 1` with the child's node
|
||||
coordinates;
|
||||
- emit the child locator as the new `LocationPage.node_id`;
|
||||
- emit `InsertionParent::internal(meta, structure_id, node_id, producer_id,
|
||||
anchor)`.
|
||||
- emit `InsertionParent::internal(meta, node_id, producer_id, anchor)`.
|
||||
|
||||
The root/child test must use `RequestMeta.page_index`, not `node_id`: child 0
|
||||
of the root also has `node_id = 0`.
|
||||
@@ -340,7 +332,6 @@ Defines a more ambitious interface:
|
||||
|
||||
```rust
|
||||
pub struct ProducerId(pub u32);
|
||||
pub struct StructureId(pub u32);
|
||||
pub struct StructureLocator(pub u32);
|
||||
pub use crate::voxel_cache::schema::StructureAnchor;
|
||||
|
||||
@@ -354,7 +345,6 @@ pub trait VoxelProducer<const N: usize> {
|
||||
fn produce(
|
||||
&self,
|
||||
producer_id: ProducerId,
|
||||
id: StructureId,
|
||||
anchor: StructureAnchor,
|
||||
locator: StructureLocator,
|
||||
) -> (InsertionInformation<N>, [Self::Output; N * N * N]);
|
||||
@@ -369,22 +359,21 @@ Differences from the demo interface:
|
||||
- The producer receives a `StructureLocator` rather than depth + coordinates,
|
||||
pushing locator arithmetic into the producer.
|
||||
- `anchor` is the content identity. A producer must derive world position from
|
||||
it (or from the id, which is stable) and never from a table slot.
|
||||
it and never from a table slot.
|
||||
|
||||
### 6.1.1 Identity model
|
||||
|
||||
| Concept | Meaning |
|
||||
|---|---|
|
||||
| `ProducerId` | Which producer fulfils the request. |
|
||||
| `StructureId` | Stable identity of one tree instance. Monotonic per producer, never reused for a different anchor. |
|
||||
| `StructureAnchor` | Opaque, table-defined content identity. Two live slots must never share one anchor. |
|
||||
| `StructureAnchor` | Opaque, table-defined content identity and the only structure identity. Two live slots must never share one anchor. |
|
||||
| `TableSlot` | Table-private placement. Recycled freely and never part of tree identity. |
|
||||
|
||||
Root identity is `(producer, structure_id, anchor)`; child identity adds the
|
||||
parent locator and child index. The table slot travels only as attachment
|
||||
metadata. The toroidal table reuses a `StructureId` for an anchor that stays in
|
||||
view, allocates fresh ids for anchors entering the window, and retires ids for
|
||||
anchors that leave. Retired ids are never reassigned.
|
||||
Root identity is `(producer, anchor)`; child identity adds the parent locator and
|
||||
child index. The table slot travels only as attachment metadata. The toroidal
|
||||
table keeps an anchor's identity while it stays in view and retires anchors that
|
||||
leave. An anchor must keep naming the same content if it later re-enters; bump
|
||||
its version word when content generation changes for the same coordinates.
|
||||
|
||||
### 6.2 `src/production/host_production.rs`
|
||||
|
||||
@@ -408,7 +397,6 @@ Key model:
|
||||
```rust
|
||||
RequestKey {
|
||||
producer_id,
|
||||
structure_id,
|
||||
anchor, // table-defined content identity
|
||||
target: Root | Child { parent: StructureLocator, children_index },
|
||||
}
|
||||
@@ -430,15 +418,16 @@ Properties:
|
||||
are dropped and re-emitted next frame.
|
||||
- Each job has a generation and attempt count. Completions from evicted,
|
||||
expired, retried, or invalidated jobs are discarded.
|
||||
- `table_slot` is attachment metadata, not part of the key. It is refreshed on
|
||||
every re-emission, including while a job is in flight or ready, so a produced
|
||||
root can follow its anchor to a new slot.
|
||||
- `invalidate_structure(id)`, `invalidate_producer(id)`, and
|
||||
`invalidate_anchor(anchor)` remove matching queued/in-flight/ready jobs.
|
||||
Invalidation is a cancellation/cleanup hint, **not** a correctness mechanism:
|
||||
the GPU rejects stale insertions by checking the current anchor/id/slot.
|
||||
- `table_slot` lives in `RequestMeta` as attachment metadata, not part of the
|
||||
key. Because the whole `RequestMeta` is refreshed on every re-emission,
|
||||
including while a job is in flight or ready, a produced root can follow its
|
||||
anchor to a new slot.
|
||||
- `invalidate_producer(id)` and `invalidate_anchor(anchor)` remove matching
|
||||
queued/in-flight/ready jobs. Invalidation is a cancellation/cleanup hint,
|
||||
**not** a correctness mechanism: the GPU rejects stale insertions by checking
|
||||
the current anchor/slot.
|
||||
- `ReadyItem::insertion_parent()` builds the `InsertionParent` for the insertion
|
||||
batch from the key, the latest `RequestMeta`, and the latest `table_slot`.
|
||||
batch from the key and the latest `RequestMeta` (which carries `table_slot`).
|
||||
|
||||
The queue is unit-tested without a GPU (`cargo test production::request_queue`).
|
||||
|
||||
@@ -494,10 +483,8 @@ Minimum viable path with the current demo interface:
|
||||
4. Emit a `LocationPage` matching the produced node. For internal requests,
|
||||
it must be `parent.child(child_x, child_y, child_z)`.
|
||||
5. Emit an `InsertionParent`:
|
||||
- external: `InsertionParent::external(structure_id, producer_id, anchor,
|
||||
table_slot)`;
|
||||
- internal: `InsertionParent::internal(meta, structure_id, node_id,
|
||||
producer_id, anchor)`.
|
||||
- external: `InsertionParent::external(producer_id, anchor, table_slot)`;
|
||||
- internal: `InsertionParent::internal(meta, node_id, producer_id, anchor)`.
|
||||
6. Set `page_count_buffer` to the number of entries. Order does not matter, but
|
||||
every entry must have matching information, location, parent, and attributes.
|
||||
7. Update the size passed to `CacheInsertionData::new` if the maximum batch can
|
||||
@@ -512,7 +499,7 @@ A production-ready producer should additionally:
|
||||
- handle `destination_indices == 0xFFFFFFFF` by retrying the request;
|
||||
- implement filtering/mip generation for coarser levels so LOD stops do not
|
||||
alias;
|
||||
- support multiple structures/producers per cache via IDs.
|
||||
- support multiple structures/producers per cache via `ProducerId` and anchors.
|
||||
|
||||
---
|
||||
|
||||
|
||||
Reference in New Issue
Block a user