From b5d7de06bcdb56a2d26b2caec6bd5774998c5670 Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Mon, 3 Jun 2024 13:55:01 -0700 Subject: [PATCH] Engine::unprotected() drops the command queue back to unprotected mode FIXES=[344021154] --- android/filament-android/src/main/cpp/Engine.cpp | 7 +++++++ .../java/com/google/android/filament/Engine.java | 13 +++++++++++++ filament/include/filament/Engine.h | 8 ++++++++ filament/src/Engine.cpp | 4 ++++ filament/src/details/Engine.cpp | 9 +++++++++ filament/src/details/Engine.h | 3 +++ web/filament-js/jsbindings.cpp | 2 ++ 7 files changed, 46 insertions(+) diff --git a/android/filament-android/src/main/cpp/Engine.cpp b/android/filament-android/src/main/cpp/Engine.cpp index a4ace37853..4b3b33e530 100644 --- a/android/filament-android/src/main/cpp/Engine.cpp +++ b/android/filament-android/src/main/cpp/Engine.cpp @@ -420,6 +420,13 @@ Java_com_google_android_filament_Engine_nSetPaused(JNIEnv*, jclass, engine->setPaused(paused); } +extern "C" JNIEXPORT void JNICALL +Java_com_google_android_filament_Engine_nUnprotected(JNIEnv*, jclass, + jlong nativeEngine, jboolean paused) { + Engine* engine = (Engine*) nativeEngine; + engine->unprotected(); +} + // Managers... extern "C" JNIEXPORT jlong JNICALL 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 827fcf11ca..5a28d1eae8 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 @@ -1289,6 +1289,18 @@ public class Engine { nSetPaused(getNativeObject(), paused); } + /** + * Switch the command queue to unprotected mode. Protected mode can be activated via + * Renderer::beginFrame() using a protected SwapChain. + + * @see Renderer + * @see SwapChain + */ + public void unprotected() { + nUnprotected(getNativeObject()); + } + + @UsedByReflection("TextureHelper.java") public long getNativeObject() { if (mNativeObject == 0) { @@ -1366,6 +1378,7 @@ public class Engine { private static native void nFlush(long nativeEngine); private static native boolean nIsPaused(long nativeEngine); private static native void nSetPaused(long nativeEngine, boolean paused); + private static native void nUnprotected(long nativeEngine); private static native long nGetTransformManager(long nativeEngine); private static native long nGetLightManager(long nativeEngine); private static native long nGetRenderableManager(long nativeEngine); diff --git a/filament/include/filament/Engine.h b/filament/include/filament/Engine.h index bade124fbe..2aed82736f 100644 --- a/filament/include/filament/Engine.h +++ b/filament/include/filament/Engine.h @@ -930,6 +930,14 @@ public: */ void pumpMessageQueues(); + /** + * Switch the command queue to unprotected mode. Protected mode can be activated via + * Renderer::beginFrame() using a protected SwapChain. + * @see Renderer + * @see SwapChain + */ + void unprotected() noexcept; + /** * Returns the default Material. * diff --git a/filament/src/Engine.cpp b/filament/src/Engine.cpp index ae37b3cea1..ad110dbc92 100644 --- a/filament/src/Engine.cpp +++ b/filament/src/Engine.cpp @@ -329,6 +329,10 @@ void Engine::pumpMessageQueues() { downcast(this)->pumpMessageQueues(); } +void Engine::unprotected() noexcept { + downcast(this)->unprotected(); +} + void Engine::setAutomaticInstancingEnabled(bool enable) noexcept { downcast(this)->setAutomaticInstancingEnabled(enable); } diff --git a/filament/src/details/Engine.cpp b/filament/src/details/Engine.cpp index 54e16bb69c..2547b40103 100644 --- a/filament/src/details/Engine.cpp +++ b/filament/src/details/Engine.cpp @@ -476,6 +476,8 @@ void FEngine::shutdown() { destroy(mDefaultMaterial); + destroy(mUnprotectedDummySwapchain); + /* * clean-up after the user -- we call terminate on each "leaked" object and clear each list. * @@ -1253,6 +1255,13 @@ void FEngine::resetBackendState() noexcept { } #endif +void FEngine::unprotected() noexcept { + if (UTILS_UNLIKELY(!mUnprotectedDummySwapchain)) { + mUnprotectedDummySwapchain = createSwapChain(1, 1, 0); + } + mUnprotectedDummySwapchain->makeCurrent(getDriverApi()); +} + // ------------------------------------------------------------------------------------------------ Engine::Builder::Builder() noexcept = default; diff --git a/filament/src/details/Engine.h b/filament/src/details/Engine.h index 85f065bf83..972e446d55 100644 --- a/filament/src/details/Engine.h +++ b/filament/src/details/Engine.h @@ -406,6 +406,8 @@ public: getDriver().purge(); } + void unprotected() noexcept; + void setAutomaticInstancingEnabled(bool enable) noexcept { // instancing is not allowed at feature level 0 if (hasFeatureLevel(FeatureLevel::FEATURE_LEVEL_1)) { @@ -539,6 +541,7 @@ private: mutable FMaterial const* mDefaultMaterial = nullptr; mutable FMaterial const* mSkyboxMaterial = nullptr; + mutable FSwapChain* mUnprotectedDummySwapchain = nullptr; mutable FTexture* mDefaultIblTexture = nullptr; mutable FIndirectLight* mDefaultIbl = nullptr; diff --git a/web/filament-js/jsbindings.cpp b/web/filament-js/jsbindings.cpp index 79a573b042..735305a563 100644 --- a/web/filament-js/jsbindings.cpp +++ b/web/filament-js/jsbindings.cpp @@ -388,6 +388,8 @@ class_("Engine") return Engine::create(); }, allow_raw_pointers()) + .function("unprotected", &Engine::unprotected) + .function("enableAccurateTranslations", &Engine::enableAccurateTranslations) .function("setAutomaticInstancingEnabled", &Engine::setAutomaticInstancingEnabled)