2024-01-01 14:58:21 -05:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2020-07-19 13:49:44 -04:00
|
|
|
|
2024-01-23 21:47:48 -05:00
|
|
|
import { core, internals } from "ext:core/mod.js";
|
2024-01-26 17:46:46 -05:00
|
|
|
import {
|
2024-01-10 17:37:25 -05:00
|
|
|
op_net_listen_udp,
|
|
|
|
op_net_listen_unixpacket,
|
|
|
|
op_runtime_memory_usage,
|
2024-01-26 17:46:46 -05:00
|
|
|
} from "ext:core/ops";
|
2023-09-26 20:21:06 -04:00
|
|
|
|
2023-03-08 06:44:54 -05:00
|
|
|
import * as timers from "ext:deno_web/02_timers.js";
|
|
|
|
import * as httpClient from "ext:deno_fetch/22_http_client.js";
|
2023-04-30 05:11:37 -04:00
|
|
|
import * as console from "ext:deno_console/01_console.js";
|
2023-03-08 06:44:54 -05:00
|
|
|
import * as ffi from "ext:deno_ffi/00_ffi.js";
|
|
|
|
import * as net from "ext:deno_net/01_net.js";
|
|
|
|
import * as tls from "ext:deno_net/02_tls.js";
|
2024-04-24 14:03:37 -04:00
|
|
|
import * as serve from "ext:deno_http/00_serve.ts";
|
2023-03-08 06:44:54 -05:00
|
|
|
import * as http from "ext:deno_http/01_http.js";
|
2024-04-19 22:02:39 -04:00
|
|
|
import * as websocket from "ext:deno_http/02_websocket.ts";
|
2023-03-08 06:44:54 -05:00
|
|
|
import * as errors from "ext:runtime/01_errors.js";
|
|
|
|
import * as version from "ext:runtime/01_version.ts";
|
|
|
|
import * as permissions from "ext:runtime/10_permissions.js";
|
|
|
|
import * as io from "ext:deno_io/12_io.js";
|
|
|
|
import * as buffer from "ext:runtime/13_buffer.js";
|
|
|
|
import * as fs from "ext:deno_fs/30_fs.js";
|
|
|
|
import * as os from "ext:runtime/30_os.js";
|
|
|
|
import * as fsEvents from "ext:runtime/40_fs_events.js";
|
|
|
|
import * as process from "ext:runtime/40_process.js";
|
|
|
|
import * as signals from "ext:runtime/40_signals.js";
|
|
|
|
import * as tty from "ext:runtime/40_tty.js";
|
2023-03-22 00:13:24 -04:00
|
|
|
import * as kv from "ext:deno_kv/01_db.ts";
|
2023-11-01 14:57:55 -04:00
|
|
|
import * as cron from "ext:deno_cron/01_cron.ts";
|
feat:: External webgpu surfaces / BYOW (#21835)
This PR contains the implementation of the External webgpu surfaces /
BYOW proposal. BYOW stands for "Bring your own window".
Closes #21713
Adds `Deno.UnsafeWindowSurface` ( `--unstable-webgpu` API) to the `Deno`
namespace:
```typescript
class UnsafeWindowSurface {
constructor(
system: "cocoa" | "x11" | "win32",
winHandle: Deno.PointerValue,
displayHandle: Deno.PointerValue | null
);
getContext(type: "webgpu"): GPUCanvasContext;
present(): void;
}
```
For the initial pass, I've opted to support the three major windowing
systems. The parameters correspond to the table below:
| system | winHandle | displayHandle |
| ----------------- | ---------- | ------- |
| "cocoa" (macOS) | `NSView*` | - |
| "win32" (Windows) | `HWND` | `HINSTANCE` |
| "x11" (Linux) | Xlib `Window` | Xlib `Display*` |
Ecosystem support:
- [x] deno_sdl2 (sdl2) -
[mod.ts#L1209](https://github.com/littledivy/deno_sdl2/blob/7e177bc6524750a8849c25ce421798b2e71ec943/mod.ts#L1209)
- [x] dwm (glfw) - https://github.com/deno-windowing/dwm/issues/29
- [ ] pane (winit)
<details>
<summary>Example</summary>
```typescript
// A simple clear screen pass, colors based on mouse position.
import { EventType, WindowBuilder } from "https://deno.land/x/sdl2@0.7.0/mod.ts";
const window = new WindowBuilder("sdl2 + deno + webgpu", 640, 480).build();
const [system, windowHandle, displayHandle] = window.rawHandle();
const adapter = await navigator.gpu.requestAdapter();
const device = await adapter.requestDevice();
const context = Deno.createWindowSurface(system, windowHandle, displayHandle);
context.configure({
device: device,
format: "bgra8unorm",
height: 480,
width: 640,
});
let r = 0.0;
let g = 0.0;
let b = 0.0;
for (const event of window.events()) {
if (event.type === EventType.Quit) {
break;
} else if (event.type === EventType.Draw) {
const textureView = context.getCurrentTexture().createView();
const renderPassDescriptor: GPURenderPassDescriptor = {
colorAttachments: [
{
view: textureView,
clearValue: { r, g, b, a: 1.0 },
loadOp: "clear",
storeOp: "store",
},
],
};
const commandEncoder = device.createCommandEncoder();
const passEncoder = commandEncoder.beginRenderPass(renderPassDescriptor);
passEncoder.end();
device.queue.submit([commandEncoder.finish()]);
Deno.presentGPUCanvasContext(context);
}
if (event.type === EventType.MouseMotion) {
r = event.x / 640;
g = event.y / 480;
b = 1.0 - r - g;
}
}
```
You can find more examples in the linked tracking issue.
</details>
---------
Signed-off-by: Divy Srivastava <dj.srivastava23@gmail.com>
2024-01-19 12:19:14 -05:00
|
|
|
import * as webgpuSurface from "ext:deno_webgpu/02_surface.js";
|
2022-11-10 16:03:28 -05:00
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
const denoNs = {
|
|
|
|
Process: process.Process,
|
|
|
|
run: process.run,
|
|
|
|
isatty: tty.isatty,
|
2023-03-04 22:37:37 -05:00
|
|
|
writeFileSync: fs.writeFileSync,
|
|
|
|
writeFile: fs.writeFile,
|
|
|
|
writeTextFileSync: fs.writeTextFileSync,
|
|
|
|
writeTextFile: fs.writeTextFile,
|
|
|
|
readTextFile: fs.readTextFile,
|
|
|
|
readTextFileSync: fs.readTextFileSync,
|
|
|
|
readFile: fs.readFile,
|
|
|
|
readFileSync: fs.readFileSync,
|
2023-02-07 14:22:46 -05:00
|
|
|
watchFs: fsEvents.watchFs,
|
|
|
|
chmodSync: fs.chmodSync,
|
|
|
|
chmod: fs.chmod,
|
|
|
|
chown: fs.chown,
|
|
|
|
chownSync: fs.chownSync,
|
|
|
|
copyFileSync: fs.copyFileSync,
|
|
|
|
cwd: fs.cwd,
|
|
|
|
makeTempDirSync: fs.makeTempDirSync,
|
|
|
|
makeTempDir: fs.makeTempDir,
|
|
|
|
makeTempFileSync: fs.makeTempFileSync,
|
|
|
|
makeTempFile: fs.makeTempFile,
|
2024-01-10 17:37:25 -05:00
|
|
|
memoryUsage: () => op_runtime_memory_usage(),
|
2023-02-07 14:22:46 -05:00
|
|
|
mkdirSync: fs.mkdirSync,
|
|
|
|
mkdir: fs.mkdir,
|
|
|
|
chdir: fs.chdir,
|
|
|
|
copyFile: fs.copyFile,
|
|
|
|
readDirSync: fs.readDirSync,
|
|
|
|
readDir: fs.readDir,
|
|
|
|
readLinkSync: fs.readLinkSync,
|
|
|
|
readLink: fs.readLink,
|
|
|
|
realPathSync: fs.realPathSync,
|
|
|
|
realPath: fs.realPath,
|
|
|
|
removeSync: fs.removeSync,
|
|
|
|
remove: fs.remove,
|
|
|
|
renameSync: fs.renameSync,
|
|
|
|
rename: fs.rename,
|
|
|
|
version: version.version,
|
2023-03-05 17:18:13 -05:00
|
|
|
build: core.build,
|
2023-02-07 14:22:46 -05:00
|
|
|
statSync: fs.statSync,
|
|
|
|
lstatSync: fs.lstatSync,
|
|
|
|
stat: fs.stat,
|
|
|
|
lstat: fs.lstat,
|
|
|
|
truncateSync: fs.truncateSync,
|
|
|
|
truncate: fs.truncate,
|
2024-01-24 09:12:22 -05:00
|
|
|
ftruncateSync(rid, len) {
|
|
|
|
internals.warnOnDeprecatedApi(
|
|
|
|
"Deno.ftruncateSync()",
|
|
|
|
new Error().stack,
|
|
|
|
"Use `Deno.FsFile.truncateSync()` instead.",
|
|
|
|
);
|
|
|
|
return fs.ftruncateSync(rid, len);
|
|
|
|
},
|
|
|
|
ftruncate(rid, len) {
|
|
|
|
internals.warnOnDeprecatedApi(
|
|
|
|
"Deno.ftruncate()",
|
|
|
|
new Error().stack,
|
|
|
|
"Use `Deno.FsFile.truncate()` instead.",
|
|
|
|
);
|
|
|
|
return fs.ftruncate(rid, len);
|
|
|
|
},
|
2023-02-07 14:22:46 -05:00
|
|
|
errors: errors.errors,
|
|
|
|
inspect: console.inspect,
|
|
|
|
env: os.env,
|
|
|
|
exit: os.exit,
|
|
|
|
execPath: os.execPath,
|
|
|
|
Buffer: buffer.Buffer,
|
|
|
|
readAll: buffer.readAll,
|
|
|
|
readAllSync: buffer.readAllSync,
|
|
|
|
writeAll: buffer.writeAll,
|
|
|
|
writeAllSync: buffer.writeAllSync,
|
|
|
|
copy: io.copy,
|
|
|
|
iter: io.iter,
|
|
|
|
iterSync: io.iterSync,
|
|
|
|
SeekMode: io.SeekMode,
|
2024-01-23 23:12:03 -05:00
|
|
|
read(rid, buffer) {
|
|
|
|
internals.warnOnDeprecatedApi(
|
|
|
|
"Deno.read()",
|
|
|
|
new Error().stack,
|
|
|
|
"Use `reader.read()` instead.",
|
|
|
|
);
|
|
|
|
return io.read(rid, buffer);
|
|
|
|
},
|
|
|
|
readSync(rid, buffer) {
|
|
|
|
internals.warnOnDeprecatedApi(
|
|
|
|
"Deno.readSync()",
|
|
|
|
new Error().stack,
|
|
|
|
"Use `reader.readSync()` instead.",
|
|
|
|
);
|
|
|
|
return io.readSync(rid, buffer);
|
|
|
|
},
|
2024-01-24 10:36:13 -05:00
|
|
|
write(rid, data) {
|
|
|
|
internals.warnOnDeprecatedApi(
|
|
|
|
"Deno.write()",
|
|
|
|
new Error().stack,
|
|
|
|
"Use `writer.write()` instead.",
|
|
|
|
);
|
|
|
|
return io.write(rid, data);
|
|
|
|
},
|
|
|
|
writeSync(rid, data) {
|
|
|
|
internals.warnOnDeprecatedApi(
|
|
|
|
"Deno.writeSync()",
|
|
|
|
new Error().stack,
|
|
|
|
"Use `writer.writeSync()` instead.",
|
|
|
|
);
|
|
|
|
return io.writeSync(rid, data);
|
|
|
|
},
|
2023-03-04 22:37:37 -05:00
|
|
|
File: fs.File,
|
2024-01-25 17:51:29 -05:00
|
|
|
FsFile: fs.FsFile,
|
2023-03-04 22:37:37 -05:00
|
|
|
open: fs.open,
|
|
|
|
openSync: fs.openSync,
|
|
|
|
create: fs.create,
|
|
|
|
createSync: fs.createSync,
|
|
|
|
stdin: io.stdin,
|
|
|
|
stdout: io.stdout,
|
|
|
|
stderr: io.stderr,
|
2024-01-23 23:09:56 -05:00
|
|
|
seek(rid, offset, whence) {
|
|
|
|
internals.warnOnDeprecatedApi(
|
|
|
|
"Deno.seek()",
|
|
|
|
new Error().stack,
|
|
|
|
"Use `file.seek()` instead.",
|
|
|
|
);
|
|
|
|
return fs.seek(rid, offset, whence);
|
|
|
|
},
|
|
|
|
seekSync(rid, offset, whence) {
|
|
|
|
internals.warnOnDeprecatedApi(
|
|
|
|
"Deno.seekSync()",
|
|
|
|
new Error().stack,
|
|
|
|
"Use `file.seekSync()` instead.",
|
|
|
|
);
|
|
|
|
return fs.seekSync(rid, offset, whence);
|
|
|
|
},
|
2023-02-07 14:22:46 -05:00
|
|
|
connect: net.connect,
|
|
|
|
listen: net.listen,
|
|
|
|
loadavg: os.loadavg,
|
|
|
|
connectTls: tls.connectTls,
|
|
|
|
listenTls: tls.listenTls,
|
|
|
|
startTls: tls.startTls,
|
2024-01-24 12:53:20 -05:00
|
|
|
fstatSync(rid) {
|
|
|
|
internals.warnOnDeprecatedApi(
|
|
|
|
"Deno.fstatSync()",
|
|
|
|
new Error().stack,
|
|
|
|
"Use `Deno.FsFile.statSync()` instead.",
|
|
|
|
);
|
|
|
|
return fs.fstatSync(rid);
|
|
|
|
},
|
|
|
|
fstat(rid) {
|
|
|
|
internals.warnOnDeprecatedApi(
|
|
|
|
"Deno.fstat()",
|
|
|
|
new Error().stack,
|
|
|
|
"Use `Deno.FsFile.stat()` instead.",
|
|
|
|
);
|
|
|
|
return fs.fstat(rid);
|
|
|
|
},
|
2024-01-24 17:38:18 -05:00
|
|
|
fsyncSync: fs.fsyncSync,
|
|
|
|
fsync: fs.fsync,
|
2023-02-07 14:22:46 -05:00
|
|
|
fdatasyncSync: fs.fdatasyncSync,
|
|
|
|
fdatasync: fs.fdatasync,
|
|
|
|
symlink: fs.symlink,
|
|
|
|
symlinkSync: fs.symlinkSync,
|
|
|
|
link: fs.link,
|
|
|
|
linkSync: fs.linkSync,
|
|
|
|
permissions: permissions.permissions,
|
|
|
|
Permissions: permissions.Permissions,
|
|
|
|
PermissionStatus: permissions.PermissionStatus,
|
2024-04-18 13:21:25 -04:00
|
|
|
serveHttp: http.serveHttp,
|
|
|
|
serve: serve.serve,
|
2023-02-07 14:22:46 -05:00
|
|
|
resolveDns: net.resolveDns,
|
2024-04-19 22:02:39 -04:00
|
|
|
upgradeWebSocket: websocket.upgradeWebSocket,
|
2023-02-07 14:22:46 -05:00
|
|
|
utime: fs.utime,
|
|
|
|
utimeSync: fs.utimeSync,
|
|
|
|
kill: process.kill,
|
|
|
|
addSignalListener: signals.addSignalListener,
|
|
|
|
removeSignalListener: signals.removeSignalListener,
|
|
|
|
refTimer: timers.refTimer,
|
|
|
|
unrefTimer: timers.unrefTimer,
|
|
|
|
osRelease: os.osRelease,
|
|
|
|
osUptime: os.osUptime,
|
|
|
|
hostname: os.hostname,
|
|
|
|
systemMemoryInfo: os.systemMemoryInfo,
|
|
|
|
networkInterfaces: os.networkInterfaces,
|
|
|
|
consoleSize: tty.consoleSize,
|
|
|
|
gid: os.gid,
|
|
|
|
uid: os.uid,
|
2023-03-05 07:19:34 -05:00
|
|
|
Command: process.Command,
|
|
|
|
ChildProcess: process.ChildProcess,
|
2023-02-07 14:22:46 -05:00
|
|
|
};
|
2020-07-19 13:49:44 -04:00
|
|
|
|
2023-11-01 18:15:08 -04:00
|
|
|
// NOTE(bartlomieju): keep IDs in sync with `cli/main.rs`
|
2023-12-08 08:24:49 -05:00
|
|
|
const unstableIds = {
|
|
|
|
broadcastChannel: 1,
|
|
|
|
cron: 2,
|
|
|
|
ffi: 3,
|
|
|
|
fs: 4,
|
|
|
|
http: 5,
|
|
|
|
kv: 6,
|
|
|
|
net: 7,
|
2024-06-13 09:00:38 -04:00
|
|
|
process: 8,
|
|
|
|
temporal: 9,
|
|
|
|
unsafeProto: 10,
|
|
|
|
webgpu: 11,
|
|
|
|
workerOptions: 12,
|
2023-11-01 18:15:08 -04:00
|
|
|
};
|
|
|
|
|
2024-05-22 18:03:35 -04:00
|
|
|
const denoNsUnstableById = { __proto__: null };
|
2023-12-08 08:24:49 -05:00
|
|
|
|
2024-05-22 18:03:35 -04:00
|
|
|
// denoNsUnstableById[unstableIds.broadcastChannel] = { __proto__: null }
|
2023-12-08 08:24:49 -05:00
|
|
|
|
|
|
|
denoNsUnstableById[unstableIds.cron] = {
|
|
|
|
cron: cron.cron,
|
|
|
|
};
|
|
|
|
|
|
|
|
denoNsUnstableById[unstableIds.ffi] = {
|
|
|
|
dlopen: ffi.dlopen,
|
|
|
|
UnsafeCallback: ffi.UnsafeCallback,
|
|
|
|
UnsafePointer: ffi.UnsafePointer,
|
|
|
|
UnsafePointerView: ffi.UnsafePointerView,
|
|
|
|
UnsafeFnPointer: ffi.UnsafeFnPointer,
|
|
|
|
};
|
|
|
|
|
|
|
|
denoNsUnstableById[unstableIds.fs] = {
|
|
|
|
flock: fs.flock,
|
|
|
|
flockSync: fs.flockSync,
|
|
|
|
funlock: fs.funlock,
|
|
|
|
funlockSync: fs.funlockSync,
|
|
|
|
umask: fs.umask,
|
|
|
|
};
|
|
|
|
|
|
|
|
denoNsUnstableById[unstableIds.http] = {
|
|
|
|
HttpClient: httpClient.HttpClient,
|
|
|
|
createHttpClient: httpClient.createHttpClient,
|
|
|
|
};
|
|
|
|
|
|
|
|
denoNsUnstableById[unstableIds.kv] = {
|
|
|
|
openKv: kv.openKv,
|
|
|
|
AtomicOperation: kv.AtomicOperation,
|
|
|
|
Kv: kv.Kv,
|
|
|
|
KvU64: kv.KvU64,
|
|
|
|
KvListIterator: kv.KvListIterator,
|
|
|
|
};
|
|
|
|
|
|
|
|
denoNsUnstableById[unstableIds.net] = {
|
|
|
|
listenDatagram: net.createListenDatagram(
|
2024-01-10 17:37:25 -05:00
|
|
|
op_net_listen_udp,
|
|
|
|
op_net_listen_unixpacket,
|
2023-12-08 08:24:49 -05:00
|
|
|
),
|
|
|
|
};
|
|
|
|
|
2024-05-22 18:03:35 -04:00
|
|
|
// denoNsUnstableById[unstableIds.unsafeProto] = { __proto__: null }
|
2023-12-08 08:24:49 -05:00
|
|
|
|
feat:: External webgpu surfaces / BYOW (#21835)
This PR contains the implementation of the External webgpu surfaces /
BYOW proposal. BYOW stands for "Bring your own window".
Closes #21713
Adds `Deno.UnsafeWindowSurface` ( `--unstable-webgpu` API) to the `Deno`
namespace:
```typescript
class UnsafeWindowSurface {
constructor(
system: "cocoa" | "x11" | "win32",
winHandle: Deno.PointerValue,
displayHandle: Deno.PointerValue | null
);
getContext(type: "webgpu"): GPUCanvasContext;
present(): void;
}
```
For the initial pass, I've opted to support the three major windowing
systems. The parameters correspond to the table below:
| system | winHandle | displayHandle |
| ----------------- | ---------- | ------- |
| "cocoa" (macOS) | `NSView*` | - |
| "win32" (Windows) | `HWND` | `HINSTANCE` |
| "x11" (Linux) | Xlib `Window` | Xlib `Display*` |
Ecosystem support:
- [x] deno_sdl2 (sdl2) -
[mod.ts#L1209](https://github.com/littledivy/deno_sdl2/blob/7e177bc6524750a8849c25ce421798b2e71ec943/mod.ts#L1209)
- [x] dwm (glfw) - https://github.com/deno-windowing/dwm/issues/29
- [ ] pane (winit)
<details>
<summary>Example</summary>
```typescript
// A simple clear screen pass, colors based on mouse position.
import { EventType, WindowBuilder } from "https://deno.land/x/sdl2@0.7.0/mod.ts";
const window = new WindowBuilder("sdl2 + deno + webgpu", 640, 480).build();
const [system, windowHandle, displayHandle] = window.rawHandle();
const adapter = await navigator.gpu.requestAdapter();
const device = await adapter.requestDevice();
const context = Deno.createWindowSurface(system, windowHandle, displayHandle);
context.configure({
device: device,
format: "bgra8unorm",
height: 480,
width: 640,
});
let r = 0.0;
let g = 0.0;
let b = 0.0;
for (const event of window.events()) {
if (event.type === EventType.Quit) {
break;
} else if (event.type === EventType.Draw) {
const textureView = context.getCurrentTexture().createView();
const renderPassDescriptor: GPURenderPassDescriptor = {
colorAttachments: [
{
view: textureView,
clearValue: { r, g, b, a: 1.0 },
loadOp: "clear",
storeOp: "store",
},
],
};
const commandEncoder = device.createCommandEncoder();
const passEncoder = commandEncoder.beginRenderPass(renderPassDescriptor);
passEncoder.end();
device.queue.submit([commandEncoder.finish()]);
Deno.presentGPUCanvasContext(context);
}
if (event.type === EventType.MouseMotion) {
r = event.x / 640;
g = event.y / 480;
b = 1.0 - r - g;
}
}
```
You can find more examples in the linked tracking issue.
</details>
---------
Signed-off-by: Divy Srivastava <dj.srivastava23@gmail.com>
2024-01-19 12:19:14 -05:00
|
|
|
denoNsUnstableById[unstableIds.webgpu] = {
|
|
|
|
UnsafeWindowSurface: webgpuSurface.UnsafeWindowSurface,
|
|
|
|
};
|
2023-12-08 19:19:16 -05:00
|
|
|
|
2024-05-22 18:03:35 -04:00
|
|
|
// denoNsUnstableById[unstableIds.workerOptions] = { __proto__: null }
|
2023-12-08 08:24:49 -05:00
|
|
|
|
2023-07-13 19:29:51 -04:00
|
|
|
// when editing this list, also update unstableDenoProps in cli/tsc/99_main_compiler.js
|
2023-02-07 14:22:46 -05:00
|
|
|
const denoNsUnstable = {
|
2023-03-28 08:44:22 -04:00
|
|
|
listenDatagram: net.createListenDatagram(
|
2024-01-10 17:37:25 -05:00
|
|
|
op_net_listen_udp,
|
|
|
|
op_net_listen_unixpacket,
|
2023-03-28 08:44:22 -04:00
|
|
|
),
|
2023-02-07 14:22:46 -05:00
|
|
|
umask: fs.umask,
|
|
|
|
HttpClient: httpClient.HttpClient,
|
|
|
|
createHttpClient: httpClient.createHttpClient,
|
|
|
|
dlopen: ffi.dlopen,
|
|
|
|
UnsafeCallback: ffi.UnsafeCallback,
|
|
|
|
UnsafePointer: ffi.UnsafePointer,
|
|
|
|
UnsafePointerView: ffi.UnsafePointerView,
|
|
|
|
UnsafeFnPointer: ffi.UnsafeFnPointer,
|
feat:: External webgpu surfaces / BYOW (#21835)
This PR contains the implementation of the External webgpu surfaces /
BYOW proposal. BYOW stands for "Bring your own window".
Closes #21713
Adds `Deno.UnsafeWindowSurface` ( `--unstable-webgpu` API) to the `Deno`
namespace:
```typescript
class UnsafeWindowSurface {
constructor(
system: "cocoa" | "x11" | "win32",
winHandle: Deno.PointerValue,
displayHandle: Deno.PointerValue | null
);
getContext(type: "webgpu"): GPUCanvasContext;
present(): void;
}
```
For the initial pass, I've opted to support the three major windowing
systems. The parameters correspond to the table below:
| system | winHandle | displayHandle |
| ----------------- | ---------- | ------- |
| "cocoa" (macOS) | `NSView*` | - |
| "win32" (Windows) | `HWND` | `HINSTANCE` |
| "x11" (Linux) | Xlib `Window` | Xlib `Display*` |
Ecosystem support:
- [x] deno_sdl2 (sdl2) -
[mod.ts#L1209](https://github.com/littledivy/deno_sdl2/blob/7e177bc6524750a8849c25ce421798b2e71ec943/mod.ts#L1209)
- [x] dwm (glfw) - https://github.com/deno-windowing/dwm/issues/29
- [ ] pane (winit)
<details>
<summary>Example</summary>
```typescript
// A simple clear screen pass, colors based on mouse position.
import { EventType, WindowBuilder } from "https://deno.land/x/sdl2@0.7.0/mod.ts";
const window = new WindowBuilder("sdl2 + deno + webgpu", 640, 480).build();
const [system, windowHandle, displayHandle] = window.rawHandle();
const adapter = await navigator.gpu.requestAdapter();
const device = await adapter.requestDevice();
const context = Deno.createWindowSurface(system, windowHandle, displayHandle);
context.configure({
device: device,
format: "bgra8unorm",
height: 480,
width: 640,
});
let r = 0.0;
let g = 0.0;
let b = 0.0;
for (const event of window.events()) {
if (event.type === EventType.Quit) {
break;
} else if (event.type === EventType.Draw) {
const textureView = context.getCurrentTexture().createView();
const renderPassDescriptor: GPURenderPassDescriptor = {
colorAttachments: [
{
view: textureView,
clearValue: { r, g, b, a: 1.0 },
loadOp: "clear",
storeOp: "store",
},
],
};
const commandEncoder = device.createCommandEncoder();
const passEncoder = commandEncoder.beginRenderPass(renderPassDescriptor);
passEncoder.end();
device.queue.submit([commandEncoder.finish()]);
Deno.presentGPUCanvasContext(context);
}
if (event.type === EventType.MouseMotion) {
r = event.x / 640;
g = event.y / 480;
b = 1.0 - r - g;
}
}
```
You can find more examples in the linked tracking issue.
</details>
---------
Signed-off-by: Divy Srivastava <dj.srivastava23@gmail.com>
2024-01-19 12:19:14 -05:00
|
|
|
UnsafeWindowSurface: webgpuSurface.UnsafeWindowSurface,
|
2023-02-07 14:22:46 -05:00
|
|
|
flock: fs.flock,
|
|
|
|
flockSync: fs.flockSync,
|
|
|
|
funlock: fs.funlock,
|
|
|
|
funlockSync: fs.funlockSync,
|
2023-03-22 15:23:36 -04:00
|
|
|
openKv: kv.openKv,
|
2023-07-01 03:24:15 -04:00
|
|
|
AtomicOperation: kv.AtomicOperation,
|
2023-03-22 00:13:24 -04:00
|
|
|
Kv: kv.Kv,
|
|
|
|
KvU64: kv.KvU64,
|
|
|
|
KvListIterator: kv.KvListIterator,
|
2023-11-01 14:57:55 -04:00
|
|
|
cron: cron.cron,
|
2023-02-07 14:22:46 -05:00
|
|
|
};
|
|
|
|
|
2023-12-08 08:24:49 -05:00
|
|
|
export { denoNs, denoNsUnstable, denoNsUnstableById, unstableIds };
|