lowenware / dotrix

A 3D engine with ECS and Vulkan renderer for Rust developers
https://dotrix.rs
MIT License
290 stars 11 forks source link

Feature Request: One time, excecute on next frame #160

Open QuantumEntangledAndy opened 2 years ago

QuantumEntangledAndy commented 2 years ago

There are times, such as when computing one off jobs on the gpu, you need to run something on the next frame once.

For example: In the PR #159 there is a method to copy textures from the GPU to the cpu. For this to work we need to enqueue a command to the gpu and wait for the next frame cycle so that it is completed.

As another example, we could compute bounding boxes on the gpu and then copy them back to the cpu next frame for collision or raycasting analysis.

This is a tracking issue to discuss how should we implement it.

QuantumEntangledAndy commented 2 years ago

Possible ways to achieve this:

  1. Async method that allows us to await a frame change, have some std::future::Future object that completes once a frame has incremented
  2. Make cycle could an Arc<AtomicU32> and expose methods to share it. This could be abusable if them modify it.
  3. Make systems cancel-able in some way. For example if a system returns STOP then we remove it. This way the user can enqueue a system do what every they need like check cycle count and act on it and remove when done.