Skip to content

Commit

Permalink
AtlasEngine: Fix ClearType being always enabled (#12705)
Browse files Browse the repository at this point in the history
HLSL uses 32-bit booleans, while C++ uses 8-bit ones aligned by 32-bit.
This meant that the shader was accessing uninitialized memory
forcing ClearType blending to be randomly enabled.

This regressed in commit 5964060.

## PR Checklist
* [x] I work here
* [x] Tests added/passed

## Validation Steps Performed
* ClearType blending works ✅
* Enabling transparent backgrounds forces grayscale blending ✅
  • Loading branch information
lhecker authored Mar 17, 2022
1 parent 5072ee6 commit 830a422
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/renderer/atlas/AtlasEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,8 @@ namespace Microsoft::Console::Render
// * Members cannot straddle 16 byte boundaries
// This means a structure like {u32; u32; u32; u32x2} would require
// padding so that it is {u32; u32; u32; <4 byte padding>; u32x2}.
// * bool will probably not work the way you want it to,
// because HLSL uses 32-bit bools and C++ doesn't.
alignas(sizeof(f32x4)) f32x4 viewport;
alignas(sizeof(f32x4)) f32 gammaRatios[4]{};
alignas(sizeof(f32)) f32 enhancedContrast = 0;
Expand All @@ -565,7 +567,7 @@ namespace Microsoft::Console::Render
alignas(sizeof(u32)) u32 backgroundColor = 0;
alignas(sizeof(u32)) u32 cursorColor = 0;
alignas(sizeof(u32)) u32 selectionColor = 0;
alignas(sizeof(u32)) bool useClearType = 0;
alignas(sizeof(u32)) u32 useClearType = 0;
#pragma warning(suppress : 4324) // 'ConstBuffer': structure was padded due to alignment specifier
};

Expand Down
2 changes: 1 addition & 1 deletion src/renderer/atlas/shader_ps.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ cbuffer ConstBuffer : register(b0)
uint backgroundColor;
uint cursorColor;
uint selectionColor;
bool useClearType;
uint useClearType;
};
StructuredBuffer<Cell> cells : register(t0);
Texture2D<float4> glyphs : register(t1);
Expand Down

0 comments on commit 830a422

Please sign in to comment.