映射DirectX纹理时cudaGraphicsMapResources速度较慢 [英] cudaGraphicsMapResources slow speed when mapping DirectX texture

查看:101
本文介绍了映射DirectX纹理时cudaGraphicsMapResources速度较慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在DirectX中写入纹理,然后在CUDA内核中读取纹理.在启动内核之前,我正在使用cudaGraphicsMapResources.有时需要10到30毫秒.当然,这会导致应用程序中出现帧丢失.纹理只能用DirectX编写,只能用CUDA读取,在其他任何地方都不会使用.

I'm writing to a texture in DirectX then reading from it in CUDA kernel. I'm using cudaGraphicsMapResources before launching the kernel. Sometimes it takes 10-30 ms. Of course that causes a framedrop in the application. The texture is only written in DirectX and only read in CUDA, not used anywhere else.

我尝试了不同的操作,例如等待几帧,但这并不总是有帮助.我还尝试仅在开始时调用cudaGraphicsMapResources(而不是每次都调用),但是后来我不能保证DirectX已经完成了编写纹理的工作(有时还没有完成).我尝试使用线程,但是当我从其他线程调用cudaGraphicsMapResources时,它会崩溃.

I tried different things, like waiting few frames, but it doesn't always help. I also tried to call cudaGraphicsMapResources only in the beginning (instead of calling it each time), but then I have no guarantee that the DirectX has already finished to write the texture (sometimes it hasn't). I tried to use threads, but it crashes when I call cudaGraphicsMapResources from different thread.

我还给人一种印象,它主要是在启用vsync时发生的.

I also have the impression that it's mostly occurs when vsync is enabled.

这是一个已知问题吗?是什么原因造成的?有没有一种方法可以测试资源是否以非阻塞方式准备好了?还是总有一些解决方法?

Is this a known problem? What causes this? Is there a way to test if the resource is ready in a non blocking way? Or in general is there some workaround?

我有GeForce GTX 670,Windows 7 64位,驱动程序v.331.82.

I have GeForce GTX 670, Windows 7 64 bit, driver ver. 331.82.

推荐答案

摘自 cudaGraphicsMapResources()上的CUDA文档:

From the CUDA documentation on cudaGraphicsMapResources():

此函数提供同步保证,确保在cudaGraphicsMapResources()之前发出的所有图形调用都将在流中随后发出的任何后续CUDA工作开始之前完成.

This function provides the synchronization guarantee that any graphics calls issued before cudaGraphicsMapResources() will complete before any subsequent CUDA work issued in stream begins.

您看到的延迟可能是由于等待绘图完成而引起的.特别是因为您指出了当不为每帧映射时,有时图形还没有完成.

It could be that the delays you are seeing are caused by waiting for the drawing to complete. In particular since you indicate that, when not mapping for each frame, the drawing has sometimes not completed.

将此功能与vsync结合使用会使问题变得更糟,因为图形调用可能必须等待下一个vsync才能开始绘制.

Combining this with vsync could make the problem worse since graphics calls may have to wait for the next vsync before they start drawing.

使用vsync时,此问题的部分解决方法可能是使用更多的后台缓冲区.

A partial workaround for the issue when vsync is in use may be to use more back buffers.

如果还没有,也可以尝试使用 cudaGraphicsMapFlagsReadOnly 调用 cudaGraphicsResourceSetMapFlags().

If you haven't already, you could also try to call cudaGraphicsResourceSetMapFlags() with cudaGraphicsMapFlagsReadOnly.

我认为它仅等待您自己的应用发出的绘图调用完成.文档说:

I think it waits only for drawing calls made by your own app to complete. The docs say:

从中注册资源的图形API在被CUDA映射时不应访问任何资源.如果应用程序这样做,则结果是不确定的.

The graphics API from which resources were registered should not access any resources while they are mapped by CUDA. If an application does so, the results are undefined.

当然,您无法控制其他应用程序执行的绘图.

And, of course, you have no control over drawing performed by other apps.

通过使用 D3DPRESENT_DONOTWAIT 标志调用 Present() Direct3D方法,您也许可以检查图形状态而不会发生阻塞.

You may be able to check drawing status without blocking by calling the Present() Direct3D method with the D3DPRESENT_DONOTWAIT flag.

这篇关于映射DirectX纹理时cudaGraphicsMapResources速度较慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆