Skip to content

Commit

Permalink
wgpu: update to v24.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
laytan committed Feb 17, 2025
1 parent f0b1357 commit ae9388c
Show file tree
Hide file tree
Showing 20 changed files with 1,801 additions and 1,342 deletions.
4 changes: 2 additions & 2 deletions vendor/wgpu/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ Have a look at the `example/` directory for the rendering of a basic triangle.
## Getting the wgpu-native libraries

For native support (not the browser), some libraries are required. Fortunately this is
extremely easy, just download them from the [releases on GitHub](https://github.com/gfx-rs/wgpu-native/releases/tag/v22.1.0.1),
the bindings are for v22.1.0.1 at the moment.
extremely easy, just download them from the [releases on GitHub](https://github.com/gfx-rs/wgpu-native/releases/tag/v24.0.1),
the bindings are for v24.0.1 at the moment.

These are expected in the `lib` folder under the same name as they are released (just unzipped).
By default it will look for a static release version (`wgpu-OS-ARCH-release.a|lib`),
Expand Down
18 changes: 9 additions & 9 deletions vendor/wgpu/examples/glfw/main.odin
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,18 @@ main :: proc() {
}
state.surface = os_get_surface(&state.os, state.instance)

wgpu.InstanceRequestAdapter(state.instance, &{ compatibleSurface = state.surface }, on_adapter, nil)
wgpu.InstanceRequestAdapter(state.instance, &{ compatibleSurface = state.surface }, { callback = on_adapter })

on_adapter :: proc "c" (status: wgpu.RequestAdapterStatus, adapter: wgpu.Adapter, message: cstring, userdata: rawptr) {
on_adapter :: proc "c" (status: wgpu.RequestAdapterStatus, adapter: wgpu.Adapter, message: string, userdata1: rawptr, userdata2: rawptr) {
context = state.ctx
if status != .Success || adapter == nil {
fmt.panicf("request adapter failure: [%v] %s", status, message)
}
state.adapter = adapter
wgpu.AdapterRequestDevice(adapter, nil, on_device)
wgpu.AdapterRequestDevice(adapter, nil, { callback = on_device })
}

on_device :: proc "c" (status: wgpu.RequestDeviceStatus, device: wgpu.Device, message: cstring, userdata: rawptr) {
on_device :: proc "c" (status: wgpu.RequestDeviceStatus, device: wgpu.Device, message: string, userdata1: rawptr, userdata2: rawptr) {
context = state.ctx
if status != .Success || device == nil {
fmt.panicf("request device failure: [%v] %s", status, message)
Expand Down Expand Up @@ -82,8 +82,8 @@ main :: proc() {
}`

state.module = wgpu.DeviceCreateShaderModule(state.device, &{
nextInChain = &wgpu.ShaderModuleWGSLDescriptor{
sType = .ShaderModuleWGSLDescriptor,
nextInChain = &wgpu.ShaderSourceWGSL{
sType = .ShaderSourceWGSL,
code = shader,
},
})
Expand Down Expand Up @@ -130,16 +130,16 @@ frame :: proc "c" (dt: f32) {

surface_texture := wgpu.SurfaceGetCurrentTexture(state.surface)
switch surface_texture.status {
case .Success:
// All good, could check for `surface_texture.suboptimal` here.
case .SuccessOptimal, .SuccessSuboptimal:
// All good, could handle suboptimal here.
case .Timeout, .Outdated, .Lost:
// Skip this frame, and re-configure surface.
if surface_texture.texture != nil {
wgpu.TextureRelease(surface_texture.texture)
}
resize()
return
case .OutOfMemory, .DeviceLost:
case .OutOfMemory, .DeviceLost, .Error:
// Fatal error
fmt.panicf("[triangle] get_current_texture status=%v", surface_texture.status)
}
Expand Down
2 changes: 1 addition & 1 deletion vendor/wgpu/examples/glfw/os_glfw.odin
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ os_init :: proc(os: ^OS) {
}

os_run :: proc(os: ^OS) {
dt: f32
dt: f32

for !glfw.WindowShouldClose(os.window) {
start := time.tick_now()
Expand Down
4 changes: 2 additions & 2 deletions vendor/wgpu/examples/glfw/os_js.odin
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ os_get_surface :: proc(os: ^OS, instance: wgpu.Instance) -> wgpu.Surface {
return wgpu.InstanceCreateSurface(
instance,
&wgpu.SurfaceDescriptor{
nextInChain = &wgpu.SurfaceDescriptorFromCanvasHTMLSelector{
sType = .SurfaceDescriptorFromCanvasHTMLSelector,
nextInChain = &wgpu.SurfaceSourceCanvasHTMLSelector{
sType = .SurfaceSourceCanvasHTMLSelector,
selector = "#wgpu-canvas",
},
},
Expand Down
18 changes: 9 additions & 9 deletions vendor/wgpu/examples/sdl2/main.odin
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,18 @@ main :: proc() {
}
state.surface = os_get_surface(&state.os, state.instance)

wgpu.InstanceRequestAdapter(state.instance, &{ compatibleSurface = state.surface }, on_adapter, nil)
wgpu.InstanceRequestAdapter(state.instance, &{ compatibleSurface = state.surface }, { callback = on_adapter })

on_adapter :: proc "c" (status: wgpu.RequestAdapterStatus, adapter: wgpu.Adapter, message: cstring, userdata: rawptr) {
on_adapter :: proc "c" (status: wgpu.RequestAdapterStatus, adapter: wgpu.Adapter, message: string, userdata1, userdata2: rawptr) {
context = state.ctx
if status != .Success || adapter == nil {
fmt.panicf("request adapter failure: [%v] %s", status, message)
}
state.adapter = adapter
wgpu.AdapterRequestDevice(adapter, nil, on_device)
wgpu.AdapterRequestDevice(adapter, nil, { callback = on_device })
}

on_device :: proc "c" (status: wgpu.RequestDeviceStatus, device: wgpu.Device, message: cstring, userdata: rawptr) {
on_device :: proc "c" (status: wgpu.RequestDeviceStatus, device: wgpu.Device, message: string, userdata1, userdata2: rawptr) {
context = state.ctx
if status != .Success || device == nil {
fmt.panicf("request device failure: [%v] %s", status, message)
Expand Down Expand Up @@ -82,8 +82,8 @@ main :: proc() {
}`

state.module = wgpu.DeviceCreateShaderModule(state.device, &{
nextInChain = &wgpu.ShaderModuleWGSLDescriptor{
sType = .ShaderModuleWGSLDescriptor,
nextInChain = &wgpu.ShaderSourceWGSL{
sType = .ShaderSourceWGSL,
code = shader,
},
})
Expand Down Expand Up @@ -130,16 +130,16 @@ frame :: proc "c" (dt: f32) {

surface_texture := wgpu.SurfaceGetCurrentTexture(state.surface)
switch surface_texture.status {
case .Success:
// All good, could check for `surface_texture.suboptimal` here.
case .SuccessOptimal, .SuccessSuboptimal:
// All good, could handle suboptimal here.
case .Timeout, .Outdated, .Lost:
// Skip this frame, and re-configure surface.
if surface_texture.texture != nil {
wgpu.TextureRelease(surface_texture.texture)
}
resize()
return
case .OutOfMemory, .DeviceLost:
case .OutOfMemory, .DeviceLost, .Error:
// Fatal error
fmt.panicf("[triangle] get_current_texture status=%v", surface_texture.status)
}
Expand Down
4 changes: 2 additions & 2 deletions vendor/wgpu/examples/sdl2/os_js.odin
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ os_get_surface :: proc(os: ^OS, instance: wgpu.Instance) -> wgpu.Surface {
return wgpu.InstanceCreateSurface(
instance,
&wgpu.SurfaceDescriptor{
nextInChain = &wgpu.SurfaceDescriptorFromCanvasHTMLSelector{
sType = .SurfaceDescriptorFromCanvasHTMLSelector,
nextInChain = &wgpu.SurfaceSourceCanvasHTMLSelector{
sType = .SurfaceSourceCanvasHTMLSelector,
selector = "#wgpu-canvas",
},
},
Expand Down
4 changes: 2 additions & 2 deletions vendor/wgpu/glfwglue/glue_darwin.odin
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ GetSurface :: proc(instance: wgpu.Instance, window: glfw.WindowHandle) -> wgpu.S
return wgpu.InstanceCreateSurface(
instance,
&wgpu.SurfaceDescriptor{
nextInChain = &wgpu.SurfaceDescriptorFromMetalLayer{
nextInChain = &wgpu.SurfaceSourceMetalLayer{
chain = wgpu.ChainedStruct{
sType = .SurfaceDescriptorFromMetalLayer,
sType = .SurfaceSourceMetalLayer,
},
layer = rawptr(metal_layer),
},
Expand Down
8 changes: 4 additions & 4 deletions vendor/wgpu/glfwglue/glue_linux.odin
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ GetSurface :: proc(instance: wgpu.Instance, window: glfw.WindowHandle) -> wgpu.S
return wgpu.InstanceCreateSurface(
instance,
&wgpu.SurfaceDescriptor{
nextInChain = &wgpu.SurfaceDescriptorFromWaylandSurface{
nextInChain = &wgpu.SurfaceSourceWaylandSurface{
chain = {
sType = .SurfaceDescriptorFromWaylandSurface,
sType = .SurfaceSourceWaylandSurface,
},
display = display,
surface = surface,
Expand All @@ -32,9 +32,9 @@ GetSurface :: proc(instance: wgpu.Instance, window: glfw.WindowHandle) -> wgpu.S
return wgpu.InstanceCreateSurface(
instance,
&wgpu.SurfaceDescriptor{
nextInChain = &wgpu.SurfaceDescriptorFromXlibWindow{
nextInChain = &wgpu.SurfaceSourceXlibWindow{
chain = {
sType = .SurfaceDescriptorFromXlibWindow,
sType = .SurfaceSourceXlibWindow,
},
display = display,
window = u64(window),
Expand Down
4 changes: 2 additions & 2 deletions vendor/wgpu/glfwglue/glue_windows.odin
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ GetSurface :: proc(instance: wgpu.Instance, window: glfw.WindowHandle) -> wgpu.S
return wgpu.InstanceCreateSurface(
instance,
&wgpu.SurfaceDescriptor{
nextInChain = &wgpu.SurfaceDescriptorFromWindowsHWND{
nextInChain = &wgpu.SurfaceSourceWindowsHWND{
chain = wgpu.ChainedStruct{
sType = .SurfaceDescriptorFromWindowsHWND,
sType = .SurfaceSourceWindowsHWND,
},
hinstance = rawptr(hinstance),
hwnd = rawptr(hwnd),
Expand Down
4 changes: 2 additions & 2 deletions vendor/wgpu/sdl2glue/glue_darwin.odin
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ GetSurface :: proc(instance: wgpu.Instance, window: ^sdl2.Window) -> wgpu.Surfac
return wgpu.InstanceCreateSurface(
instance,
&wgpu.SurfaceDescriptor{
nextInChain = &wgpu.SurfaceDescriptorFromMetalLayer{
nextInChain = &wgpu.SurfaceSourceMetalLayer{
chain = wgpu.ChainedStruct{
sType = .SurfaceDescriptorFromMetalLayer,
sType = .SurfaceSourceMetalLayer,
},
layer = rawptr(metal_layer),
},
Expand Down
8 changes: 4 additions & 4 deletions vendor/wgpu/sdl2glue/glue_linux.odin
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ GetSurface :: proc(instance: wgpu.Instance, window: ^sdl2.Window) -> wgpu.Surfac
return wgpu.InstanceCreateSurface(
instance,
&wgpu.SurfaceDescriptor{
nextInChain = &wgpu.SurfaceDescriptorFromWaylandSurface{
nextInChain = &wgpu.SurfaceSourceWaylandSurface{
chain = {
sType = .SurfaceDescriptorFromWaylandSurface,
sType = .SurfaceSourceWaylandSurface,
},
display = display,
surface = surface,
Expand All @@ -29,9 +29,9 @@ GetSurface :: proc(instance: wgpu.Instance, window: ^sdl2.Window) -> wgpu.Surfac
return wgpu.InstanceCreateSurface(
instance,
&wgpu.SurfaceDescriptor{
nextInChain = &wgpu.SurfaceDescriptorFromXlibWindow{
nextInChain = &wgpu.SurfaceSourceXlibWindow{
chain = {
sType = .SurfaceDescriptorFromXlibWindow,
sType = .SurfaceSourceXlibWindow,
},
display = display,
window = u64(window),
Expand Down
4 changes: 2 additions & 2 deletions vendor/wgpu/sdl2glue/glue_windows.odin
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ GetSurface :: proc(instance: wgpu.Instance, window: ^sdl2.Window) -> wgpu.Surfac
return wgpu.InstanceCreateSurface(
instance,
&wgpu.SurfaceDescriptor{
nextInChain = &wgpu.SurfaceDescriptorFromWindowsHWND{
nextInChain = &wgpu.SurfaceSourceWindowsHWND{
chain = wgpu.ChainedStruct{
sType = .SurfaceDescriptorFromWindowsHWND,
sType = .SurfaceSourceWindowsHWND,
},
hinstance = rawptr(hinstance),
hwnd = rawptr(hwnd),
Expand Down
12 changes: 6 additions & 6 deletions vendor/wgpu/sdl3glue/glue.odin
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#+build !linux
#+build !windows
#+build !darwin
package wgpu_sdl3_glue

#panic("package wgpu/sdl3glue is not supported on the current target")
#+build !linux
#+build !windows
#+build !darwin
package wgpu_sdl3_glue

#panic("package wgpu/sdl3glue is not supported on the current target")
39 changes: 21 additions & 18 deletions vendor/wgpu/sdl3glue/glue_darwin.odin
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
package wgpu_sdl3_glue

import "vendor:sdl3"
import "vendor:wgpu"

GetSurface :: proc(instance: wgpu.Instance, window: ^sdl3.Window) -> wgpu.Surface {
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 = metal_layer,
},
},
)
}
package wgpu_sdl3_glue

import "vendor:sdl3"
import "vendor:wgpu"

GetSurface :: proc(instance: wgpu.Instance, window: ^sdl3.Window) -> wgpu.Surface {
view := sdl3.Metal_CreateView(window)
layer := sdl3.Metal_GetLayer(view)

return wgpu.InstanceCreateSurface(
instance,
&wgpu.SurfaceDescriptor{
nextInChain = &wgpu.SurfaceSourceMetalLayer{
chain = wgpu.ChainedStruct{
sType = .SurfaceSourceMetalLayer,
},
layer = layer,
},
},
)
}
91 changes: 37 additions & 54 deletions vendor/wgpu/sdl3glue/glue_linux.odin
Original file line number Diff line number Diff line change
@@ -1,54 +1,37 @@
package wgpu_sdl3_glue

import "vendor:sdl3"
import "vendor:wgpu"


GetSurface :: proc(instance: wgpu.Instance, window: ^sdl3.Window) -> wgpu.Surface {
switch sdl3.GetCurrentVideoDriver() {
case "x11":
display := sdl3.GetPointerProperty(
sdl3.GetWindowProperties(window),
sdl3.PROP_WINDOW_X11_DISPLAY_POINTER,
nil,
)
x_window := sdl3.GetNumberProperty(
sdl3.GetWindowProperties(window),
sdl3.PROP_WINDOW_X11_WINDOW_NUMBER,
0,
)
return wgpu.InstanceCreateSurface(
instance,
&wgpu.SurfaceDescriptor {
nextInChain = &wgpu.SurfaceDescriptorFromXlibWindow {
chain = {sType = .SurfaceDescriptorFromXlibWindow},
display = display,
window = u64(x_window),
},
},
)
case "wayland":
display := sdl3.GetPointerProperty(
sdl3.GetWindowProperties(window),
sdl3.PROP_WINDOW_WAYLAND_DISPLAY_POINTER,
nil,
)
w_surface := sdl3.GetPointerProperty(
sdl3.GetWindowProperties(window),
sdl3.PROP_WINDOW_WAYLAND_SURFACE_POINTER,
nil,
)
return wgpu.InstanceCreateSurface(
instance,
&wgpu.SurfaceDescriptor {
nextInChain = &wgpu.SurfaceDescriptorFromWaylandSurface {
chain = {sType = .SurfaceDescriptorFromWaylandSurface},
display = display,
surface = w_surface,
},
},
)
case:
panic("wgpu sdl3 glue: unsupported platform, expected Wayland or X11")
}
}
package wgpu_sdl3_glue

import "vendor:sdl3"
import "vendor:wgpu"

GetSurface :: proc(instance: wgpu.Instance, window: ^sdl3.Window) -> wgpu.Surface {
switch sdl3.GetCurrentVideoDriver() {
case "wayland":
return wgpu.InstanceCreateSurface(
instance,
&wgpu.SurfaceDescriptor{
nextInChain = &wgpu.SurfaceSourceWaylandSurface{
chain = {
sType = .SurfaceSourceWaylandSurface,
},
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, nil),
},
},
)
case "x11":
return wgpu.InstanceCreateSurface(
instance,
&wgpu.SurfaceDescriptor{
nextInChain = &wgpu.SurfaceSourceXlibWindow{
chain = {
sType = .SurfaceSourceXlibWindow,
},
display = sdl3.GetPointerProperty(sdl3.GetWindowProperties(window), sdl3.PROP_WINDOW_X11_DISPLAY_POINTER, nil),
window = cast(u64)sdl3.GetNumberProperty(sdl3.GetWindowProperties(window), sdl3.PROP_WINDOW_X11_WINDOW_NUMBER, 0),
},
},
)
case:
panic("wgpu sdl3 glue: unsupported video driver, expected Wayland or X11")
}
}
Loading

0 comments on commit ae9388c

Please sign in to comment.