diff --git a/src/attribute-utils.ts b/src/attribute-utils.ts index 8859ec6..c351e47 100644 --- a/src/attribute-utils.ts +++ b/src/attribute-utils.ts @@ -41,14 +41,14 @@ export type ArrayUnion = number | number[] | TypedArray | FullArraySpec; * Each array can be 1 of 4 things. A native JavaScript array, a TypedArray, a number, a {@link FullArraySpec} * * If it's a native array then, if the name of the array is `indices` the data will be converted - * to a `Uint32Array`, otherwise a `Float32Array. Use a TypedArray or a FullArraySpec to choose a different type. - * The FullArraySpec type is only used if it's not already a TypedArray + * to a `Uint32Array`, otherwise a `Float32Array`. Use a TypedArray or a {@link FullArraySpec} to choose a different type. + * The {@link FullArraySpec} `type` is only used if it's not already a TypedArray * * If it's a native array or a TypedArray or if `numComponents` in a {@link FullArraySpec} is not - * specified it will be guess. If the name contains 'coord', 'texture' or 'uv' then numComponents will be 2. + * specified it will be guessed. If the name contains 'coord', 'texture' or 'uv' then numComponents will be 2. * If the name contains 'color' or 'colour' then numComponents will be 4. Otherwise it's 3. * - * For attribute formats, guesses are made based on type at number of components. The guess is + * For attribute formats, guesses are made based on type and number of components. The guess is * based on this table where (d) is the default for that type if `normalize` is not specified * * | Type | .. | normalize | diff --git a/src/buffer-views.ts b/src/buffer-views.ts index 672c1fb..053a5b5 100644 --- a/src/buffer-views.ts +++ b/src/buffer-views.ts @@ -59,6 +59,11 @@ const b: Record = { mat3x4h: { numElements: 12, align: 8, size: 24, pad: [3, 1], type: 'u16', View: Uint16Array }, mat4x4f: { numElements: 16, align: 16, size: 64, type: 'f32', View: Float32Array }, mat4x4h: { numElements: 16, align: 8, size: 32, type: 'u16', View: Uint16Array }, + + // Note: At least as of WGSL V1 you can not create a bool for uniform or storage. + // You can only create one in an internal struct. But, this code generates + // views of structs and it needs to not fail if the struct has a bool + bool: { numElements: 0, align: 1, size: 0, type: 'bool', View: Uint32Array }, }; const typeInfo: Record = { diff --git a/test/tests/buffer-views-test.js b/test/tests/buffer-views-test.js index b919f0d..b0d2e3a 100644 --- a/test/tests/buffer-views-test.js +++ b/test/tests/buffer-views-test.js @@ -897,4 +897,39 @@ describe('buffer-views-tests', () => { }); + // Note: At least as of WGSL V1 you can not create a bool for uniform or storage. + // You can only create one in an internal struct. But, this code generates + // views of structs and it needs to not fail if the struct has a bool + it('generates handles bool', () => { + const shader = ` + struct Test { + a: u32, + b: bool, + c: u32, + }; + `; + const defs = makeShaderDataDefinitions(shader).structs; + const {views, arrayBuffer} = makeStructuredView(defs.Test); + assertEqual(arrayBuffer.byteLength, 8); + assertEqual(views.a.byteOffset, 0); + assertEqual(views.c.byteOffset, 4); + }); + + /* wgsl_reflect returns bad data for this case. See comment above though. + it('generates handles bool array', () => { + const shader = ` + struct Test { + a: u32, + b: array, + c: u32, + }; + `; + const defs = makeShaderDataDefinitions(shader).structs; + const {views, arrayBuffer} = makeStructuredView(defs.Test); + assertEqual(arrayBuffer.byteLength, 8); + assertEqual(views.a.byteOffset, 0); + assertEqual(views.c.byteOffset, 4); + }); + */ + }); \ No newline at end of file diff --git a/test/tests/data-definition-test.js b/test/tests/data-definition-test.js index 36ba5d8..36be7be 100644 --- a/test/tests/data-definition-test.js +++ b/test/tests/data-definition-test.js @@ -56,6 +56,7 @@ describe('data-definition-tests', () => { foo: u32, bar: f32, moo: vec3f, + brp: bool, // bool is not valid in WGSL 1 for storage/uniforms but can appear internally mrp: i32, }; @group(4) @binding(1) var uni1: VSUniforms;