frazzle
frazzle
DDeno
Created by frazzle on 6/16/2024 in #help
Deno BYOW help with macOS [Solved] and X11
@divy @crowlKats is it possible to make a headless WebGPU surface and then render it to a texture? I wanted to use three.js with RTT
12 replies
DDeno
Created by frazzle on 6/16/2024 in #help
Deno BYOW help with macOS [Solved] and X11
Worked when I recreated the surface and called the redraw function in the resize callback
12 replies
DDeno
Created by frazzle on 6/16/2024 in #help
Deno BYOW help with macOS [Solved] and X11
on resize, you need to recreate the surface
This didn't work either, is this a macOS only limitation? works fine on Windows and Wayland. This is what I did:
WindowEvent::Resized(size) => {
match window.raw_window_handle() {
raw_window_handle::RawWindowHandle::AppKit(handle) => setup_func(
handle.ns_window,
handle.ns_view,
window.inner_size().width,
window.inner_size().height,
),
_ => (),
}
resize_func(size.width, size.height);
}
WindowEvent::Resized(size) => {
match window.raw_window_handle() {
raw_window_handle::RawWindowHandle::AppKit(handle) => setup_func(
handle.ns_window,
handle.ns_view,
window.inner_size().width,
window.inner_size().height,
),
_ => (),
}
resize_func(size.width, size.height);
}
setup_func recreates the WebGPU surface.
12 replies
DDeno
Created by frazzle on 6/16/2024 in #help
Deno BYOW help with macOS [Solved] and X11
No description
12 replies
DDeno
Created by frazzle on 6/16/2024 in #help
Deno BYOW help with macOS [Solved] and X11
For X11 I have to check again, the window doesn't even spawn but that could be because I'm not using winit correctly.
12 replies
DDeno
Created by frazzle on 6/16/2024 in #help
Deno BYOW help with macOS [Solved] and X11
This is the from the Deno.UnsafeWindowSurface doc:
| system | winHandle | displayHandle |
| ----------------- | ------------- | --------------- |
| "cocoa" (macOS) | `NSView*` | - |
| "win32" (Windows) | `HWND` | `HINSTANCE` |
| "x11" (Linux) | Xlib `Window` | Xlib `Display*` |
| "wayland" (Linux) | `wl_surface*` | `wl_display*` |
| system | winHandle | displayHandle |
| ----------------- | ------------- | --------------- |
| "cocoa" (macOS) | `NSView*` | - |
| "win32" (Windows) | `HWND` | `HINSTANCE` |
| "x11" (Linux) | Xlib `Window` | Xlib `Display*` |
| "wayland" (Linux) | `wl_surface*` | `wl_display*` |
For macOS, I'm passing in handle.ns_view for the window handle and a null pointer for the display handle but I think the draw function callback is being called before the setup function and nothing gets drawn to the window. When I pass in handle.ns_window for the window handle and handle.ns_view for the display handle it does work except it doesn't redraw properly when the window is resized. @divy what am I doing wrong?
12 replies
DDeno
Created by frazzle on 6/16/2024 in #help
Deno BYOW help with macOS [Solved] and X11
And these are the callback in Deno (in mod.ts),
let surface: Deno.UnsafeWindowSurface | null = null;
let context: GPUCanvasContext | null = null;
const setupFunctionCallback = new Deno.UnsafeCallback(
{ parameters: ["pointer", "pointer", "u32", "u32"], result: "void" },
(winHandle, displayHandle, width, height) => {
if (!this.system) {
console.error("System not supported.");
return;
}

surface = new Deno.UnsafeWindowSurface(
this.system,
winHandle,
displayHandle
);
context = surface.getContext("webgpu");
context.configure({
device,
format: this.presentationFormat,
width,
height,
});
this.setupFunction(device, context);
}
);

const drawFunctionCallback = new Deno.UnsafeCallback(
{ parameters: [], result: "void" },
() => {
if (!surface) {
console.error("Surface not initialized.");
return;
}

if (!context) {
console.error("Context not initialized.");
return;
}

this.drawFunction(device, context);
surface.present();
}
);
let surface: Deno.UnsafeWindowSurface | null = null;
let context: GPUCanvasContext | null = null;
const setupFunctionCallback = new Deno.UnsafeCallback(
{ parameters: ["pointer", "pointer", "u32", "u32"], result: "void" },
(winHandle, displayHandle, width, height) => {
if (!this.system) {
console.error("System not supported.");
return;
}

surface = new Deno.UnsafeWindowSurface(
this.system,
winHandle,
displayHandle
);
context = surface.getContext("webgpu");
context.configure({
device,
format: this.presentationFormat,
width,
height,
});
this.setupFunction(device, context);
}
);

const drawFunctionCallback = new Deno.UnsafeCallback(
{ parameters: [], result: "void" },
() => {
if (!surface) {
console.error("Surface not initialized.");
return;
}

if (!context) {
console.error("Context not initialized.");
return;
}

this.drawFunction(device, context);
surface.present();
}
);
12 replies
DDeno
Created by frazzle on 6/16/2024 in #help
Deno BYOW help with macOS [Solved] and X11
This is the setup code in Rust (in src/lib.rs):
match window.raw_window_handle() {
raw_window_handle::RawWindowHandle::Win32(handle) => setup_func(
handle.hwnd,
handle.hinstance,
window.inner_size().width,
window.inner_size().height,
),
raw_window_handle::RawWindowHandle::AppKit(handle) => setup_func(
handle.ns_view,
null::<ffi::c_void>() as *mut ffi::c_void,
window.inner_size().width,
window.inner_size().height,
),
_ => (),
}

if let raw_window_handle::RawWindowHandle::Wayland(window_handle) = window.raw_window_handle() {
match window.raw_display_handle() {
raw_window_handle::RawDisplayHandle::Wayland(display_handle) => setup_func(
window_handle.surface,
display_handle.display,
window.inner_size().width,
window.inner_size().height,
),
_ => (),
}
} else if let raw_window_handle::RawWindowHandle::Xlib(window_handle) =
window.raw_window_handle()
{
match window.raw_display_handle() {
raw_window_handle::RawDisplayHandle::Xlib(display_handle) => {
setup_func(
window_handle.window as *mut ffi::c_void,
display_handle.display,
window.inner_size().width,
window.inner_size().height,
);
}
_ => (),
}
}
match window.raw_window_handle() {
raw_window_handle::RawWindowHandle::Win32(handle) => setup_func(
handle.hwnd,
handle.hinstance,
window.inner_size().width,
window.inner_size().height,
),
raw_window_handle::RawWindowHandle::AppKit(handle) => setup_func(
handle.ns_view,
null::<ffi::c_void>() as *mut ffi::c_void,
window.inner_size().width,
window.inner_size().height,
),
_ => (),
}

if let raw_window_handle::RawWindowHandle::Wayland(window_handle) = window.raw_window_handle() {
match window.raw_display_handle() {
raw_window_handle::RawDisplayHandle::Wayland(display_handle) => setup_func(
window_handle.surface,
display_handle.display,
window.inner_size().width,
window.inner_size().height,
),
_ => (),
}
} else if let raw_window_handle::RawWindowHandle::Xlib(window_handle) =
window.raw_window_handle()
{
match window.raw_display_handle() {
raw_window_handle::RawDisplayHandle::Xlib(display_handle) => {
setup_func(
window_handle.window as *mut ffi::c_void,
display_handle.display,
window.inner_size().width,
window.inner_size().height,
);
}
_ => (),
}
}
12 replies
DDeno
Created by frazzle on 11/15/2022 in #help
Arrow keys don't work when using cli on windows
6 replies
DDeno
Created by frazzle on 11/15/2022 in #help
Arrow keys don't work when using cli on windows
It's a known bug from 2020
6 replies