Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Streamed Loading #56

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft

Streamed Loading #56

wants to merge 3 commits into from

Conversation

Shinmera
Copy link
Member

@Shinmera Shinmera commented Sep 1, 2023

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:

  • A new resource class, deferrable-resource is introduced. Resources of this type can be loaded minimally.
  • The function allocate when called on a deferrable-resource will perform minimal allocation, rather than full allocation.
  • The function load when called on a deferrable-resource will perform full allocation with data loading. The resource's data field must be properly populated before this function can be called. Alternatively, the standard update-buffer-data or resize-buffer may be used as well.
  • A new asset class, deferrable-asset is introduced. Assets of this type can be loaded minimally.
  • The function allocate when called on a deferrable-asset will perform minimal loading, only producing as much metadata as necessary for standard operation, and producing deferrable-resource instances that are "close enough" to the real resource type once loaded fully.
  • The function load when called on a deferrable-asset will perform full allocation with data loading. The data of resources it generates will be populated fully so that they may be loaded as well.
  • Context creation must allow for a derived context, which can be active in a background thread alongside the main context, used for streaming in texture and buffer data.
  • A new staging area class, deferred-staging-area is introduced. When commit is called on such an area, the loader will perform a deferred load, and keep track of the assets and resources that have not been fully loaded yet.
  • A new loader class, streamed-loader is introduced. This loader keeps a background thread and derived context for use in background streamed loading. When commit is called on a deferred-staging-area with the keyword argument :stream T, then it will automatically start loading in the remaining assets and resources in the background.
  • Documentation of the new systems

@Shinmera Shinmera force-pushed the master branch 6 times, most recently from 1be38da to afb0476 Compare September 12, 2023 07:44
@Shinmera Shinmera force-pushed the master branch 3 times, most recently from 4f867f5 to 3fbd53d Compare October 12, 2023 09:19
@Shinmera Shinmera force-pushed the master branch 3 times, most recently from 86f03fa to 391bc2f Compare November 13, 2023 12:12
@Shinmera Shinmera force-pushed the master branch 2 times, most recently from abcb908 to b102af3 Compare November 21, 2023 10:44
@Shinmera Shinmera force-pushed the master branch 9 times, most recently from 816cb1a to 4fe60d3 Compare December 5, 2023 13:58
@Shinmera Shinmera force-pushed the master branch 2 times, most recently from f2e5fe6 to 1b6faad Compare December 11, 2023 10:31
@Shinmera Shinmera force-pushed the master branch 3 times, most recently from fc79f56 to cf6f722 Compare April 5, 2024 16:06
@Shinmera Shinmera force-pushed the master branch 4 times, most recently from 91a40bf to c0fb2d2 Compare August 19, 2024 20:57
@Shinmera Shinmera force-pushed the master branch 3 times, most recently from e6d8bfc to a8d853f Compare August 24, 2024 12:22
@Shinmera Shinmera force-pushed the master branch 2 times, most recently from 339197b to 1264753 Compare November 8, 2024 22:29
@Shinmera Shinmera force-pushed the master branch 3 times, most recently from 3a40ad5 to 3fe007a Compare December 14, 2024 19:46
@Shinmera Shinmera force-pushed the master branch 3 times, most recently from 9e0be4b to c6bae42 Compare January 4, 2025 11:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant