sokol icon indicating copy to clipboard operation
sokol copied to clipboard

Brain dump: Async resource initialization / updating

Open floooh opened this issue 5 years ago • 0 comments

Newer APIs like Metal and WebGPU allow to fill buffer and image resources with data asynchronously, so that the calls to sg_make_buffer(), sg_update_buffer() etc... could return before the data is actually copied to the resource.

This would work in sokol-gfx (because resources can be used before they are ready, just the draw calls using them would be dropped), except that the provided data must persist until the asynchronous content update has finished.

...however the more convenient solution is the same as now, that the data can be thrown away right after the function call, so this will remain definitely in as default way to initialize or update resource content.

Proposal: The asynchronous initialization/updating could be implemented with minimal "API disruption" by providing an "async flag", and an optional "ready/done" callback in the sg_*_desc structs.

If the async flag is false (default), behaviour is the same as now and the data can be thrown away right after the function returns. When it is true, the provided data must remain valid until the callback is invoked.

The same idea might later also be useful for initializing shaders and pipeline in a separate thread (if the underlying 3D API allows this).

floooh avatar Feb 02 '20 17:02 floooh