Skip to content

Commit

Permalink
Deploying to gh-pages from @ d63fef9 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
greggman committed Dec 4, 2023
1 parent 36bc2d5 commit c7809ad
Show file tree
Hide file tree
Showing 85 changed files with 895 additions and 62 deletions.
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ passEncoder.drawIndexed(bi.numElements);

## Notes about structured data

### The first level of an array of intrinsic types is flattened.
### The first level of an array of intrinsic types is flattened by default.

Example:

Expand Down Expand Up @@ -246,6 +246,28 @@ The reason it's this way is it's common to make large arrays of `f32`, `u32`,
`vec2f`, `vec3f`, `vec4f` etc. We wouldn't want every element of an array to
have its own typedarray view.

You can configure this per type by calling `setIntrinsicsToView`.
The configuration is global. Given th example above

```js
const code = `
@group(0) @binding(0) var<uniform> uni1: array<vec3f, 4>;
@group(0) @binding(1) var<uniform> uni2: array<array<vec3f, 3>, 4>;
`;
const defs = makeShaderDataDefinitions(code);
setIntrinsicsToView(['vec3f']);
const uni1 = makeStructuredView(defs.uniforms.uni1);

uni1.set([
[1, 2, 3], // uni1[0]
[4, 5, 6], // uni1[1]
...
]);
```

Or to put it another way, in the default case, `uni1.views is a Float32Array(16)`.
In the 2nd case it's an array of 4 `Float32Array` each 3 elements big

### arrays of intrinsics can be set by arrays of arrays

```js
Expand Down
54 changes: 53 additions & 1 deletion dist/0.x/buffer-views.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,56 @@
import { StructDefinition, TypeDefinition, VariableDefinition } from './data-definitions.js';
import { TypedArray } from './typed-arrays.js';
import { TypedArrayConstructor, TypedArray } from './typed-arrays.js';
type TypeDef = {
numElements: number;
align: number;
size: number;
type: string;
View: TypedArrayConstructor;
flatten?: boolean;
pad?: readonly number[];
};
declare const typeInfo: {
readonly [K: string]: TypeDef;
};
export type kType = Extract<keyof typeof typeInfo, string>;
export declare const kTypes: readonly kType[];
/**
* Set which intrinsic types to make views for.
*
* Example:
*
* Given a an array of intrinsics like this
* `array<vec3, 200>`
*
* The default is to create a single `Float32Array(4 * 200)`
* because creating 200 `Float32Array` views is not usually
* what you want.
*
* If you do want individual views then you'd call
* `setIntrinsicsToView(['vec3f`])` and now you get
* an array of 200 `Float32Array`s.
*
* Note: `setIntrinsicsToView` always sets ALL types. The list you
* pass it is the types you want views created for, all other types
* will be reset to do the default. In other words
*
* ```js
* setIntrinsicsToView(['vec3f`])
* setIntrinsicsToView(['vec2f`])
* ```
*
* Only `vec2f` will have views created. `vec3f` has been reset to the default by
* the second call
*
* You can pass in `true` as the 2nd parameter to make it set which types
* to flatten and all others will be set to have views created.
*
* To reset all types to the default call it with no arguments
*
* @param types array of types to make views for
* @param flatten whether to flatten or expand the specified types.
*/
export declare function setIntrinsicsToView(types?: readonly kType[], flatten?: boolean): void;
export type TypedArrayOrViews = TypedArray | Views | Views[];
export interface Views {
[x: string]: TypedArrayOrViews;
Expand Down Expand Up @@ -153,3 +204,4 @@ export declare function setTypedValues(typeDef: TypeDefinition, data: any, array
* @param offset An offset in the arrayBuffer to start at.
*/
export declare function setStructuredValues(varDef: VariableDefinition, data: any, arrayBuffer: ArrayBuffer, offset?: number): void;
export {};
4 changes: 4 additions & 0 deletions dist/0.x/utils.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
export declare const roundUpToMultipleOf: (v: number, multiple: number) => number;
export declare function keysOf<T extends string>(obj: {
[k in T]: unknown;
}): readonly T[];
export declare function range<T>(count: number, fn: (i: number) => T): T[];
65 changes: 60 additions & 5 deletions dist/0.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/0.x/webgpu-utils.js.map

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

65 changes: 59 additions & 6 deletions dist/0.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/0.x/webgpu-utils.module.js.map

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions docs/assets/highlight.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
--dark-hl-9: #C8C8C8;
--light-hl-10: #267F99;
--dark-hl-10: #4EC9B0;
--light-hl-11: #CD3131;
--dark-hl-11: #F44747;
--light-code-background: #FFFFFF;
--dark-code-background: #1E1E1E;
}
Expand All @@ -37,6 +39,7 @@
--hl-8: var(--light-hl-8);
--hl-9: var(--light-hl-9);
--hl-10: var(--light-hl-10);
--hl-11: var(--light-hl-11);
--code-background: var(--light-code-background);
} }

Expand All @@ -52,6 +55,7 @@
--hl-8: var(--dark-hl-8);
--hl-9: var(--dark-hl-9);
--hl-10: var(--dark-hl-10);
--hl-11: var(--dark-hl-11);
--code-background: var(--dark-code-background);
} }

Expand All @@ -67,6 +71,7 @@
--hl-8: var(--light-hl-8);
--hl-9: var(--light-hl-9);
--hl-10: var(--light-hl-10);
--hl-11: var(--light-hl-11);
--code-background: var(--light-code-background);
}

Expand All @@ -82,6 +87,7 @@
--hl-8: var(--dark-hl-8);
--hl-9: var(--dark-hl-9);
--hl-10: var(--dark-hl-10);
--hl-11: var(--dark-hl-11);
--code-background: var(--dark-code-background);
}

Expand All @@ -96,4 +102,5 @@
.hl-8 { color: var(--hl-8); }
.hl-9 { color: var(--hl-9); }
.hl-10 { color: var(--hl-10); }
.hl-11 { color: var(--hl-11); }
pre, code { background: var(--code-background); }
2 changes: 1 addition & 1 deletion docs/assets/search.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions docs/classes/TypedArrayViewGenerator.html
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ <h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none"><use href="#icon
<li><a href="../types/TypedArrayConstructor.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-4194304"></use></svg><span>Typed<wbr/>Array<wbr/>Constructor</span></a></li>
<li><a href="../types/TypedArrayOrViews.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-4194304"></use></svg><span>Typed<wbr/>Array<wbr/>Or<wbr/>Views</span></a></li>
<li><a href="../types/VariableDefinitions.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-4194304"></use></svg><span>Variable<wbr/>Definitions</span></a></li>
<li><a href="../types/kType.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-4194304"></use></svg><span>k<wbr/>Type</span></a></li>
<li><a href="../variables/kTypes.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><g id="icon-32"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-variable)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="6"></rect><path d="M11.106 16L8.85 7.24H9.966L11.454 13.192C11.558 13.608 11.646 13.996 11.718 14.356C11.79 14.708 11.842 14.976 11.874 15.16C11.906 14.976 11.954 14.708 12.018 14.356C12.09 13.996 12.178 13.608 12.282 13.192L13.758 7.24H14.85L12.582 16H11.106Z" fill="var(--color-text)"></path></g></svg><span>k<wbr/>Types</span></a></li>
<li><a href="../functions/copySourceToTexture.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><g id="icon-64"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-function)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="6"></rect><path d="M9.39 16V7.24H14.55V8.224H10.446V11.128H14.238V12.112H10.47V16H9.39Z" fill="var(--color-text)"></path></g></svg><span>copy<wbr/>Source<wbr/>To<wbr/>Texture</span></a></li>
<li><a href="../functions/copySourcesToTexture.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-64"></use></svg><span>copy<wbr/>Sources<wbr/>To<wbr/>Texture</span></a></li>
<li><a href="../functions/createBufferLayoutsFromArrays.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-64"></use></svg><span>create<wbr/>Buffer<wbr/>Layouts<wbr/>From<wbr/>Arrays</span></a></li>
Expand All @@ -178,6 +180,7 @@ <h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none"><use href="#icon
<li><a href="../functions/makeTypedArrayViews.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-64"></use></svg><span>make<wbr/>Typed<wbr/>Array<wbr/>Views</span></a></li>
<li><a href="../functions/normalizeGPUExtent3D.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-64"></use></svg><span>normalizeGPUExtent3D</span></a></li>
<li><a href="../functions/numMipLevels.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-64"></use></svg><span>num<wbr/>Mip<wbr/>Levels</span></a></li>
<li><a href="../functions/setIntrinsicsToView.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-64"></use></svg><span>set<wbr/>Intrinsics<wbr/>To<wbr/>View</span></a></li>
<li><a href="../functions/setStructuredValues.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-64"></use></svg><span>set<wbr/>Structured<wbr/>Values</span></a></li>
<li><a href="../functions/setStructuredView.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-64"></use></svg><span>set<wbr/>Structured<wbr/>View</span></a></li>
<li><a href="../functions/setTypedValues.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-64"></use></svg><span>set<wbr/>Typed<wbr/>Values</span></a></li>
Expand Down
Loading

0 comments on commit c7809ad

Please sign in to comment.