Win32+Angle: reuse the first created D3D11 display #12574
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does the pull request do?
On Windows, when Angle + DirectX 11 are used (these are the defaults), a call to
D3D11CreateDevice
is made to ensure that D3D11 works correctly. However, this call is very slow: on my system, it's ≈65ms spent in native code (DirectX lib + Nvidia drivers).When the renderer starts, it makes the same call again. It's a bit faster, but not by much (≈50ms).
This PR reuses the first created display if possible, improving startup time in all scenarios, NativeAOT included.
Remarks
AngleWin32PlatformGraphics
has been split into two classes: D3D9 (shared) and D3D11 (non shared) since they use two distinct paths, making clearer which members are used.IPlatformGraphicsOpenGlContextFactory
isn't implemented anymore for D3D9: itsCreateContext
implementation was always throwing anyways. The only usage is inOpenGlControlBase
, which will fail a line earlier in this case:Avalonia/src/Avalonia.OpenGL/Controls/OpenGlControlBase.cs
Lines 84 to 85 in 4f08bce