Skip to content

Commit

Permalink
add resolveQuerySet tests
Browse files Browse the repository at this point in the history
  • Loading branch information
greggman committed Jun 11, 2024
1 parent ca3accb commit 3a0cea5
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 2 deletions.
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})`);
});
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 3a0cea5

Please sign in to comment.