Shirakumo / trial

A fully-fledged Common Lisp game engine
https://shirakumo.github.io/trial
Other
1.02k stars 49 forks source link

Streamed Loading #56

Open Shinmera opened 1 year ago

Shinmera commented 1 year ago

This pull request implements a revision of the existing resources, assets, and loader system to add support for delayed or streamed loading.

Currently loading has to happen synchronously: a staging-area is populated with desired assets and resources. The area is sorted by dependencies between the resources and assets, and incrementally repopulated as new dependencies and resource artefacts emerge from loading an asset's data. This is fine and convenient, but it does not allow for data to be loaded in the background, forcing either synchronous loads during gameplay introducing lag stutters, or forcing long load screens to preload as much data as possible.

This PR aims to separate loading into two phases, if desired:

  1. Resource generation and allocation
    1. During this time, assets that generate resources must create a "stub" of the resources that they provide, and only load as little of their input data as possible. The stub resources may be textures and buffers, the size of which will be unknown.
    2. Resources like textures and buffers are only allocated minimally, only loading as little data into them as absolutely necessary. Other resources like framebuffers, shaders, etc. are loaded as before.
    3. The deferred load now returns synchronously, having created a state that can be rendered. Special care must be taken for assets that produce metadata, as that metadata is often necessary for normal operation.
  2. Deferred or background loading
    1. The textures and buffers that were deferred can now be loaded at a later point, incrementally as needed, or streamed in the background using a derived context.
    2. Once the load is complete, the same state is achieved as with the old synchronous load system, but yielding much lower pause times for the first synchronous step.

In order to achieve this the following needs to be done: