Skip to content

Conversation

@shaoboyan091
Copy link
Contributor

immediateSize attribute is used for pipeline layout creation. It requires immediateSize must be a multiple of 4 and immediateSize must be smaller or equal to maxImmediateSize.

Issue: #


Requirements for PR author:

  • All missing test coverage is tracked with "TODO" or .unimplemented().
  • New helpers are /** documented */ and new helper files are found in helper_index.txt.
  • Test behaves as expected in a WebGPU implementation. (If not passing, explain above.)
  • Test have be tested with compatibility mode validation enabled and behave as expected. (If not passing, explain above.)

Requirements for reviewer sign-off:

  • Tests are properly located.
  • Test descriptions are accurate and complete.
  • Tests provide complete coverage (including validation control cases). Missing coverage MUST be covered by TODOs.
  • Tests avoid over-parameterization (see case count report).

When landing this PR, be sure to make any necessary issue status updates.

@github-actions
Copy link

github-actions bot commented Jan 21, 2026

Results for build job (at 3a32182):

(No pr-comment-body.txt artifact found from this job.)

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds validation tests for the experimental immediateSize attribute used in pipeline layout creation. The tests verify that immediateSize must be a multiple of 4 and must not exceed device.limits.maxImmediateSize.

Changes:

  • Added a new test immediate_data_size to validate immediateSize parameter constraints
  • Added supportsImmediateData helper function to check for immediate data support

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/webgpu/api/validation/createPipelineLayout.spec.ts Added validation test for immediateSize parameter with edge case coverage including valid/invalid multiples of 4 and boundary values
src/common/util/util.ts Added supportsImmediateData helper function to detect immediate data feature support through prototype and language feature checks

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +532 to +538
export function supportsImmediateData(gpu: GPU): boolean {
return (
'setImmediates' in GPURenderPassEncoder.prototype ||
'setImmediates' in GPUComputePassEncoder.prototype ||
'setImmediates' in GPURenderBundleEncoder.prototype ||
'maxImmediateSize' in GPUSupportedLimits.prototype ||
gpu.wgslLanguageFeatures.has('immediate_address_space')
Copy link

Copilot AI Jan 21, 2026

Choose a reason for hiding this comment

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

The function signature expects a GPU parameter, but it's being called from test code with the test context object (line 526 in createPipelineLayout.spec.ts). The function should accept a parameter that allows accessing the GPU object through getGPU(t.rec) pattern, similar to how it's done in other tests like setImmediates.spec.ts. Consider changing the signature to accept a test recorder or the test context instead of directly requiring a GPU object.

Suggested change
export function supportsImmediateData(gpu: GPU): boolean {
return (
'setImmediates' in GPURenderPassEncoder.prototype ||
'setImmediates' in GPUComputePassEncoder.prototype ||
'setImmediates' in GPURenderBundleEncoder.prototype ||
'maxImmediateSize' in GPUSupportedLimits.prototype ||
gpu.wgslLanguageFeatures.has('immediate_address_space')
export function supportsImmediateData(): boolean {
// Try to detect support via global WebGPU language features, if available.
let hasImmediateAddressSpace = false;
const nav: unknown = typeof navigator !== 'undefined' ? navigator : undefined;
const maybeGpu =
nav && typeof nav === 'object' && 'gpu' in nav ? (nav as { gpu: unknown }).gpu : undefined;
if (maybeGpu && typeof maybeGpu === 'object' && 'wgslLanguageFeatures' in maybeGpu) {
const languageFeatures = (maybeGpu as { wgslLanguageFeatures: GPUSupportedFeatures })
.wgslLanguageFeatures;
if (
languageFeatures &&
typeof languageFeatures.has === 'function' &&
languageFeatures.has('immediate_address_space')
) {
hasImmediateAddressSpace = true;
}
}
return (
'setImmediates' in GPURenderPassEncoder.prototype ||
'setImmediates' in GPUComputePassEncoder.prototype ||
'setImmediates' in GPURenderBundleEncoder.prototype ||
'maxImmediateSize' in GPUSupportedLimits.prototype ||
hasImmediateAddressSpace

Copilot uses AI. Check for mistakes.
immediateSize attribute is used for pipeline layout creation. It requires
immediateSize must be a multiple of 4 and immediateSize must be smaller
or equal to maxImmediateSize.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 4 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +527 to +530
if (!supportsImmediateData(getGPU(t.rec))) {
t.skip('Immediate data not supported');
return;
}
Copy link

Copilot AI Jan 21, 2026

Choose a reason for hiding this comment

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

The check for immediate data support is performed inside the test function instead of being handled at the fixture level like similar tests. This pattern is inconsistent with how the setImmediates tests handle the same feature detection. Consider creating a custom test fixture class (similar to SetImmediatesTest) that performs this check in the init() method, or use t.skipIf() instead of t.skip() with an early return pattern, which is more common in this codebase.

Suggested change
if (!supportsImmediateData(getGPU(t.rec))) {
t.skip('Immediate data not supported');
return;
}
t.skipIf(!supportsImmediateData(getGPU(t.rec)), 'Immediate data not supported');

Copilot uses AI. Check for mistakes.
return;
}

const maxImmediateSize = t.device.limits.maxImmediateSize!;
Copy link

Copilot AI Jan 21, 2026

Choose a reason for hiding this comment

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

The non-null assertion operator is used on t.device.limits.maxImmediateSize without verifying that the value exists. If immediate data is supported but maxImmediateSize is not available on the device limits, this could cause a runtime error. Consider adding a validation check that maxImmediateSize is defined, similar to how the setImmediates tests handle this in lines 173-176 of setImmediates.spec.ts.

Suggested change
const maxImmediateSize = t.device.limits.maxImmediateSize!;
const maxImmediateSize = t.device.limits.maxImmediateSize;
if (maxImmediateSize === undefined) {
t.skip('maxImmediateSize limit is not available on this device');
return;
}

Copilot uses AI. Check for mistakes.
- immediateSize must be <= device.limits.maxImmediateSize.
`
)
.params(u => u.combine('immediateSize', [0, 4, 'max', 'max+4', 1, 2, 3, 5] as const))
Copy link

Copilot AI Jan 21, 2026

Choose a reason for hiding this comment

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

The test parameters include both positive and negative test cases mixed together in a single parameterization. Consider organizing the test parameters more clearly, separating valid cases (0, 4, 'max') from invalid alignment cases (1, 2, 3, 5) and invalid range cases ('max+4'). This would make the test's intent clearer and easier to understand at a glance.

Suggested change
.params(u => u.combine('immediateSize', [0, 4, 'max', 'max+4', 1, 2, 3, 5] as const))
.params(u => {
const validImmediateSizes = [0, 4, 'max'] as const;
const invalidAlignmentImmediateSizes = [1, 2, 3, 5] as const;
const invalidRangeImmediateSizes = ['max+4'] as const;
return u.combine('immediateSize', [
...validImmediateSizes,
...invalidAlignmentImmediateSizes,
...invalidRangeImmediateSizes,
] as const);
})

Copilot uses AI. Check for mistakes.
Comment on lines +532 to +539
export function supportsImmediateData(gpu: GPU): boolean {
return (
'setImmediates' in GPURenderPassEncoder.prototype ||
'setImmediates' in GPUComputePassEncoder.prototype ||
'setImmediates' in GPURenderBundleEncoder.prototype ||
'maxImmediateSize' in GPUSupportedLimits.prototype ||
gpu.wgslLanguageFeatures.has('immediate_address_space')
);
Copy link

Copilot AI Jan 21, 2026

Choose a reason for hiding this comment

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

The supportsImmediateData helper function accepts a GPU parameter but never uses it in most of the checks. Only the last check (gpu.wgslLanguageFeatures.has) actually uses the parameter. The other checks examine prototypes which don't require the GPU instance. Consider either removing the unused parameter or documenting why it's included for future extensibility.

Copilot uses AI. Check for mistakes.
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.

1 participant