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

Fix countItems in DataFilterExtension #9158

Merged
merged 9 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions modules/extensions/src/data-filter/aggregator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {Device, DeviceFeature, Framebuffer} from '@luma.gl/core';
import {Device, DeviceFeature, Framebuffer, RenderPipelineParameters} from '@luma.gl/core';
import {Model} from '@luma.gl/engine';
import {GL} from '@luma.gl/constants';

const AGGREGATE_VS = `\
#version 300 es
Expand All @@ -19,7 +18,8 @@ const float component = 1.0 / 255.0;

void main() {
#ifdef FLOAT_TARGET
dataFilter_value *= float(filterIndices != filterPrevIndices);
// BUG: always 0 for some reason
// dataFilter_value *= float(filterIndices != filterPrevIndices);
gl_Position = vec4(0.0, 0.0, 0.0, 1.0);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@Pessimistress any idea why this is broken? I've tried different variants of the check and it always evaluates to 0. Perhaps there is something wrong with using vertexOffset?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Subtle catch of v9 - when an attribute's descriptor contains shaderAttributes, the sub-attributes cannot use the same name.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That is subtle indeed :) would be nice if the types could catch this

vColor = vec4(0.0, 0.0, 0.0, 1.0);
#else
Expand Down Expand Up @@ -94,16 +94,20 @@ export function getModel(device: Device, shaderOptions: any, useFloatTarget: boo
id: 'data-filter-aggregation-model',
vertexCount: 1,
isInstanced: false,
drawMode: GL.POINTS,
topology: 'point-list',
vs: AGGREGATE_VS,
fs: AGGREGATE_FS,
...shaderOptions
});
}

export const parameters = {
export const parameters: RenderPipelineParameters = {
blend: true,
blendFunc: [GL.ONE, GL.ONE, GL.ONE, GL.ONE],
blendEquation: [GL.FUNC_ADD, GL.FUNC_ADD],
depthTest: false
blendColorSrcFactor: 'one',
blendColorDstFactor: 'one',
blendAlphaSrcFactor: 'one',
blendAlphaDstFactor: 'one',
blendColorOperation: 'add',
blendAlphaOperation: 'add',
depthCompare: 'never'
} as const;
41 changes: 23 additions & 18 deletions modules/extensions/src/data-filter/data-filter-extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

import type {Framebuffer} from '@luma.gl/core';
import type {Buffer, Framebuffer} from '@luma.gl/core';
import type {Model} from '@luma.gl/engine';
import type {Layer, LayerContext, Accessor, UpdateParameters} from '@deck.gl/core';
import {_deepEqual as deepEqual, LayerExtension, log} from '@deck.gl/core';
Expand All @@ -30,6 +30,7 @@ import {
dataFilter64
} from './shader-module';
import * as aggregator from './aggregator';
import {NumberArray4} from '@math.gl/core';

const defaultProps = {
getFilterValue: {type: 'accessor', value: 0},
Expand Down Expand Up @@ -229,6 +230,7 @@ export default class DataFilterExtension extends LayerExtension<
extension.getShaders.call(this, extension),
useFloatTarget
);
filterModel.setBufferLayout(attributeManager.getBufferLayouts(filterModel));
this.setState({filterFBO, filterModel});
}
}
Expand Down Expand Up @@ -311,32 +313,35 @@ export default class DataFilterExtension extends LayerExtension<

/* eslint-disable-next-line camelcase */
if (filterNeedsUpdate && onFilteredItemsChange && filterModel) {
const attributeManager = this.getAttributeManager()!;
const {
attributes: {filterValues, filterCategoryValues, filterIndices}
} = this.getAttributeManager()!;
} = attributeManager;
filterModel.setVertexCount(this.getNumInstances());

this.context.device.clearWebGL({framebuffer: filterFBO, color: [0, 0, 0, 0]});

filterModel.updateModuleSettings(params.moduleParameters);
// @ts-expect-error filterValue and filterIndices should always have buffer value
filterModel.setAttributes({
const attributes: Record<string, Buffer> = {
...filterValues?.getValue(),
...filterCategoryValues?.getValue(),
...filterIndices?.getValue()
};
filterModel.setAttributes(attributes);
filterModel.shaderInputs.setProps({
dataFilter: dataFilterProps
});
filterModel.shaderInputs.setProps({dataFilter: dataFilterProps});
filterModel.device.withParametersWebGL(
{
framebuffer: filterFBO,
// ts-ignore 'readonly' cannot be assigned to the mutable type '[GLBlendEquation, GLBlendEquation]'
...(aggregator.parameters as any),
viewport: [0, 0, filterFBO.width, filterFBO.height]
},
() => {
filterModel.draw(this.context.renderPass);
}
);

const viewport = [0, 0, filterFBO.width, filterFBO.height] as NumberArray4;

const renderPass = filterModel.device.beginRenderPass({
id: 'data-filter-aggregation',
framebuffer: filterFBO,
parameters: {viewport},
clearColor: [0, 0, 0, 0]
});
filterModel.setParameters(aggregator.parameters);
filterModel.draw(renderPass);
renderPass.end();

const color = filterModel.device.readPixelsToArrayWebGL(filterFBO);
let count = 0;
for (let i = 0; i < color.length; i++) {
Expand Down
8 changes: 7 additions & 1 deletion test/modules/extensions/data-filter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ test('DataFilterExtension#categories', t => {

test('DataFilterExtension#countItems', t => {
let cbCalled = 0;
let cbCount = -1;

const testCases = [
{
Expand All @@ -150,12 +151,16 @@ test('DataFilterExtension#countItems', t => {
],
getPosition: d => d.position,
getFilterValue: d => d.timestamp,
onFilteredItemsChange: () => cbCalled++,
onFilteredItemsChange: event => {
cbCalled++;
cbCount = event.count;
},
filterRange: [80, 160],
extensions: [new DataFilterExtension({filterSize: 1, countItems: true})]
},
onAfterUpdate: () => {
t.is(cbCalled, 1, 'onFilteredItemsChange is called');
t.is(cbCount, 2, 'count is correct');
}
},
{
Expand All @@ -172,6 +177,7 @@ test('DataFilterExtension#countItems', t => {
},
onAfterUpdate: () => {
t.is(cbCalled, 2, 'onFilteredItemsChange is called');
t.is(cbCount, 0, 'count is correct');
}
}
];
Expand Down
Loading