1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-21 21:50:00 -05:00
denoland-deno/runtime/js
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
..
01_errors.js chore: update copyright to 2024 (#21753) 2024-01-01 19:58:21 +00:00
01_version.ts refactor: use core.ensureFastOps() (#21888) 2024-01-10 15:37:25 -07:00
06_util.js refactor: use core.ensureFastOps() (#21888) 2024-01-10 15:37:25 -07:00
10_permissions.js refactor: use core.ensureFastOps() (#21888) 2024-01-10 15:37:25 -07:00
11_workers.js refactor: use core.ensureFastOps() (#21888) 2024-01-10 15:37:25 -07:00
13_buffer.js refactor: use core.ensureFastOps() (#21888) 2024-01-10 15:37:25 -07:00
30_os.js refactor: use core.ensureFastOps() (#21888) 2024-01-10 15:37:25 -07:00
40_fs_events.js refactor: use core.ensureFastOps() (#21888) 2024-01-10 15:37:25 -07:00
40_http.js refactor: use core.ensureFastOps() (#21888) 2024-01-10 15:37:25 -07:00
40_process.js feat: Start warning on each use of a deprecated API (#21939) 2024-01-18 23:30:49 +00:00
40_signals.js refactor: use core.ensureFastOps() (#21888) 2024-01-10 15:37:25 -07:00
40_tty.js refactor: use core.ensureFastOps() (#21888) 2024-01-10 15:37:25 -07:00
41_prompt.js fix(web): use rustyline for prompt (#21893) 2024-01-11 22:05:55 +01:00
90_deno_ns.js feat:: External webgpu surfaces / BYOW (#21835) 2024-01-19 22:49:14 +05:30
98_global_scope_shared.js refactor: split runtime/98_global_scope.js (#21785) 2024-01-06 14:40:26 +01:00
98_global_scope_window.js refactor: use core.ensureFastOps() (#21888) 2024-01-10 15:37:25 -07:00
98_global_scope_worker.js refactor: use core.ensureFastOps() (#21888) 2024-01-10 15:37:25 -07:00
99_main.js feat: Start warning on each use of a deprecated API (#21939) 2024-01-18 23:30:49 +00:00
README.md feat: add --location=<href> and globalThis.location (#7369) 2021-01-07 19:06:08 +01:00

Runtime JavaScript Code

This directory contains Deno runtime code written in plain JavaScript.

Each file is a plain, old script, not ES modules. The reason is that snapshotting ES modules is much harder, especially if one needs to manipulate global scope (like in case of Deno).

Each file is prefixed with a number, telling in which order scripts should be loaded into V8 isolate. This is temporary solution and we're striving not to require specific order (though it's not 100% obvious if that's feasible).

Deno Web APIs

This directory facilities Web APIs that are available in Deno.

Please note, that some implementations might not be completely aligned with specification.

Some Web APIs are using ops under the hood, eg. console, performance.

Implemented Web APIs