Monday, November 14, 2022
HomeGame Developmentstructure - Render Thread and Replace Thread with D3D11 DXGI

structure – Render Thread and Replace Thread with D3D11 DXGI


Major Thread: window, message pump and D3D11 DXGI. Render body N.

Background thread: sport logic and physics. Replace body N + 1.

Threadpool: employee threads.

It might be extraordinarily useful if somebody may take a look at my first try and separate the work between the Major Thread and Background Thread. Do you’ve gotten any solutions for enchancment to this threading mannequin?

//Render body N
void render_MainThread()
{
    createWindow();
    createD3D11Resources();
    
    int inputBufferIndex = 0; //[0, 1]
    int gameStateBufferIndex = 0; //[0, 1]
    
    whereas(!shouldClose())
    {
        waitForUpdateThread();
        
        //PeekMessage(...)
        pumpMessagesOS(inputBufferIndex);
        
        //The replace thread could have the newest keyboard and mouse occasions.
        signalUpdateThread();
        
        //Replace GPU information
        //Draw calls
        //Swapchain Current
        render(gameStateBufferIndex);
        
        inputBufferIndex = 1 - inputBufferIndex;
        gameStateBufferIndex = 1 - gameStateBufferIndex;
    }
    
    exitApp.retailer(true); //Atomic
}

//Replace body N + 1
void update_BackgroundThread()
{
    createGameWorld();
    
    int inputBufferIndex = 1; //[0, 1]
    int gameStateBufferIndex = 0; //[0, 1]
    
    whereas(!exitApp)
    {
        updateGameLogic(inputBufferIndex);
        updatePhysics();
        updateGameState(gameStateBufferIndex);
        
        inputBufferIndex = 1 - inputBufferIndex;
        gameStateBufferIndex = 1 - gameStateBufferIndex;
        
        //The render thread could have the newest sport state.
        signalRenderThread();
        waitForRenderThread();
    }
}

We may do this threading mannequin as an alternative:

Major Thread: window, message pump, sport logic and physics.

Background thread: D3D11 DXGI.

Threadpool: employee threads.

However this mannequin is harmful, due to the way in which DXGI works. Can simply result in impasse and different nasty stuff.

See:

https://be taught.microsoft.com/en-us/home windows/win32/direct3darticles/dxgi-best-practices#multithreading-and-dxgi

https://be taught.microsoft.com/en-us/home windows/win32/direct3ddxgi/d3d10-graphics-programming-guide-dxgi#multithread-considerations

One other threading mannequin:

Major Thread: window, message pump.

Replace thread: sport logic and physics.

Render thread: D3D11 DXGI.

Threadpool: employee threads.

I now know easy methods to keep away from impasse with this threading mannequin, however this mannequin wants quite a lot of work to get all the pieces proper. This mannequin has the benefit of having the ability to timestamp every enter message, which implies that we will apply enter per fastened replace (fastened time-step) as an alternative of per body.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments