Skip to content

Commit 3d96885

Browse files
committed
Clear and commit all render data on view zones changed
Fixes microsoft#233856
1 parent 3ef664f commit 3d96885

File tree

1 file changed

+45
-16
lines changed

1 file changed

+45
-16
lines changed

src/vs/editor/browser/gpu/fullFileRenderStrategy.ts

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { EditorOption } from '../../common/config/editorOptions.js';
99
import { CursorColumns } from '../../common/core/cursorColumns.js';
1010
import type { IViewLineTokens } from '../../common/tokens/lineTokens.js';
1111
import { ViewEventHandler } from '../../common/viewEventHandler.js';
12-
import type { ViewConfigurationChangedEvent, ViewLinesChangedEvent, ViewLinesDeletedEvent, ViewLinesInsertedEvent, ViewScrollChangedEvent, ViewTokensChangedEvent } from '../../common/viewEvents.js';
12+
import { ViewEventType, type ViewConfigurationChangedEvent, type ViewLinesChangedEvent, type ViewLinesDeletedEvent, type ViewLinesInsertedEvent, type ViewScrollChangedEvent, type ViewTokensChangedEvent, type ViewZonesChangedEvent } from '../../common/viewEvents.js';
1313
import type { ViewportData } from '../../common/viewLayout/viewLinesViewportData.js';
1414
import type { ViewLineRenderingData } from '../../common/viewModel.js';
1515
import type { ViewContext } from '../../common/viewModel/viewContext.js';
@@ -38,6 +38,8 @@ const enum CellBufferInfo {
3838
TextureIndex = 5,
3939
}
4040

41+
type QueuedBufferEvent = ViewLinesDeletedEvent | ViewZonesChangedEvent;
42+
4143
export class FullFileRenderStrategy extends ViewEventHandler implements IGpuRenderStrategy {
4244

4345
readonly wgsl: string = fullFileRenderStrategyWgsl;
@@ -61,7 +63,7 @@ export class FullFileRenderStrategy extends ViewEventHandler implements IGpuRend
6163
private _scrollOffsetValueBuffer: Float32Array;
6264
private _scrollInitialized: boolean = false;
6365

64-
private readonly _queuedBufferUpdates: [ViewLinesDeletedEvent[], ViewLinesDeletedEvent[]] = [[], []];
66+
private readonly _queuedBufferUpdates: [QueuedBufferEvent[], QueuedBufferEvent[]] = [[], []];
6567

6668
get bindGroupEntries(): GPUBindGroupEntry[] {
6769
return [
@@ -162,6 +164,18 @@ export class FullFileRenderStrategy extends ViewEventHandler implements IGpuRend
162164
return true;
163165
}
164166

167+
public override onZonesChanged(e: ViewZonesChangedEvent): boolean {
168+
this._upToDateLines[0].clear();
169+
this._upToDateLines[1].clear();
170+
171+
// Queue updates that need to happen on the active buffer, not just the cache. This is
172+
// deferred since the active buffer could be locked by the GPU which would block the main
173+
// thread.
174+
this._queueBufferUpdate(e);
175+
176+
return true;
177+
}
178+
165179
// #endregion
166180

167181
private _invalidateLinesFrom(lineNumber: number): void {
@@ -230,19 +244,34 @@ export class FullFileRenderStrategy extends ViewEventHandler implements IGpuRend
230244
while (queuedBufferUpdates.length) {
231245
const e = queuedBufferUpdates.shift()!;
232246

233-
// Shift content below deleted line up
234-
const deletedLineContentStartIndex = (e.fromLineNumber - 1) * this._viewGpuContext.maxGpuCols * Constants.IndicesPerCell;
235-
const deletedLineContentEndIndex = (e.toLineNumber) * this._viewGpuContext.maxGpuCols * Constants.IndicesPerCell;
236-
const nullContentStartIndex = (this._finalRenderedLine - (e.toLineNumber - e.fromLineNumber + 1)) * this._viewGpuContext.maxGpuCols * Constants.IndicesPerCell;
237-
cellBuffer.set(cellBuffer.subarray(deletedLineContentEndIndex), deletedLineContentStartIndex);
238-
239-
// Zero out content on lines that are no longer valid
240-
cellBuffer.fill(0, nullContentStartIndex);
241-
242-
// Update dirty lines and final rendered line
243-
dirtyLineStart = Math.min(dirtyLineStart, e.fromLineNumber);
244-
dirtyLineEnd = this._finalRenderedLine;
245-
this._finalRenderedLine -= e.toLineNumber - e.fromLineNumber + 1;
247+
switch (e.type) {
248+
case ViewEventType.ViewLinesDeleted: {
249+
// Shift content below deleted line up
250+
const deletedLineContentStartIndex = (e.fromLineNumber - 1) * this._viewGpuContext.maxGpuCols * Constants.IndicesPerCell;
251+
const deletedLineContentEndIndex = (e.toLineNumber) * this._viewGpuContext.maxGpuCols * Constants.IndicesPerCell;
252+
const nullContentStartIndex = (this._finalRenderedLine - (e.toLineNumber - e.fromLineNumber + 1)) * this._viewGpuContext.maxGpuCols * Constants.IndicesPerCell;
253+
cellBuffer.set(cellBuffer.subarray(deletedLineContentEndIndex), deletedLineContentStartIndex);
254+
255+
// Zero out content on lines that are no longer valid
256+
cellBuffer.fill(0, nullContentStartIndex);
257+
258+
// Update dirty lines and final rendered line
259+
dirtyLineStart = Math.min(dirtyLineStart, e.fromLineNumber);
260+
dirtyLineEnd = this._finalRenderedLine;
261+
this._finalRenderedLine -= e.toLineNumber - e.fromLineNumber + 1;
262+
break;
263+
}
264+
case ViewEventType.ViewZonesChanged: {
265+
// TODO: We could retain render data if we know what view zones changed and how
266+
// Zero out content on all lines
267+
cellBuffer.fill(0);
268+
269+
dirtyLineStart = 1;
270+
dirtyLineEnd = this._finalRenderedLine;
271+
this._finalRenderedLine = 0;
272+
break;
273+
}
274+
}
246275
}
247276

248277
for (y = viewportData.startLineNumber; y <= viewportData.endLineNumber; y++) {
@@ -360,7 +389,7 @@ export class FullFileRenderStrategy extends ViewEventHandler implements IGpuRend
360389
);
361390
}
362391

363-
private _queueBufferUpdate(e: ViewLinesDeletedEvent) {
392+
private _queueBufferUpdate(e: QueuedBufferEvent) {
364393
this._queuedBufferUpdates[0].push(e);
365394
this._queuedBufferUpdates[1].push(e);
366395
}

0 commit comments

Comments
 (0)