Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0a56063b authored by Cairn Overturf's avatar Cairn Overturf
Browse files

Track full HWC strategy when doing prediction

Query for testing:

WITH SliceCounts AS (
  SELECT
    SUM(CASE WHEN name = 'prepareFrameAsync' THEN 1 ELSE 0 END) AS prepareFrameAsync_count,
    SUM(CASE WHEN name = 'CompositionStrategyPredictionHit' THEN 1 ELSE 0 END) AS predictionHit_count,
    SUM(CASE WHEN name = 'CompositionStrategyPredictionMiss' THEN 1 ELSE 0 END) AS predictionMiss_count
  FROM slice
  WHERE name IN (
    'prepareFrameAsync',
    'CompositionStrategyPredictionHit',
    'CompositionStrategyPredictionMiss'
  )
)
SELECT
  prepareFrameAsync_count,
  predictionHit_count,
  predictionMiss_count,
  CASE
    WHEN prepareFrameAsync_count = 0 THEN 0.0
    ELSE (predictionHit_count + predictionMiss_count) * 1.0 / prepareFrameAsync_count
  END AS prediction_to_prepare_ratio
FROM SliceCounts;

Bug: 383675195, 399044498
Test: Take a perfetto trace of some CUJs and run the above script. It should be similar before and after the change.
Flag: EXEMPT bugfix
Change-Id: Ifb01f4edbfd73e03763356b5b06744771d4665e8
parent d567757a
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
@@ -1143,6 +1143,15 @@ void Output::prepareFrame() {

    std::optional<android::HWComposer::DeviceRequestedChanges> changes;
    bool success = chooseCompositionStrategy(&changes);

    if (success && changes.has_value()) {
        for (const compositionengine::OutputLayer* layer : getOutputLayersOrderedByZ()) {
            HWC2::Layer* hwcLayer = layer->getHwcLayer();
            if (!hwcLayer || changes->changedTypes.contains(hwcLayer)) continue;
            changes->changedTypes[hwcLayer] = layer->getState().hwc->hwcCompositionType;
        }
    }

    resetCompositionStrategy();
    outputState.strategyPrediction = CompositionStrategyPredictionState::DISABLED;
    outputState.previousDeviceRequestedChanges = changes;
@@ -1174,6 +1183,14 @@ GpuCompositionResult Output::prepareFrameAsync() {
    const auto& previousChanges = state.previousDeviceRequestedChanges;
    std::optional<android::HWComposer::DeviceRequestedChanges> changes;
    resetCompositionStrategy();
    // Store all layer composition types before appplying composition strategy
    android::HWComposer::DeviceRequestedChanges::ChangedTypes backups;
    for (const compositionengine::OutputLayer* layer : getOutputLayersOrderedByZ()) {
        HWC2::Layer* hwcLayer = layer->getHwcLayer();
        if (!hwcLayer) continue;
        backups[hwcLayer] = layer->getState().hwc->hwcCompositionType;
    }

    auto hwcResult = chooseCompositionStrategyAsync(&changes);
    if (state.previousDeviceRequestedSuccess) {
        applyCompositionStrategy(previousChanges);
@@ -1194,6 +1211,14 @@ GpuCompositionResult Output::prepareFrameAsync() {
    }

    auto chooseCompositionSuccess = hwcResult.get();
    if (chooseCompositionSuccess && changes.has_value()) {
        // Keep track of all layer composition types, not just changes
        for (const compositionengine::OutputLayer* layer : getOutputLayersOrderedByZ()) {
            HWC2::Layer* hwcLayer = layer->getHwcLayer();
            if (!hwcLayer || changes->changedTypes.contains(hwcLayer)) continue;
            changes->changedTypes[hwcLayer] = backups[hwcLayer];
        }
    }
    const bool predictionSucceeded = dequeueSucceeded && changes == previousChanges;
    state.strategyPrediction = predictionSucceeded ? CompositionStrategyPredictionState::SUCCESS
                                                   : CompositionStrategyPredictionState::FAIL;
+5 −0
Original line number Diff line number Diff line
@@ -970,6 +970,11 @@ void OutputLayer::applyDeviceCompositionTypeChange(Composition compositionType)
    LOG_FATAL_IF(!state.hwc);
    auto& hwcState = *state.hwc;

    if (hwcState.hwcCompositionType == compositionType) {
        // no changes
        return;
    }

    // Only detected disallowed changes if this was not a skip layer, because the
    // validated composition type may be arbitrary (usually DEVICE, to reflect that there were
    // fewer GPU layers)