FNA-XNA / FNA3D

FNA3D - 3D Graphics Library for FNA
http://fna-xna.github.io/
Other
287 stars 48 forks source link

Regression: D3D11 fails with NoSuitableGraphicsDeviceException in Wine #199

Open madewokherd opened 9 months ago

madewokherd commented 9 months ago

Tested for merging into Wine Mono, but this most likely affects Wine generally. I used One Finger Death Punch to test.

Excerpt of terminal output:

01ac:fixme:d3d11:d3d11_device_CheckFormatSupport iface 02BBD018, format 28, format_support 0060E404 partial-stub!

Unhandled Exception:
Microsoft.Xna.Framework.Graphics.NoSuitableGraphicsDeviceException: Unsupported backbuffer DXGI format
  at Microsoft.Xna.Framework.Graphics.GraphicsDevice..ctor (Microsoft.Xna.Framework.Graphics.GraphicsAdapter adapter, Microsoft.Xna.Framework.Graphics.GraphicsProfile graphicsProfile, Microsoft.Xna.Framework
.Graphics.PresentationParameters presentationParameters) [0x000e8] in <4f068e9dcd4d43d0a8fa447441bae910>:0 
  at Microsoft.Xna.Framework.GraphicsDeviceManager.Microsoft.Xna.Framework.IGraphicsDeviceManager.CreateDevice () [0x000db] in <4f068e9dcd4d43d0a8fa447441bae910>:0 
  at Microsoft.Xna.Framework.Game.DoInitialize () [0x00031] in <4f068e9dcd4d43d0a8fa447441bae910>:0 
  at Microsoft.Xna.Framework.Game.Run () [0x00011] in <4f068e9dcd4d43d0a8fa447441bae910>:0 
  at One_Finger_Death_Punch.Program.Main (System.String[] args) [0x00008] in <3ace895f2277420d87519d83d7f08e21>:0 

So it's probably something with Wine's CheckFormatSupport stub.

madewokherd commented 9 months ago

Forgot to mention: the first bad commit is 508d572a675f016df7ec90431e40ce6338854b0d

madewokherd commented 9 months ago

A quick test shows that Wine was not using the DXGI_FORMAT_R8G8B8A8_UNORM fallback, so I guess DXGI_FORMAT_R8G8B8A8_UNORM_SRGB does work but CheckFormatSupport isn't able to determine that.

madewokherd commented 9 months ago

Let me know if reporting this to Winehq would be appropriate. I'm kinda in over my head here.

flibitijibibo commented 9 months ago

Looks like WineD3D is missing the SUPPORT_DISPLAY flags, which are required for some formats depending on the feature level: https://learn.microsoft.com/en-us/previous-versions/windows/desktop/legacy/bb173064(v=vs.85)

This will likely come up more often as HDR adoption in particular increases.

flibitijibibo commented 9 months ago

Not sure if the WineHQ Bugzilla has a ticket yet, but I wrote a quick patch that would fix this for WineD3D:

diff --git a/dlls/d3d11/device.c b/dlls/d3d11/device.c
index 061fd57fe09..bfe0a92f805 100644
--- a/dlls/d3d11/device.c
+++ b/dlls/d3d11/device.c
@@ -3960,6 +3960,32 @@ static HRESULT STDMETHODCALLTYPE d3d11_device_CheckFormatSupport(ID3D11Device2 *
                 | D3D11_FORMAT_SUPPORT_MULTISAMPLE_LOAD;
     }

+    if (feature_level >= D3D_FEATURE_LEVEL_9_1)
+    {
+        if (format == DXGI_FORMAT_R8G8B8A8_UNORM ||
+                format == DXGI_FORMAT_R8G8B8A8_UNORM_SRGB ||
+                format == DXGI_FORMAT_B8G8R8A8_UNORM ||
+                format == DXGI_FORMAT_B8G8R8A8_UNORM_SRGB)
+        {
+            *format_support |= D3D11_FORMAT_SUPPORT_DISPLAY;
+        }
+    }
+    if (feature_level >= D3D_FEATURE_LEVEL_10_0)
+    {
+        if (format == DXGI_FORMAT_R16G16B16A16_FLOAT ||
+                format == DXGI_FORMAT_R10G10B10A2_UNORM)
+        {
+            *format_support |= D3D11_FORMAT_SUPPORT_DISPLAY;
+        }
+    }
+    if (feature_level >= D3D_FEATURE_LEVEL_11_0)
+    {
+        if (format == DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM)
+        {
+            *format_support |= D3D11_FORMAT_SUPPORT_DISPLAY;
+        }
+    }
+
     return *format_support ? S_OK : E_FAIL;
 }

I'm sure the WineD3D team would want something more thorough/accurate-to-hardware but this at least covers the surface formats mandated by the D3D feature levels!

madewokherd commented 9 months ago

They might be OK with a partial solution like this.

flibitijibibo commented 8 months ago

Since we didn't have any other commits this month I went ahead and added a quick workaround that should make XNA games happy:

https://github.com/FNA-XNA/FNA3D/commit/085e573d4228ce7bf6abf0e48e2710cbc113f973

We'll undo this when WineD3D is caught up! Will keep this issue open to track on our end.

madewokherd commented 8 months ago

Thanks, it works so I just merged the update. At some point I'll file a Winehq bug and link it here.

madewokherd commented 8 months ago

Filed a Winehq bug: https://bugs.winehq.org/show_bug.cgi?id=56383