Skip to content

Commit

Permalink
feat(engine): Option to disable warnings in ShaderInputs (#2301)
Browse files Browse the repository at this point in the history
  • Loading branch information
ibgreen authored Dec 13, 2024
1 parent 7559423 commit 06fda66
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
10 changes: 7 additions & 3 deletions modules/engine/src/model/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
25 changes: 19 additions & 6 deletions modules/engine/src/shader-inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -20,11 +24,15 @@ export class ShaderInputs<
Record<string, Record<string, unknown>>
>
> {
options: Required<ShaderInputsOptions> = {
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<ShaderPropsT[P]>}>;

/** Stores the uniform values for each module */
Expand All @@ -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<ShaderPropsT[P], any>}) {
constructor(
// @ts-ignore Fix typings
modules: {[P in keyof ShaderPropsT]?: ShaderModule<ShaderPropsT[P], any>},
options?: ShaderInputsOptions
) {
Object.assign(this.options, options);

// Extract modules with dependencies
const resolvedModules = getShaderModuleDependencies(
Object.values(modules).filter(module => module.dependencies)
Expand All @@ -52,15 +65,15 @@ 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<ShaderPropsT[P]>};
this.moduleUniforms = {} as Record<keyof ShaderPropsT, Record<string, UniformValue>>;
this.moduleBindings = {} as Record<keyof ShaderPropsT, Record<string, Binding>>;

// 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}`)();
}
}
Expand All @@ -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
Expand Down

0 comments on commit 06fda66

Please sign in to comment.