Directx 什么是ID3D12GraphicsCommandList::DiscardResource?

Directx 什么是ID3D12GraphicsCommandList::DiscardResource?,directx,direct3d,directx-12,direct3d12,Directx,Direct3d,Directx 12,Direct3d12,使用时我应该期望发生什么 放弃和销毁/删除资源有什么区别 何时是丢弃资源的好时机/用例 不幸的是,微软除了“放弃一项资源”之外,似乎并没有对它说太多;DR:是一个很少使用的函数,它提供了与处理清晰压缩结构相关的驱动程序提示。除非基于特定的性能建议,否则不太可能使用它 DiscardResource是Direct3D 11.1方法的DirectX 12版本。看 这些方法的主要用途是通过在呈现后丢弃渲染目标来优化基于平铺的延迟光栅化器图形部件的性能。这是对驱动程序的提示,提示渲染目标的内容与程序的操

使用时我应该期望发生什么

放弃和销毁/删除资源有什么区别

何时是丢弃资源的好时机/用例


不幸的是,微软除了“放弃一项资源”之外,似乎并没有对它说太多;DR:是一个很少使用的函数,它提供了与处理清晰压缩结构相关的驱动程序提示。除非基于特定的性能建议,否则不太可能使用它

DiscardResource
是Direct3D 11.1方法的DirectX 12版本。看

这些方法的主要用途是通过在呈现后丢弃渲染目标来优化基于平铺的延迟光栅化器图形部件的性能。这是对驱动程序的提示,提示渲染目标的内容与程序的操作不再相关,因此它可以避免下次使用时的一些内部清除操作

对于DirectX 11,这是在DirectX 11应用程序模板中使用的
DiscardView
,因为它使用了
DXGI\u SWAP\u EFFECT\u FLIP\u SEQUENTIAL

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.
    DXGI_PRESENT_PARAMETERS parameters = { 0 };
    HRESULT hr = m_swapChain->Present1(1, 0, &parameters);

    // 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->DiscardView1(m_d3dRenderTargetView.Get(), nullptr, 0);

    // Discard the contents of the depth stencil.
    m_d3dContext->DiscardView1(m_d3dDepthStencilView.Get(), nullptr, 0);

    // 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);
    }
}
DirectX 12应用程序模板不需要这些显式调用,因为它使用
DXGI\u SWAP\u EFFECT\u FLIP\u DISCARD

如果您想知道为什么DirectX 11应用程序不只是使用
DXGI\u SWAP\u EFFECT\u FLIP\u DISCARD
,它可能应该这样做。
DXGI\u交换\u效果\u翻转\u顺序
交换效果是Windows 8.x为Windows应用商店应用程序提供的唯一支持的效果,这是在引入
DiscardView
时。对于Windows 10/DirectX 12/UWP,可能最好始终使用
DXGI\u SWAP\u EFFECT\u FLIP\u DISCARD
,除非您特别不希望丢弃backbuffer

它对于多GPU SLI/Crossfire配置也很有用,因为清除操作可能需要GPU之间的同步。看


还有其他特定于场景的用法。例如,如果对G缓冲区执行延迟渲染,而您知道每个像素都将被覆盖,则可以使用
DiscardResource
而不是执行
ClearRenderTargetView
/
ClearDepthStencilView

TL;DR:是一个很少使用的函数,它提供了与处理清晰压缩结构相关的驱动程序提示。除非基于特定的性能建议,否则不太可能使用它

DiscardResource
是Direct3D 11.1方法的DirectX 12版本。看

这些方法的主要用途是通过在呈现后丢弃渲染目标来优化基于平铺的延迟光栅化器图形部件的性能。这是对驱动程序的提示,提示渲染目标的内容与程序的操作不再相关,因此它可以避免下次使用时的一些内部清除操作

对于DirectX 11,这是在DirectX 11应用程序模板中使用的
DiscardView
,因为它使用了
DXGI\u SWAP\u EFFECT\u FLIP\u SEQUENTIAL

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.
    DXGI_PRESENT_PARAMETERS parameters = { 0 };
    HRESULT hr = m_swapChain->Present1(1, 0, &parameters);

    // 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->DiscardView1(m_d3dRenderTargetView.Get(), nullptr, 0);

    // Discard the contents of the depth stencil.
    m_d3dContext->DiscardView1(m_d3dDepthStencilView.Get(), nullptr, 0);

    // 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);
    }
}
DirectX 12应用程序模板不需要这些显式调用,因为它使用
DXGI\u SWAP\u EFFECT\u FLIP\u DISCARD

如果您想知道为什么DirectX 11应用程序不只是使用
DXGI\u SWAP\u EFFECT\u FLIP\u DISCARD
,它可能应该这样做。
DXGI\u交换\u效果\u翻转\u顺序
交换效果是Windows 8.x为Windows应用商店应用程序提供的唯一支持的效果,这是在引入
DiscardView
时。对于Windows 10/DirectX 12/UWP,可能最好始终使用
DXGI\u SWAP\u EFFECT\u FLIP\u DISCARD
,除非您特别不希望丢弃backbuffer

它对于多GPU SLI/Crossfire配置也很有用,因为清除操作可能需要GPU之间的同步。看


还有其他特定于场景的用法。例如,如果对G缓冲区执行延迟渲染,您知道每个像素都将被覆盖,则可以使用
DiscardResource
而不是执行
ClearRenderTargetView
/
ClearDepthStencilView

感谢您的响应。稍微相关的一点是,参数将
pRects
设置为NULL,但仍然指定要丢弃的子资源,这有意义吗?我很难理解RECT和子资源之间的关系。您可以在不使用RECT的情况下提供子资源索引。我非常确定此优化不仅适用于基于平铺的GPU,也适用于桌面GPU。感谢您的回复。稍微相关的一点是,参数将
pRects
设置为NULL,但仍然指定要丢弃的子资源,这有意义吗?我很难理解RECT和子资源之间的关系。您可以在不使用RECT的情况下提供子资源索引。我非常确定此优化不仅适用于基于平铺的GPU,也适用于桌面GPU。