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).

  • \$\begingroup\$ Did you ever figure this out? I'm interested in an answer :) \$\endgroup\$ Oct 21, 2016 at 22:09
  • \$\begingroup\$ IIRC, we figured out d3d9 didn't support this scenario and went with a solution that didn't involve sharing a surface on the graphics card. Things may have changed with d3d10 and above, though. \$\endgroup\$
    – Asik
    Oct 23, 2016 at 21:24

1 Answer 1


your res sharing process is OK, I think. In dx9ex theres a flag in Present called D3DPRESENT_FORCEIMMEDIATE, can be used to force GPU render the resource, and then use the right picture later.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .