本文介绍了D3D图像闪烁,可能与时序有关的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用DispatcherTimer在用户交互后大约一秒钟渲染到D3DImage,但出现了零星的闪烁(黑框).当收到输入后立即调用渲染时,我没有闪烁问题.原因 因为延迟是要具有立即快速渲染模式和更昂贵的延迟质量模式.

I'm trying to render to a D3DImage about a second after user interaction by using a DispatcherTimer, but I'm getting a sporadic flicker (black frame). When rendering is immediately called upon receiving input, I do not have the flicker problem. The reason for the delay is to have an immediate fast render mode and a more expensive delayed quality mode.

在后台线程上渲染时,闪烁更加频繁,并且还会出现撕裂.我使用了三重缓冲表面,因此主线程更新可以独立于后台渲染.每帧都在后台线程中渲染 后台缓冲区,然后与中间缓冲区交换.使用DispatcherTimer或类似的程序,主线程将通过锁定D3DImage,交换中间缓冲区和前端缓冲区,分配新的前端缓冲区以固定间隔更新D3DImage. 指针,设置脏区并解锁.尽管我进行了检查,但IsFrontBufferAvailable始终没有为假.根据文档,解锁将分配的表面区域复制到D3DImage.我一直在谨慎地锁定 因此一个线程上的缓冲区不会被另一个线程触及.

When rendering on a background thread, the flicker was more frequent and tearing would also be present. I used a triple-buffered surface so main thread updates could be independent of the background rendering. Each frame is rendered in the background thread to a back buffer, which is then swapped with the intermediate buffer. Using a DispatcherTimer or similar, the main thread would update the D3DImage at a fixed interval by locking it, swapping the intermediate and front buffers, assigning the new front buffer pointer, setting the dirty region, and unlocking. Although I check for it, at no point has IsFrontBufferAvailable been false. According to the documentation, unlocking copies the assigned surface region to the D3DImage. I've been careful about locking appropriately so buffers on one thread are not touched by the other.

作为参考,我使用的是.NET 4.0/VS2010,DirectX 2010年2月和nVidia 260M.

For reference, I'm using .NET 4.0/VS2010, DirectX Feb 2010, and an nVidia 260M.

在使用.NET 3.5时,我注意到在WPF动画期间闪烁现象更多.我不知道这是否仍然是一个问题.与.NET 3.5相比,总体上似乎没有那么多的闪烁,而且我记得读过一篇文章,指出了一些修复程序 发生在D3DImage中.

When using .NET 3.5, I had noticed that the flickering occurred much more during WPF animations. I don't know if that is still an issue. There appears to be less flickering in general than with .NET 3.5, and I remember reading a post indicating some fixes had occurred with D3DImage.

对于主线程和背景线程渲染,当渲染帧所需的时间改变时,我注意到闪烁的数量有所不同.我想知道D3D是否没有出现在我的表面上,在这种情况下D3D和WPF都可能 正在访问它.

I've noticed some differences in the amount of flicker when the time required to render a frame changes, for both main and background thread rendering. I wonder if D3D is not presenting to my surface when I think it is, in which case both D3D and WPF might be accessing it.

有人对可能发生的事情或我在哪里寻找更多信息有想法吗?

Does anyone have ideas about what might be happening or where I might look for more info?

谢谢!

-Ben

推荐答案

此类问题可能是由许多情况引起的.您能否将代码打包到一个小项目中并在此处共享,例如通过sky driver上传?这可以帮助我们重现该问题.

Such kind of issues can be caused by so many cases. Could you please package the code in a small project and share it here, such as uploading it via sky driver? This can help us to reproduce the issue.

我有两个建议:

1.由于通过D3DImage进行渲染会消耗大量资源,并且通常不如我们预期的那样快,因此最好降低帧速率(增加计时器的间隔).这将使图形有更多时间完成渲染.

1. Since the rendering via D3DImage will consume lots of resources and often not as fast as we expected, so it is better to decrease the frame rate(increase the interval of the timer). This will give the graphics more time to finish rendering.

2.调用一些方法来手动刷新WPF窗口,例如InvalidateVisual.这两个渲染系统可能不同步.

2. Call some methods to refresh the WPF window manually, such as InvalidateVisual. It is possible that the two rendering systems are not synchronized.

让我知道这是否无济于事.
李亚伦

Let me know if this does not help.
Aland Li


这篇关于D3D图像闪烁,可能与时序有关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-03 19:33
查看更多