Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement api,validation,state,device_mismatched: Part II #1094

Merged
merged 4 commits into from
Mar 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
27 changes: 27 additions & 0 deletions src/webgpu/api/validation/encoding/cmds/clearBuffer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,33 @@ g.test('invalid_buffer')
});
});

g.test('buffer,device_mismatch')
.desc(`Tests clearBuffer cannot be called with buffer created from another device.`)
.paramsSubcasesOnly(u => u.combine('mismatched', [true, false]))
.fn(async t => {
const { mismatched } = t.params;

if (mismatched) {
await t.selectMismatchedDeviceOrSkipTestCase(undefined);
}

const device = mismatched ? t.mismatchedDevice : t.device;
const size = 8;

const buffer = device.createBuffer({
size,
usage: GPUBufferUsage.COPY_DST,
});
t.trackForCleanup(buffer);

t.TestClearBuffer({
buffer,
offset: 0,
size,
isSuccess: !mismatched,
});
});

g.test('default_args')
.desc(`Test that calling clearBuffer with a default offset and size is valid.`)
.paramsSubcasesOnly([
Expand Down
46 changes: 44 additions & 2 deletions src/webgpu/api/validation/encoding/cmds/compute_pass.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,28 @@ setPipeline should generate an error iff using an 'invalid' pipeline.
g.test('pipeline,device_mismatch')
.desc('Tests setPipeline cannot be called with a compute pipeline created from another device')
.paramsSubcasesOnly(u => u.combine('mismatched', [true, false]))
.unimplemented();
.fn(async t => {
const { mismatched } = t.params;

if (mismatched) {
await t.selectMismatchedDeviceOrSkipTestCase(undefined);
}

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);
validateFinish(!mismatched);
});

const kMaxDispatch = DefaultLimits.maxComputeWorkgroupsPerDimension;
g.test('dispatch_sizes')
Expand Down Expand Up @@ -160,4 +181,25 @@ g.test('indirect_dispatch_buffer,device_mismatch')
'Tests dispatchIndirect cannot be called with an indirect buffer created from another device'
)
.paramsSubcasesOnly(u => u.combine('mismatched', [true, false]))
.unimplemented();
.fn(async t => {
const { mismatched } = t.params;

if (mismatched) {
await t.selectMismatchedDeviceOrSkipTestCase(undefined);
}

const pipeline = t.createNoOpComputePipeline();

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

const buffer = device.createBuffer({
size: 16,
usage: GPUBufferUsage.INDIRECT,
});
t.trackForCleanup(buffer);

const { encoder, validateFinish } = t.createEncoder('compute pass');
encoder.setPipeline(pipeline);
encoder.dispatchIndirect(buffer, 0);
validateFinish(!mismatched);
});
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,37 @@ g.test('buffer,device_mismatch')
{ srcMismatched: true, dstMismatched: false },
{ srcMismatched: false, dstMismatched: true },
] as const)
.unimplemented();
.fn(async t => {
const { srcMismatched, dstMismatched } = t.params;
const mismatched = srcMismatched || dstMismatched;

if (mismatched) {
await t.selectMismatchedDeviceOrSkipTestCase(undefined);
}

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

const srcBuffer = device.createBuffer({
size: 16,
usage: GPUBufferUsage.COPY_SRC,
});
t.trackForCleanup(srcBuffer);

const dstBuffer = device.createBuffer({
size: 16,
usage: GPUBufferUsage.COPY_DST,
});
t.trackForCleanup(dstBuffer);

t.TestCopyBufferToBuffer({
srcBuffer,
srcOffset: 0,
dstBuffer,
dstOffset: 0,
copySize: 8,
isSuccess: !mismatched,
});
});

g.test('buffer_usage')
.paramsSubcasesOnly(u =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,39 @@ g.test('texture,device_mismatch')
{ srcMismatched: true, dstMismatched: false },
{ srcMismatched: false, dstMismatched: true },
] as const)
.unimplemented();
.fn(async t => {
const { srcMismatched, dstMismatched } = t.params;
const mismatched = srcMismatched || dstMismatched;

if (mismatched) {
await t.selectMismatchedDeviceOrSkipTestCase(undefined);
}

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

const srcTexture = device.createTexture({
size,
format,
usage: GPUTextureUsage.COPY_SRC,
});
t.trackForCleanup(srcTexture);

const dstTexture = device.createTexture({
size,
format,
usage: GPUTextureUsage.COPY_DST,
});
t.trackForCleanup(dstTexture);

t.TestCopyTextureToTexture(
{ texture: srcTexture },
{ texture: dstTexture },
{ width: 1, height: 1, depthOrArrayLayers: 1 },
mismatched ? 'FinishError' : 'Success'
);
});

g.test('mipmap_level')
.desc(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,32 @@ g.test('indirect_buffer,device_mismatch')
'Tests draw(Indexed)Indirect cannot be called with an indirect buffer created from another device'
)
.paramsSubcasesOnly(kIndirectDrawTestParams.combine('mismatched', [true, false]))
.unimplemented();
.fn(async t => {
const { encoderType, indexed, mismatched } = t.params;

if (mismatched) {
await t.selectMismatchedDeviceOrSkipTestCase(undefined);
}

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

const indirectBuffer = device.createBuffer({
size: 256,
usage: GPUBufferUsage.INDIRECT,
});
t.trackForCleanup(indirectBuffer);

const { encoder, validateFinish } = t.createEncoder(encoderType);
encoder.setPipeline(t.createNoOpRenderPipeline());

if (indexed) {
encoder.setIndexBuffer(t.makeIndexBuffer(), 'uint32');
encoder.drawIndexedIndirect(indirectBuffer, 0);
} else {
encoder.drawIndirect(indirectBuffer, 0);
}
validateFinish(!mismatched);
});

g.test('indirect_buffer_usage')
.desc(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,25 @@ Tests index buffer must be valid.
g.test('index_buffer,device_mismatch')
.desc('Tests setIndexBuffer cannot be called with an index buffer created from another device')
.paramsSubcasesOnly(kRenderEncodeTypeParams.combine('mismatched', [true, false]))
.unimplemented();
.fn(async t => {
const { encoderType, mismatched } = t.params;

if (mismatched) {
await t.selectMismatchedDeviceOrSkipTestCase(undefined);
}

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

const indexBuffer = device.createBuffer({
size: 16,
usage: GPUBufferUsage.INDEX,
});
t.trackForCleanup(indexBuffer);

const { encoder, validateFinish } = t.createEncoder(encoderType);
encoder.setIndexBuffer(indexBuffer, 'uint32');
validateFinish(!mismatched);
});

g.test('index_buffer_usage')
.desc(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,33 @@ Tests setPipeline should generate an error iff using an 'invalid' pipeline.
g.test('pipeline,device_mismatch')
.desc('Tests setPipeline cannot be called with a render pipeline created from another device')
.paramsSubcasesOnly(kRenderEncodeTypeParams.combine('mismatched', [true, false]))
.unimplemented();
.fn(async t => {
const { encoderType, mismatched } = t.params;

if (mismatched) {
await t.selectMismatchedDeviceOrSkipTestCase(undefined);
}

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);
validateFinish(!mismatched);
});
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,25 @@ Tests vertex buffer must be valid.
g.test('vertex_buffer,device_mismatch')
.desc('Tests setVertexBuffer cannot be called with a vertex buffer created from another device')
.paramsSubcasesOnly(kRenderEncodeTypeParams.combine('mismatched', [true, false]))
.unimplemented();
.fn(async t => {
const { encoderType, mismatched } = t.params;

if (mismatched) {
await t.selectMismatchedDeviceOrSkipTestCase(undefined);
}

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

const vertexBuffer = device.createBuffer({
size: 16,
usage: GPUBufferUsage.VERTEX,
});
t.trackForCleanup(vertexBuffer);

const { encoder, validateFinish } = t.createEncoder(encoderType);
encoder.setVertexBuffer(0, vertexBuffer);
validateFinish(!mismatched);
});

g.test('vertex_buffer_usage')
.desc(
Expand Down
Loading