
Enables seamless integration of WebGPU by providing bindings to the wgpu library using a Rust-based backend, supporting desktop and mobile platforms, with detailed API references.
This project is a WebGPU binding compatible with Desktop and Mobile.
If you are looking for an experience that also covers the web, you can use the wgpu4k project.
This library uses the Firefox backend written in Rust, available here.
./gradlew demo:desktop-and-ios:runJvm
./gradlew demo:desktop-and-ios:runDebugExecutable
android with android studio or IntelliJ IDEA!./gradlew build, then run the subproject android-native with android studio or IntelliJ IDEA!./gradlew demo:desktop-and-ios:assembleWgpuAppXCFramework to build the XC Framework, then you can run the subproject iosApp (on demo/desktop-and-ios folder) with XCode on a iOS simulator or real device.The desktop demo also has headless render paths that do not create a GLFW window or a WebGPU surface. They render the triangle into an offscreen texture, copy it back to CPU memory, and write an image file.
On JVM:
./gradlew :demo:desktop-and-ios:runJvmHeadlessThis writes:
demo/desktop-and-ios/build/headless/triangle.png
On Kotlin/Native desktop, first link the executable for the host target, then run it with --headless. For example, on macOS arm64:
./gradlew :demo:desktop-and-ios:linkDebugExecutableMacosArm64
cd demo/desktop-and-ios
./build/bin/macosArm64/debugExecutable/desktop-and-ios.kexe --headlessThis writes:
demo/desktop-and-ios/build/headless/triangle.ppm
From a basic multiplatform project, create a common native source set and add the library:
private val hierarchyTemplate = KotlinHierarchyTemplate {
/* natural hierarchy is only applied to default 'main'/'test' compilations (by default) */
withSourceSetTree(KotlinSourceSetTree.main, KotlinSourceSetTree.test)
common {
/* All compilations shall be added to the common group by default */
withCompilations { true }
group("commonNative") {
group("native") {
withNative()
group("apple") {
withApple()
group("ios") {
withIos()
}
group("tvos") {
withTvos()
}
group("watchos") {
withWatchos()
}
group("macos") {
withMacos()
}
}
group("linux") {
withLinux()
}
group("mingw") {
withMingw()
}
}
withJvm()
withAndroidTarget()
}
}
}
kotlin {
...
jvm {
compilerOptions {
jvmTarget = JvmTarget.JVM_24
}
}
iosX64()
iosArm64()
iosSimulatorArm64()
macosArm64()
macosX64()
linuxArm64()
linuxX64()
mingwX64()
androidTarget {
compilerOptions {
jvmTarget = JvmTarget.JVM_24
}
publishLibraryVariants("release", "debug")
}
applyHierarchyTemplate(hierarchyTemplate)
sourceSets {
...
val commonNativeMain by getting {
dependencies { api("io.ygdrasil:wgpu4k-native:<library version>) }
}
...
}
...
}This project is a WebGPU binding compatible with Desktop and Mobile.
If you are looking for an experience that also covers the web, you can use the wgpu4k project.
This library uses the Firefox backend written in Rust, available here.
./gradlew demo:desktop-and-ios:runJvm
./gradlew demo:desktop-and-ios:runDebugExecutable
android with android studio or IntelliJ IDEA!./gradlew build, then run the subproject android-native with android studio or IntelliJ IDEA!./gradlew demo:desktop-and-ios:assembleWgpuAppXCFramework to build the XC Framework, then you can run the subproject iosApp (on demo/desktop-and-ios folder) with XCode on a iOS simulator or real device.The desktop demo also has headless render paths that do not create a GLFW window or a WebGPU surface. They render the triangle into an offscreen texture, copy it back to CPU memory, and write an image file.
On JVM:
./gradlew :demo:desktop-and-ios:runJvmHeadlessThis writes:
demo/desktop-and-ios/build/headless/triangle.png
On Kotlin/Native desktop, first link the executable for the host target, then run it with --headless. For example, on macOS arm64:
./gradlew :demo:desktop-and-ios:linkDebugExecutableMacosArm64
cd demo/desktop-and-ios
./build/bin/macosArm64/debugExecutable/desktop-and-ios.kexe --headlessThis writes:
demo/desktop-and-ios/build/headless/triangle.ppm
From a basic multiplatform project, create a common native source set and add the library:
private val hierarchyTemplate = KotlinHierarchyTemplate {
/* natural hierarchy is only applied to default 'main'/'test' compilations (by default) */
withSourceSetTree(KotlinSourceSetTree.main, KotlinSourceSetTree.test)
common {
/* All compilations shall be added to the common group by default */
withCompilations { true }
group("commonNative") {
group("native") {
withNative()
group("apple") {
withApple()
group("ios") {
withIos()
}
group("tvos") {
withTvos()
}
group("watchos") {
withWatchos()
}
group("macos") {
withMacos()
}
}
group("linux") {
withLinux()
}
group("mingw") {
withMingw()
}
}
withJvm()
withAndroidTarget()
}
}
}
kotlin {
...
jvm {
compilerOptions {
jvmTarget = JvmTarget.JVM_24
}
}
iosX64()
iosArm64()
iosSimulatorArm64()
macosArm64()
macosX64()
linuxArm64()
linuxX64()
mingwX64()
androidTarget {
compilerOptions {
jvmTarget = JvmTarget.JVM_24
}
publishLibraryVariants("release", "debug")
}
applyHierarchyTemplate(hierarchyTemplate)
sourceSets {
...
val commonNativeMain by getting {
dependencies { api("io.ygdrasil:wgpu4k-native:<library version>) }
}
...
}
...
}