Skip to content

Commit

Permalink
Deploying to gh-pages from @ df61916 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
greggman committed Dec 30, 2023
1 parent aa8c572 commit 487bfa0
Show file tree
Hide file tree
Showing 88 changed files with 804 additions and 55 deletions.
4 changes: 4 additions & 0 deletions CHANGELIST.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change List

### 1.2.0

* Add `getSizeOfUnsizedArrayElement`

### 1.1.0

* Make `generateMipmap` support compatibility mode
Expand Down
44 changes: 41 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -301,12 +301,50 @@ Example:

```js
const code = `
@group(0) @binding(0) var<uniform> uni1: array<vec3f>; // unsized array
@group(0) @binding(0) var<storage> buf1: array<vec3f>; // unsized array
`;
const defs = makeShaderDataDefinitions(code);
const uni1 = makeStructuredView(defs.uniforms.uni1, new ArrayBuffer(4 * 16));
const buf1 = makeStructuredView(defs.storages.buf1, new ArrayBuffer(4 * 16));

// uni.views will be a Float32Array representing 4 vec3fs
// buf1.views will be a Float32Array representing 4 vec3fs
```

Note: If you have a complex array element type you can call
`getSizeOfUnsizedArrayElement` to get its size. Example:

```js
const code = `
struct Light {
intensity: f32,
direction: vec3f,
};
@group(0) @binding(7) var<storage> lights: array<Light>;
`;
const defs = makeShaderDataDefinitions(code);
const {size} = getSizeOfUnsizedArrayElement(defs.storages.lights);
const numLights = 4;
const buf1 = makeStructuredView(
defs.storages.lights, new ArrayBuffer(numLights * size));
```

Similarly if you are using an unsized array as the last member of a struct
you might do this

```js
const code = `
struct Kernel {
amount: f32,
entries: array<vec3f>,
};
@group(0) @binding(7) var<storage> conv: Kernel;
`;
const defs = makeShaderDataDefinitions(code);
const {size: elemSize} = getSizeOfUnsizedArrayElement(defs.storages.conv);
const numKernelEntries = 4;
const size = defs.storages.conv.size + numKernelEntries * elemSize;
const buf1 = makeStructuredView(
defs.storages.conv, new ArrayBuffer(size));
)
```

## Usage
Expand Down
49 changes: 48 additions & 1 deletion dist/1.x/buffer-views.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,57 @@ export declare function makeStructuredView(varDef: VariableDefinition | StructDe
export declare function setTypedValues(typeDef: TypeDefinition, data: any, arrayBuffer: ArrayBuffer, offset?: number): void;
/**
* Same as @link {setTypedValues} except it takes a @link {VariableDefinition}.
* @param typeDef A variable definition provided by @link {makeShaderDataDefinitions}
* @param varDef A variable definition provided by @link {makeShaderDataDefinitions}
* @param data The source data
* @param arrayBuffer The arrayBuffer who's data to set.
* @param offset An offset in the arrayBuffer to start at.
*/
export declare function setStructuredValues(varDef: VariableDefinition, data: any, arrayBuffer: ArrayBuffer, offset?: number): void;
/**
* Returns the size, align, and unalignedSize of "the" unsized array element. Unsized arrays are only
* allowed at the outer most level or the last member of a top level struct.
*
* Example:
*
* ```js
* const code = `
* struct Foo {
* a: u32,
* b: array<vec3f>,
* };
* @group(0) @binding(0) var<storage> f: Foo;
* `;
* const defs = makeShaderDataDefinitions(code);
* const { size, align, unalignedSize } = getSizeAndAlignmentOfUnsizedArrayElement(
* defs.storages.f);
* // size = 16 (since you need to allocate 16 bytes per element)
* // align = 16 (since vec3f needs to be aligned to 16 bytes)
* // unalignedSize = 12 (since only 12 bytes are used for a vec3f)
* ```
*
* Generally you only need size. Example:
*
*
* ```js
* const code = `
* struct Foo {
* a: u32,
* b: array<vec3f>,
* };
* @group(0) @binding(0) var<storage> f: Foo;
* `;
* const defs = makeShaderDataDefinitions(code);
* const { size } = getSizeAndAlignmentOfUnsizedArrayElement(defs.storages.f);
* const numElements = 10;
* const views = makeStructuredViews(
* defs.storages.f,
* new ArrayBuffer(defs.storages.f.size + size * numElements));
* ```
* @param varDef A variable definition provided by @link {makeShaderDataDefinitions}
* @returns the size, align, and unalignedSize in bytes of the unsized array element in this type definition.
*/
export declare function getSizeAndAlignmentOfUnsizedArrayElement(varDef: VariableDefinition | StructDefinition): {
size: number;
align: number;
};
export {};
94 changes: 89 additions & 5 deletions dist/1.x/webgpu-utils.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/1.x/webgpu-utils.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/1.x/webgpu-utils.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/1.x/webgpu-utils.min.js.map

Large diffs are not rendered by default.

95 changes: 89 additions & 6 deletions dist/1.x/webgpu-utils.module.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/1.x/webgpu-utils.module.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/assets/search.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/classes/TypedArrayViewGenerator.html
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ <h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none"><use href="#icon
<li><a href="../functions/createTextureFromSources.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-64"></use></svg><span>create<wbr/>Texture<wbr/>From<wbr/>Sources</span></a></li>
<li><a href="../functions/drawArrays.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-64"></use></svg><span>draw<wbr/>Arrays</span></a></li>
<li><a href="../functions/generateMipmap.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-64"></use></svg><span>generate<wbr/>Mipmap</span></a></li>
<li><a href="../functions/getSizeAndAlignmentOfUnsizedArrayElement.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-64"></use></svg><span>get<wbr/>Size<wbr/>And<wbr/>Alignment<wbr/>Of<wbr/>Unsized<wbr/>Array<wbr/>Element</span></a></li>
<li><a href="../functions/getSizeForMipFromTexture.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-64"></use></svg><span>get<wbr/>Size<wbr/>For<wbr/>Mip<wbr/>From<wbr/>Texture</span></a></li>
<li><a href="../functions/getSizeFromSource.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-64"></use></svg><span>get<wbr/>Size<wbr/>From<wbr/>Source</span></a></li>
<li><a href="../functions/interleaveVertexData.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-64"></use></svg><span>interleave<wbr/>Vertex<wbr/>Data</span></a></li>
Expand Down
1 change: 1 addition & 0 deletions docs/classes/primitives.TypedArrayWrapper.html
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ <h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none"><use href="#icon
<li><a href="../functions/createTextureFromSources.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-64"></use></svg><span>create<wbr/>Texture<wbr/>From<wbr/>Sources</span></a></li>
<li><a href="../functions/drawArrays.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-64"></use></svg><span>draw<wbr/>Arrays</span></a></li>
<li><a href="../functions/generateMipmap.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-64"></use></svg><span>generate<wbr/>Mipmap</span></a></li>
<li><a href="../functions/getSizeAndAlignmentOfUnsizedArrayElement.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-64"></use></svg><span>get<wbr/>Size<wbr/>And<wbr/>Alignment<wbr/>Of<wbr/>Unsized<wbr/>Array<wbr/>Element</span></a></li>
<li><a href="../functions/getSizeForMipFromTexture.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-64"></use></svg><span>get<wbr/>Size<wbr/>For<wbr/>Mip<wbr/>From<wbr/>Texture</span></a></li>
<li><a href="../functions/getSizeFromSource.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-64"></use></svg><span>get<wbr/>Size<wbr/>From<wbr/>Source</span></a></li>
<li><a href="../functions/interleaveVertexData.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-64"></use></svg><span>interleave<wbr/>Vertex<wbr/>Data</span></a></li>
Expand Down
Loading

0 comments on commit 487bfa0

Please sign in to comment.