LukasBanana/LLGL

Multithreading example crash using DX12 renderer

duckdoom4 opened this issue ยท 4 comments

When running the Multi-Threading example (in debug mode) using the DirectX12 renderer I got the following error:

D3D12 ERROR: ID3D12CommandQueue::ExecuteCommandLists: A command list, which writes to a swapchain back buffer, may only be executed when that back buffer is the back buffer that will be presented during the next call to Present*. Such a back buffer is also referred to as the "current back buffer". Swap Chain: 0x0000022962A35080:'Unnamed Object' - Current Back Buffer Buffer: 0x0000022961DA41B0:'Unnamed ID3D12Resource Object' - Attempted Write Buffer: 0x0000022961DA6880:'Unnamed ID3D12Resource Object' [ STATE_SETTING ERROR #907: EXECUTECOMMANDLISTS_WRONGSWAPCHAINBUFFERREFERENCE]
D3D12: Removing Device.
D3D12 ERROR: ID3D12Device::RemoveDevice: Device removal has been triggered for the following reason (DXGI_ERROR_ACCESS_DENIED: The application attempted to use a resource it does not access to.  This  could be, for example, rendering to a texture while only having read access.). [ EXECUTION ERROR #232: DEVICE_REMOVAL_PROCESS_AT_FAULT]

Console output:

selected renderer: Direct3D12
render system:
  renderer:           Direct3D 11.1
  device:             NVIDIA GeForce RTX 2060 SUPER
  vendor:             NVIDIA Corporation
  shading language:   HLSL 6.0

render context:
  resolution:         800 x 600
  samples:            8
  colorFormat:        RGBA8UNorm
  depthStencilFormat: D24UNormS8UInt

Enter thread: mainThread
Leave thread: mainThread
failed to present DXGI swap chain (error code = DXGI_ERROR_DEVICE_REMOVED)

Multi-threading is in an experimental and unstable state. Ironically, the only backend that supports multi-threading in LLGL right now is OpenGL with the deferred command buffer. That being said, I just found out that the JIT compiler is broken, too (also more an experimental sub project). So make sure LLGL_ENABLE_JIT_COMPILER is disabled in CMake. It's not really essential anyway.

About the output renderer: Direct3D 11.1: that's another bug with the static lib build configuration. I tested the engine with dynamic libs most of the time, so some of those things slipped through. The macro LLGL_DX_ENABLE_D3D12 is defined for D3D12, but with the static lib configuration those definitions overlap with the different backends.

EDIT:
I updated the TODO list accordingly.

How about some warning the entire library is not multithread friendly?
You list features but that immediately burns 90% of usage for most people, and there is no mention of it on the page.

@dmiller423 there are some multi-threading capabilities but not all renderers implement that. In what renderer did you run into MT problems? And please let me know where you found misleading information in the description.

Several improvements have been implemented in recent commits to better support multi-threaded command recording in all backends. Please feel free to open a new ticket if any previously mentioned issues persist.