diff --git a/.github/workflows/build-win32-shader.yml b/.github/workflows/build-win32-shader.yml index 3a0ac37a2..7a6d7b5a0 100644 --- a/.github/workflows/build-win32-shader.yml +++ b/.github/workflows/build-win32-shader.yml @@ -29,7 +29,6 @@ jobs: -A ${{ inputs.platform }} ^ -D BX_CONFIG_DEBUG=ON ^ -D GRAPHICS_API=D3D11 ^ - -D BGFX_CONFIG_MAX_FRAME_BUFFERS=256 ^ -D BABYLON_DEBUG_TRACE=ON ^ -D BABYLON_NATIVE_PLUGIN_NATIVEENGINE_COMPILESHADERS=OFF diff --git a/.github/workflows/build-win32.yml b/.github/workflows/build-win32.yml index 64198185b..d260818ae 100644 --- a/.github/workflows/build-win32.yml +++ b/.github/workflows/build-win32.yml @@ -65,7 +65,6 @@ jobs: ${{ steps.vars.outputs.js_define }} ^ -D BX_CONFIG_DEBUG=ON ^ -D GRAPHICS_API=${{ inputs.graphics-api }} ^ - -D BGFX_CONFIG_MAX_FRAME_BUFFERS=256 ^ -D BABYLON_DEBUG_TRACE=ON ^ -D BABYLON_NATIVE_PLUGIN_NATIVEDRACO=ON ^ -D BABYLON_NATIVE_PLUGIN_NATIVEMESHOPT=ON ^ diff --git a/CMakeLists.txt b/CMakeLists.txt index b9e529d43..35175d04b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,7 +35,7 @@ FetchContent_Declare(base-n EXCLUDE_FROM_ALL) FetchContent_Declare(bgfx.cmake GIT_REPOSITORY https://github.com/BabylonJS/bgfx.cmake.git - GIT_TAG 5c98749de48e8609a62e5c1fd2cfffbbd970588e + GIT_TAG f7333d92a0ca19ad9a6bd2efb34548e8a8d8a792 EXCLUDE_FROM_ALL) FetchContent_Declare(CMakeExtensions GIT_REPOSITORY https://github.com/BabylonJS/CMakeExtensions.git diff --git a/Dependencies/CMakeLists.txt b/Dependencies/CMakeLists.txt index 17989e3ff..df41933c5 100644 --- a/Dependencies/CMakeLists.txt +++ b/Dependencies/CMakeLists.txt @@ -38,6 +38,39 @@ set(BGFX_INSTALL OFF) set(BGFX_OPENGL_USE_EGL ON) set(BGFX_USE_DEBUG_SUFFIX OFF) +# Babylon Native's bgfx settings are defaults. A value already supplied, on the command +# line or by a project embedding Babylon Native, is left alone. bgfx.cmake forwards +# whichever value survives, so each setting reaches the compiler exactly once. +macro(babylon_native_bgfx_config NAME DEFAULT) + if("${BGFX_CONFIG_${NAME}}" STREQUAL "") + set(BGFX_CONFIG_${NAME} "${DEFAULT}") + endif() +endmacro() + +babylon_native_bgfx_config(DEFAULT_MAX_ENCODERS 2) +babylon_native_bgfx_config(MAX_VERTEX_STREAMS 18) +babylon_native_bgfx_config(MIN_RESOURCE_COMMAND_BUFFER_SIZE 16) +babylon_native_bgfx_config(MIN_UNIFORM_BUFFER_SIZE 4096) +babylon_native_bgfx_config(UNIFORM_BUFFER_RESIZE_THRESHOLD_SIZE 256) +babylon_native_bgfx_config(UNIFORM_BUFFER_RESIZE_INCREMENT_SIZE 1024) + +# Temporary disable uniform debug. +babylon_native_bgfx_config(DEBUG_UNIFORM 0) + +# Disable video decoding support (not used by Babylon Native). +babylon_native_bgfx_config(VIDEO 0) + +# Disable the C99 API (Babylon Native uses the C++ API only); saves binary size. +babylon_native_bgfx_config(C99_API 0) + +# The Canvas polyfill allocates one bgfx framebuffer per JS Canvas object and per +# text-rendering operation; combined with V8 GC pacing this can exceed the bgfx default +# of 128 during long playground sweeps. An embedder that disables the polyfill draws +# into a handful of framebuffers and has no reason to pay for the larger pool. +if(BABYLON_NATIVE_POLYFILL_CANVAS) + babylon_native_bgfx_config(MAX_FRAME_BUFFERS 512) +endif() + FetchContent_MakeAvailable_With_Message(bgfx.cmake) # Turn off debug annotations as it causes an access violation in D3D12. @@ -45,12 +78,6 @@ FetchContent_MakeAvailable_With_Message(bgfx.cmake) # See https://github.com/BabylonJS/bgfx.cmake/blob/0af3c9865a66aff1748a51bb466b24f05a123043/cmake/bgfx/bgfx.cmake#L126. 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_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) -target_compile_definitions(bgfx PRIVATE BGFX_CONFIG_UNIFORM_BUFFER_RESIZE_THRESHOLD_SIZE=256) -target_compile_definitions(bgfx PRIVATE BGFX_CONFIG_UNIFORM_BUFFER_RESIZE_INCREMENT_SIZE=1024) target_compile_definitions(bgfx PUBLIC BGFX_PLATFORM_SUPPORTS_WGSL=0) # bgfx bundles the Khronos GLES headers but adds them as a PRIVATE include @@ -58,26 +85,6 @@ target_compile_definitions(bgfx PUBLIC BGFX_PLATFORM_SUPPORTS_WGSL=0) # Expose the path so the OpenGL backends of our own targets can use it. set(BGFX_KHRONOS_INCLUDE_DIR "${bgfx.cmake_SOURCE_DIR}/bgfx/3rdparty/khronos" CACHE INTERNAL "") -# Canvas plugin allocates one bgfx framebuffer per JS Canvas object and per -# text-rendering operation; combined with V8 GC pacing this can exceed the -# default 128 limit during long playground sweeps. We enforce a floor of 512: -# CI workflows pass -DBGFX_CONFIG_MAX_FRAME_BUFFERS, and any value below 512 -# (including a smaller CI override) is clamped up so the pool never regresses -# below the size the Canvas sweeps need. -if(NOT BGFX_CONFIG_MAX_FRAME_BUFFERS OR BGFX_CONFIG_MAX_FRAME_BUFFERS LESS 512) - set(BGFX_CONFIG_MAX_FRAME_BUFFERS 512) -endif() -target_compile_definitions(bgfx PRIVATE BGFX_CONFIG_MAX_FRAME_BUFFERS=${BGFX_CONFIG_MAX_FRAME_BUFFERS}) - -# Temporary disable uniform debug. -target_compile_definitions(bgfx PRIVATE BGFX_CONFIG_DEBUG_UNIFORM=0) - -# Disable video decoding support (not used by Babylon Native). -target_compile_definitions(bgfx PRIVATE BGFX_CONFIG_VIDEO=0) - -# Disable the C99 API (Babylon Native uses the C++ API only); saves binary size. -target_compile_definitions(bgfx PRIVATE BGFX_CONFIG_C99_API=0) - if(GRAPHICS_API STREQUAL "D3D11") target_compile_definitions(bgfx PRIVATE BGFX_CONFIG_RENDERER_DIRECT3D11=1) elseif(GRAPHICS_API STREQUAL "D3D12") diff --git a/nightly.yml b/nightly.yml index b85eba28a..95ba71035 100644 --- a/nightly.yml +++ b/nightly.yml @@ -21,7 +21,7 @@ jobs: - checkout: self - script: | - cmake -G "Visual Studio 17 2022" -B build -A x64 -D BX_CONFIG_DEBUG=ON -D BGFX_CONFIG_MAX_FRAME_BUFFERS=256 -D BABYLON_DEBUG_TRACE=ON + cmake -G "Visual Studio 17 2022" -B build -A x64 -D BX_CONFIG_DEBUG=ON -D BABYLON_DEBUG_TRACE=ON displayName: 'Generate solution' - script: |