diff --git a/android/filament-android/src/main/cpp/Engine.cpp b/android/filament-android/src/main/cpp/Engine.cpp index d6e941209b..2896dbd030 100644 --- a/android/filament-android/src/main/cpp/Engine.cpp +++ b/android/filament-android/src/main/cpp/Engine.cpp @@ -556,7 +556,8 @@ extern "C" JNIEXPORT void JNICALL Java_com_google_android_filament_Engine_nSetBu jlong resourceAllocatorCacheSizeMB, jlong resourceAllocatorCacheMaxAge, jboolean disableHandleUseAfterFreeCheck, jint preferredShaderLanguage, - jboolean forceGLES2Context, jboolean assertNativeWindowIsValid) { + jboolean forceGLES2Context, jboolean assertNativeWindowIsValid, + jint gpuContextPriority) { Engine::Builder* builder = (Engine::Builder*) nativeBuilder; Engine::Config config = { .commandBufferSizeMB = (uint32_t) commandBufferSizeMB, @@ -574,6 +575,7 @@ extern "C" JNIEXPORT void JNICALL Java_com_google_android_filament_Engine_nSetBu .preferredShaderLanguage = (Engine::Config::ShaderLanguage) preferredShaderLanguage, .forceGLES2Context = (bool) forceGLES2Context, .assertNativeWindowIsValid = (bool) assertNativeWindowIsValid, + .gpuContextPriority = (Engine::GpuContextPriority) gpuContextPriority, }; 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 63056170e3..957e2c2a0b 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 @@ -175,6 +175,36 @@ public class Engine { MULTIVIEW, }; + /** + * This controls the priority level for GPU work scheduling, which helps prioritize the + * submitted GPU work and enables preemption. + */ + public enum GpuContextPriority { + /** + * Backend default GPU context priority (typically MEDIUM) + */ + DEFAULT, + /** + * For non-interactive, deferrable workloads. This should not interfere with standard + * applications. + */ + LOW, + /** + * The default priority level for standard applications. + */ + MEDIUM, + /** + * For high-priority, latency-sensitive workloads that are more important than standard + * applications. + */ + HIGH, + /** + * The highest priority, intended for system-critical, real-time applications where missing + * deadlines is unacceptable (e.g., VR/AR compositors or other system-critical tasks). + */ + REALTIME, + }; + /** * Constructs Engine objects using a builder pattern. */ @@ -233,7 +263,8 @@ public class Engine { config.resourceAllocatorCacheSizeMB, config.resourceAllocatorCacheMaxAge, config.disableHandleUseAfterFreeCheck, config.preferredShaderLanguage.ordinal(), - config.forceGLES2Context, config.assertNativeWindowIsValid); + config.forceGLES2Context, config.assertNativeWindowIsValid, + config.gpuContextPriority.ordinal()); return this; } @@ -489,6 +520,11 @@ public class Engine { * @Deprecated use "backend.opengl.assert_native_window_is_valid" feature flag instead */ public boolean assertNativeWindowIsValid = false; + + /** + * GPU context priority level. Controls GPU work scheduling and preemption. + */ + public GpuContextPriority gpuContextPriority = GpuContextPriority.DEFAULT; } private Engine(long nativeEngine, Config config) { @@ -1492,7 +1528,8 @@ public class Engine { long resourceAllocatorCacheSizeMB, long resourceAllocatorCacheMaxAge, boolean disableHandleUseAfterFreeCheck, int preferredShaderLanguage, - boolean forceGLES2Context, boolean assertNativeWindowIsValid); + boolean forceGLES2Context, boolean assertNativeWindowIsValid, + int gpuContextPriority); 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 103a579d0f..63dbcc089e 100644 --- a/filament/include/filament/Engine.h +++ b/filament/include/filament/Engine.h @@ -190,6 +190,7 @@ public: using FeatureLevel = backend::FeatureLevel; using StereoscopicType = backend::StereoscopicType; using Driver = backend::Driver; + using GpuContextPriority = backend::Platform::GpuContextPriority; /** * Config is used to define the memory footprint used by the engine, such as the @@ -410,6 +411,11 @@ public: * @deprecated use "backend.opengl.assert_native_window_is_valid" feature flag instead */ bool assertNativeWindowIsValid = false; + + /** + * GPU context priority level. Controls GPU work scheduling and preemption. + */ + GpuContextPriority gpuContextPriority = GpuContextPriority::DEFAULT; }; diff --git a/filament/src/details/Engine.cpp b/filament/src/details/Engine.cpp index 9ea362abcd..8a8145a699 100644 --- a/filament/src/details/Engine.cpp +++ b/filament/src/details/Engine.cpp @@ -141,6 +141,7 @@ Engine* FEngine::create(Builder const& builder) { .stereoscopicType = instance->getConfig().stereoscopicType, .assertNativeWindowIsValid = instance->features.backend.opengl.assert_native_window_is_valid, .metalDisablePanicOnDrawableFailure = instance->getConfig().metalDisablePanicOnDrawableFailure, + .gpuContextPriority = instance->getConfig().gpuContextPriority, }; instance->mDriver = platform->createDriver(sharedContext, driverConfig); @@ -761,6 +762,7 @@ int FEngine::loop() { .stereoscopicType = mConfig.stereoscopicType, .assertNativeWindowIsValid = features.backend.opengl.assert_native_window_is_valid, .metalDisablePanicOnDrawableFailure = mConfig.metalDisablePanicOnDrawableFailure, + .gpuContextPriority = mConfig.gpuContextPriority, }; mDriver = mPlatform->createDriver(mSharedGLContext, driverConfig); @@ -822,9 +824,9 @@ int FEngine::loop() { #if FILAMENT_ENABLE_MATDBG if(debug.server) { delete debug.server; - } + } #endif -#if FILAMENT_ENABLE_FGVIEWER +#if FILAMENT_ENABLE_FGVIEWER if(debug.fgviewerServer) { delete debug.fgviewerServer; }