Using D3DImage with DirectX 11 in WPF?

Ethan Kim 10 Reputation points
Jan 25, 2023, 8:14 AM

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://video2.skills-academy.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.

.NET
.NET
Microsoft Technologies based on the .NET software framework.
4,018 questions
Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,806 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. zhan zhan 0 Reputation points
    Oct 27, 2023, 10:58 PM

    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 Answers by the question author, which helps users to know the answer solved the author's problem.