Skip to content

Capati/wgpu-odin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WGPU Odin Bindings

Bindings to wgpu-native 0.19.4.1 in the Odin programming language.

See examples here.

Status

Note

The wgpu-API still in the "Working Draft" phase. Until the specification is stabilized, break changes can happen without notice.

Bindings only

You can use the bindings only where the procedures are called directly from the foreign block.

Wrapper

The wrapper version exposes an API similar to the WebGPU spec. Most of the inner procedures are boilerplate code that create an convenient way to work with idiomatic Odin and wgpu data.

Linking

To make this repository easy to maintain and light to download, I decided to not include all binaries files (that can exceed 130MB). You can build the library yourself, but all those files are autogenerated and you can download on wgpu-native releases page:

https://github.com/gfx-rs/wgpu-native/releases/tag/v0.19.4.1

Make sure to match the version tag is the same from upstream, just place the corresponding files according to the bindings tree in bindings/lib/:

📦lib
 ┣ 📂linux
 ┃ ┣ 📂arch64
 ┃ ┃ ┗ 📜libwgpu_native.a
 ┃ ┗ 📂x86_64
 ┃ ┃ ┗ 📜libwgpu_native.a
 ┣ 📂mac_os
 ┃ ┣ 📂arch64
 ┃ ┃ ┗ 📜libwgpu_native.a
 ┃ ┗ 📂x86_64
 ┃ ┃ ┗ 📜libwgpu_native.a
 ┣ 📂windows
 ┃ ┣ 📂i686
 ┃ ┃ ┗ 📜wgpu_native.dll.lib
 ┃ ┗ 📂x86_64
 ┃ ┃ ┗ 📜wgpu_native.dll.lib

Check the foreign import in the file bindings.odin for more details. For example, download wgpu-windows-x86_64-release.zip and copy wgpu_native.dll.lib to the folder bindings/lib/windows/x86_64/.

On Windows the linking is dynamic, you need wgpu_native.dll along side your executable. Both Linux and Mac are statically linked for ease of use.

Link against system

On Linux or Mac, you can tell the library to link against system libwgpu_native instead of one provided in the directory by defining the Odin config value WGPU_USE_SYSTEM_LIBRARIES as true.

Quick Start Guide

  1. Clone this repository.
  2. Make sure you follow the Linking steps above to include the binaries for your target.
  3. Create a folder libs/wgpu in the root of your project (from where you run odin build).
  4. If you want the wrapper version, copy the folders bindings, wrapper and utils from this repository to the directory created in the previous step.
  5. To easily import the package to your project, you can set a collection:
odin build ./src -collection:libs=./libs
  1. Import the package:
import wgpu "libs:wgpu/wrapper"

Or

import wgpu "libs:wgpu/bindings"

Naming Conventions

Types and values follow the Odin Naming Convention. In general, Ada_Case for types and snake_case for values

Case
Import Name snake_case (but prefer single word)
Types Ada_Case
Enum Values Ada_Case
Procedures snake_case
Local Variables snake_case
Constant Variables SCREAMING_SNAKE_CASE

License

MIT license.