Repository: microsoft/terminal (language: cpp)

Issue:
Missing cursor when experimental text rendering engine is enabled in HDR enabled monitor
### Windows Terminal version

1.13.10395.0

### Windows build number

10.0.22000

### Other Software

Plain vanilla Powershell

### Steps to reproduce

1. Enable Experimental text rendering engine in the advanced submenu of the Powershell profile and save config.
2. Open a Windows Powershell, Powershell Core, or Command Prompt tab. **on an HDR monitor.**

### Expected Behavior

The cursor should appear and blink.

### Actual Behavior

No cursor at all, not even a solid cursor shows up.

**Disabling experimental rendering brings back a fully functional blinking cursor.
Moving the Terminal window to a monitor without HDR brings the cursor back.**



Discussion / hints:
If you don't mind, could you post your config file (a minimal one that reproduces your issue is enough), as well as a screenshot of your terminal while you've got input focus?
Interestingly if I print-screen the cursor isn't there (which is also what I see during use):

![image](https://user-images.githubusercontent.com/343550/154822144-c3d105f9-77c5-4b07-84cb-c67717962265.png)

and if I unfocus the window and print-screen the cursor isn't there:

![image](https://user-images.githubusercontent.com/343550/154822152-914fece1-fb0f-4503-accc-43c309c657a7.png)

but if I snipping-tool the window while it is focused the cursor renders:

![image](https://user-images.githubusercontent.com/343550/154822159-10e37545-2a96-4d9b-ac6d-aab629f8fd9a.png)

settings.json for reference:

[settings.json.txt](https://github.com/microsoft/terminal/files/8103140/settings.json.txt)


Your settings work for me:
![image](https://user-images.githubusercontent.com/2256941/154823376-2a62e40c-d4f4-47c7-8312-4ce5644e6ef9.png)

I wonder how I can reproduce your issue...
It's especially concerning that your cursor shows up if the snipping tool is running, which suggests that something must work in Windows Terminal (otherwise it would be consistently invisible).
I think I bisected the issue, the trigger seems to be HDR. In this video I start the bottom monitor with HDR disabled and the top monitor with HDR enabled. The cursor blinks on the non-HDR monitor and stops blinking when the window is moved to the HDR monitor. If I enable HDR on the bottom monitor the issue occurs on both monitors:

https://user-images.githubusercontent.com/343550/154824156-f3d0cdf9-6684-4223-9db1-8ca2859d5906.mp4

Snipping tool takes a non-HDR snapshot of the display buffer during the "freeze-frame" where you can select the portion of the screen to snip. Print-screen on the other hand takes an immediate HDR copy of the output buffer. This explains why the 2 modes behaved differently.

Finally this occurs on a machine with an AMD GPU and a machine with an Nvidia GPU and does not change if software rendering is used. This makes me feel it's not a hardware/driver specific issue rather something with the experimental renderer and HDR directly.



> If you don't mind, could you post your config file (a minimal one that reproduces your issue is enough), as well as a screenshot of your terminal while you've got input focus?

I am attaching the settings file and a screenshot of an active session. As you can see the cursor shows up in the capture, but it is not actually rendered on the screen. I am attaching the settings file. It fails both Windows Powershell and Powershell core. 
It must be related to the screen resolution and bit depth. When I move the terminal window to another monitor without HDR 4K, it works perfectly both with the new experimental text rendering activated and deactivated. The system uses an Intel GPU, but as far as I read, it was duplicated also with AMD and Nvidia GPUs.

[settings.json.txt](https://github.com/microsoft/terminal/files/8103287/settings.json.txt)
![Win+S](https://user-images.githubusercontent.com/22417711/154824681-2acd84fa-d329-4702-a8e9-d7a33d269e5e.jpg)



Fix patch:
diff --git a/src/renderer/atlas/shader_ps.hlsl b/src/renderer/atlas/shader_ps.hlsl
index 15a24ae6c0e..a6f74899a90 100644
--- a/src/renderer/atlas/shader_ps.hlsl
+++ b/src/renderer/atlas/shader_ps.hlsl
@@ -142,10 +142,13 @@ float4 main(float4 pos: SV_Position): SV_Target
     }
 
     // Layer 3 (optional):
-    // Uncolored cursors invert the cells color.
-    if ((cell.flags & CellFlags_Cursor) && cursorColor == INVALID_COLOR)
+    // Uncolored cursors are used as a mask that inverts the cells color.
+    [branch] if (cell.flags & CellFlags_Cursor)
     {
-        color.rgb = abs(glyphs[cellPos].rgb - color.rgb);
+        [flatten] if (cursorColor == INVALID_COLOR && glyphs[cellPos].a != 0)
+        {
+            color = float4(1 - color.rgb, 1);
+        }
     }
 
     // Layer 4:


Test patch: