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

DataFilterExtension category filtering uint32 attribute #9350

Merged
merged 3 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
9 changes: 8 additions & 1 deletion modules/extensions/src/data-filter/data-filter-extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ const defaultOptions: Required<DataFilterExtensionOptions> = {
countItems: false
};

const CATEGORY_TYPE_FROM_SIZE = {
1: 'uint' as const,
Copy link
Collaborator

Choose a reason for hiding this comment

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

This will need another pass for WebGPU some day...

2: 'uvec2' as const,
3: 'uvec3' as const,
4: 'uvec4' as const
};
const DATA_TYPE_FROM_SIZE = {
1: 'float' as const,
2: 'vec2' as const,
Expand All @@ -137,7 +143,7 @@ export default class DataFilterExtension extends LayerExtension<
const {categorySize, filterSize, fp64} = extension.opts;
const defines: Defines = {};
if (categorySize) {
defines.DATACATEGORY_TYPE = DATA_TYPE_FROM_SIZE[categorySize];
defines.DATACATEGORY_TYPE = CATEGORY_TYPE_FROM_SIZE[categorySize];
defines.DATACATEGORY_CHANNELS = categorySize;
}
if (filterSize) {
Expand Down Expand Up @@ -173,6 +179,7 @@ export default class DataFilterExtension extends LayerExtension<
size: categorySize,
stepMode: 'dynamic',
accessor: 'getFilterCategory',
type: 'uint32',
transform:
categorySize === 1
? d => extension._getCategoryKey.call(this, d, 0)
Expand Down
24 changes: 12 additions & 12 deletions modules/extensions/src/data-filter/shader-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export type Defines = {
/**
* Primitive type of parameter used for category filtering. If undefined, category filtering disabled.
*/
DATACATEGORY_TYPE?: 'float' | 'vec2' | 'vec3' | 'vec4';
DATACATEGORY_TYPE?: 'uint' | 'uvec2' | 'uvec3' | 'uvec4';
/**
* Number of category filtering channels. Must match dimension of `DATACATEGORY_TYPE`
*/
Expand Down Expand Up @@ -48,7 +48,7 @@ uniform dataFilterUniforms {
#endif
#endif
#ifdef DATACATEGORY_TYPE
highp ivec4 categoryBitMask;
highp uvec4 categoryBitMask;
#endif
} dataFilter;
`;
Expand Down Expand Up @@ -107,26 +107,26 @@ float dataFilter_reduceValue(vec4 value) {
#ifdef DATACATEGORY_TYPE
void dataFilter_setCategoryValue(DATACATEGORY_TYPE category) {
#if DATACATEGORY_CHANNELS == 1 // One 128-bit mask
int dataFilter_masks = dataFilter.categoryBitMask[int(category / 32.0)];
uint dataFilter_masks = dataFilter.categoryBitMask[category / 32u];
#elif DATACATEGORY_CHANNELS == 2 // Two 64-bit masks
ivec2 dataFilter_masks = ivec2(
dataFilter.categoryBitMask[int(category.x / 32.0)],
dataFilter.categoryBitMask[int(category.y / 32.0) + 2]
uvec2 dataFilter_masks = uvec2(
dataFilter.categoryBitMask[category.x / 32u],
dataFilter.categoryBitMask[category.y / 32u + 2u]
);
#elif DATACATEGORY_CHANNELS == 3 // Three 32-bit masks
ivec3 dataFilter_masks = dataFilter.categoryBitMask.xyz;
uvec3 dataFilter_masks = dataFilter.categoryBitMask.xyz;
#else // Four 32-bit masks
ivec4 dataFilter_masks = dataFilter.categoryBitMask;
uvec4 dataFilter_masks = dataFilter.categoryBitMask;
#endif

// Shift mask and extract relevant bits
DATACATEGORY_TYPE dataFilter_bits = DATACATEGORY_TYPE(dataFilter_masks) / pow(DATACATEGORY_TYPE(2.0), mod(category, 32.0));
dataFilter_bits = mod(floor(dataFilter_bits), 2.0);
DATACATEGORY_TYPE dataFilter_bits = DATACATEGORY_TYPE(dataFilter_masks) >> (category & 31u);
dataFilter_bits &= 1u;

#if DATACATEGORY_CHANNELS == 1
if(dataFilter_bits == 0.0) dataFilter_value = 0.0;
if(dataFilter_bits == 0u) dataFilter_value = 0.0;
#else
if(any(equal(dataFilter_bits, DATACATEGORY_TYPE(0.0)))) dataFilter_value = 0.0;
if(any(equal(dataFilter_bits, DATACATEGORY_TYPE(0u)))) dataFilter_value = 0.0;
#endif
}
#endif
Expand Down
Loading