WebGPU
WebGPU requires glslang
and twgsl
(including their binaries) to work correctly.
To configure their URLs individually:
javascript
const glslangOptions = { jsPath: baseUrl + "/glslang/glslang.js", wasmPath: baseUrl + "/glslang/glslang.wasm",};
const twgslOptions = { jsPath: baseUrl + "/twgsl/twgsl.js", wasmPath: baseUrl + "/twgsl/twgsl.wasm",};
const options = { // ... webgpu options};
const engine = new BABYLON.WebGPUEngine(window.canvas, options);await engine.initAsync(glslangOptions, twgslOptions);
YO @sebavan / @Deltakosh
What if you dont pass these
engine.initAsync();
Where do they come from, I am using a vite react typescript project
if (navigator.gpu && webgpu) {
const webgpuEngine = new BABYLON.WebGPUEngine(canvas, {
...engineOptions,
antialias,
adaptToDeviceRatio,
setMaximumLimits: true,
enableAllFeatures:true,
});
await webgpuEngine.initAsync();
engine = (webgpuEngine as any);
} else {
engine = new BABYLON.Engine(canvas, antialias, engineOptions, adaptToDeviceRatio);
}
Did you have a fix on this issue?
Hi MackeyK24! If not specified, both are loaded from default Babylon CDN (https://cdn.babylonjs.com , as of today).
Glslang:
*/
twgslOptions?: TwgslOptions;
}
/**
* The web GPU engine class provides support for WebGPU version of babylon.js.
* @since 5.0.0
*/
export class WebGPUEngine extends ThinWebGPUEngine {
// Default glslang options.
private static readonly _GlslangDefaultOptions: GlslangOptions = {
jsPath: `${Tools._DefaultCdnUrl}/glslang/glslang.js`,
wasmPath: `${Tools._DefaultCdnUrl}/glslang/glslang.wasm`,
};
private static _InstanceId = 0;
/** A unique id to identify this instance */
public readonly uniqueId = -1;
// Page Life cycle and constants
Twgsl:
jsPath?: string;
/**
* Defines the URL of the twgsl WASM File.
*/
wasmPath?: string;
}
/** @internal */
export class WebGPUTintWASM {
// Default twgsl options.
private static readonly _TwgslDefaultOptions: TwgslOptions = {
jsPath: `${Tools._DefaultCdnUrl}/twgsl/twgsl.js`,
wasmPath: `${Tools._DefaultCdnUrl}/twgsl/twgsl.wasm`,
};
public static ShowWGSLShaderCode = false;
public static DisableUniformityAnalysis = false;
private static _Twgsl: any = null;
Also they are not required if you are using only babylon base shaders as all of them were ported to WGSL
YO @Deltakosh
When you say they are not required, and you dont specify them, are they still LOADED from the cdn… Or is there a way to tell it NOT to try load them at all, if they are not required ?
They are loaded ONLY if we find that you use a glsl shader in a WebGPU engine context
1 Like
Thanks for the clarification