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 1 commit
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
8 changes: 0 additions & 8 deletions src/webgpu/api/validation/createBindGroup.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -502,10 +502,6 @@ g.test('bind_group_layout,device_mismatch')
.fn(async t => {
const mismatched = t.params.mismatched;

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

const descriptor = {
entries: [
{
Expand Down Expand Up @@ -562,10 +558,6 @@ g.test('binding_resources,device_mismatch')
.fn(async t => {
const { entry, resource0Mismatched, resource1Mismatched } = t.params;

if (resource0Mismatched || resource1Mismatched) {
await t.selectMismatchedDeviceOrSkipTestCase(undefined);
}

const info = bindingTypeInfo(entry);

const resource0 = resource0Mismatched
Expand Down
8 changes: 0 additions & 8 deletions src/webgpu/api/validation/createComputePipeline.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,6 @@ g.test('pipeline_layout,device_mismatch')
.fn(async t => {
const { isAsync, mismatched } = t.params;

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

const layoutDescriptor = { bindGroupLayouts: [] };
const layout = mismatched
? t.mismatchedDevice.createPipelineLayout(layoutDescriptor)
Expand All @@ -207,10 +203,6 @@ g.test('shader_module,device_mismatch')
.fn(async t => {
const { isAsync, mismatched } = t.params;

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

const code = '@stage(compute) @workgroup_size(1) fn main() {}';
const module = mismatched
? t.mismatchedDevice.createShaderModule({ code })
Expand Down
4 changes: 0 additions & 4 deletions src/webgpu/api/validation/createPipelineLayout.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,6 @@ g.test('bind_group_layouts,device_mismatch')

const mismatched = layout0Mismatched || layout1Mismatched;

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

const bglDescriptor: GPUBindGroupLayoutDescriptor = {
entries: [],
};
Expand Down
8 changes: 0 additions & 8 deletions src/webgpu/api/validation/createRenderPipeline.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -664,10 +664,6 @@ g.test('pipeline_layout,device_mismatch')
.fn(async t => {
const { isAsync, mismatched } = t.params;

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

const layoutDescriptor = { bindGroupLayouts: [] };
const layout = mismatched
? t.mismatchedDevice.createPipelineLayout(layoutDescriptor)
Expand Down Expand Up @@ -709,10 +705,6 @@ g.test('shader_module,device_mismatch')
.fn(async t => {
const { isAsync, vertex_mismatched, fragment_mismatched, _success } = t.params;

if (vertex_mismatched || fragment_mismatched) {
await t.selectMismatchedDeviceOrSkipTestCase(undefined);
}

const code = `
@stage(vertex) fn main() -> @builtin(position) vec4<f32> {
return vec4<f32>(0.0, 0.0, 0.0, 1.0);
Expand Down
12 changes: 0 additions & 12 deletions src/webgpu/api/validation/encoding/beginRenderPass.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ g.test('color_attachments,device_mismatch')

const mismatched = view0Mismatched || target0Mismatched || view1Mismatched || target1Mismatched;

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

const view0Texture = view0Mismatched
? t.getDeviceMismatchedRenderTexture(4)
: t.getRenderTexture(4);
Expand Down Expand Up @@ -114,10 +110,6 @@ g.test('depth_stencil_attachment,device_mismatch')
.fn(async t => {
const { mismatched } = t.params;

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

const descriptor: GPUTextureDescriptor = {
size: { width: 4, height: 4, depthOrArrayLayers: 1 },
format: 'depth24plus-stencil8',
Expand Down Expand Up @@ -154,10 +146,6 @@ g.test('occlusion_query_set,device_mismatch')
.fn(async t => {
const { mismatched } = t.params;

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

const descriptor: GPUQuerySetDescriptor = {
type: 'occlusion',
count: 1,
Expand Down
23 changes: 23 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,29 @@ 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;

const bufferSize = 8;
const descriptor: GPUBufferDescriptor = {
size: bufferSize,
usage: GPUBufferUsage.COPY_DST,
};
const buffer = mismatched
? t.getDeviceMismatchedBuffer(descriptor)
: t.createBufferWithState('valid', descriptor);
haoxli marked this conversation as resolved.
Show resolved Hide resolved

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

g.test('default_args')
.desc(`Test that calling clearBuffer with a default offset and size is valid.`)
.paramsSubcasesOnly([
Expand Down
42 changes: 40 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 @@ -18,6 +18,17 @@ 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 @@ -65,7 +76,17 @@ 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;

const pipeline = mismatched
? t.createComputePipelineForMismatch(t.mismatchedDevice)
: t.createComputePipelineForMismatch(t.device);
haoxli marked this conversation as resolved.
Show resolved Hide resolved

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,21 @@ 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;

const pipeline = t.createNoOpComputePipeline();

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

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,34 @@ 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 srcDescriptor: GPUBufferDescriptor = {
size: 16,
usage: GPUBufferUsage.COPY_SRC,
};
const srcBuffer = srcMismatched
? t.getDeviceMismatchedBuffer(srcDescriptor)
: t.createBufferWithState('valid', srcDescriptor);

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

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

g.test('buffer_usage')
.paramsSubcasesOnly(u =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,38 @@ 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;

const kFormat = 'rgba8unorm';

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

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

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,28 @@ 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;

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

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,21 @@ 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;

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

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

g.test('index_buffer_usage')
.desc(
Expand Down
35 changes: 33 additions & 2 deletions src/webgpu/api/validation/encoding/cmds/render/setPipeline.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,28 @@ import { ValidationTest } from '../../../validation_test.js';

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

export const g = makeTestGroup(ValidationTest);
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);

g.test('invalid_pipeline')
.desc(
Expand All @@ -31,4 +52,14 @@ 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;

const pipeline = mismatched
? t.createRenderPipelineForMismatch(t.mismatchedDevice)
: t.createRenderPipelineForMismatch(t.device);
haoxli marked this conversation as resolved.
Show resolved Hide resolved

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,21 @@ 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;

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

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

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