C++ c++;,directx 12:颜色选择问题
我想在DirectX 12中实现颜色选择。所以基本上我要做的是同时渲染到两个渲染目标。第一个渲染目标应包含正常渲染,而第二个渲染目标应包含objectID 要渲染到两个渲染目标,我认为您所需要做的就是使用OMSetRenderTargets设置它们 问题1:如何指定特定渲染目标应使用哪个着色器或管道状态对象?就像你怎么说render_target_0应该用shader_0渲染,render_target_1应该用shader_1渲染一样 问题2:渲染后如何从帧缓冲区读取像素?使用CopySubresourceRegion然后映射是否与DirectX 11中的一样?您需要使用回读堆吗?您是否需要使用资源屏障或围栏或某种排序同步原语来避免CPU和GPU同时使用帧缓冲区资源 我试着在谷歌上搜索答案,但没有走多远,因为DirectX 12非常新,而且DirectX 12的示例、教程或开源项目还不多 提前谢谢你的帮助C++ c++;,directx 12:颜色选择问题,c++,directx-12,direct3d12,C++,Directx 12,Direct3d12,我想在DirectX 12中实现颜色选择。所以基本上我要做的是同时渲染到两个渲染目标。第一个渲染目标应包含正常渲染,而第二个渲染目标应包含objectID 要渲染到两个渲染目标,我认为您所需要做的就是使用OMSetRenderTargets设置它们 问题1:如何指定特定渲染目标应使用哪个着色器或管道状态对象?就像你怎么说render_target_0应该用shader_0渲染,render_target_1应该用shader_1渲染一样 问题2:渲染后如何从帧缓冲区读取像素?使用CopySubr
代码示例的额外特别奖励点。由于我没有得到任何关于堆栈溢出的响应,我在gamedev.net上交叉发布,并在那里得到了很好的响应: 对于将来发现这一点的人,我将从这里的GameDev论坛复制red75prime的答案 red75prime的答案是: 问题1并不特定于D3D12。使用具有多个输出的一个像素着色器 问题2。对所有人都是 伪代码:
ID3D12GraphicsCommandList *gl = ...;
ID3D12CommandQueue *gqueue = ...;
ID3D12Resource *render_target, *read_back_texture;
...
// Draw scene
gl->DrawInstanced(...);
// Make ready for copy
gl->ResourceBarrier(render_target, RENDER_TARGET, COPY_SOURCE);
//gl->ResourceBarrier(read_back_texture, GENERIC_READ, COPY_DEST);
// Copy
gl->CopyTextureRegion(...);
// Make render_target ready for Present(), read_back_texture for Map()
gl->ResourceBarrier(render_target, COPY_SOURCE, PRESENT);
//gl->ResourceBarrier(read_back_texture, COPY_DEST, GENERIC_READ);
gl->Close(); // It's easy to forget
gqueue->ExecuteCommandLists(gl);
// Instruct GPU to signal when command list is done.
gqueue->Signal(fence, ...);
// Wait until GPU completes drawing
// It's inefficient. It doesn't allow GPU and CPU work in parallel.
// It's here just to make example simple.
wait_for_fence(fence, ...);
// Also, you can map texture once and store pointer to mapped data.
read_back_texture->Map(...);
// Read texture data
...
read_back_texture->Unmap();
编辑:我在代码中添加了“gl->Close()
EDIT2:不需要read_back_纹理的状态转换。回读堆中的资源必须始终具有state COPY\u DEST。因为我在堆栈溢出上没有得到任何响应,所以我在gamedev.net上交叉发布,并在那里得到了很好的响应: 对于将来发现这一点的人,我将从这里的GameDev论坛复制red75prime的答案 red75prime的答案是: 问题1并不特定于D3D12。使用具有多个输出的一个像素着色器 问题2。对所有人都是 伪代码:
ID3D12GraphicsCommandList *gl = ...;
ID3D12CommandQueue *gqueue = ...;
ID3D12Resource *render_target, *read_back_texture;
...
// Draw scene
gl->DrawInstanced(...);
// Make ready for copy
gl->ResourceBarrier(render_target, RENDER_TARGET, COPY_SOURCE);
//gl->ResourceBarrier(read_back_texture, GENERIC_READ, COPY_DEST);
// Copy
gl->CopyTextureRegion(...);
// Make render_target ready for Present(), read_back_texture for Map()
gl->ResourceBarrier(render_target, COPY_SOURCE, PRESENT);
//gl->ResourceBarrier(read_back_texture, COPY_DEST, GENERIC_READ);
gl->Close(); // It's easy to forget
gqueue->ExecuteCommandLists(gl);
// Instruct GPU to signal when command list is done.
gqueue->Signal(fence, ...);
// Wait until GPU completes drawing
// It's inefficient. It doesn't allow GPU and CPU work in parallel.
// It's here just to make example simple.
wait_for_fence(fence, ...);
// Also, you can map texture once and store pointer to mapped data.
read_back_texture->Map(...);
// Read texture data
...
read_back_texture->Unmap();
编辑:我在代码中添加了“gl->Close()
EDIT2:不需要read_back_纹理的状态转换。回读堆中的资源必须始终具有状态COPY\u DEST