keijiro / KlakSpout

Spout plugin for Unity
The Unlicense
673 stars 101 forks source link

Crash when instantiating SpoutReceiver on standalone DX12 build, Unity 2021.2.0.13b, GTX1660 SUPER #80

Closed WoutStandaert closed 2 years ago

WoutStandaert commented 2 years ago

I have a standalone Unity build running on a GTX1660 SUPER.

At a certain moment I try to instantiate a prefab with a SpoutReceiver on it.

The SpoutReceiver renders to a render texture, the "renderer" field is not set.

The render texture is displayed via a RawImage on a UI canvas.

During development, it works in the editor on my laptop with a RTX 2060.

In the build on a GTX1660 SUPER, it crashes with the following error:

d3d12 : CreateCommittedResource 'TexturesD3D12::CreateTextureInternal() Texture' (1920 x 1080) format 72 failed (887a0005).
    Device Remove Reason (HRESULT): 0x887a002b
    Device Memory Stats:
        Local AvailableForReservation: 2739 MB, Budget: 5223 MB, CurrentUsage: 1983 MB, CurrentReservation: 64 MB
        Non-local AvailableForReservation: 1867 MB, Budget: 3539 MB, CurrentUsage: 393 MB, CurrentReservation: 0 MB
d3d12: failed to create 2D texture id=457 w=1920 h=1080 mips=1 d3dfmt=72
d3d12 : CreateCommittedResource 'GfxDeviceD3D12::ReserveScratchMemorySlow() Scratch' (1228800 x 1) format 0 failed (887a0005).
    Device Remove Reason (HRESULT): 0x887a002b
    Device Memory Stats:
        Local AvailableForReservation: 2739 MB, Budget: 5223 MB, CurrentUsage: 1983 MB, CurrentReservation: 64 MB
        Non-local AvailableForReservation: 1867 MB, Budget: 3539 MB, CurrentUsage: 393 MB, CurrentReservation: 0 MB
Crash!!!
keijiro commented 2 years ago

Does it reproduce with the sample project (the project contained in this repository)?

WoutStandaert commented 2 years ago

The sample project also crashes.

I did the following:

The reason why it crashes is different, but it also seems to be related to DirectX 12 memory management:

Device removed reason (887a0001).
GfxDevice was not out of Local memory
Local memory usage:
 Budget: 5476712448
 CurrentUsage: 458534912
 AvailableForReservation: 67108864
 CurrentReservation: 2872573952
GfxDevice was not out of Non-Local memory
Non-Local memory usage:
 Budget: 3800763188
 CurrentUsage: 163983360
 AvailableForReservation: 0
 CurrentReservation: 2005958349
Set -force-d3d12-debug for more information on device removal
Crash!!!

I'm not bound to DirectX12 for my project. I might go back to DirectX11 for now. I've read that one of the big differences between DX11 and DX12 is memory management, so the source of my problem might very well lie there.

The standalone version of my application also crashes on my RTX2060 powered laptop. In the Unity editor it works.

keijiro commented 2 years ago

Thanks for the clarification.

I only found very few similar cases. Unfortunately, the root cause of the problem is unknown. Sometimes it disappears by upgrading the graphics driver.

I'd recommend switching to DX11 if it reproduces with the latest driver.

WoutStandaert commented 2 years ago

Switching to DX11 fixes the problem. Thanks for looking into it!

keijiro commented 2 years ago

I'm closing this issue. Although the issue still exists, there is nothing to do on my side at the moment. I'll reopen it when I get more information about it.