Skip to content

Commit

Permalink
Only copy used parts of texture atlas
Browse files Browse the repository at this point in the history
This will slow as the page gets filled but this simple change improves start up quite a bit
  • Loading branch information
Tyriar committed Aug 16, 2024
1 parent ec59051 commit aef2733
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/vs/editor/browser/view/gpu/atlas/atlas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export interface ITextureAtlasAllocator {

export interface IReadableTextureAtlasPage {
readonly version: number;
readonly usedArea: Readonly<IBoundingBox>;
readonly glyphs: IterableIterator<ITextureAtlasGlyph>;
readonly source: OffscreenCanvas;
getUsagePreview(): Promise<Blob>;
Expand Down
10 changes: 9 additions & 1 deletion src/vs/editor/browser/view/gpu/atlas/textureAtlasPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { Event } from 'vs/base/common/event';
import { Disposable, toDisposable } from 'vs/base/common/lifecycle';
import { TwoKeyMap } from 'vs/base/common/map';
import type { IReadableTextureAtlasPage, ITextureAtlasAllocator, ITextureAtlasGlyph } from 'vs/editor/browser/view/gpu/atlas/atlas';
import type { IBoundingBox, IReadableTextureAtlasPage, ITextureAtlasAllocator, ITextureAtlasGlyph } from 'vs/editor/browser/view/gpu/atlas/atlas';
import { TextureAtlasShelfAllocator } from 'vs/editor/browser/view/gpu/atlas/textureAtlasShelfAllocator';
import { TextureAtlasSlabAllocator } from 'vs/editor/browser/view/gpu/atlas/textureAtlasSlabAllocator';
import type { GlyphRasterizer } from 'vs/editor/browser/view/gpu/raster/glyphRasterizer';
Expand All @@ -16,6 +16,11 @@ import { IThemeService } from 'vs/platform/theme/common/themeService';
export class TextureAtlasPage extends Disposable implements IReadableTextureAtlasPage {
private _version: number = 0;

private _usedArea: IBoundingBox = { left: 0, top: 0, right: 0, bottom: 0 };
public get usedArea(): Readonly<IBoundingBox> {
return this._usedArea;
}

/**
* The version of the texture atlas. This is incremented every time the page's texture changes.
*/
Expand Down Expand Up @@ -82,7 +87,10 @@ export class TextureAtlasPage extends Disposable implements IReadableTextureAtla
const glyph = this._allocator.allocate(chars, tokenFg, rasterizedGlyph)!;
this._glyphMap.set(chars, tokenFg, glyph);
this._glyphInOrderSet.add(glyph);

this._version++;
this._usedArea.right = Math.max(this._usedArea.right, glyph.x + glyph.w);
this._usedArea.bottom = Math.max(this._usedArea.bottom, glyph.y + glyph.h);

if (this._logService.getLevel() === LogLevel.Trace) {
this._logService.trace('New glyph', {
Expand Down
5 changes: 2 additions & 3 deletions src/vs/editor/browser/view/gpu/gpuViewLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,11 +326,10 @@ export class GpuViewLayerRenderer<T extends IVisibleLine> {
entryOffset += SpriteInfoStorageBufferInfo.Size;
}
this._device.queue.writeBuffer(this._glyphStorageBuffer[layerIndex], 0, values);
// TODO: Draw only dirty regions
this._device.queue.copyExternalImageToTexture(
{ source: page.source },
{ texture: this._atlasGpuTexture, origin: { x: 0, y: 0, z: layerIndex } },
{ width: page.source.width, height: page.source.height },
{ texture: this._atlasGpuTexture, origin: { x: page.usedArea.left, y: page.usedArea.top, z: layerIndex } },
{ width: page.usedArea.right - page.usedArea.left, height: page.usedArea.bottom - page.usedArea.top },
);
this._atlasGpuTextureVersions[layerIndex] = page.version;
}
Expand Down

0 comments on commit aef2733

Please sign in to comment.