Unverified Commit 0048f343 authored by Pavel's avatar Pavel Committed by GitHub

Adapter exclusion (#617)

* allow to specify platform for adapter exclusion

* allow patterns in `not-supported-adapters.list`

* FL-16182 disable opengl on virgl

* encode list of excluded videocards in kotlin instead of resource file

by some reason loading resource file took about ~30-40ms
parent b4f0c9da
...@@ -97,7 +97,7 @@ internal class Direct3DRedrawer( ...@@ -97,7 +97,7 @@ internal class Direct3DRedrawer(
fun initFence() = initFence(device) fun initFence() = initFence(device)
// Called from native code // Called from native code
private fun isAdapterSupported(name: String) = isVideoCardSupported(GraphicsApi.DIRECT3D, name) private fun isAdapterSupported(name: String) = isVideoCardSupported(GraphicsApi.DIRECT3D, hostOs, name)
private external fun chooseAdapter(adapterPriority: Int): Long private external fun chooseAdapter(adapterPriority: Int): Long
private external fun createDirectXDevice(adapter: Long, contentHandle: Long, transparency: Boolean): Long private external fun createDirectXDevice(adapter: Long, contentHandle: Long, transparency: Boolean): Long
......
...@@ -22,9 +22,11 @@ internal class LinuxOpenGLRedrawer( ...@@ -22,9 +22,11 @@ internal class LinuxOpenGLRedrawer(
throw RenderException("Cannot create Linux GL context") throw RenderException("Cannot create Linux GL context")
} }
it.makeCurrent(context) it.makeCurrent(context)
if (!isVideoCardSupported(GraphicsApi.OPENGL, adapterName)) { adapterName.also { adapterName ->
if (adapterName != null && !isVideoCardSupported(GraphicsApi.OPENGL, hostOs, adapterName)) {
throw RenderException("Cannot create Linux GL context") throw RenderException("Cannot create Linux GL context")
} }
}
onDeviceChosen(adapterName) onDeviceChosen(adapterName)
it.setSwapInterval(swapInterval) it.setSwapInterval(swapInterval)
} }
......
...@@ -20,9 +20,11 @@ internal class WindowsOpenGLRedrawer( ...@@ -20,9 +20,11 @@ internal class WindowsOpenGLRedrawer(
throw RenderException("Cannot create Windows GL context") throw RenderException("Cannot create Windows GL context")
} }
makeCurrent(device, it) makeCurrent(device, it)
if (!isVideoCardSupported(GraphicsApi.OPENGL, adapterName)) { adapterName.also { adapterName ->
if (adapterName != null && !isVideoCardSupported(GraphicsApi.OPENGL, hostOs, adapterName)) {
throw RenderException("Cannot create Windows GL context") throw RenderException("Cannot create Windows GL context")
} }
}
onDeviceChosen(adapterName) onDeviceChosen(adapterName)
} }
......
package org.jetbrains.skiko package org.jetbrains.skiko
private val notSupportedAdapters: Set<NotSupportedAdapter> by lazy { import kotlin.system.measureNanoTime
val resource = SkiaLayer::class.java.getResource("/not-supported-adapter.list")?.readText().orEmpty() import kotlin.time.Duration
resource.splitToSequence(";").map { it.trim() }.mapNotNullTo(mutableSetOf()) { import kotlin.time.Duration.Companion.nanoseconds
val splits = it.split(":")
val api = when (splits.getOrNull(0)) {
"directx" -> GraphicsApi.DIRECT3D
"opengl" -> GraphicsApi.OPENGL
else -> return@mapNotNullTo null
}
val name = splits.getOrNull(1) ?: return@mapNotNullTo null
NotSupportedAdapter(api, name)
}
}
internal fun isVideoCardSupported(
api: GraphicsApi,
name: String?
): Boolean = name == null || !notSupportedAdapters.contains(NotSupportedAdapter(api, name))
private data class NotSupportedAdapter( internal data class NotSupportedAdapter(
val os: OS,
val api: GraphicsApi, val api: GraphicsApi,
val name: String val pattern: Regex
) )
private val notSupportedAdapters: List<NotSupportedAdapter> by lazy {
listOf(
NotSupportedAdapter(os = OS.Windows, api = GraphicsApi.DIRECT3D, pattern = Regex("Intel(R) HD Graphics 520")),
NotSupportedAdapter(os = OS.Windows, api = GraphicsApi.DIRECT3D, pattern = Regex("Intel(R) HD Graphics 530")),
NotSupportedAdapter(os = OS.Windows, api = GraphicsApi.DIRECT3D, pattern = Regex("Intel(R) HD Graphics 4400")),
NotSupportedAdapter(os = OS.Windows, api = GraphicsApi.DIRECT3D, pattern = Regex("NVIDIA GeForce GTX 750 Ti")),
NotSupportedAdapter(os = OS.Windows, api = GraphicsApi.DIRECT3D, pattern = Regex("NVIDIA GeForce GTX 960M")),
NotSupportedAdapter(os = OS.Windows, api = GraphicsApi.DIRECT3D, pattern = Regex("NVIDIA Quadro M2000M")),
NotSupportedAdapter(os = OS.Windows, api = GraphicsApi.OPENGL, pattern = Regex("Intel(R) HD Graphics 2000")),
NotSupportedAdapter(os = OS.Windows, api = GraphicsApi.OPENGL, pattern = Regex("Intel(R) HD Graphics 3000")),
NotSupportedAdapter(os = OS.Linux, api = GraphicsApi.OPENGL, pattern = Regex("llvmpipe.*")),
NotSupportedAdapter(os = OS.Linux, api = GraphicsApi.OPENGL, pattern = Regex("virgl.*"))
)
}
internal fun isVideoCardSupported(api: GraphicsApi, hostOs: OS, name: String): Boolean {
return notSupportedAdapters.any { entry ->
entry.os == hostOs && entry.api == api && entry.pattern.matches(name)
}.not()
}
\ No newline at end of file
directx:Intel(R) HD Graphics 520;
directx:Intel(R) HD Graphics 530;
directx:Intel(R) HD Graphics 4400;
directx:NVIDIA GeForce GTX 750 Ti;
directx:NVIDIA GeForce GTX 960M;
directx:NVIDIA Quadro M2000M;
opengl:Intel(R) HD Graphics 2000;
opengl:Intel(R) HD Graphics 3000;
opengl:llvmpipe;
\ No newline at end of file
package org.jetbrains.skiko
import kotlin.test.*
class GraphicsApiTest {
@Test
fun `device is supported test`() {
assertTrue { isVideoCardSupported(GraphicsApi.METAL, OS.MacOS, "AMD Radeon Pro 5500M") }
}
@Test
fun `device is not supported test`() {
assertFalse { isVideoCardSupported(GraphicsApi.DIRECT3D, OS.Windows, "NVIDIA Quadro M2000M") }
}
@Test
fun `device is not supported by pattern`() {
assertFalse { isVideoCardSupported(GraphicsApi.OPENGL, OS.Linux, "llvmpipe") }
assertFalse { isVideoCardSupported(GraphicsApi.OPENGL, OS.Linux, "llvmpipe (LLVM 5.0 256 bits)") }
assertFalse { isVideoCardSupported(GraphicsApi.OPENGL, OS.Linux, "virgl (Apple M1 Max (Compat))") }
assertTrue { isVideoCardSupported(GraphicsApi.OPENGL, OS.Linux, "Intel llvmpipe") }
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment