何时在RTV / DSV上调用DiscardView?

时间:2015-08-08 01:20:31

标签: direct3d11

在清除相关视图之前立即调用DiscardView是否安全?似乎滥用这个API可能导致坏事,所以对如何有效地使用它的一些解释将非常感激。

1 个答案:

答案 0 :(得分:2)

DiscardView是平铺硬件渲染的优化,因此并非严格要求。

在标准Windows 8商店,Windows Phone 8和通用Windows应用模板中,它在Present

之后立即调用
void DX::DeviceResources::Present() 
{
    // The first argument instructs DXGI to block until VSync, putting the application
    // to sleep until the next VSync. This ensures we don't waste any cycles rendering
    // frames that will never be displayed to the screen.
    HRESULT hr = m_swapChain->Present(1, 0);

    // Discard the contents of the render target.
    // This is a valid operation only when the existing contents will be entirely
    // overwritten. If dirty or scroll rects are used, this call should be removed.
    m_d3dContext->DiscardView(m_d3dRenderTargetView.Get());

    // Discard the contents of the depth stencil.
    m_d3dContext->DiscardView(m_d3dDepthStencilView.Get());

    // If the device was removed either by a disconnection or a driver upgrade, we 
    // must recreate all device resources.
    if (hr == DXGI_ERROR_DEVICE_REMOVED || hr == DXGI_ERROR_DEVICE_RESET)
    {
        HandleDeviceLost();
    }
    else
    {
        DX::ThrowIfFailed(hr);
    }
}