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

shadertools: Resolve dependencies in ShaderInputs #2073

Merged
merged 3 commits into from Apr 25, 2024

Conversation

felixpalmer
Copy link
Collaborator

For visgl/deck.gl#8782 implemented on 9.0 branch and tested against deck. Works for project/project32 pair. Also tested with luma.gl/examples/showcase/instancing which uses a non-ShaderModule input

Change List

  • Obtain module dependencies when constructing ShaderInputs
  • Uncouple getDependencyGraph from ShaderModuleInstance type
  • Test

modules/engine/src/shader-inputs.ts Outdated Show resolved Hide resolved
modules/engine/src/shader-inputs.ts Outdated Show resolved Hide resolved
@felixpalmer
Copy link
Collaborator Author

@ibgreen In general I don't see have we can resolve the types on the module dependencies, so I have at least made it so the user can specify the expected props on creation:

const shaderInputs = new ShaderInputs<{
  custom: CustomProps;
  picking: typeof picking.props;
}>({custom}); // <- No need to pass `picking` at runtime as it is a dependency of `custom`

shaderInputs.setProps({
  custom: {color: [255, 0, 0]},
  picking: {highlightedObjectColor: [1, 2, 3]}
}); // <- setProps has correct type that knows about `picking`

modules: (ShaderModule | ShaderModuleInstance)[],
instantiate: boolean = true
): (ShaderModule | ShaderModuleInstance)[] {
return getShaderDependencies(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A problem here is that if a ShaderModule has been involved in instantiation, all its dependencies have been converted to ShaderModuleInstances. So I am not convinced that the result of any repeated calls to resolveModules() will actually be a ShaderModule[] in spite of this typing effort.

The ShaderModule / ShaderModuleInstance dichotomy seems to generate a lot more trouble than it is worth.

I note that instantiation actually doesn't do that much, it adds some methods (that could be global functions) and initializes some things for perf:

    this.deprecations = this._parseDeprecationDefinitions(deprecations);
    this.injections = normalizeInjections(inject);
    if (uniformPropTypes) {
      this.uniforms = makePropValidators(uniformPropTypes);
    }
}

Perhaps we should try to move away from ShaderModuleInstance.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will try to remove ShaderModuleInstance so that we can avoid this mess, partial work in #2074 will continue tomorrow

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, it also makes it simpler for situations where we extend ShaderModule, like ShaderPass. Why have ShaderModuleInstance, but not ShaderPassInstance? If I instantiateModules with ShaderPass instances what is returned etc...

@ibgreen
Copy link
Collaborator

ibgreen commented Apr 22, 2024

@felixpalmer Just an update as I am still working on the PR to remove shader modules #2074 it is getting pretty big. As long as we are not planning to backport this it should be fine.

@felixpalmer
Copy link
Collaborator Author

@ibgreen thanks for the push. Types aside, is the implementation OK to land in v9.0? I would like to land visgl/deck.gl#8782 and continue to port the other shader module. I'm happy to work with full ShaderModules as you suggested

@ibgreen ibgreen merged commit 11efb29 into master Apr 25, 2024
2 checks passed
@ibgreen ibgreen deleted the felix/shader-input-dependencies branch April 25, 2024 12:57
ibgreen added a commit that referenced this pull request Apr 25, 2024
ibgreen added a commit that referenced this pull request Apr 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants