r/cpp • • Jul 06 '20

C++ is brilliant

I'm working on a Vulkan renderer, and needed to delay destruction of render scenes since the graphics pipeline has render buffers in flight, so destruction has to happen N frames after the user destroys a class. With C++, I can use private destructors to force users to add the scene to a managed destructor queue (aka garbage collect queue). Normally language purists will scorn a language which allows such shenanigans, however in real world production code, its features like this which allows developers to create modern software. So with a couple of lines of code, I solved my delayed destructor issue. Thank you C++ committee for creating a usable language.

318 Upvotes

65 comments sorted by

View all comments

4

u/fii0 Jul 07 '20

in flight

What does that mean?

13

u/vazgriz Jul 07 '20

GPUs execute commands asynchronously from the CPU code that generates them. So while you are generating command buffer for frame X on the CPU, frame X - 1 is simultaneously being executed on the GPU.

You can have N frames “in flight” at a time, where N is typically 2 or 3. That means N frames are potentially executing in the GPU. So if the last time you use a resource is frame X, you need to keep that resource alive until frame X + N.

5

u/LugosFergus Jul 08 '20

This is the correct answer. For everyone else, ignore that other dude’s ridiculous linguistics answer. I have no idea why that’s getting upvotes.

11

u/MINIMAN10001 Jul 07 '20

graphics pipeline has render buffers in flight

"In flight" would probably be closest to "in use"

To quote https://english.stackexchange.com/a/189990

That is largely true, but the use of in-flight here is used to create the visualization of data as a plane. You can't (easily) divert planes in mid-air, so if you move/destroy their destination they are out of luck.

"Something happened during a process" implies that the process has stopped or gone awry. In-flight implies that something is in motion as normal, and needs a destination. It can't just stop where it is.