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

Simplify data-driven paint attributes implementation #3527

Merged
merged 20 commits into from
Nov 8, 2016

Conversation

mourner
Copy link
Member

@mourner mourner commented Nov 3, 2016

A work in progress, closes #3525. cc @jfirebaugh @lucaswoj

The tests are failing because of bucket.test.js, which is mocked in a very complex way so I can't figure out how to fix a few of its failing assertions yet.

getPaintValue(name, globalProperties, featureProperties) {
const value = super.getPaintValue(name, globalProperties, featureProperties);
if (name === 'fill-extrusion-color') {
value[3] = 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we do this in the vertex shader instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, thought about that too. I just placed it here temporarily.

Copy link
Member Author

Choose a reason for hiding this comment

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

Looking at the vertex shader, it seems that fill-extrusion-color alpha value is not used there at all. So we could simply remove this code. @lbud does this sound right?

Copy link
Contributor

Choose a reason for hiding this comment

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

The reason for this is that if you provide an rgba color in the style, we premultiply it in StyleDeclaration, but we don't render using the alpha channel, so providing a non-opaque rgba value leads to unexpected color results. We decided the best of several not-great approaches here would be to deliberately ignore the alpha channel before premultiplying.

@jfirebaugh
Copy link
Contributor

After #3523 I believe we have a regular naming convention for the attribute/uniform name -- it's the name of the paint property with the layer type prefix removed.

I haven't looked at the bucket.test.js failures, but basically the one thing that it mocks is the feature objects. The other collaborator objects in the test -- style layer and properties, bucket subclass, and program interface -- are the real thing.

@mourner
Copy link
Member Author

mourner commented Nov 3, 2016

Yes, noticed about attribute/uniform name convention too — I figured this was the reason you asked for #3523. :)

I'm still unsure about deriving type/multipliers — we can do it for colors, but for things like circle-blur and fill-extrusion-height, converting them to float doubles the memory requirement (16 -> 32 bits), and picking the right maximum in the spec with the intent to make it automagically derived as Uint16 feels a bit too magic and fragile to me. Thoughts?

@mourner mourner force-pushed the simplify-dds-attributes branch 7 times, most recently from 71a4f4f to c04f3e7 Compare November 5, 2016 06:42
@mourner mourner added performance ⚡ Speed, stability, CPU usage, memory usage, or power usage refactoring 🏗️ and removed not ready for review labels Nov 5, 2016
@mourner mourner force-pushed the simplify-dds-attributes branch 2 times, most recently from 957c467 to 1d06cd2 Compare November 5, 2016 07:01
@mourner
Copy link
Member Author

mourner commented Nov 5, 2016

@lucaswoj @jfirebaugh @lbud @ansis this PR is ready for review. It didn't accomplish everything that was planned in #3525 fully, but instead led me to significantly improve the clarity of data-driven-properties code (and -107 lines net!).

Performance also slightly improved — from 6.1ms to 5.5ms on the Streets z13 benchmark. Buffer bench results are unchanged. All commits are self-contained and pass tests.

I suggest merging this now and following up with the points below in other PRs:

  • Move extrude color alpha ignore logic to the shaders.
  • Derive type and multiplier from spec min/max.

@mourner mourner force-pushed the simplify-dds-attributes branch 2 times, most recently from 95407bf to 4fcb5c9 Compare November 5, 2016 19:34
@mourner mourner changed the title Derive data-driven paint attributes configuration from spec Simplify data-driven paint attributes implementation Nov 6, 2016
} else if (layer.isPaintValueZoomConstant(attribute.property)) {
self.addDataDrivenAttribute(name, attribute);
} else {
self.addDataAndZoomDrivenAttribute(name, attribute, layer, zoom);
Copy link
Contributor

Choose a reason for hiding this comment

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

In the codebase we use the terminology property functions, zoom functions, and zoom and property functions."data-driven" is a broader designation that may include unrelated features in the future.

Copy link
Contributor

Choose a reason for hiding this comment

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

We could call these methods addZoomAttribute, addPropertyAttribute, and addZoomAndPropertyAttribute

@lucaswoj
Copy link
Contributor

lucaswoj commented Nov 7, 2016

This looks great! I have couple thoughts on terminology in ProgramConfiguration. I feel 👍 on merging this once those and #3527 (review) are cleared up.

@jfirebaugh
Copy link
Contributor

It's definitely easier to understand ProgramConfiguration now. 👍

In gl-native, the implementation is going to center entirely around paint properties. We use code generation to create a unique type for each paint property, which can provide to C++ the data that's in the style specification. Having unique types allows the use of C++ structural metaprogramming techniques to define generic operations over tuples of paint properties. There will be an equivalent of ProgramConfiguration, but it's likely to use a more functional programming style, where things like the list of uniforms and pragmas are generated as needed from a tuple type representing the DDS-enabled paint properties.

In the initial implementation, I'm not going to use multipliers. fill-extrusion-height will use a float attribute. *-color and *-opacity will use normalized uint8s.

I'm also going to use glVertexAttrib* rather than dynamically generated shaders as a first cut.

@mourner mourner merged commit 0d16d21 into master Nov 8, 2016
@mourner mourner deleted the simplify-dds-attributes branch November 8, 2016 00:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance ⚡ Speed, stability, CPU usage, memory usage, or power usage refactoring 🏗️
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Drive paint attribute binding logic off the style spec
4 participants