Skip to content

Commit

Permalink
Deploying to gh-pages from @ 0f34f16 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
greggman committed Jun 11, 2024
1 parent f1f63da commit 67f5c9a
Show file tree
Hide file tree
Showing 19 changed files with 628 additions and 723 deletions.
4 changes: 2 additions & 2 deletions dist/0.x/webgpu-debug-helper.js

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

2 changes: 1 addition & 1 deletion dist/0.x/webgpu-debug-helper.js.map

Large diffs are not rendered by default.

585 changes: 300 additions & 285 deletions package-lock.json

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "webgpu-debug-helper",
"version": "0.1.0",
"version": "0.1.1",
"description": "webgpu debug helper",
"main": "dist/0.x/webgpu-debug-helper.js",
"type": "module",
Expand Down Expand Up @@ -42,9 +42,9 @@
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-typescript": "^11.1.6",
"@tsconfig/recommended": "^1.0.6",
"@typescript-eslint/eslint-plugin": "^7.6.0",
"@typescript-eslint/parser": "^7.6.0",
"@webgpu/types": "^0.1.40",
"@typescript-eslint/eslint-plugin": "^7.13.0",
"@typescript-eslint/parser": "^7.13.0",
"@webgpu/types": "^0.1.42",
"eslint": "^8.57.0",
"eslint-plugin-html": "^7.1.0",
"eslint-plugin-one-variable-per-var": "^0.0.3",
Expand All @@ -53,10 +53,10 @@
"express": "^4.19.2",
"markdown-it": "^13.0.2",
"mocha": "^10.4.0",
"puppeteer": "^21.11.0",
"rollup": "^4.14.1",
"servez": "^2.1.4",
"tslib": "^2.6.2",
"puppeteer": "^22.10.0",
"rollup": "^4.18.0",
"servez": "^2.1.6",
"tslib": "^2.6.3",
"typedoc": "^0.25.13",
"typescript": "^5.4.5"
},
Expand Down
2 changes: 1 addition & 1 deletion src/command-encoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ function validateB2TorT2BCopy(encoder: GPUCommandEncoder, buf: GPUImageCopyBuffe
assert(device === s_objToDevice.get(tex.texture), 'texture is not from same device as commandEncoder', [tex.texture, encoder]);

validateImageCopyBuffer(buf);
const [bufRequiredUsage, texRequiredUsage]: [keyof GPUBufferUsage, keyof GPUTextureUsage] = bufferIsSource
const [bufRequiredUsage, texRequiredUsage]: [keyof typeof GPUBufferUsage, keyof typeof GPUTextureUsage] = bufferIsSource
? ['COPY_SRC', 'COPY_DST']
: ['COPY_DST', 'COPY_SRC'];
assert(!!(buf.buffer.usage & GPUBufferUsage[bufRequiredUsage]), () => `src.usage(${bufferUsageToString(buf.buffer.usage)} missing ${bufRequiredUsage})`, [buf.buffer]);
Expand Down
11 changes: 11 additions & 0 deletions test/js/utils.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {it} from '../mocha-support.js';

function saveFunctionsOfClass(obj) {
const desc = Object.getOwnPropertyDescriptors(obj);
return Object.entries(desc)
Expand Down Expand Up @@ -66,4 +68,13 @@ export async function expectValidationError(expectError, fn) {
throw error;
}
}
}

export function itWithDevice(desc, fn) {
it.call(this, desc, async () => {
const adapter = await navigator.gpu.requestAdapter();
const device = await adapter.requestDevice();
await fn.call(this, device);
device.destroy();
});
}
84 changes: 37 additions & 47 deletions test/tests/binding-mixin-tests.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {describe, it} from '../mocha-support.js';
import {expectValidationError} from '../js/utils.js';
import {describe} from '../mocha-support.js';
import {expectValidationError, itWithDevice} from '../js/utils.js';

async function createBindGroup(device, buffer) {
device = device || await (await navigator.gpu.requestAdapter()).requestDevice();
Expand Down Expand Up @@ -65,17 +65,15 @@ export function addBindingMixinTests({

describe('check errors on setBindGroup', () => {

it('works', async () => {
const device = await (await navigator.gpu.requestAdapter()).requestDevice();
itWithDevice('works', async (device) => {
const pass = await makePass(device);
const bindGroup = await createBindGroup(device);
await expectValidationError(false, () => {
pass.setBindGroup(0, bindGroup);
});
});

it('fails if ended', async () => {
const device = await (await navigator.gpu.requestAdapter()).requestDevice();
itWithDevice('fails if ended', async (device) => {
const pass = await makePass(device);
const bindGroup = await createBindGroup(device);
endPass(pass);
Expand All @@ -84,34 +82,31 @@ export function addBindingMixinTests({
});
});

it('bindGroup from different device', async () => {
const pass = await makePass();
itWithDevice('bindGroup from different device', async (device) => {
const pass = await makePass(device);
const bindGroup = await createBindGroup();
await expectValidationError(true, () => {
pass.setBindGroup(0, bindGroup);
});
});

it('index < 0', async () => {
const device = await (await navigator.gpu.requestAdapter()).requestDevice();
itWithDevice('index < 0', async (device) => {
const pass = await makePass(device);
const bindGroup = await createBindGroup(device);
await expectValidationError(true, () => {
pass.setBindGroup(-1, bindGroup);
});
});

it('index > max', async () => {
const device = await (await navigator.gpu.requestAdapter()).requestDevice();
itWithDevice('index > max', async (device) => {
const pass = await makePass(device);
const bindGroup = await createBindGroup(device);
await expectValidationError(true, () => {
pass.setBindGroup(device.limits.maxBindGroups, bindGroup);
});
});

it('fails if buffer destroyed', async () => {
const device = await (await navigator.gpu.requestAdapter()).requestDevice();
itWithDevice('fails if buffer destroyed', async (device) => {
const pass = await makePass(device);
const buffer = device.createBuffer({size: 16, usage: GPUBufferUsage.UNIFORM});
const bindGroup = await createBindGroup(device, buffer);
Expand All @@ -122,45 +117,40 @@ export function addBindingMixinTests({
});

const addDynamicOffsetTests = (fn) => {
it('works', async () => {
const device = await (await navigator.gpu.requestAdapter()).requestDevice();
const pass = await makePass(device);
itWithDevice('works', async (device) => {
const pass = await makePass(device);
const bindGroup = await createBindGroupWithDynamicOffsets(device);
await expectValidationError(false, () => {
pass.setBindGroup(0, bindGroup, ...fn([2048 - 1024, 1024 - 512]));
});
});

it('fails if wrong number of dynamic offsets', async () => {
const device = await (await navigator.gpu.requestAdapter()).requestDevice();
const pass = await makePass(device);
itWithDevice('fails if wrong number of dynamic offsets', async (device) => {
const pass = await makePass(device);
const bindGroup = await createBindGroupWithDynamicOffsets(device);
await expectValidationError('same number of dynamicOffsets', () => {
pass.setBindGroup(0, bindGroup, ...fn([0, 0, 0]));
});
});

it('fails if dynamic offset out of range', async () => {
const device = await (await navigator.gpu.requestAdapter()).requestDevice();
const pass = await makePass(device);
itWithDevice('fails if dynamic offset out of range', async (device) => {
const pass = await makePass(device);
const bindGroup = await createBindGroupWithDynamicOffsets(device);
await expectValidationError('dynamic offset is out of range', () => {
pass.setBindGroup(0, bindGroup, ...fn([2048, 0]));
});
});

it('fails if dynamic offset is not storage aligned', async () => {
const device = await (await navigator.gpu.requestAdapter()).requestDevice();
const pass = await makePass(device);
itWithDevice('fails if dynamic offset is not storage aligned', async (device) => {
const pass = await makePass(device);
const bindGroup = await createBindGroupWithDynamicOffsets(device);
await expectValidationError('device.limits.minStorageBufferOffsetAlignment', () => {
pass.setBindGroup(0, bindGroup, ...fn([128, 0]));
});
});

it('fails if dynamic offset is not uniform aligned', async () => {
const device = await (await navigator.gpu.requestAdapter()).requestDevice();
const pass = await makePass(device);
itWithDevice('fails if dynamic offset is not uniform aligned', async (device) => {
const pass = await makePass(device);
const bindGroup = await createBindGroupWithDynamicOffsets(device);
await expectValidationError('device.limits.minUniformBufferOffsetAlignment', () => {
pass.setBindGroup(0, bindGroup, ...fn([0, 128]));
Expand Down Expand Up @@ -332,8 +322,8 @@ export function addValidateBindGroupTests({

describe('auto layout', () => {

it('works with auto layout', async () => {
const { pass, bindGroup0, bindGroup1, bindGroup2 } = await createResourcesForAutoLayoutBindGroupTests(makePassAndPipeline);
itWithDevice('works with auto layout', async (device) => {
const { pass, bindGroup0, bindGroup1, bindGroup2 } = await createResourcesForAutoLayoutBindGroupTests(makePassAndPipeline, device);
pass.setBindGroup(0, bindGroup0);
pass.setBindGroup(1, bindGroup1);
pass.setBindGroup(2, bindGroup2);
Expand All @@ -343,8 +333,8 @@ export function addValidateBindGroupTests({
});
});

it('fails if missing bindGroup', async () => {
const { pass, bindGroup1, bindGroup2 } = await createResourcesForAutoLayoutBindGroupTests(makePassAndPipeline);
itWithDevice('fails if missing bindGroup', async (device) => {
const { pass, bindGroup1, bindGroup2 } = await createResourcesForAutoLayoutBindGroupTests(makePassAndPipeline, device);
pass.setBindGroup(1, bindGroup1);
pass.setBindGroup(2, bindGroup2);

Expand All @@ -353,8 +343,8 @@ export function addValidateBindGroupTests({
});
});

it('fails if resource is destroyed', async () => {
const { pass, u01Buffer, bindGroup0, bindGroup1, bindGroup2 } = await createResourcesForAutoLayoutBindGroupTests(makePassAndPipeline);
itWithDevice('fails if resource is destroyed', async (device) => {
const { pass, u01Buffer, bindGroup0, bindGroup1, bindGroup2 } = await createResourcesForAutoLayoutBindGroupTests(makePassAndPipeline, device);
pass.setBindGroup(0, bindGroup0);
pass.setBindGroup(1, bindGroup1);
pass.setBindGroup(2, bindGroup2);
Expand All @@ -365,8 +355,8 @@ export function addValidateBindGroupTests({
});
});

it('fails if layout is incompatible (auto layout)', async () => {
const { device, pass, bindGroup0, bindGroup2 } = await createResourcesForAutoLayoutBindGroupTests(makePassAndPipeline);
itWithDevice('fails if layout is incompatible (auto layout)', async (device) => {
const { pass, bindGroup0, bindGroup2 } = await createResourcesForAutoLayoutBindGroupTests(makePassAndPipeline, device);
const { bindGroup1 } = await createResourcesForAutoLayoutBindGroupTests(makePassAndPipeline, device);
pass.setBindGroup(0, bindGroup0);
pass.setBindGroup(1, bindGroup1);
Expand All @@ -377,8 +367,8 @@ export function addValidateBindGroupTests({
});
});

it('works if layout is compatible (auto layout)', async () => {
const { pass, bindGroup0, bindGroup1, bindGroup2 } = await createResourcesForAutoLayoutBindGroupTests(makePassAndPipeline);
itWithDevice('works if layout is compatible (auto layout)', async (device) => {
const { pass, bindGroup0, bindGroup1, bindGroup2 } = await createResourcesForAutoLayoutBindGroupTests(makePassAndPipeline, device);
pass.setBindGroup(0, bindGroup0);
pass.setBindGroup(1, bindGroup2); // 2 and 1 are swapped but
pass.setBindGroup(2, bindGroup1); // they should be compatible
Expand All @@ -388,8 +378,8 @@ export function addValidateBindGroupTests({
});
});

it('false if layout is incompatible (auto layout + manual bindGroupLayout)', async () => {
const { device, pass, bindGroup0, bindGroup1, u20Buffer } = await createResourcesForAutoLayoutBindGroupTests(makePassAndPipeline);
itWithDevice('false if layout is incompatible (auto layout + manual bindGroupLayout)', async (device) => {
const { pass, bindGroup0, bindGroup1, u20Buffer } = await createResourcesForAutoLayoutBindGroupTests(makePassAndPipeline, device);
const bindGroupLayout = device.createBindGroupLayout({
entries: [
{
Expand Down Expand Up @@ -418,8 +408,8 @@ export function addValidateBindGroupTests({

describe('explicit layout', () => {

it('works with explicit layout', async () => {
const { pass, bindGroup0, bindGroup1, bindGroup2 } = await createResourcesForExplicitLayoutBindGroupTests({ makePassAndPipeline, visibility });
itWithDevice('works with explicit layout', async (device) => {
const { pass, bindGroup0, bindGroup1, bindGroup2 } = await createResourcesForExplicitLayoutBindGroupTests({ makePassAndPipeline, visibility, device });
pass.setBindGroup(0, bindGroup0);
pass.setBindGroup(1, bindGroup1);
pass.setBindGroup(2, bindGroup2);
Expand All @@ -429,8 +419,8 @@ export function addValidateBindGroupTests({
});
});

it('works with different explicit layout if they are compatible', async () => {
const { device, pass, bindGroup0, bindGroup1 } = await createResourcesForExplicitLayoutBindGroupTests({ makePassAndPipeline, visibility });
itWithDevice('works with different explicit layout if they are compatible', async (device) => {
const { pass, bindGroup0, bindGroup1 } = await createResourcesForExplicitLayoutBindGroupTests({ makePassAndPipeline, visibility, device });
const { bindGroup2 } = await createResourcesForExplicitLayoutBindGroupTests({ makePassAndPipeline, device, visibility });
pass.setBindGroup(0, bindGroup0);
pass.setBindGroup(1, bindGroup1);
Expand All @@ -441,8 +431,8 @@ export function addValidateBindGroupTests({
});
});

it('fails with incompatible bindGroup', async () => {
const { pass, bindGroup1, bindGroup2 } = await createResourcesForExplicitLayoutBindGroupTests({ makePassAndPipeline, visibility });
itWithDevice('fails with incompatible bindGroup', async (device) => {
const { pass, bindGroup1, bindGroup2 } = await createResourcesForExplicitLayoutBindGroupTests({ makePassAndPipeline, visibility, device });
pass.setBindGroup(0, bindGroup1); // incompatible
pass.setBindGroup(1, bindGroup1);
pass.setBindGroup(2, bindGroup2);
Expand Down
7 changes: 3 additions & 4 deletions test/tests/canvas-context-tests.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {describe, it} from '../mocha-support.js';
import {expectValidationError} from '../js/utils.js';
import {describe} from '../mocha-support.js';
import {expectValidationError, itWithDevice} from '../js/utils.js';

async function createCommandEncoder(device) {
device = device || await (await navigator.gpu.requestAdapter()).requestDevice();
Expand All @@ -26,8 +26,7 @@ describe('test canvas context', () => {

describe('test getCurrentTexture', () => {

it('works', async () => {
const device = await (await navigator.gpu.requestAdapter()).requestDevice();
itWithDevice('works', async (device) => {
const context = new OffscreenCanvas(1, 1).getContext('webgpu');
context.configure({
device,
Expand Down
Loading

0 comments on commit 67f5c9a

Please sign in to comment.