diff --git a/apps/typegpu-docs/tests/individual-example-tests/oklab.test.ts b/apps/typegpu-docs/tests/individual-example-tests/oklab.test.ts index 23abf35258..f7a3a93c49 100644 --- a/apps/typegpu-docs/tests/individual-example-tests/oklab.test.ts +++ b/apps/typegpu-docs/tests/individual-example-tests/oklab.test.ts @@ -178,11 +178,11 @@ describe('oklab example', () => { let g2 = (((-1.2684380046f * ldt2) + (2.6097574011f * mdt2)) - (0.3413193965f * sdt2)); let u_g = (g1 / ((g1 * g1) - ((0.5f * g) * g2))); var t_g = (-(g) * u_g); - let b_1 = ((((-0.0041960863f * l) - (0.7034186147f * m)) + (1.707614701f * s)) - 1f); + let b0 = ((((-0.0041960863f * l) - (0.7034186147f * m)) + (1.707614701f * s)) - 1f); let b1 = (((-0.0041960863f * ldt) - (0.7034186147f * mdt)) + (1.707614701f * sdt)); let b2 = (((-0.0041960863f * ldt2) - (0.7034186147f * mdt2)) + (1.707614701f * sdt2)); - let u_b = (b1 / ((b1 * b1) - ((0.5f * b_1) * b2))); - var t_b = (-(b_1) * u_b); + let u_b = (b1 / ((b1 * b1) - ((0.5f * b0) * b2))); + var t_b = (-(b0) * u_b); t_r = select(FLT_MAX, t_r, (u_r >= 0f)); t_g = select(FLT_MAX, t_g, (u_g >= 0f)); t_b = select(FLT_MAX, t_b, (u_b >= 0f)); diff --git a/env.ts b/env.ts new file mode 100644 index 0000000000..1e66e9134c --- /dev/null +++ b/env.ts @@ -0,0 +1,3 @@ +export const TEST_BUILT_CODE = process.env.TEST_BUILT_CODE + ? { true: true, false: false }[process.env.TEST_BUILT_CODE] + : undefined; diff --git a/package.json b/package.json index 9dd5762786..b032ce13ba 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "dev": "DEV=true pnpm run --filter typegpu-docs dev", "dev:host": "DEV=true pnpm run --filter typegpu-docs dev --host --mode https", "fix": "oxlint -c oxlint.config.ts --fix && oxfmt", - "test": "pnpm run test:types && pnpm run test:style && pnpm run test:unit-and-attest && pnpm run test:circular-deps", + "test": "pnpm -r --filter=!typegpu-docs run build && pnpm run test:types && pnpm run test:style && TEST_BUILT_CODE=true pnpm run test:unit-and-attest && pnpm run test:circular-deps", "test:circular-deps": "pnpm dpdm -T --exit-code circular:1 packages/**/src/index.ts packages/**/src/index.js !packages/**/node_modules", "test:types": "pnpm run --filter typegpu-docs transform-overloads && pnpm run -r --parallel test:types", "test:style": "oxlint -c oxlint.config.ts --max-warnings=0 --type-aware --report-unused-disable-directives && oxfmt --check", diff --git a/packages/typegpu-color/src/oklab.ts b/packages/typegpu-color/src/oklab.ts index f18efcc05d..a6c5203242 100644 --- a/packages/typegpu-color/src/oklab.ts +++ b/packages/typegpu-color/src/oklab.ts @@ -236,12 +236,12 @@ const findGamutIntersection = tgpu.fn( const u_g = g1 / (g1 * g1 - 0.5 * g * g2); let t_g = -g * u_g; - const b = -0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s - 1; + const b0 = -0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s - 1; const b1 = -0.0041960863 * ldt - 0.7034186147 * mdt + 1.707614701 * sdt; const b2 = -0.0041960863 * ldt2 - 0.7034186147 * mdt2 + 1.707614701 * sdt2; - const u_b = b1 / (b1 * b1 - 0.5 * b * b2); - let t_b = -b * u_b; + const u_b = b1 / (b1 * b1 - 0.5 * b0 * b2); + let t_b = -b0 * u_b; t_r = select(FLT_MAX, t_r, u_r >= 0); t_g = select(FLT_MAX, t_g, u_g >= 0); diff --git a/packages/typegpu/tests/accessor.test.ts b/packages/typegpu/tests/accessor.test.ts index 851263eb88..bc425d3ead 100644 --- a/packages/typegpu/tests/accessor.test.ts +++ b/packages/typegpu/tests/accessor.test.ts @@ -1,5 +1,5 @@ import { describe, expect, expectTypeOf } from 'vitest'; -import tgpu, { d, std, type TgpuAccessor } from '../src/index.js'; +import tgpu, { d, std, type TgpuAccessor } from 'typegpu'; import { it } from 'typegpu-testing-utility'; const RED = d.vec3f(1, 0, 0); diff --git a/packages/typegpu/tests/align.test.ts b/packages/typegpu/tests/align.test.ts index 67804585ae..f52ec08222 100644 --- a/packages/typegpu/tests/align.test.ts +++ b/packages/typegpu/tests/align.test.ts @@ -1,5 +1,5 @@ import { describe, expect, expectTypeOf, it } from 'vitest'; -import { d, tgpu } from '../src/index.js'; +import { d, tgpu } from 'typegpu'; describe('d.align', () => { it('adds @align attribute for custom aligned struct members', () => { diff --git a/packages/typegpu/tests/array.test.ts b/packages/typegpu/tests/array.test.ts index 0eb30bbd72..564b94dbd9 100644 --- a/packages/typegpu/tests/array.test.ts +++ b/packages/typegpu/tests/array.test.ts @@ -2,7 +2,7 @@ import { attest } from '@ark/attest'; import { BufferReader, BufferWriter } from 'typed-binary'; import { describe, expect, expectTypeOf, it } from 'vitest'; import { readData, writeData } from '../src/data/dataIO.ts'; -import { d, tgpu } from '../src/index.js'; +import { d, tgpu } from 'typegpu'; import { namespace } from '../src/core/resolve/namespace.ts'; import { resolve } from '../src/resolutionCtx.ts'; import type { Infer } from '../src/shared/repr.ts'; diff --git a/packages/typegpu/tests/attributes.test.ts b/packages/typegpu/tests/attributes.test.ts index 97bf76592c..90ebda9d1b 100644 --- a/packages/typegpu/tests/attributes.test.ts +++ b/packages/typegpu/tests/attributes.test.ts @@ -1,5 +1,5 @@ import { describe, expect, expectTypeOf, it } from 'vitest'; -import { d, tgpu } from '../src/index.js'; +import { d, tgpu } from 'typegpu'; describe('attributes', () => { it('adds attributes in the correct order', () => { diff --git a/packages/typegpu/tests/bindGroupLayout.test.ts b/packages/typegpu/tests/bindGroupLayout.test.ts index b7fe5d5a81..87370af360 100644 --- a/packages/typegpu/tests/bindGroupLayout.test.ts +++ b/packages/typegpu/tests/bindGroupLayout.test.ts @@ -6,7 +6,7 @@ import { type TgpuBuffer, type TgpuTextureView, type UniformFlag, -} from '../src/index.js'; +} from 'typegpu'; import { type ExtractBindGroupInputFromLayout, MissingBindingError, diff --git a/packages/typegpu/tests/buffer.test.ts b/packages/typegpu/tests/buffer.test.ts index f1938683f4..93283f108c 100644 --- a/packages/typegpu/tests/buffer.test.ts +++ b/packages/typegpu/tests/buffer.test.ts @@ -3,7 +3,7 @@ import { describe, expect, expectTypeOf, vi } from 'vitest'; import * as common from '../src/common/index.ts'; import * as d from '../src/data/index.ts'; import { sizeOf } from '../src/data/sizeOf.ts'; -import type { ValidateBufferSchema, ValidUsagesFor } from '../src/index.js'; +import type { ValidateBufferSchema, ValidUsagesFor } from 'typegpu'; import { getName } from '../src/shared/meta.ts'; import type { InferPatch, IsValidBufferSchema, IsValidUniformSchema } from '../src/shared/repr.ts'; import type { TypedArray } from '../src/shared/utilityTypes.ts'; diff --git a/packages/typegpu/tests/bufferShorthands.test.ts b/packages/typegpu/tests/bufferShorthands.test.ts index 7f0301e963..8a8ced6283 100644 --- a/packages/typegpu/tests/bufferShorthands.test.ts +++ b/packages/typegpu/tests/bufferShorthands.test.ts @@ -8,7 +8,7 @@ import type { TgpuReadonly, TgpuUniform, UniformFlag, -} from '../src/index.js'; +} from 'typegpu'; import { attest } from '@ark/attest'; describe('root.createMutable', () => { diff --git a/packages/typegpu/tests/bufferUsage.test.ts b/packages/typegpu/tests/bufferUsage.test.ts index d3ca51e60b..d9afdfaa79 100644 --- a/packages/typegpu/tests/bufferUsage.test.ts +++ b/packages/typegpu/tests/bufferUsage.test.ts @@ -1,6 +1,6 @@ import { describe, expect, expectTypeOf } from 'vitest'; -import { d, tgpu } from '../src/index.js'; +import { d, tgpu } from 'typegpu'; import type { Infer } from '../src/shared/repr.ts'; import { it } from 'typegpu-testing-utility'; diff --git a/packages/typegpu/tests/computePipeline.test.ts b/packages/typegpu/tests/computePipeline.test.ts index 6fadc72872..36d210b128 100644 --- a/packages/typegpu/tests/computePipeline.test.ts +++ b/packages/typegpu/tests/computePipeline.test.ts @@ -1,6 +1,6 @@ import { describe, expect, expectTypeOf, vi } from 'vitest'; import type { TgpuQuerySet } from '../src/core/querySet/querySet.ts'; -import { d, MissingBindGroupsError, tgpu, type TgpuComputePipeline } from '../src/index.js'; +import { d, MissingBindGroupsError, tgpu, type TgpuComputePipeline } from 'typegpu'; import { $internal } from '../src/shared/symbols.ts'; import { it } from 'typegpu-testing-utility'; import { extensionEnabled } from '../src/std/extensions.ts'; diff --git a/packages/typegpu/tests/constant.test.ts b/packages/typegpu/tests/constant.test.ts index 707aa9ef2e..38cfd1ea01 100644 --- a/packages/typegpu/tests/constant.test.ts +++ b/packages/typegpu/tests/constant.test.ts @@ -1,5 +1,5 @@ import { describe, expect, it } from 'vitest'; -import { d, tgpu } from '../src/index.js'; +import { d, tgpu } from 'typegpu'; const Boid = d.struct({ pos: d.vec3f, diff --git a/packages/typegpu/tests/data/atomic.test.ts b/packages/typegpu/tests/data/atomic.test.ts index ba2915993b..76e4286a28 100644 --- a/packages/typegpu/tests/data/atomic.test.ts +++ b/packages/typegpu/tests/data/atomic.test.ts @@ -1,5 +1,5 @@ import { describe, expect, expectTypeOf, it } from 'vitest'; -import * as d from '../../src/data/index.ts'; +import { d } from 'typegpu'; describe('d.atomic', () => { it('creates a u32 atomic schema', () => { diff --git a/packages/typegpu/tests/data/deepEqual.test.ts b/packages/typegpu/tests/data/deepEqual.test.ts index f994e2c9eb..55602a1660 100644 --- a/packages/typegpu/tests/data/deepEqual.test.ts +++ b/packages/typegpu/tests/data/deepEqual.test.ts @@ -21,8 +21,10 @@ import { vec2f, vec2u, vec3f, -} from '../../src/data/index.ts'; -import { ptrPrivate, ptrStorage, ptrWorkgroup } from '../../src/data/ptr.ts'; + ptrPrivate, + ptrStorage, + ptrWorkgroup, +} from 'typegpu/data'; describe('deepEqual', () => { it('compares simple types', () => { diff --git a/packages/typegpu/tests/data/ptr.test.ts b/packages/typegpu/tests/data/ptr.test.ts index 12c9921127..b4228cae37 100644 --- a/packages/typegpu/tests/data/ptr.test.ts +++ b/packages/typegpu/tests/data/ptr.test.ts @@ -1,5 +1,5 @@ import { describe, expect, expectTypeOf, it } from 'vitest'; -import { d, tgpu } from '../../src/index.js'; +import { d, tgpu } from 'typegpu'; describe('d.ptrFn', () => { it('wraps a schema and infers type properly', () => { diff --git a/packages/typegpu/tests/data/schemaCallWrapper.test.ts b/packages/typegpu/tests/data/schemaCallWrapper.test.ts index 6bedaba098..5e7defda4b 100644 --- a/packages/typegpu/tests/data/schemaCallWrapper.test.ts +++ b/packages/typegpu/tests/data/schemaCallWrapper.test.ts @@ -1,5 +1,5 @@ import { describe, expect, it } from 'vitest'; -import * as d from '../../src/data/index.ts'; +import { d } from 'typegpu'; import { schemaCallWrapper } from '../../src/data/schemaCallWrapper.ts'; describe('schemaCallWrapper', () => { diff --git a/packages/typegpu/tests/declare.test.ts b/packages/typegpu/tests/declare.test.ts index a4247ba832..2b08d5c93b 100644 --- a/packages/typegpu/tests/declare.test.ts +++ b/packages/typegpu/tests/declare.test.ts @@ -1,5 +1,5 @@ import { describe, expect, it } from 'vitest'; -import { d, tgpu } from '../src/index.js'; +import { d, tgpu } from 'typegpu'; describe('tgpu.declare', () => { it('should inject provided declaration when resolving a function', () => { diff --git a/packages/typegpu/tests/entryFnBuiltinArgs.test.ts b/packages/typegpu/tests/entryFnBuiltinArgs.test.ts index d064eb9148..da7888a4b0 100644 --- a/packages/typegpu/tests/entryFnBuiltinArgs.test.ts +++ b/packages/typegpu/tests/entryFnBuiltinArgs.test.ts @@ -1,6 +1,6 @@ import { describe, it } from 'vitest'; import * as d from '../src/data/index.ts'; -import tgpu, { type TgpuComputeFn, type TgpuFragmentFn, type TgpuVertexFn } from '../src/index.js'; +import tgpu, { type TgpuComputeFn, type TgpuFragmentFn, type TgpuVertexFn } from 'typegpu'; import { attest } from '@ark/attest'; describe('entry functions accepting only the allowed subset of builtins', () => { diff --git a/packages/typegpu/tests/entryFnHeaderGen.test.ts b/packages/typegpu/tests/entryFnHeaderGen.test.ts index a0b9abfa69..a1fe6757f1 100644 --- a/packages/typegpu/tests/entryFnHeaderGen.test.ts +++ b/packages/typegpu/tests/entryFnHeaderGen.test.ts @@ -1,6 +1,6 @@ import { describe, expect, it } from 'vitest'; import * as d from '../src/data/index.ts'; -import tgpu from '../src/index.js'; +import tgpu from 'typegpu'; describe('autogenerating wgsl headers for tgpu entry functions with raw string WGSL implementations', () => { it('works for fragment entry function with non-decorated non-struct output', () => { diff --git a/packages/typegpu/tests/function.test.ts b/packages/typegpu/tests/function.test.ts index 0940c5045a..0c5892c597 100644 --- a/packages/typegpu/tests/function.test.ts +++ b/packages/typegpu/tests/function.test.ts @@ -3,7 +3,7 @@ import { describe, expect, expectTypeOf, it } from 'vitest'; import type { InferIO, InheritArgNames, IOLayout } from '../src/core/function/fnTypes.ts'; import * as d from '../src/data/index.ts'; import { Void } from '../src/data/wgslTypes.ts'; -import tgpu, { type TgpuFn, type TgpuFnShell } from '../src/index.js'; +import tgpu, { type TgpuFn, type TgpuFnShell } from 'typegpu'; import type { Prettify } from '../src/shared/utilityTypes.ts'; const empty = tgpu.fn([])`() { diff --git a/packages/typegpu/tests/functionTagged.test.ts b/packages/typegpu/tests/functionTagged.test.ts index 6d86b8c85d..8944104f97 100644 --- a/packages/typegpu/tests/functionTagged.test.ts +++ b/packages/typegpu/tests/functionTagged.test.ts @@ -1,6 +1,6 @@ import { describe, expect, it } from 'vitest'; import * as d from '../src/data/index.ts'; -import tgpu from '../src/index.js'; +import tgpu from 'typegpu'; describe('tagged syntax', () => { describe('function', () => { diff --git a/packages/typegpu/tests/indent.test.ts b/packages/typegpu/tests/indent.test.ts index f3e7d4ef7d..4e24f52d8d 100644 --- a/packages/typegpu/tests/indent.test.ts +++ b/packages/typegpu/tests/indent.test.ts @@ -1,5 +1,5 @@ import { describe, expect, it } from 'vitest'; -import tgpu, { d, std } from '../src/index.js'; +import tgpu, { d, std } from 'typegpu'; describe('indents', () => { it('should indent sanely', () => { diff --git a/packages/typegpu/tests/internal/arrayToContainedAttribs.test.ts b/packages/typegpu/tests/internal/arrayToContainedAttribs.test.ts new file mode 100644 index 0000000000..e3e42a6ebc --- /dev/null +++ b/packages/typegpu/tests/internal/arrayToContainedAttribs.test.ts @@ -0,0 +1,69 @@ +import { describe, expectTypeOf, it } from 'vitest'; +import type { d } from '../../src/index.js'; +import type { ArrayToContainedAttribs } from '../../src/core/vertexLayout/vertexAttribute.ts'; +import type { TgpuVertexAttrib } from '../../src/shared/vertexFormat.ts'; + +describe('ArrayToContainedAttribs', () => { + it('processes a loose array of uint8x2', () => { + type Result = ArrayToContainedAttribs>; + + expectTypeOf().toEqualTypeOf>(); + }); + + it('processes a loose array of unorm10-10-10-2', () => { + type Result = ArrayToContainedAttribs>; + + expectTypeOf().toEqualTypeOf>(); + }); + + it('processes an array of u32s', () => { + type Result = ArrayToContainedAttribs>; + + expectTypeOf().toEqualTypeOf>(); + }); + + it('processes a loose array of f32s', () => { + type Result = ArrayToContainedAttribs>; + + expectTypeOf().toEqualTypeOf>(); + }); + + it('processes a loose array of structs', () => { + type Result = ArrayToContainedAttribs>>; + + expectTypeOf().toEqualTypeOf<{ + a: TgpuVertexAttrib<'float32'>; + b: TgpuVertexAttrib<'float32'>; + }>(); + }); + + it('processes a loose array of loose struct', () => { + type Result = ArrayToContainedAttribs>>; + + expectTypeOf().toEqualTypeOf<{ + a: TgpuVertexAttrib<'float32'>; + b: TgpuVertexAttrib<'float32'>; + }>(); + }); + + it('processes an array of structs', () => { + type Result = ArrayToContainedAttribs>>; + + expectTypeOf().toEqualTypeOf<{ + a: TgpuVertexAttrib<'float32'>; + b: TgpuVertexAttrib<'float32'>; + }>(); + }); + + it('processes an array of f16s', () => { + type Result = ArrayToContainedAttribs>; + + expectTypeOf().toEqualTypeOf>(); + }); + + it('processes a loose array of snorm16x2', () => { + type Result = ArrayToContainedAttribs>; + + expectTypeOf().toEqualTypeOf>(); + }); +}); diff --git a/packages/typegpu/tests/unplugin/autoname.test.ts b/packages/typegpu/tests/internal/autoname.test.ts similarity index 99% rename from packages/typegpu/tests/unplugin/autoname.test.ts rename to packages/typegpu/tests/internal/autoname.test.ts index 45faa7039b..255fe1db9c 100644 --- a/packages/typegpu/tests/unplugin/autoname.test.ts +++ b/packages/typegpu/tests/internal/autoname.test.ts @@ -1,4 +1,5 @@ import { describe, expect } from 'vitest'; +// Importing directly from source, since we're testing internals import { struct } from '../../src/data/index.ts'; import tgpu, { d, type TgpuBindGroupLayout } from '../../src/index.js'; import { getName } from '../../src/shared/meta.ts'; diff --git a/packages/typegpu/tests/internal/connectAttributesToShader.test.ts b/packages/typegpu/tests/internal/connectAttributesToShader.test.ts new file mode 100644 index 0000000000..6907ef6352 --- /dev/null +++ b/packages/typegpu/tests/internal/connectAttributesToShader.test.ts @@ -0,0 +1,254 @@ +import { expect, describe, it } from 'vitest'; + +import tgpu, { d } from '../../src/index.js'; +import { connectAttributesToShader } from '../../src/core/vertexLayout/connectAttributesToShader.ts'; + +describe('connectAttributesToShader', () => { + it('connects a single f32 attribute', () => { + const shaderInputLayout = d.f32; + const layout = tgpu.vertexLayout(d.arrayOf(d.f32)); + const attrib = layout.attrib; + + expect(connectAttributesToShader(shaderInputLayout, attrib)).toStrictEqual({ + bufferDefinitions: [ + { + arrayStride: 4, + stepMode: 'vertex', + attributes: [ + { + format: 'float32', + offset: 0, + shaderLocation: 0, + }, + ], + }, + ], + usedVertexLayouts: [layout], + }); + }); + + it('connects a single vec4f attribute (with custom shader location)', () => { + const shaderInputLayout = d.location(3, d.vec4f); + const layout = tgpu.vertexLayout((n: number) => d.disarrayOf(d.unorm16x4, n)); + const attrib = layout.attrib; + + expect(connectAttributesToShader(shaderInputLayout, attrib)).toStrictEqual({ + bufferDefinitions: [ + { + arrayStride: 8, + stepMode: 'vertex', + attributes: [ + { + format: 'unorm16x4', + offset: 0, + shaderLocation: 3, + }, + ], + }, + ], + usedVertexLayouts: [layout], + }); + }); + + it('connects a record of attributes from a single layout', () => { + const shaderInputLayout = { + a: d.f32, + b: d.location(3, d.vec2f), + c: d.u32 /* should get @location(4) automatically */, + }; + + const layout = tgpu.vertexLayout((n: number) => + d.disarrayOf( + d.unstruct({ + alpha: d.f32, // 4 bytes + beta: d.unorm8x2, // 2 bytes + gamma: d.u32, // 4 bytes + }), + n, + ), + ); + + const result = connectAttributesToShader(shaderInputLayout, { + // purposefully out of order, which should be controlled by the shader input. + b: layout.attrib.beta, + c: layout.attrib.gamma, + a: layout.attrib.alpha, + }); + + expect(result).toStrictEqual({ + bufferDefinitions: [ + { + arrayStride: 10, + stepMode: 'vertex', + attributes: [ + { + format: 'float32', + offset: 0, + shaderLocation: 0, + }, + { + format: 'unorm8x2', + offset: 4, + shaderLocation: 3, + }, + { + format: 'uint32', + offset: 6, + shaderLocation: 4, + }, + ], + }, + ], + usedVertexLayouts: [layout], + }); + }); + + it('connects a record of attributes from multiple layouts', () => { + const shaderInputLayout = { + vi: d.builtin.vertexIndex, // should be omitted + a: d.f32, + b: d.location(3, d.vec2f), + c: d.u32 /* should get @location(4) automatically */, + }; + + const alphaBetaLayout = tgpu.vertexLayout((n: number) => + d.disarrayOf( + d.unstruct({ + alpha: d.f32, // 4 bytes + beta: d.unorm8x2, // 2 bytes + }), + n, + ), + ); + + const gammaLayout = tgpu.vertexLayout(d.arrayOf(d.u32)); + + const result = connectAttributesToShader(shaderInputLayout, { + // purposefully out of order, which should be controlled by the shader input. + b: alphaBetaLayout.attrib.beta, + c: gammaLayout.attrib, + a: alphaBetaLayout.attrib.alpha, + }); + + expect(result).toStrictEqual({ + bufferDefinitions: [ + { + arrayStride: 6, + stepMode: 'vertex', + attributes: [ + { + format: 'float32', + offset: 0, + shaderLocation: 0, + }, + { + format: 'unorm8x2', + offset: 4, + shaderLocation: 3, + }, + ], + }, + { + arrayStride: 4, + stepMode: 'vertex', + attributes: [ + { + format: 'uint32', + offset: 0, + shaderLocation: 4, + }, + ], + }, + ], + usedVertexLayouts: [alphaBetaLayout, gammaLayout], + }); + }); + + it('connects a single vec4h attribute', () => { + const shaderInputLayout = d.vec4h; + const layout = tgpu.vertexLayout((n: number) => d.disarrayOf(d.float16x4, n)); + const attrib = layout.attrib; + + expect(connectAttributesToShader(shaderInputLayout, attrib)).toStrictEqual({ + bufferDefinitions: [ + { + arrayStride: 8, + stepMode: 'vertex', + attributes: [ + { + format: 'float16x4', + offset: 0, + shaderLocation: 0, + }, + ], + }, + ], + usedVertexLayouts: [layout], + }); + }); + + it('connects a record of attributes from a single layout (with f16 variants)', () => { + const shaderInputLayout = { + a: d.f16, + b: d.location(3, d.vec2h), + c: d.u32 /* should get @location(4) automatically */, + d: d.f32, + }; + + const layout = tgpu.vertexLayout((n: number) => + d.disarrayOf( + d.unstruct({ + alpha: d.f16, // 2 bytes + beta: d.float16x2, // 4 bytes + gamma: d.u32, // 4 bytes + delta: d.float16, // 2 bytes + }), + n, + ), + ); + + const result = connectAttributesToShader(shaderInputLayout, { + // purposefully out of order, which should be controlled by the shader input. + b: layout.attrib.beta, + c: layout.attrib.gamma, + d: layout.attrib.delta, + a: layout.attrib.alpha, + }); + + expect(result).toStrictEqual({ + bufferDefinitions: [ + { + arrayStride: 12, + stepMode: 'vertex', + attributes: [ + { + format: 'float16', + offset: 0, + shaderLocation: 0, + }, + { + format: 'float16x2', + offset: 2, + shaderLocation: 3, + }, + { + format: 'uint32', + offset: 6, + shaderLocation: 4, + }, + { + format: 'float16', + offset: 10, + shaderLocation: 5, + }, + ], + }, + ], + usedVertexLayouts: [layout], + }); + }); + + it('throws when trying to use type that has no attribute representation', () => { + expect(() => tgpu.vertexLayout(d.disarrayOf(d.vec3h))).toThrow(); + }); +}); diff --git a/packages/typegpu/tests/tgsl/conversion.test.ts b/packages/typegpu/tests/internal/conversion.test.ts similarity index 99% rename from packages/typegpu/tests/tgsl/conversion.test.ts rename to packages/typegpu/tests/internal/conversion.test.ts index d1836a9bd7..f1e911ca6a 100644 --- a/packages/typegpu/tests/tgsl/conversion.test.ts +++ b/packages/typegpu/tests/internal/conversion.test.ts @@ -1,4 +1,5 @@ import { afterAll, beforeAll, describe, expect } from 'vitest'; +// Importing directly from source, since we're testing internals import { abstractFloat, abstractInt } from '../../src/data/numeric.ts'; import * as d from '../../src/data/index.ts'; import { snip, type Snippet } from '../../src/data/snippet.ts'; diff --git a/packages/typegpu/tests/internal/deserializeAndStringify.test.ts b/packages/typegpu/tests/internal/deserializeAndStringify.test.ts new file mode 100644 index 0000000000..77318ffb1c --- /dev/null +++ b/packages/typegpu/tests/internal/deserializeAndStringify.test.ts @@ -0,0 +1,133 @@ +import { describe, expect } from 'vitest'; +// Importing directly from source, since we're testing internals +import { deserializeAndStringify } from '../../src/tgsl/consoleLog/deserializers.ts'; +import { d } from '../../src/index.js'; +import { it } from 'typegpu-testing-utility'; + +describe('deserializeAndStringify', () => { + it('works for string literals', () => { + const data = new Uint32Array([]); + const logInfo: (string | d.AnyWgslData)[] = ['String literal']; + + expect(deserializeAndStringify(data, logInfo)).toMatchInlineSnapshot( + ` + [ + "String literal", + ] + `, + ); + }); + + it('works for u32', () => { + const data = new Uint32Array([123]); + const logInfo: (string | d.AnyWgslData)[] = [d.u32]; + + expect(deserializeAndStringify(data, logInfo)).toMatchInlineSnapshot( + ` + [ + "123", + ] + `, + ); + }); + + it('works for vec3u', () => { + const data = new Uint32Array([1, 2, 3]); + const logInfo: (string | d.AnyWgslData)[] = [d.vec3u]; + + expect(deserializeAndStringify(data, logInfo)).toMatchInlineSnapshot( + ` + [ + "vec3u(1, 2, 3)", + ] + `, + ); + }); + + it('works for clumped vectors', () => { + const data = new Uint32Array([1, 2, 3, 4, 5, 6]); // no alignment + const logInfo: (string | d.AnyWgslData)[] = [d.vec3u, d.vec3u]; + + expect(deserializeAndStringify(data, logInfo)).toMatchInlineSnapshot( + ` + [ + "vec3u(1, 2, 3)", + "vec3u(4, 5, 6)", + ] + `, + ); + }); + + it('works for multiple arguments', () => { + const data = new Uint32Array([1, 2, 3, 456]); + const logInfo: (string | d.AnyWgslData)[] = ['GID:', d.vec3u, 'Result:', d.u32]; + + expect(deserializeAndStringify(data, logInfo)).toMatchInlineSnapshot( + ` + [ + "GID:", + "vec3u(1, 2, 3)", + "Result:", + "456", + ] + `, + ); + }); + + it('works for arrays', () => { + const data = new Uint32Array([1, 2, 3, 4]); + const logInfo: (string | d.AnyWgslData)[] = [d.arrayOf(d.u32, 4)]; + + expect(deserializeAndStringify(data, logInfo)).toMatchInlineSnapshot( + ` + [ + "[1, 2, 3, 4]", + ] + `, + ); + }); + + it('works for nested arrays', () => { + const data = new Uint32Array([1, 2, 3, 4]); + const logInfo: (string | d.AnyWgslData)[] = [d.arrayOf(d.arrayOf(d.u32, 2), 2)]; + + expect(deserializeAndStringify(data, logInfo)).toMatchInlineSnapshot( + ` + [ + "[[1, 2], [3, 4]]", + ] + `, + ); + }); + + it('works for structs', () => { + const data = new Uint32Array([1, 2, 3, 4]); + const logInfo: (string | d.AnyWgslData)[] = [d.struct({ vec: d.vec3u, num: d.u32 })]; + + expect(deserializeAndStringify(data, logInfo)).toMatchInlineSnapshot( + ` + [ + "{ vec: vec3u(1, 2, 3), num: 4 }", + ] + `, + ); + }); + + it('works for nested structs', () => { + const data = new Uint32Array([1, 2, 3, 4, 1]); + const logInfo: (string | d.AnyWgslData)[] = [ + d.struct({ + nested: d.struct({ vec: d.vec3u, num: d.u32 }), + bool: d.bool, + }), + ]; + + expect(deserializeAndStringify(data, logInfo)).toMatchInlineSnapshot( + ` + [ + "{ nested: { vec: vec3u(1, 2, 3), num: 4 }, bool: true }", + ] + `, + ); + }); +}); diff --git a/packages/typegpu/tests/tgsl/dualImpl.test.ts b/packages/typegpu/tests/internal/dualImpl.test.ts similarity index 98% rename from packages/typegpu/tests/tgsl/dualImpl.test.ts rename to packages/typegpu/tests/internal/dualImpl.test.ts index 758b14befb..5dba380984 100644 --- a/packages/typegpu/tests/tgsl/dualImpl.test.ts +++ b/packages/typegpu/tests/internal/dualImpl.test.ts @@ -1,4 +1,5 @@ import { describe, expect, it } from 'vitest'; +// Importing directly from source, since we're testing internals import { dualImpl, MissingCpuImplError } from '../../src/core/function/dualImpl.ts'; import { Void } from '../../src/data/wgslTypes.ts'; import tgpu from '../../src/index.js'; diff --git a/packages/typegpu/tests/tgsl/generationHelpers.test.ts b/packages/typegpu/tests/internal/generationHelpers.test.ts similarity index 99% rename from packages/typegpu/tests/tgsl/generationHelpers.test.ts rename to packages/typegpu/tests/internal/generationHelpers.test.ts index 9a51b702c3..0a7b32c961 100644 --- a/packages/typegpu/tests/tgsl/generationHelpers.test.ts +++ b/packages/typegpu/tests/internal/generationHelpers.test.ts @@ -1,4 +1,5 @@ import { afterEach, beforeEach, describe, expect, it } from 'vitest'; +// Importing directly from source, since we're testing internals import { arrayOf } from '../../src/data/array.ts'; import { mat2x2f, mat3x3f, mat4x4f } from '../../src/data/matrix.ts'; import { abstractFloat, abstractInt, bool, f16, f32, i32, u32 } from '../../src/data/numeric.ts'; diff --git a/packages/typegpu/tests/gpuValueOf.test.ts b/packages/typegpu/tests/internal/gpuValueOf.test.ts similarity index 86% rename from packages/typegpu/tests/gpuValueOf.test.ts rename to packages/typegpu/tests/internal/gpuValueOf.test.ts index 9c4a87abc3..b677e75322 100644 --- a/packages/typegpu/tests/gpuValueOf.test.ts +++ b/packages/typegpu/tests/internal/gpuValueOf.test.ts @@ -1,7 +1,6 @@ import { describe, expectTypeOf } from 'vitest'; -import * as d from '../src/data/index.ts'; -import tgpu from '../src/index.js'; -import type { GPUValueOf } from '../src/shared/repr.ts'; +import tgpu, { d } from '../../src/index.js'; +import type { GPUValueOf } from '../../src/shared/repr.ts'; import { it } from 'typegpu-testing-utility'; describe('GPUValueOf', () => { diff --git a/packages/typegpu/tests/tgsl/wgslGenerator.test.ts b/packages/typegpu/tests/internal/wgslGenerator.test.ts similarity index 99% rename from packages/typegpu/tests/tgsl/wgslGenerator.test.ts rename to packages/typegpu/tests/internal/wgslGenerator.test.ts index 43f7b6ce77..c38ca16601 100644 --- a/packages/typegpu/tests/tgsl/wgslGenerator.test.ts +++ b/packages/typegpu/tests/internal/wgslGenerator.test.ts @@ -1,5 +1,5 @@ import * as tinyest from 'tinyest'; -import { beforeEach, describe, expect, vi } from 'vitest'; +import { beforeEach, describe, expect } from 'vitest'; import { namespace } from '../../src/core/resolve/namespace.ts'; import * as d from '../../src/data/index.ts'; import { abstractFloat, abstractInt } from '../../src/data/numeric.ts'; diff --git a/packages/typegpu/tests/invariant.test.ts b/packages/typegpu/tests/invariant.test.ts index 2a83ef94dc..e87613ba33 100644 --- a/packages/typegpu/tests/invariant.test.ts +++ b/packages/typegpu/tests/invariant.test.ts @@ -1,5 +1,5 @@ import { describe, expect, it } from 'vitest'; -import tgpu, { d } from '../src/index.js'; +import tgpu, { d } from 'typegpu'; describe('invariant', () => { it('adds @invariant attribute to position builtin', () => { diff --git a/packages/typegpu/tests/jsMath.test.ts b/packages/typegpu/tests/jsMath.test.ts index a0f08e0410..724033bcee 100644 --- a/packages/typegpu/tests/jsMath.test.ts +++ b/packages/typegpu/tests/jsMath.test.ts @@ -1,5 +1,5 @@ import { describe, expect, it } from 'vitest'; -import tgpu, { d } from '../src/index.js'; +import tgpu, { d } from 'typegpu'; describe('Math', () => { it('allows using Math.PI', () => { diff --git a/packages/typegpu/tests/lazy.test.ts b/packages/typegpu/tests/lazy.test.ts index 5058c537e2..4e0a209bbd 100644 --- a/packages/typegpu/tests/lazy.test.ts +++ b/packages/typegpu/tests/lazy.test.ts @@ -1,6 +1,6 @@ import { describe, expect, expectTypeOf, vi } from 'vitest'; import * as d from '../src/data/index.ts'; -import tgpu, { type TgpuLazy } from '../src/index.js'; +import tgpu, { type TgpuLazy } from 'typegpu'; import { mul } from '../src/std/index.ts'; import { it } from 'typegpu-testing-utility'; diff --git a/packages/typegpu/tests/limitsOverflow.test.ts b/packages/typegpu/tests/limitsOverflow.test.ts index f0630e8ee5..cf3a31897f 100644 --- a/packages/typegpu/tests/limitsOverflow.test.ts +++ b/packages/typegpu/tests/limitsOverflow.test.ts @@ -1,6 +1,6 @@ import { describe, expect, vi } from 'vitest'; import { it } from 'typegpu-testing-utility'; -import tgpu, { d } from '../src/index.js'; +import tgpu, { d } from 'typegpu'; import { warnIfOverflow } from '../src/core/pipeline/limitsOverflow.ts'; describe('warnIfOverflow', () => { diff --git a/packages/typegpu/tests/matrix.test.ts b/packages/typegpu/tests/matrix.test.ts index 989f6f4c8f..3d20449e6b 100644 --- a/packages/typegpu/tests/matrix.test.ts +++ b/packages/typegpu/tests/matrix.test.ts @@ -1,6 +1,6 @@ import { BufferReader, BufferWriter } from 'typed-binary'; import { describe, expect, expectTypeOf, it } from 'vitest'; -import tgpu, { d } from '../src/index.js'; +import tgpu, { d } from 'typegpu'; import { readData, writeData } from '../src/data/dataIO.ts'; import { isCloseTo } from '../src/std/index.ts'; diff --git a/packages/typegpu/tests/namespace.test.ts b/packages/typegpu/tests/namespace.test.ts index ee6fe33099..aa9a6f53f4 100644 --- a/packages/typegpu/tests/namespace.test.ts +++ b/packages/typegpu/tests/namespace.test.ts @@ -1,5 +1,5 @@ import { describe, expect, vi } from 'vitest'; -import tgpu, { d } from '../src/index.js'; +import tgpu, { d } from 'typegpu'; import { it } from 'typegpu-testing-utility'; describe('tgpu.namespace', () => { diff --git a/packages/typegpu/tests/numeric.test.ts b/packages/typegpu/tests/numeric.test.ts index 71c66278ee..1350ac3f4f 100644 --- a/packages/typegpu/tests/numeric.test.ts +++ b/packages/typegpu/tests/numeric.test.ts @@ -1,5 +1,5 @@ import { describe, expect, it } from 'vitest'; -import tgpu, { d } from '../src/index.js'; +import tgpu, { d } from 'typegpu'; describe('f32', () => { it('differs in type from other numeric schemas', () => { diff --git a/packages/typegpu/tests/offsetUtils.test.ts b/packages/typegpu/tests/offsetUtils.test.ts index 96c2409d5f..4efc6a961d 100644 --- a/packages/typegpu/tests/offsetUtils.test.ts +++ b/packages/typegpu/tests/offsetUtils.test.ts @@ -1,5 +1,5 @@ import { describe, expect, it } from 'vitest'; -import { d } from '../src/index.js'; +import { d } from 'typegpu'; import { sizeOf } from '../src/data/sizeOf.ts'; describe('d.memoryLayoutOf (default)', () => { diff --git a/packages/typegpu/tests/pipeline-resolution.test.ts b/packages/typegpu/tests/pipeline-resolution.test.ts index 3d5272ae8f..9f92bb0b3a 100644 --- a/packages/typegpu/tests/pipeline-resolution.test.ts +++ b/packages/typegpu/tests/pipeline-resolution.test.ts @@ -1,5 +1,5 @@ import { describe, expect } from 'vitest'; -import tgpu, { d } from '../src/index.js'; +import tgpu, { d } from 'typegpu'; import { it } from 'typegpu-testing-utility'; describe('resolve', () => { diff --git a/packages/typegpu/tests/rawFn.test.ts b/packages/typegpu/tests/rawFn.test.ts index b63036de3b..9faa28ea29 100644 --- a/packages/typegpu/tests/rawFn.test.ts +++ b/packages/typegpu/tests/rawFn.test.ts @@ -1,5 +1,5 @@ import { describe, expect, it } from 'vitest'; -import tgpu, { d } from '../src/index.js'; +import tgpu, { d } from 'typegpu'; import { getName } from '../src/shared/meta.ts'; describe('tgpu.fn with raw string WGSL implementation', () => { diff --git a/packages/typegpu/tests/ref.test.ts b/packages/typegpu/tests/ref.test.ts index 4eb9f5b1b4..198686486c 100644 --- a/packages/typegpu/tests/ref.test.ts +++ b/packages/typegpu/tests/ref.test.ts @@ -1,4 +1,4 @@ -import tgpu, { d } from '../src/index.js'; +import tgpu, { d } from 'typegpu'; import { describe, expect } from 'vitest'; import { it } from 'typegpu-testing-utility'; diff --git a/packages/typegpu/tests/renderPipeline.test.ts b/packages/typegpu/tests/renderPipeline.test.ts index be0c2888e4..db4f0b5a7e 100644 --- a/packages/typegpu/tests/renderPipeline.test.ts +++ b/packages/typegpu/tests/renderPipeline.test.ts @@ -11,7 +11,7 @@ import tgpu, { type TgpuRenderPipeline, type TgpuVertexFn, type TgpuVertexFnShell, -} from '../src/index.js'; +} from 'typegpu'; import { $internal } from '../src/shared/symbols.ts'; import { it } from 'typegpu-testing-utility'; diff --git a/packages/typegpu/tests/resolve.test.ts b/packages/typegpu/tests/resolve.test.ts index 254730def2..17427294f8 100644 --- a/packages/typegpu/tests/resolve.test.ts +++ b/packages/typegpu/tests/resolve.test.ts @@ -1,5 +1,5 @@ import { describe, expect, vi } from 'vitest'; -import tgpu, { d } from '../src/index.js'; +import tgpu, { d } from 'typegpu'; import { setName } from '../src/shared/meta.ts'; import { $gpuValueOf, $internal, $ownSnippet, $resolve } from '../src/shared/symbols.ts'; import type { ResolutionCtx } from '../src/types.ts'; diff --git a/packages/typegpu/tests/root.test.ts b/packages/typegpu/tests/root.test.ts index 525e9a0007..cce511a092 100644 --- a/packages/typegpu/tests/root.test.ts +++ b/packages/typegpu/tests/root.test.ts @@ -1,6 +1,6 @@ import { describe, expect, vi } from 'vitest'; import { Void } from '../src/data/wgslTypes.ts'; -import tgpu, { d } from '../src/index.js'; +import tgpu, { d } from 'typegpu'; import { it } from 'typegpu-testing-utility'; describe('TgpuRoot', () => { diff --git a/packages/typegpu/tests/simulate.test.ts b/packages/typegpu/tests/simulate.test.ts index b3310f1f71..492f6a99ad 100644 --- a/packages/typegpu/tests/simulate.test.ts +++ b/packages/typegpu/tests/simulate.test.ts @@ -1,5 +1,5 @@ import { describe, expect } from 'vitest'; -import tgpu, { d } from '../src/index.js'; +import tgpu, { d } from 'typegpu'; import { it } from 'typegpu-testing-utility'; describe('tgpu.simulate()', () => { diff --git a/packages/typegpu/tests/slot.test.ts b/packages/typegpu/tests/slot.test.ts index 8f1fd76175..d2032ff0ac 100644 --- a/packages/typegpu/tests/slot.test.ts +++ b/packages/typegpu/tests/slot.test.ts @@ -1,5 +1,5 @@ import { describe, expect } from 'vitest'; -import tgpu, { d, std } from '../src/index.js'; +import tgpu, { d, std } from 'typegpu'; import { it } from 'typegpu-testing-utility'; import { getName } from '../src/shared/meta.ts'; diff --git a/packages/typegpu/tests/std/bitcast.test.ts b/packages/typegpu/tests/std/bitcast.test.ts index dabcd382a4..948964b270 100644 --- a/packages/typegpu/tests/std/bitcast.test.ts +++ b/packages/typegpu/tests/std/bitcast.test.ts @@ -1,16 +1,6 @@ import { describe, expect, it } from 'vitest'; -import { - vec2f, - vec2i, - vec2u, - vec3f, - vec3i, - vec3u, - vec4f, - vec4i, - vec4u, -} from '../../src/data/vector.ts'; -import tgpu, { d, std } from '../../src/index.js'; +import { vec2f, vec2i, vec2u, vec3f, vec3i, vec3u, vec4f, vec4i, vec4u } from 'typegpu/data'; +import tgpu, { d, std } from 'typegpu'; describe('bitcast', () => { it('bitcastU32toF32', () => { diff --git a/packages/typegpu/tests/std/boolean/not.test.ts b/packages/typegpu/tests/std/boolean/not.test.ts index 930c405ccd..00438326a3 100644 --- a/packages/typegpu/tests/std/boolean/not.test.ts +++ b/packages/typegpu/tests/std/boolean/not.test.ts @@ -1,7 +1,7 @@ import { describe, expect } from 'vitest'; import { it } from 'typegpu-testing-utility'; -import { not } from '../../../src/std/boolean.ts'; -import tgpu, { d, std } from '../../../src/index.js'; +import { not } from 'typegpu/std'; +import tgpu, { d, std } from 'typegpu'; describe('not', () => { it('negates booleans', () => { diff --git a/packages/typegpu/tests/std/boolean/select.test.ts b/packages/typegpu/tests/std/boolean/select.test.ts index 3c1bdc908a..97963c4613 100644 --- a/packages/typegpu/tests/std/boolean/select.test.ts +++ b/packages/typegpu/tests/std/boolean/select.test.ts @@ -1,5 +1,5 @@ import { describe, expect, it } from 'vitest'; -import tgpu, { d } from '../../../src/index.js'; +import tgpu, { d } from 'typegpu'; import { vec2b, vec2f, @@ -16,8 +16,8 @@ import { vec4h, vec4i, vec4u, -} from '../../../src/data/index.ts'; -import { select } from '../../../src/std/boolean.ts'; +} from 'typegpu/data'; +import { select } from 'typegpu/std'; describe('select', () => { it('selects for numbers', () => { diff --git a/packages/typegpu/tests/std/matrix/rotate.test.ts b/packages/typegpu/tests/std/matrix/rotate.test.ts index 191aa4d3ab..56d68a01ae 100644 --- a/packages/typegpu/tests/std/matrix/rotate.test.ts +++ b/packages/typegpu/tests/std/matrix/rotate.test.ts @@ -1,8 +1,7 @@ import { describe, expect, it } from 'vitest'; -import { mat4x4f, vec4f } from '../../../src/data/index.ts'; -import tgpu from '../../../src/index.js'; -import { isCloseTo, mul } from '../../../src/std/index.ts'; -import { rotateX4, rotateY4, rotateZ4 } from '../../../src/std/matrix.ts'; +import tgpu from 'typegpu'; +import { mat4x4f, vec4f } from 'typegpu/data'; +import { isCloseTo, mul, rotateX4, rotateY4, rotateZ4 } from 'typegpu/std'; describe('rotate', () => { it('generates correct WGSL for rotateX4 with custom matrix', () => { diff --git a/packages/typegpu/tests/std/matrix/scale.test.ts b/packages/typegpu/tests/std/matrix/scale.test.ts index 89907e7ec8..123068c10c 100644 --- a/packages/typegpu/tests/std/matrix/scale.test.ts +++ b/packages/typegpu/tests/std/matrix/scale.test.ts @@ -1,7 +1,7 @@ import { describe, expect, it } from 'vitest'; -import { mat4x4f, vec3f, vec4f } from '../../../src/data/index.ts'; -import tgpu from '../../../src/index.js'; -import { isCloseTo, mul, scale4, translate4 } from '../../../src/std/index.ts'; +import { mat4x4f, vec3f, vec4f } from 'typegpu/data'; +import tgpu from 'typegpu'; +import { isCloseTo, mul, scale4, translate4 } from 'typegpu/std'; describe('scale', () => { it('scales a matrix by a vec3f vector', () => { diff --git a/packages/typegpu/tests/std/matrix/translate.test.ts b/packages/typegpu/tests/std/matrix/translate.test.ts index 20b3998551..dfd2e0c2de 100644 --- a/packages/typegpu/tests/std/matrix/translate.test.ts +++ b/packages/typegpu/tests/std/matrix/translate.test.ts @@ -1,7 +1,7 @@ import { describe, expect, it } from 'vitest'; -import { mat4x4f, vec3f, vec4f } from '../../../src/data/index.ts'; -import tgpu from '../../../src/index.js'; -import { isCloseTo, mul, scale4, translate4 } from '../../../src/std/index.ts'; +import tgpu from 'typegpu'; +import { mat4x4f, vec3f, vec4f } from 'typegpu/data'; +import { isCloseTo, mul, scale4, translate4 } from 'typegpu/std'; describe('translate', () => { it('translates a matrix by a vec3f vector', () => { diff --git a/packages/typegpu/tests/std/numeric/acos.test.ts b/packages/typegpu/tests/std/numeric/acos.test.ts index 0b08a76027..dc17ce2366 100644 --- a/packages/typegpu/tests/std/numeric/acos.test.ts +++ b/packages/typegpu/tests/std/numeric/acos.test.ts @@ -1,6 +1,6 @@ import { describe, expect, it } from 'vitest'; -import { vec3f } from '../../../src/data/index.ts'; -import { acos, isCloseTo } from '../../../src/std/index.ts'; +import { vec3f } from 'typegpu/data'; +import { acos, isCloseTo } from 'typegpu/std'; describe('acos', () => { it('computes acos of numeric value', () => { diff --git a/packages/typegpu/tests/std/numeric/acosh.test.ts b/packages/typegpu/tests/std/numeric/acosh.test.ts index 7a052fe858..b99913137f 100644 --- a/packages/typegpu/tests/std/numeric/acosh.test.ts +++ b/packages/typegpu/tests/std/numeric/acosh.test.ts @@ -1,6 +1,6 @@ import { describe, expect, it } from 'vitest'; -import { vec2f, vec3f, vec4f } from '../../../src/data/index.ts'; -import { acosh, isCloseTo } from '../../../src/std/index.ts'; +import { vec2f, vec3f, vec4f } from 'typegpu/data'; +import { acosh, isCloseTo } from 'typegpu/std'; describe('acosh', () => { it('computes acosh of a number', () => { diff --git a/packages/typegpu/tests/std/numeric/add.test.ts b/packages/typegpu/tests/std/numeric/add.test.ts index d8f64b17ea..473b05e21c 100644 --- a/packages/typegpu/tests/std/numeric/add.test.ts +++ b/packages/typegpu/tests/std/numeric/add.test.ts @@ -1,5 +1,5 @@ import { describe, expect, expectTypeOf, it } from 'vitest'; -import type { m3x3f, v2f, v3f, v4f } from '../../../src/data/index.ts'; +import type { m3x3f, v2f, v3f, v4f } from 'typegpu/data'; import { mat2x2f, mat3x3f, @@ -13,10 +13,9 @@ import { vec4f, vec4i, vec4u, -} from '../../../src/data/index.ts'; -import { add } from '../../../src/std/index.ts'; +} from 'typegpu/data'; +import { add } from 'typegpu/std'; import { expectDataTypeOf } from '../../utils/parseResolved.ts'; -import { abstractFloat, abstractInt } from '../../../src/data/numeric.ts'; describe('add', () => { it('computes sum of two vec2f', () => { @@ -122,10 +121,10 @@ describe('add', () => { return 1 + 2.3; }; - expectDataTypeOf(int_int).toBe(abstractInt); - expectDataTypeOf(float_float).toBe(abstractFloat); - expectDataTypeOf(int_float).toBe(abstractFloat); - expectDataTypeOf(float_int).toBe(abstractFloat); + expectDataTypeOf(int_int).toMatchObject({ type: 'abstractInt' }); + expectDataTypeOf(float_float).toMatchObject({ type: 'abstractFloat' }); + expectDataTypeOf(int_float).toMatchObject({ type: 'abstractFloat' }); + expectDataTypeOf(float_int).toMatchObject({ type: 'abstractFloat' }); }); }); }); diff --git a/packages/typegpu/tests/std/numeric/asin.test.ts b/packages/typegpu/tests/std/numeric/asin.test.ts index f2647c0502..7e88b4eb4a 100644 --- a/packages/typegpu/tests/std/numeric/asin.test.ts +++ b/packages/typegpu/tests/std/numeric/asin.test.ts @@ -1,6 +1,6 @@ import { describe, expect, it } from 'vitest'; -import { vec3f } from '../../../src/data/index.ts'; -import { asin, isCloseTo } from '../../../src/std/index.ts'; +import { vec3f } from 'typegpu/data'; +import { asin, isCloseTo } from 'typegpu/std'; describe('asin', () => { it('computes asin of numeric value', () => { diff --git a/packages/typegpu/tests/std/numeric/atan2.test.ts b/packages/typegpu/tests/std/numeric/atan2.test.ts index fd28aa7fd4..11cbc60a5a 100644 --- a/packages/typegpu/tests/std/numeric/atan2.test.ts +++ b/packages/typegpu/tests/std/numeric/atan2.test.ts @@ -1,6 +1,6 @@ import { describe, expect, it } from 'vitest'; -import { vec4f } from '../../../src/data/index.ts'; -import { atan2, isCloseTo } from '../../../src/std/index.ts'; +import { vec4f } from 'typegpu/data'; +import { atan2, isCloseTo } from 'typegpu/std'; describe('atan2', () => { it('computes atan2 of two values', () => { diff --git a/packages/typegpu/tests/std/numeric/bitShift.test.ts b/packages/typegpu/tests/std/numeric/bitShift.test.ts index ce87d830c6..11ab246b9d 100644 --- a/packages/typegpu/tests/std/numeric/bitShift.test.ts +++ b/packages/typegpu/tests/std/numeric/bitShift.test.ts @@ -1,7 +1,7 @@ -import { describe, expect, it, vi } from 'vitest'; -import { u32, i32, vec3f, vec3i, vec3u, f32, vec2u } from '../../../src/data/index.ts'; -import { bitShiftLeft, bitShiftRight } from '../../../src/std/index.ts'; -import tgpu from '../../../src/index.js'; +import { describe, expect, it } from 'vitest'; +import { u32, i32, vec3f, vec3i, vec3u, f32, vec2u } from 'typegpu/data'; +import { bitShiftLeft, bitShiftRight } from 'typegpu/std'; +import tgpu from 'typegpu'; describe('bit shift', () => { it('casts rhs to u32', () => { diff --git a/packages/typegpu/tests/std/numeric/cosh.test.ts b/packages/typegpu/tests/std/numeric/cosh.test.ts index 38a2aa6e1e..ea2fd141d1 100644 --- a/packages/typegpu/tests/std/numeric/cosh.test.ts +++ b/packages/typegpu/tests/std/numeric/cosh.test.ts @@ -1,6 +1,6 @@ import { describe, expect, it } from 'vitest'; -import { vec2f, vec3f, vec4f } from '../../../src/data/index.ts'; -import { cosh, isCloseTo } from '../../../src/std/index.ts'; +import { vec2f, vec3f, vec4f } from 'typegpu/data'; +import { cosh, isCloseTo } from 'typegpu/std'; describe('cosh', () => { it('computes cosh of a number', () => { diff --git a/packages/typegpu/tests/std/numeric/cross.test.ts b/packages/typegpu/tests/std/numeric/cross.test.ts index 0e469653e6..a1fa2d8ed0 100644 --- a/packages/typegpu/tests/std/numeric/cross.test.ts +++ b/packages/typegpu/tests/std/numeric/cross.test.ts @@ -1,6 +1,6 @@ import { describe, expect, it } from 'vitest'; -import { vec3f, vec3h } from '../../../src/data/index.ts'; -import { cross } from '../../../src/std/index.ts'; +import { vec3f, vec3h } from 'typegpu/data'; +import { cross } from 'typegpu/std'; describe('cross', () => { it('computes cross product of two vec3f', () => { diff --git a/packages/typegpu/tests/std/numeric/distance.test.ts b/packages/typegpu/tests/std/numeric/distance.test.ts index b4a9be2c93..c20c4c1d41 100644 --- a/packages/typegpu/tests/std/numeric/distance.test.ts +++ b/packages/typegpu/tests/std/numeric/distance.test.ts @@ -1,6 +1,6 @@ import { describe, expect, it } from 'vitest'; -import { vec2f, vec3h } from '../../../src/data/index.ts'; -import { distance } from '../../../src/std/index.ts'; +import { vec2f, vec3h } from 'typegpu/data'; +import { distance } from 'typegpu/std'; describe('distance', () => { it('computes distance between two points', () => { diff --git a/packages/typegpu/tests/std/numeric/div.test.ts b/packages/typegpu/tests/std/numeric/div.test.ts index 072f6037e7..1ac394e700 100644 --- a/packages/typegpu/tests/std/numeric/div.test.ts +++ b/packages/typegpu/tests/std/numeric/div.test.ts @@ -1,6 +1,6 @@ import { describe, expect, expectTypeOf, it } from 'vitest'; -import tgpu, { d } from '../../../src/index.js'; -import { div, isCloseTo } from '../../../src/std/index.ts'; +import tgpu, { d } from 'typegpu'; +import { div, isCloseTo } from 'typegpu/std'; describe('div', () => { it('divides numbers just like js would', () => { diff --git a/packages/typegpu/tests/std/numeric/dot.test.ts b/packages/typegpu/tests/std/numeric/dot.test.ts index 0eedba51ab..0a646df32b 100644 --- a/packages/typegpu/tests/std/numeric/dot.test.ts +++ b/packages/typegpu/tests/std/numeric/dot.test.ts @@ -1,6 +1,6 @@ import { describe, expect, it } from 'vitest'; -import { vec2f, vec3f } from '../../../src/data/index.ts'; -import { dot } from '../../../src/std/index.ts'; +import { vec2f, vec3f } from 'typegpu/data'; +import { dot } from 'typegpu/std'; describe('dot', () => { it('computes dot product of two vec2f', () => { diff --git a/packages/typegpu/tests/std/numeric/exp2.test.ts b/packages/typegpu/tests/std/numeric/exp2.test.ts index d6f05134df..7c3f72f751 100644 --- a/packages/typegpu/tests/std/numeric/exp2.test.ts +++ b/packages/typegpu/tests/std/numeric/exp2.test.ts @@ -1,7 +1,6 @@ import { describe, expect, it } from 'vitest'; -import { vec2f, vec2h, vec3f, vec3h, vec4f, vec4h } from '../../../src/data/index.ts'; -import { isCloseTo } from '../../../src/std/index.ts'; -import { exp2 } from '../../../src/std/numeric.ts'; +import { vec2f, vec2h, vec3f, vec3h, vec4f, vec4h } from 'typegpu/data'; +import { isCloseTo, exp2 } from 'typegpu/std'; describe('exp2', () => { it('computes exp2 of a number', () => { diff --git a/packages/typegpu/tests/std/numeric/fract.test.ts b/packages/typegpu/tests/std/numeric/fract.test.ts index 8284286b85..c90aeb8e2a 100644 --- a/packages/typegpu/tests/std/numeric/fract.test.ts +++ b/packages/typegpu/tests/std/numeric/fract.test.ts @@ -1,5 +1,5 @@ import { describe, expect, it } from 'vitest'; -import { fract } from '../../../src/std/index.ts'; +import { fract } from 'typegpu/std'; describe('fract', () => { it('computes fractional part of a number', () => { diff --git a/packages/typegpu/tests/std/numeric/frexp.test.ts b/packages/typegpu/tests/std/numeric/frexp.test.ts index c35590d698..9949a83f7b 100644 --- a/packages/typegpu/tests/std/numeric/frexp.test.ts +++ b/packages/typegpu/tests/std/numeric/frexp.test.ts @@ -1,9 +1,8 @@ import { describe, expect, expectTypeOf } from 'vitest'; import { it } from 'typegpu-testing-utility'; -import { frexp } from '../../../src/std/numeric.ts'; -import { vec2f, vec3h } from '../../../src/data/vector.ts'; -import type { v2f, v2i, v3i } from '../../../src/data/index.ts'; -import type { v3h } from '../../../src/data/wgslTypes.ts'; +import { frexp } from 'typegpu/std'; +import { vec2f, vec3h } from 'typegpu/data'; +import type { v2f, v2i, v3i, v3h } from 'typegpu/data'; describe('frexp', () => { it('gets inferred correctly', () => { diff --git a/packages/typegpu/tests/std/numeric/length.test.ts b/packages/typegpu/tests/std/numeric/length.test.ts index 6eed577943..6c5334ef9f 100644 --- a/packages/typegpu/tests/std/numeric/length.test.ts +++ b/packages/typegpu/tests/std/numeric/length.test.ts @@ -1,6 +1,6 @@ import { describe, expect, it } from 'vitest'; -import { vec2f, vec3f, vec4f } from '../../../src/data/index.ts'; -import { length } from '../../../src/std/index.ts'; +import { vec2f, vec3f, vec4f } from 'typegpu/data'; +import { length } from 'typegpu/std'; describe('length', () => { it('computes length of vec2f', () => { diff --git a/packages/typegpu/tests/std/numeric/log.test.ts b/packages/typegpu/tests/std/numeric/log.test.ts index b39205f8ec..cf2eef6c82 100644 --- a/packages/typegpu/tests/std/numeric/log.test.ts +++ b/packages/typegpu/tests/std/numeric/log.test.ts @@ -1,6 +1,6 @@ import { describe, expect, it } from 'vitest'; -import { vec2f, vec3f, vec4f } from '../../../src/data/index.ts'; -import { isCloseTo, log } from '../../../src/std/index.ts'; +import { vec2f, vec3f, vec4f } from 'typegpu/data'; +import { isCloseTo, log } from 'typegpu/std'; describe('log', () => { it('computes natural logarithm of numeric value', () => { diff --git a/packages/typegpu/tests/std/numeric/log2.test.ts b/packages/typegpu/tests/std/numeric/log2.test.ts index ffef6476d8..17cf617b2f 100644 --- a/packages/typegpu/tests/std/numeric/log2.test.ts +++ b/packages/typegpu/tests/std/numeric/log2.test.ts @@ -1,6 +1,6 @@ import { describe, expect, it } from 'vitest'; -import { vec2f, vec3f, vec4f } from '../../../src/data/index.ts'; -import { isCloseTo, log2 } from '../../../src/std/index.ts'; +import { vec2f, vec3f, vec4f } from 'typegpu/data'; +import { isCloseTo, log2 } from 'typegpu/std'; describe('log2', () => { it('computes base-2 logarithm of numeric value', () => { diff --git a/packages/typegpu/tests/std/numeric/max.test.ts b/packages/typegpu/tests/std/numeric/max.test.ts index 40eee2dfd1..0a759ca837 100644 --- a/packages/typegpu/tests/std/numeric/max.test.ts +++ b/packages/typegpu/tests/std/numeric/max.test.ts @@ -1,5 +1,5 @@ import { describe, expect, it } from 'vitest'; -import tgpu, { d, std } from '../../../src/index.js'; +import tgpu, { d, std } from 'typegpu'; describe('max', () => { it('acts as identity when called with one argument', () => { diff --git a/packages/typegpu/tests/std/numeric/min.test.ts b/packages/typegpu/tests/std/numeric/min.test.ts index ac3fa8da8a..3267c48284 100644 --- a/packages/typegpu/tests/std/numeric/min.test.ts +++ b/packages/typegpu/tests/std/numeric/min.test.ts @@ -1,5 +1,5 @@ import { describe, expect, it } from 'vitest'; -import tgpu, { d, std } from '../../../src/index.js'; +import tgpu, { d, std } from 'typegpu'; describe('min', () => { it('acts as identity when called with one argument', () => { diff --git a/packages/typegpu/tests/std/numeric/mix.test.ts b/packages/typegpu/tests/std/numeric/mix.test.ts index 4e6891daab..28e6988165 100644 --- a/packages/typegpu/tests/std/numeric/mix.test.ts +++ b/packages/typegpu/tests/std/numeric/mix.test.ts @@ -1,6 +1,6 @@ import { describe, expect, it } from 'vitest'; -import { vec2f, vec3f, vec4h } from '../../../src/data/index.ts'; -import { mix } from '../../../src/std/index.ts'; +import { vec2f, vec3f, vec4h } from 'typegpu/data'; +import { mix } from 'typegpu/std'; describe('mix', () => { it('should blend scalar values correctly', () => { diff --git a/packages/typegpu/tests/std/numeric/mod.test.ts b/packages/typegpu/tests/std/numeric/mod.test.ts index 06844ec878..125365b336 100644 --- a/packages/typegpu/tests/std/numeric/mod.test.ts +++ b/packages/typegpu/tests/std/numeric/mod.test.ts @@ -12,23 +12,10 @@ import { vec4h, vec4i, vec4u, -} from '../../../src/data/index.ts'; -import type { - v2f, - v2h, - v2i, - v2u, - v3f, - v3h, - v3i, - v3u, - v4f, - v4h, - v4i, - v4u, -} from '../../../src/data/wgslTypes.ts'; -import { isCloseTo, mod } from '../../../src/std/index.ts'; -import tgpu, { d } from '../../../src/index.js'; +} from 'typegpu/data'; +import type { v2f, v2h, v2i, v2u, v3f, v3h, v3i, v3u, v4f, v4h, v4i, v4u } from 'typegpu/data'; +import { isCloseTo, mod } from 'typegpu/std'; +import tgpu, { d } from 'typegpu'; describe('mod', () => { it('computes modulo of a number and a number', () => { diff --git a/packages/typegpu/tests/std/numeric/modf.test.ts b/packages/typegpu/tests/std/numeric/modf.test.ts index 3c1697bedc..3ce9ddca41 100644 --- a/packages/typegpu/tests/std/numeric/modf.test.ts +++ b/packages/typegpu/tests/std/numeric/modf.test.ts @@ -1,9 +1,8 @@ import { describe, expect, expectTypeOf } from 'vitest'; import { it } from 'typegpu-testing-utility'; -import { modf } from '../../../src/std/numeric.ts'; -import { vec2f, vec3h } from '../../../src/data/vector.ts'; -import type { v2f } from '../../../src/data/index.ts'; -import type { v3h } from '../../../src/data/wgslTypes.ts'; +import { modf } from 'typegpu/std'; +import { vec2f, vec3h } from 'typegpu/data'; +import type { v2f, v3h } from 'typegpu/data'; describe('modf', () => { it('gets inferred correctly', () => { diff --git a/packages/typegpu/tests/std/numeric/mul.test.ts b/packages/typegpu/tests/std/numeric/mul.test.ts index 1b66472427..8d8e1bf02e 100644 --- a/packages/typegpu/tests/std/numeric/mul.test.ts +++ b/packages/typegpu/tests/std/numeric/mul.test.ts @@ -1,5 +1,5 @@ import { describe, expect, expectTypeOf, it } from 'vitest'; -import tgpu, { d } from '../../../src/index.js'; +import tgpu, { d } from 'typegpu'; import { mat2x2f, mat3x3f, @@ -16,9 +16,9 @@ import { vec4h, vec4i, vec4u, -} from '../../../src/data/index.ts'; -import type { m2x2f, m3x3f, m4x4f, v2f, v3f, v4f } from '../../../src/data/wgslTypes.ts'; -import { mul } from '../../../src/std/index.ts'; +} from 'typegpu/data'; +import type { m2x2f, m3x3f, m4x4f, v2f, v3f, v4f } from 'typegpu/data'; +import { mul } from 'typegpu/std'; describe('mul', () => { it('computes product of a number and a number', () => { diff --git a/packages/typegpu/tests/std/numeric/normalize.test.ts b/packages/typegpu/tests/std/numeric/normalize.test.ts index f8e268b130..943270d5ac 100644 --- a/packages/typegpu/tests/std/numeric/normalize.test.ts +++ b/packages/typegpu/tests/std/numeric/normalize.test.ts @@ -1,6 +1,6 @@ import { describe, expect, it } from 'vitest'; -import { vec2f, vec3f, vec4f } from '../../../src/data/index.ts'; -import { normalize } from '../../../src/std/index.ts'; +import { vec2f, vec3f, vec4f } from 'typegpu/data'; +import { normalize } from 'typegpu/std'; describe('normalize', () => { it('computes normalized vector from vec2f', () => { diff --git a/packages/typegpu/tests/std/numeric/pow.test.ts b/packages/typegpu/tests/std/numeric/pow.test.ts index 1c9739720d..2638220b68 100644 --- a/packages/typegpu/tests/std/numeric/pow.test.ts +++ b/packages/typegpu/tests/std/numeric/pow.test.ts @@ -1,6 +1,6 @@ import { describe, expect, it } from 'vitest'; -import { vec2f, vec3f, vec4h } from '../../../src/data/index.ts'; -import { pow } from '../../../src/std/index.ts'; +import { vec2f, vec3f, vec4h } from 'typegpu/data'; +import { pow } from 'typegpu/std'; describe('pow', () => { it('should return the correct power', () => { diff --git a/packages/typegpu/tests/std/numeric/reflect.test.ts b/packages/typegpu/tests/std/numeric/reflect.test.ts index f5cd209079..5bf54b22ae 100644 --- a/packages/typegpu/tests/std/numeric/reflect.test.ts +++ b/packages/typegpu/tests/std/numeric/reflect.test.ts @@ -1,6 +1,6 @@ import { describe, expect, it } from 'vitest'; -import { vec2f, vec3f } from '../../../src/data/index.ts'; -import { reflect } from '../../../src/std/index.ts'; +import { vec2f, vec3f } from 'typegpu/data'; +import { reflect } from 'typegpu/std'; describe('reflect', () => { it('reflects a vec2f vector correctly', () => { diff --git a/packages/typegpu/tests/std/numeric/round.test.ts b/packages/typegpu/tests/std/numeric/round.test.ts index 119f4762ec..2d9e3e9a9d 100644 --- a/packages/typegpu/tests/std/numeric/round.test.ts +++ b/packages/typegpu/tests/std/numeric/round.test.ts @@ -1,5 +1,5 @@ import { describe, expect, it } from 'vitest'; -import tgpu, { d, std } from '../../../src/index.js'; +import tgpu, { d, std } from 'typegpu'; describe('round', () => { it('rounds to even numbers', () => { diff --git a/packages/typegpu/tests/std/numeric/sign.test.ts b/packages/typegpu/tests/std/numeric/sign.test.ts index 6ebc1ba0dd..00dc5857e6 100644 --- a/packages/typegpu/tests/std/numeric/sign.test.ts +++ b/packages/typegpu/tests/std/numeric/sign.test.ts @@ -1,6 +1,6 @@ import { describe, expect, it } from 'vitest'; -import { vec3f } from '../../../src/data/index.ts'; -import { isCloseTo, sign } from '../../../src/std/index.ts'; +import { vec3f } from 'typegpu/data'; +import { isCloseTo, sign } from 'typegpu/std'; describe('sign', () => { it('computes sign of numeric value', () => { diff --git a/packages/typegpu/tests/std/numeric/smoothstep.test.ts b/packages/typegpu/tests/std/numeric/smoothstep.test.ts index 32fdc224b6..b821207d60 100644 --- a/packages/typegpu/tests/std/numeric/smoothstep.test.ts +++ b/packages/typegpu/tests/std/numeric/smoothstep.test.ts @@ -1,7 +1,6 @@ import { describe, expect, it } from 'vitest'; -import { vec2f, vec3f, vec4f } from '../../../src/data/index.ts'; -import { smoothstep } from '../../../src/std/index.ts'; -import { isCloseTo } from '../../../src/std/boolean.ts'; +import { vec2f, vec3f, vec4f } from 'typegpu/data'; +import { smoothstep, isCloseTo } from 'typegpu/std'; describe('smoothstep', () => { it('returns 0 when x is less than or equal to edge0', () => { diff --git a/packages/typegpu/tests/std/numeric/sub.test.ts b/packages/typegpu/tests/std/numeric/sub.test.ts index 99067479c6..ff62a7cfe0 100644 --- a/packages/typegpu/tests/std/numeric/sub.test.ts +++ b/packages/typegpu/tests/std/numeric/sub.test.ts @@ -1,5 +1,5 @@ import { describe, expect, expectTypeOf, it } from 'vitest'; -import type { m3x3f, v2f, v3f, v4f } from '../../../src/data/index.ts'; +import type { m3x3f, v2f, v3f, v4f } from 'typegpu/data'; import { mat2x2f, mat3x3f, @@ -13,9 +13,8 @@ import { vec4f, vec4i, vec4u, -} from '../../../src/data/index.ts'; - -import { sub } from '../../../src/std/index.ts'; +} from 'typegpu/data'; +import { sub } from 'typegpu/std'; describe('sub', () => { it('computes difference of two vec2f', () => { diff --git a/packages/typegpu/tests/std/packing.test.ts b/packages/typegpu/tests/std/packing.test.ts index 816487a7fe..e7ed0e296d 100644 --- a/packages/typegpu/tests/std/packing.test.ts +++ b/packages/typegpu/tests/std/packing.test.ts @@ -1,11 +1,6 @@ import { describe, expect, it } from 'vitest'; -import { vec2f, vec4f } from '../../src/data/vector.ts'; -import { - pack2x16float, - pack4x8unorm, - unpack2x16float, - unpack4x8unorm, -} from '../../src/std/packing.ts'; +import { vec2f, vec4f } from 'typegpu/data'; +import { pack2x16float, pack4x8unorm, unpack2x16float, unpack4x8unorm } from 'typegpu/std'; describe('packing', () => { it('packs and unpacks 4x8 unorm', () => { diff --git a/packages/typegpu/tests/std/range.test.ts b/packages/typegpu/tests/std/range.test.ts index d51e5971ed..aafbb1b511 100644 --- a/packages/typegpu/tests/std/range.test.ts +++ b/packages/typegpu/tests/std/range.test.ts @@ -1,7 +1,7 @@ import { test } from 'typegpu-testing-utility'; import { describe, expect } from 'vitest'; -import { d, std } from '../../src/index.js'; -import tgpu from '../../src/index.js'; +import { d, std } from 'typegpu'; +import tgpu from 'typegpu'; // range(n) — single argument, generates [0, n) test('std.range - single arg', () => { diff --git a/packages/typegpu/tests/std/texture/textureGather.test.ts b/packages/typegpu/tests/std/texture/textureGather.test.ts index 902cc8ae4e..243a755fcd 100644 --- a/packages/typegpu/tests/std/texture/textureGather.test.ts +++ b/packages/typegpu/tests/std/texture/textureGather.test.ts @@ -1,14 +1,11 @@ import { describe, expect, expectTypeOf } from 'vitest'; import { it } from 'typegpu-testing-utility'; -import { textureGather } from '../../../src/std/texture.ts'; -import tgpu from '../../../src/index.js'; -import * as d from '../../../src/data/index.ts'; -import { bindGroupLayout } from '../../../src/tgpuBindGroupLayout.ts'; -import { resolve } from '../../../src/core/resolve/tgpuResolve.ts'; +import { textureGather } from 'typegpu/std'; +import tgpu, { d } from 'typegpu'; describe('textureGather', () => { it('Has correct signatures', () => { - const testLayout = bindGroupLayout({ + const testLayout = tgpu.bindGroupLayout({ tex2d: { texture: d.texture2d() }, tex2d_u32: { texture: d.texture2d(d.u32) }, tex2d_array: { texture: d.texture2dArray(d.i32) }, @@ -66,7 +63,7 @@ describe('textureGather', () => { } }); - expect(resolve([testFn])).toMatchInlineSnapshot(` + expect(tgpu.resolve([testFn])).toMatchInlineSnapshot(` "@group(0) @binding(0) var tex2d: texture_2d; @group(0) @binding(6) var sampler_1: sampler; diff --git a/packages/typegpu/tests/std/texture/textureLoad.test.ts b/packages/typegpu/tests/std/texture/textureLoad.test.ts index ff498b7e05..a120b30788 100644 --- a/packages/typegpu/tests/std/texture/textureLoad.test.ts +++ b/packages/typegpu/tests/std/texture/textureLoad.test.ts @@ -1,17 +1,13 @@ import { describe, expect, expectTypeOf } from 'vitest'; import { it } from 'typegpu-testing-utility'; -import { textureLoad } from '../../../src/std/texture.ts'; -import tgpu from '../../../src/index.js'; -import * as d from '../../../src/data/index.ts'; -import { bindGroupLayout } from '../../../src/tgpuBindGroupLayout.ts'; -import { resolve } from '../../../src/core/resolve/tgpuResolve.ts'; +import tgpu, { d, std } from 'typegpu'; // we need this since all other usages will be removed by plugin expectTypeOf(() => {}); describe('textureLoad', () => { it('Has correct signatures for sampled and depth textures', () => { - const testLayout = bindGroupLayout({ + const testLayout = tgpu.bindGroupLayout({ tex1d: { texture: d.texture1d() }, tex2d: { texture: d.texture2d() }, tex2d_u32: { texture: d.texture2d(d.u32) }, @@ -32,21 +28,21 @@ describe('textureLoad', () => { const arrayIndex = d.i32(0); const sampleIndex = d.i32(0); - const load1d = textureLoad(testLayout.$.tex1d, coord1d, level); - const load2d = textureLoad(testLayout.$.tex2d, coord2d, level); - const load2d_u32 = textureLoad(testLayout.$.tex2d_u32, coord2d, level); - const load2d_i32 = textureLoad(testLayout.$.tex2d_i32, coord2d, level); - const load2d_array = textureLoad(testLayout.$.tex2d_array, coord2d, arrayIndex, level); - const load3d = textureLoad(testLayout.$.tex3d, coord3d, level); - const loadms2d = textureLoad(testLayout.$.texms2d, coord2d, sampleIndex); - const loaddepth2d = textureLoad(testLayout.$.texdepth2d, coord2d, level); - const loaddepth2d_array = textureLoad( + const load1d = std.textureLoad(testLayout.$.tex1d, coord1d, level); + const load2d = std.textureLoad(testLayout.$.tex2d, coord2d, level); + const load2d_u32 = std.textureLoad(testLayout.$.tex2d_u32, coord2d, level); + const load2d_i32 = std.textureLoad(testLayout.$.tex2d_i32, coord2d, level); + const load2d_array = std.textureLoad(testLayout.$.tex2d_array, coord2d, arrayIndex, level); + const load3d = std.textureLoad(testLayout.$.tex3d, coord3d, level); + const loadms2d = std.textureLoad(testLayout.$.texms2d, coord2d, sampleIndex); + const loaddepth2d = std.textureLoad(testLayout.$.texdepth2d, coord2d, level); + const loaddepth2d_array = std.textureLoad( testLayout.$.texdepth2d_array, coord2d, arrayIndex, level, ); - const loaddepthms2d = textureLoad(testLayout.$.texdepthms2d, coord2d, sampleIndex); + const loaddepthms2d = std.textureLoad(testLayout.$.texdepthms2d, coord2d, sampleIndex); if (false) { expectTypeOf(load1d).toEqualTypeOf(); @@ -62,7 +58,7 @@ describe('textureLoad', () => { } }); - expect(resolve([testFn])).toMatchInlineSnapshot(` + expect(tgpu.resolve([testFn])).toMatchInlineSnapshot(` "@group(0) @binding(0) var tex1d: texture_1d; @group(0) @binding(1) var tex2d: texture_2d; @@ -105,7 +101,7 @@ describe('textureLoad', () => { }); it('Has correct signatures for storage textures', () => { - const testLayout = bindGroupLayout({ + const testLayout = tgpu.bindGroupLayout({ store1d: { storageTexture: d.textureStorage1d('rgba32float', 'read-only') }, store2d: { storageTexture: d.textureStorage2d('rgba32float', 'read-only') }, store2d_uint: { storageTexture: d.textureStorage2d('rgba32uint', 'read-only') }, @@ -120,12 +116,12 @@ describe('textureLoad', () => { const coord3d = d.vec3i(0, 0, 0); const arrayIndex = d.i32(0); - const loadStore1d = textureLoad(testLayout.$.store1d, coord1d); - const loadStore2d = textureLoad(testLayout.$.store2d, coord2d); - const loadStore2d_uint = textureLoad(testLayout.$.store2d_uint, coord2d); - const loadStore2d_sint = textureLoad(testLayout.$.store2d_sint, coord2d); - const loadStore2d_array = textureLoad(testLayout.$.store2d_array, coord2d, arrayIndex); - const loadStore3d = textureLoad(testLayout.$.store3d, coord3d); + const loadStore1d = std.textureLoad(testLayout.$.store1d, coord1d); + const loadStore2d = std.textureLoad(testLayout.$.store2d, coord2d); + const loadStore2d_uint = std.textureLoad(testLayout.$.store2d_uint, coord2d); + const loadStore2d_sint = std.textureLoad(testLayout.$.store2d_sint, coord2d); + const loadStore2d_array = std.textureLoad(testLayout.$.store2d_array, coord2d, arrayIndex); + const loadStore3d = std.textureLoad(testLayout.$.store3d, coord3d); if (false) { expectTypeOf(loadStore1d).toEqualTypeOf(); @@ -137,7 +133,7 @@ describe('textureLoad', () => { } }); - expect(resolve([testFn])).toMatchInlineSnapshot(` + expect(tgpu.resolve([testFn])).toMatchInlineSnapshot(` "@group(0) @binding(0) var store1d: texture_storage_1d; @group(0) @binding(1) var store2d: texture_storage_2d; @@ -166,21 +162,21 @@ describe('textureLoad', () => { }); it('Has correct signatures for external textures', () => { - const testLayout = bindGroupLayout({ + const testLayout = tgpu.bindGroupLayout({ texExternal: { externalTexture: d.textureExternal() }, }); const testFn = tgpu.fn([])(() => { const coord2d = d.vec2i(0, 0); - const loadExternal = textureLoad(testLayout.$.texExternal, coord2d); + const loadExternal = std.textureLoad(testLayout.$.texExternal, coord2d); if (false) { expectTypeOf(loadExternal).toEqualTypeOf(); } }); - expect(resolve([testFn])).toMatchInlineSnapshot(` + expect(tgpu.resolve([testFn])).toMatchInlineSnapshot(` "@group(0) @binding(0) var texExternal: texture_external; fn testFn() { @@ -199,7 +195,7 @@ describe('textureLoad', () => { .$usage('sampled'); const sampledView = someTexture.createView(d.texture2d()); - const someLayout = bindGroupLayout({ + const someLayout = tgpu.bindGroupLayout({ tex2d: { texture: d.texture2d() }, }); @@ -207,13 +203,13 @@ describe('textureLoad', () => { const _validFn = tgpu.fn( [], d.vec4f, - )(() => textureLoad(sampledView.$, d.vec2i(0, 0), d.i32(0))); + )(() => std.textureLoad(sampledView.$, d.vec2i(0, 0), d.i32(0))); // Valid: view from a layout binding const _validFn2 = tgpu.fn( [], d.vec4f, - )(() => textureLoad(someLayout.$.tex2d, d.vec2i(0, 0), d.i32(0))); + )(() => std.textureLoad(someLayout.$.tex2d, d.vec2i(0, 0), d.i32(0))); // @ts-expect-error — raw schema must not be accepted const _invalidFn = tgpu.fn( @@ -221,7 +217,7 @@ describe('textureLoad', () => { d.vec4f, )(() => // @ts-expect-error - textureLoad(d.texture2d(), d.vec2i(0, 0), 0), + std.textureLoad(d.texture2d(), d.vec2i(0, 0), 0), ); }); }); diff --git a/packages/typegpu/tests/std/texture/textureSample.test.ts b/packages/typegpu/tests/std/texture/textureSample.test.ts index c1886cdb54..877fe739ec 100644 --- a/packages/typegpu/tests/std/texture/textureSample.test.ts +++ b/packages/typegpu/tests/std/texture/textureSample.test.ts @@ -1,9 +1,7 @@ import { describe, expect } from 'vitest'; import { it } from 'typegpu-testing-utility'; -import { textureSample } from '../../../src/std/texture.ts'; -import { fn } from '../../../src/core/function/tgpuFn.ts'; -import * as d from '../../../src/data/index.ts'; -import { bindGroupLayout } from '../../../src/tgpuBindGroupLayout.ts'; +import tgpu, { d } from 'typegpu'; +import { textureSample } from 'typegpu/std'; describe('textureSample', () => { it('does not allow for raw schemas to be passed in', ({ root }) => { @@ -20,21 +18,21 @@ describe('textureSample', () => { .$usage('sampled'); const sampledView = someTexture.createView(d.texture2d()); - const someLayout = bindGroupLayout({ + const someLayout = tgpu.bindGroupLayout({ sampledCube: { texture: d.textureCube() }, }); - const validFn = fn( + const validFn = tgpu.fn( [], d.vec4f, )(() => textureSample(sampledView.$, linSampler.$, d.vec2f(0.5))); - const validFn2 = fn( + const validFn2 = tgpu.fn( [], d.vec4f, )(() => textureSample(someLayout.$.sampledCube, linSampler.$, d.vec3f(0.5))); - const invalidFn = fn( + const invalidFn = tgpu.fn( [], d.vec4f, )(() => @@ -42,7 +40,7 @@ describe('textureSample', () => { textureSample(d.texture2d(), linSampler, d.vec2f(0.5)), ); - const invalidFn2 = fn( + const invalidFn2 = tgpu.fn( [], d.vec4f, )(() => diff --git a/packages/typegpu/tests/struct.test.ts b/packages/typegpu/tests/struct.test.ts index 14dc0984aa..306f210af1 100644 --- a/packages/typegpu/tests/struct.test.ts +++ b/packages/typegpu/tests/struct.test.ts @@ -18,7 +18,7 @@ import { vec3h, vec3u, } from '../src/data/index.ts'; -import tgpu from '../src/index.js'; +import tgpu from 'typegpu'; import * as d from '../src/data/index.ts'; import type { Infer } from '../src/shared/repr.ts'; import { frexp } from '../src/std/numeric.ts'; diff --git a/packages/typegpu/tests/swizzleMixedValidation.test.ts b/packages/typegpu/tests/swizzleMixedValidation.test.ts index 82e5069db0..a45d4a617c 100644 --- a/packages/typegpu/tests/swizzleMixedValidation.test.ts +++ b/packages/typegpu/tests/swizzleMixedValidation.test.ts @@ -1,5 +1,5 @@ import { describe, expect, it } from 'vitest'; -import tgpu, { d } from '../src/index.js'; +import tgpu, { d } from 'typegpu'; describe('Mixed swizzle validation', () => { describe('JS validation', () => { diff --git a/packages/typegpu/tests/texture.test.ts b/packages/typegpu/tests/texture.test.ts index 450537c8f5..886454ace2 100644 --- a/packages/typegpu/tests/texture.test.ts +++ b/packages/typegpu/tests/texture.test.ts @@ -5,7 +5,7 @@ import type { ExperimentalTgpuRoot } from '../src/core/root/rootTypes.ts'; import { it } from 'typegpu-testing-utility'; import * as d from '../src/data/index.ts'; import { attest } from '@ark/attest'; -import tgpu from '../src/index.js'; +import tgpu from 'typegpu'; import { getName } from '../src/shared/meta.ts'; describe('TgpuTexture', () => { diff --git a/packages/typegpu/tests/tgpuGenericFn.test.ts b/packages/typegpu/tests/tgpuGenericFn.test.ts index fd136ced01..0a11c756e7 100644 --- a/packages/typegpu/tests/tgpuGenericFn.test.ts +++ b/packages/typegpu/tests/tgpuGenericFn.test.ts @@ -1,6 +1,6 @@ import { describe, expect } from 'vitest'; import * as d from '../src/data/index.ts'; -import tgpu, { std } from '../src/index.js'; +import tgpu, { std } from 'typegpu'; import { it } from 'typegpu-testing-utility'; describe('TgpuGenericFn - shellless callback wrapper', () => { diff --git a/packages/typegpu/tests/tgsl/argumentOrigin.test.ts b/packages/typegpu/tests/tgsl/argumentOrigin.test.ts index 3fd4f3ce40..bfa935bc51 100644 --- a/packages/typegpu/tests/tgsl/argumentOrigin.test.ts +++ b/packages/typegpu/tests/tgsl/argumentOrigin.test.ts @@ -1,6 +1,6 @@ import { describe, expect } from 'vitest'; import { it } from 'typegpu-testing-utility'; -import tgpu, { d } from '../../src/index.js'; +import tgpu, { d } from 'typegpu'; describe('function argument origin tracking', () => { it('should fail on mutation of primitive arguments', () => { diff --git a/packages/typegpu/tests/tgsl/assignment.test.ts b/packages/typegpu/tests/tgsl/assignment.test.ts index dc8961413d..a84b39be8a 100644 --- a/packages/typegpu/tests/tgsl/assignment.test.ts +++ b/packages/typegpu/tests/tgsl/assignment.test.ts @@ -1,6 +1,6 @@ import { beforeEach, expect, type MockInstance, vi } from 'vitest'; import { it } from 'typegpu-testing-utility'; -import tgpu, { d } from '../../src/index.js'; +import tgpu, { d } from 'typegpu'; let warnSpy: MockInstance; diff --git a/packages/typegpu/tests/tgsl/codeGen.test.ts b/packages/typegpu/tests/tgsl/codeGen.test.ts index 38f48adc6e..df7871f1f2 100644 --- a/packages/typegpu/tests/tgsl/codeGen.test.ts +++ b/packages/typegpu/tests/tgsl/codeGen.test.ts @@ -1,7 +1,7 @@ import { describe, expect } from 'vitest'; import { it } from 'typegpu-testing-utility'; -import tgpu, { d } from '../../src/index.js'; +import tgpu, { d } from 'typegpu'; describe('codeGen', () => { describe('vectors', () => { diff --git a/packages/typegpu/tests/tgsl/comptime.test.ts b/packages/typegpu/tests/tgsl/comptime.test.ts index f4fc57f42c..a4c65ae9c1 100644 --- a/packages/typegpu/tests/tgsl/comptime.test.ts +++ b/packages/typegpu/tests/tgsl/comptime.test.ts @@ -1,6 +1,6 @@ import { describe, expect } from 'vitest'; import { it } from 'typegpu-testing-utility'; -import tgpu, { d } from '../../src/index.js'; +import tgpu, { d } from 'typegpu'; describe('comptime', () => { it('should work in JS', () => { diff --git a/packages/typegpu/tests/tgsl/consoleLog.test.ts b/packages/typegpu/tests/tgsl/consoleLog.test.ts index f452dd5f2a..f0c40f2b63 100644 --- a/packages/typegpu/tests/tgsl/consoleLog.test.ts +++ b/packages/typegpu/tests/tgsl/consoleLog.test.ts @@ -1,18 +1,8 @@ -import { beforeEach, describe, expect, vi } from 'vitest'; -import { namespace } from '../../src/core/resolve/namespace.ts'; -import tgpu, { d } from '../../src/index.js'; -import { ResolutionCtxImpl } from '../../src/resolutionCtx.ts'; -import { deserializeAndStringify } from '../../src/tgsl/consoleLog/deserializers.ts'; -import { CodegenState } from '../../src/types.ts'; +import { describe, expect, vi } from 'vitest'; +import tgpu, { d } from 'typegpu'; import { it } from 'typegpu-testing-utility'; describe('wgslGenerator with console.log', () => { - let ctx: ResolutionCtxImpl; - beforeEach(() => { - ctx = new ResolutionCtxImpl({ namespace: namespace() }); - ctx.pushMode(new CodegenState()); - }); - it('Parses console.log in a stray function to a comment and warns', () => { using consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {}); @@ -749,131 +739,3 @@ describe('wgslGenerator with console.log', () => { `); }); }); - -describe('deserializeAndStringify', () => { - it('works for string literals', () => { - const data = new Uint32Array([]); - const logInfo: (string | d.AnyWgslData)[] = ['String literal']; - - expect(deserializeAndStringify(data, logInfo)).toMatchInlineSnapshot( - ` - [ - "String literal", - ] - `, - ); - }); - - it('works for u32', () => { - const data = new Uint32Array([123]); - const logInfo: (string | d.AnyWgslData)[] = [d.u32]; - - expect(deserializeAndStringify(data, logInfo)).toMatchInlineSnapshot( - ` - [ - "123", - ] - `, - ); - }); - - it('works for vec3u', () => { - const data = new Uint32Array([1, 2, 3]); - const logInfo: (string | d.AnyWgslData)[] = [d.vec3u]; - - expect(deserializeAndStringify(data, logInfo)).toMatchInlineSnapshot( - ` - [ - "vec3u(1, 2, 3)", - ] - `, - ); - }); - - it('works for clumped vectors', () => { - const data = new Uint32Array([1, 2, 3, 4, 5, 6]); // no alignment - const logInfo: (string | d.AnyWgslData)[] = [d.vec3u, d.vec3u]; - - expect(deserializeAndStringify(data, logInfo)).toMatchInlineSnapshot( - ` - [ - "vec3u(1, 2, 3)", - "vec3u(4, 5, 6)", - ] - `, - ); - }); - - it('works for multiple arguments', () => { - const data = new Uint32Array([1, 2, 3, 456]); - const logInfo: (string | d.AnyWgslData)[] = ['GID:', d.vec3u, 'Result:', d.u32]; - - expect(deserializeAndStringify(data, logInfo)).toMatchInlineSnapshot( - ` - [ - "GID:", - "vec3u(1, 2, 3)", - "Result:", - "456", - ] - `, - ); - }); - - it('works for arrays', () => { - const data = new Uint32Array([1, 2, 3, 4]); - const logInfo: (string | d.AnyWgslData)[] = [d.arrayOf(d.u32, 4)]; - - expect(deserializeAndStringify(data, logInfo)).toMatchInlineSnapshot( - ` - [ - "[1, 2, 3, 4]", - ] - `, - ); - }); - - it('works for nested arrays', () => { - const data = new Uint32Array([1, 2, 3, 4]); - const logInfo: (string | d.AnyWgslData)[] = [d.arrayOf(d.arrayOf(d.u32, 2), 2)]; - - expect(deserializeAndStringify(data, logInfo)).toMatchInlineSnapshot( - ` - [ - "[[1, 2], [3, 4]]", - ] - `, - ); - }); - - it('works for structs', () => { - const data = new Uint32Array([1, 2, 3, 4]); - const logInfo: (string | d.AnyWgslData)[] = [d.struct({ vec: d.vec3u, num: d.u32 })]; - - expect(deserializeAndStringify(data, logInfo)).toMatchInlineSnapshot( - ` - [ - "{ vec: vec3u(1, 2, 3), num: 4 }", - ] - `, - ); - }); - - it('works for nested structs', () => { - const data = new Uint32Array([1, 2, 3, 4, 1]); - const logInfo: (string | d.AnyWgslData)[] = [ - d.struct({ - nested: d.struct({ vec: d.vec3u, num: d.u32 }), - bool: d.bool, - }), - ]; - - expect(deserializeAndStringify(data, logInfo)).toMatchInlineSnapshot( - ` - [ - "{ nested: { vec: vec3u(1, 2, 3), num: 4 }, bool: true }", - ] - `, - ); - }); -}); diff --git a/packages/typegpu/tests/tgsl/entryFnParamPruning.test.ts b/packages/typegpu/tests/tgsl/entryFnParamPruning.test.ts index b60274fede..0b620c0a98 100644 --- a/packages/typegpu/tests/tgsl/entryFnParamPruning.test.ts +++ b/packages/typegpu/tests/tgsl/entryFnParamPruning.test.ts @@ -1,7 +1,7 @@ import { describe, expect } from 'vitest'; import { it } from 'typegpu-testing-utility'; -import tgpu, { d, std } from '../../src/index.js'; +import tgpu, { d, std } from 'typegpu'; const layout = tgpu.bindGroupLayout({ output: { storage: d.arrayOf(d.f32), access: 'mutable' }, diff --git a/packages/typegpu/tests/tgsl/extensionEnabled.test.ts b/packages/typegpu/tests/tgsl/extensionEnabled.test.ts index 58150fbee5..67d03cf85d 100644 --- a/packages/typegpu/tests/tgsl/extensionEnabled.test.ts +++ b/packages/typegpu/tests/tgsl/extensionEnabled.test.ts @@ -1,7 +1,7 @@ import { describe, expect } from 'vitest'; import { it } from 'typegpu-testing-utility'; -import tgpu, { d, std } from '../../src/index.js'; +import tgpu, { d, std } from 'typegpu'; describe('extension based pruning', () => { it('should include extension code when the feature is used', () => { diff --git a/packages/typegpu/tests/tgsl/infixOperators.test.ts b/packages/typegpu/tests/tgsl/infixOperators.test.ts index 2e18ed3331..81c8322a86 100644 --- a/packages/typegpu/tests/tgsl/infixOperators.test.ts +++ b/packages/typegpu/tests/tgsl/infixOperators.test.ts @@ -1,5 +1,5 @@ import { describe, expect } from 'vitest'; -import tgpu, { d } from '../../src/index.js'; +import tgpu, { d } from 'typegpu'; import { it } from 'typegpu-testing-utility'; describe('wgslGenerator', () => { diff --git a/packages/typegpu/tests/tgsl/memberAccess.test.ts b/packages/typegpu/tests/tgsl/memberAccess.test.ts index 41483b66a3..bdef82c1da 100644 --- a/packages/typegpu/tests/tgsl/memberAccess.test.ts +++ b/packages/typegpu/tests/tgsl/memberAccess.test.ts @@ -1,7 +1,7 @@ import { describe } from 'vitest'; import { it } from 'typegpu-testing-utility'; import { expectSnippetOf } from '../utils/parseResolved.ts'; -import tgpu, { d } from '../../src/index.js'; +import tgpu, { d } from 'typegpu'; describe('Member Access', () => { const Boid = d.struct({ diff --git a/packages/typegpu/tests/tgsl/nameClashes.test.ts b/packages/typegpu/tests/tgsl/nameClashes.test.ts index 586e8e3bf1..97bb151c5e 100644 --- a/packages/typegpu/tests/tgsl/nameClashes.test.ts +++ b/packages/typegpu/tests/tgsl/nameClashes.test.ts @@ -1,5 +1,5 @@ import { expect } from 'vitest'; -import tgpu, { d, std } from '../../src/index.js'; +import tgpu, { d, std } from 'typegpu'; import { test } from 'typegpu-testing-utility'; test('should differentiate parameter names from existing declarations', () => { diff --git a/packages/typegpu/tests/tgsl/operatorOverloads.test.ts b/packages/typegpu/tests/tgsl/operatorOverloads.test.ts index a351fefcb4..97a54000ee 100644 --- a/packages/typegpu/tests/tgsl/operatorOverloads.test.ts +++ b/packages/typegpu/tests/tgsl/operatorOverloads.test.ts @@ -1,5 +1,5 @@ import { describe, expect } from 'vitest'; -import { d, tgpu } from '../../src/index.js'; +import { d, tgpu } from 'typegpu'; import { test } from 'typegpu-testing-utility'; test('vec3f() +', () => { diff --git a/packages/typegpu/tests/tgsl/rawCodeSnippet.test.ts b/packages/typegpu/tests/tgsl/rawCodeSnippet.test.ts index b0dcd5f70b..f84c760de2 100644 --- a/packages/typegpu/tests/tgsl/rawCodeSnippet.test.ts +++ b/packages/typegpu/tests/tgsl/rawCodeSnippet.test.ts @@ -1,6 +1,6 @@ import { describe, expect, expectTypeOf } from 'vitest'; import { it } from 'typegpu-testing-utility'; -import tgpu, { d } from '../../src/index.js'; +import tgpu, { d } from 'typegpu'; describe('rawCodeSnippet', () => { it('should throw a descriptive error when called in JS', () => { diff --git a/packages/typegpu/tests/tgsl/shellless.test.ts b/packages/typegpu/tests/tgsl/shellless.test.ts index dffa03992f..85b705b3ba 100644 --- a/packages/typegpu/tests/tgsl/shellless.test.ts +++ b/packages/typegpu/tests/tgsl/shellless.test.ts @@ -7,7 +7,7 @@ import tgpu, { type TgpuSlot, type TgpuTextureView, type TgpuUniform, -} from '../../src/index.js'; +} from 'typegpu'; import { it } from 'typegpu-testing-utility'; describe('shellless', () => { diff --git a/packages/typegpu/tests/tgsl/ternaryOperator.test.ts b/packages/typegpu/tests/tgsl/ternaryOperator.test.ts index c41cc6b27c..bf2a3a1b72 100644 --- a/packages/typegpu/tests/tgsl/ternaryOperator.test.ts +++ b/packages/typegpu/tests/tgsl/ternaryOperator.test.ts @@ -1,6 +1,6 @@ import { describe, expect } from 'vitest'; import { it } from 'typegpu-testing-utility'; -import tgpu, { d, std } from '../../src/index.js'; +import tgpu, { d, std } from 'typegpu'; describe('ternary operator', () => { it('should resolve to one of the branches', () => { diff --git a/packages/typegpu/tests/tgsl/typeInference.test.ts b/packages/typegpu/tests/tgsl/typeInference.test.ts index 10c6c81726..1910f71a13 100644 --- a/packages/typegpu/tests/tgsl/typeInference.test.ts +++ b/packages/typegpu/tests/tgsl/typeInference.test.ts @@ -1,21 +1,7 @@ -import { beforeEach, describe, expect, it, vi } from 'vitest'; -import tgpu, { d, std } from '../../src/index.js'; -import { namespace } from '../../src/core/resolve/namespace.ts'; -import { ResolutionCtxImpl } from '../../src/resolutionCtx.ts'; -import { CodegenState } from '../../src/types.ts'; -import wgslGenerator from '../../src/tgsl/wgslGenerator.ts'; +import { describe, expect, it, vi } from 'vitest'; +import tgpu, { d, std } from 'typegpu'; describe('wgsl generator type inference', () => { - let ctx: ResolutionCtxImpl; - - beforeEach(() => { - ctx = new ResolutionCtxImpl({ - namespace: namespace({ names: 'strict' }), - shaderGenerator: wgslGenerator, - }); - ctx.pushMode(new CodegenState()); - }); - it('coerces nested structs', () => { const Inner = d.struct({ prop: d.vec2f }); const Outer = d.struct({ inner: Inner }); @@ -339,16 +325,6 @@ describe('wgsl generator type inference', () => { }); describe('wgsl generator js type inference', () => { - let ctx: ResolutionCtxImpl; - - beforeEach(() => { - ctx = new ResolutionCtxImpl({ - namespace: namespace({ names: 'strict' }), - shaderGenerator: wgslGenerator, - }); - ctx.pushMode(new CodegenState()); - }); - it('coerces external to be an array', () => { const arr = [1, 2, 3]; const Result = d.arrayOf(d.f32, 3); diff --git a/packages/typegpu/tests/tgslFn.test.ts b/packages/typegpu/tests/tgslFn.test.ts index 9278a82a00..13a85e8acc 100644 --- a/packages/typegpu/tests/tgslFn.test.ts +++ b/packages/typegpu/tests/tgslFn.test.ts @@ -1,7 +1,7 @@ import { attest } from '@ark/attest'; import { describe, expect } from 'vitest'; import { builtin } from '../src/builtin.ts'; -import tgpu, { d, type TgpuFn, type TgpuSlot } from '../src/index.js'; +import tgpu, { d, type TgpuFn, type TgpuSlot } from 'typegpu'; import { getName } from '../src/shared/meta.ts'; import { it } from 'typegpu-testing-utility'; diff --git a/packages/typegpu/tests/unroll.test.ts b/packages/typegpu/tests/unroll.test.ts index c35689684e..02af9ec6f1 100644 --- a/packages/typegpu/tests/unroll.test.ts +++ b/packages/typegpu/tests/unroll.test.ts @@ -1,7 +1,7 @@ import { describe, expect } from 'vitest'; import { it } from 'typegpu-testing-utility'; import * as d from '../src/data/index.ts'; -import tgpu, { std } from '../src/index.js'; +import tgpu, { std } from 'typegpu'; describe('tgpu.unroll', () => { it('called outside the gpu function returns passed iterable', () => { diff --git a/packages/typegpu/tests/variable.test.ts b/packages/typegpu/tests/variable.test.ts index fc425ab9ef..dc98bf5ac3 100644 --- a/packages/typegpu/tests/variable.test.ts +++ b/packages/typegpu/tests/variable.test.ts @@ -1,6 +1,6 @@ import { describe, expect, it } from 'vitest'; import type { TgpuVar, VariableScope } from '../src/core/variable/tgpuVariable.ts'; -import tgpu, { d, std } from '../src/index.js'; +import tgpu, { d, std } from 'typegpu'; describe('tgpu.privateVar|tgpu.workgroupVar', () => { it('should inject variable declaration when used in functions', () => { diff --git a/packages/typegpu/tests/vector.test.ts b/packages/typegpu/tests/vector.test.ts index 87149c62a0..f157574fce 100644 --- a/packages/typegpu/tests/vector.test.ts +++ b/packages/typegpu/tests/vector.test.ts @@ -2,7 +2,7 @@ import { BufferReader, BufferWriter } from 'typed-binary'; import { describe, expect, expectTypeOf, it } from 'vitest'; import { readData, writeData } from '../src/data/dataIO.ts'; import { sizeOf } from '../src/data/sizeOf.ts'; -import tgpu, { d } from '../src/index.js'; +import tgpu, { d } from 'typegpu'; import * as std from '../src/std/index.ts'; describe('constructors', () => { diff --git a/packages/typegpu/tests/vertexLayout.test.ts b/packages/typegpu/tests/vertexLayout.test.ts index b107968e88..f4e002cd12 100644 --- a/packages/typegpu/tests/vertexLayout.test.ts +++ b/packages/typegpu/tests/vertexLayout.test.ts @@ -1,73 +1,5 @@ -import { describe, expect, expectTypeOf, it } from 'vitest'; -import { connectAttributesToShader } from '../src/core/vertexLayout/connectAttributesToShader.ts'; -import type { ArrayToContainedAttribs } from '../src/core/vertexLayout/vertexAttribute.ts'; -import tgpu, { d } from '../src/index.js'; -import type { TgpuVertexAttrib } from '../src/shared/vertexFormat.ts'; - -describe('ArrayToContainedAttribs', () => { - it('processes a loose array of uint8x2', () => { - type Result = ArrayToContainedAttribs>; - - expectTypeOf().toEqualTypeOf>(); - }); - - it('processes a loose array of unorm10-10-10-2', () => { - type Result = ArrayToContainedAttribs>; - - expectTypeOf().toEqualTypeOf>(); - }); - - it('processes an array of u32s', () => { - type Result = ArrayToContainedAttribs>; - - expectTypeOf().toEqualTypeOf>(); - }); - - it('processes a loose array of f32s', () => { - type Result = ArrayToContainedAttribs>; - - expectTypeOf().toEqualTypeOf>(); - }); - - it('processes a loose array of structs', () => { - type Result = ArrayToContainedAttribs>>; - - expectTypeOf().toEqualTypeOf<{ - a: TgpuVertexAttrib<'float32'>; - b: TgpuVertexAttrib<'float32'>; - }>(); - }); - - it('processes a loose array of loose struct', () => { - type Result = ArrayToContainedAttribs>>; - - expectTypeOf().toEqualTypeOf<{ - a: TgpuVertexAttrib<'float32'>; - b: TgpuVertexAttrib<'float32'>; - }>(); - }); - - it('processes an array of structs', () => { - type Result = ArrayToContainedAttribs>>; - - expectTypeOf().toEqualTypeOf<{ - a: TgpuVertexAttrib<'float32'>; - b: TgpuVertexAttrib<'float32'>; - }>(); - }); - - it('processes an array of f16s', () => { - type Result = ArrayToContainedAttribs>; - - expectTypeOf().toEqualTypeOf>(); - }); - - it('processes a loose array of snorm16x2', () => { - type Result = ArrayToContainedAttribs>; - - expectTypeOf().toEqualTypeOf>(); - }); -}); +import { describe, expect, it } from 'vitest'; +import tgpu, { d } from 'typegpu'; describe('tgpu.vertexLayout', () => { it('creates attributes from loose array of vec3f', () => { @@ -150,253 +82,3 @@ describe('tgpu.vertexLayout', () => { }); }); }); - -describe('connectAttributesToShader', () => { - it('connects a single f32 attribute', () => { - const shaderInputLayout = d.f32; - const layout = tgpu.vertexLayout(d.arrayOf(d.f32)); - const attrib = layout.attrib; - - expect(connectAttributesToShader(shaderInputLayout, attrib)).toStrictEqual({ - bufferDefinitions: [ - { - arrayStride: 4, - stepMode: 'vertex', - attributes: [ - { - format: 'float32', - offset: 0, - shaderLocation: 0, - }, - ], - }, - ], - usedVertexLayouts: [layout], - }); - }); - - it('connects a single vec4f attribute (with custom shader location)', () => { - const shaderInputLayout = d.location(3, d.vec4f); - const layout = tgpu.vertexLayout((n: number) => d.disarrayOf(d.unorm16x4, n)); - const attrib = layout.attrib; - - expect(connectAttributesToShader(shaderInputLayout, attrib)).toStrictEqual({ - bufferDefinitions: [ - { - arrayStride: 8, - stepMode: 'vertex', - attributes: [ - { - format: 'unorm16x4', - offset: 0, - shaderLocation: 3, - }, - ], - }, - ], - usedVertexLayouts: [layout], - }); - }); - - it('connects a record of attributes from a single layout', () => { - const shaderInputLayout = { - a: d.f32, - b: d.location(3, d.vec2f), - c: d.u32 /* should get @location(4) automatically */, - }; - - const layout = tgpu.vertexLayout((n: number) => - d.disarrayOf( - d.unstruct({ - alpha: d.f32, // 4 bytes - beta: d.unorm8x2, // 2 bytes - gamma: d.u32, // 4 bytes - }), - n, - ), - ); - - const result = connectAttributesToShader(shaderInputLayout, { - // purposefully out of order, which should be controlled by the shader input. - b: layout.attrib.beta, - c: layout.attrib.gamma, - a: layout.attrib.alpha, - }); - - expect(result).toStrictEqual({ - bufferDefinitions: [ - { - arrayStride: 10, - stepMode: 'vertex', - attributes: [ - { - format: 'float32', - offset: 0, - shaderLocation: 0, - }, - { - format: 'unorm8x2', - offset: 4, - shaderLocation: 3, - }, - { - format: 'uint32', - offset: 6, - shaderLocation: 4, - }, - ], - }, - ], - usedVertexLayouts: [layout], - }); - }); - - it('connects a record of attributes from multiple layouts', () => { - const shaderInputLayout = { - vi: d.builtin.vertexIndex, // should be omitted - a: d.f32, - b: d.location(3, d.vec2f), - c: d.u32 /* should get @location(4) automatically */, - }; - - const alphaBetaLayout = tgpu.vertexLayout((n: number) => - d.disarrayOf( - d.unstruct({ - alpha: d.f32, // 4 bytes - beta: d.unorm8x2, // 2 bytes - }), - n, - ), - ); - - const gammaLayout = tgpu.vertexLayout(d.arrayOf(d.u32)); - - const result = connectAttributesToShader(shaderInputLayout, { - // purposefully out of order, which should be controlled by the shader input. - b: alphaBetaLayout.attrib.beta, - c: gammaLayout.attrib, - a: alphaBetaLayout.attrib.alpha, - }); - - expect(result).toStrictEqual({ - bufferDefinitions: [ - { - arrayStride: 6, - stepMode: 'vertex', - attributes: [ - { - format: 'float32', - offset: 0, - shaderLocation: 0, - }, - { - format: 'unorm8x2', - offset: 4, - shaderLocation: 3, - }, - ], - }, - { - arrayStride: 4, - stepMode: 'vertex', - attributes: [ - { - format: 'uint32', - offset: 0, - shaderLocation: 4, - }, - ], - }, - ], - usedVertexLayouts: [alphaBetaLayout, gammaLayout], - }); - }); - - it('connects a single vec4h attribute', () => { - const shaderInputLayout = d.vec4h; - const layout = tgpu.vertexLayout((n: number) => d.disarrayOf(d.float16x4, n)); - const attrib = layout.attrib; - - expect(connectAttributesToShader(shaderInputLayout, attrib)).toStrictEqual({ - bufferDefinitions: [ - { - arrayStride: 8, - stepMode: 'vertex', - attributes: [ - { - format: 'float16x4', - offset: 0, - shaderLocation: 0, - }, - ], - }, - ], - usedVertexLayouts: [layout], - }); - }); - - it('connects a record of attributes from a single layout (with f16 variants)', () => { - const shaderInputLayout = { - a: d.f16, - b: d.location(3, d.vec2h), - c: d.u32 /* should get @location(4) automatically */, - d: d.f32, - }; - - const layout = tgpu.vertexLayout((n: number) => - d.disarrayOf( - d.unstruct({ - alpha: d.f16, // 2 bytes - beta: d.float16x2, // 4 bytes - gamma: d.u32, // 4 bytes - delta: d.float16, // 2 bytes - }), - n, - ), - ); - - const result = connectAttributesToShader(shaderInputLayout, { - // purposefully out of order, which should be controlled by the shader input. - b: layout.attrib.beta, - c: layout.attrib.gamma, - d: layout.attrib.delta, - a: layout.attrib.alpha, - }); - - expect(result).toStrictEqual({ - bufferDefinitions: [ - { - arrayStride: 12, - stepMode: 'vertex', - attributes: [ - { - format: 'float16', - offset: 0, - shaderLocation: 0, - }, - { - format: 'float16x2', - offset: 2, - shaderLocation: 3, - }, - { - format: 'uint32', - offset: 6, - shaderLocation: 4, - }, - { - format: 'float16', - offset: 10, - shaderLocation: 5, - }, - ], - }, - ], - usedVertexLayouts: [layout], - }); - }); - - it('throws when trying to use type that has no attribute representation', () => { - expect(() => tgpu.vertexLayout(d.disarrayOf(d.vec3h))).toThrow(); - }); -}); diff --git a/packages/typegpu/vitest.config.mts b/packages/typegpu/vitest.config.mts index 18da22bbb0..dd1bca02de 100644 --- a/packages/typegpu/vitest.config.mts +++ b/packages/typegpu/vitest.config.mts @@ -1,13 +1,17 @@ import { createJiti } from 'jiti'; import type TypeGPUPlugin from 'unplugin-typegpu/vite'; import { defineConfig } from 'vitest/config'; +import { TEST_BUILT_CODE } from '../../env.ts'; const jiti = createJiti(import.meta.url); const typegpu = await jiti.import('unplugin-typegpu/vite', { default: true }); +const defaultExclude = ['**/node_modules/**', '**/.git/**']; + export default defineConfig({ plugins: [typegpu({ forceTgpuAlias: 'tgpu', earlyPruning: false })], test: { globalSetup: ['setupVitest.ts'], + exclude: TEST_BUILT_CODE ? [...defaultExclude, '**/internal/**'] : defaultExclude, }, }); diff --git a/setupVitest.ts b/setupVitest.ts new file mode 100644 index 0000000000..6ac4383e19 --- /dev/null +++ b/setupVitest.ts @@ -0,0 +1,62 @@ +import * as fs from 'node:fs/promises'; +import { existsSync, readdirSync, writeFileSync } from 'node:fs'; +import { join } from 'node:path'; +import { TEST_BUILT_CODE } from './env.ts'; + +if (TEST_BUILT_CODE === undefined) { + throw new Error('TEST_BUILT_CODE must be "true" or "false"'); +} + +const PACKAGES_DIR = join(import.meta.dirname, 'packages'); + +interface PackageJson { + name: string; + main?: string | undefined; + types?: string | undefined; + exports?: Record | undefined; + publishConfig?: { + main?: string | undefined; + types?: string | undefined; + exports?: Record | undefined; + }; +} + +export default async () => { + if (!TEST_BUILT_CODE) { + // Skip changing package.json to use built packages + return; + } + + const packageJsonPaths = readdirSync(PACKAGES_DIR, { withFileTypes: true }) + .filter((dirent) => dirent.isDirectory()) + .map((dirent) => join(PACKAGES_DIR, dirent.name, 'package.json')); + + const onExit: (() => void)[] = []; + + await Promise.all( + packageJsonPaths.map(async (path) => { + if (!existsSync(path)) return; + + const originalContent = await fs.readFile(path, 'utf-8'); + const packageJson: PackageJson = JSON.parse(originalContent); + + packageJson.main = packageJson.publishConfig?.main ?? packageJson.main; + packageJson.types = packageJson.publishConfig?.types ?? packageJson.types; + packageJson.exports = packageJson.publishConfig?.exports ?? packageJson.exports; + + await fs.writeFile(path, JSON.stringify(packageJson, null, 2), 'utf-8'); + + onExit.push(() => { + writeFileSync(path, originalContent, 'utf-8'); + }); + }), + ); + + process.on('SIGINT', () => { + onExit.forEach((cb) => cb()); + }); + + return () => { + onExit.forEach((cb) => cb()); + }; +}; diff --git a/vitest.config.mts b/vitest.config.mts index 2372abc9ac..0d90030057 100644 --- a/vitest.config.mts +++ b/vitest.config.mts @@ -2,6 +2,7 @@ import { defineConfig } from 'vitest/config'; export default defineConfig({ test: { + globalSetup: ['./setupVitest.ts'], projects: ['packages/*', 'apps/*'], }, });