Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am trying to share a direct3d9 surface between two processes. One process (let's call it A) writes to the surface, and the other (B) displays it on screen. Currently, process A does a StretchRect of its rendering surface to a shared surface, and then sets a flag in shared system memory to tell B that it's done. When B sees the flag, it then does a StretchRect of the shared surface to its own display surface. Process B then sets the flag again to tell A it is done.

It seems however that after the StretchRect on the shared surface returns, the texture has not necessarily finished copying, because sometimes Process B gets the previous picture, or sometimes even there is tearing (i.e. one half of picture N + one half of picture N + 1).

As I understand it, Direct3D is largely asynchronous under the hood, and does not ensure synchronisation between processes. I therefore need to ensure by myself that Process A has finished copying before displaying in process B, and vice-versa. Am I correct in my interpretation of the situation, and how would I achieve this? I am experimenting with LockRect() but I'm not sure if that's optimal or even guaranteed to work.

From MSDN documentation:

Shared cross-process surfaces provide no synchronization mechanism. Read/write changes to a shared surface may not reflect a referencing process's view of the surface when expected. To provide synchronization, use event queries or lock the texture.

Only the process that initially creates a shared resource can lock it (any process that opens a reference to that shared resource cannot lock it).

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.