Library provides a way to compile Scala 3 DSL to SPIR-V and to run it with Vulkan runtime on GPUs.
It is multiplatform. It works on:
- Linux, Windows, and Mac (for Mac requires installation of moltenvk).
- Any dedicated or integrated GPUs that support Vulkan. In practice, it means almost all moderately modern devices from most manufacturers including Nvidia, AMD, Intel, Apple.
Included Foton library provides a clean and fun way to animate functions and ray traced scenes.
//> using scala "3.6.4"
//> using dep "io.computenode::cyfra-foton:0.1.0-RC1"
import io.computenode.cyfra.dsl.{*, given}
import io.computenode.cyfra.foton.GFunction
import io.computenode.cyfra.runtime.VkCyfraRuntime
@main
def multiplyByTwo(): Unit =
VkCyfraRuntime.using:
val input = (0 until 256).map(_.toFloat).toArray
val doubleIt: GFunction[GStruct.Empty, Float32, Float32] = GFunction: x =>
x * 2.0f
val result: Array[Float] = doubleIt.run(input)
println(s"Output: ${result.take(10).mkString(", ")}...")Run it with:
scala filename.scala
Running on macOS
On macOS, you may need to add extra dependencies://> using dep "org.lwjgl:lwjgl:3.4.0,classifier=natives-macos-arm64"
//> using dep "org.lwjgl:lwjgl-vulkan:3.4.0,classifier=natives-macos-arm64"
//> using dep "org.lwjgl:lwjgl-vma:3.4.0,classifier=natives-macos-arm64"code (this is API usage, to see ray tracing implementation look at RtRenderer)
To enable validation layers for vulkan, you need to install vulkan SDK. After installing, set the following VM option:
-Dio.computenode.cyfra.vulkan.validation=true
If you are on MacOs, then also add:
-Dorg.lwjgl.vulkan.libname=libvulkan.1.dylib
-Djava.library.path=$VULKAN_SDK/lib

