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

feat(engine): ShaderModule.getBindings() #2099

Merged
merged 3 commits into from
Jun 20, 2024

Conversation

felixpalmer
Copy link
Collaborator

Background

ShaderModule has no support for bindings, which are needed to complete the port over to UBOs. If this approach looks OK I can make a PR on master, but doing this on v9 in order to test against deck.gl

Change List

  • Add getBindings to ShaderModule type
  • Support in ShaderInputs & Model classes
  • Tests

Copy link
Collaborator

@donmccurdy donmccurdy left a comment

Choose a reason for hiding this comment

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

Nice clean approach!

@@ -43,6 +44,7 @@ export type ShaderModule<

/** uniform buffers, textures, samplers, storage, ... */
bindings?: Record<keyof BindingsT, {location: number; type: 'texture' | 'sampler' | 'uniforms'}>;
getBindings?: (settings?: any, prevBindings?: any) => Record<string, Texture | Sampler>;
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: Types could be a little more strict here I think, with Record<keyof BindingsT, ...>? Should prevBindings have the same type?

Copy link
Collaborator

Choose a reason for hiding this comment

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

+1

Copy link
Collaborator

@Pessimistress Pessimistress left a comment

Choose a reason for hiding this comment

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

Looks like the minimal change needed to enable deck migration to full UBO. My only thought is that binding/uniforms are usually calculated together (e.g. texture, dimensions and uv) and using separate callbacks for them will lead to a lot of duplicate code.

@felixpalmer
Copy link
Collaborator Author

@Pessimistress I'm not sure I'm convinced about the scale of the problem. Usually the texture is just a prop that is passed through as a binding: https://github.com/visgl/deck.gl/blob/f1a163a172c4cda5aeccaa11c518798bfe8779b1/modules/layers/src/bitmap-layer/bitmap-layer.ts#L298

I would say we go with this approach, migrate the deck layers and if we see too much duplication we can revise the API. Having a combined callback has drawbacks, if we use getUniforms also for bindings the naming is confusing, and changing to something like getUniformsAndBindings would be a breaking change. Two separate callbacks also lets us be more strict about the types

Copy link
Collaborator

@ibgreen ibgreen left a comment

Choose a reason for hiding this comment

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

There is a utility function splitUniformsAndBindings() in core. I would probably have looked into use something like that here and avoid requiring shader modules to define two get... functions (overall I would prefer if most shader modules were "pure objects" and didn't define functions).

@@ -505,6 +505,7 @@ export class Model {
/** Update uniform buffers from the model's shader inputs */
updateShaderInputs(): void {
this._uniformStore.setUniforms(this.shaderInputs.getUniformValues());
this.setBindings(this.shaderInputs.getBindings());
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: not much reason for this comment other than symmetry:

Suggested change
this.setBindings(this.shaderInputs.getBindings());
this.setBindings(this.shaderInputs.getBindingValues());

@@ -43,6 +44,7 @@ export type ShaderModule<

/** uniform buffers, textures, samplers, storage, ... */
bindings?: Record<keyof BindingsT, {location: number; type: 'texture' | 'sampler' | 'uniforms'}>;
getBindings?: (settings?: any, prevBindings?: any) => Record<string, Texture | Sampler>;
Copy link
Collaborator

Choose a reason for hiding this comment

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

+1

@felixpalmer felixpalmer merged commit 98fef5f into 9.0-release Jun 20, 2024
1 check passed
@felixpalmer felixpalmer deleted the felix/shader-module-getBindings branch June 20, 2024 07:47
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.

4 participants