From a0a102fba0933b2d7b3b4e8ad7f3148d9c042699 Mon Sep 17 00:00:00 2001 From: Gregg Tavares Date: Wed, 3 Jan 2024 14:12:28 -0800 Subject: [PATCH] support atomics --- src/buffer-views.ts | 3 +++ test/tests/buffer-views-test.js | 43 +++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/src/buffer-views.ts b/src/buffer-views.ts index 2ad0f07..3188eeb 100644 --- a/src/buffer-views.ts +++ b/src/buffer-views.ts @@ -70,6 +70,9 @@ const b: { readonly [K: string]: TypeDef } = { const typeInfo: { readonly [K: string]: TypeDef } = { ...b, + 'atomic': b.i32, + 'atomic': b.u32, + 'vec2': b.vec2i, 'vec2': b.vec2u, 'vec2': b.vec2f, diff --git a/test/tests/buffer-views-test.js b/test/tests/buffer-views-test.js index 4f654ca..7e5f99a 100644 --- a/test/tests/buffer-views-test.js +++ b/test/tests/buffer-views-test.js @@ -227,6 +227,49 @@ describe('buffer-views-tests', () => { test(defs.storages.vsStorage); }); + it('handles atomics', () => { + const shader = ` + struct AB { + a: atomic, + b: array, 4>, + }; + + @group(0) @binding(0) var s1: atomic; + @group(0) @binding(1) var s2: array, 4>; + @group(0) @binding(2) var s3: AB; + @group(0) @binding(0) var s4: atomic; + `; + 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 {