Skip to content

Commit e12b522

Browse files
authored
Small changes to aid in headless WebGPU rendering (playcanvas#7748)
1 parent 19997da commit e12b522

2 files changed

Lines changed: 9 additions & 9 deletions

File tree

src/platform/graphics/webgpu/webgpu-graphics-device.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ class WebgpuGraphicsDevice extends GraphicsDevice {
176176
this.samples = this.backBufferAntialias ? 4 : 1;
177177

178178
// WGSL features
179-
const wgslFeatures = navigator.gpu.wgslLanguageFeatures;
179+
const wgslFeatures = window.navigator.gpu.wgslLanguageFeatures;
180180
this.supportsStorageTextureRead = wgslFeatures?.has('readonly_and_readwrite_storage_textures');
181181

182182
this.initCapsDefines();
@@ -291,7 +291,7 @@ class WebgpuGraphicsDevice extends GraphicsDevice {
291291
let canvasToneMapping = 'standard';
292292

293293
// pixel format of the framebuffer that is the most efficient one on the system
294-
let preferredCanvasFormat = navigator.gpu.getPreferredCanvasFormat();
294+
let preferredCanvasFormat = window.navigator.gpu.getPreferredCanvasFormat();
295295

296296
// display format the user asked for
297297
const displayFormat = this.initOptions.displayFormat;
@@ -346,7 +346,7 @@ class WebgpuGraphicsDevice extends GraphicsDevice {
346346
// (this allows us to view the preferred format as srgb)
347347
viewFormats: displayFormat === DISPLAYFORMAT_LDR_SRGB ? [this.backBufferViewFormat] : []
348348
};
349-
this.gpuContext.configure(this.canvasConfig);
349+
this.gpuContext?.configure(this.canvasConfig);
350350

351351
this.createBackbuffer();
352352

@@ -411,8 +411,8 @@ class WebgpuGraphicsDevice extends GraphicsDevice {
411411
WebgpuDebug.memory(this);
412412
WebgpuDebug.validate(this);
413413

414-
// current frame color output buffer
415-
const outColorBuffer = this.gpuContext.getCurrentTexture();
414+
// current frame color output buffer (fallback to external backbuffer if not available)
415+
const outColorBuffer = this.gpuContext?.getCurrentTexture?.() ?? this.externalBackbuffer?.impl.gpuTexture;
416416
DebugHelper.setLabel(outColorBuffer, `${this.backBuffer.name}`);
417417

418418
// reallocate framebuffer if dimensions change, to match the output texture

src/platform/graphics/webgpu/webgpu-texture.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -401,10 +401,10 @@ class WebgpuTexture {
401401

402402
// image types supported by copyExternalImageToTexture
403403
isExternalImage(image) {
404-
return (image instanceof ImageBitmap) ||
405-
(image instanceof HTMLVideoElement) ||
406-
(image instanceof HTMLCanvasElement) ||
407-
(image instanceof OffscreenCanvas);
404+
return (typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap) ||
405+
(typeof HTMLVideoElement !== 'undefined' && image instanceof HTMLVideoElement) ||
406+
(typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement) ||
407+
(typeof OffscreenCanvas !== 'undefined' && image instanceof OffscreenCanvas);
408408
}
409409

410410
uploadExternalImage(device, image, mipLevel, index) {

0 commit comments

Comments
 (0)