且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么DirectX全屏应用程序会显示黑色屏幕截图?

更新时间:2023-01-25 21:53:24

原因很简单:性能。

想法是尽可能地在GPU上渲染场景,而与CPU不同步。您使用CPU将渲染缓冲区发送到GPU(顶点,索引,着色器等),由于它们很小,因此总体来说确实很便宜,然后您就可以做任何您想做的事情,物理操作,多人同步等。GPU可以处理

The idea is to render a scene as much as possible on the GPU out of lock-step with the CPU. You use the CPU to send the rendering buffers to the GPU (vertex, indices, shaders etc), which is overall really cheap because they're small, then you do whatever you want, physics, multiplayer sync etc. The GPU can just crunch the data and render it on its own.

如果需要在窗口上绘制场景,则必须中断GPU,要求提供渲染缓冲区字节( LockRect ),为窗口请求图形对象(对GPU的干扰更大),渲染它并释放每个锁。通过与GPU不同步在GPU上渲染,您刚刚失去了任何收获。更糟糕的是,当您想到所有不同的CPU内核由于忙于渲染而闲置时(更像是等待缓冲区传输)。

If you require the scene to be drawn on the window, you have to interrupt the GPU, ask for the rendering buffer bytes (LockRect), ask for the graphics object for the window (more interference with the GPU), render it and free every lock. You just lost any sort of gain you had by rendering on the GPU out of sync with the CPU. Even worse when you think of all the different CPU cores just sitting idle because you're busy "rendering" (more like waiting on buffer transfers).

所以图形驱动程序要做的是用神奇的颜色绘制渲染区域,并告诉GPU场景的位置,GPU负责将场景覆盖在基于魔术色像素的显示屏幕(一种多遍像素着色器,当第一个纹理具有特定颜色的 x , y ,但并不慢)。您会完全脱离同步渲染,但是当您要求操作系统提供其视频内存时,您会得到场景所处位置的魔幻色彩,因为这正是它实际使用的颜色。

So what graphics drivers do is they paint the rendering area with a magic color and tell the GPU the position of the scene, and the GPU takes care of overlaying the scene over the displayed screen based on the magic color pixels (sort of a multi-pass pixel shader that takes from the 2nd texture when the 1st texture has a certain color for x,y, but not that slow). You get completely out of sync rendering, but when you ask the OS for its video memory, you get the magic color where the scene is because that's what it actually uses.

参考: http://en.wikipedia.org/wiki/Hardware_overlay