diff --git a/Core/Graphics/Source/DeviceImpl.cpp b/Core/Graphics/Source/DeviceImpl.cpp index 3b449cd9d5..4ebfec0bc5 100644 --- a/Core/Graphics/Source/DeviceImpl.cpp +++ b/Core/Graphics/Source/DeviceImpl.cpp @@ -40,6 +40,20 @@ namespace Babylon::Graphics auto& init = m_state.Bgfx.InitState; init.callback = &m_bgfxCallback; + // bgfx reserves limits.numDrawCalls render-item slots (sort keys, RenderItem, + // RenderBind) up front for every Frame, and defaults to + // BGFX_CONFIG_MAX_DRAW_CALLS (65535) -- tens of megabytes. + // + // 0 asks for a single BGFX_CONFIG_DRAW_CALL_BLOCK instead (4096, set in + // Dependencies/CMakeLists.txt), and bgfx resizes in block steps up to that same + // ceiling. Growth is reactive -- the frame that overflows drops the draws past + // capacity -- so the block should sit above the expected peak. + // + // numDrawCallPeakFrames is the shrink delay in frames, ~1s at 60fps. Resizing + // is disabled entirely at 0. + init.limits.numDrawCalls = 0; + init.limits.numDrawCallPeakFrames = 60; + // Use the noop renderer if the configuration has no window and no size. if (config.Window == WindowT{} && config.Width == 0 && config.Height == 0) { diff --git a/Dependencies/CMakeLists.txt b/Dependencies/CMakeLists.txt index 9f7a5a6f4c..c6b2b599e5 100644 --- a/Dependencies/CMakeLists.txt +++ b/Dependencies/CMakeLists.txt @@ -46,6 +46,7 @@ FetchContent_MakeAvailable_With_Message(bgfx.cmake) target_compile_definitions(bgfx PRIVATE BGFX_CONFIG_DEBUG_ANNOTATION=0) target_compile_definitions(bgfx PRIVATE BGFX_CONFIG_DEFAULT_MAX_ENCODERS=2) +target_compile_definitions(bgfx PRIVATE BGFX_CONFIG_DRAW_CALL_BLOCK=4096) target_compile_definitions(bgfx PRIVATE BGFX_CONFIG_MAX_VERTEX_STREAMS=18) target_compile_definitions(bgfx PRIVATE BGFX_CONFIG_MIN_RESOURCE_COMMAND_BUFFER_SIZE=16) target_compile_definitions(bgfx PRIVATE BGFX_CONFIG_MIN_UNIFORM_BUFFER_SIZE=4096)