实施API以等待d3d10命令完成 [英] Implement API to wait for d3d10 commands to finish

查看:94
本文介绍了实施API以等待d3d10命令完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在实现一些功能,这需要我实现一个API以等待d3d10完成渲染.基本上我正在尝试实现对共享纹理的同步访问,以便在d3d10成功呈现后可以更新纹理后缓冲.通过调用此黑匣子API,我认为可以实现,并且我认为它将类似于glfinish().我已阅读到我们可以使用ID3D10Query查询来实现同步访问.

I am implementing some functionality which requires me to implement an API to wait for d3d10 to finish rendering.Basically i am trying to implement synchronize access to a shared texture such that i can update a texture after d3d10 is successfully able to present to backbuffer. By calling this black box api i think this can be achieved and i think it will be something similar like glfinish().I have read we can use ID3D10Query queries for implementing synchronize access.

  D3D10_QUERY_DESC queryDesc;

  ... // Fill out queryDesc structure

  ID3D10Query * pQuery;
  pDevice->CreateQuery( &queryDesc, &pQuery );

  pQuery->Begin();

  ... // Issue graphis commands, do whatever

  pQuery->End();

  UINT64 queryData; // This data type is different depending on the query type

  while( S_OK != pQuery->GetData( &queryData, sizeof( UINT64 ), 0 ) )
  {
  }

我应该在开始和结束之间放置一些虚拟命令吗?因为我想将此功能公开为公共API,所以将其命名为waitforgraphiscompletion

should i put some dummy command between begin and end this? since i want to expose this functionality as public API something named as waitforgraphiscompletion

这里什么是虚拟命令?

推荐答案

如果您尝试在OpenGL中同步执行CPU和GPU,则可以使用

If you are trying to synchronize execution CPU and GPU in OpenGL, you would use glFenceSync to followed by a glClientWaitSync. The equivalents in Direct 10 are ID3D10Asynchronous::End, and ID3D10Asynchronous::GetData (note, in DX11, the interfaces are slightly different). These let you know when the GPU has finished processing the command buffer to a particular point. This allows you to know when previous read/write operations on a resource have completed, and the CPU can safely access the resource without additional synchronization.

您不需要在while循环中放置任何命令.命令缓冲区最终将处理您的查询,并将返回S_OK(或您可能要处理的错误消息).但是,这有点浪费,因为CPU只会旋转等待GPU,因此,如果可能的话,您应该在循环中做一些额外的有用工作.

You are not required to put any commands in the while loop. The command buffer will eventually process your query, and will return S_OK (or an error message, which you might want to handle). However, this is somewhat wasteful, as the CPU will just spin waiting for the GPU, so if possible, you should do some extra useful work within the loop.

请注意,如果您将D3D10_ASYNC_GETDATA_DONOTFLUSH用作GetData的最终参数(而不是"0"),则上述情况并非如此-无法保证命令缓冲区会自动"启动,并且您可能会陷入无限循环(因此不建议这样做).

Note, if you used D3D10_ASYNC_GETDATA_DONOTFLUSH as the final parameter to GetData (instead of '0'), the above would not be the case - there is no guarantee that the command buffer would 'automatically' kick off, and you could end up in an infinite loop (and, as such is not the recommended usage).

这篇关于实施API以等待d3d10命令完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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