Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose an internal API that will let us plug in a separate render stack #221202

Open
Tyriar opened this issue Jul 8, 2024 · 1 comment
Open
Assignees
Labels
editor-gpu Editor GPU rendering related issues feature-request Request for new features or functionality

Comments

@Tyriar
Copy link
Member

Tyriar commented Jul 8, 2024

Parent issue: #221145

The initial plan with the webgpu based is to provide a separate mode via a setting (editor.gpuAcceleration: 'on' | 'off'?) which will switch the rendering stack to a GPU-based one. The first step is for this renderer to simply fallback entirely to rendering lines using the DOM such that we can start self hosting on it and then incrementally swap out parts to render onto a canvas.

Some requirements:

  • The new renderer will need to create a canvas that sits below all the editor content, is sized to the viewport (excluding minimap/breadcrumbs) and has a fixed position (since moving it would cause a layout).
  • Initially this could cover just the editor viewport (.view-lines). Eventually we want to swap out the line numbers as well (.margin-view-overlays .line-numbers) since they're relatively expensive, ideally we would share the canvas for this.
  • We want to be able to incrementally swap out view parts of monaco as they are implemented on the GPU side, for example rulers would be an easy win.
  • The more we can isolate the GPU code the better as this feature will be experimental and opt-in for some time and we don't want to leak the complexity of dealing with webgpu to the rest of the codebase.

You can look at the parts outside of the gpu/ in tyriar/gpu_exploration for the parts that I needed to hook into to get it to work. Note that disableNonGpuRendering can mostly be ignored initially, this was used get a better idea of the kind of numbers if we could theoretically get by removing almost all DOM interaction.

VisibleLinesCollection owned the canvas and renderer:

private readonly _canvas: HTMLCanvasElement;

private _gpuRenderer: GpuViewLayerRenderer<T> | undefined;

VisibleLinesCollection disabled ViewLayerRenderer being created (would be needed for fallback?):

if (viewOverlays) {
renderer = new ViewLayerRenderer<T>(this.domNode.domNode, this._host, viewportData);
} else {

Forcing the DOM node to not shift around was done in ViewLines:

this.domNode.setWidth(this._context.viewLayout.getCurrentViewport().width);
this.domNode.setHeight(Math.min(this._context.viewLayout.getCurrentViewport().height, 1000000));

// (3) handle scrolling
this._linesContent.setLayerHinting(this._canUseLayerHinting);
this._linesContent.setContain('strict');
// this._linesContent.setTop(-adjustedScrollTop);
// this._linesContent.setLeft(-this._context.viewLayout.getCurrentScrollLeft());

@Tyriar Tyriar added feature-request Request for new features or functionality editor-gpu Editor GPU rendering related issues labels Jul 8, 2024
@Tyriar Tyriar added this to the July 2024 milestone Jul 8, 2024
@Tyriar
Copy link
Member Author

Tyriar commented Jul 9, 2024

Another approach that might work better is to allow view parts to optionally draw to a canvas. For example:

  • viewLayer.ts/view.ts or something similar manages the shared canvas and renderer object
  • viewParts/lines/gpu/ contains the logic to render to a canvas
  • viewParts/lines/ contains something that determines whether to draw via dom or gpu
  • We could then use the pattern for all view parts (viewParts/<part>/gpu)

I'm not sure about the persistence of object in viewParts/ but as long as we have a shared renderer object we would be able to set/fetch state on that if needed.

@hediet hediet modified the milestones: July 2024, August 2024 Jul 24, 2024
@hediet hediet modified the milestones: August 2024, September 2024 Aug 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
editor-gpu Editor GPU rendering related issues feature-request Request for new features or functionality
Projects
None yet
Development

No branches or pull requests

2 participants