[ad_1]

I’ve adopted https://gafferongames.com/submit/fix_your_timestep/ to do interpolated physics. I’ve a separate thread totally from my graphics thread. I take advantage of vulkan which permits me to do asynchronous GPU transfers, initiated from fully totally different threads. Nonetheless I am having bother understanding how you can successfully broadcast the related alpha fixed over to might important graphics thread.

Background

I my physics thread updates at 60hz, my framerate might be something. There are a set of double buffered host seen, host coherent (however not system seen) buffers, there additionally a set of double buffered system resident buffers. Every buffer incorporates each earlier and present knowledge for physics for simplicity sake.

Each time my physics thread finishes a actual replace, it units a flag that the info is able to be despatched off. Then exterior the collected delta time verify, my code checks if new knowledge might be despatched, and if all swapchain frames are utilizing the outdated knowledge within the system facet double buffer utilizing a timeline semaphore. It then executes a duplicate command on a switch queue with an thread owned command pool an extended with the related queue switch buffer reminiscence barrier, copying the info to the un-used system reminiscence.

On the show facet, every new ready body checks if a brand new physics knowledge has been accomplished transferring, through a separate timeline semaphore signaled through the copy command. The following command makes use of prepares a command buffer that tells the body to make use of the brand new completed uploaded knowledge if it is prepared, and alerts it is personal timeline semaphore incrementing a price which alerts what number of swapchain frames are utilizing mentioned knowledge. This a lot works with out interpolation.

Downside

I used to be going to make use of an atomic variable from my physics thread to ship to the drawing thread the present alpha worth, as seen within the linked article. Nonetheless, I noticed that it’s attainable that the alpha worth may very well be seen and up to date earlier than the related despatched knowledge could be able to eat through the draw thread, and fewer of a priority, after both.

Query

How do I broadcast the alpha variable correctly to my physics thread? The very best I may give you was in some way utilizing an related counter worth, which counted the variety of frames, and may line up with the related timeline semaphore worth, so I add the distinction between frames (the one used with the body, and the one related to the alpha worth) after which add that to the alpha worth after I lastly use it in my precise shader. This will likely sometimes make the worth for t go above 1.0 (although doubtless for under a really quick period of time), but it surely ought to look easy sufficient to the participant. Eg:

struct AlphaCount{
    double alpha;  
    std::uint64_t depend; 
}

std::atomic<AlphaCount> alpha_count; 

[ad_2]

Leave a Reply

Your email address will not be published. Required fields are marked *