Skip to content

Benchmarks. Support GPU on Windows #5216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import org.jetbrains.skia.ColorSpace
import org.jetbrains.skia.PixelGeometry
import org.jetbrains.skia.Surface
import org.jetbrains.skia.SurfaceColorFormat
import org.jetbrains.skia.SurfaceOrigin
import org.jetbrains.skia.SurfaceProps
import org.jetbrains.skiko.ExperimentalSkikoApi
import org.jetbrains.skiko.graphicapi.DirectXOffscreenContext
import org.jetbrains.skiko.hostOs

@OptIn(ExperimentalSkikoApi::class)
fun graphicsContext(): GraphicsContext? = when {
hostOs.isWindows -> DirectXGraphicsContext()
else -> {
println("Unsupported desktop host OS: $hostOs. Using non-GPU graphic context")
null
}
}

@OptIn(ExperimentalSkikoApi::class)
class DirectXGraphicsContext() : GraphicsContext {
// Note: we don't close `context` and `texture` after using,
// because it is created once in the main function
private val context = DirectXOffscreenContext()
private var texture: DirectXOffscreenContext.Texture? = null

override fun surface(width: Int, height: Int): Surface {
texture?.close()
texture = context.Texture(width, height)
return Surface.makeFromBackendRenderTarget(
context.directContext,
texture!!.backendRenderTarget,
SurfaceOrigin.TOP_LEFT,
SurfaceColorFormat.BGRA_8888,
ColorSpace.sRGB,
SurfaceProps(pixelGeometry = PixelGeometry.UNKNOWN)
) ?: throw IllegalStateException("Can't create Surface")
}

override suspend fun awaitGPUCompletion() {
texture?.waitForCompletion()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ import kotlinx.coroutines.runBlocking

fun main(args: Array<String>) {
Config.setGlobalFromArgs(args)
runBlocking(Dispatchers.Main) { runBenchmarks() }
runBlocking(Dispatchers.Main) { runBenchmarks(graphicsContext = graphicsContext()) }
}