Skip to content

Commit f600ab2

Browse files
committed
GPU support on Windows
1 parent b0fbfff commit f600ab2

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import org.jetbrains.skia.ColorSpace
2+
import org.jetbrains.skia.PixelGeometry
3+
import org.jetbrains.skia.Surface
4+
import org.jetbrains.skia.SurfaceColorFormat
5+
import org.jetbrains.skia.SurfaceOrigin
6+
import org.jetbrains.skia.SurfaceProps
7+
import org.jetbrains.skiko.ExperimentalSkikoApi
8+
import org.jetbrains.skiko.graphicapi.DirectXOffscreenContext
9+
import org.jetbrains.skiko.hostOs
10+
11+
@OptIn(ExperimentalSkikoApi::class)
12+
fun graphicsContext(): GraphicsContext? = when {
13+
hostOs.isWindows -> DirectXGraphicsContext()
14+
else -> {
15+
println("Unsupported desktop host OS: $hostOs. Using non-GPU graphic context")
16+
null
17+
}
18+
}
19+
20+
@OptIn(ExperimentalSkikoApi::class)
21+
class DirectXGraphicsContext() : GraphicsContext {
22+
// Note: we don't close `context` and `texture` after using,
23+
// because it is created once in the main function
24+
private val context = DirectXOffscreenContext()
25+
private var texture: DirectXOffscreenContext.Texture? = null
26+
27+
override fun surface(width: Int, height: Int): Surface {
28+
texture?.close()
29+
texture = context.Texture(width, height)
30+
return Surface.makeFromBackendRenderTarget(
31+
context.directContext,
32+
texture!!.backendRenderTarget,
33+
SurfaceOrigin.TOP_LEFT,
34+
SurfaceColorFormat.BGRA_8888,
35+
ColorSpace.sRGB,
36+
SurfaceProps(pixelGeometry = PixelGeometry.UNKNOWN)
37+
) ?: throw IllegalStateException("Can't create Surface")
38+
}
39+
40+
override suspend fun awaitGPUCompletion() {
41+
texture?.waitForCompletion()
42+
}
43+
}

benchmarks/multiplatform/benchmarks/src/desktopMain/kotlin/main.desktop.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ import kotlinx.coroutines.runBlocking
88

99
fun main(args: Array<String>) {
1010
Config.setGlobalFromArgs(args)
11-
runBlocking(Dispatchers.Main) { runBenchmarks() }
11+
runBlocking(Dispatchers.Main) { runBenchmarks(graphicsContext = graphicsContext()) }
1212
}

benchmarks/multiplatform/gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[versions]
2-
compose-multiplatform = "1.8.0-beta01"
2+
compose-multiplatform = "1.8.0-rc01"
33
kotlin = "2.1.20"
44
kotlinx-coroutines = "1.8.0"
55
kotlinx-serialization = "1.8.0"

0 commit comments

Comments
 (0)