什么时候在 RTV/DSV 上调用 DiscardView?
When to call DiscardView on RTV/DSV?
在清除关联视图之前立即调用 DiscardView
是否安全?似乎滥用此 API 可能会导致不好的事情,因此非常感谢有关如何有效使用它的一些解释。
DiscardView
是对分块硬件渲染的优化,所以不是严格要求。
在标准 Windows 8 Store、Windows phone 8 和通用 Windows 应用程序模板中,它在 Present
[=13 之后调用=]
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);
}
}
在清除关联视图之前立即调用 DiscardView
是否安全?似乎滥用此 API 可能会导致不好的事情,因此非常感谢有关如何有效使用它的一些解释。
DiscardView
是对分块硬件渲染的优化,所以不是严格要求。
在标准 Windows 8 Store、Windows phone 8 和通用 Windows 应用程序模板中,它在 Present
[=13 之后调用=]
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);
}
}