Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebGPU: Allow to pass an offscreen canvas to the constructor #14714

Merged
merged 1 commit into from Jan 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 7 additions & 3 deletions packages/dev/core/src/Engines/webgpuEngine.ts
Expand Up @@ -566,7 +566,7 @@ export class WebGPUEngine extends Engine {
* @param canvas Defines the canvas to use to display the result
* @param options Defines the options passed to the engine to create the GPU context dependencies
*/
public constructor(canvas: HTMLCanvasElement, options: WebGPUEngineOptions = {}) {
public constructor(canvas: HTMLCanvasElement | OffscreenCanvas, options: WebGPUEngineOptions = {}) {
super(null, options.antialias ?? true, options);
this._name = "WebGPU";

Expand All @@ -584,14 +584,14 @@ export class WebGPUEngine extends Engine {
this._isWebGPU = true;
this._shaderPlatformName = "WEBGPU";

this._renderingCanvas = canvas;
this._renderingCanvas = canvas as HTMLCanvasElement;
this._options = options;

this._mainPassSampleCount = options.antialias ? this._defaultSampleCount : 1;

this._setupMobileChecks();

this._sharedInit(canvas);
this._sharedInit(this._renderingCanvas);

this._shaderProcessor = new WebGPUShaderProcessorGLSL();
this._shaderProcessorWGSL = new WebGPUShaderProcessorWGSL();
Expand Down Expand Up @@ -667,6 +667,10 @@ export class WebGPUEngine extends Engine {
if (this._options.setMaximumLimits && !deviceDescriptor.requiredLimits) {
deviceDescriptor.requiredLimits = {};
for (const name in this._adapterSupportedLimits) {
if (name === "minSubgroupSize" || name === "maxSubgroupSize") {
// Chrome exposes these limits in "webgpu developer" mode, but these can't be set on the device.
continue;
}
deviceDescriptor.requiredLimits[name] = this._adapterSupportedLimits[name];
}
}
Expand Down