microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
162.49k stars 28.65k forks source link

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

Open Tyriar opened 2 months ago

Tyriar commented 2 months ago

Parent issue: https://github.com/microsoft/vscode/issues/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:

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:

https://github.com/microsoft/vscode/blob/4f7eededdcbaadc8f9e1bc52c72188aa906684c2/src/vs/editor/browser/view/viewLayer.ts#L262 https://github.com/microsoft/vscode/blob/4f7eededdcbaadc8f9e1bc52c72188aa906684c2/src/vs/editor/browser/view/viewLayer.ts#L362

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

https://github.com/microsoft/vscode/blob/4f7eededdcbaadc8f9e1bc52c72188aa906684c2/src/vs/editor/browser/view/viewLayer.ts#L368-L370

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

https://github.com/microsoft/vscode/blob/4f7eededdcbaadc8f9e1bc52c72188aa906684c2/src/vs/editor/browser/viewParts/lines/viewLines.ts#L613-L614 https://github.com/microsoft/vscode/blob/4f7eededdcbaadc8f9e1bc52c72188aa906684c2/src/vs/editor/browser/viewParts/lines/viewLines.ts#L667-L671

Tyriar commented 2 months ago

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

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.