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(layers): Simplify ArcLayer #8859

Merged
merged 3 commits into from May 6, 2024
Merged

feat(layers): Simplify ArcLayer #8859

merged 3 commits into from May 6, 2024

Conversation

Pessimistress
Copy link
Collaborator

Taking advantage of our move to es300.

Change List

  • Removes positions attribute, use gl_VertexID instead
  • No longer rebuilds model on numSegments change

@coveralls
Copy link

coveralls commented May 1, 2024

Coverage Status

coverage: 89.826% (-0.004%) from 89.83%
when pulling c836b34 on x/arc-layer-vertex
into a9acdf8 on master.

Comment on lines 263 to 269
const model = new Model(this.context.device, {
...this.getShaders(),
id: this.props.id,
bufferLayout: this.getAttributeManager()!.getBufferLayouts(),
geometry: new Geometry({
topology: 'triangle-strip',
attributes: {
positions: {size: 3, value: new Float32Array(positions)}
}
}),
topology: 'triangle-strip',
isInstanced: true
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

It feels a little strange to me that the Model class can be allocated without a vertex count or buffers – is that intended? Just wondering if passing in vertexCount here, or perhaps stricter Model/Geometry APIs in Luma, might make sense at some point. No action needed.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It feels a little strange to me that the Model class can be allocated without a vertex count or buffers

Yes, models without geometry are a thing. Since we are now using GLSL 3.0, for small geometries we can define the arrays directly in the shader. We have a geometry-less triangle in GLSL and WGSL in https://github.com/visgl/luma.gl/blob/master/examples/tutorials/hello-triangle/app.ts#L22

I agree it surprised me when I first realized that it was possible. We could disallow it to avoid surprising folks.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe two parts here:

  1. model without geometry
  2. model without vertex count

For me (2) was the more surprising part, since that would seem to be an invalid initialization state. If a Model without Geometry or Attributes is valid, is a Geometry without Attributes also valid? Not suggesting we add more flexibility, just maybe clarity to make valid/invalid states obvious.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes... I am not sure how to encode these things in APIs and types.

"Either-or type checks" require a fair bit of typescript machinery (discriminated unions) that makes code less readable.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The geometry & vertexCount props are quite closely linked. Model._setGeometryAttributes() sets the vertexCount based on the number of vertices obtained from the gpuGeometry, which is then optionally overwritten with props.vertexCount. I wonder if it would be better to support a NullGeometry that contained nothing but a vertexCount and then we remove the vertexCount prop altogether and make props.geometry required.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I like the general idea... Though we do have a similar situation with instanceCount so it would be nice to handle both in a similar way.

Something I really liked was the design we did in deck.gl-native, where we took the "table view" and avoided the term geometry and instead said that a model can have two tables, basically something like:

model.setAttributes(table: arrow.Table) 
model.setInstancedAttributes(table: arrow.Table)

This makes it clear that these are tables of different lengths, and the table lengths determine the vertexCount and instanceCount (though these can be overridden during draw of course, to just draw a range).

Of course we can still have a convenience function setGeometries that contain table, indices and topology and that calls this underlying function.

We dohave the complication of indexed geometries and vertex-sharing topologies to deal with (though modern GPU programming practices often seem to recommend avoiding indices and vertex-sharing topologies, so we could make the decision to start phasing that out).

Copy link
Collaborator

@donmccurdy donmccurdy May 3, 2024

Choose a reason for hiding this comment

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

My feeling is that indexed geometries are still very much recommended, and are key to certain optimizations. I agree that alternative geometries like strips and lists could be phased out.

While working on porting code to v9, I personally found the number of different ways to get attributes into a Model confusing, I wasn't always sure if I was doing it the correct way, or mixing two correct ways incorrectly. That can be a hidden cost of convenience methods.

I quite like the "two tables" idea!

(and sorry for starting a long thread here, @Pessimistress please feel free to merge!)

@Pessimistress Pessimistress merged commit 05e1b01 into master May 6, 2024
4 checks passed
@Pessimistress Pessimistress deleted the x/arc-layer-vertex branch May 6, 2024 00:31
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

5 participants