From 02b19b115bcc00584e315c22f1d01fe7ac1f2248 Mon Sep 17 00:00:00 2001 From: Slashscreen Date: Wed, 12 Feb 2025 14:27:16 -0800 Subject: [PATCH 1/4] wgpu: add sdl3 glue --- vendor/wgpu/sdl3glue/glue.odin | 6 ++++ vendor/wgpu/sdl3glue/glue_darwin.odin | 23 +++++++++++++ vendor/wgpu/sdl3glue/glue_linux.odin | 45 ++++++++++++++++++++++++++ vendor/wgpu/sdl3glue/glue_windows.odin | 23 +++++++++++++ 4 files changed, 97 insertions(+) create mode 100644 vendor/wgpu/sdl3glue/glue.odin create mode 100644 vendor/wgpu/sdl3glue/glue_darwin.odin create mode 100644 vendor/wgpu/sdl3glue/glue_linux.odin create mode 100644 vendor/wgpu/sdl3glue/glue_windows.odin diff --git a/vendor/wgpu/sdl3glue/glue.odin b/vendor/wgpu/sdl3glue/glue.odin new file mode 100644 index 000000000..7d4975fb0 --- /dev/null +++ b/vendor/wgpu/sdl3glue/glue.odin @@ -0,0 +1,6 @@ +#+build !linux +#+build !windows +#+build !darwin +package wgpu_sdl3_glue + +#panic("package wgpu/sdl3glue is not supported on the current target") diff --git a/vendor/wgpu/sdl3glue/glue_darwin.odin b/vendor/wgpu/sdl3glue/glue_darwin.odin new file mode 100644 index 000000000..8cea27256 --- /dev/null +++ b/vendor/wgpu/sdl3glue/glue_darwin.odin @@ -0,0 +1,23 @@ +package wgpu_sdl3_glue + +import "vendor:sdl3" +import "vendor:wgpu" +import CA "vendor:darwin/QuartzCore" +import NS "core:sys/darwin/Foundation" + +GetSurface :: proc(instance: wgpu.Instance, window: ^sdl3.Window) -> wgpu.Surface { + ns_window := cast(^NS.Window)sdl3.GetPointerProperty(sdl3.GetWindowProperties(window), sdl3.PROP_WINDOW_COCOA_WINDOW_POINTER, nil) + metal_layer := CA.MetalLayer_layer() + ns_window->contentView()->setLayer(metal_layer) + return wgpu.InstanceCreateSurface( + instance, + &wgpu.SurfaceDescriptor{ + nextInChain = &wgpu.SurfaceDescriptorFromMetalLayer{ + chain = wgpu.ChainedStruct{ + sType = .SurfaceDescriptorFromMetalLayer, + }, + layer = rawptr(metal_layer), + }, + }, + ) +} diff --git a/vendor/wgpu/sdl3glue/glue_linux.odin b/vendor/wgpu/sdl3glue/glue_linux.odin new file mode 100644 index 000000000..3d89718db --- /dev/null +++ b/vendor/wgpu/sdl3glue/glue_linux.odin @@ -0,0 +1,45 @@ +package wgpu_sdl3_glue + +import "vendor:sdl3" +import "vendor:wgpu" + +@(private="file") +DRIVER_X11: cstring = "x11" +@(private="file") +DRIVER_WAYLAND: cstring = "wayland" + +GetSurface :: proc(instance: wgpu.Instance, window: ^sdl3.Window) -> wgpu.Surface { + if sdl3.strcmp(sdl3.GetCurrentVideoDriver(), DRIVER_WAYLAND) == 0 { + display := sdl3.GetPointerProperty(sdl3.GetWindowProperties(window), sdl3.PROP_WINDOW_X11_DISPLAY_POINTER, nil) + surface := sdl3.GetNumberProperty(sdl3.GetWindowProperties(window), sdl3.PROP_WINDOW_X11_WINDOW_NUMBER, 0) + return wgpu.InstanceCreateSurface( + instance, + &wgpu.SurfaceDescriptor{ + nextInChain = &wgpu.SurfaceDescriptorFromWaylandSurface{ + chain = { + sType = .SurfaceDescriptorFromWaylandSurface, + }, + display = display, + surface = surface, + }, + }, + ) + } else if sdl3.strcmp(sdl3.GetCurrentVideoDriver(), DRIVER_X11) == 0 { + display := sdl3.GetPointerProperty(sdl3.GetWindowProperties(window), sdl3.PROP_WINDOW_WAYLAND_DISPLAY_POINTER, nil) + surface := sdl3.GetPointerProperty(sdl3.GetWindowProperties(window), sdl3.PROP_WINDOW_WAYLAND_SURFACE_POINTER, 0) + return wgpu.InstanceCreateSurface( + instance, + &wgpu.SurfaceDescriptor{ + nextInChain = &wgpu.SurfaceDescriptorFromXlibWindow{ + chain = { + sType = .SurfaceDescriptorFromXlibWindow, + }, + display = display, + window = u64(window), + }, + }, + ) + } else { + panic("wgpu sdl3 glue: unsupported platform, expected Wayland or X11") + } +} diff --git a/vendor/wgpu/sdl3glue/glue_windows.odin b/vendor/wgpu/sdl3glue/glue_windows.odin new file mode 100644 index 000000000..48adf52f8 --- /dev/null +++ b/vendor/wgpu/sdl3glue/glue_windows.odin @@ -0,0 +1,23 @@ +package wgpu_sdl3_glue + +import win "core:sys/windows" + +import "vendor:sdl3" +import "vendor:wgpu" + +GetSurface :: proc(instance: wgpu.Instance, window: ^sdl3.Window) -> wgpu.Surface { + hwnd := sdl3.GetPointerProperty(sdl3.GetWindowProperties(window), sdl3.PROP_WINDOW_WIN32_HWND_POINTER, nil) + hinstance := win.GetModuleHandleW(nil) + return wgpu.InstanceCreateSurface( + instance, + &wgpu.SurfaceDescriptor{ + nextInChain = &wgpu.SurfaceDescriptorFromWindowsHWND{ + chain = wgpu.ChainedStruct{ + sType = .SurfaceDescriptorFromWindowsHWND, + }, + hinstance = rawptr(hinstance), + hwnd = rawptr(hwnd), + }, + }, + ) +} From 2f82d4e325c2b9d7ba3db9deef45c9000521d7ac Mon Sep 17 00:00:00 2001 From: Slashscreen Date: Wed, 12 Feb 2025 15:06:22 -0800 Subject: [PATCH 2/4] fixed many oversights --- vendor/wgpu/sdl3glue/glue_darwin.odin | 21 ++++------ vendor/wgpu/sdl3glue/glue_linux.odin | 53 +++++++++++++++----------- vendor/wgpu/sdl3glue/glue_windows.odin | 28 ++++++++------ 3 files changed, 56 insertions(+), 46 deletions(-) diff --git a/vendor/wgpu/sdl3glue/glue_darwin.odin b/vendor/wgpu/sdl3glue/glue_darwin.odin index 8cea27256..4de39b3e3 100644 --- a/vendor/wgpu/sdl3glue/glue_darwin.odin +++ b/vendor/wgpu/sdl3glue/glue_darwin.odin @@ -1,22 +1,17 @@ package wgpu_sdl3_glue -import "vendor:sdl3" -import "vendor:wgpu" -import CA "vendor:darwin/QuartzCore" -import NS "core:sys/darwin/Foundation" +import "vendor:sdl3" +import "vendor:wgpu" GetSurface :: proc(instance: wgpu.Instance, window: ^sdl3.Window) -> wgpu.Surface { - ns_window := cast(^NS.Window)sdl3.GetPointerProperty(sdl3.GetWindowProperties(window), sdl3.PROP_WINDOW_COCOA_WINDOW_POINTER, nil) - metal_layer := CA.MetalLayer_layer() - ns_window->contentView()->setLayer(metal_layer) + view := sdl3.Metal_CreateView(window) + metal_layer := sdl3.Metal_GetLayer(view) return wgpu.InstanceCreateSurface( instance, - &wgpu.SurfaceDescriptor{ - nextInChain = &wgpu.SurfaceDescriptorFromMetalLayer{ - chain = wgpu.ChainedStruct{ - sType = .SurfaceDescriptorFromMetalLayer, - }, - layer = rawptr(metal_layer), + &wgpu.SurfaceDescriptor { + nextInChain = &wgpu.SurfaceDescriptorFromMetalLayer { + chain = wgpu.ChainedStruct{sType = .SurfaceDescriptorFromMetalLayer}, + layer = metal_layer, }, }, ) diff --git a/vendor/wgpu/sdl3glue/glue_linux.odin b/vendor/wgpu/sdl3glue/glue_linux.odin index 3d89718db..735868447 100644 --- a/vendor/wgpu/sdl3glue/glue_linux.odin +++ b/vendor/wgpu/sdl3glue/glue_linux.odin @@ -3,43 +3,52 @@ package wgpu_sdl3_glue import "vendor:sdl3" import "vendor:wgpu" -@(private="file") -DRIVER_X11: cstring = "x11" -@(private="file") -DRIVER_WAYLAND: cstring = "wayland" GetSurface :: proc(instance: wgpu.Instance, window: ^sdl3.Window) -> wgpu.Surface { - if sdl3.strcmp(sdl3.GetCurrentVideoDriver(), DRIVER_WAYLAND) == 0 { - display := sdl3.GetPointerProperty(sdl3.GetWindowProperties(window), sdl3.PROP_WINDOW_X11_DISPLAY_POINTER, nil) - surface := sdl3.GetNumberProperty(sdl3.GetWindowProperties(window), sdl3.PROP_WINDOW_X11_WINDOW_NUMBER, 0) + switch sdl3.GetCurrentVideoDriver() { + case "x11": + display := sdl3.GetPointerProperty( + sdl3.GetWindowProperties(window), + sdl3.PROP_WINDOW_X11_DISPLAY_POINTER, + nil, + ) + surface := sdl3.GetNumberProperty( + sdl3.GetWindowProperties(window), + sdl3.PROP_WINDOW_X11_WINDOW_NUMBER, + 0, + ) return wgpu.InstanceCreateSurface( instance, - &wgpu.SurfaceDescriptor{ - nextInChain = &wgpu.SurfaceDescriptorFromWaylandSurface{ - chain = { - sType = .SurfaceDescriptorFromWaylandSurface, - }, + &wgpu.SurfaceDescriptor { + nextInChain = &wgpu.SurfaceDescriptorFromWaylandSurface { + chain = {sType = .SurfaceDescriptorFromWaylandSurface}, display = display, surface = surface, }, }, ) - } else if sdl3.strcmp(sdl3.GetCurrentVideoDriver(), DRIVER_X11) == 0 { - display := sdl3.GetPointerProperty(sdl3.GetWindowProperties(window), sdl3.PROP_WINDOW_WAYLAND_DISPLAY_POINTER, nil) - surface := sdl3.GetPointerProperty(sdl3.GetWindowProperties(window), sdl3.PROP_WINDOW_WAYLAND_SURFACE_POINTER, 0) + case "wayland": + display := sdl3.GetPointerProperty( + sdl3.GetWindowProperties(window), + sdl3.PROP_WINDOW_WAYLAND_DISPLAY_POINTER, + nil, + ) + surface := sdl3.GetPointerProperty( + sdl3.GetWindowProperties(window), + sdl3.PROP_WINDOW_WAYLAND_SURFACE_POINTER, + 0, + ) return wgpu.InstanceCreateSurface( instance, - &wgpu.SurfaceDescriptor{ - nextInChain = &wgpu.SurfaceDescriptorFromXlibWindow{ - chain = { - sType = .SurfaceDescriptorFromXlibWindow, - }, + &wgpu.SurfaceDescriptor { + nextInChain = &wgpu.SurfaceDescriptorFromXlibWindow { + chain = {sType = .SurfaceDescriptorFromXlibWindow}, display = display, - window = u64(window), + window = u64(window), }, }, ) - } else { + case: panic("wgpu sdl3 glue: unsupported platform, expected Wayland or X11") } } diff --git a/vendor/wgpu/sdl3glue/glue_windows.odin b/vendor/wgpu/sdl3glue/glue_windows.odin index 48adf52f8..c114789f0 100644 --- a/vendor/wgpu/sdl3glue/glue_windows.odin +++ b/vendor/wgpu/sdl3glue/glue_windows.odin @@ -2,21 +2,27 @@ package wgpu_sdl3_glue import win "core:sys/windows" -import "vendor:sdl3" -import "vendor:wgpu" +import "vendor:sdl3" +import "vendor:wgpu" GetSurface :: proc(instance: wgpu.Instance, window: ^sdl3.Window) -> wgpu.Surface { - hwnd := sdl3.GetPointerProperty(sdl3.GetWindowProperties(window), sdl3.PROP_WINDOW_WIN32_HWND_POINTER, nil) - hinstance := win.GetModuleHandleW(nil) + hwnd := sdl3.GetPointerProperty( + sdl3.GetWindowProperties(window), + sdl3.PROP_WINDOW_WIN32_HWND_POINTER, + nil, + ) + hinstance := sdl3.GetPointerProperty( + sdl3.GetWindowProperties(window), + sdl3.PROP_WINDOW_WIN32_INSTANCE_POINTER, + nil, + ) return wgpu.InstanceCreateSurface( instance, - &wgpu.SurfaceDescriptor{ - nextInChain = &wgpu.SurfaceDescriptorFromWindowsHWND{ - chain = wgpu.ChainedStruct{ - sType = .SurfaceDescriptorFromWindowsHWND, - }, - hinstance = rawptr(hinstance), - hwnd = rawptr(hwnd), + &wgpu.SurfaceDescriptor { + nextInChain = &wgpu.SurfaceDescriptorFromWindowsHWND { + chain = wgpu.ChainedStruct{sType = .SurfaceDescriptorFromWindowsHWND}, + hinstance = hinstance, + hwnd = hwnd, }, }, ) From 503813431b203437a56ba6e49307044387ae6d3c Mon Sep 17 00:00:00 2001 From: Slashscreen Date: Wed, 12 Feb 2025 15:58:56 -0800 Subject: [PATCH 3/4] Switched X11 and Wayland --- vendor/wgpu/sdl3glue/glue_linux.odin | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/vendor/wgpu/sdl3glue/glue_linux.odin b/vendor/wgpu/sdl3glue/glue_linux.odin index 735868447..10fff757f 100644 --- a/vendor/wgpu/sdl3glue/glue_linux.odin +++ b/vendor/wgpu/sdl3glue/glue_linux.odin @@ -12,7 +12,7 @@ GetSurface :: proc(instance: wgpu.Instance, window: ^sdl3.Window) -> wgpu.Surfac sdl3.PROP_WINDOW_X11_DISPLAY_POINTER, nil, ) - surface := sdl3.GetNumberProperty( + x_window := sdl3.GetNumberProperty( sdl3.GetWindowProperties(window), sdl3.PROP_WINDOW_X11_WINDOW_NUMBER, 0, @@ -20,10 +20,10 @@ GetSurface :: proc(instance: wgpu.Instance, window: ^sdl3.Window) -> wgpu.Surfac return wgpu.InstanceCreateSurface( instance, &wgpu.SurfaceDescriptor { - nextInChain = &wgpu.SurfaceDescriptorFromWaylandSurface { - chain = {sType = .SurfaceDescriptorFromWaylandSurface}, + nextInChain = &wgpu.SurfaceDescriptorFromXlibWindow { + chain = {sType = .SurfaceDescriptorFromXlibWindow}, display = display, - surface = surface, + window = u64(x_window), }, }, ) @@ -33,18 +33,18 @@ GetSurface :: proc(instance: wgpu.Instance, window: ^sdl3.Window) -> wgpu.Surfac sdl3.PROP_WINDOW_WAYLAND_DISPLAY_POINTER, nil, ) - surface := sdl3.GetPointerProperty( + w_surface := sdl3.GetPointerProperty( sdl3.GetWindowProperties(window), sdl3.PROP_WINDOW_WAYLAND_SURFACE_POINTER, - 0, + nil, ) return wgpu.InstanceCreateSurface( instance, &wgpu.SurfaceDescriptor { - nextInChain = &wgpu.SurfaceDescriptorFromXlibWindow { - chain = {sType = .SurfaceDescriptorFromXlibWindow}, + nextInChain = &wgpu.SurfaceDescriptorFromWaylandSurface { + chain = {sType = .SurfaceDescriptorFromWaylandSurface}, display = display, - window = u64(window), + surface = u64(w_surface), }, }, ) From b7f37bbee500b05233959e4b276310db6cd63ae4 Mon Sep 17 00:00:00 2001 From: Slashscreen Date: Wed, 12 Feb 2025 16:13:57 -0800 Subject: [PATCH 4/4] removed cast. --- vendor/wgpu/sdl3glue/glue_linux.odin | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vendor/wgpu/sdl3glue/glue_linux.odin b/vendor/wgpu/sdl3glue/glue_linux.odin index 10fff757f..a8dc6f180 100644 --- a/vendor/wgpu/sdl3glue/glue_linux.odin +++ b/vendor/wgpu/sdl3glue/glue_linux.odin @@ -44,7 +44,7 @@ GetSurface :: proc(instance: wgpu.Instance, window: ^sdl3.Window) -> wgpu.Surfac nextInChain = &wgpu.SurfaceDescriptorFromWaylandSurface { chain = {sType = .SurfaceDescriptorFromWaylandSurface}, display = display, - surface = u64(w_surface), + surface = w_surface, }, }, )