Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

COMException in IDirect3DDevice9Ex.CreateRenderTarget when GLWpfControlSettings.Samples > 1 #138

Open
roccomartino opened this issue Aug 11, 2024 · 9 comments
Labels
4.0 bug Something isn't working
Milestone

Comments

@roccomartino
Copy link

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

@NogginBops
Copy link
Member

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.

@roccomartino
Copy link
Author

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
Copy link
Author

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?

@ddstlvd
Copy link

ddstlvd commented Oct 3, 2024

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.

@NogginBops
Copy link
Member

NogginBops commented Oct 3, 2024

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.

@ddstlvd
Copy link

ddstlvd commented Oct 3, 2024

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

@NogginBops
Copy link
Member

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

@Xerxes004
Copy link

@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

@NogginBops NogginBops added bug Something isn't working 4.0 labels Oct 31, 2024
@NogginBops NogginBops modified the milestones: 4.3.3, 3.3.1, 4.3.4 Oct 31, 2024
@NogginBops
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4.0 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants