GLWpfControl icon indicating copy to clipboard operation
GLWpfControl copied to clipboard

COMException in IDirect3DDevice9Ex.CreateRenderTarget when GLWpfControlSettings.Samples > 1

Open roccomartino opened this issue 1 year ago • 9 comments

after commit "Use share handles, this fixes AMD integrated graphics" (#131 ) the control consistently crashes with System.Runtime.InteropServices.COMException: '0x8876086C' during the IDirect3DDevice9Ex.CreateRenderTarget call whenever GLWpfControlSettings.Samples is set to a value greater than 1

  • NVIDIA GeForce RTX 3070 Laptop
  • Windows 11
  • .NET 8

StackTrace: System.Private.CoreLib.dll!System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(int errorCode) Riga 849 GLWpfControl.dll!OpenTK.Wpf.Interop.DXInterop.CheckHResult(int hresult) Riga 36 GLWpfControl.dll!OpenTK.Wpf.Interop.DXInterop.IDirect3DDevice9Ex.CreateRenderTarget(int width, int height, OpenTK.Wpf.Interop.Format format, OpenTK.Wpf.Interop.MultisampleType multisample, int multisampleQuality, bool lockable, out OpenTK.Wpf.Interop.DXInterop.IDirect3DSurface9 surfaceHandle, ref nint sharedHandle) Riga 298 GLWpfControl.dll!OpenTK.Wpf.GLWpfControlRenderer.ReallocateFramebufferIfNeeded(double width, double height, double dpiScaleX, double dpiScaleY, OpenTK.Wpf.Interop.Format format, OpenTK.Wpf.Interop.MultisampleType msaaType) Riga 104 GLWpfControl.dll!OpenTK.Wpf.GLWpfControl.OnRender(System.Windows.Media.DrawingContext drawingContext) Riga 251

Thanks for your work

roccomartino avatar Aug 11 '24 17:08 roccomartino

Yeah this is a known issue documented in #131. I gave not been able to figure out why this issue occurs or how to diagnose the issue. If you have any ideas I'm all ears.

NogginBops avatar Aug 11 '24 17:08 NogginBops

I've been troubleshooting this issue for hours. In my specific use case, I don't require multisampling so I can proceed without it. I'll step away for a bit and then return to the problem.

roccomartino avatar Aug 12 '24 12:08 roccomartino

Perhaps I found something interesting. My goal was to debug the disassembled code of d3d9.dll while the program was running, but I couldn't figure out how to do it (I'm quietly new to Microsoft tools and SO), so I had to resort to a manual inspection. Through this manual examination, I observed that the CreateRenderTarget, at a certain point, refers to the string 'Multisample surfaces are not shareable. CreateRenderTarget/CreateDepthStencil fails' and subsequently returns the error code 0x8876086C. It's possible that there isn't a solution to this problem. Do you know where DirectX writes its log messages?

roccomartino avatar Aug 12 '24 16:08 roccomartino

Any info on fixing this. I got my old code which was working on Winforms working on this control, but the display without the anti aliasing is horrible.

ddstlvd avatar Oct 03 '24 11:10 ddstlvd

No, not really. A workaround that is quite simple is to render to an MSAA framebuffer and blit to the wpf controls framebuffer as a resolve pass.

NogginBops avatar Oct 03 '24 11:10 NogginBops

Thanks for the information. Is it possible to provide a sample on how to do this for myself and future references?

ddstlvd avatar Oct 03 '24 13:10 ddstlvd

I can't really give you the code you need, but you should be able to figure framebuffers out from the wiki and learnopengl tutorial.

Framebuffer tutorial: https://learnopengl.com/Advanced-OpenGL/Framebuffers MSAA tutorial (see "Off-screen MSAA" section): https://learnopengl.com/Advanced-OpenGL/Anti-Aliasing OpenGL Wiki article on framebuffers: https://www.khronos.org/opengl/wiki/Framebuffer_Object

NogginBops avatar Oct 03 '24 13:10 NogginBops

@NogginBops you may need to check for those specific vendor ID's and force MSAA = 1. I wound up just doing MSAA myself using the method (more or less) described by learnopengl. Would you accept a PR with my hand-rolled MSAA implementation?

I did some digging to figure out why this issue is occurring because I really, really want to use OpenGL in my WPF project. I found several locations where folks are complaining about using MSAA > 1 in d3d9 on Iris Xe. From what I can gather, this issue is Intel Xe specific, and may even be vendor specific (this is just my conjecture). Most of the hardware mentioned is Dell and Lenovo, but that may be due to popularity. I am using a Dell PC with an i5-10400. I've tried pretty much every driver I could find from Dell and Intel, and get the same results always.

Example 1: https://community.intel.com/t5/Graphics/Iris-Xe-Bugs-and-Problems-Direct3D-NET-WPF-LineTopology-Double/m-p/1495360 Example 2: https://www.gamedev.net/forums/topic/716976-directx-issue-with-intel-iris-graphics/ Example 3: https://stackoverflow.com/questions/43399487/load-from-multisampled-texture-fails-on-some-intel-gpus

Xerxes004 avatar Oct 23 '24 17:10 Xerxes004

Moving this to 4.3.4 to make sure to follow it up to see that the issue is fixed in 4.3.3.

NogginBops avatar Oct 31 '24 20:10 NogginBops

This should be fixed with #151, closing. If this is not fixed, feel free to re-open.

NogginBops avatar Oct 06 '25 11:10 NogginBops