Skip to content

Commit c8532de

Browse files
committed
Merged relevant changes from 0.3
1 parent 5af7fcc commit c8532de

File tree

9 files changed

+74
-284
lines changed

9 files changed

+74
-284
lines changed

packages/jit/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@
5555
"devDependencies": {
5656
"typescript": "^5.3.3",
5757
"tsup": "^8.0.2",
58-
"typegpu": "workspace:*",
5958
"@typegpu/tgpu-dev-cli": "workspace:*",
6059
"vitest": "^2.1.5"
6160
},
6261
"packageManager": "pnpm@8.15.8+sha256.691fe176eea9a8a80df20e4976f3dfb44a04841ceb885638fe2a26174f81e65e",
6362
"dependencies": {
6463
"acorn": "^8.12.1",
64+
"tinyest": "workspace:~0.0.0",
6565
"@typegpu/tgsl-tools": "workspace:~0.0.0"
6666
}
6767
}

packages/jit/src/index.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,26 @@
11
import { transpileFn } from '@typegpu/tgsl-tools';
22
import { parse } from 'acorn';
3-
import type { JitTranspiler as IJitTranspiler } from 'typegpu/experimental';
3+
import type { Block } from 'tinyest';
4+
5+
/**
6+
* Information extracted from transpiling a JS function.
7+
*/
8+
type TranspilationResult = {
9+
argNames: string[];
10+
body: Block;
11+
/**
12+
* All identifiers found in the function code that are not declared in the
13+
* function itself, or in the block that is accessing that identifier.
14+
*/
15+
externalNames: string[];
16+
};
17+
18+
/**
19+
* Used to transpile JS resources into SMoL on demand.
20+
*/
21+
interface IJitTranspiler {
22+
transpileFn(rawJs: string): TranspilationResult;
23+
}
424

525
export class JitTranspiler implements IJitTranspiler {
626
transpileFn(rawJs: string) {

packages/typegpu/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
"devDependencies": {
6868
"@typegpu/tgpu-dev-cli": "workspace:*",
6969
"@typegpu/wgsl-parser": "workspace:*",
70+
"@typegpu/jit": "workspace:*",
7071
"@types/node": "^20.11.13",
7172
"@webgpu/types": "^0.1.43",
7273
"rollup-plugin-typegpu": "workspace:*",

packages/typegpu/src/experimental/index.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ import {
1616
} from '../core/root/init';
1717
import type { ExperimentalTgpuRoot } from '../core/root/rootTypes';
1818
import { vertexLayout } from '../core/vertexLayout/vertexLayout';
19-
import { createBuffer } from '../legacyBufferApi';
2019
import { bindGroupLayout } from '../tgpuBindGroupLayout';
21-
import { read, write } from '../tgpuBufferUtils';
2220

2321
export const tgpu = {
2422
/** @deprecated Use `'uniform'` string literal instead. */
@@ -44,10 +42,6 @@ export const tgpu = {
4442
) => ExperimentalTgpuRoot,
4543

4644
resolve,
47-
48-
createBuffer,
49-
read,
50-
write,
5145
};
5246

5347
// Hidden API, used only by tooling (e.g., rollup plugin).
@@ -57,16 +51,28 @@ Object.assign(tgpu, {
5751

5852
export default tgpu;
5953

60-
export * from '../errors';
61-
export * from '../types';
62-
export * from '../namable';
63-
export * from '../core/root/rootTypes';
54+
export {
55+
MissingBindGroupError,
56+
MissingLinksError,
57+
MissingSlotValueError,
58+
NotUniformError,
59+
ResolutionError,
60+
} from '../errors';
61+
export {
62+
TgpuRoot,
63+
ExperimentalTgpuRoot,
64+
WithBinding,
65+
WithCompute,
66+
WithFragment,
67+
WithVertex,
68+
} from '../core/root/rootTypes';
6469
export { StrictNameRegistry, RandomNameRegistry } from '../nameRegistry';
6570
export * from '../builtin';
6671

6772
export { default as wgsl } from '../wgsl';
6873
export { std } from '../std';
6974
export {
75+
isBuffer,
7076
isUsableAsUniform,
7177
isUsableAsVertex,
7278
} from '../core/buffer/buffer';
@@ -121,6 +127,10 @@ export type {
121127
TgpuBindGroupLayout,
122128
TgpuLayoutEntry,
123129
TgpuLayoutSampler,
130+
TgpuLayoutTexture,
131+
TgpuLayoutStorage,
132+
TgpuLayoutStorageTexture,
133+
TgpuLayoutExternalTexture,
124134
TgpuLayoutUniform,
125135
BindLayoutEntry,
126136
LayoutEntryToInput,
Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,41 @@
1-
import { describe, expect, it } from 'vitest';
1+
import { describe, expect } from 'vitest';
22
import { u32 } from '../src/data';
3-
import tgpu, { asMutable, asReadonly, asUniform } from '../src/experimental';
3+
import { asMutable, asReadonly, asUniform } from '../src/experimental';
44
import './utils/webgpuGlobals';
5+
import { it } from './utils/extendedIt';
56

67
describe('asUsage', () => {
7-
it('allows creating bufferUsages only for buffers allowing them', () => {
8-
asReadonly(tgpu.createBuffer(u32, 2).$usage('storage'));
9-
asReadonly(tgpu.createBuffer(u32, 2).$usage('storage', 'uniform'));
10-
asReadonly(tgpu.createBuffer(u32, 2).$usage('storage', 'vertex'));
8+
it('allows creating bufferUsages only for buffers allowing them', ({
9+
root,
10+
}) => {
11+
asReadonly(root.createBuffer(u32, 2).$usage('storage'));
12+
asReadonly(root.createBuffer(u32, 2).$usage('storage', 'uniform'));
13+
asReadonly(root.createBuffer(u32, 2).$usage('storage', 'vertex'));
1114
// @ts-expect-error
12-
expect(() => asReadonly(tgpu.createBuffer(u32, 2))).toThrow();
15+
expect(() => asReadonly(root.createBuffer(u32, 2))).toThrow();
1316
expect(() =>
1417
// @ts-expect-error
15-
asReadonly(tgpu.createBuffer(u32, 2).$usage('uniform')),
18+
asReadonly(root.createBuffer(u32, 2).$usage('uniform')),
1619
).toThrow();
1720

18-
asUniform(tgpu.createBuffer(u32, 2).$usage('uniform'));
19-
asUniform(tgpu.createBuffer(u32, 2).$usage('uniform', 'storage'));
20-
asUniform(tgpu.createBuffer(u32, 2).$usage('uniform', 'vertex'));
21+
asUniform(root.createBuffer(u32, 2).$usage('uniform'));
22+
asUniform(root.createBuffer(u32, 2).$usage('uniform', 'storage'));
23+
asUniform(root.createBuffer(u32, 2).$usage('uniform', 'vertex'));
2124
// @ts-expect-error
22-
expect(() => asUniform(tgpu.createBuffer(u32, 2))).toThrow();
25+
expect(() => asUniform(root.createBuffer(u32, 2))).toThrow();
2326
expect(() =>
2427
// @ts-expect-error
25-
asUniform(tgpu.createBuffer(u32, 2).$usage('storage')),
28+
asUniform(root.createBuffer(u32, 2).$usage('storage')),
2629
).toThrow();
2730

28-
asMutable(tgpu.createBuffer(u32, 2).$usage('storage'));
29-
asMutable(tgpu.createBuffer(u32, 2).$usage('storage', 'uniform'));
30-
asMutable(tgpu.createBuffer(u32, 2).$usage('vertex', 'storage'));
31+
asMutable(root.createBuffer(u32, 2).$usage('storage'));
32+
asMutable(root.createBuffer(u32, 2).$usage('storage', 'uniform'));
33+
asMutable(root.createBuffer(u32, 2).$usage('vertex', 'storage'));
3134
// @ts-expect-error
32-
expect(() => asMutable(tgpu.createBuffer(u32, 2))).toThrow();
35+
expect(() => asMutable(root.createBuffer(u32, 2))).toThrow();
3336
expect(() =>
3437
// @ts-expect-error
35-
asMutable(tgpu.createBuffer(u32, 2).$usage('uniform')),
38+
asMutable(root.createBuffer(u32, 2).$usage('uniform')),
3639
).toThrow();
3740
});
3841
});

packages/typegpu/tests/resolve.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { parse } from '@typegpu/wgsl-parser';
22
import { describe, expect, it } from 'vitest';
33
import * as d from '../src/data';
44
import tgpu, { type TgpuBufferReadonly } from '../src/experimental';
5-
import type { ResolutionCtx } from '../src/experimental';
5+
import type { ResolutionCtx } from '../src/types';
66

77
describe('tgpu resolve', () => {
88
it('should resolve a string (identity)', () => {

0 commit comments

Comments
 (0)