Skip to content

Support renderer fast presents #7147

Closed
Closed

Description

@mrange

Description of the new feature/enhancement

The current renderer has a complex workflow in order to render a frame. If one are looking into providing animated backgrounds or terminal effects that require high FPS rates the process is too slow especially since terminal effects disables partial (faster) repaints.

In addition; in DxRenderer.cpp there is lot of copying back-n-forth between forward and back buffer to enable partial updates and terminal effects.

This proposal is to:

  1. Allow fast presents (60+ FPS) for renderers where it makes sense.
  2. Enable partial updates even if terminal effects are enabled.
  3. Simplify and speed up DxRenderer.

I realize this is probably not high on the list of "need to" stuff but if the retro terminal effects is a thing I think it makes sense to make it render fast enough to support other cool scenarios.

Proposed technical implementation details (optional)

Proposed design

Activity

  1. added
    Issue-Feature
    on Aug 1, 2020
  2. ghost added
    Needs-Triage
    on Aug 1, 2020
  3. ghost added
    Needs-Tag-Fix
    on Aug 1, 2020
  4. added a commit that references this issue on Aug 1, 2020
  5. zadjii-msft commented on Aug 3, 2020

    @zadjii-msft
    Member

    Huh, I like the idea. I know that we've been tossing around ideas for making the retro effect work with differential drawing for a bit now, but this might be cleaner. I'm gonna summon Michael Niksa (@miniksa) to get his thoughts on your spec (and fork), since he's our rendering expert

  6. added
    Area-Performance
    Area-Rendering
    Product-Terminal
    on Aug 3, 2020
  7. ghost removed
    Needs-Tag-Fix
    on Aug 3, 2020
  8. removed
    Needs-Triage
    on Aug 12, 2020
  9. mrange commented on Aug 16, 2020

    @mrange
    ContributorAuthor

    Hi. Anyone had a chance to look at the proposal?

  10. miniksa commented on Aug 17, 2020

    @miniksa
    Contributor

    I'll read this today. Sorry for the delay.

  11. miniksa commented on Aug 17, 2020

    @miniksa
    Contributor

    I like the initial proposal.

    I'm not sure where the assertion that the existing slow workflow is too slow for 60fps comes from. Is that specifically in the context of when a shader is applied? I don't think I've seen the partial rendering stalling us below 60fps on my machine for simple text...

    I don't mind the texture idea. It's not a problem if we use MORE of DX11 than before. The whole point of moving to DX was that we'd use more and more of it over time anyway. Also, having a sort of backing buffer that is drawn to and then composing it on the front is fine. I think I did something like that in the GDI renderer.

    Regarding the proposed impl:

    1. I definitely don't want a full invalidate on scroll. That's a big deal for outputting big.txt.
    2. Pixelshader always applied. I agree with your theoretical proposal to skip the shader route completely if no shader is applied. NOP shader is a creative idea, but I'd rather save all the memory overhead of not instantiating those things if no one is using them.

    For the fast present impl:
    A. For the renderers that don't support it, we generally return S_FALSE not S_OK. S_FALSE is still a SUCCEEDED() value, but it says that nothing was done or nothing needed to be done.
    B. I feel like in lieu of using the frame limiting number for the FastPresent function if this shouldn't just be tied up with the WaitUntilCanRender method which would allow a FastPresent to be called every time the Waitable swap chain says it's ready until another the rest of the terminal is ready for a repaint and regular Present. Additionally... I wonder if we can't just have FastPresent and Present be the same thing with each renderer realizing it either can re-present the previous frame or that it should just S_FALSE until someone paints again. That saves adding another interface method and might simplify the thread.cpp loop/conditions.

    Finally, we should continue to use Present1() where possible. There are significant performance advantages realized in the rest of the system rendering pipeline (specifically DirectComposition, the DWM, and any aware application that can use the additional metadata to do partial presentation such as Remote Desktop) by passing that data. I don't mind using Present for shaders enabled, but the common high-performance case must continue to use Present1.

  12. mrange commented on Aug 17, 2020

    @mrange
    ContributorAuthor
    1. my intention was to restore scroll partial invalidate but it was too much work for the prototype.
    2. Yes, the initial idea was the NOP shader but I am back tracking from that idea in favour of CopySubResource or something similar.

    WRT to Present1. I don't think Present1 is compatible with full screen shader effects but it could be possible to retain the current workflow and then have a separate workflow when shaders enabled. However, the drawback would be increased code-complexity.

    With fullscreen refresh needed for the current implementation of how shaders are enabled it feels that repainting the full frame and then apply a destructive shader effect on the full frame feels like it unnecessary wasteful compared to just applying a pixel shader on a pre existing texture.

    With that said I only have Debug built on my machine (disk space issues) and Debug is kind of sluggish at least for me.

    Retaining the existing workflow and having a separate flow for pixel shaders is a significant change and it will take me some time to produce a working prototype.

  13. 1 remaining item

  14. mrange commented on Aug 18, 2020

    @mrange
    ContributorAuthor

    I aware that DEBUG in C++ is very sluggish compared to RELEASE and I agree it's not a good measurement for good reasons. However, as this is at a conceptual stage currently I haven't bothered to do proper measurement. I guess I shouldn't have mentioned the performance reason without facts.

  15. mrange commented on Aug 18, 2020

    @mrange
    ContributorAuthor

    When it comes to Present1 the remote desktop is a good argument and a good test case where I can see the existing code flow being beneficial in terms over the approach in this proposal.

  16. zadjii-msft commented on Feb 18, 2021

    @zadjii-msft
    Member

    We don't really have an issue open already for "re-enable differential drawing when shaders are enabled", do we? I suppose this is the closest one.

    I probably should have read this thread closer before I tried messing with the shaders yesterday (dev/migrie/dol/messing-with-shaders-take-1). Whoops. Well, I guess I know what I'll be looking into next month 😉

  17. zadjii-msft commented on Jul 27, 2021

    @zadjii-msft
    Member

    I'm trying this out this week, and it's really close to working. I'm getting caught up in the scrolling bit though - I definitely don't want to do the InvalidateAll thing - that's the whole point of the optimization here, to not do that.

    Mårten Rånge (@mrange) do you have any pointers for how to do the

    my intention was to restore scroll partial invalidate but it was too much work for the prototype.

    thing you mentioned? Any pointers would be immensely helpful 😄

    My WIP branch is dev/migrie/fhl-2021/differential-pixel-shading, which is branched from dev/migrie/fhl-2021/more-shader-variables

  18. zadjii-msft commented on Jul 28, 2021

    @zadjii-msft
    Member

    Nevermind, I figured it out. I made two incredibly embarrassing mistakes

    • I forgot to pass some ComPtrs by ref into a function. Instead I was copy-constructing new ones, then creating objects into those copies, then assuming the value would persist to the caller. 🤦
    • I actually wasn't swapping the variables correctly. Thanks std::swap 🤦

    That's what I get for trying to write code with a head cold. It works now, and works well. I'm pretty confident you could leave shaders on all the time and not feel the pain with these changes. It even works acceptably to have cmatrix running with retro effects full screen on my slaptop (bless it's little heart)

    So now dev/migrie/fhl-2021/differential-pixel-shading looks a lot better. I gotta untie those branches but #shipit

  19. lhecker commented on Sep 1, 2022

    @lhecker
    Member

    With #13885 in place, our new text renderer can handle this situation now. Since shading on the GPU is fast, it simply redraws the entire screen on every frame. Sounds slow? With the retro shader enabled rendering my entire 4K monitor worth of content 144 times per second takes up about 2-5% of my GPU load.
    It'll ship, enabled by default, in Windows Terminal Preview 1.16 sometime soon. 🙂

  20. ghost added
    Needs-Tag-Fix
    on Sep 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-PerformanceArea-RenderingIssue-FeatureNeeds-Tag-FixProduct-Terminal

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions