Documentation
¶
Overview ¶
Package worldgpuchunk defines portal-selected spatial cells containing final GPU buffers and independently resident, offline prepared RNM images.
Index ¶
- Constants
- Variables
- func AppendStaticRecord(destination []byte, record StaticRecord) ([]byte, error)
- func AppendVertex(destination []byte, vertex Vertex) []byte
- func EncodeCatalog(catalog Catalog) ([]byte, error)
- func EncodePayload(payload Payload) ([]byte, error)
- func PortalSpaces(document *world.Document) ([]uint32, error)
- func ValidateDeclaration(entries []level.Entry, metadata level.Metadata, features []string) error
- func ValidatePayload(payload Payload, materialIDs []uint32, sectorCount, solidCount int) error
- func ValidateRecord(record []byte, materialLayer uint32, rgbmRange float64, probeCount uint32) error
- type Catalog
- type Cell
- type CompileOptions
- type Draw
- type GPUData
- type Payload
- type RecordRef
- type StaticRecord
- type Vertex
Constants ¶
const ( Feature = "world/gpu-chunks@2" Schema = "karty.world-gpu-chunks@2" MetadataKey = "kartyWorldGPUChunks" CellMetadataKey = "kartyWorldGPUCell" CatalogEntry = "@world/gpu-chunks/catalog" PayloadEntry = "@world/gpu-chunks/cell" RNMEntry = "@world/gpu-chunks/rnm.ktx2" ABI = "karty.webgpu-cell@2" VertexStride = 96 AddressStride = 8 IndexStride = 4 RecordStride = 368 MaxCells = 4096 MaxRecords = 8192 MaxDraws = 1024 MaxVertices = 262144 MaxIndices = 1572864 MaxDimension = 2048 MaxEncodedSize = level.MaxEntrySize OwnerSector uint32 = 0 OwnerSolid uint32 = 1 )
Variables ¶
var ErrChunk = errors.New("GPU-ready spatial chunk is invalid")
Functions ¶
func AppendStaticRecord ¶
func AppendStaticRecord(destination []byte, record StaticRecord) ([]byte, error)
AppendStaticRecord writes an identity-transform RNM record. Its local RNM base layer is always zero; a cell owns precisely its three prepared planes.
func AppendVertex ¶
AppendVertex writes exactly one little-endian, 96-byte source vertex.
func EncodeCatalog ¶
EncodeCatalog emits the bounded canonical KGC2 root grid catalog.
func EncodePayload ¶
EncodePayload writes metadata and the final GPU byte streams without changing any vertex, address, index or record bytes. ValidatePayload admits root refs.
func PortalSpaces ¶
PortalSpaces labels admitted sectors by their lowest connected sector index. Only reciprocal portals with an identity coordinate transform join spaces. Directed, transformed and absent links never imply coordinate adjacency. This is bounded topology inspection, not visibility or prefetch selection.
func ValidateDeclaration ¶
ValidateDeclaration requires complete, explicitly selected root or cell data. Reserved entries cannot silently select a legacy renderer or partial asset.
func ValidatePayload ¶
ValidatePayload additionally binds owners and canonical shared material layers to admitted root metadata. The root layout order is the material layer order.
func ValidateRecord ¶
func ValidateRecord(record []byte, materialLayer uint32, rgbmRange float64, probeCount uint32) error
ValidateRecord admits one complete changed metadata record before any writes. MaterialLayer is the canonical root array index, not an authored material ID. ProbeCount is the admitted immutable root probe table length (at most 511).
Types ¶
type Catalog ¶
type Catalog struct {
BakedLights []uint32
GeometrySHA256, MaterialLayoutSHA256 [32]byte
Origin [2]float64
CellSize float64
Cells []Cell
}
Catalog groups whole room/geometry extents inside enclosing XY grid bounds. Portal topology, rather than grid adjacency, determines loading and visibility.
func DecodeCatalog ¶
DecodeCatalog validates all counts before allocating typed metadata.
func (Catalog) Validate ¶
Validate checks canonical identities, spatial ownership and allocation bounds.
func (Catalog) ValidateCell ¶
ValidateCell binds the complete payload and its independently prepared RNM image to one content-addressed root descriptor. Module hashing stays with the level loader because the descriptor identifies the entire KLD, not its image.
func (Catalog) ValidateLights ¶
ValidateLights binds the sorted baked-source union to the root authored light table. It preserves selective prebaking without runtime double contribution.
type Cell ¶
type Cell struct {
ID, SpaceID uint32
Group uint32
GridSpan uint32
Grid [2]int32
Bounds [6]float64
Sectors, PhysicalIDs []uint32
ContentSHA256 [32]byte
Size, GPUBytes, RNMBytes uint64
}
Cell is a content-addressed independent render asset. Sectors are explicit topological ownership, including for solids; PhysicalIDs never own rendering. Grid/GridSpan enclose the extent without requiring room cuts. The first sector ID distinguishes canonical room owners sharing the same enclosing grid key.
type CompileOptions ¶
type CompileOptions struct {
RGBMRange float64
SectorProbes, SolidProbes []uint32
SolidSectors [][]uint32
CellSectors []uint32
SkipTerrainSectors []uint32
}
CompileOptions provides only immutable, offline lighting/ownership inputs. Probe values are one-based slots in the shared root reflection resource.
type Draw ¶
type Draw struct {
FirstIndex, IndexCount, Record, AlphaMode uint32
Bounds [6]float64
Sectors []uint32
}
Draw refers only to cell-local address/index and same-owner record buffers. Sectors retain build-time ownership. Renderers submit complete prebuilt ranges without subdividing them by internal sector boundaries.
type GPUData ¶
type GPUData struct {
Vertices, Addresses, Indices, Records []byte
RecordRefs []RecordRef
Draws []Draw
}
GPUData contains final shader ABI bytes, already ordered and indexed offline. Decoders borrow buffer bytes; callers must retain immutable source storage.
func CompileReady ¶
func CompileReady( ready worldchunk.Ready, document *world.Document, materials worldmaterial.Layout, options CompileOptions, ) (GPUData, error)
CompileReady converts source-oriented Ready streams into the final cell ABI. It runs only in the asset build. Runtime code consumes GPUData unchanged.
type Payload ¶
type Payload struct {
CellID uint32
Bounds [6]float64
MaterialLayoutSHA256 [32]byte
RGBMRange float64
GPUData
}
Payload is paired with one cell-local, three-layer lossless RNM KTX2 image. All buffers and lighting use authored coordinates; portal contexts are dynamic draw metadata and never modify this asset.
func DecodePayload ¶
DecodePayload borrows immutable GPU bytes and validates all local references. It neither converts vertices nor constructs draw addresses or image pools.
func DecodePayloadWithCheckpoint ¶
DecodePayloadWithCheckpoint performs the same complete admission while letting a host cancel or cooperatively yield during bounded scan batches. The callback must not mutate encoded bytes; failure never returns a partial cell.
type RecordRef ¶
type RecordRef struct{ MaterialID, OwnerKind, OwnerID, SurfaceKind uint32 }
RecordRef binds a packed immutable GPU record to canonical authored owners and a material ID in the root's bound material layout.
type StaticRecord ¶
type StaticRecord struct {
Layer, AlphaMode, Probe uint32
RGBMRange, Emission float32
Water bool
Opacity, Exponent float32
Specular [3]float32
UVTransform [4]float32
}
StaticRecord contains the material-dependent values in an immutable cell record. Owner and surface metadata are carried separately by RecordRef.
type Vertex ¶
type Vertex struct {
Position, Normal [3]float32
Tangent [4]float32
UV, LightUV [2]float32
BakeTangent, BakeBitangent [3]float32
Motion [4]float32
}
Vertex matches the versioned shader storage ABI, without host struct padding. Build tools fill these fields; runtime cell loaders upload the encoded bytes.