AvaloniaUI / Avalonia

Develop Desktop, Embedded, Mobile and WebAssembly apps with C# and XAML. The most popular .NET UI client technology
https://avaloniaui.net
MIT License
24.51k stars 2.12k forks source link

D3D11CreateDevice+Hardware crashes and fallback doesn't work #16062

Open maxkatz6 opened 1 week ago

maxkatz6 commented 1 week ago
          @Sewer56 looks like this PR break Angle/DX on my machine:
[OpenGL]Unable to initialize ANGLE-based rendering with DirectX11 : 'System.ArgumentException: Value does not fall within the expected range.
   at Avalonia.Win32.DirectX.DirectXUnmanagedMethods.D3D11CreateDevice(IntPtr adapter, D3D_DRIVER_TYPE DriverType, IntPtr Software, UInt32 Flags, D3D_FEATURE_LEVEL[] pFeatureLevels, UInt32 FeatureLevels, UInt32 SDKVersion, IntPtr& ppDevice, D3D_FEATURE_LEVEL& pFeatureLevel, IntPtr* ppImmediateContext)
   at Avalonia.Win32.OpenGl.Angle.AngleWin32EglDisplay.CreateD3D11Device(IDXGIAdapter1 chosenAdapter, D3D_FEATURE_LEVEL[] featureLevels) in E:\Work\Projects\AvaloniaCopy1\src\Windows\Avalonia.Win32\OpenGl\Angle\AngleWin32EglDisplay.cs:line 175
   at Avalonia.Win32.OpenGl.Angle.AngleWin32EglDisplay.CreateD3D11Display(Win32AngleEglInterface egl) in E:\Work\Projects\AvaloniaCopy1\src\Windows\Avalonia.Win32\OpenGl\Angle\AngleWin32EglDisplay.cs:line 106
   at Avalonia.Win32.OpenGl.Angle.D3D11AngleWin32PlatformGraphics.TryCreate(Win32AngleEglInterface egl) in E:\Work\Projects\AvaloniaCopy1\src\Windows\Avalonia.Win32\OpenGl\Angle\D3D11AngleWin32PlatformGraphics.cs:line 77'
[OpenGL]Unknown requested PlatformApi 'DirectX11'

There are couple of problems:

  1. D3D11CreateDevice+HARDWARE fails here with invalid argument. Don't really know why.
  2. D3D11CreateDevice+SOFTWARE fails too, but UNKNOWN works fine.
  3. D3D11CreateDevice return type should be "int" (non-void), and PreserveSig = false should be removed, if you want to implement fallback logic.
  4. Before each fallback, there should be a warning log message, so developers can easier find this problem. Something like:
    Logger.TryGet(LogEventLevel.Warning, LogArea.Win32Platform)?.Log(null, "Unable to create hardware ID3D11Device, error code = {ErrorCode}", $"0x{result:X}")

Originally posted by @maxkatz6 in https://github.com/AvaloniaUI/Avalonia/issues/16035#issuecomment-2177788039

Sewer56 commented 1 week ago

This is technically fixed by

And the feedback was implemented in:

As per https://github.com/AvaloniaUI/Avalonia/pull/16035#issuecomment-2177884713, I'm not sure what the current course of action should be.