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

Remove withParametersWebGL method in Pass classes #8636

Merged
merged 26 commits into from Mar 21, 2024

Conversation

felixpalmer
Copy link
Collaborator

@felixpalmer felixpalmer commented Mar 12, 2024

For #8582 requires visgl/luma.gl#2046

Blending via layer parameters and Deck parameters is not working. Comparison before/after fix:

Screen.Recording.2024-03-12.at.12.19.42.mov

In general we want to remove withParametersWebGL/setParametersWebGL from the codebase

Change List

  • Remove setParametersWebGL & withParametersWebGL methods for setting GL parameters
  • Support colorMask & scissorRect in LayerPass.render()

extension.draw.call(this, opts, extension);
}
// Call subclass lifecycle method
const opts: DrawOptions = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you try calling model.setParameters here for all this.getModels()? I think the exception is rare (ScenegraphLayer comes to mind).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done. It works, however I cannot get picking to work if I remove the withParametersWebGL call below

Copy link
Collaborator

Choose a reason for hiding this comment

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

model.setParameters takes RenderPipelineParameters (v9 string format) and device.withParametersWebGL takes GLParameters (v8 WebGL constant format). Picking pass used the later (blend and blendColor).

@@ -182,10 +182,11 @@ export default class LineLayer<DataT = any, ExtraProps extends {} = {}> extends
}
}

draw({uniforms}): void {
draw({parameters, uniforms}): void {
Copy link
Collaborator

Choose a reason for hiding this comment

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

With the current caching mechanism, changing parameters will cause a pipeline to rebuild. Because each layer has a unique polygonOffset to battle z-fighting, calling model.setParameters will practically disable all program reuse. @ibgreen @donmccurdy

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm... @ibgreen I assume this is the purpose of the new factory destroy policy 'never' setting? Let's test that and consider a future 'lazy' destroy policy (or similar) if the performance benefits are worthwhile?

Copy link
Collaborator

Choose a reason for hiding this comment

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

No the problem is not cache getting removed, it's that the hash is overly aggressive.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Does the hash even need to include the parameters? Could we have a whitelist or exclude list?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Discussing with @ibgreen in a separate channel - basically WebGPU render pipeline does not allow dynamically setting parameters so the unified API does not accept it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Based on ...

https://github.com/visgl/luma.gl/blob/c5c15fbb9ab2fcaad998d030eac9e6312dd70aad/modules/engine/src/lib/pipeline-factory.ts#L111-L115

... it might be optional for WebGL, but will require a new pipeline for WebGPU. My hope with the suggestion of a 'lazy' destroy policy would be that if we have N layers and 1 pipeline, we can at least keep N pipelines in the cache rather than creating and destroying pipelines N times per frame.

WebGPU's equivalent of polygonOffset is depth stencil state bias, and is configured on the render pipeline.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I wonder if it would be possible to combat the z-fighting in the vertex shader via a uniform, something like gl_Position.z += 0.0001 * layerIndex

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes... we also have instance ID now with WebGL2.

The z fighting work around has long been due for an update. We definitely need to make some changes while working on WebGPU support.

@coveralls
Copy link

coveralls commented Mar 13, 2024

Coverage Status

coverage: 89.027% (-0.009%) from 89.036%
when pulling 625d1d3 on felix/deck-layer-parameters-v9
into 1d504e9 on master.

@felixpalmer felixpalmer marked this pull request as ready for review March 13, 2024 12:15
modules/core/src/lib/layer.ts Outdated Show resolved Hide resolved
@@ -184,6 +184,14 @@ export type UpdateParameters<LayerT extends Layer> = {
changeFlags: ChangeFlags;
};

export type DrawOptions = {
context: LayerContext;
moduleParameters: any;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not new in this PR, but the name can be really confusing. I think it's better called moduleSettings or shaderInputProps?

@felixpalmer felixpalmer force-pushed the felix/deck-layer-parameters-v9 branch from c24ab11 to 11dcd54 Compare March 15, 2024 09:41
@felixpalmer
Copy link
Collaborator Author

felixpalmer commented Mar 15, 2024

@Pessimistress I've moved the merge to layers-pass and it works. The pick-layers-pass is the problem, I tried to migrate that over as well, but the parameters used there are the old GLParameters type, and it isn't possible to convert to the new types without changes in luma. In the interests of landing this and fixing the blending I would propose we tackle the migration of the pick-layers-pass in a future PR, once luma has the missing BlendFactor

@donmccurdy
Copy link
Collaborator

PR for the BlendFactor issue:

@felixpalmer
Copy link
Collaborator Author

@donmccurdy @Pessimistress I've updated pick-layers-pass with the new BlendFactor types

modules/core/src/passes/pick-layers-pass.ts Outdated Show resolved Hide resolved
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.

The following passes also have withParametersWebGL and need to be merged in the proper order:

  • ShadowPass
  • CollisionFilterPass
  • MaskPass
  • TerrainPass
  • TerrainPickingPass

modules/core/src/passes/pick-layers-pass.ts Show resolved Hide resolved
const pickParameters = {
...layer.props.parameters,
scissorTest: true,
scissor: [x, y, width, height],
Copy link
Collaborator

Choose a reason for hiding this comment

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

For both perf and WebGPU readiness it's probably appropriate to align LayersPassRenderOptions with luma's RenderPassProps/RenderPassParameters and set scissor/depth parameters per-pass instead of per-layer.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've moved the scissor test to be performed on the pass, but I'm not sure about depth. It is common for layers to override the depth handling via parameters

Copy link
Collaborator

Choose a reason for hiding this comment

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

The picking pass only resets depth to avoid dirty context state handover (in v8 deck.props.parameters is not set before picking buffer redraw). They can be overwritten by per-layer settings. In this case we should reset the depth parameters in render pass creation. In the other cases depth parameters should override user props.

@felixpalmer felixpalmer changed the title Set parameters without withParametersWebGL method Remove withParametersWebGL method in Pass classes Mar 20, 2024
modules/core/src/lib/layer.ts Show resolved Hide resolved
modules/core/src/passes/pick-layers-pass.ts Show resolved Hide resolved
modules/core/src/passes/pick-layers-pass.ts Outdated Show resolved Hide resolved
const pickParameters = {
...layer.props.parameters,
scissorTest: true,
scissor: [x, y, width, height],
Copy link
Collaborator

Choose a reason for hiding this comment

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

The picking pass only resets depth to avoid dirty context state handover (in v8 deck.props.parameters is not set before picking buffer redraw). They can be overwritten by per-layer settings. In this case we should reset the depth parameters in render pass creation. In the other cases depth parameters should override user props.

@felixpalmer felixpalmer merged commit 7bd54c9 into master Mar 21, 2024
2 checks passed
@felixpalmer felixpalmer deleted the felix/deck-layer-parameters-v9 branch March 21, 2024 16:20
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

4 participants