diff --git a/android/filament-android/src/main/cpp/Engine.cpp b/android/filament-android/src/main/cpp/Engine.cpp index 2896dbd030..e1c33f8c93 100644 --- a/android/filament-android/src/main/cpp/Engine.cpp +++ b/android/filament-android/src/main/cpp/Engine.cpp @@ -557,7 +557,8 @@ extern "C" JNIEXPORT void JNICALL Java_com_google_android_filament_Engine_nSetBu jboolean disableHandleUseAfterFreeCheck, jint preferredShaderLanguage, jboolean forceGLES2Context, jboolean assertNativeWindowIsValid, - jint gpuContextPriority) { + jint gpuContextPriority, + jlong sharedUboInitialSizeInBytes) { Engine::Builder* builder = (Engine::Builder*) nativeBuilder; Engine::Config config = { .commandBufferSizeMB = (uint32_t) commandBufferSizeMB, @@ -576,6 +577,7 @@ extern "C" JNIEXPORT void JNICALL Java_com_google_android_filament_Engine_nSetBu .forceGLES2Context = (bool) forceGLES2Context, .assertNativeWindowIsValid = (bool) assertNativeWindowIsValid, .gpuContextPriority = (Engine::GpuContextPriority) gpuContextPriority, + .sharedUboInitialSizeInBytes = (uint32_t) sharedUboInitialSizeInBytes, }; builder->config(&config); } diff --git a/android/filament-android/src/main/java/com/google/android/filament/Engine.java b/android/filament-android/src/main/java/com/google/android/filament/Engine.java index 957e2c2a0b..299ceed272 100644 --- a/android/filament-android/src/main/java/com/google/android/filament/Engine.java +++ b/android/filament-android/src/main/java/com/google/android/filament/Engine.java @@ -264,7 +264,8 @@ public class Engine { config.disableHandleUseAfterFreeCheck, config.preferredShaderLanguage.ordinal(), config.forceGLES2Context, config.assertNativeWindowIsValid, - config.gpuContextPriority.ordinal()); + config.gpuContextPriority.ordinal(), + config.sharedUboInitialSizeInBytes); return this; } @@ -525,6 +526,16 @@ public class Engine { * GPU context priority level. Controls GPU work scheduling and preemption. */ public GpuContextPriority gpuContextPriority = GpuContextPriority.DEFAULT; + + /** + * The initial size in bytes of the shared uniform buffer used for material instance batching. + * + * If the buffer runs out of space during a frame, it will be automatically reallocated + * with a larger capacity. Setting an appropriate initial size can help avoid runtime + * reallocations, which can cause a minor performance stutter, at the cost of higher + * initial memory usage. + */ + public long sharedUboInitialSizeInBytes = 256 * 64; } private Engine(long nativeEngine, Config config) { @@ -1529,7 +1540,8 @@ public class Engine { boolean disableHandleUseAfterFreeCheck, int preferredShaderLanguage, boolean forceGLES2Context, boolean assertNativeWindowIsValid, - int gpuContextPriority); + int gpuContextPriority, + long sharedUboInitialSizeInBytes); private static native void nSetBuilderFeatureLevel(long nativeBuilder, int ordinal); private static native void nSetBuilderSharedContext(long nativeBuilder, long sharedContext); private static native void nSetBuilderPaused(long nativeBuilder, boolean paused); diff --git a/filament/include/filament/Engine.h b/filament/include/filament/Engine.h index 22c8c6f622..b1006516f9 100644 --- a/filament/include/filament/Engine.h +++ b/filament/include/filament/Engine.h @@ -417,6 +417,17 @@ public: * GPU context priority level. Controls GPU work scheduling and preemption. */ GpuContextPriority gpuContextPriority = GpuContextPriority::DEFAULT; + + /** + * The initial size in bytes of the shared uniform buffer used for material instance + * batching. + * + * If the buffer runs out of space during a frame, it will be automatically reallocated + * with a larger capacity. Setting an appropriate initial size can help avoid runtime + * reallocations, which can cause a minor performance stutter, at the cost of higher + * initial memory usage. + */ + uint32_t sharedUboInitialSizeInBytes = 256 * 64; };