Skip to content

Commit ff59377

Browse files
authored
Merge pull request microsoft#238158 from microsoft/tyriar/238157
Share GPU device across editors, access sync when possible
2 parents cff1a6a + 8121532 commit ff59377

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed

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

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ export class ViewGpuContext extends Disposable {
4646
readonly canvas: FastDomNode<HTMLCanvasElement>;
4747
readonly ctx: GPUCanvasContext;
4848

49-
readonly device: Promise<GPUDevice>;
49+
static device: Promise<GPUDevice>;
50+
static deviceSync: GPUDevice | undefined;
5051

5152
readonly rectangleRenderer: RectangleRenderer;
5253

@@ -109,18 +110,23 @@ export class ViewGpuContext extends Disposable {
109110

110111
this.ctx = ensureNonNullable(this.canvas.domNode.getContext('webgpu'));
111112

112-
this.device = GPULifecycle.requestDevice((message) => {
113-
const choices: IPromptChoice[] = [{
114-
label: nls.localize('editor.dom.render', "Use DOM-based rendering"),
115-
run: () => this.configurationService.updateValue('editor.experimentalGpuAcceleration', 'off'),
116-
}];
117-
this._notificationService.prompt(Severity.Warning, message, choices);
118-
}).then(ref => this._register(ref).object);
119-
this.device.then(device => {
120-
if (!ViewGpuContext._atlas) {
121-
ViewGpuContext._atlas = this._instantiationService.createInstance(TextureAtlas, device.limits.maxTextureDimension2D, undefined);
122-
}
123-
});
113+
// Request the GPU device, we only want to do this a single time per window as it's async
114+
// and can delay the initial render.
115+
if (!ViewGpuContext.device) {
116+
ViewGpuContext.device = GPULifecycle.requestDevice((message) => {
117+
const choices: IPromptChoice[] = [{
118+
label: nls.localize('editor.dom.render', "Use DOM-based rendering"),
119+
run: () => this.configurationService.updateValue('editor.experimentalGpuAcceleration', 'off'),
120+
}];
121+
this._notificationService.prompt(Severity.Warning, message, choices);
122+
}).then(ref => {
123+
ViewGpuContext.deviceSync = ref.object;
124+
if (!ViewGpuContext._atlas) {
125+
ViewGpuContext._atlas = this._instantiationService.createInstance(TextureAtlas, ref.object.limits.maxTextureDimension2D, undefined);
126+
}
127+
return ref.object;
128+
});
129+
}
124130

125131
const dprObs = observableValue(this, getActiveWindow().devicePixelRatio);
126132
this._register(addDisposableListener(getActiveWindow(), 'resize', () => {
@@ -147,8 +153,7 @@ export class ViewGpuContext extends Disposable {
147153
}));
148154
this.contentLeft = contentLeft;
149155

150-
151-
this.rectangleRenderer = this._instantiationService.createInstance(RectangleRenderer, context, this.contentLeft, this.devicePixelRatio, this.canvas.domNode, this.ctx, this.device);
156+
this.rectangleRenderer = this._instantiationService.createInstance(RectangleRenderer, context, this.contentLeft, this.devicePixelRatio, this.canvas.domNode, this.ctx, ViewGpuContext.device);
152157
}
153158

154159
/**

src/vs/editor/browser/viewParts/viewLinesGpu/viewLinesGpu.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export class ViewLinesGpu extends ViewPart implements IViewLines {
9292
async initWebgpu() {
9393
// #region General
9494

95-
this._device = await this._viewGpuContext.device;
95+
this._device = ViewGpuContext.deviceSync || await ViewGpuContext.device;
9696

9797
if (this._store.isDisposed) {
9898
return;
@@ -650,7 +650,6 @@ export class ViewLinesGpu extends ViewPart implements IViewLines {
650650
column++;
651651
}
652652

653-
console.log(lineNumber, column);
654653
return new Position(lineNumber, column + 1);
655654
}
656655
}

0 commit comments

Comments
 (0)