Skip to content

Commit

Permalink
Fix Kai's comments
Browse files Browse the repository at this point in the history
  • Loading branch information
haoxli committed Mar 22, 2022
1 parent d0c47bb commit 108e5f5
Show file tree
Hide file tree
Showing 21 changed files with 165 additions and 195 deletions.
10 changes: 4 additions & 6 deletions src/webgpu/api/validation/createBindGroup.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -506,19 +506,17 @@ g.test('bind_group_layout,device_mismatch')
await t.selectMismatchedDeviceOrSkipTestCase(undefined);
}

const descriptor = {
const device = mismatched ? t.mismatchedDevice : t.device;

const bgl = device.createBindGroupLayout({
entries: [
{
binding: 0,
visibility: GPUConst.ShaderStage.VERTEX,
buffer: {},
},
],
};

const bgl = mismatched
? t.mismatchedDevice.createBindGroupLayout(descriptor)
: t.device.createBindGroupLayout(descriptor);
});

t.expectValidationError(() => {
t.device.createBindGroup({
Expand Down
16 changes: 8 additions & 8 deletions src/webgpu/api/validation/createComputePipeline.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,9 @@ g.test('pipeline_layout,device_mismatch')
await t.selectMismatchedDeviceOrSkipTestCase(undefined);
}

const layoutDescriptor = { bindGroupLayouts: [] };
const layout = mismatched
? t.mismatchedDevice.createPipelineLayout(layoutDescriptor)
: t.device.createPipelineLayout(layoutDescriptor);
const device = mismatched ? t.mismatchedDevice : t.device;

const layout = device.createPipelineLayout({ bindGroupLayouts: [] });

const descriptor = {
layout,
Expand All @@ -211,10 +210,11 @@ g.test('shader_module,device_mismatch')
await t.selectMismatchedDeviceOrSkipTestCase(undefined);
}

const code = '@stage(compute) @workgroup_size(1) fn main() {}';
const module = mismatched
? t.mismatchedDevice.createShaderModule({ code })
: t.device.createShaderModule({ code });
const device = mismatched ? t.mismatchedDevice : t.device;

const module = device.createShaderModule({
code: '@stage(compute) @workgroup_size(1) fn main() {}',
});

const descriptor = {
compute: {
Expand Down
7 changes: 3 additions & 4 deletions src/webgpu/api/validation/createRenderPipeline.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -668,10 +668,9 @@ g.test('pipeline_layout,device_mismatch')
await t.selectMismatchedDeviceOrSkipTestCase(undefined);
}

const layoutDescriptor = { bindGroupLayouts: [] };
const layout = mismatched
? t.mismatchedDevice.createPipelineLayout(layoutDescriptor)
: t.device.createPipelineLayout(layoutDescriptor);
const device = mismatched ? t.mismatchedDevice : t.device;

const layout = device.createPipelineLayout({ bindGroupLayouts: [] });

const descriptor = {
layout,
Expand Down
11 changes: 5 additions & 6 deletions src/webgpu/api/validation/encoding/beginRenderPass.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,13 @@ g.test('occlusion_query_set,device_mismatch')
await t.selectMismatchedDeviceOrSkipTestCase(undefined);
}

const descriptor: GPUQuerySetDescriptor = {
const device = mismatched ? t.mismatchedDevice : t.device;

const occlusionQuerySet = device.createQuerySet({
type: 'occlusion',
count: 1,
};

const occlusionQuerySet = mismatched
? t.mismatchedDevice.createQuerySet(descriptor)
: t.device.createQuerySet(descriptor);
});
t.trackForCleanup(occlusionQuerySet);

const encoder = t.createEncoder('render pass', { occlusionQuerySet });
encoder.validateFinish(!mismatched);
Expand Down
16 changes: 8 additions & 8 deletions src/webgpu/api/validation/encoding/cmds/clearBuffer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,19 @@ g.test('buffer,device_mismatch')
await t.selectMismatchedDeviceOrSkipTestCase(undefined);
}

const bufferSize = 8;
const descriptor: GPUBufferDescriptor = {
size: bufferSize,
const device = mismatched ? t.mismatchedDevice : t.device;
const size = 8;

const buffer = device.createBuffer({
size,
usage: GPUBufferUsage.COPY_DST,
};
const buffer = mismatched
? t.getDeviceMismatchedBuffer(descriptor)
: t.createBufferWithState('valid', descriptor);
});
t.trackForCleanup(buffer);

t.TestClearBuffer({
buffer,
offset: 0,
size: bufferSize,
size,
isSuccess: !mismatched,
});
});
Expand Down
34 changes: 15 additions & 19 deletions src/webgpu/api/validation/encoding/cmds/compute_pass.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,6 @@ class F extends ValidationTest {
return this.createErrorComputePipeline();
}

createComputePipelineForMismatch(device: GPUDevice) {
return device.createComputePipeline({
compute: {
module: device.createShaderModule({
code: '@stage(compute) @workgroup_size(1) fn main() {}',
}),
entryPoint: 'main',
},
});
}

createIndirectBuffer(state: ResourceState, data: Uint32Array): GPUBuffer {
const descriptor: GPUBufferDescriptor = {
size: data.byteLength,
Expand Down Expand Up @@ -83,9 +72,16 @@ g.test('pipeline,device_mismatch')
await t.selectMismatchedDeviceOrSkipTestCase(undefined);
}

const pipeline = mismatched
? t.createComputePipelineForMismatch(t.mismatchedDevice)
: t.createComputePipelineForMismatch(t.device);
const device = mismatched ? t.mismatchedDevice : t.device;

const pipeline = device.createComputePipeline({
compute: {
module: device.createShaderModule({
code: '@stage(compute) @workgroup_size(1) fn main() {}',
}),
entryPoint: 'main',
},
});

const { encoder, validateFinish } = t.createEncoder('compute pass');
encoder.setPipeline(pipeline);
Expand Down Expand Up @@ -194,13 +190,13 @@ g.test('indirect_dispatch_buffer,device_mismatch')

const pipeline = t.createNoOpComputePipeline();

const descriptor: GPUBufferDescriptor = {
const device = mismatched ? t.mismatchedDevice : t.device;

const buffer = device.createBuffer({
size: 16,
usage: GPUBufferUsage.INDIRECT,
};
const buffer = mismatched
? t.getDeviceMismatchedBuffer(descriptor)
: t.createBufferWithState('valid', descriptor);
});
t.trackForCleanup(buffer);

const { encoder, validateFinish } = t.createEncoder('compute pass');
encoder.setPipeline(pipeline);
Expand Down
18 changes: 8 additions & 10 deletions src/webgpu/api/validation/encoding/cmds/copyBufferToBuffer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,21 +94,19 @@ g.test('buffer,device_mismatch')
await t.selectMismatchedDeviceOrSkipTestCase(undefined);
}

const srcDescriptor: GPUBufferDescriptor = {
const device = mismatched ? t.mismatchedDevice : t.device;

const srcBuffer = device.createBuffer({
size: 16,
usage: GPUBufferUsage.COPY_SRC,
};
const srcBuffer = srcMismatched
? t.getDeviceMismatchedBuffer(srcDescriptor)
: t.createBufferWithState('valid', srcDescriptor);
});
t.trackForCleanup(srcBuffer);

const dstDescriptor: GPUBufferDescriptor = {
const dstBuffer = device.createBuffer({
size: 16,
usage: GPUBufferUsage.COPY_DST,
};
const dstBuffer = dstMismatched
? t.getDeviceMismatchedBuffer(dstDescriptor)
: t.createBufferWithState('valid', dstDescriptor);
});
t.trackForCleanup(dstBuffer);

t.TestCopyBufferToBuffer({
srcBuffer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,25 +125,23 @@ g.test('texture,device_mismatch')
await t.selectMismatchedDeviceOrSkipTestCase(undefined);
}

const kFormat = 'rgba8unorm';
const device = mismatched ? t.mismatchedDevice : t.device;
const size = { width: 4, height: 4, depthOrArrayLayers: 1 };
const format = 'rgba8unorm';

const srcDescriptor: GPUTextureDescriptor = {
size: { width: 4, height: 4, depthOrArrayLayers: 1 },
format: kFormat,
const srcTexture = device.createTexture({
size,
format,
usage: GPUTextureUsage.COPY_SRC,
};
const srcTexture = srcMismatched
? t.getDeviceMismatchedTexture(srcDescriptor)
: t.createTextureWithState('valid', srcDescriptor);
});
t.trackForCleanup(srcTexture);

const dstDescriptor: GPUTextureDescriptor = {
size: { width: 4, height: 4, depthOrArrayLayers: 1 },
format: kFormat,
const dstTexture = device.createTexture({
size,
format,
usage: GPUTextureUsage.COPY_DST,
};
const dstTexture = dstMismatched
? t.getDeviceMismatchedTexture(dstDescriptor)
: t.createTextureWithState('valid', dstDescriptor);
});
t.trackForCleanup(dstTexture);

t.TestCopyTextureToTexture(
{ texture: srcTexture },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ g.test('indirect_buffer,device_mismatch')
await t.selectMismatchedDeviceOrSkipTestCase(undefined);
}

const descriptor: GPUBufferDescriptor = {
const device = mismatched ? t.mismatchedDevice : t.device;

const indirectBuffer = device.createBuffer({
size: 256,
usage: GPUBufferUsage.INDIRECT,
};
const indirectBuffer = mismatched
? t.getDeviceMismatchedBuffer(descriptor)
: t.createBufferWithState('valid', descriptor);
});
t.trackForCleanup(indirectBuffer);

const { encoder, validateFinish } = t.createEncoder(encoderType);
encoder.setPipeline(t.createNoOpRenderPipeline());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ g.test('index_buffer,device_mismatch')
await t.selectMismatchedDeviceOrSkipTestCase(undefined);
}

const descriptor: GPUBufferDescriptor = {
const device = mismatched ? t.mismatchedDevice : t.device;

const indexBuffer = device.createBuffer({
size: 16,
usage: GPUBufferUsage.INDEX,
};
const indexBuffer = mismatched
? t.getDeviceMismatchedBuffer(descriptor)
: t.createBufferWithState('valid', descriptor);
});
t.trackForCleanup(indexBuffer);

const { encoder, validateFinish } = t.createEncoder(encoderType);
encoder.setIndexBuffer(indexBuffer, 'uint32');
Expand Down
44 changes: 19 additions & 25 deletions src/webgpu/api/validation/encoding/cmds/render/setPipeline.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,7 @@ import { ValidationTest } from '../../../validation_test.js';

import { kRenderEncodeTypeParams } from './render.js';

class F extends ValidationTest {
createRenderPipelineForMismatch(device: GPUDevice) {
return device.createRenderPipeline({
vertex: {
module: device.createShaderModule({
code: `@stage(vertex) fn main() -> @builtin(position) vec4<f32> { return vec4<f32>(); }`,
}),
entryPoint: 'main',
},
fragment: {
module: device.createShaderModule({
code: '@stage(fragment) fn main() {}',
}),
entryPoint: 'main',
targets: [{ format: 'rgba8unorm', writeMask: 0 }],
},
primitive: { topology: 'triangle-list' },
});
}
}

export const g = makeTestGroup(F);
export const g = makeTestGroup(ValidationTest);

g.test('invalid_pipeline')
.desc(
Expand Down Expand Up @@ -59,9 +38,24 @@ g.test('pipeline,device_mismatch')
await t.selectMismatchedDeviceOrSkipTestCase(undefined);
}

const pipeline = mismatched
? t.createRenderPipelineForMismatch(t.mismatchedDevice)
: t.createRenderPipelineForMismatch(t.device);
const device = mismatched ? t.mismatchedDevice : t.device;

const pipeline = device.createRenderPipeline({
vertex: {
module: device.createShaderModule({
code: `@stage(vertex) fn main() -> @builtin(position) vec4<f32> { return vec4<f32>(); }`,
}),
entryPoint: 'main',
},
fragment: {
module: device.createShaderModule({
code: '@stage(fragment) fn main() {}',
}),
entryPoint: 'main',
targets: [{ format: 'rgba8unorm', writeMask: 0 }],
},
primitive: { topology: 'triangle-list' },
});

const { encoder, validateFinish } = t.createEncoder(encoderType);
encoder.setPipeline(pipeline);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ g.test('vertex_buffer,device_mismatch')
await t.selectMismatchedDeviceOrSkipTestCase(undefined);
}

const descriptor: GPUBufferDescriptor = {
const device = mismatched ? t.mismatchedDevice : t.device;

const vertexBuffer = device.createBuffer({
size: 16,
usage: GPUBufferUsage.VERTEX,
};
const vertexBuffer = mismatched
? t.getDeviceMismatchedBuffer(descriptor)
: t.createBufferWithState('valid', descriptor);
});
t.trackForCleanup(vertexBuffer);

const { encoder, validateFinish } = t.createEncoder(encoderType);
encoder.setVertexBuffer(0, vertexBuffer);
Expand Down
Loading

0 comments on commit 108e5f5

Please sign in to comment.