Skip to content

Commit 306ba74

Browse files
authored
Merge branch 'main' into patch-1
2 parents 1088979 + 0186fac commit 306ba74

19 files changed

Lines changed: 314 additions & 58 deletions

File tree

apps/typegpu-docs/src/examples/image-processing/image-tuning/index.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,16 +259,17 @@ async function updateLUT(file: string) {
259259

260260
// #region Example controls and cleanup
261261

262+
// Some of the files became corrupted
262263
const LUTFiles = {
263264
None: '',
264-
Chrome:
265-
'https://raw.githubusercontent.com/abpy/FujifilmCameraProfiles/refs/heads/master/cube%20lut/classic%20chrome.cube',
265+
// Chrome:
266+
// 'https://raw.githubusercontent.com/abpy/FujifilmCameraProfiles/refs/heads/master/cube%20lut/classic%20chrome.cube',
266267
Hollywood:
267268
'https://raw.githubusercontent.com/changyun233/Lumix-V-log-LUTs/refs/heads/main/luts/lumix_color_lab_A/HollywoodBlue_Day.cube',
268269
Dramatic:
269270
'https://raw.githubusercontent.com/changyun233/Lumix-V-log-LUTs/refs/heads/main/recommended/Dramatic_BlockBuster_33.cube',
270-
'Pro Neg':
271-
'https://raw.githubusercontent.com/abpy/FujifilmCameraProfiles/refs/heads/master/cube%20lut/srgb/pro%20neg%20hi_srgb.cube',
271+
// 'Pro Neg':
272+
// 'https://raw.githubusercontent.com/abpy/FujifilmCameraProfiles/refs/heads/master/cube%20lut/srgb/pro%20neg%20hi_srgb.cube',
272273
'Cold Ice':
273274
'https://raw.githubusercontent.com/aras-p/smol-cube/refs/heads/main/tests/luts/tinyglade-Cold_Ice.cube',
274275
Bluecine:

apps/typegpu-docs/src/examples/image-processing/selfie-segmentation/frame.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,33 @@ export interface VideoFrameCrop {
44
sourceSize: [number, number];
55
cropOrigin: [number, number];
66
cropSize: [number, number];
7+
uvTransform: d.m2x2f;
78
}
89

910
export const FrameCropParams = d.struct({
1011
sourceSize: d.vec2u,
1112
cropOrigin: d.vec2f,
1213
cropSize: d.vec2f,
14+
uvTransform: d.mat2x2f,
1315
});
1416

1517
export const initialFrameCropParams: VideoFrameCrop = {
1618
sourceSize: [1, 1],
1719
cropOrigin: [0, 0],
1820
cropSize: [1, 1],
21+
uvTransform: d.mat2x2f.identity(),
1922
};
2023

21-
export function squareCrop(sourceWidth: number, sourceHeight: number): VideoFrameCrop {
24+
export function squareCrop(
25+
sourceWidth: number,
26+
sourceHeight: number,
27+
uvTransform: d.m2x2f,
28+
): VideoFrameCrop {
2229
const size = Math.min(sourceWidth, sourceHeight);
2330
return {
2431
sourceSize: [sourceWidth, sourceHeight],
2532
cropOrigin: [Math.floor((sourceWidth - size) / 2), Math.floor((sourceHeight - size) / 2)],
2633
cropSize: [size, size],
34+
uvTransform,
2735
};
2836
}

apps/typegpu-docs/src/examples/image-processing/selfie-segmentation/index.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ export const compositeFragment = tgpu.fragmentFn({
7070
'use gpu';
7171
const cropUv = d.vec2f(1 - uv.x, uv.y);
7272
const sourcePixel = compositeUniform.$.cropOrigin + cropUv * compositeUniform.$.cropSize;
73-
const cameraUv = sourcePixel / d.vec2f(compositeUniform.$.sourceSize);
73+
const sourceUv = sourcePixel / d.vec2f(compositeUniform.$.sourceSize);
74+
const cameraUv = compositeUniform.$.uvTransform * (sourceUv - 0.5) + 0.5;
7475
const cameraColor = std.textureSampleBaseClampToEdge(
7576
compositeFrameLayout.$.frame,
7677
sampler.$,
@@ -108,13 +109,33 @@ video.srcObject = await navigator.mediaDevices.getUserMedia({
108109

109110
let videoFrameCallbackId = 0;
110111
let postProcessProfile: MaskPostProcessProfile = 'balanced';
112+
let uvTransform = d.mat2x2f.identity();
113+
114+
const isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent);
115+
function setUVTransformForIOS() {
116+
const angle = screen.orientation.type;
117+
118+
uvTransform = d.mat2x2f.identity();
119+
if (angle === 'portrait-primary') {
120+
uvTransform = d.mat2x2f(0, -1, 1, 0);
121+
} else if (angle === 'portrait-secondary') {
122+
uvTransform = d.mat2x2f(0, 1, -1, 0);
123+
} else if (angle === 'landscape-primary') {
124+
uvTransform = d.mat2x2f(-1, 0, 0, -1);
125+
}
126+
}
127+
128+
if (isIOS) {
129+
setUVTransformForIOS();
130+
window.addEventListener('orientationchange', setUVTransformForIOS);
131+
}
111132

112133
function processVideoFrame(_: number, metadata: VideoFrameCallbackMetadata) {
113134
if (video.readyState < 2) {
114135
videoFrameCallbackId = video.requestVideoFrameCallback(processVideoFrame);
115136
return;
116137
}
117-
const crop = squareCrop(metadata.width, metadata.height);
138+
const crop = squareCrop(metadata.width, metadata.height, uvTransform);
118139
const externalTexture = root.device.importExternalTexture({ source: video });
119140
const encoder = root.device.createCommandEncoder();
120141
const pass = encoder.beginComputePass();
@@ -175,6 +196,9 @@ export const controls = defineControls({
175196

176197
export function onCleanup() {
177198
video.cancelVideoFrameCallback(videoFrameCallbackId);
199+
if (isIOS) {
200+
window.removeEventListener('orientationchange', setUVTransformForIOS);
201+
}
178202
if (video.srcObject) {
179203
for (const track of (video.srcObject as MediaStream).getTracks()) {
180204
track.stop();

apps/typegpu-docs/src/examples/image-processing/selfie-segmentation/inference/video-preprocess.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,11 @@ export const videoPreprocessKernel = tgpu.computeFn({
4646
const coord = d.vec2u(i & MODEL_COORD_MASK, std.bitShiftRight(i, MODEL_COORD_SHIFT));
4747
const pixel = d.vec2f(coord) + 0.5;
4848
const cropUv = d.vec2f(MODEL_SIZE.x - pixel.x, pixel.y) / MODEL_SIZE;
49-
const uv =
49+
const sourceUv =
5050
(videoFrameParamsLayout.$.params.cropOrigin +
5151
cropUv * videoFrameParamsLayout.$.params.cropSize) /
5252
d.vec2f(videoFrameParamsLayout.$.params.sourceSize);
53+
const uv = videoFrameParamsLayout.$.params.uvTransform * (sourceUv - 0.5) + 0.5;
5354

5455
const color = std.textureSampleBaseClampToEdge(
5556
videoFrameFrameLayout.$.frame,

apps/typegpu-docs/src/examples/image-processing/selfie-segmentation/post-processing/kernels.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export const UpsampleParams = d.struct({
4646
sourceSize: d.vec2u,
4747
cropOrigin: d.vec2f,
4848
cropSize: d.vec2f,
49+
uvTransform: d.mat2x2f,
4950
edgeAware: d.u32,
5051
});
5152

@@ -167,7 +168,8 @@ const cameraUvFromScreenUv = (uv: d.v2f) => {
167168
const cropUv = d.vec2f(1 - uv.x, uv.y);
168169
const sourcePixel =
169170
upsampleParamsLayout.$.params.cropOrigin + cropUv * upsampleParamsLayout.$.params.cropSize;
170-
return sourcePixel / d.vec2f(upsampleParamsLayout.$.params.sourceSize);
171+
const sourceUv = sourcePixel / d.vec2f(upsampleParamsLayout.$.params.sourceSize);
172+
return upsampleParamsLayout.$.params.uvTransform * (sourceUv - 0.5) + 0.5;
171173
};
172174

173175
const cameraColorAtScreenUv = (uv: d.v2f) => {

packages/typegpu-cli/README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
1-
# tgpu
1+
# @typegpu/cli
22
Create a new TypeGPU project or enhance an existing one.
33

44
## Creating
5-
To run interactive project scaffolding
5+
To run interactive project scaffolding:
66

77
```sh
8-
pnpm dlx tgpu@latest
8+
pnpm dlx typegpu@latest
99
# or
10-
npx tgpu@latest
10+
npx typegpu@latest
1111
# or
12-
yarn dlx tgpu@latest
12+
yarn dlx typegpu@latest
1313
# or
14-
bunx tgpu@latest
14+
bunx typegpu@latest
1515
```
1616

1717
## Enhancing
18-
Run inside the root of an existing Vite project:
18+
Run inside the root of an existing project:
1919

2020
```sh
21-
pnpm dlx tgpu@latest -e
21+
pnpm dlx typegpu@latest -e
2222
# or
23-
npx tgpu@latest -e
23+
npx typegpu@latest -e
2424
# or
25-
yarn dlx tgpu@latest -e
25+
yarn dlx typegpu@latest -e
2626
# or
27-
bunx tgpu@latest -e
27+
bunx typegpu@latest -e
2828
```
2929

3030
> [!CAUTION]

packages/typegpu-cli/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
22
"name": "@typegpu/cli",
3-
"version": "0.11.1",
3+
"version": "0.11.2",
44
"description": "Add TypeGPU to your project",
55
"license": "MIT",
66
"repository": {
77
"type": "git",
88
"url": "git+https://github.com/software-mansion/TypeGPU.git#main",
9-
"directory": "packages/tgpu"
9+
"directory": "packages/typegpu-cli"
1010
},
1111
"bin": "./dist/index.js",
1212
"files": [

packages/typegpu-cli/src/create.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { askForAgentSkills } from './steps/skills.ts';
1111
const DEFAULT_PROJECT_DIR = 'tgpu-project';
1212

1313
const GRADIENT_START = [0.831, 0.553, 1.0] as const;
14-
const GRADIENT_END = [0.216, 0.263, 0.82] as const;
14+
const GRADIENT_END = [0.32, 0.4, 0.95] as const;
1515

1616
const PROJECT_TEMPLATES = [
1717
{
@@ -72,8 +72,7 @@ export async function createProject(cwd: string) {
7272
p.log.success(`Scaffolded project at ${projectName}.`);
7373

7474
const detected = await detect({ cwd: root });
75-
const inferredPm = detected?.agent ?? pmFromUserAgent(process.env.npm_config_user_agent);
76-
const pm = projectTemplate === 'expo-simple' && inferredPm === 'npm' ? 'yarn' : inferredPm;
75+
const pm = detected?.agent ?? pmFromUserAgent(process.env.npm_config_user_agent);
7776
const shouldInstall = await confirmStep(`Install dependencies with ${pm}?`, true);
7877
process.chdir(root);
7978

@@ -85,12 +84,12 @@ export async function createProject(cwd: string) {
8584

8685
const cdPath = path.relative(cwd, root);
8786
const installCmd = resolveCommand(pm, 'install', []);
88-
const prebuildCmd =
89-
projectTemplate === 'expo-simple' ? { command: 'npx', args: ['expo', 'prebuild'] } : undefined;
90-
const runCmd =
91-
projectTemplate === 'expo-simple'
92-
? resolveCommand(pm, 'run', ['ios # or android'])
93-
: resolveCommand(pm, 'run', ['dev']);
87+
const prebuildCmd = projectTemplate.includes('expo')
88+
? { command: 'npx', args: ['expo', 'prebuild'] }
89+
: undefined;
90+
const runCmd = projectTemplate.includes('expo')
91+
? resolveCommand(pm, 'run', ['ios # or android'])
92+
: resolveCommand(pm, 'run', ['dev']);
9493

9594
const steps: string[] = [];
9695
const shouldCd = (!shouldInstall && !!installCmd) || !!runCmd || !!cdPath;

packages/typegpu-cli/templates/template-expo-simple/_package.json

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,32 @@
1818
"react": "19.1.0",
1919
"react-dom": "19.1.0",
2020
"react-native": "0.81.5",
21-
"react-native-safe-area-context": "^5.6.2",
21+
"react-native-safe-area-context": "~5.6.0",
2222
"react-native-web": "^0.21.0",
2323
"react-native-wgpu": "^0.5.9",
2424
"typegpu": "^0.11.6",
2525
"unplugin-typegpu": "^0.11.4"
2626
},
2727
"devDependencies": {
2828
"@babel/core": "^7.28.5",
29-
"babel-preset-expo": "^54.0.0",
30-
"@types/react": "~19.2.2",
29+
"@types/react": "~19.1.10",
3130
"@webgpu/types": "^0.1.69",
31+
"babel-preset-expo": "^54.0.0",
32+
"eslint": "^9.38.0",
3233
"eslint-plugin-typegpu": "^0.11.1",
3334
"oxfmt": "^0.49.0",
3435
"oxlint": "^1.64.0",
35-
"typescript": "npm:tsover@6.0.1"
36+
"typescript": "npm:tsover@5.9.2"
37+
},
38+
"resolutions": {
39+
"typescript": "npm:tsover@5.9.2"
3640
},
3741
"overrides": {
38-
"typescript": "npm:tsover@6.0.1"
42+
"typescript": "npm:tsover@5.9.2"
3943
},
4044
"pnpm": {
4145
"overrides": {
42-
"typescript": "npm:tsover@6.0.1"
46+
"typescript": "npm:tsover@5.9.2"
4347
}
4448
}
4549
}

packages/typegpu/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "typegpu",
3-
"version": "0.11.7",
3+
"version": "0.11.8",
44
"description": "A thin layer between JS and WebGPU/WGSL that improves development experience and allows for faster iteration.",
55
"keywords": [
66
"compute",

0 commit comments

Comments
 (0)