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 ) )
{
}
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
what should be a dummy command here?
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.
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.
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).