From 06fda6695cdaccb61ee04b0fabeeb2914b06a8ed Mon Sep 17 00:00:00 2001 From: Ib Green <7025232+ibgreen@users.noreply.github.com> Date: Fri, 13 Dec 2024 10:14:49 -0500 Subject: [PATCH] feat(engine): Option to disable warnings in ShaderInputs (#2301) --- modules/engine/src/model/model.ts | 10 +++++++--- modules/engine/src/shader-inputs.ts | 25 +++++++++++++++++++------ 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/modules/engine/src/model/model.ts b/modules/engine/src/model/model.ts index 7fa386626e..331908d268 100644 --- a/modules/engine/src/model/model.ts +++ b/modules/engine/src/model/model.ts @@ -241,15 +241,19 @@ export class Model { const moduleMap = Object.fromEntries( this.props.modules?.map(module => [module.name, module]) || [] ); - // @ts-expect-error Fix typings - this.setShaderInputs(props.shaderInputs || new ShaderInputs(moduleMap)); + + const shaderInputs = + props.shaderInputs || + new ShaderInputs(moduleMap, {disableWarnings: this.props.disableWarnings}); + // @ts-ignore + this.setShaderInputs(shaderInputs); // Setup shader assembler const platformInfo = getPlatformInfo(device); // Extract modules from shader inputs if not supplied const modules = - // @ts-expect-error shaderInputs is assigned in setShaderInputs above. + // @ts-ignore shaderInputs is assigned in setShaderInputs above. (this.props.modules?.length > 0 ? this.props.modules : this.shaderInputs?.getModules()) || []; const isWebGPU = this.device.type === 'webgpu'; diff --git a/modules/engine/src/shader-inputs.ts b/modules/engine/src/shader-inputs.ts index c8d58d99d4..2d16b8f8a3 100644 --- a/modules/engine/src/shader-inputs.ts +++ b/modules/engine/src/shader-inputs.ts @@ -8,6 +8,10 @@ import {log} from '@luma.gl/core'; import {getShaderModuleDependencies, ShaderModule} from '@luma.gl/shadertools'; import {splitUniformsAndBindings} from './model/split-uniforms-and-bindings'; +export type ShaderInputsOptions = { + disableWarnings?: boolean; +}; + /** * ShaderInputs holds uniform and binding values for one or more shader modules, * - It can generate binary data for any uniform buffer @@ -20,11 +24,15 @@ export class ShaderInputs< Record> > > { + options: Required = { + disableWarnings: false + }; + /** * The map of modules * @todo should should this include the resolved dependencies? */ - // @ts-expect-error Fix typings + // @ts-ignore Fix typings modules: Readonly<{[P in keyof ShaderPropsT]: ShaderModule}>; /** Stores the uniform values for each module */ @@ -38,8 +46,13 @@ export class ShaderInputs< * Create a new UniformStore instance * @param modules */ - // @ts-expect-error Fix typings - constructor(modules: {[P in keyof ShaderPropsT]?: ShaderModule}) { + constructor( + // @ts-ignore Fix typings + modules: {[P in keyof ShaderPropsT]?: ShaderModule}, + options?: ShaderInputsOptions + ) { + Object.assign(this.options, options); + // Extract modules with dependencies const resolvedModules = getShaderModuleDependencies( Object.values(modules).filter(module => module.dependencies) @@ -52,7 +65,7 @@ export class ShaderInputs< log.log(1, 'Creating ShaderInputs with modules', Object.keys(modules))(); // Store the module definitions and create storage for uniform values and binding values, per module - // @ts-expect-error Fix typings + // @ts-ignore Fix typings this.modules = modules as {[P in keyof ShaderPropsT]: ShaderModule}; this.moduleUniforms = {} as Record>; this.moduleBindings = {} as Record>; @@ -60,7 +73,7 @@ export class ShaderInputs< // Initialize the modules for (const [name, module] of Object.entries(modules)) { this._addModule(module); - if (module.name && name !== module.name) { + if (module.name && name !== module.name && !this.options.disableWarnings) { log.warn(`Module name: ${name} vs ${module.name}`)(); } } @@ -77,7 +90,7 @@ export class ShaderInputs< const moduleName = name as keyof ShaderPropsT; const moduleProps = props[moduleName] || {}; const module = this.modules[moduleName]; - if (!module) { + if (!module && !this.options.disableWarnings) { // Ignore props for unregistered modules log.warn(`Module ${name} not found`)(); continue; // eslint-disable-line no-continue