Skip to content

Conversation

@shaoboyan091
Copy link
Contributor

@shaoboyan091 shaoboyan091 commented Dec 3, 2025

This PR adding validation tests to cover setImmediates API in different encoder types (compute pass, render pass, render bundle) by covering:

  • Interpretation:
    • Passing a TypedArray, the data offset and size are given in elements (not bytes).
  • Alignment:
    • rangeOffset is not a multiple of 4 bytes.
    • content size, converted to bytes, is not a multiple of 4 bytes.
  • Arithmetic overflow
    • rangeOffset + contentSize is overflow
  • Bounds:
    • dataOffset + contentSize (in bytes) exceeds the content data size.
    • rangeOffset + contentSize (in bytes) exceeds the 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 in the test tree.
  • Test descriptions allow a reader to "read only the test plans and evaluate coverage completeness", and accurately reflect the test code.
  • Tests provide complete coverage (including validation control cases). Missing coverage MUST be covered by TODOs.
  • Helpers and types promote readability and maintainability.

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

Copy link

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 comprehensive validation tests for the setImmediates API across different encoder types (compute pass, render pass, render bundle). The tests validate interpretation of TypedArray data offsets/sizes, alignment requirements, arithmetic overflow handling, and bounds checking.

  • Adds validation tests for setImmediates API covering interpretation, alignment, overflow, and bounds scenarios
  • Tests validate that data offset and size are interpreted as bytes (not elements) for TypedArrays
  • Updates @webgpu/types package from version 0.1.66 to 0.1.67 to support the new API

Reviewed changes

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

File Description
src/webgpu/api/validation/encoding/cmds/setImmediates.spec.ts New test file implementing comprehensive validation tests for the setImmediates API across different encoder types
package.json Updates @webgpu/types dependency to version 0.1.67
package-lock.json Updates package lock file to reflect new @webgpu/types version with corresponding integrity hashes

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

Copy link

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 2 out of 3 changed files in this pull request and generated 4 comments.


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

Copy link

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 2 out of 3 changed files in this pull request and generated 4 comments.


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

This PR adding validation tests to cover setImmediates API in  different
encoder types (compute pass, render pass, render bundle) by covering:
  * Interpretation:
    - Passing a TypedArray the data offset and size is not given in elements.
  * Alignment:
    - rangeOffset is not a multiple of 4 bytes.
    - content size, converted to bytes, is not a multiple of 4 bytes.
  * Arithmetic overflow
    - rangeOffset + contentSize is overflow
  * Bounds:
    - dataOffset + size (in bytes) exceeds the content data size.
    - rangeOffset + size (in bytes) exceeds the maxImmdiateSize.
Copy link

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 1 out of 1 changed files in this pull request and generated 3 comments.


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

Copy link

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 1 out of 1 changed files in this pull request and generated 2 comments.


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

Copy link

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 1 out of 1 changed files in this pull request and generated 3 comments.


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

Copy link

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 1 out of 1 changed files in this pull request and generated 4 comments.


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

});

g.test('overflow')
.desc('Tests that rangeOffset + contentSize exceeds Number.MAX_SAFE_INTEGER.')
Copy link

Copilot AI Dec 8, 2025

Choose a reason for hiding this comment

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

In the description, there's a grammatical issue. The description should read "Tests that rangeOffset + contentSize do not exceed Number.MAX_SAFE_INTEGER" or "Tests the case when rangeOffset + contentSize exceeds Number.MAX_SAFE_INTEGER" to be clearer about what is being validated. Currently "exceeds" suggests the test is checking that overflow occurs, but based on the test logic, it should be preventing overflow.

Suggested change
.desc('Tests that rangeOffset + contentSize exceeds Number.MAX_SAFE_INTEGER.')
.desc('Tests that rangeOffset + contentSize do not exceed Number.MAX_SAFE_INTEGER.')

Copilot uses AI. Check for mistakes.
- rangeOffset is not a multiple of 4 bytes.
- content size, converted to bytes, is not a multiple of 4 bytes.
* Arithmetic overflow
- rangeOffset + contentSize is overflow
Copy link

Copilot AI Dec 8, 2025

Choose a reason for hiding this comment

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

Grammar issue: "is overflow" is incorrect. Should be "overflows" or "causes overflow".

Suggested change
- rangeOffset + contentSize is overflow
- rangeOffset + contentSize overflows

Copilot uses AI. Check for mistakes.
Comment on lines +137 to +138
.desc(
'Tests that rangeOffset + contentSize is greater than maxImmediateSize and contentSize is larger than data size.'
Copy link

Copilot AI Dec 8, 2025

Choose a reason for hiding this comment

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

Grammar issue: "contentSize" is singular, so it should be "is larger" not "are larger".

Copilot uses AI. Check for mistakes.
Comment on lines +109 to +124
{
offset: 8,
contentByteSize: kMaxSafeMultipleOf8,
_rangeValid: true,
_contentValid: false,
},
] as const)
)
.fn(t => {
const { encoderType, offset, contentByteSize, _rangeValid, _contentValid } = t.params;
const data = new Uint8Array(t.device.limits.maxImmediateSize);

const { encoder, validateFinish } = t.createEncoder(encoderType);

const doSetImmediates = () => {
encoder.setImmediates(offset, data, 0, contentByteSize);
Copy link

Copilot AI Dec 8, 2025

Choose a reason for hiding this comment

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

The overflow test creates a Uint8Array with size maxImmediateSize, but the overflow test case attempts to use contentByteSize: kMaxSafeMultipleOf8 (approximately 9e15). This will throw a RangeError due to accessing data beyond the array bounds (lines 163-170 in the out_of_bounds test also validate this scenario), not due to arithmetic overflow of rangeOffset + contentSize.

The test expects a RangeError (due to _contentValid: false), but this conflates two different validation errors: data bounds checking vs arithmetic overflow checking. The _rangeValid: true parameter suggests the range validation should pass, but since a RangeError is thrown earlier for bounds checking, the validateFinish(_rangeValid) call never actually validates the overflow behavior.

Consider separating these concerns: use a sufficiently large data array for the overflow test, or adjust the test to properly distinguish between bounds errors and overflow errors.

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