LLGL icon indicating copy to clipboard operation
LLGL copied to clipboard

Multithreading example crash using DX12 renderer

Open duckdoom4 opened this issue 4 years ago • 3 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)

duckdoom4 avatar Oct 23 '20 08:10 duckdoom4

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.

LukasBanana avatar Oct 24 '20 16:10 LukasBanana

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 avatar Oct 02 '21 16:10 dmiller423

@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.

LukasBanana avatar Oct 05 '21 01:10 LukasBanana

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.

LukasBanana avatar Oct 08 '23 19:10 LukasBanana