@snovakow/greenscreen 0.0.0-stage → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +238 -2
  3. package/dist/greenscreen.d.ts +32 -0
  4. package/dist/greenscreen.d.ts.map +1 -0
  5. package/dist/greenscreen.global.js +315 -0
  6. package/dist/greenscreen.global.js.map +1 -0
  7. package/dist/greenscreen.js +250 -0
  8. package/dist/greenscreen.js.map +1 -0
  9. package/dist/greenscreen.min.js +315 -0
  10. package/dist/greenscreen.min.js.map +1 -0
  11. package/dist/index.d.ts +6 -0
  12. package/dist/index.d.ts.map +1 -0
  13. package/dist/index.js +3 -0
  14. package/dist/index.js.map +1 -0
  15. package/dist/pack.d.ts +7 -0
  16. package/dist/pack.d.ts.map +1 -0
  17. package/dist/pack.js +63 -0
  18. package/dist/pack.js.map +1 -0
  19. package/dist/react.d.ts +26 -0
  20. package/dist/react.d.ts.map +1 -0
  21. package/dist/react.js +78 -0
  22. package/dist/react.js.map +1 -0
  23. package/dist/renderer.d.ts +19 -0
  24. package/dist/renderer.d.ts.map +1 -0
  25. package/dist/renderer.js +25 -0
  26. package/dist/renderer.js.map +1 -0
  27. package/dist/settings.d.ts +36 -0
  28. package/dist/settings.d.ts.map +1 -0
  29. package/dist/settings.js +112 -0
  30. package/dist/settings.js.map +1 -0
  31. package/dist/shader.glsl.d.ts +3 -0
  32. package/dist/shader.glsl.d.ts.map +1 -0
  33. package/dist/shader.glsl.js +179 -0
  34. package/dist/shader.glsl.js.map +1 -0
  35. package/dist/shader.wgsl.d.ts +2 -0
  36. package/dist/shader.wgsl.d.ts.map +1 -0
  37. package/dist/shader.wgsl.js +160 -0
  38. package/dist/shader.wgsl.js.map +1 -0
  39. package/dist/source.d.ts +16 -0
  40. package/dist/source.d.ts.map +1 -0
  41. package/dist/source.js +103 -0
  42. package/dist/source.js.map +1 -0
  43. package/dist/three-webgpu.d.ts +20 -0
  44. package/dist/three-webgpu.d.ts.map +1 -0
  45. package/dist/three-webgpu.js +178 -0
  46. package/dist/three-webgpu.js.map +1 -0
  47. package/dist/three.d.ts +27 -0
  48. package/dist/three.d.ts.map +1 -0
  49. package/dist/three.js +81 -0
  50. package/dist/three.js.map +1 -0
  51. package/dist/types.d.ts +4 -0
  52. package/dist/types.d.ts.map +1 -0
  53. package/dist/types.js +4 -0
  54. package/dist/types.js.map +1 -0
  55. package/dist/webgl.d.ts +13 -0
  56. package/dist/webgl.d.ts.map +1 -0
  57. package/dist/webgl.js +183 -0
  58. package/dist/webgl.js.map +1 -0
  59. package/dist/webgpu.d.ts +19 -0
  60. package/dist/webgpu.d.ts.map +1 -0
  61. package/dist/webgpu.js +303 -0
  62. package/dist/webgpu.js.map +1 -0
  63. package/package.json +103 -4
  64. package/src/global.ts +11 -0
  65. package/src/greenscreen.ts +286 -0
  66. package/src/index.ts +5 -0
  67. package/src/pack.ts +73 -0
  68. package/src/react.tsx +126 -0
  69. package/src/renderer.ts +53 -0
  70. package/src/settings.ts +177 -0
  71. package/src/shader.glsl.ts +179 -0
  72. package/src/shader.wgsl.ts +159 -0
  73. package/src/source.ts +105 -0
  74. package/src/three-webgpu.ts +261 -0
  75. package/src/three.ts +114 -0
  76. package/src/types.ts +10 -0
  77. package/src/webgl.ts +191 -0
  78. package/src/webgpu.ts +312 -0
package/dist/types.js ADDED
@@ -0,0 +1,4 @@
1
+ // The public types the keyer's API is written in, kept apart from the modules that use them so that the declarations a
2
+ // project reads name nothing newer than they must
3
+ export {};
4
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,uHAAuH;AACvH,kDAAkD"}
@@ -0,0 +1,13 @@
1
+ import type { Renderer, RendererEvents } from './renderer.js';
2
+ import type { Canvas, Source } from './types.js';
3
+ export declare class WebGLRenderer implements Renderer {
4
+ #private;
5
+ readonly backend = "webgl";
6
+ constructor(canvas: Canvas, events: RendererEvents);
7
+ get lost(): boolean;
8
+ upload(source: Source, width: number, height: number): void;
9
+ draw(settings: Float32Array<ArrayBuffer>): void;
10
+ clear(): void;
11
+ dispose(): void;
12
+ }
13
+ //# sourceMappingURL=webgl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webgl.d.ts","sourceRoot":"","sources":["../src/webgl.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAE7D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAahD,qBAAa,aAAc,YAAW,QAAQ;;IAC5C,QAAQ,CAAC,OAAO,WAAU;IAa1B,YAAY,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc,EASjD;IAED,IAAI,IAAI,YAEP;IA4CD,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAUnD;IA4BD,IAAI,CAAC,QAAQ,EAAE,YAAY,CAAC,WAAW,CAAC,QAcvC;IAGD,KAAK,SAKJ;IAqBD,OAAO,SAUN;CACF"}
package/dist/webgl.js ADDED
@@ -0,0 +1,183 @@
1
+ import { contextOf, tooLarge } from './renderer.js';
2
+ import { FRAGMENT, VERTEX } from './shader.glsl.js';
3
+ // Drawn with blending premultiplied, as the shader's output is, and kept between draws, so the canvas can be copied
4
+ // from at any time and not just in the task that drew it
5
+ const ATTRIBUTES = {
6
+ alpha: true,
7
+ premultipliedAlpha: true,
8
+ antialias: false,
9
+ depth: false,
10
+ stencil: false,
11
+ preserveDrawingBuffer: true,
12
+ };
13
+ export class WebGLRenderer {
14
+ backend = 'webgl';
15
+ #canvas;
16
+ #gl;
17
+ #events;
18
+ #program = null;
19
+ #settings = null;
20
+ #texture = null;
21
+ #width = 0;
22
+ #height = 0;
23
+ // The most pixels a side it can take and draw
24
+ #limit = 0;
25
+ #lost = false;
26
+ constructor(canvas, events) {
27
+ const gl = contextOf(canvas, 'webgl2', ATTRIBUTES);
28
+ if (!gl)
29
+ throw new Error('Greenscreen: WebGL2 is not available on this canvas');
30
+ this.#canvas = canvas;
31
+ this.#gl = gl;
32
+ this.#events = events;
33
+ canvas.addEventListener('webglcontextlost', this.#onLost);
34
+ canvas.addEventListener('webglcontextrestored', this.#onRestored);
35
+ this.#build();
36
+ }
37
+ get lost() {
38
+ return this.#lost;
39
+ }
40
+ // The program and the texture, as at first and again once a lost context is back. The picture is uploaded as it
41
+ // comes: top row first, not premultiplied, in sRGB
42
+ #build() {
43
+ const gl = this.#gl;
44
+ const program = gl.createProgram();
45
+ const vertex = compile(gl, gl.VERTEX_SHADER, VERTEX);
46
+ const fragment = compile(gl, gl.FRAGMENT_SHADER, `#version 300 es\n${FRAGMENT}`);
47
+ gl.attachShader(program, vertex);
48
+ gl.attachShader(program, fragment);
49
+ gl.linkProgram(program);
50
+ if (!gl.getProgramParameter(program, gl.LINK_STATUS) && !gl.isContextLost()) {
51
+ throw new Error(`Greenscreen: the shader didn't link: ${gl.getProgramInfoLog(program)}`);
52
+ }
53
+ gl.deleteShader(vertex);
54
+ gl.deleteShader(fragment);
55
+ gl.useProgram(program);
56
+ gl.uniform1i(gl.getUniformLocation(program, 'image'), 0);
57
+ this.#program = program;
58
+ this.#settings = gl.getUniformLocation(program, 'settings');
59
+ const texture = gl.createTexture();
60
+ gl.activeTexture(gl.TEXTURE0);
61
+ gl.bindTexture(gl.TEXTURE_2D, texture);
62
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
63
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
64
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
65
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
66
+ gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
67
+ gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
68
+ gl.pixelStorei(gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, gl.BROWSER_DEFAULT_WEBGL);
69
+ this.#texture = texture;
70
+ this.#width = 0;
71
+ this.#height = 0;
72
+ // The widest picture it can take and draw: its largest texture, and its largest viewport, as the canvas is sized to
73
+ // the picture. A lost context says neither, and draws nothing until it's back
74
+ const texture2D = gl.getParameter(gl.MAX_TEXTURE_SIZE);
75
+ const viewport = gl.getParameter(gl.MAX_VIEWPORT_DIMS);
76
+ const sides = [texture2D, ...(viewport instanceof Int32Array ? viewport : [])];
77
+ this.#limit = Math.min(...sides.filter((side) => typeof side === 'number'));
78
+ }
79
+ // A picture larger than the context's textures throws, as it would otherwise be drawn black
80
+ upload(source, width, height) {
81
+ if (this.#lost)
82
+ return;
83
+ const limit = this.#limit;
84
+ if (width > limit || height > limit)
85
+ throw tooLarge(width, height, 'WebGL2', limit);
86
+ const gl = this.#gl;
87
+ gl.activeTexture(gl.TEXTURE0);
88
+ gl.bindTexture(gl.TEXTURE_2D, this.#texture);
89
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA8, gl.RGBA, gl.UNSIGNED_BYTE, this.#straight(source, width, height));
90
+ this.#width = width;
91
+ this.#height = height;
92
+ }
93
+ // WebGL uploads an ImageBitmap as it was made, ignoring the unpacking flags, so one made premultiplied, as they are
94
+ // by default, would arrive premultiplied. Drawn into a canvas first, it arrives straight, as everything else does
95
+ #bitmaps = null;
96
+ #straight(source, width, height) {
97
+ if (typeof ImageBitmap === 'undefined' || !(source instanceof ImageBitmap) || typeof OffscreenCanvas === 'undefined') {
98
+ return source;
99
+ }
100
+ let context = this.#bitmaps;
101
+ if (!context) {
102
+ context = new OffscreenCanvas(width, height).getContext('2d');
103
+ if (!context)
104
+ return source;
105
+ this.#bitmaps = context;
106
+ }
107
+ const canvas = context.canvas;
108
+ if (canvas.width !== width || canvas.height !== height) {
109
+ canvas.width = width;
110
+ canvas.height = height;
111
+ }
112
+ else {
113
+ context.clearRect(0, 0, width, height);
114
+ }
115
+ context.drawImage(source, 0, 0);
116
+ return canvas;
117
+ }
118
+ // Every pixel is drawn over, unblended, so there's nothing to clear first
119
+ draw(settings) {
120
+ if (this.#lost || !this.#width || !this.#height)
121
+ return;
122
+ const gl = this.#gl;
123
+ const canvas = this.#canvas;
124
+ if (canvas.width !== this.#width || canvas.height !== this.#height) {
125
+ canvas.width = this.#width;
126
+ canvas.height = this.#height;
127
+ }
128
+ gl.viewport(0, 0, this.#width, this.#height);
129
+ gl.useProgram(this.#program);
130
+ gl.uniform4fv(this.#settings, settings);
131
+ gl.activeTexture(gl.TEXTURE0);
132
+ gl.bindTexture(gl.TEXTURE_2D, this.#texture);
133
+ gl.drawArrays(gl.TRIANGLES, 0, 3);
134
+ }
135
+ // The drawing buffer is kept between draws, so it stays clear until the next
136
+ clear() {
137
+ if (this.#lost)
138
+ return;
139
+ const gl = this.#gl;
140
+ gl.clearColor(0, 0, 0, 0);
141
+ gl.clear(gl.COLOR_BUFFER_BIT);
142
+ }
143
+ // Lost, its default is prevented, which lets the browser give it back
144
+ #onLost = (event) => {
145
+ event.preventDefault();
146
+ this.#lost = true;
147
+ this.#program = null;
148
+ this.#texture = null;
149
+ this.#width = 0;
150
+ this.#height = 0;
151
+ this.#events.lost();
152
+ };
153
+ #onRestored = () => {
154
+ this.#lost = false;
155
+ this.#build();
156
+ this.#events.restored();
157
+ };
158
+ // Loses the context on purpose, as that frees it at once rather than when it's collected, and a page can only have
159
+ // so many
160
+ dispose() {
161
+ const gl = this.#gl;
162
+ this.#canvas.removeEventListener('webglcontextlost', this.#onLost);
163
+ this.#canvas.removeEventListener('webglcontextrestored', this.#onRestored);
164
+ if (!this.#lost) {
165
+ gl.deleteTexture(this.#texture);
166
+ gl.deleteProgram(this.#program);
167
+ }
168
+ this.#lost = true;
169
+ gl.getExtension('WEBGL_lose_context')?.loseContext();
170
+ }
171
+ }
172
+ function compile(gl, type, source) {
173
+ const shader = gl.createShader(type);
174
+ if (!shader)
175
+ throw new Error('Greenscreen: no shader could be made');
176
+ gl.shaderSource(shader, source);
177
+ gl.compileShader(shader);
178
+ if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS) && !gl.isContextLost()) {
179
+ throw new Error(`Greenscreen: the shader didn't compile: ${gl.getShaderInfoLog(shader)}`);
180
+ }
181
+ return shader;
182
+ }
183
+ //# sourceMappingURL=webgl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webgl.js","sourceRoot":"","sources":["../src/webgl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAEnD,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AAGnD,oHAAoH;AACpH,yDAAyD;AACzD,MAAM,UAAU,GAA2B;IACzC,KAAK,EAAE,IAAI;IACX,kBAAkB,EAAE,IAAI;IACxB,SAAS,EAAE,KAAK;IAChB,KAAK,EAAE,KAAK;IACZ,OAAO,EAAE,KAAK;IACd,qBAAqB,EAAE,IAAI;CAC5B,CAAA;AAED,MAAM,OAAO,aAAa;IACf,OAAO,GAAG,OAAO,CAAA;IACjB,OAAO,CAAQ;IACf,GAAG,CAAwB;IAC3B,OAAO,CAAgB;IAChC,QAAQ,GAAwB,IAAI,CAAA;IACpC,SAAS,GAAgC,IAAI,CAAA;IAC7C,QAAQ,GAAwB,IAAI,CAAA;IACpC,MAAM,GAAG,CAAC,CAAA;IACV,OAAO,GAAG,CAAC,CAAA;IACX,8CAA8C;IAC9C,MAAM,GAAG,CAAC,CAAA;IACV,KAAK,GAAG,KAAK,CAAA;IAEb,YAAY,MAAc,EAAE,MAAsB;QAChD,MAAM,EAAE,GAAG,SAAS,CAAC,MAAM,EAAE,QAAQ,EAAE,UAAU,CAAC,CAA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;QAAE,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAA;IACpE,EAAE,CAAC,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC/B,EAAE,CAAC,aAAa,CAAC,MAAM,CAAC,CAAA;IACxB,IAAI,CAAC,EAAE,CAAC,kBAAkB,CAAC,MAAM,EAAE,EAAE,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,CAAC,aAAa,EAAE,EAAE,CAAC;QAC7E,MAAM,IAAI,KAAK,CAAC,2CAA2C,EAAE,CAAC,gBAAgB,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;IAC3F,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC"}
@@ -0,0 +1,19 @@
1
+ import type { Renderer, RendererEvents } from './renderer.js';
2
+ import type { Canvas, Source } from './types.js';
3
+ export declare function requestDevice(given?: GPUAdapter): Promise<GPUDevice>;
4
+ export declare function currentDevice(): GPUDevice | null;
5
+ export declare function prefersWebGPU(): Promise<boolean>;
6
+ export declare function knownPreference(): boolean | null;
7
+ export declare function pipelineFor(device: GPUDevice, format: GPUTextureFormat): GPURenderPipeline;
8
+ export declare function preferredFormat(): GPUTextureFormat;
9
+ export declare class WebGPURenderer implements Renderer {
10
+ #private;
11
+ readonly backend = "webgpu";
12
+ constructor(canvas: Canvas, device: GPUDevice, events: RendererEvents);
13
+ get lost(): boolean;
14
+ upload(source: Source, width: number, height: number): void;
15
+ draw(settings: Float32Array<ArrayBuffer>): void;
16
+ clear(): void;
17
+ dispose(): void;
18
+ }
19
+ //# sourceMappingURL=webgpu.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webgpu.d.ts","sourceRoot":"","sources":["../src/webgpu.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAa,QAAQ,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAExE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAsBhD,wBAAgB,aAAa,CAAC,KAAK,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,SAAS,CAAC,CAyBpE;AAGD,wBAAgB,aAAa,IAAI,SAAS,GAAG,IAAI,CAEhD;AAYD,wBAAgB,aAAa,IAAI,OAAO,CAAC,OAAO,CAAC,CAiBhD;AAGD,wBAAgB,eAAe,IAAI,OAAO,GAAG,IAAI,CAGhD;AAMD,wBAAgB,WAAW,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,gBAAgB,GAAG,iBAAiB,CAmB1F;AAED,wBAAgB,eAAe,IAAI,gBAAgB,CAElD;AAKD,qBAAa,cAAe,YAAW,QAAQ;;IAC7C,QAAQ,CAAC,OAAO,YAAW;IAe3B,YAAY,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,cAAc,EAapE;IAED,IAAI,IAAI,YAEP;IAuCD,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QA4BnD;IA4BD,IAAI,CAAC,QAAQ,EAAE,YAAY,CAAC,WAAW,CAAC,QAgCvC;IAGD,KAAK,SAGJ;IAED,OAAO,SASN;CACF"}
package/dist/webgpu.js ADDED
@@ -0,0 +1,303 @@
1
+ import { PACKED_LENGTH } from './pack.js';
2
+ import { contextOf, tooLarge } from './renderer.js';
3
+ import { SHADER } from './shader.wgsl.js';
4
+ // The WebGPU usage flags, as the spec numbers them, rather than the browser's globals, which TypeScript doesn't declare
5
+ const TEXTURE_COPY_DST = 0x02;
6
+ const TEXTURE_BINDING = 0x04;
7
+ const TEXTURE_RENDER_ATTACHMENT = 0x10;
8
+ const BUFFER_COPY_DST = 0x08;
9
+ const BUFFER_UNIFORM = 0x40;
10
+ // One device for every keyer on the page, as a page can have many, and WebGPU, unlike WebGL, doesn't need a context of
11
+ // its own for each. It's asked for once, and asked for again only after it's lost
12
+ let shared = null;
13
+ // The device once it's there, for a keyer made after it to start with at once
14
+ let current = null;
15
+ // Whether 'auto' takes WebGPU, found once, and again after the device is lost. known is what it came to, for a keyer to
16
+ // choose by at once, and null until then
17
+ let preferred = null;
18
+ let known = null;
19
+ // The page's device, from the adapter given or the browser's own. It's asked for with the largest texture the adapter
20
+ // has, as a device takes pictures of only 8192 pixels a side unless more is asked for
21
+ export function requestDevice(given) {
22
+ if (shared)
23
+ return shared;
24
+ const attempt = (async () => {
25
+ const adapter = given ?? (await requestAdapter());
26
+ const device = await adapter.requestDevice({
27
+ requiredLimits: { maxTextureDimension2D: adapter.limits.maxTextureDimension2D },
28
+ });
29
+ void device.lost.then(() => {
30
+ if (shared !== attempt)
31
+ return;
32
+ shared = null;
33
+ current = null;
34
+ preferred = null;
35
+ known = null;
36
+ });
37
+ return device;
38
+ })();
39
+ shared = attempt;
40
+ // Before anything that waits for it goes on, as this waits first
41
+ void attempt.then((device) => {
42
+ if (shared === attempt)
43
+ current = device;
44
+ }, () => { });
45
+ return attempt;
46
+ }
47
+ // The device, where it has been had already and not lost since
48
+ export function currentDevice() {
49
+ return current;
50
+ }
51
+ async function requestAdapter() {
52
+ const gpu = typeof navigator === 'undefined' ? undefined : navigator.gpu;
53
+ if (!gpu)
54
+ throw new Error('Greenscreen: WebGPU is not available here');
55
+ const adapter = await gpu.requestAdapter();
56
+ if (!adapter)
57
+ throw new Error('Greenscreen: WebGPU has no adapter here');
58
+ return adapter;
59
+ }
60
+ // Whether 'auto' takes WebGPU: where the browser has an adapter for it on the GPU, and a device from that adapter. A
61
+ // fallback adapter, which runs WebGPU on the CPU, doesn't count, as WebGL2 is then likely on the GPU, and faster
62
+ export function prefersWebGPU() {
63
+ if (preferred)
64
+ return preferred;
65
+ const attempt = (async () => {
66
+ try {
67
+ const adapter = await requestAdapter();
68
+ if (adapter.info.isFallbackAdapter)
69
+ return false;
70
+ await requestDevice(adapter);
71
+ return true;
72
+ }
73
+ catch {
74
+ return false;
75
+ }
76
+ })();
77
+ preferred = attempt;
78
+ void attempt.then((webgpu) => {
79
+ if (preferred === attempt)
80
+ known = webgpu;
81
+ });
82
+ return attempt;
83
+ }
84
+ // What prefersWebGPU() comes to, where that's known already: once it has resolved, or at once where there's no WebGPU
85
+ export function knownPreference() {
86
+ if (typeof navigator === 'undefined' || !navigator.gpu)
87
+ return false;
88
+ return known;
89
+ }
90
+ const pipelines = new WeakMap();
91
+ // The keying pipeline for the device and canvas format, made once. It has no sampler: the shader reads the texture's
92
+ // pixels itself, and blends them as OBS's sampler would
93
+ export function pipelineFor(device, format) {
94
+ let byFormat = pipelines.get(device);
95
+ if (!byFormat) {
96
+ byFormat = new Map();
97
+ pipelines.set(device, byFormat);
98
+ }
99
+ let made = byFormat.get(format);
100
+ if (!made) {
101
+ const module = device.createShaderModule({ label: 'Greenscreen', code: SHADER });
102
+ made = device.createRenderPipeline({
103
+ label: 'Greenscreen',
104
+ layout: 'auto',
105
+ vertex: { module, entryPoint: 'vertexMain' },
106
+ fragment: { module, entryPoint: 'fragmentMain', targets: [{ format }] },
107
+ primitive: { topology: 'triangle-list' },
108
+ });
109
+ byFormat.set(format, made);
110
+ }
111
+ return made;
112
+ }
113
+ export function preferredFormat() {
114
+ return navigator.gpu.getPreferredCanvasFormat();
115
+ }
116
+ // WebGPU keys into a canvas of its own, off the page, and each picture is copied from there into the keyer's canvas,
117
+ // which shows it through a 2D context. A WebGPU canvas on the page gives drawImage nothing once the browser has drawn
118
+ // the page, where a 2D canvas keeps its picture until it's drawn again, on the page or off it
119
+ export class WebGPURenderer {
120
+ backend = 'webgpu';
121
+ #canvas;
122
+ #output;
123
+ #surface;
124
+ #context;
125
+ #events;
126
+ #device;
127
+ #pipeline;
128
+ #uniforms;
129
+ #texture = null;
130
+ #bindGroup = null;
131
+ #videos = null;
132
+ #lost = false;
133
+ #disposed = false;
134
+ constructor(canvas, device, events) {
135
+ // WebGPU first, so a canvas WebGPU can't draw for is left as it was
136
+ const surface = new OffscreenCanvas(1, 1);
137
+ const context = contextOf(surface, 'webgpu');
138
+ if (!context)
139
+ throw new Error('Greenscreen: WebGPU is not available on this canvas');
140
+ const output = contextOf(canvas, '2d');
141
+ if (!output)
142
+ throw new Error('Greenscreen: this canvas has a context of another kind already');
143
+ this.#canvas = canvas;
144
+ this.#output = output;
145
+ this.#surface = surface;
146
+ this.#context = context;
147
+ this.#events = events;
148
+ this.#build(device);
149
+ }
150
+ get lost() {
151
+ return this.#lost;
152
+ }
153
+ // The surface set up for the device, premultiplied as the shader's output is
154
+ #build(device) {
155
+ const format = preferredFormat();
156
+ this.#device = device;
157
+ this.#context.configure({ device, format, alphaMode: 'premultiplied', usage: TEXTURE_RENDER_ATTACHMENT });
158
+ this.#pipeline = pipelineFor(device, format);
159
+ this.#uniforms = device.createBuffer({
160
+ label: 'Greenscreen settings',
161
+ size: PACKED_LENGTH * 4,
162
+ usage: BUFFER_UNIFORM | BUFFER_COPY_DST,
163
+ });
164
+ this.#texture = null;
165
+ this.#bindGroup = null;
166
+ void device.lost.then(() => this.#onLost(device));
167
+ }
168
+ // Lost with the device, it asks for the next one and starts again with it
169
+ async #onLost(device) {
170
+ if (this.#disposed || device !== this.#device)
171
+ return;
172
+ this.#lost = true;
173
+ this.#texture = null;
174
+ this.#bindGroup = null;
175
+ this.#events.lost();
176
+ try {
177
+ const next = await requestDevice();
178
+ if (this.#disposed)
179
+ return;
180
+ this.#build(next);
181
+ this.#lost = false;
182
+ this.#events.restored();
183
+ }
184
+ catch {
185
+ // No device to be had: it stays lost
186
+ }
187
+ }
188
+ // The picture as it comes, top row first and not premultiplied, in a texture of its size. copyExternalImageToTexture
189
+ // takes every kind of source, a video by way of a 2D canvas. A picture larger than the device's textures throws, as
190
+ // a texture of its size would be made without an error thrown, and never drawn
191
+ upload(source, width, height) {
192
+ if (this.#lost)
193
+ return;
194
+ const device = this.#device;
195
+ const limit = device.limits.maxTextureDimension2D;
196
+ if (width > limit || height > limit)
197
+ throw tooLarge(width, height, 'WebGPU', limit);
198
+ let texture = this.#texture;
199
+ if (!texture || texture.width !== width || texture.height !== height) {
200
+ texture?.destroy();
201
+ texture = device.createTexture({
202
+ label: 'Greenscreen picture',
203
+ size: { width, height },
204
+ format: 'rgba8unorm',
205
+ usage: TEXTURE_BINDING | TEXTURE_COPY_DST | TEXTURE_RENDER_ATTACHMENT,
206
+ });
207
+ this.#texture = texture;
208
+ this.#bindGroup = device.createBindGroup({
209
+ layout: this.#pipeline.getBindGroupLayout(0),
210
+ entries: [
211
+ { binding: 0, resource: texture.createView() },
212
+ { binding: 1, resource: { buffer: this.#uniforms } },
213
+ ],
214
+ });
215
+ }
216
+ device.queue.copyExternalImageToTexture({ source: this.#asDrawn(source, width, height), flipY: false }, { texture, colorSpace: 'srgb', premultipliedAlpha: false }, { width, height });
217
+ }
218
+ // A video comes in through a 2D canvas. WebGPU's own copy converts a video's colours from the video's colour space
219
+ // to sRGB, which moves those of a BT.601 video, as cameras' and recordings often are, by as much as 20 levels in 255:
220
+ // the keyer would key colours a little apart from those WebGL keys, and from those a 2D canvas reads, as an
221
+ // eyedropper does. A 2D canvas reads a video as WebGL does. It also reads a camera's first frame, which WebGPU's copy
222
+ // can't. A VideoFrame of RGB pixels, as one made from a canvas is, has nothing to convert, and comes as it is
223
+ #asDrawn(source, width, height) {
224
+ const video = 'videoWidth' in source || ('displayWidth' in source && !/^(RGB|BGR)/.test(source.format ?? ''));
225
+ if (!video)
226
+ return source;
227
+ let context = this.#videos;
228
+ if (!context) {
229
+ context = contextOf(stagingCanvas(), '2d');
230
+ if (!context)
231
+ return source;
232
+ this.#videos = context;
233
+ }
234
+ const canvas = context.canvas;
235
+ if (canvas.width !== width || canvas.height !== height) {
236
+ canvas.width = width;
237
+ canvas.height = height;
238
+ }
239
+ context.globalCompositeOperation = 'copy';
240
+ context.drawImage(source, 0, 0, width, height);
241
+ return canvas;
242
+ }
243
+ // The surface's texture is taken just before it's drawn over whole, and the picture is copied across, alpha and all,
244
+ // into the keyer's canvas
245
+ draw(settings) {
246
+ const texture = this.#texture;
247
+ const bindGroup = this.#bindGroup;
248
+ if (this.#lost || !texture || !bindGroup)
249
+ return;
250
+ const { width, height } = texture;
251
+ for (const canvas of [this.#surface, this.#canvas]) {
252
+ if (canvas.width !== width || canvas.height !== height) {
253
+ canvas.width = width;
254
+ canvas.height = height;
255
+ }
256
+ }
257
+ const device = this.#device;
258
+ device.queue.writeBuffer(this.#uniforms, 0, settings, 0, settings.length);
259
+ const encoder = device.createCommandEncoder();
260
+ const pass = encoder.beginRenderPass({
261
+ colorAttachments: [
262
+ {
263
+ view: this.#context.getCurrentTexture().createView(),
264
+ loadOp: 'clear',
265
+ clearValue: [0, 0, 0, 0],
266
+ storeOp: 'store',
267
+ },
268
+ ],
269
+ });
270
+ pass.setPipeline(this.#pipeline);
271
+ pass.setBindGroup(0, bindGroup);
272
+ pass.draw(3);
273
+ pass.end();
274
+ device.queue.submit([encoder.finish()]);
275
+ const output = this.#output;
276
+ output.globalCompositeOperation = 'copy';
277
+ output.drawImage(this.#surface, 0, 0);
278
+ }
279
+ // The keyer's canvas shows its picture through a 2D context, which clears whatever its composite operation
280
+ clear() {
281
+ const canvas = this.#canvas;
282
+ this.#output.clearRect(0, 0, canvas.width, canvas.height);
283
+ }
284
+ dispose() {
285
+ this.#disposed = true;
286
+ this.#lost = true;
287
+ this.#texture?.destroy();
288
+ this.#uniforms.destroy();
289
+ this.#texture = null;
290
+ this.#bindGroup = null;
291
+ this.#videos = null;
292
+ this.#context.unconfigure();
293
+ }
294
+ }
295
+ // The canvas a video is drawn into on its way in: an element, off the page, where there's a document. WebGPU's copy
296
+ // from a 2D OffscreenCanvas comes out empty on SwiftShader, Chrome's software renderer, where one from an element
297
+ // doesn't. A worker has only OffscreenCanvas
298
+ function stagingCanvas() {
299
+ if (typeof document !== 'undefined')
300
+ return document.createElement('canvas');
301
+ return new OffscreenCanvas(1, 1);
302
+ }
303
+ //# sourceMappingURL=webgpu.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webgpu.js","sourceRoot":"","sources":["../src/webgpu.ts"],"names":[],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