0

私はアンドロイドrenderscriptプログラムを書いています。奇妙なパフォーマンスの問題があります。プログラムには次の 2 つの部分があります。

  1. 2 つの画像をミックスします。
  2. 混合画像に特殊効果を追加します。

パート 1 をテストしたところ、20 ミリ秒かかりました。パート 2 はさらに 10ms かかります。しかし、パート 2 の結果を返すと、全体の実行時間は 200ms になります。

コードは次のとおりです。

static uchar4 effect (uint32_t x, uint32_t y) {

    /* Part 1: Mix two images */
    const uchar4 *element1 = rsGetElementAt(gIn1, x, y);
    const uchar4 *element2 = rsGetElementAt(gIn2, x, y);
    float4 inColor1 = rsUnpackColor8888(*element1);
    float4 inColor2 = rsUnpackColor8888(*element2);

    float4 mixed = inColor1 * 0.5 + inColor2 * 0.5;

    /* Part 2: Special Effect */
    /* a lot computation here ... */
    /* a lot computation here ... */
    /* a lot computation here ... */
    float4 effect = ...;    /* computation result */

    float4 mixedEffect = mixed * 0.5 + effect * 0.5;

    /* Output result */
    return rsPackColorTo8888(mixed);        // fast
    // return rsPackColorTo8888(mixedEffect);   // very slow
}

void root(const uchar4 *v_in, uchar4 *v_out, const void *usrData,
    uint32_t x, uint32_t y) {
    *v_out = effect(x, y);
}

私は 3 つのテストを行いました: 1) パート 1 混合画像コードのみで、混合 float4、20ms を返します 2) パート 1 とパート 2 コードの両方で、混合 float4、30ms を返します 3) パート 1 とパート 2 コードの両方で、mixedEffect float4 を返します、200ms

2 回目と 3 回目のテストでは、返す変数を変更すると、全体的なパフォーマンスが低下します。なぜこれが起こっているのか誰にも分かりますか?

4

1 に答える 1