Skip to content

Commit 8d6e8b8

Browse files
authored
buffer update opt: Add engine config for default shared Ubo size (#9340)
1 parent 9da29e3 commit 8d6e8b8

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

android/filament-android/src/main/cpp/Engine.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,8 @@ extern "C" JNIEXPORT void JNICALL Java_com_google_android_filament_Engine_nSetBu
557557
jboolean disableHandleUseAfterFreeCheck,
558558
jint preferredShaderLanguage,
559559
jboolean forceGLES2Context, jboolean assertNativeWindowIsValid,
560-
jint gpuContextPriority) {
560+
jint gpuContextPriority,
561+
jlong sharedUboInitialSizeInBytes) {
561562
Engine::Builder* builder = (Engine::Builder*) nativeBuilder;
562563
Engine::Config config = {
563564
.commandBufferSizeMB = (uint32_t) commandBufferSizeMB,
@@ -576,6 +577,7 @@ extern "C" JNIEXPORT void JNICALL Java_com_google_android_filament_Engine_nSetBu
576577
.forceGLES2Context = (bool) forceGLES2Context,
577578
.assertNativeWindowIsValid = (bool) assertNativeWindowIsValid,
578579
.gpuContextPriority = (Engine::GpuContextPriority) gpuContextPriority,
580+
.sharedUboInitialSizeInBytes = (uint32_t) sharedUboInitialSizeInBytes,
579581
};
580582
builder->config(&config);
581583
}

android/filament-android/src/main/java/com/google/android/filament/Engine.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,8 @@ public Builder config(Config config) {
264264
config.disableHandleUseAfterFreeCheck,
265265
config.preferredShaderLanguage.ordinal(),
266266
config.forceGLES2Context, config.assertNativeWindowIsValid,
267-
config.gpuContextPriority.ordinal());
267+
config.gpuContextPriority.ordinal(),
268+
config.sharedUboInitialSizeInBytes);
268269
return this;
269270
}
270271

@@ -525,6 +526,16 @@ public enum ShaderLanguage {
525526
* GPU context priority level. Controls GPU work scheduling and preemption.
526527
*/
527528
public GpuContextPriority gpuContextPriority = GpuContextPriority.DEFAULT;
529+
530+
/**
531+
* The initial size in bytes of the shared uniform buffer used for material instance batching.
532+
*
533+
* If the buffer runs out of space during a frame, it will be automatically reallocated
534+
* with a larger capacity. Setting an appropriate initial size can help avoid runtime
535+
* reallocations, which can cause a minor performance stutter, at the cost of higher
536+
* initial memory usage.
537+
*/
538+
public long sharedUboInitialSizeInBytes = 256 * 64;
528539
}
529540

530541
private Engine(long nativeEngine, Config config) {
@@ -1529,7 +1540,8 @@ private static native void nSetBuilderConfig(long nativeBuilder, long commandBuf
15291540
boolean disableHandleUseAfterFreeCheck,
15301541
int preferredShaderLanguage,
15311542
boolean forceGLES2Context, boolean assertNativeWindowIsValid,
1532-
int gpuContextPriority);
1543+
int gpuContextPriority,
1544+
long sharedUboInitialSizeInBytes);
15331545
private static native void nSetBuilderFeatureLevel(long nativeBuilder, int ordinal);
15341546
private static native void nSetBuilderSharedContext(long nativeBuilder, long sharedContext);
15351547
private static native void nSetBuilderPaused(long nativeBuilder, boolean paused);

filament/include/filament/Engine.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,17 @@ class UTILS_PUBLIC Engine {
417417
* GPU context priority level. Controls GPU work scheduling and preemption.
418418
*/
419419
GpuContextPriority gpuContextPriority = GpuContextPriority::DEFAULT;
420+
421+
/**
422+
* The initial size in bytes of the shared uniform buffer used for material instance
423+
* batching.
424+
*
425+
* If the buffer runs out of space during a frame, it will be automatically reallocated
426+
* with a larger capacity. Setting an appropriate initial size can help avoid runtime
427+
* reallocations, which can cause a minor performance stutter, at the cost of higher
428+
* initial memory usage.
429+
*/
430+
uint32_t sharedUboInitialSizeInBytes = 256 * 64;
420431
};
421432

422433

0 commit comments

Comments
 (0)