Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
17 changes: 9 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"@types/w3c-image-capture": "^1.0.10",
"@typescript-eslint/eslint-plugin": "^6.9.1",
"@typescript-eslint/parser": "^6.9.1",
"@webgpu/types": "^0.1.59",
"@webgpu/types": "^0.1.60",
"ansi-colors": "4.1.3",
"babel-plugin-add-header-comment": "^1.0.3",
"babel-plugin-const-enum": "^1.2.0",
Expand Down
51 changes: 41 additions & 10 deletions src/webgpu/api/operation/command_buffer/copyBufferToBuffer.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export const description = 'copyBufferToBuffer operation tests';

import { makeTestGroup } from '../../../../common/framework/test_group.js';
import { assert } from '../../../../common/util/util.js';
import { AllFeaturesMaxLimitsGPUTest } from '../../../gpu_test.js';

export const g = makeTestGroup(AllFeaturesMaxLimitsGPUTest);
Expand All @@ -16,13 +17,30 @@ g.test('single')
- covers the end of the dstBuffer
- covers neither the beginning nor the end of the dstBuffer`
)
.paramsSubcasesOnly(u =>
.params(u =>
u //
.combine('srcOffset', [0, 4, 8, 16])
.combine('dstOffset', [0, 4, 8, 16])
.combine('copySize', [0, 4, 8, 16])
.expand('srcBufferSize', p => [p.srcOffset + p.copySize, p.srcOffset + p.copySize + 8])
.expand('dstBufferSize', p => [p.dstOffset + p.copySize, p.dstOffset + p.copySize + 8])
// Whether the test case requires the newly-added method signature or not.
.combine('newSig', [false, true])
.beginSubcases()
.combine('srcOffset', [0, 4, 8, 16, undefined])
.combine('dstOffset', [0, 4, 8, 16, undefined])
.unless(
p => (p.srcOffset === undefined || p.dstOffset === undefined) && p.srcOffset !== p.dstOffset
)
.combine('copySize', [0, 4, 8, 16, undefined])
.expand('srcBufferSize', p => [
(p.srcOffset ?? 0) + (p.copySize ?? 0),
(p.srcOffset ?? 0) + (p.copySize ?? 0) + 8,
])
.expand('dstBufferSize', p => [
(p.dstOffset ?? 0) + (p.copySize ?? 0),
(p.dstOffset ?? 0) + (p.copySize ?? 0) + 8,
])
// Bifurcate the cases between newSig=false and newSig=true based on whether they need it.
.filter(p => {
const needsNewSignature = [p.srcOffset, p.dstOffset, p.copySize].includes(undefined);
return p.newSig === needsNewSignature;
})
)
.fn(t => {
const { srcOffset, dstOffset, copySize, srcBufferSize, dstBufferSize } = t.params;
Expand All @@ -40,12 +58,25 @@ g.test('single')
});

const encoder = t.device.createCommandEncoder();
encoder.copyBufferToBuffer(src, srcOffset, dst, dstOffset, copySize);
t.device.queue.submit([encoder.finish()]);
if (srcOffset === undefined || dstOffset === undefined) {
assert(srcOffset === undefined && dstOffset === undefined);
encoder.copyBufferToBuffer(src, dst, copySize);
} else {
encoder.copyBufferToBuffer(src, srcOffset, dst, dstOffset, copySize);
}

const expectedSrcOffset = srcOffset ?? 0;
const expectedDstOffset = dstOffset ?? 0;
const expectedCopySize = copySize ?? srcBufferSize - expectedSrcOffset;

const isValid = dstBufferSize - expectedDstOffset >= expectedCopySize;
t.expectValidationError(() => {
t.device.queue.submit([encoder.finish()]);
}, !isValid);

const expectedDstData = new Uint8Array(dstBufferSize);
for (let i = 0; i < copySize; ++i) {
expectedDstData[dstOffset + i] = srcData[srcOffset + i];
for (let i = 0; i < expectedCopySize; ++i) {
expectedDstData[expectedDstOffset + i] = srcData[expectedSrcOffset + i];
}

t.expectGPUBufferValuesEqual(dst, expectedDstData);
Expand Down