typegpu 0.12.2 → 0.12.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,7 +3,7 @@ import { isVoid, isWgslStruct } from "../../data/wgslTypes.js";
3
3
  export function connectTargetsToShader(fragmentOut, targets) {
4
4
  let presentationFormat;
5
5
  if (isVoid(fragmentOut) || isBuiltin(fragmentOut)) {
6
- return [null];
6
+ return [];
7
7
  }
8
8
  if (isWgslStruct(fragmentOut)) {
9
9
  const result = [];
@@ -409,7 +409,7 @@ class RenderPipelineCore {
409
409
  // One other reason is that if the shelled fragment has already been resolved in this namespace,
410
410
  // then this.#latestAutoFragmentOut will be undefined.
411
411
  const fragmentOut = fragment?.shell?.returnType ?? this.#latestAutoFragmentOut;
412
- const connectedTargets = fragmentOut ? connectTargetsToShader(fragmentOut, targets) : [null];
412
+ const connectedTargets = fragmentOut ? connectTargetsToShader(fragmentOut, targets) : [];
413
413
  const descriptor = {
414
414
  layout: device.createPipelineLayout({
415
415
  label: `${getName(this) ?? '<unnamed>'} - Pipeline Layout`,
@@ -1 +1 @@
1
- export {};
1
+ export declare function assignInfixOperators(): void;
@@ -2,13 +2,20 @@ import { Operator } from 'tsover-runtime';
2
2
  import { MatBase } from "./matrix.js";
3
3
  import { VecBase } from "./vectorImpl.js";
4
4
  import { assignInfixOperator } from "../tgsl/infixDispatch.js";
5
- assignInfixOperator(VecBase, 'add', Operator.plus);
6
- assignInfixOperator(MatBase, 'add', Operator.plus);
7
- assignInfixOperator(VecBase, 'sub', Operator.minus);
8
- assignInfixOperator(MatBase, 'sub', Operator.minus);
9
- assignInfixOperator(VecBase, 'mul', Operator.star);
10
- assignInfixOperator(MatBase, 'mul', Operator.star);
11
- assignInfixOperator(VecBase, 'div', Operator.slash);
12
- assignInfixOperator(VecBase, 'mod', Operator.percent);
13
- assignInfixOperator(VecBase, 'bitShiftLeft', Symbol()); // bitShift does not yet have tsover operator symbol
14
- assignInfixOperator(VecBase, 'bitShiftRight', Symbol()); // bitShift does not yet have tsover operator symbol
5
+ let infixOperatorsAssigned = false;
6
+ export function assignInfixOperators() {
7
+ if (infixOperatorsAssigned) {
8
+ return;
9
+ }
10
+ infixOperatorsAssigned = true;
11
+ assignInfixOperator(VecBase, 'add', Operator.plus);
12
+ assignInfixOperator(MatBase, 'add', Operator.plus);
13
+ assignInfixOperator(VecBase, 'sub', Operator.minus);
14
+ assignInfixOperator(MatBase, 'sub', Operator.minus);
15
+ assignInfixOperator(VecBase, 'mul', Operator.star);
16
+ assignInfixOperator(MatBase, 'mul', Operator.star);
17
+ assignInfixOperator(VecBase, 'div', Operator.slash);
18
+ assignInfixOperator(VecBase, 'mod', Operator.percent);
19
+ assignInfixOperator(VecBase, 'bitShiftLeft', Symbol()); // bitShift does not yet have tsover operator symbol
20
+ assignInfixOperator(VecBase, 'bitShiftRight', Symbol()); // bitShift does not yet have tsover operator symbol
21
+ }
package/data/index.d.ts CHANGED
@@ -1,7 +1,24 @@
1
1
  /**
2
2
  * @module typegpu/data
3
3
  */
4
- import './assignInfixOperators.ts';
4
+ export declare const vec2b: import("./wgslTypes.ts").Vec2b;
5
+ export declare const vec2f: import("./wgslTypes.ts").Vec2f;
6
+ export declare const vec2h: import("./wgslTypes.ts").Vec2h;
7
+ export declare const vec2i: import("./wgslTypes.ts").Vec2i;
8
+ export declare const vec2u: import("./wgslTypes.ts").Vec2u;
9
+ export declare const vec3b: import("./wgslTypes.ts").Vec3b;
10
+ export declare const vec3f: import("./wgslTypes.ts").Vec3f;
11
+ export declare const vec3h: import("./wgslTypes.ts").Vec3h;
12
+ export declare const vec3i: import("./wgslTypes.ts").Vec3i;
13
+ export declare const vec3u: import("./wgslTypes.ts").Vec3u;
14
+ export declare const vec4b: import("./wgslTypes.ts").Vec4b;
15
+ export declare const vec4f: import("./wgslTypes.ts").Vec4f;
16
+ export declare const vec4h: import("./wgslTypes.ts").Vec4h;
17
+ export declare const vec4i: import("./wgslTypes.ts").Vec4i;
18
+ export declare const vec4u: import("./wgslTypes.ts").Vec4u;
19
+ export declare const mat2x2f: import("./wgslTypes.ts").Mat2x2f;
20
+ export declare const mat3x3f: import("./wgslTypes.ts").Mat3x3f;
21
+ export declare const mat4x4f: import("./wgslTypes.ts").Mat4x4f;
5
22
  export { bool, f16, f32, i32, u16, u32 } from './numeric.ts';
6
23
  export { isAlignAttrib, isAtomic, isBuiltinAttrib, isDecorated, isInterpolateAttrib, isInvariantAttrib, isLocationAttrib, isPtr, isSizeAttrib, isWgslArray, isWgslData, isWgslStruct, Void, } from './wgslTypes.ts';
7
24
  export type { Align, AnyVecInstance, AnyWgslData, AnyWgslStruct, Atomic, atomicI32, atomicU32, BaseData, BaseData as BaseWgslData, Bool, Builtin, Decorated, F16, F32, I32, Interpolate, Invariant, Location, m2x2f, m3x3f, m4x4f, Mat2x2f, Mat3x3f, Mat4x4f, matBase, Ptr, Size, StorableData, U16, U32, v2b, v2f, v2h, v2i, v2u, v3b, v3f, v3h, v3i, v3u, v4b, v4f, v4h, v4i, v4u, Vec2b, Vec2f, Vec2h, Vec2i, Vec2u, Vec3b, Vec3f, Vec3h, Vec3i, Vec3u, Vec4b, Vec4f, Vec4h, Vec4i, Vec4u, vecBase, WgslArray, WgslStruct, } from './wgslTypes.ts';
@@ -11,10 +28,9 @@ export { ptrFn, ptrHandle, ptrPrivate, ptrStorage, ptrUniform, ptrWorkgroup } fr
11
28
  export type { AnyData, AnyLooseData, Disarray, LooseDecorated, Unstruct } from './dataTypes.ts';
12
29
  export { texture1d, texture2d, texture2dArray, texture3d, textureCube, textureCubeArray, textureDepth2d, textureDepth2dArray, textureDepthCube, textureDepthCubeArray, textureDepthMultisampled2d, textureExternal, textureMultisampled2d, textureStorage1d, textureStorage2d, textureStorage2dArray, textureStorage3d, type WgslExternalTexture, type WgslStorageTexture, type WgslStorageTexture1d, type WgslStorageTexture2d, type WgslStorageTexture2dArray, type WgslStorageTexture3d, type WgslStorageTextureProps, type WgslTexture, type WgslTexture1d, type WgslTexture2d, type WgslTexture2dArray, type WgslTexture3d, type WgslTextureCube, type WgslTextureCubeArray, type WgslTextureDepth2d, type WgslTextureDepth2dArray, type WgslTextureDepthCube, type WgslTextureDepthCubeArray, type WgslTextureDepthMultisampled2d, type WgslTextureMultisampled2d, } from './texture.ts';
13
30
  export { comparisonSampler, sampler, type WgslComparisonSampler, type WgslSampler, } from './sampler.ts';
14
- export { vec2b, vec2f, vec2h, vec2i, vec2u, vec3b, vec3f, vec3h, vec3i, vec3u, vec4b, vec4f, vec4h, vec4i, vec4u, } from './vector.ts';
15
31
  export { disarrayOf } from './disarray.ts';
16
32
  export { unstruct } from './unstruct.ts';
17
- export { mat2x2f, mat3x3f, mat4x4f, matToArray } from './matrix.ts';
33
+ export { matToArray } from './matrix.ts';
18
34
  export * from './vertexFormatData.ts';
19
35
  export { atomic } from './atomic.ts';
20
36
  export { _ref as ref } from './ref.ts';
package/data/index.js CHANGED
@@ -2,8 +2,27 @@
2
2
  * @module typegpu/data
3
3
  */
4
4
  // NOTE: This is a barrel file, internal files should not import things from this file
5
- // oxlint-disable-next-line import/no-unassigned-import -- this import has side effects
6
- import "./assignInfixOperators.js";
5
+ import { assignInfixOperators } from "./assignInfixOperators.js";
6
+ import { vec2b as _vec2b, vec2f as _vec2f, vec2h as _vec2h, vec2i as _vec2i, vec2u as _vec2u, vec3b as _vec3b, vec3f as _vec3f, vec3h as _vec3h, vec3i as _vec3i, vec3u as _vec3u, vec4b as _vec4b, vec4f as _vec4f, vec4h as _vec4h, vec4i as _vec4i, vec4u as _vec4u, } from "./vector.js";
7
+ export const vec2b = (() => (assignInfixOperators(), _vec2b))();
8
+ export const vec2f = (() => (assignInfixOperators(), _vec2f))();
9
+ export const vec2h = (() => (assignInfixOperators(), _vec2h))();
10
+ export const vec2i = (() => (assignInfixOperators(), _vec2i))();
11
+ export const vec2u = (() => (assignInfixOperators(), _vec2u))();
12
+ export const vec3b = (() => (assignInfixOperators(), _vec3b))();
13
+ export const vec3f = (() => (assignInfixOperators(), _vec3f))();
14
+ export const vec3h = (() => (assignInfixOperators(), _vec3h))();
15
+ export const vec3i = (() => (assignInfixOperators(), _vec3i))();
16
+ export const vec3u = (() => (assignInfixOperators(), _vec3u))();
17
+ export const vec4b = (() => (assignInfixOperators(), _vec4b))();
18
+ export const vec4f = (() => (assignInfixOperators(), _vec4f))();
19
+ export const vec4h = (() => (assignInfixOperators(), _vec4h))();
20
+ export const vec4i = (() => (assignInfixOperators(), _vec4i))();
21
+ export const vec4u = (() => (assignInfixOperators(), _vec4u))();
22
+ import { mat2x2f as _mat2x2f, mat3x3f as _mat3x3f, mat4x4f as _mat4x4f } from "./matrix.js";
23
+ export const mat2x2f = (() => (assignInfixOperators(), _mat2x2f))();
24
+ export const mat3x3f = (() => (assignInfixOperators(), _mat3x3f))();
25
+ export const mat4x4f = (() => (assignInfixOperators(), _mat4x4f))();
7
26
  export { bool, f16, f32, i32, u16, u32 } from "./numeric.js";
8
27
  export { isAlignAttrib, isAtomic, isBuiltinAttrib, isDecorated, isInterpolateAttrib, isInvariantAttrib, isLocationAttrib, isPtr, isSizeAttrib, isWgslArray, isWgslData, isWgslStruct, Void, } from "./wgslTypes.js";
9
28
  export { struct } from "./struct.js";
@@ -11,10 +30,9 @@ export { arrayOf } from "./array.js";
11
30
  export { ptrFn, ptrHandle, ptrPrivate, ptrStorage, ptrUniform, ptrWorkgroup } from "./ptr.js";
12
31
  export { texture1d, texture2d, texture2dArray, texture3d, textureCube, textureCubeArray, textureDepth2d, textureDepth2dArray, textureDepthCube, textureDepthCubeArray, textureDepthMultisampled2d, textureExternal, textureMultisampled2d, textureStorage1d, textureStorage2d, textureStorage2dArray, textureStorage3d, } from "./texture.js";
13
32
  export { comparisonSampler, sampler, } from "./sampler.js";
14
- export { vec2b, vec2f, vec2h, vec2i, vec2u, vec3b, vec3f, vec3h, vec3i, vec3u, vec4b, vec4f, vec4h, vec4i, vec4u, } from "./vector.js";
15
33
  export { disarrayOf } from "./disarray.js";
16
34
  export { unstruct } from "./unstruct.js";
17
- export { mat2x2f, mat3x3f, mat4x4f, matToArray } from "./matrix.js";
35
+ export { matToArray } from "./matrix.js";
18
36
  export * from "./vertexFormatData.js";
19
37
  export { atomic } from "./atomic.js";
20
38
  export { _ref as ref } from "./ref.js";
package/index.d.ts CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  // NOTE: This is a barrel file, internal files should not import things from this file
6
6
 
7
- export declare const tgpu: {
7
+ declare const tgpu_default: {
8
8
  const: typeof import('./core/constant/tgpuConstant.ts').constant;
9
9
  fn: typeof import('./core/function/tgpuFn.ts').fn;
10
10
  comptime: typeof import('./core/function/comptime.ts').comptime;
@@ -28,6 +28,7 @@ export declare const tgpu: {
28
28
  '~unstable': typeof import('./tgpuUnstable.ts');
29
29
  };
30
30
 
31
- export default tgpu;
31
+ export { tgpu_default as tgpu };
32
+ export default tgpu_default;
32
33
 
33
34
  export * from './indexNamedExports.ts';
package/index.js CHANGED
@@ -2,7 +2,6 @@
2
2
  * @module typegpu
3
3
  */
4
4
  // NOTE: This is a barrel file, internal files should not import things from this file
5
- import * as tgpu from "./tgpu.js";
6
5
  export * as tgpu from "./tgpu.js";
7
- export default tgpu;
6
+ export * as default from "./tgpu.js";
8
7
  export * from "./indexNamedExports.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typegpu",
3
- "version": "0.12.2",
3
+ "version": "0.12.4",
4
4
  "description": "A thin layer between JS and WebGPU/WGSL that improves development experience and allows for faster iteration.",
5
5
  "keywords": [
6
6
  "compute",
@@ -23,9 +23,7 @@
23
23
  "directory": "packages/typegpu"
24
24
  },
25
25
  "type": "module",
26
- "sideEffects": [
27
- "./data/assignInfixOperators.js"
28
- ],
26
+ "sideEffects": false,
29
27
  "exports": {
30
28
  "./package.json": "./package.json",
31
29
  ".": {
@@ -52,7 +50,7 @@
52
50
  "dependencies": {
53
51
  "tsover-runtime": "^0.0.7",
54
52
  "typed-binary": "^4.3.3",
55
- "tinyest": "~0.3.2"
53
+ "tinyest": "~0.3.3"
56
54
  },
57
55
  "engines": {
58
56
  "node": ">=12.20.0"
package/resolutionCtx.js CHANGED
@@ -845,6 +845,9 @@ export class ResolutionCtxImpl {
845
845
  if (schema && isWgslStruct(schema)) {
846
846
  return this.gen.typeInstantiation(schema, Object.entries(schema.propTypes).map(([key, propType]) => snip(item[key], propType, /* origin */ 'runtime')));
847
847
  }
848
+ if (item === null) {
849
+ throw new WgslTypeError(`'null' is not resolvable. 'null' is only allowed in comptime checks.`);
850
+ }
848
851
  throw new WgslTypeError(`Value ${safeStringify(item)} is not resolvable${schema && schema !== UnknownData ? ` to type ${safeStringify(schema)}` : ''}`);
849
852
  }
850
853
  resolveSnippet(snippet) {
package/shared/meta.js CHANGED
@@ -1,4 +1,4 @@
1
- const version = "0.12.2";
1
+ const version = "0.12.4";
2
2
  import { DEV, TEST } from "./env.js";
3
3
  import { $getNameForward, $soul, isMarkedInternal } from "./symbols.js";
4
4
  import { normalizeMetadata } from "./normalizeMetadata.js";
package/shared/symbols.js CHANGED
@@ -1,4 +1,4 @@
1
- const version = "0.12.2";
1
+ const version = "0.12.4";
2
2
  export const $internal = Symbol(`typegpu:${version}:$internal`);
3
3
  /** A plain record of all definitional state of a resource, surviving transfer between runtimes */
4
4
  export const $soul = Symbol(`typegpu:${version}:$soul`);
package/shared/tseynit.js CHANGED
@@ -124,6 +124,9 @@ function stringifyExpression(node, ident) {
124
124
  if (node[0] === NODE.conditionalExpr) {
125
125
  return `${wrapIfComplex(node[1], ident)} ? ${wrapIfComplex(node[2], ident)} : ${wrapIfComplex(node[3], ident)}`;
126
126
  }
127
+ if (node[0] === NODE.nullLiteral) {
128
+ return 'null';
129
+ }
127
130
  assertExhaustive(node);
128
131
  }
129
132
  function assertExhaustive(value) {
@@ -145,7 +148,8 @@ function isExpression(node) {
145
148
  node[0] === NODE.preUpdate ||
146
149
  node[0] === NODE.postUpdate ||
147
150
  node[0] === NODE.objectExpr ||
148
- node[0] === NODE.conditionalExpr) {
151
+ node[0] === NODE.conditionalExpr ||
152
+ node[0] === NODE.nullLiteral) {
149
153
  node;
150
154
  return true;
151
155
  }
@@ -734,6 +734,9 @@ export class WgslGenerator {
734
734
  if (expression[0] === NODE.preUpdate) {
735
735
  throw new Error('Cannot use pre-updates in TypeGPU functions.');
736
736
  }
737
+ if (expression[0] === NODE.nullLiteral) {
738
+ return snip(null, UnknownData, 'constant', false);
739
+ }
737
740
  assertExhaustive(expression);
738
741
  }
739
742
  declareGlobalConst(options) {