linebender / piet

An abstraction for 2D graphics.
Apache License 2.0
1.24k stars 93 forks source link

Is it possible to fallback to a software/CPU based renderer when GPU is not available? #469

Closed ngugcx closed 2 years ago

ngugcx commented 2 years ago

I noticed that the druid apps just not start without any errors when testing with my Window 7 virtual machines (run by virtualbox). When GPU is not available for renderering, like in some kinds of remote desktop sessions, or virtual machines, is it possible to fallback to a software/CPU based renderer?

raphlinus commented 2 years ago

It should be falling back to CPU rendering (using the warp renderer). There are probably still warning messages just from not finding the Windows 10 calls, and we should clean those up.

Could you post the error log?

ngugcx commented 2 years ago
PS C:\test> .\hello.exe
PS C:\test> Nov 01 07:31:11.963  INFO druid_shell::backend::windows::util: No shcore.dll
Nov 01 07:31:11.963  INFO druid_shell::backend::windows::util: Could not load `GetDpiForSystem`. Window
s 10 or later is needed
Nov 01 07:31:11.963  INFO druid_shell::backend::windows::util: Could not load `GetDpiForWindow`. Window
s 10 or later is needed
Nov 01 07:31:11.979  INFO druid_shell::backend::windows::util: Could not load `SetProcessDpiAwarenessCo
ntext`. Windows 10 or later is needed
Nov 01 07:31:11.979  INFO druid_shell::backend::windows::util: Could not load `GetSystemMetricsForDpi`.
 Windows 10 or later is needed
Nov 01 07:31:11.979  INFO druid_shell::backend::windows::util: No dcomp.dll
Nov 01 07:31:11.979 DEBUG druid::localization: available locales [], current zh-CN
Nov 01 07:31:11.979 DEBUG druid::localization: resolved: [en-US]
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: hresult 80004002', druid-shell\src\backend\windo
ws\window.rs:1350:48
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Looks like a limitation of druid_shell. By the way, why it's not working "set RUST_BACKTRACE=1" in Dos?

druid-shell\src\backend\windows\window.rs image

raphlinus commented 2 years ago

Interesting. This shouldn't be happening. Here's a related StackOverflow question. Can you try changing D2D1_FACTORY_TYPE_MULTI_THREADED to D2D1_FACTORY_TYPE_SINGLE_THREADED in piet-direct2d/src/d2d.rs , and maybe also turning off the warnings?

ngugcx commented 2 years ago

Sure. Is there an easy way to use my local piet repo with druid?

raphlinus commented 2 years ago

You'll probably find success using the [patch] mechanism of Cargo.

ngugcx commented 2 years ago

Tried, the same error and logs. By the way, I built on my Windows 10 desktop.

raphlinus commented 2 years ago

This sounds like a dup of #443. Do you have Windows 7 platform update installed? We're absolutely not targeting anything earlier than that, and are considering raising our minimum version requirements anyway.

ngugcx commented 2 years ago

Ooops! I must have amnesia!!!

ngugcx commented 2 years ago

One more question. Can I force it to fall back to CPU rendering from my druid app?

raphlinus commented 2 years ago

I don't think it's a question of CPU rendering, it's because we're using the D2D1 interface which is not supported on pre-platform update Windows 7. And no, we're not going to make that change, as it comes with some really painful limitations, for example the fact that you have to discard and rebuild resources on certain events; note that the rebuild_resources method was originally for this, but should probably be removed now.

It's fine to ask, and I'd be happy to make it work if it didn't come with serious drawbacks, but the official answer is that Windows 7 with platform update is the earliest version we support.

ngugcx commented 2 years ago

I was not asking to support pre-platform update Windows 7. I just want to know if there is a way to force to CPU rendering for debug purpose.

raphlinus commented 2 years ago

Ah, I misunderstood. Here's the place to patch druid: https://github.com/linebender/druid/blob/master/druid-shell/src/backend/windows/dcomp.rs#L54. Remove D3D_DRIVER_TYPE_HARDWARE or put WARP first, depending on how you want fallback to behave.

Arquios commented 1 year ago

Hi, i found the solution!!!, Windows 7 SP1 32-bit needs the "Platform Update for Windows 7" patch (Windows6.1-KB2670838-x86.msu), the patch activates and improves the Direct2D library (the d2d1.dll file among other things) with version 1.1, since the one installed in Windows 7 SP1 is present but disabled by default in addition to an outdated version of d2d1.dll, it is worth mentioning that this does not happen in 64-bit versions of windows because it is already activated.

I had been fighting with this for 3 days, I have successfully tested it on 8 computers that had the same problem and in various forums like this one or this one they mention the advantages of using it.

Note: If once the patch is installed it doesn't work, try the command to force the registry with "regsrv32 C:\Windows\System32\d2d1.dll" to unlock it and even if it gives an error it will work when you try again, it happened to me on 1 of the 8 computers.

Note 2: Don't forget to compile using the --target i686-pc-windows-msvc in your cargo command.