Repository: microsoft/terminal (language: cpp)

Issue:
Renderer encountered an unexpected error: -2147024809
### Windows Terminal version

1.16.2523.0

### Windows build number

10.0.19044.1889

### Other Software

I'm on an Intel Core i5-2500K CPU, using its integrated HD 3000 GPU. Graphics driver version 9.17.10.4459

### Steps to reproduce

Open Windows Terminal

### Expected Behavior

_No response_

### Actual Behavior

A "Warning" dialog pops up saying "Renderer encountered an unexpected error: -2147024809".

If I click OK it just pops up again, ad infinitum.

I assume it's related to the Atlas renderer that is now enabled by default in the preview version of Terminal.


Discussion / hints:
@lhecker there's an internal bug for this too. I thought the internal person was on DX but I might have been mistaken 
-2147024809 is `E_INVALIDARG`. Could you run [DebugView](https://docs.microsoft.com/en-us/sysinternals/downloads/debugview) and check if any failure messages are visible when launching Windows Terminal With AtlasEngine enabled?
@lhecker I might be using it wrong but nothing is logged, except when I close the Terminal app via the task bar ("Suspending").
I think I found the internal bug: MSFT-41000959, but that one is -2005270527 (`DXGI_ERROR_INVALID_CALL`).

The biggest problem is that the oldest, still functional Intel hardware that I personally have is an i7-6600U, which is clearly far newer than a i5-2500K. I can't really think of any reason why our engine would fail, as I ran it with the reference Direct3D driver all the way down to DirectX 9.1.

@noinkling If you'd like to help with this investigation, another thing you could try is to run `dxcpl` from the start menu. That application isn't entirely intuitive, but basically you do this:
![dxcpl](https://user-images.githubusercontent.com/2256941/190035983-b41e5daa-1a27-424b-8be2-083ae1afced8.png)

Afterwards you can modify the DirectX settings for Windows Terminal. For instance:
![dxcpl](https://user-images.githubusercontent.com/2256941/190036121-6cd2c491-c126-464e-b4d7-8f90d28492cd.png)

Just hit "Apply" afterwards and restart Windows Terminal. Once you're done with testing I strongly suggest to do this:
![dxcpl](https://user-images.githubusercontent.com/2256941/190036276-ea44ce22-37cc-4969-b60c-369fdf454aeb.png)

If that doesn't yield any insights in combination with DebugView, another option would be for you to send us a ETL trace as described here: https://github.com/microsoft/terminal/wiki/Capturing-a-Debug-ETL-Trace
However that requires you to install Windows Performance Recorder (WPR).

It's fine if you don't have the time to investigate this further. But unfortunately it might take a little bit to procure your hardware first.

If I had to take a guess I'd say that the problem is that the i5-2500K advertises DirectX 10.1 support to us but doesn't actually support all the features that we expect from 10.1. It's difficult for me to test this as the reference driver I'm using implements the full 10.1 spec whenever it advertises 10.1 and not just parts of it. The only possible way to reproduce this issue is thus by testing it on the actual hardware in question (an Intel HD 3000 iGPU).
@lhecker With just the debug setting on, DebugView now shows this message:

> [8796] D3D11 ERROR: ID3D11Device::CreatePixelShader: Shader uses features (Raw or Structured Buffers) not supported by this device. Use the CheckFeatureSupport() API with D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS to discover support for these features if using D3D_FEATURE_LEVEL_10_*. [ STATE_CREATION ERROR #192: CREATEPIXELSHADER_INVALIDSHADERBYTECODE]

Terminal does work when selecting 9_3 or below for the feature level limit. The error happens again when selecting 10_0 or above.

I can confirm that the GPU is supposed to support the DirectX 10.1 feature level, dxdiag and GPU-Z say the same thing.
> Direct3D 10.x devices (`D3D_FEATURE_LEVEL_10_0`, `D3D_FEATURE_LEVEL_10_1`) can ***optionally*** support Compute Shader model 4.0 or 4.1.

Whoops. So it actually really doesn't support all the features we expect from 10.1 devices...
...because we expect too much from 10.1 devices. 😓
I'll submit a PR to fix this tomorrow. Thank you so much for helping us debug this!

In the meantime I'd suggest to disable AtlasEngine in the settings tab (there's a switch under "Rendering"). Once a bug fix has shipped, our bot will post a notification in this issue and you could try running the new engine once again. 🙂
> In the meantime I'd suggest to disable AtlasEngine in the settings tab (there's a switch under "Rendering").

FYI for anyone who can't access the settings due to the error making the Terminal unusable: Edit the settings JSON file manually (see https://docs.microsoft.com/en-us/windows/terminal/install#settings-json-file it's under `%LOCALAPPDATA%\Packages\Microsoft.WindowsTerminalPreview_8wekyb3d8bbwe\LocalState\settings.json` for the Windows Store release & Terminal Preview) and add:

```json
"defaults": {
  "useAtlasEngine": false
},
```

into `profiles` or `"useAtlasEngine": false` to any profile.

Fix patch:
diff --git a/src/renderer/atlas/AtlasEngine.cpp b/src/renderer/atlas/AtlasEngine.cpp
index 983b4cd082b..dcb91353230 100644
--- a/src/renderer/atlas/AtlasEngine.cpp
+++ b/src/renderer/atlas/AtlasEngine.cpp
@@ -639,8 +639,6 @@ void AtlasEngine::_createResources()
     }
 #endif // NDEBUG
 
-    const auto featureLevel = _r.device->GetFeatureLevel();
-
     {
         wil::com_ptr<IDXGIAdapter1> dxgiAdapter;
         THROW_IF_FAILED(_r.device.query<IDXGIObject>()->GetParent(__uuidof(dxgiAdapter), dxgiAdapter.put_void()));
@@ -648,7 +646,23 @@ void AtlasEngine::_createResources()
 
         DXGI_ADAPTER_DESC1 desc;
         THROW_IF_FAILED(dxgiAdapter->GetDesc1(&desc));
-        _r.d2dMode = debugForceD2DMode || featureLevel < D3D_FEATURE_LEVEL_10_0 || WI_IsAnyFlagSet(desc.Flags, DXGI_ADAPTER_FLAG_REMOTE | DXGI_ADAPTER_FLAG_SOFTWARE);
+        _r.d2dMode = debugForceD2DMode || WI_IsAnyFlagSet(desc.Flags, DXGI_ADAPTER_FLAG_REMOTE | DXGI_ADAPTER_FLAG_SOFTWARE);
+    }
+
+    const auto featureLevel = _r.device->GetFeatureLevel();
+
+    if (featureLevel < D3D_FEATURE_LEVEL_10_0)
+    {
+        _r.d2dMode = true;
+    }
+    else if (featureLevel < D3D_FEATURE_LEVEL_11_0)
+    {
+        D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS options;
+        THROW_IF_FAILED(_r.device->CheckFeatureSupport(D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &options, sizeof(options)));
+        if (!options.ComputeShaders_Plus_RawAndStructuredBuffers_Via_Shader_4_x)
+        {
+            _r.d2dMode = true;
+        }
     }
 
     if (!_r.d2dMode)


Test patch: