-
Notifications
You must be signed in to change notification settings - Fork 109
Test GPUBuffer in GPUBindingResource #4390
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
Changes from 4 commits
54eb9da
5a1acb3
630cf39
0640df2
0b59f35
8a5cbaa
6580afd
c407f0d
ad68f0a
ef363ab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -160,3 +160,76 @@ g.test('large_dispatch') | |||||
|
|
||||||
| dst.destroy(); | ||||||
| }); | ||||||
|
|
||||||
| g.test('buffer_binding_resource') | ||||||
| .desc( | ||||||
| `Validate the correctness of the buffer binding resource by filling the buffer with | ||||||
| testable data, clearing buffer in shader, and verifying the content of the whole buffer: | ||||||
| - covers the whole buffer | ||||||
| - covers the beginning of the buffer | ||||||
| - covers the end of the buffer | ||||||
| - covers neither the beginning nor the end of the buffer` | ||||||
| ) | ||||||
| .paramsSubcasesOnly(u => | ||||||
| u // | ||||||
| .combine('bindBufferResource', [false, true] as const) | ||||||
| .combine('offset', [0, 256, undefined]) | ||||||
| .combine('size', [4, 8, undefined]) | ||||||
| .expand('bufferSize', p => [ | ||||||
| (p.offset ?? 0) + (p.size ?? 16), | ||||||
| (p.offset ?? 0) + (p.size ?? 16) + 8, | ||||||
| ]) | ||||||
| ) | ||||||
| .fn(t => { | ||||||
| const { offset, size, bufferSize, bindBufferResource } = t.params; | ||||||
|
|
||||||
| const bufferData = new Uint8Array(bufferSize); | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. optional nit
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This forces me to add
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good. |
||||||
| for (let i = 0; i < bufferSize; ++i) { | ||||||
| bufferData[i] = i + 1; | ||||||
| } | ||||||
|
|
||||||
| const buffer = t.makeBufferWithContents( | ||||||
| bufferData, | ||||||
| GPUBufferUsage.COPY_DST | GPUBufferUsage.COPY_SRC | GPUBufferUsage.STORAGE | ||||||
| ); | ||||||
|
|
||||||
| const pipeline = t.device.createComputePipeline({ | ||||||
| layout: 'auto', | ||||||
| compute: { | ||||||
| module: t.device.createShaderModule({ | ||||||
| code: ` | ||||||
| @group(0) @binding(0) var<storage, read_write> buffer : array<u32>; | ||||||
|
|
||||||
| @compute @workgroup_size(1) fn main() { | ||||||
| for (var i = 0u; i < arrayLength(&buffer); i = i + 1u) { | ||||||
| buffer[i] = 0; | ||||||
| } | ||||||
| return; | ||||||
| }`, | ||||||
| }), | ||||||
| }, | ||||||
| }); | ||||||
|
|
||||||
| const resource = bindBufferResource ? buffer : { buffer, offset, size }; | ||||||
| const bg = t.device.createBindGroup({ | ||||||
| entries: [{ binding: 0, resource }], | ||||||
| layout: pipeline.getBindGroupLayout(0), | ||||||
| }); | ||||||
|
|
||||||
| const encoder = t.device.createCommandEncoder(); | ||||||
| const pass = encoder.beginComputePass(); | ||||||
| pass.setPipeline(pipeline); | ||||||
| pass.setBindGroup(0, bg); | ||||||
| pass.dispatchWorkgroups(1); | ||||||
| pass.end(); | ||||||
| t.device.queue.submit([encoder.finish()]); | ||||||
|
|
||||||
| const expectOffset = bindBufferResource ? 0 : offset ?? 0; | ||||||
| const expectSize = bindBufferResource ? bufferSize : size ?? bufferSize - expectOffset; | ||||||
|
|
||||||
| for (let i = 0; i < expectSize; ++i) { | ||||||
| bufferData[expectOffset + i] = 0; | ||||||
| } | ||||||
|
|
||||||
| t.expectGPUBufferValuesEqual(buffer, bufferData); | ||||||
| }); | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could avoid generating the subcases with offset / size when bindBufferResource is true. Also bufferSize could be
extraBufferSize: [0, 8]and the computation done in the test.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done