Skip to content

Commit

Permalink
Add setScissorRect check
Browse files Browse the repository at this point in the history
Add beginRenderPass check for different sized attachments
  • Loading branch information
greggman committed Feb 23, 2024
1 parent 46b2822 commit 2d7bac4
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/webgpu-debug-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,15 @@ if (typeof GPUDevice !== 'undefined') {
assert(y + height <= targetHeight, 'y + height > texture.height');
});

wrapFunctionBefore(GPURenderPassEncoder, 'setScissorRect', function(this: GPURenderPassEncoder, x: number, y: number, width: number, height: number) {
const {
targetWidth,
targetHeight,
} = renderPassToPassInfoMap.get(this)!;
assert(x >= 0, 'x < 0');
assert(y >= 0, 'y < 0');
assert(x + width <= targetWidth, 'x + width > texture.width');
assert(y + height <= targetHeight, 'y + height > texture.height');
});

}
83 changes: 82 additions & 1 deletion test/tests/webgpu-debug-helper-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,88 @@ describe('test webgpu-debug-helper', () => {

describe('test render pass encoder', () => {

describe('should generate error on setViewport', () => {
describe('check errors on beginRenderPass', () => {

it('errors when colorAttachments are not the same size', async () => {
const adapter = await navigator.gpu.requestAdapter();
const device = await adapter.requestDevice();
const textures = [2, 3].map(width => device.createTexture({
size: [width, 3],
usage: GPUTextureUsage.RENDER_ATTACHMENT,
format: 'rgba8unorm',
}));
const encoder = device.createCommandEncoder();
expectValidationError(true, () => {
encoder.beginRenderPass({
colorAttachments: textures.map(texture => ({
view: texture.createView(),
clearColor: [0, 0, 0, 0],
loadOp: 'clear',
storeOp: 'store',
})),
});
});
});

it('errors when depthStencilAttachment is a different size than the colorAttachments', async () => {
const adapter = await navigator.gpu.requestAdapter();
const device = await adapter.requestDevice();
const colorTexture = device.createTexture({
size: [2, 2],
usage: GPUTextureUsage.RENDER_ATTACHMENT,
format: 'rgba8unorm',
});
const depthTexture = device.createTexture({
size: [2, 3],
usage: GPUTextureUsage.RENDER_ATTACHMENT,
format: 'depth24plus',
});
const encoder = device.createCommandEncoder();
expectValidationError(true, () => {
encoder.beginRenderPass({
colorAttachments: [{
view: colorTexture.createView(),
clearColor: [0, 0, 0, 0],
loadOp: 'clear',
storeOp: 'store',
}],
depthStencilAttachment: {
view: depthTexture.createView(),
depthClearValue: 1.0,
depthLoadOp: 'clear',
depthStoreOp: 'store',
},
});
});
});

});

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

const tests = [
{ success: true, args: [0, 0, 2, 3, 0, 1], desc: 'valid' },
{ success: false, args: [-1, 0, 1, 1, 0, 1], desc: 'x < 0' },
{ success: false, args: [ 0, -1, 1, 1, 0, 1], desc: 'y < 0' },
{ success: false, args: [ 0, 0, 3, 1, 0, 1], desc: 'x + width > targetWidth' },
{ success: false, args: [ 1, 0, 2, 1, 0, 1], desc: 'x + width > targetWidth' },
{ success: false, args: [ 0, 0, 1, 4, 0, 1], desc: 'y + height > targetHeight' },
{ success: false, args: [ 0, 1, 1, 3, 0, 1], desc: 'y + height > targetHeight' },
];

for (let {success, args, desc} of tests) {
it(desc, async () => {
const pass = await createRenderPass();
expectValidationError(!success, () => {
pass.setViewport(...args);
});
});

}

});

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

const tests = [
{ success: true, args: [0, 0, 2, 3, 0, 1], desc: 'valid' },
Expand Down

0 comments on commit 2d7bac4

Please sign in to comment.