Monday, August 8, 2022
HomeGame Developmenthome windows - Learn how to Resize SwapChain in directX12?

home windows – Learn how to Resize SwapChain in directX12?


I’m making an attempt to resize the swapChain following the strategy offered within the following hyperlink. I’m additionally flushing the GPU earlier than resizing utilizing the flushGpu() technique however nonetheless I get the next error in debugLayer:

D3D12 ERROR: ID3D12CommandAllocator::Reset: A command allocator 0x0000022B3BE50830:'Unnamed ID3D12CommandAllocator Object' is being reset earlier than earlier executions related to the allocator have accomplished. [ EXECUTION ERROR #552: COMMAND_ALLOCATOR_SYNC]

Are you able to please inform what am I doing flawed? Additionally attaching code block for additional reference:

void IG::DX_Renderer::OnResize(unsigned int width, unsigned int top)
{
    fence->flush_gpu();
    ThrowIfFailed(commandAllocator->get_command_allocator(fence->m_frameIndex)->Reset());
    std::cout << "command allocator no.: " << fence->m_frameIndex << std::endl;
    ThrowIfFailed(commandList->get_command_list()->Reset(commandAllocator->get_command_allocator(fence->m_frameIndex).get(), nullptr));
    for (int i = 0; i < FrameCount; i++)
    {
        m_renderTargets[i].Reset();
    }
    std::cout << swapChain->get_swap_chain().get() << std::endl;
    //ThrowIfFailed(swapChain->get_swap_chain()->ResizeBuffers(FrameCount, (UINT)width, (UINT)top, DXGI_FORMAT_R8G8B8A8_UNORM, 0));
    HRESULT hr = swapChain->get_swap_chain()->ResizeBuffers(FrameCount, (UINT)width, (UINT)top, DXGI_FORMAT_R8G8B8A8_UNORM, 0);
    
    std::cout << "End result code: " << hr << std::endl;

    if (hr == DXGI_ERROR_DEVICE_REMOVED || hr == DXGI_ERROR_DEVICE_RESET)
    {
        std::cout << "Machine is misplaced" << std::endl;
    }

    fence->m_frameIndex = 0;
    LoadPipeline();

    //Set viewPort
    m_viewport.TopLeftX = 0.0f;
    m_viewport.TopLeftY = 0.0f;
    m_viewport.Width = static_cast<float>(width);
    m_viewport.Peak = static_cast<float>(top);

    //Set scissorRect
    m_scissorRect.left = 0.0f;
    m_scissorRect.prime = 0.0f;
    m_scissorRect.proper = static_cast<LONG>(width);
    m_scissorRect.backside = static_cast<LONG>(top);

    ThrowIfFailed(commandList->get_command_list()->Shut());
    // Execute the command listing.
    ID3D12CommandList* ppCommandLists[] = { commandList->get_command_list().get() };
    commandQueue->get_command_queue()->ExecuteCommandLists(_countof(ppCommandLists), ppCommandLists);
}

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments