From 841716786f0314452b6a91868e5ee2dce2a330d3 Mon Sep 17 00:00:00 2001 From: Felix Palmer Date: Tue, 17 Sep 2024 15:03:43 +0200 Subject: [PATCH 1/8] drawMode -> topology --- modules/extensions/src/data-filter/aggregator.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/extensions/src/data-filter/aggregator.ts b/modules/extensions/src/data-filter/aggregator.ts index 14d2333b267..9bd55e749a7 100644 --- a/modules/extensions/src/data-filter/aggregator.ts +++ b/modules/extensions/src/data-filter/aggregator.ts @@ -94,7 +94,7 @@ 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 From 69240a0cab331c3f15da13f859b6806c336319c4 Mon Sep 17 00:00:00 2001 From: Felix Palmer Date: Tue, 17 Sep 2024 15:06:26 +0200 Subject: [PATCH 2/8] Try using renderpass --- .../src/data-filter/data-filter-extension.ts | 42 ++++++++++++------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/modules/extensions/src/data-filter/data-filter-extension.ts b/modules/extensions/src/data-filter/data-filter-extension.ts index 269afe67ebe..d0152ca28c1 100644 --- a/modules/extensions/src/data-filter/data-filter-extension.ts +++ b/modules/extensions/src/data-filter/data-filter-extension.ts @@ -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}, @@ -316,27 +317,40 @@ export default class DataFilterExtension extends LayerExtension< } = this.getAttributeManager()!; 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({ ...filterValues?.getValue(), ...filterCategoryValues?.getValue(), ...filterIndices?.getValue() }); - 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.shaderInputs.setProps({ + dataFilter: dataFilterProps + }); + + const viewport = [0, 0, filterFBO.width, filterFBO.height] as NumberArray4; + + const renderPass = filterModel.device.beginRenderPass({ + id: 'data-filter-count', + framebuffer: filterFBO, + parameters: { + viewport }, - () => { - filterModel.draw(this.context.renderPass); - } - ); + clearColor: [0, 0, 0, 0], + clearDepth: 1 + }); + filterModel.setParameters({ + blend: true, + blendColorSrcFactor: 'one', + blendColorDstFactor: 'one', + blendAlphaSrcFactor: 'one', + blendAlphaDstFactor: 'one', + blendColorOperation: 'add', + blendAlphaOperation: 'add', + depthCompare: 'never' + }); + filterModel.draw(renderPass); + renderPass.end(); + const color = filterModel.device.readPixelsToArrayWebGL(filterFBO); let count = 0; for (let i = 0; i < color.length; i++) { From 8304b3dcff08f380fe96001a8869a0f1c7ccf348 Mon Sep 17 00:00:00 2001 From: Felix Palmer Date: Tue, 17 Sep 2024 16:22:55 +0200 Subject: [PATCH 3/8] Disable vertex check --- modules/extensions/src/data-filter/aggregator.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/extensions/src/data-filter/aggregator.ts b/modules/extensions/src/data-filter/aggregator.ts index 9bd55e749a7..621b3b91b03 100644 --- a/modules/extensions/src/data-filter/aggregator.ts +++ b/modules/extensions/src/data-filter/aggregator.ts @@ -19,7 +19,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); vColor = vec4(0.0, 0.0, 0.0, 1.0); #else From a45f4e4a9e78977f5a51de75d7d09f63b594d67e Mon Sep 17 00:00:00 2001 From: Felix Palmer Date: Tue, 17 Sep 2024 16:24:53 +0200 Subject: [PATCH 4/8] Model fixes --- .../src/data-filter/data-filter-extension.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/modules/extensions/src/data-filter/data-filter-extension.ts b/modules/extensions/src/data-filter/data-filter-extension.ts index d0152ca28c1..1d082c9a10c 100644 --- a/modules/extensions/src/data-filter/data-filter-extension.ts +++ b/modules/extensions/src/data-filter/data-filter-extension.ts @@ -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'; @@ -312,17 +312,20 @@ 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()); + filterModel.setBufferLayout(attributeManager.getBufferLayouts(filterModel)); // @ts-expect-error filterValue and filterIndices should always have buffer value - filterModel.setAttributes({ + const attributes: Record = { ...filterValues?.getValue(), ...filterCategoryValues?.getValue(), ...filterIndices?.getValue() - }); + }; + filterModel.setAttributes(attributes); filterModel.shaderInputs.setProps({ dataFilter: dataFilterProps }); From f3a1f312fb0411acd51ec8a7a73db8930d2727f6 Mon Sep 17 00:00:00 2001 From: Felix Palmer Date: Tue, 17 Sep 2024 16:26:42 +0200 Subject: [PATCH 5/8] Only get buffer layout once --- modules/extensions/src/data-filter/data-filter-extension.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/extensions/src/data-filter/data-filter-extension.ts b/modules/extensions/src/data-filter/data-filter-extension.ts index 1d082c9a10c..25b370f2e0f 100644 --- a/modules/extensions/src/data-filter/data-filter-extension.ts +++ b/modules/extensions/src/data-filter/data-filter-extension.ts @@ -230,6 +230,7 @@ export default class DataFilterExtension extends LayerExtension< extension.getShaders.call(this, extension), useFloatTarget ); + filterModel.setBufferLayout(attributeManager.getBufferLayouts(filterModel)); this.setState({filterFBO, filterModel}); } } @@ -317,7 +318,6 @@ export default class DataFilterExtension extends LayerExtension< attributes: {filterValues, filterCategoryValues, filterIndices} } = attributeManager; filterModel.setVertexCount(this.getNumInstances()); - filterModel.setBufferLayout(attributeManager.getBufferLayouts(filterModel)); // @ts-expect-error filterValue and filterIndices should always have buffer value const attributes: Record = { From f9fcf1f333def9e9d4732756630635daa7867966 Mon Sep 17 00:00:00 2001 From: Felix Palmer Date: Tue, 17 Sep 2024 16:33:11 +0200 Subject: [PATCH 6/8] Tidy --- .../extensions/src/data-filter/aggregator.ts | 15 ++++++++------ .../src/data-filter/data-filter-extension.ts | 20 ++++--------------- 2 files changed, 13 insertions(+), 22 deletions(-) diff --git a/modules/extensions/src/data-filter/aggregator.ts b/modules/extensions/src/data-filter/aggregator.ts index 621b3b91b03..5d0d0cf0c84 100644 --- a/modules/extensions/src/data-filter/aggregator.ts +++ b/modules/extensions/src/data-filter/aggregator.ts @@ -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 @@ -102,9 +101,13 @@ export function getModel(device: Device, shaderOptions: any, useFloatTarget: boo }); } -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; diff --git a/modules/extensions/src/data-filter/data-filter-extension.ts b/modules/extensions/src/data-filter/data-filter-extension.ts index 25b370f2e0f..29f50bce1e9 100644 --- a/modules/extensions/src/data-filter/data-filter-extension.ts +++ b/modules/extensions/src/data-filter/data-filter-extension.ts @@ -333,24 +333,12 @@ export default class DataFilterExtension extends LayerExtension< const viewport = [0, 0, filterFBO.width, filterFBO.height] as NumberArray4; const renderPass = filterModel.device.beginRenderPass({ - id: 'data-filter-count', + id: 'data-filter-aggregation', framebuffer: filterFBO, - parameters: { - viewport - }, - clearColor: [0, 0, 0, 0], - clearDepth: 1 - }); - filterModel.setParameters({ - blend: true, - blendColorSrcFactor: 'one', - blendColorDstFactor: 'one', - blendAlphaSrcFactor: 'one', - blendAlphaDstFactor: 'one', - blendColorOperation: 'add', - blendAlphaOperation: 'add', - depthCompare: 'never' + parameters: {viewport}, + clearColor: [0, 0, 0, 0] }); + filterModel.setParameters(aggregator.parameters); filterModel.draw(renderPass); renderPass.end(); From a769749348d5ad9c82330a79874d979393460343 Mon Sep 17 00:00:00 2001 From: Felix Palmer Date: Tue, 17 Sep 2024 16:37:06 +0200 Subject: [PATCH 7/8] Improve test --- test/modules/extensions/data-filter.spec.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/modules/extensions/data-filter.spec.ts b/test/modules/extensions/data-filter.spec.ts index 1491a6eed6a..c307ec568ff 100644 --- a/test/modules/extensions/data-filter.spec.ts +++ b/test/modules/extensions/data-filter.spec.ts @@ -140,6 +140,7 @@ test('DataFilterExtension#categories', t => { test('DataFilterExtension#countItems', t => { let cbCalled = 0; + let cbCount = -1; const testCases = [ { @@ -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'); } }, { @@ -172,6 +177,7 @@ test('DataFilterExtension#countItems', t => { }, onAfterUpdate: () => { t.is(cbCalled, 2, 'onFilteredItemsChange is called'); + t.is(cbCount, 0, 'count is correct'); } } ]; From 3daae3e3a78d11dbb8652fea59f9a648f39ca241 Mon Sep 17 00:00:00 2001 From: Xiaoji Chen Date: Wed, 25 Sep 2024 17:29:10 -0700 Subject: [PATCH 8/8] Fix filterIndices attribute --- modules/extensions/src/data-filter/aggregator.ts | 13 +++++++++---- .../src/data-filter/data-filter-extension.ts | 10 +++++----- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/modules/extensions/src/data-filter/aggregator.ts b/modules/extensions/src/data-filter/aggregator.ts index 5d0d0cf0c84..80d66ea5d67 100644 --- a/modules/extensions/src/data-filter/aggregator.ts +++ b/modules/extensions/src/data-filter/aggregator.ts @@ -1,5 +1,5 @@ import {Device, DeviceFeature, Framebuffer, RenderPipelineParameters} from '@luma.gl/core'; -import {Model} from '@luma.gl/engine'; +import {Model, ModelProps} from '@luma.gl/engine'; const AGGREGATE_VS = `\ #version 300 es @@ -18,8 +18,7 @@ const float component = 1.0 / 255.0; void main() { #ifdef FLOAT_TARGET - // BUG: always 0 for some reason - // dataFilter_value *= float(filterIndices != filterPrevIndices); + dataFilter_value *= float(filterIndices != filterPrevIndices); gl_Position = vec4(0.0, 0.0, 0.0, 1.0); vColor = vec4(0.0, 0.0, 0.0, 1.0); #else @@ -84,7 +83,12 @@ export function getFramebuffer(device: Device, useFloatTarget: boolean): Framebu } // Increments the counter based on dataFilter_value -export function getModel(device: Device, shaderOptions: any, useFloatTarget: boolean): Model { +export function getModel( + device: Device, + bufferLayout: ModelProps['bufferLayout'], + shaderOptions: any, + useFloatTarget: boolean +): Model { shaderOptions.defines.NON_INSTANCED_MODEL = 1; if (useFloatTarget) { shaderOptions.defines.FLOAT_TARGET = 1; @@ -97,6 +101,7 @@ export function getModel(device: Device, shaderOptions: any, useFloatTarget: boo topology: 'point-list', vs: AGGREGATE_VS, fs: AGGREGATE_FS, + bufferLayout, ...shaderOptions }); } diff --git a/modules/extensions/src/data-filter/data-filter-extension.ts b/modules/extensions/src/data-filter/data-filter-extension.ts index 29f50bce1e9..768ae8aea44 100644 --- a/modules/extensions/src/data-filter/data-filter-extension.ts +++ b/modules/extensions/src/data-filter/data-filter-extension.ts @@ -205,7 +205,7 @@ export default class DataFilterExtension extends LayerExtension< // The vertex shader checks if a vertex has the same "index" as the previous vertex // so that we only write one count cross multiple vertices of the same object attributeManager.add({ - filterIndices: { + filterVertexIndices: { size: useFloatTarget ? 1 : 2, vertexOffset: 1, type: 'unorm8', @@ -227,10 +227,10 @@ export default class DataFilterExtension extends LayerExtension< const filterFBO = aggregator.getFramebuffer(device, useFloatTarget); const filterModel = aggregator.getModel( device, + attributeManager.getBufferLayouts({isInstanced: false}), extension.getShaders.call(this, extension), useFloatTarget ); - filterModel.setBufferLayout(attributeManager.getBufferLayouts(filterModel)); this.setState({filterFBO, filterModel}); } } @@ -315,15 +315,15 @@ export default class DataFilterExtension extends LayerExtension< if (filterNeedsUpdate && onFilteredItemsChange && filterModel) { const attributeManager = this.getAttributeManager()!; const { - attributes: {filterValues, filterCategoryValues, filterIndices} + attributes: {filterValues, filterCategoryValues, filterVertexIndices} } = attributeManager; filterModel.setVertexCount(this.getNumInstances()); - // @ts-expect-error filterValue and filterIndices should always have buffer value + // @ts-expect-error filterValue and filterVertexIndices should always have buffer value const attributes: Record = { ...filterValues?.getValue(), ...filterCategoryValues?.getValue(), - ...filterIndices?.getValue() + ...filterVertexIndices?.getValue() }; filterModel.setAttributes(attributes); filterModel.shaderInputs.setProps({