Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
3 changes: 3 additions & 0 deletions env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const TEST_BUILT_CODE = process.env.TEST_BUILT_CODE
? { true: true, false: false }[process.env.TEST_BUILT_CODE]
: undefined;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions packages/typegpu-color/src/oklab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion packages/typegpu/tests/accessor.test.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand Down Expand Up @@ -36,7 +36,7 @@
return colorAccess.$;
};

expect(tgpu.resolve([getColor])).toMatchInlineSnapshot(`

Check failure on line 39 in packages/typegpu/tests/accessor.test.ts

View workflow job for this annotation

GitHub Actions / build-and-test

[typegpu] tests/accessor.test.ts > tgpu.accessor > resolves to invocation of provided shellless callback

Error: Snapshot `tgpu.accessor > resolves to invocation of provided shellless callback 1` mismatched - Expected + Received - "fn colorAccess() -> vec3f { + "fn item() -> vec3f { return vec3f(1, 2, 3); } fn getColor() -> vec3f { - return colorAccess(); + return item(); }" ❯ tests/accessor.test.ts:39:38
"fn colorAccess() -> vec3f {
return vec3f(1, 2, 3);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/typegpu/tests/align.test.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/typegpu/tests/array.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 { 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';
Expand Down Expand Up @@ -521,7 +521,7 @@
return arrayLength(layout.$.values);
});

expect(tgpu.resolve([testFn])).toMatchInlineSnapshot(`

Check failure on line 524 in packages/typegpu/tests/array.test.ts

View workflow job for this annotation

GitHub Actions / build-and-test

[typegpu] tests/array.test.ts > array.length > arrayLength > returns the length of a static array

Error: Resolution of the following tree failed: - <root> - fn:testFn: Function 'arrayLength' is not marked with the 'use gpu' directive and cannot be used in a shader ❯ tests/array.test.ts:524:19 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { trace: [ { toString: 'Function<toString>' }, 'Function<impl>' ], appendToTrace: 'Function<appendToTrace>' } Caused by: Caused by: Error: Function 'arrayLength' is not marked with the 'use gpu' directive and cannot be used in a shader
"fn testFn() -> i32 {
return 5;
}"
Expand All @@ -544,7 +544,7 @@
return arrayLength(layout.$.values);
});

expect(tgpu.resolve([testFn])).toMatchInlineSnapshot(`

Check failure on line 547 in packages/typegpu/tests/array.test.ts

View workflow job for this annotation

GitHub Actions / build-and-test

[typegpu] tests/array.test.ts > array.length > arrayLength > returns the length of a dynamic array

Error: Resolution of the following tree failed: - <root> - fn:testFn: Function 'arrayLength' is not marked with the 'use gpu' directive and cannot be used in a shader ❯ tests/array.test.ts:547:19 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { trace: [ { toString: 'Function<toString>' }, 'Function<impl>' ], appendToTrace: 'Function<appendToTrace>' } Caused by: Caused by: Error: Function 'arrayLength' is not marked with the 'use gpu' directive and cannot be used in a shader
"@group(0) @binding(0) var<storage, read_write> values: array<f32>;

fn testFn() -> u32 {
Expand Down
2 changes: 1 addition & 1 deletion packages/typegpu/tests/attributes.test.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/typegpu/tests/bindGroupLayout.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
type TgpuBuffer,
type TgpuTextureView,
type UniformFlag,
} from '../src/index.js';
} from 'typegpu';
import {
type ExtractBindGroupInputFromLayout,
MissingBindingError,
Expand Down Expand Up @@ -73,7 +73,7 @@

root.unwrap(bindGroup);

expect(root.device.createBindGroup).toBeCalledWith({

Check failure on line 76 in packages/typegpu/tests/bindGroupLayout.test.ts

View workflow job for this annotation

GitHub Actions / build-and-test

[typegpu] tests/bindGroupLayout.test.ts > TgpuBindGroupLayout > works for entries passed as functions returning TgpuData

AssertionError: expected "vi.fn()" to be called with arguments: [ { label: 'layout', …(2) } ] Received: 1st vi.fn() call: @@ -30,9 +30,9 @@ "usage": 140, }, }, }, ], - "label": "layout", + "label": "<unnamed>", "layout": "mockBindGroupLayout", }, ] Number of calls: 1 ❯ tests/bindGroupLayout.test.ts:76:41
label: 'layout',
layout: root.unwrap(layout),
entries: [
Expand Down Expand Up @@ -130,7 +130,7 @@

root.unwrap(layout); // Creating the WebGPU resource

expect(root.device.createBindGroupLayout).toBeCalledWith({

Check failure on line 133 in packages/typegpu/tests/bindGroupLayout.test.ts

View workflow job for this annotation

GitHub Actions / build-and-test

[typegpu] tests/bindGroupLayout.test.ts > TgpuBindGroupLayout > omits null properties

AssertionError: expected "vi.fn()" to be called with arguments: [ { label: 'layout', …(1) } ] Received: 1st vi.fn() call: @@ -14,8 +14,8 @@ "type": "read-only-storage", }, "visibility": 7, }, ], - "label": "layout", + "label": "<unnamed>", }, ] Number of calls: 1 ❯ tests/bindGroupLayout.test.ts:133:47
label: 'layout',
entries: [
{
Expand Down Expand Up @@ -158,7 +158,7 @@

const main = tgpu.fn([])`() { textureLoad(layout.$.fooTexture); }`.$uses({ layout });

expect(tgpu.resolve([main])).toMatchInlineSnapshot(`

Check failure on line 161 in packages/typegpu/tests/bindGroupLayout.test.ts

View workflow job for this annotation

GitHub Actions / build-and-test

[typegpu] tests/bindGroupLayout.test.ts > TgpuBindGroupLayout > resolves textures to valid WGSL code

Error: Snapshot `TgpuBindGroupLayout > resolves textures to valid WGSL code 1` mismatched - Expected + Received "@group(0) @binding(0) var fooTexture: texture_1d<f32>; - fn main() { textureLoad(fooTexture); }" + fn item() { textureLoad(fooTexture); }" ❯ tests/bindGroupLayout.test.ts:161:34
"@group(0) @binding(0) var fooTexture: texture_1d<f32>;

fn main() { textureLoad(fooTexture); }"
Expand Down
2 changes: 1 addition & 1 deletion packages/typegpu/tests/buffer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion packages/typegpu/tests/bufferShorthands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type {
TgpuReadonly,
TgpuUniform,
UniformFlag,
} from '../src/index.js';
} from 'typegpu';
import { attest } from '@ark/attest';

describe('root.createMutable', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/typegpu/tests/bufferUsage.test.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
2 changes: 1 addition & 1 deletion packages/typegpu/tests/computePipeline.test.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
2 changes: 1 addition & 1 deletion packages/typegpu/tests/constant.test.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/typegpu/tests/data/atomic.test.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down
6 changes: 4 additions & 2 deletions packages/typegpu/tests/data/deepEqual.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/typegpu/tests/data/ptr.test.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/typegpu/tests/data/schemaCallWrapper.test.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/typegpu/tests/declare.test.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/typegpu/tests/entryFnBuiltinArgs.test.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/typegpu/tests/entryFnHeaderGen.test.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/typegpu/tests/function.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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([])`() {
Expand Down
2 changes: 1 addition & 1 deletion packages/typegpu/tests/functionTagged.test.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/typegpu/tests/indent.test.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down
69 changes: 69 additions & 0 deletions packages/typegpu/tests/internal/arrayToContainedAttribs.test.ts
Original file line number Diff line number Diff line change
@@ -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<d.Disarray<d.uint8x2>>;

expectTypeOf<Result>().toEqualTypeOf<TgpuVertexAttrib<'uint8x2'>>();
});

it('processes a loose array of unorm10-10-10-2', () => {
type Result = ArrayToContainedAttribs<d.Disarray<d.unorm10_10_10_2>>;

expectTypeOf<Result>().toEqualTypeOf<TgpuVertexAttrib<'unorm10-10-10-2'>>();
});

it('processes an array of u32s', () => {
type Result = ArrayToContainedAttribs<d.WgslArray<d.U32>>;

expectTypeOf<Result>().toEqualTypeOf<TgpuVertexAttrib<'uint32'>>();
});

it('processes a loose array of f32s', () => {
type Result = ArrayToContainedAttribs<d.Disarray<d.F32>>;

expectTypeOf<Result>().toEqualTypeOf<TgpuVertexAttrib<'float32'>>();
});

it('processes a loose array of structs', () => {
type Result = ArrayToContainedAttribs<d.Disarray<d.WgslStruct<{ a: d.F32; b: d.F32 }>>>;

expectTypeOf<Result>().toEqualTypeOf<{
a: TgpuVertexAttrib<'float32'>;
b: TgpuVertexAttrib<'float32'>;
}>();
});

it('processes a loose array of loose struct', () => {
type Result = ArrayToContainedAttribs<d.Disarray<d.Unstruct<{ a: d.F32; b: d.F32 }>>>;

expectTypeOf<Result>().toEqualTypeOf<{
a: TgpuVertexAttrib<'float32'>;
b: TgpuVertexAttrib<'float32'>;
}>();
});

it('processes an array of structs', () => {
type Result = ArrayToContainedAttribs<d.Disarray<d.Unstruct<{ a: d.F32; b: d.F32 }>>>;

expectTypeOf<Result>().toEqualTypeOf<{
a: TgpuVertexAttrib<'float32'>;
b: TgpuVertexAttrib<'float32'>;
}>();
});

it('processes an array of f16s', () => {
type Result = ArrayToContainedAttribs<d.WgslArray<d.F16>>;

expectTypeOf<Result>().toEqualTypeOf<TgpuVertexAttrib<'float16'>>();
});

it('processes a loose array of snorm16x2', () => {
type Result = ArrayToContainedAttribs<d.Disarray<d.snorm16x2>>;

expectTypeOf<Result>().toEqualTypeOf<TgpuVertexAttrib<'snorm16x2'>>();
});
});
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
Loading
Loading