#5934·dxvk

[d3d9] D3D9Ex SYSTEMMEM "user memory" resources: GetRenderTargetData never writes to the app-provided memory (plus imported shared textures get zero-cleared)

Author: AdaptEngineeringCreated Sep 29, 2026Updated Sep 30, 2026
Labelsd3d9

Summary

D3D9Ex (Windows Vista and later) lets an app pass a pointer to its own memory through pSharedHandle when it creates a D3DPOOL_SYSTEMMEM texture (1 level) or offscreen plain surface. That memory becomes the resource's storage. Apps then use GetRenderTargetData() to read a render target straight into their own buffer, without calling LockRect().

DXVK treats the pointer only as initial data (see the comment in D3D9DeviceEx::CreateTexture / CreateOffscreenPlainSurfaceEx): it copies the data once and keeps its own staging storage. As a result, GetRenderTargetData() never updates the application's memory, and apps that rely on this display nothing.

A second, related issue: when D3D9 opens an existing shared resource (*pSharedHandle != nullptr), D3D9Initializer::InitTexture() still calls InitDeviceLocalTexture(), and its initImage(..., UNDEFINED) zero-clears the imported image. That erases content another device has already rendered, for every device sharing it. D3D11's OpenSharedResource() doesn't initialize imported textures.

Software

FlightScope FS Golf PC 2.0 (golf launch-monitor software; .NET 9 WPF). Its WebGL 3D views (WebGLControlDirectXInterop.dll + ANGLE) render with ANGLE into a D3D11 shared texture, open it in a D3D9Ex device, and then every frame: CreateTexture(w, h, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &tex, (HANDLE*)&appBufferPtr) followed by GetRenderTargetData(sharedRT, texSurface), and display appBuffer. On DXVK the 3D view is completely blank (white). With the patch below it renders correctly.

Minimal reproduction

c
static DWORD mem[64 * 32];
void *p = mem;
memset(mem, 0x11, sizeof(mem));
IDirect3DDevice9Ex_CreateRenderTarget(dev, 64, 32, D3DFMT_A8R8G8B8, D3DMULTISAMPLE_NONE, 0, FALSE, &rt, NULL);
IDirect3DDevice9Ex_ColorFill(dev, rt, NULL, D3DCOLOR_ARGB(255, 0, 0, 255));
IDirect3DDevice9Ex_CreateTexture(dev, 64, 32, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &tex, (HANDLE *)&p);
IDirect3DTexture9_GetSurfaceLevel(tex, 0, &sys);
IDirect3DDevice9Ex_GetRenderTargetData(dev, rt, sys);
printf("%08lx\n", mem[64 * 5 + 5]);   /* Windows: ff0000ff   DXVK: 11111111 */

Shared-import clear: a D3D11 device creates a MISC_SHARED texture and a second D3D11 device clears it to red; a D3D9Ex device then opens it with CreateTexture(..., &handle) and reads it back with GetRenderTargetData. The result is 00000000 instead of ffff0000, and the D3D11 devices also see the texture zeroed. Content drawn after the import is shared correctly. Opening a D3D9-created shared texture on a second D3D9Ex device also wipes it for both devices.

Full test sources (C, mingw-w64) are included below.

Proposed fix (tested)

diff
--- a/src/d3d9/d3d9_initializer.cpp
+++ b/src/d3d9/d3d9_initializer.cpp
@@ void D3D9Initializer::InitTexture(
-    if (pTexture->GetImage() != nullptr)
+    // Don't clear imported shared images: another device may already have written to them,
+    // and D3D11's OpenSharedResource does not initialize imports either.
+    if (pTexture->GetImage() != nullptr
+     && pTexture->GetImage()->info().sharing.mode != DxvkSharedHandleMode::Import)
       InitDeviceLocalTexture(pTexture);

On top of that, store the user pointer on D3D9CommonTexture (SetUserMemory() / GetUserMemory()) in CreateTexture and CreateOffscreenPlainSurfaceEx. At the end of GetRenderTargetData, if the destination has user memory, LockRect(D3DLOCK_READONLY) it (which waits for the copy) and memcpy the rows into the user memory. I assumed the user memory's pitch is align(width * bytesPerElement, 4). This is simpler than making the app memory the real backing storage, and it matches Windows' synchronous GetRenderTargetData semantics. The full patch against 25ca63f is included below (about 35 lines).

System information

  • GPU: NVIDIA RTX A4500 (a monitor is also connected to the Intel Arrow Lake iGPU)
  • Driver: NVIDIA 595.91.07 (open kernel modules)
  • OS: Ubuntu 26.04, kernel 7.0, GNOME Wayland
  • Wine/Proton: Proton Experimental (September 2026)
  • DXVK: v3.1.1-27-g25ca63f (as shipped in Proton Experimental)

Log files

  • d3d9 log excerpt: D3D9DeviceEx::ValidateSharedTexture: Found D3D11 texture, skipping validation. (import path)
Full patch (against 25ca63f)
diff
diff --git a/src/d3d9/d3d9_common_texture.h b/src/d3d9/d3d9_common_texture.h
index 59898597..2d68a64b 100644
--- a/src/d3d9/d3d9_common_texture.h
+++ b/src/d3d9/d3d9_common_texture.h
@@ -494,8 +494,19 @@ namespace dxvk {
 
     ID3D9VkInteropTexture* GetVkInterop() { return &m_d3d9Interop; }
 
+    /**
+     * \brief Application-provided backing memory (D3D9Ex SYSTEMMEM "user memory" resources)
+     *
+     * On Vista+, passing a pointer via pSharedHandle for a SYSTEMMEM resource makes that
+     * memory the resource's storage, so GPU->sysmem copies land directly in it.
+     */
+    void  SetUserMemory(void* pMemory) { m_userMemory = pMemory; }
+    void* GetUserMemory() const { return m_userMemory; }
+
   private:
 
+    void*                         m_userMemory = nullptr;
+
     D3D9DeviceEx*                 m_device;
     D3D9_COMMON_TEXTURE_DESC      m_desc;
     D3DRESOURCETYPE               m_type;
diff --git a/src/d3d9/d3d9_device.cpp b/src/d3d9/d3d9_device.cpp
index 9b72bb2e..31fdc34b 100644
--- a/src/d3d9/d3d9_device.cpp
+++ b/src/d3d9/d3d9_device.cpp
@@ -658,6 +659,7 @@ namespace dxvk {
       const Com<D3D9Texture2D> texture = new D3D9Texture2D(this, &desc, isExtended, pSharedHandle);
 
       m_initializer->InitTexture(texture->GetCommonTexture(), initialData);
+      texture->GetCommonTexture()->SetUserMemory(initialData);
       *ppTexture = texture.ref();
 
       if (desc.Pool == D3DPOOL_DEFAULT)
@@ -1193,6 +1195,23 @@ namespace dxvk {
     dstTexInfo->SetNeedsReadback(dst->GetSubresource(), true);
     TrackTextureMappingBufferSequenceNumber(dstTexInfo, dst->GetSubresource());
 
+    // Application-provided sysmem storage: the app expects the pixels in its own memory
+    // without locking, so wait for the copy and write them back like Windows would.
+    if (void* userMemory = dstTexInfo->GetUserMemory()) {
+      D3DLOCKED_RECT locked;
+      if (SUCCEEDED(dst->LockRect(&locked, nullptr, D3DLOCK_READONLY))) {
+        const DxvkFormatInfo* fmtInfo = lookupFormatInfo(dstTexInfo->GetFormatMapping().Format);
+        const uint32_t rowBytes = dstTexExtent.width * fmtInfo->elementSize;
+        const uint32_t pitch = align(rowBytes, 4u);
+        for (uint32_t y = 0; y < dstTexExtent.height; y++) {
+          std::memcpy(reinterpret_cast<uint8_t*>(userMemory) + size_t(y) * pitch,
+                      reinterpret_cast<const uint8_t*>(locked.pBits) + size_t(y) * locked.Pitch,
+                      std::min<uint32_t>(rowBytes, uint32_t(locked.Pitch)));
+        }
+        dst->UnlockRect();
+      }
+    }
+
     return D3D_OK;
   }
 
@@ -4404,6 +4423,7 @@ namespace dxvk {
       const bool isExtended = m_d3dCompatibility.test(D3DCompatibility::D3D9Ex);
       const Com<D3D9Surface> surface = new D3D9Surface(this, &desc, isExtended, nullptr, pSharedHandle);
       m_initializer->InitTexture(surface->GetCommonTexture(), initialData);
+      surface->GetCommonTexture()->SetUserMemory(initialData);
       *ppSurface = surface.ref();
 
       if (desc.Pool == D3DPOOL_DEFAULT)
diff --git a/src/d3d9/d3d9_initializer.cpp b/src/d3d9/d3d9_initializer.cpp
index 469eebfa..595c54bb 100644
--- a/src/d3d9/d3d9_initializer.cpp
+++ b/src/d3d9/d3d9_initializer.cpp
@@ -52,7 +52,10 @@ namespace dxvk {
         throw DxvkError("D3D9: InitTexture: map failed");
     }
 
-    if (pTexture->GetImage() != nullptr)
+    // Don't clear imported shared images: another device (e.g. D3D11/ANGLE) may already have
+    // written to them, and D3D11's OpenSharedResource does not initialize imports either.
+    if (pTexture->GetImage() != nullptr
+     && pTexture->GetImage()->info().sharing.mode != DxvkSharedHandleMode::Import)
       InitDeviceLocalTexture(pTexture);
 
     if (mapPtr != nullptr) {
usermem.c: SYSTEMMEM user-memory + GetRenderTargetData test
c
/* usermem.exe : D3D9Ex SYSTEMMEM texture backed by app memory, filled via GetRenderTargetData */
#define COBJMACROS
#include <windows.h>
#include <d3d9.h>
#include <stdio.h>
#define W 64
#define H 32
int main(void)
{
    static DWORD mem[W * H];
    void *p = mem;
    IDirect3D9Ex *d3d; IDirect3DDevice9Ex *dev; D3DPRESENT_PARAMETERS pp = {0};
    IDirect3DSurface9 *rt, *sys; IDirect3DTexture9 *tex; HRESULT hr;
    HWND hwnd = CreateWindowA("STATIC", "um", WS_OVERLAPPEDWINDOW, 0, 0, 100, 100, NULL, NULL, NULL, NULL);
    memset(mem, 0x11, sizeof(mem));
    Direct3DCreate9Ex(D3D_SDK_VERSION, &d3d);
    pp.Windowed = TRUE; pp.SwapEffect = D3DSWAPEFFECT_DISCARD; pp.hDeviceWindow = hwnd;
    IDirect3D9Ex_CreateDeviceEx(d3d, 0, D3DDEVTYPE_HAL, hwnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &pp, NULL, &dev);
    IDirect3DDevice9Ex_CreateRenderTarget(dev, W, H, D3DFMT_A8R8G8B8, D3DMULTISAMPLE_NONE, 0, FALSE, &rt, NULL);
    IDirect3DDevice9Ex_ColorFill(dev, rt, NULL, D3DCOLOR_ARGB(255, 0, 0, 255));
    hr = IDirect3DDevice9Ex_CreateTexture(dev, W, H, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &tex, (HANDLE *)&p);
    printf("CreateTexture(user memory) hr=%08lx\n", hr);
    IDirect3DTexture9_GetSurfaceLevel(tex, 0, &sys);
    hr = IDirect3DDevice9Ex_GetRenderTargetData(dev, rt, sys);
    printf("GetRenderTargetData hr=%08lx\n", hr);
    printf("app memory pixel = %08lx (expect ff0000ff = blue)\n", mem[W * 5 + 5]);
    return 0;
}
sharetest.c: D3D11 → D3D11 → D3D9Ex shared-texture chain test
c
/* sharetest.exe : reproduce FS Golf's D3D11 -> D3D11 (ANGLE) -> D3D9Ex shared-texture chain and report pixels. */
#define COBJMACROS
#include <windows.h>
#include <d3d11.h>
#include <dxgi.h>
#include <d3d9.h>
#include <stdio.h>

#define W 64
#define H 64

static void check(HRESULT hr, const char *what)
{
    printf("%-40s hr=0x%08lx %s\n", what, (unsigned long)hr, SUCCEEDED(hr) ? "ok" : "FAILED");
    fflush(stdout);
}

/* Read one pixel of a D3D11 texture via a staging copy on its own device. */
static void read11(ID3D11Device *dev, ID3D11DeviceContext *ctx, ID3D11Texture2D *tex, const char *label)
{
    D3D11_TEXTURE2D_DESC d;
    ID3D11Texture2D *st;
    D3D11_MAPPED_SUBRESOURCE m;
    ID3D11Texture2D_GetDesc(tex, &d);
    d.Usage = D3D11_USAGE_STAGING; d.BindFlags = 0; d.MiscFlags = 0; d.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
    if (FAILED(ID3D11Device_CreateTexture2D(dev, &d, NULL, &st))) { printf("%s: staging failed\n", label); return; }
    ID3D11DeviceContext_CopyResource(ctx, (ID3D11Resource *)st, (ID3D11Resource *)tex);
    if (SUCCEEDED(ID3D11DeviceContext_Map(ctx, (ID3D11Resource *)st, 0, D3D11_MAP_READ, 0, &m))) {
        printf("%-40s pixel(BGRA)=%08x\n", label, ((DWORD *)m.pData)[W * 10 + 10]);
        ID3D11DeviceContext_Unmap(ctx, (ID3D11Resource *)st, 0);
    }
    ID3D11Texture2D_Release(st);
}

int main(int argc, char **argv)
{
    ID3D11Device *devA, *devB;
    ID3D11DeviceContext *ctxA, *ctxB;
    ID3D11Texture2D *texA, *texB;
    IDXGIResource *res;
    HANDLE share = NULL;
    D3D11_TEXTURE2D_DESC td = {0};
    ID3D11RenderTargetView *rtv;
    float red[4] = {1, 0, 0, 1};
    IDirect3D9Ex *d3d9;
    IDirect3DDevice9Ex *dev9;
    D3DPRESENT_PARAMETERS pp = {0};
    IDirect3DTexture9 *tex9 = NULL;
    IDirect3DSurface9 *surf9, *sys9;
    D3DLOCKED_RECT lr;
    HWND hwnd = CreateWindowA("STATIC", "sharetest", WS_OVERLAPPEDWINDOW, 0, 0, 100, 100, NULL, NULL, NULL, NULL);
    UINT flags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
    BOOL keyed = argc > 1 && !strcmp(argv[1], "keyed");

    check(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, flags, NULL, 0, D3D11_SDK_VERSION, &devA, NULL, &ctxA), "A: D3D11CreateDevice");
    td.Width = W; td.Height = H; td.MipLevels = 1; td.ArraySize = 1; td.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
    td.SampleDesc.Count = 1; td.Usage = D3D11_USAGE_DEFAULT;
    td.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
    td.MiscFlags = keyed ? D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX : D3D11_RESOURCE_MISC_SHARED;
    check(ID3D11Device_CreateTexture2D(devA, &td, NULL, &texA), "A: CreateTexture2D(shared)");
    check(ID3D11Texture2D_QueryInterface(texA, &IID_IDXGIResource, (void **)&res), "A: QI IDXGIResource");
    check(IDXGIResource_GetSharedHandle(res, &share), "A: GetSharedHandle");
    printf("share handle = %p\n", share);

    /* Device B plays the role of ANGLE: open the share handle and clear it red. */
    check(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, flags, NULL, 0, D3D11_SDK_VERSION, &devB, NULL, &ctxB), "B: D3D11CreateDevice");
    check(ID3D11Device_OpenSharedResource(devB, share, &IID_ID3D11Texture2D, (void **)&texB), "B: OpenSharedResource");
    check(ID3D11Device_CreateRenderTargetView(devB, (ID3D11Resource *)texB, NULL, &rtv), "B: CreateRenderTargetView");
    ID3D11DeviceContext_ClearRenderTargetView(ctxB, rtv, red);
    ID3D11DeviceContext_Flush(ctxB);
    Sleep(200);
    read11(devB, ctxB, texB, "B reads its own write");
    read11(devA, ctxA, texA, "A reads B's write");

    /* D3D9Ex plays the role of FS Golf's window side: open the same handle. */
    check(Direct3DCreate9Ex(D3D_SDK_VERSION, &d3d9), "9: Direct3DCreate9Ex");
    pp.Windowed = TRUE; pp.SwapEffect = D3DSWAPEFFECT_DISCARD; pp.hDeviceWindow = hwnd; pp.BackBufferFormat = D3DFMT_UNKNOWN;
    check(IDirect3D9Ex_CreateDeviceEx(d3d9, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
          D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_MULTITHREADED | D3DCREATE_FPU_PRESERVE, &pp, NULL, &dev9), "9: CreateDeviceEx");
    check(IDirect3DDevice9Ex_CreateTexture(dev9, W, H, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &tex9, &share), "9: CreateTexture(open shared)");
    if (!tex9) return 1;
    IDirect3DTexture9_GetSurfaceLevel(tex9, 0, &surf9);
    check(IDirect3DDevice9Ex_CreateOffscreenPlainSurface(dev9, W, H, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &sys9, NULL), "9: CreateOffscreenPlainSurface");
    check(IDirect3DDevice9Ex_GetRenderTargetData(dev9, surf9, sys9), "9: GetRenderTargetData");
    if (SUCCEEDED(IDirect3DSurface9_LockRect(sys9, &lr, NULL, D3DLOCK_READONLY))) {
        printf("%-40s pixel(ARGB)=%08x\n", "D3D9 reads the shared texture", ((DWORD *)lr.pBits)[W * 10 + 10]);
        IDirect3DSurface9_UnlockRect(sys9);
    }

    /* Second round: B writes green after D3D9 already opened it. */
    {
        float green[4] = {0, 1, 0, 1};
        ID3D11DeviceContext_ClearRenderTargetView(ctxB, rtv, green);
        ID3D11DeviceContext_Flush(ctxB);
        Sleep(200);
        IDirect3DDevice9Ex_GetRenderTargetData(dev9, surf9, sys9);
        if (SUCCEEDED(IDirect3DSurface9_LockRect(sys9, &lr, NULL, D3DLOCK_READONLY))) {
            printf("%-40s pixel(ARGB)=%08x\n", "D3D9 reads after B writes green", ((DWORD *)lr.pBits)[W * 10 + 10]);
            IDirect3DSurface9_UnlockRect(sys9);
        }
    }
    /* Third round: WPF-style D3D9 -> D3D9 hop. Copy into a D3D9-created shared render target on the
     * interop device, then open that on a second D3D9Ex device (WPF's render device) and read it. */
    {
        IDirect3DDevice9Ex *wpf;
        IDirect3DSurface9 *rt = NULL, *wsurf, *wsys;
        IDirect3DTexture9 *wtex = NULL;
        HANDLE h9 = NULL;
        check(IDirect3DDevice9Ex_CreateRenderTarget(dev9, W, H, D3DFMT_A8R8G8B8, D3DMULTISAMPLE_NONE, 0, FALSE, &rt, &h9), "9: CreateRenderTarget(shared)");
        printf("d3d9 share handle = %p\n", h9);
        check(IDirect3DDevice9Ex_StretchRect(dev9, surf9, NULL, rt, NULL, D3DTEXF_NONE), "9: StretchRect -> shared RT");
        {
            IDirect3DQuery9 *q;
            if (SUCCEEDED(IDirect3DDevice9Ex_CreateQuery(dev9, D3DQUERYTYPE_EVENT, &q))) {
                IDirect3DQuery9_Issue(q, D3DISSUE_END);
                while (IDirect3DQuery9_GetData(q, NULL, 0, D3DGETDATA_FLUSH) == S_FALSE) Sleep(1);
                IDirect3DQuery9_Release(q);
            }
        }
        check(IDirect3D9Ex_CreateDeviceEx(d3d9, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
              D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_MULTITHREADED | D3DCREATE_FPU_PRESERVE, &pp, NULL, &wpf), "W: CreateDeviceEx");
        check(IDirect3DDevice9Ex_CreateTexture(wpf, W, H, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &wtex, &h9), "W: CreateTexture(open d3d9 shared)");
        if (wtex) {
            IDirect3DTexture9_GetSurfaceLevel(wtex, 0, &wsurf);
            IDirect3DDevice9Ex_CreateOffscreenPlainSurface(wpf, W, H, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &wsys, NULL);
            check(IDirect3DDevice9Ex_GetRenderTargetData(wpf, wsurf, wsys), "W: GetRenderTargetData");
            if (SUCCEEDED(IDirect3DSurface9_LockRect(wsys, &lr, NULL, D3DLOCK_READONLY))) {
                printf("%-40s pixel(ARGB)=%08x\n", "WPF device reads the d3d9 shared RT", ((DWORD *)lr.pBits)[W * 10 + 10]);
                IDirect3DSurface9_UnlockRect(wsys);
            }
        }
        /* Texture->texture D3D9 sharing (shared RT texture created on the interop device). */
        {
            IDirect3DTexture9 *t2 = NULL, *t2w = NULL;
            IDirect3DSurface9 *t2s, *t2ws, *t2sys;
            HANDLE h2 = NULL;
            check(IDirect3DDevice9Ex_CreateTexture(dev9, W, H, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &t2, &h2), "9: CreateTexture(shared RT tex)");
            IDirect3DTexture9_GetSurfaceLevel(t2, 0, &t2s);
            check(IDirect3DDevice9Ex_StretchRect(dev9, surf9, NULL, t2s, NULL, D3DTEXF_NONE), "9: StretchRect -> shared RT tex");
            IDirect3DDevice9Ex_GetRenderTargetData(dev9, t2s, sys9);
            if (SUCCEEDED(IDirect3DSurface9_LockRect(sys9, &lr, NULL, D3DLOCK_READONLY))) {
                printf("%-40s pixel(ARGB)=%08x\n", "interop dev reads its shared RT tex", ((DWORD *)lr.pBits)[W * 10 + 10]);
                IDirect3DSurface9_UnlockRect(sys9);
            }
            check(IDirect3DDevice9Ex_CreateTexture(wpf, W, H, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &t2w, &h2), "W: CreateTexture(open d3d9 shared tex)");
            if (t2w) {
                IDirect3DTexture9_GetSurfaceLevel(t2w, 0, &t2ws);
                IDirect3DDevice9Ex_CreateOffscreenPlainSurface(wpf, W, H, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &t2sys, NULL);
                IDirect3DDevice9Ex_GetRenderTargetData(wpf, t2ws, t2sys);
                if (SUCCEEDED(IDirect3DSurface9_LockRect(t2sys, &lr, NULL, D3DLOCK_READONLY))) {
                    printf("%-40s pixel(ARGB)=%08x\n", "WPF dev reads opened shared tex", ((DWORD *)lr.pBits)[W * 10 + 10]);
                    IDirect3DSurface9_UnlockRect(t2sys);
                }
                /* Did opening wipe the interop device's copy? */
                IDirect3DDevice9Ex_GetRenderTargetData(dev9, t2s, sys9);
                if (SUCCEEDED(IDirect3DSurface9_LockRect(sys9, &lr, NULL, D3DLOCK_READONLY))) {
                    printf("%-40s pixel(ARGB)=%08x\n", "interop dev re-reads after WPF opened", ((DWORD *)lr.pBits)[W * 10 + 10]);
                    IDirect3DSurface9_UnlockRect(sys9);
                }
                /* Per-frame copy after both have it open. */
                IDirect3DDevice9Ex_StretchRect(dev9, surf9, NULL, t2s, NULL, D3DTEXF_NONE);
                {
                    IDirect3DQuery9 *q;
                    if (SUCCEEDED(IDirect3DDevice9Ex_CreateQuery(dev9, D3DQUERYTYPE_EVENT, &q))) {
                        IDirect3DQuery9_Issue(q, D3DISSUE_END);
                        while (IDirect3DQuery9_GetData(q, NULL, 0, D3DGETDATA_FLUSH) == S_FALSE) Sleep(1);
                        IDirect3DQuery9_Release(q);
                    }
                }
                IDirect3DDevice9Ex_GetRenderTargetData(wpf, t2ws, t2