2024-01-01 14:58:21 -05:00
|
|
|
# Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2023-12-08 19:19:16 -05:00
|
|
|
|
|
|
|
[package]
|
|
|
|
name = "deno_webgpu"
|
2024-02-15 01:45:36 -05:00
|
|
|
version = "0.105.0"
|
2023-12-08 19:19:16 -05:00
|
|
|
authors = ["the Deno authors"]
|
|
|
|
edition.workspace = true
|
|
|
|
license = "MIT"
|
|
|
|
readme = "README.md"
|
|
|
|
repository = "https://github.com/gfx-rs/wgpu"
|
|
|
|
description = "WebGPU implementation for Deno"
|
|
|
|
|
|
|
|
[lib]
|
|
|
|
path = "lib.rs"
|
|
|
|
|
|
|
|
# We make all dependencies conditional on not being wasm,
|
|
|
|
# so the whole workspace can built as wasm.
|
|
|
|
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
|
|
|
deno_core.workspace = true
|
|
|
|
serde = { workspace = true, features = ["derive"] }
|
|
|
|
tokio = { workspace = true, features = ["full"] }
|
|
|
|
wgpu-types = { workspace = true, features = ["trace", "replay", "serde"] }
|
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
|
|
|
raw-window-handle = { workspace = true }
|
2023-12-08 19:19:16 -05:00
|
|
|
|
|
|
|
[target.'cfg(not(target_arch = "wasm32"))'.dependencies.wgpu-core]
|
|
|
|
workspace = true
|
|
|
|
features = ["trace", "replay", "serde", "strict_asserts", "wgsl", "gles"]
|
|
|
|
|
|
|
|
# We want the wgpu-core Metal backend on macOS and iOS.
|
|
|
|
[target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies.wgpu-core]
|
|
|
|
workspace = true
|
|
|
|
features = ["metal"]
|
|
|
|
|
|
|
|
# We want the wgpu-core Direct3D backends on Windows.
|
|
|
|
[target.'cfg(windows)'.dependencies.wgpu-core]
|
|
|
|
workspace = true
|
|
|
|
features = ["dx11", "dx12"]
|
|
|
|
|
|
|
|
[target.'cfg(windows)'.dependencies.wgpu-hal]
|
|
|
|
workspace = true
|
|
|
|
features = ["windows_rs"]
|
|
|
|
|
|
|
|
# We want the wgpu-core Vulkan backend on Unix (but not Emscripten) and Windows.
|
|
|
|
[target.'cfg(any(windows, all(unix, not(target_os = "emscripten"))))'.dependencies.wgpu-core]
|
|
|
|
workspace = true
|
|
|
|
features = ["vulkan"]
|