diff --git a/src/command-encoder.ts b/src/command-encoder.ts index 4c6e6be..dba33e3 100644 --- a/src/command-encoder.ts +++ b/src/command-encoder.ts @@ -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})`); }); \ No newline at end of file diff --git a/test/tests/command-encoder-tests.js b/test/tests/command-encoder-tests.js index 95797a4..1dd7cb8 100644 --- a/test/tests/command-encoder-tests.js +++ b/test/tests/command-encoder-tests.js @@ -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) => { @@ -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(); diff --git a/test/tests/timestamp-tests.js b/test/tests/timestamp-tests.js index 1720cc7..020e86c 100644 --- a/test/tests/timestamp-tests.js +++ b/test/tests/timestamp-tests.js @@ -119,6 +119,5 @@ export function addTimestampWriteTests({ }); }); - }); } \ No newline at end of file