1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 07:14:47 -05:00
denoland-deno/ext
Divy Srivastava 40febd9dd1
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](7e177bc652/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 22:49:14 +05:30
..
broadcast_channel chore: forward v1.39.4 release commit to main (#21933) 2024-01-13 20:32:50 -05:00
cache chore(ext/cache): remove CachePutResource in preparation for resource rewrite (#21949) 2024-01-15 13:14:54 -07:00
console feat(unstable): add Temporal API support (#21738) 2024-01-15 01:26:57 +01:00
cron chore: forward v1.39.4 release commit to main (#21933) 2024-01-13 20:32:50 -05:00
crypto chore: forward v1.39.4 release commit to main (#21933) 2024-01-13 20:32:50 -05:00
fetch chore: upgrade deno_core to 0.247.0 (#21974) 2024-01-18 17:57:22 +01:00
ffi chore: forward v1.39.4 release commit to main (#21933) 2024-01-13 20:32:50 -05:00
fs chore: forward v1.39.4 release commit to main (#21933) 2024-01-13 20:32:50 -05:00
http chore: forward v1.39.4 release commit to main (#21933) 2024-01-13 20:32:50 -05:00
io chore: forward v1.39.4 release commit to main (#21933) 2024-01-13 20:32:50 -05:00
kv chore: forward v1.39.4 release commit to main (#21933) 2024-01-13 20:32:50 -05:00
napi chore: forward v1.39.4 release commit to main (#21933) 2024-01-13 20:32:50 -05:00
net chore: bump rustls-tokio-stream and rustls (#21955) 2024-01-16 21:51:54 +01:00
node fix(node): remove use of non existing FunctionPrototypeApply primordial (#21986) 2024-01-19 12:01:46 -05:00
tls chore: forward v1.39.4 release commit to main (#21933) 2024-01-13 20:32:50 -05:00
url chore: forward v1.39.4 release commit to main (#21933) 2024-01-13 20:32:50 -05:00
web chore: forward v1.39.4 release commit to main (#21933) 2024-01-13 20:32:50 -05:00
webgpu feat:: External webgpu surfaces / BYOW (#21835) 2024-01-19 22:49:14 +05:30
webidl chore: forward v1.39.4 release commit to main (#21933) 2024-01-13 20:32:50 -05:00
websocket chore: bump rustls-tokio-stream and rustls (#21955) 2024-01-16 21:51:54 +01:00
webstorage chore: forward v1.39.4 release commit to main (#21933) 2024-01-13 20:32:50 -05:00