Skip to content

Commit

Permalink
Deploying to gh-pages from @ 954f138 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
greggman committed Jun 12, 2024
1 parent 67f5c9a commit 2e52642
Show file tree
Hide file tree
Showing 11 changed files with 7,786 additions and 7,518 deletions.
15,060 changes: 7,565 additions & 7,495 deletions dist/0.x/webgpu-debug-helper.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

4 changes: 2 additions & 2 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
@@ -1,6 +1,6 @@
{
"name": "webgpu-debug-helper",
"version": "0.1.1",
"version": "0.1.2",
"description": "webgpu debug helper",
"main": "dist/0.x/webgpu-debug-helper.js",
"type": "module",
Expand Down
2 changes: 1 addition & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default [
output: [
{
file: `${dist}/${name}.js`,
format: 'esm',
format: 'umd',
sourcemap: true,
freeze: false,
banner,
Expand Down
2 changes: 1 addition & 1 deletion src/command-encoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,5 +282,5 @@ wrapFunctionBefore(GPUCommandEncoder, 'resolveQuerySet', function (this: GPUComm
assert(firstQuery < querySet.count, () => `firstQuery(${firstQuery}) out of range for querySet.count(${querySet.count})`);
assert(firstQuery + queryCount <= querySet.count, () => `firstQuery(${firstQuery}) + queryCount(${queryCount}) > querySet.count(${querySet.count})`);
assert(destinationOffset % 256 === 0, () => `destinationOffset(${destinationOffset}) is not multiple of 256`);
assert(destinationOffset + queryCount * 8 < destination.size, () => `destinationOffset(${destinationOffset}) + queryCount(${queryCount}) * 8 > destination.size(${destination.size})`);
assert(destinationOffset + queryCount * 8 <= destination.size, () => `destinationOffset(${destinationOffset}) + queryCount(${queryCount}) * 8 > destination.size(${destination.size})`);
});
46 changes: 46 additions & 0 deletions src/format-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,56 @@ export type FormatInfo = {
feature?: string,
};



// exported from the WebGPU CTS by adding the following line to src/webgpu/format_info.ts
//
// console.log(JSON.stringify(kAllTextureFormatInfo, null, 2));

/** `kDepthStencilFormatResolvedAspect[format][aspect]` returns the aspect-specific format for a
* depth-stencil format, or `undefined` if the format doesn't have the aspect.
*/
const kDepthStencilFormatResolvedAspect = {
// kUnsizedDepthStencilFormats
depth24plus: {
all: 'depth24plus',
'depth-only': 'depth24plus',
'stencil-only': undefined,
},
'depth24plus-stencil8': {
all: 'depth24plus-stencil8',
'depth-only': 'depth24plus',
'stencil-only': 'stencil8',
},

// kSizedDepthStencilFormats
depth16unorm: {
all: 'depth16unorm',
'depth-only': 'depth16unorm',
'stencil-only': undefined,
},
depth32float: {
all: 'depth32float',
'depth-only': 'depth32float',
'stencil-only': undefined,
},
'depth32float-stencil8': {
all: 'depth32float-stencil8',
'depth-only': 'depth32float',
'stencil-only': 'stencil8',
},
stencil8: {
all: 'stencil8',
'depth-only': undefined,
'stencil-only': 'stencil8',
},
};

export function getDepthStencilFormatResolvedAspect(format: GPUTextureFormat, aspect: GPUTextureAspect): GPUTextureFormat | undefined {
const info = kDepthStencilFormatResolvedAspect[format as keyof typeof kDepthStencilFormatResolvedAspect];
return info ? info[aspect] as GPUTextureFormat : undefined;
}

export const kAllTextureFormatInfo: {[key: string]: FormatInfo} = {
"r8unorm": {
"blockWidth": 1,
Expand Down
51 changes: 39 additions & 12 deletions src/texture.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import {
getDepthStencilFormatResolvedAspect,
} from './format-info.js';
import {
wrapFunctionBefore,
wrapFunctionAfter,
Expand All @@ -15,20 +18,44 @@ export type TextureViewDescriptor = {
export const s_textureViewToTexture = new WeakMap<GPUTextureView, GPUTexture>();
export const s_textureViewToDesc = new WeakMap<GPUTextureView, TextureViewDescriptor>();

function resolveTextureAspect(format: GPUTextureFormat, aspect: GPUTextureAspect) {
switch (aspect) {
case 'all':
return format;
case 'depth-only':
case 'stencil-only':
return getDepthStencilFormatResolvedAspect(format, aspect);
}
return undefined;
}

function reifyTextureViewDescriptor(texture: GPUTexture, desc: GPUTextureViewDescriptor | undefined): TextureViewDescriptor {
const {
format = texture.format,
dimension = texture.dimension === '2d'
? (texture.depthOrArrayLayers === 1 ? '2d' : '2d-array')
: texture.dimension,
aspect = 'all',
baseMipLevel = 0,
mipLevelCount = texture.mipLevelCount,
baseArrayLayer = 0,
arrayLayerCount = texture.depthOrArrayLayers,
} = desc || {};
const dimension = desc?.dimension ?? (
texture.dimension === '2d'
? (texture.depthOrArrayLayers === 1 ? '2d' : '2d-array')
: texture.dimension
);
const aspect = desc?.aspect ?? 'all';
let format = desc?.format;
if (!format) {
const f = resolveTextureAspect(texture.format, aspect);
format = f ?? texture.format;
}
return {
format, dimension, aspect, baseMipLevel, mipLevelCount, baseArrayLayer, arrayLayerCount,
format,
dimension,
aspect,
baseMipLevel: desc?.baseMipLevel ?? 0,
mipLevelCount: desc?.mipLevelCount ?? (texture.mipLevelCount - (desc?.baseMipLevel ?? 0)),
baseArrayLayer: desc?.baseArrayLayer ?? 0,
arrayLayerCount: desc?.arrayLayerCount ?? (
dimension === 'cube'
? 6
: (dimension === '2d-array' || dimension === 'cube-array'
? texture.depthOrArrayLayers - (desc?.baseArrayLayer ?? 0)
: 1
)
),
};
}

Expand Down
4 changes: 0 additions & 4 deletions src/webgpu-debug-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,3 @@ import './compute-pass-encoder.js';
import './render-pass-encoder.js';
import './render-bundle-encoder.js';
import './texture.js';

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const _ = import.meta; // webgpu-debug-helper must be imported as a module with import or `<script type="module" ...>`
console.log('webgpu-debug-helper loaded:', _ !== undefined);
130 changes: 130 additions & 0 deletions test/tests/command-encoder-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ describe('test command encoder', () => {
await expectValidationError(true, async () => {
encoder.clearBuffer(buffer);
});
device2.destroy();
});

itWithDevice('fails if buffer.usage missing COPY_DST', async (device) => {
Expand Down Expand Up @@ -112,6 +113,135 @@ describe('test command encoder', () => {

});

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

itWithDevice('works', async (device) => {
const querySet = device.createQuerySet({count: 2, type: 'occlusion'});
const encoder = await createCommandEncoder(device);
const resolveBuffer = device.createBuffer({
size: 16,
usage: GPUBufferUsage.QUERY_RESOLVE,
});
encoder.resolveQuerySet(querySet, 0, 2, resolveBuffer, 0);
encoder.finish();
});

itWithDevice('fails if querySet destroyed', async (device) => {
const querySet = device.createQuerySet({count: 2, type: 'occlusion'});
const encoder = await createCommandEncoder(device);
const resolveBuffer = device.createBuffer({
size: 16,
usage: GPUBufferUsage.QUERY_RESOLVE,
});
querySet.destroy();
await expectValidationError(true, async () => {
encoder.resolveQuerySet(querySet, 0, 2, resolveBuffer, 0);
});
});

itWithDevice('fails if resolve buffer destroyed', async (device) => {
const querySet = device.createQuerySet({count: 2, type: 'occlusion'});
const encoder = await createCommandEncoder(device);
const resolveBuffer = device.createBuffer({
size: 16,
usage: GPUBufferUsage.QUERY_RESOLVE,
});
resolveBuffer.destroy();
await expectValidationError(true, async () => {
encoder.resolveQuerySet(querySet, 0, 2, resolveBuffer, 0);
});
});

itWithDevice('fails if querySet not from same device', async (device) => {
const device2 = await (await navigator.gpu.requestAdapter()).requestDevice();
const querySet = device2.createQuerySet({count: 2, type: 'occlusion'});
const encoder = await createCommandEncoder(device);
const resolveBuffer = device.createBuffer({
size: 16,
usage: GPUBufferUsage.QUERY_RESOLVE,
});
await expectValidationError(true, async () => {
encoder.resolveQuerySet(querySet, 0, 2, resolveBuffer, 0);
});
device2.destroy();
});

itWithDevice('fails if resolveBuffer not from same device', async (device) => {
const device2 = await (await navigator.gpu.requestAdapter()).requestDevice();
const querySet = device.createQuerySet({count: 2, type: 'occlusion'});
const encoder = await createCommandEncoder(device);
const resolveBuffer = device2.createBuffer({
size: 16,
usage: GPUBufferUsage.QUERY_RESOLVE,
});
await expectValidationError(true, async () => {
encoder.resolveQuerySet(querySet, 0, 2, resolveBuffer, 0);
});
device2.destroy();
});

itWithDevice('fails if resolveBuffer missing usage QUERY_RESOLVE', async (device) => {
const querySet = device.createQuerySet({count: 2, type: 'occlusion'});
const encoder = await createCommandEncoder(device);
const resolveBuffer = device.createBuffer({
size: 16,
usage: GPUBufferUsage.UNIFORM,
});
await expectValidationError(true, async () => {
encoder.resolveQuerySet(querySet, 0, 2, resolveBuffer, 0);
});
});

itWithDevice('fails if start out of range', async (device) => {
const querySet = device.createQuerySet({count: 2, type: 'occlusion'});
const encoder = await createCommandEncoder(device);
const resolveBuffer = device.createBuffer({
size: 16,
usage: GPUBufferUsage.UNIFORM,
});
await expectValidationError(true, async () => {
encoder.resolveQuerySet(querySet, 3, 1, resolveBuffer, 0);
});
});

itWithDevice('fails if end out of range', async (device) => {
const querySet = device.createQuerySet({count: 2, type: 'occlusion'});
const encoder = await createCommandEncoder(device);
const resolveBuffer = device.createBuffer({
size: 16,
usage: GPUBufferUsage.UNIFORM,
});
await expectValidationError(true, async () => {
encoder.resolveQuerySet(querySet, 1, 2, resolveBuffer, 0);
});
});

itWithDevice('fails if resolveBuffer offset not multiple of 256', async (device) => {
const querySet = device.createQuerySet({count: 2, type: 'occlusion'});
const encoder = await createCommandEncoder(device);
const resolveBuffer = device.createBuffer({
size: 2048,
usage: GPUBufferUsage.UNIFORM,
});
await expectValidationError(true, async () => {
encoder.resolveQuerySet(querySet, 0, 2, resolveBuffer, 128);
});
});

itWithDevice('fails if resolveBuffer too small', async (device) => {
const querySet = device.createQuerySet({count: 2, type: 'occlusion'});
const encoder = await createCommandEncoder(device);
const resolveBuffer = device.createBuffer({
size: 8,
usage: GPUBufferUsage.UNIFORM,
});
await expectValidationError(true, async () => {
encoder.resolveQuerySet(querySet, 0, 2, resolveBuffer, 0);
});
});

});

copyBufferToBufferTests();
copyBufferToTextureTests();
copyTextureToBufferTests();
Expand Down
1 change: 0 additions & 1 deletion test/tests/timestamp-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,5 @@ export function addTimestampWriteTests({
});
});


});
}

0 comments on commit 2e52642

Please sign in to comment.