使用 CopyResource() 更新绑定到 Direct3D 交换链的缓冲区时,是否需要设置相应的主渲染目标视图?

问题描述 投票:0回答:1

我有两个纹理,它们都分配给单独的 RTV:

  • texture_rgb
    - 分配给我的主 RTV(我与
    swapchain->Present(...)
    一起使用的 RTV。它是通过从我的交换链
    调用 
    GetBuffer()
  • 创建的)
  • texture_extra
    - 分配给单独的 RTV。纹理和 RTV 是相同的(在配置方面),最大的区别是这里的纹理是手动创建的,而不是由交换链创建的。

我正在将场景渲染为

texture_extra
,我正在以某种方式修改其内容(例如更改某些纹理像素的值)。然后我继续使用
CopyResource(texture_rgb, texture_extra)
将内容复制到空的
texture_rgb
中。然后交换链会呈现结果。

将一个纹理的内容复制到另一个纹理的内容是否取决于在触发复制之前是否为目标 RTV 调用了

OMSetRenderTargets(...)

伪代码(渲染帧函数):

// Switch to main RTV
device_context->OMSetRenderTargets(1, &rtv, dsv);
// Clear buffers
device_context->ClearRenderTargetView(rtv, color);
device_context->ClearDepthStencilView(dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);

// Switch to extra RTV
device_context->OMSetRenderTargets(1, &rtv_extra, dsv); // DSV is the depth stencil view used by all RTVs
// Clear buffers
device_context->ClearRenderTargetView(rtv_extra, color);
device_context->ClearDepthStencilView(dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);
// Set constant buffer and shaders
...
// Draw
device_context->DrawIndexed(36, 0, 0);
// Process rendered scene further
...

// Copy result to main <--------------- DO I NEED TO SWITCH TO MAIN RTV HERE?
device_context->CopyResource(texture_rgb, texture_extra);

// Switch back to main RTV
device_context->OMSetRenderTargets(1, &rtv, dsv);
// Present
swapchain->Present(1, 0);
c++ directx directx-11 direct3d direct3d11
1个回答
0
投票

CopyResource 不依赖于分配资源的位置,因此不需要将资源分配给 rtv 即可执行复制。

此外,如果您不在交换链上绘图,而仅使用复制资源进行 blit,则调用:

device_context->CopyResource(texture_rgb, texture_extra);

// This is not necessary unless you still want to draw something on the swapchain
device_context->OMSetRenderTargets(1, &rtv, dsv);
// Present
swapchain->Present(1, 0);
© www.soinside.com 2019 - 2024. All rights reserved.