[PR #5185] [MERGED] Render row-by-row instead of invalidating entire screen #26158

Open
opened 2026-01-31 09:14:19 +00:00 by claunia · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/microsoft/terminal/pull/5185
Author: @miniksa
Created: 3/30/2020
Status: Merged
Merged: 4/13/2020
Merged by: @undefined

Base: masterHead: dev/miniksa/dx_bitmap_rows


📝 Commits (10+)

  • 7e8f039 Start moving dx renderer onto bitmap.
  • b46b5d0 it works!
  • 78c1bc1 try to get present1 working and get mad because std::vector is bad.
  • 39d67e3 Merge branch 'master' into dev/miniksa/dx_bitmap
  • 777524a Change invalidation to full rows to restore ligature drawing.
  • a15af9b Add tests for til and round out the operators.
  • ac01c0b code format
  • c478983 code format and audit mode.
  • f39b352 Dustin's suggestion about helper for invalidating rectangles .
  • 0d863c2 Fix selection issues.

📊 Changes

17 files changed (+762 additions, -431 deletions)

View changed files

📝 src/cascadia/TerminalControl/TermControl.cpp (+5 -0)
📝 src/cascadia/TerminalCore/Terminal.cpp (+13 -2)
📝 src/inc/til.h (+1 -1)
📝 src/inc/til/bitmap.h (+8 -3)
📝 src/inc/til/operators.h (+0 -4)
📝 src/inc/til/point.h (+13 -0)
📝 src/inc/til/rectangle.h (+48 -4)
📝 src/inc/til/size.h (+13 -0)
📝 src/renderer/base/renderer.cpp (+68 -7)
📝 src/renderer/base/renderer.hpp (+1 -0)
📝 src/renderer/dx/DxRenderer.cpp (+345 -394)
📝 src/renderer/dx/DxRenderer.hpp (+10 -16)
📝 src/renderer/dx/precomp.h (+5 -0)
📝 src/til/ut_til/BitmapTests.cpp (+8 -0)
📝 src/til/ut_til/PointTests.cpp (+27 -0)
📝 src/til/ut_til/RectangleTests.cpp (+170 -0)
📝 src/til/ut_til/SizeTests.cpp (+27 -0)

📄 Description

Summary of the Pull Request

Adjusts DirectX renderer to use til::bitmap to track invalidation
regions. Uses special modification to invalidate a row-at-a-time to
ensure ligatures and NxM glyphs continue to work.

References

Likely helps #1064

PR Checklist

Detailed Description of the Pull Request / Additional comments

  • Applies til::bitmap as the new invalidation scheme inside the
    DirectX renderer and updates all entrypoints for collecting
    invalidation data to coalesce into this structure.
  • Semi-permanently routes all invalidations through a helper method
    _InvalidateRectangle that will expand any invalidation to cover the
    entire line. This ensures that ligatures and NxM glyphs will continue
    to render appropriately while still allowing us to dramatically reduce
    the number of lines drawn overall. In the future, we may come up with
    a tighter solution than line-by-line invalidation and can modify this
    helper method appropriately at that later date to further scope the
    invalid region.
  • Ensures that the experimental.retroTerminalEffects feature continues
    to invalidate the entire display on start of frame as the shader is
    applied at the end of the frame composition and will stack on itself
    in an amusing fashion when we only redraw part of the display.
  • Moves many member variables inside the DirectX renderer into the new
    til::size, til::point, and til::rectangle methods to facilitate
    easier management and mathematical operations. Consequently adds
    try/catch blocks around many of the already-existing noexcept
    methods to deal with mathematical or casting failures now detected by
    using the support classes.
  • Corrects TerminalCore redraw triggers to appropriately communicate
    scrolling circumstances to the renderer so it can optimize the draw
    regions appropriately.
  • Fixes an issue in the base Renderer that was causing overlapping
    scroll regions due to behavior of Viewport::TrimToViewport modifying
    the local. This fix is "good enough" for now and should go away when
    Viewport is fully migrated to til::rectangle.
  • Adds multiplication and division operators to til::rectangle and
    supporting tests. These operates will help scale back and forth
    between a cell-based rectangle and a pixel-based rectangle. They take
    special care to ensure that a pixel rectangle being divided downward
    back to cells will expand (with the ceiling division methods) to cover
    a full cell when even one pixel inside the cell is touched (as is how
    a redraw would have to occur).
  • Blocks off trace logging of invalid regions if no one is listening to
    optimize performance.
  • Restores full usage of IDXGISwapChain1::Present1 to accurately and
    fully communicate dirty and scroll regions to the underlying DirectX
    framework. This additional information allows the framework to
    optimize drawing between frames by eliminating data transfer of
    regions that aren't modified and shuffling frames in place. See
    Remarks
    for more details.
  • Updates til::bitmap set methods to use more optimized versions of
    the setters on the dynamic_bitset<> that can bulk fill bits as the
    existing algorithm was noticeably slow after applying the
    "expand-to-row" helper to the DirectX renderer invalidation.
  • All til import hierarchy is now handled in the parent til.h file
    and not in the child files to prevent circular imports from happening.
    We don't expect the import of any individual library file, only the
    base one. So this should be OK for now.

Validation Steps Performed

  • Ran cmatrix, cmatrix -u0, and cacafire after changes were made.
  • Made a bunch of ligatures with Cascadia Code in the Terminal
    before/after the changes and confirmed they still ligate.
  • Ran dir in Powershell and fixed the scrolling issues
  • Clicked all over the place and dragged to make sure selection works.
  • Checked retro terminal effect manually with Powershell.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/microsoft/terminal/pull/5185 **Author:** [@miniksa](https://github.com/miniksa) **Created:** 3/30/2020 **Status:** ✅ Merged **Merged:** 4/13/2020 **Merged by:** [@undefined](undefined) **Base:** `master` ← **Head:** `dev/miniksa/dx_bitmap_rows` --- ### 📝 Commits (10+) - [`7e8f039`](https://github.com/microsoft/terminal/commit/7e8f0398c3c851c96189b1ef72f1c82feda7510e) Start moving dx renderer onto bitmap. - [`b46b5d0`](https://github.com/microsoft/terminal/commit/b46b5d0f6f0e09ce874c9a1097f7c24dc5cd6c85) it works! - [`78c1bc1`](https://github.com/microsoft/terminal/commit/78c1bc10f7680f3ada2e3ccdf317322e550afdcb) try to get present1 working and get mad because std::vector<bool> is bad. - [`39d67e3`](https://github.com/microsoft/terminal/commit/39d67e3859f9fac479212d5cb7dfce32269aaf3a) Merge branch 'master' into dev/miniksa/dx_bitmap - [`777524a`](https://github.com/microsoft/terminal/commit/777524a00f80c532ed45af2a022bb163a1923a1d) Change invalidation to full rows to restore ligature drawing. - [`a15af9b`](https://github.com/microsoft/terminal/commit/a15af9b3fd7c023fd380eb76b6dd2cdc34df63c0) Add tests for til and round out the operators. - [`ac01c0b`](https://github.com/microsoft/terminal/commit/ac01c0bd8f5e3b8f2d4aa39639d25cfa72119002) code format - [`c478983`](https://github.com/microsoft/terminal/commit/c4789836d5ae26bae5375fad37a3043f9913afe5) code format and audit mode. - [`f39b352`](https://github.com/microsoft/terminal/commit/f39b352b608ad854bf689d9e7e2ae77e7a4fbb7a) Dustin's suggestion about helper for invalidating rectangles . - [`0d863c2`](https://github.com/microsoft/terminal/commit/0d863c2ed190969b1eb56707030e10e17c711206) Fix selection issues. ### 📊 Changes **17 files changed** (+762 additions, -431 deletions) <details> <summary>View changed files</summary> 📝 `src/cascadia/TerminalControl/TermControl.cpp` (+5 -0) 📝 `src/cascadia/TerminalCore/Terminal.cpp` (+13 -2) 📝 `src/inc/til.h` (+1 -1) 📝 `src/inc/til/bitmap.h` (+8 -3) 📝 `src/inc/til/operators.h` (+0 -4) 📝 `src/inc/til/point.h` (+13 -0) 📝 `src/inc/til/rectangle.h` (+48 -4) 📝 `src/inc/til/size.h` (+13 -0) 📝 `src/renderer/base/renderer.cpp` (+68 -7) 📝 `src/renderer/base/renderer.hpp` (+1 -0) 📝 `src/renderer/dx/DxRenderer.cpp` (+345 -394) 📝 `src/renderer/dx/DxRenderer.hpp` (+10 -16) 📝 `src/renderer/dx/precomp.h` (+5 -0) 📝 `src/til/ut_til/BitmapTests.cpp` (+8 -0) 📝 `src/til/ut_til/PointTests.cpp` (+27 -0) 📝 `src/til/ut_til/RectangleTests.cpp` (+170 -0) 📝 `src/til/ut_til/SizeTests.cpp` (+27 -0) </details> ### 📄 Description ## Summary of the Pull Request Adjusts DirectX renderer to use `til::bitmap` to track invalidation regions. Uses special modification to invalidate a row-at-a-time to ensure ligatures and NxM glyphs continue to work. ## References Likely helps #1064 ## PR Checklist * [x] Closes #778 * [x] I work here. * [x] Manual testing performed. See Performance traces in #778. * [x] Automated tests for `til` changes. * [x] Am core contributor. And discussed with @DHowett-MSFT. ## Detailed Description of the Pull Request / Additional comments - Applies `til::bitmap` as the new invalidation scheme inside the DirectX renderer and updates all entrypoints for collecting invalidation data to coalesce into this structure. - Semi-permanently routes all invalidations through a helper method `_InvalidateRectangle` that will expand any invalidation to cover the entire line. This ensures that ligatures and NxM glyphs will continue to render appropriately while still allowing us to dramatically reduce the number of lines drawn overall. In the future, we may come up with a tighter solution than line-by-line invalidation and can modify this helper method appropriately at that later date to further scope the invalid region. - Ensures that the `experimental.retroTerminalEffects` feature continues to invalidate the entire display on start of frame as the shader is applied at the end of the frame composition and will stack on itself in an amusing fashion when we only redraw part of the display. - Moves many member variables inside the DirectX renderer into the new `til::size`, `til::point`, and `til::rectangle` methods to facilitate easier management and mathematical operations. Consequently adds `try/catch` blocks around many of the already-existing `noexcept` methods to deal with mathematical or casting failures now detected by using the support classes. - Corrects `TerminalCore` redraw triggers to appropriately communicate scrolling circumstances to the renderer so it can optimize the draw regions appropriately. - Fixes an issue in the base `Renderer` that was causing overlapping scroll regions due to behavior of `Viewport::TrimToViewport` modifying the local. This fix is "good enough" for now and should go away when `Viewport` is fully migrated to `til::rectangle`. - Adds multiplication and division operators to `til::rectangle` and supporting tests. These operates will help scale back and forth between a cell-based rectangle and a pixel-based rectangle. They take special care to ensure that a pixel rectangle being divided downward back to cells will expand (with the ceiling division methods) to cover a full cell when even one pixel inside the cell is touched (as is how a redraw would have to occur). - Blocks off trace logging of invalid regions if no one is listening to optimize performance. - Restores full usage of `IDXGISwapChain1::Present1` to accurately and fully communicate dirty and scroll regions to the underlying DirectX framework. This additional information allows the framework to optimize drawing between frames by eliminating data transfer of regions that aren't modified and shuffling frames in place. See [Remarks](https://docs.microsoft.com/en-us/windows/win32/api/dxgi1_2/nf-dxgi1_2-idxgiswapchain1-present1#remarks) for more details. - Updates `til::bitmap` set methods to use more optimized versions of the setters on the `dynamic_bitset<>` that can bulk fill bits as the existing algorithm was noticeably slow after applying the "expand-to-row" helper to the DirectX renderer invalidation. - All `til` import hierarchy is now handled in the parent `til.h` file and not in the child files to prevent circular imports from happening. We don't expect the import of any individual library file, only the base one. So this should be OK for now. ## Validation Steps Performed - Ran `cmatrix`, `cmatrix -u0`, and `cacafire` after changes were made. - Made a bunch of ligatures with `Cascadia Code` in the Terminal before/after the changes and confirmed they still ligate. - Ran `dir` in Powershell and fixed the scrolling issues - Clicked all over the place and dragged to make sure selection works. - Checked retro terminal effect manually with Powershell. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-31 09:14:19 +00:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#26158