Skip to content

Commit

Permalink
support atomics
Browse files Browse the repository at this point in the history
  • Loading branch information
greggman committed Jan 3, 2024
1 parent 47f4665 commit a0a102f
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/buffer-views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ const b: { readonly [K: string]: TypeDef } = {
const typeInfo: { readonly [K: string]: TypeDef } = {
...b,

'atomic<i32>': b.i32,
'atomic<u32>': b.u32,

'vec2<i32>': b.vec2i,
'vec2<u32>': b.vec2u,
'vec2<f32>': b.vec2f,
Expand Down
43 changes: 43 additions & 0 deletions test/tests/buffer-views-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,49 @@ describe('buffer-views-tests', () => {
test(defs.storages.vsStorage);
});

it('handles atomics', () => {
const shader = `
struct AB {
a: atomic<u32>,
b: array<atomic<u32>, 4>,
};
@group(0) @binding(0) var<storage, read_write> s1: atomic<u32>;
@group(0) @binding(1) var<storage, read_write> s2: array<atomic<u32>, 4>;
@group(0) @binding(2) var<storage, read_write> s3: AB;
@group(0) @binding(0) var<storage, read_write> s4: atomic<i32>;
`;
const defs = makeShaderDataDefinitions(shader);
{
const {views, arrayBuffer} = makeStructuredView(defs.storages.s1);
assertEqual(arrayBuffer.byteLength, 4);
assertEqual(views.length, 1);
assertTruthy(views instanceof Uint32Array);
}
{
const {views, arrayBuffer} = makeStructuredView(defs.storages.s2);
assertEqual(arrayBuffer.byteLength, 16);
assertEqual(views.length, 4);
assertTruthy(views instanceof Uint32Array);
}
{
const {views, arrayBuffer} = makeStructuredView(defs.storages.s3);
assertEqual(arrayBuffer.byteLength, 20);
assertEqual(views.a.length, 1);
assertEqual(views.a.byteOffset, 0);
assertEqual(views.b.length, 4);
assertEqual(views.b.byteOffset, 4);
assertTruthy(views.a instanceof Uint32Array);
assertTruthy(views.b instanceof Uint32Array);
}
{
const {views, arrayBuffer} = makeStructuredView(defs.storages.s4);
assertEqual(arrayBuffer.byteLength, 4);
assertEqual(views.length, 1);
assertTruthy(views instanceof Int32Array);
}
});

it('handles arrays of structs', () => {
const shader = `
struct VertexDesc {
Expand Down

0 comments on commit a0a102f

Please sign in to comment.