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

Avoid Adreno DXGI adapter on Win-ARM devices #13538

Merged
merged 2 commits into from
Dec 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/Windows/Avalonia.Win32/OpenGl/Angle/AngleWin32EglDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ public static AngleWin32EglDisplay CreateSharedD3D11Display(EglInterface egl)
}, AngleOptions.PlatformApi.DirectX11);
}

public static unsafe AngleWin32EglDisplay CreateD3D11Display(Win32AngleEglInterface egl,
bool preferDiscreteAdapter = false)
public static unsafe AngleWin32EglDisplay CreateD3D11Display(Win32AngleEglInterface egl)
{
var featureLevels = new[]
{
Expand All @@ -65,7 +64,9 @@ public static unsafe AngleWin32EglDisplay CreateD3D11Display(Win32AngleEglInterf
using var factory = MicroComRuntime.CreateProxyFor<IDXGIFactory1>(pDxgiFactory, true);

void* pAdapter = null;
if (preferDiscreteAdapter)
// As for now, we only need to redefine default adapter only on ARM64 just in case of Adreno GPU.
var redefineDefaultAdapter = RuntimeInformation.ProcessArchitecture == Architecture.Arm64;
if (redefineDefaultAdapter)
{
ushort adapterIndex = 0;
var adapters = new List<(IDXGIAdapter1 adapter, string name)>();
Expand All @@ -80,9 +81,14 @@ public static unsafe AngleWin32EglDisplay CreateD3D11Display(Win32AngleEglInterf

if (adapters.Count == 0)
throw new OpenGlException("No adapters found");

chosenAdapter = adapters
.OrderByDescending(x => x.name.Contains("nvidia") ? 2 : x.name.Contains("amd") ? 1 : 0)
.First().adapter.CloneReference();
.OrderByDescending(x =>
// Put adreno in lower priority - it's broken in Avalonia.
x.name.Contains("adreno") ? -1 : 0)
.First().adapter
.CloneReference();

foreach (var a in adapters)
a.adapter.Dispose();
}
Expand Down