Repository: google/filament
File: filament/src/details/Engine.cpp (C++)

Code before:

    // Finally, call user callbacks that might have been scheduled.
    // These callbacks CANNOT call driver APIs.
    getDriver().purge();

    // and destroy the CommandStream
    std::destroy_at(std::launder(reinterpret_cast<DriverApi*>(&mDriverApiStorage)));

    /*
     * Terminate the JobSystem...
     */

    // detach this thread from the JobSystem
    mJobSystem.emancipate();
}

void FEngine::prepare() {
    FILAMENT_TRACING_CALL(FILAMENT_TRACING_CATEGORY_FILAMENT);
    // prepare() is called once per Renderer frame. Ideally we would upload the content of
    // UBOs that are visible only. It's not such a big issue because the actual upload() is
    // skipped if the UBO hasn't changed. Still we could have a lot of these.
    DriverApi& driver = getDriverApi();

    for (auto& materialInstanceList: mMaterialInstances) {
        materialInstanceList.second.forEach([&driver](FMaterialInstance* item) {
            // post-process materials isntances must be commited explicitly because their
            // parameters are typically not set at this point in time.
            if (item->getMaterial()->getMaterialDomain() == MaterialDomain::SURFACE) {
                item->commitStreamUniformAssociations(driver);
                item->commit(driver);
            }
        });
    }

    mMaterials.forEach([](FMaterial* material) {
#if FILAMENT_ENABLE_MATDBG // NOLINT(*-include-cleaner)
        material->checkProgramEdits();
#endif
    });
}

void FEngine::gc() {
    // Note: this runs in a Job
    auto& em = mEntityManager;
    mRenderableManager.gc(em);
    mLightManager.gc(em);
    mTransformManager.gc(em);
    mCameraManager.gc(*this, em);
}

void FEngine::flush() {

Review comment (suggestion):
```suggestion
            // post-process materials instances must be commited explicitly because their
```

Code after:

    // Finally, call user callbacks that might have been scheduled.
    // These callbacks CANNOT call driver APIs.
    getDriver().purge();

    // and destroy the CommandStream
    std::destroy_at(std::launder(reinterpret_cast<DriverApi*>(&mDriverApiStorage)));

    /*
     * Terminate the JobSystem...
     */

    // detach this thread from the JobSystem
    mJobSystem.emancipate();
}

void FEngine::prepare() {
    FILAMENT_TRACING_CALL(FILAMENT_TRACING_CATEGORY_FILAMENT);
    // prepare() is called once per Renderer frame. Ideally we would upload the content of
    // UBOs that are visible only. It's not such a big issue because the actual upload() is
    // skipped if the UBO hasn't changed. Still we could have a lot of these.
    DriverApi& driver = getDriverApi();

    for (auto& materialInstanceList: mMaterialInstances) {
        materialInstanceList.second.forEach([&driver](FMaterialInstance* item) {
            // post-process materials instances must be commited explicitly because their
            // parameters are typically not set at this point in time.
            if (item->getMaterial()->getMaterialDomain() == MaterialDomain::SURFACE) {
                item->commitStreamUniformAssociations(driver);
                item->commit(driver);
            }
        });
    }

    mMaterials.forEach([](FMaterial* material) {
#if FILAMENT_ENABLE_MATDBG // NOLINT(*-include-cleaner)
        material->checkProgramEdits();
#endif
    });
}

void FEngine::gc() {
    // Note: this runs in a Job
    auto& em = mEntityManager;
    mRenderableManager.gc(em);
    mLightManager.gc(em);
    mTransformManager.gc(em);
    mCameraManager.gc(*this, em);
}

void FEngine::flush() {