-
Notifications
You must be signed in to change notification settings - Fork 101
Add immediate size validation tests for pipeline layout creation. #4572
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
base: main
Are you sure you want to change the base?
Conversation
41cde25 to
3a32182
Compare
There was a problem hiding this 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_sizeto validateimmediateSizeparameter constraints - Added
supportsImmediateDatahelper 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.
| 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') |
Copilot
AI
Jan 21, 2026
There was a problem hiding this comment.
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.
| 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 |
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.
3a32182 to
49d9432
Compare
There was a problem hiding this 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.
| if (!supportsImmediateData(getGPU(t.rec))) { | ||
| t.skip('Immediate data not supported'); | ||
| return; | ||
| } |
Copilot
AI
Jan 21, 2026
There was a problem hiding this comment.
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.
| if (!supportsImmediateData(getGPU(t.rec))) { | |
| t.skip('Immediate data not supported'); | |
| return; | |
| } | |
| t.skipIf(!supportsImmediateData(getGPU(t.rec)), 'Immediate data not supported'); |
| return; | ||
| } | ||
|
|
||
| const maxImmediateSize = t.device.limits.maxImmediateSize!; |
Copilot
AI
Jan 21, 2026
There was a problem hiding this comment.
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.
| 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; | |
| } |
| - immediateSize must be <= device.limits.maxImmediateSize. | ||
| ` | ||
| ) | ||
| .params(u => u.combine('immediateSize', [0, 4, 'max', 'max+4', 1, 2, 3, 5] as const)) |
Copilot
AI
Jan 21, 2026
There was a problem hiding this comment.
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.
| .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); | |
| }) |
| 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') | ||
| ); |
Copilot
AI
Jan 21, 2026
There was a problem hiding this comment.
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.
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:
.unimplemented()./** documented */and new helper files are found inhelper_index.txt.Requirements for reviewer sign-off:
When landing this PR, be sure to make any necessary issue status updates.