Using D3DImage with DirectX 11 in WPF?

Ethan Kim 10 Reputation points
2023-01-25T08:14:37.7266667+00:00

Hi,

I'm trying to replace WriteableBitmap-based image display with D3Dimage for my WPF with .Net framework 4.8 program.

The reason that I want to use D3Dimage is to display a quite large 16bit grayscale or float image and to support contrast/brightness adjustment.

Because I render the surface using DirectX 11, I did the followings,

  1. I created a texture of DirectX 9 for render target which is used for D3Dimage backbuffer.
  2. I call CreateRenderTargetView of DirectX 11 using the handle received from the above creation of DirectX 9 texture.
  3. I call ID3D11DeviceContext::Flush after a series of DirectX 11 rendering commands.

Here is my question.

Is it enough to call ID3D11DeviceContext::Flush to synchronize DirectX11 of DirectX 9 texture and DirectX 9 texture?

I read Flush is a asynchronous function according to this [https://learn.microsoft.com/en-us/windows/win32/api/d3d11/nf-d3d11-id3d11devicecontext-flush. So I'm worried.

I'm asking this question because sometimes(not that frequently) I see flickering.(between ClearRenderTargetView state and all rendered state, this is my guess based on my analysis so far).

I also tried the following but it doesn't solve my problem.

ID3D11Query* pQuery = nullptr;
	D3D11_QUERY_DESC queryDesc;
	queryDesc.Query = D3D11_QUERY_EVENT;
	m_pD11Device->CreateQuery(&queryDesc, &pQuery);
	m_pD11DeviceContext->End(pQuery);
	m_pD11DeviceContext->Flush();
	while (m_pD11DeviceContext->GetData(pQuery, NULL, 0, 0) == S_FALSE)
	{ }

I also tried to solve the problem using [https://github.com/microsoft/WPFDXInterop but I experienced the same phenomenon.

When it is okay, it displays like this. I called ClearRenderTargetView with green color for the demonstration.case1

When it is not okay, it displays like this. I'm rendering overlays using WPF so it still displays. I only render image using D3DImage

case2

Thank you for reading.

Developer technologies | Windows Presentation Foundation
Developer technologies | .NET | Other
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. zhan zhan 0 Reputation points
    2023-10-27T22:58:18.52+00:00

    Hello,have you found some solutions?Do you use mutil id3d11device and device contex?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.