Skip to content

Add packed integer dot product sample - #572

Open
lyonsno wants to merge 3 commits into
webgpu:mainfrom
lyonsno:cc/dp4a-recovery-0915
Open

lyonsno wants to merge 3 commits into
webgpu:mainfrom
lyonsno:cc/dp4a-recovery-0915

Conversation

@lyonsno

@lyonsno lyonsno commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Adds a small dot4I8Packed compute example toward #350.

The sample packs four signed 8-bit components into each u32, computes four example dot products, and reads the results back from the GPU. A dat.gui selector displays the input vectors and result for each example.

It requires packed_4x8_integer_dot_product and displays a requirement message when that WGSL language feature is unavailable. There is one packed compute pipeline, with no scalar fallback or in-sample result validation.

Testing

  • Lint, source typecheck, and the Node 20.20.2 build pass. The build emits existing typed-array warnings in unrelated samples.
  • Chrome 153.0.8010.48, headless with --enable-unsafe-webgpu, on an Apple Metal adapter: all four examples returned the expected results, and the dat.gui selector was exercised.
  • Desktop and narrow-screen layouts inspected. Injecting feature unavailability displayed the requirement message without requesting an adapter or compiling a shader.

No new dependencies or external assets.

Comment thread test/packedIntegerDotProduct.test.mjs Outdated

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

this code should not be so complicated that it needs tests

Comment on lines +46 to +66
export function selectRoute(
requestedRoute: RequestedRoute,
languageFeatures: ReadonlySet<string>
): RouteSelection {
const packedLanguageFeatureSupported = languageFeatures.has(
packedDotLanguageFeature
);
const wantsPacked = requestedRoute !== 'scalar';
const effectiveRoute =
wantsPacked && packedLanguageFeatureSupported ? 'packed' : 'scalar';

return {
requestedRoute,
effectiveRoute,
packedLanguageFeatureSupported,
fallbackReason:
requestedRoute === 'packed' && !packedLanguageFeatureSupported
? `WGSL language feature '${packedDotLanguageFeature}' is unavailable`
: null,
};
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

this seems excessively complicated, also I don't think we should have fallback in a sample, that makes it confusing about what implementation you're looking at

Comment on lines +83 to +94
if (actual.length !== expected.length) {
throw new Error(
`partial output: expected ${expected.length} results, received ${actual.length}`
);
}
for (let index = 0; index < expected.length; ++index) {
if (actual[index] !== expected[index]) {
throw new Error(
`result ${index} mismatch: expected ${expected[index]}, received ${actual[index]}`
);
}
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

this is a sample not a test, don't check results as it makes the total amount of code too much for the sample to be easily readable by a learner

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

please use dat.gui like other samples instead of implementing custom UI

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.

2 participants