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

Commit cb040a06 authored by Xia Wang's avatar Xia Wang
Browse files

Add more opengl benchmark test:

 - all apps in launcher
 - shortcuts of apps in home page

Change-Id: Ibec109993bd17a990378dba394dfb0ab99774181
parent 622d5441
Loading
Loading
Loading
Loading
+16 −5
Original line number Original line Diff line number Diff line
@@ -44,6 +44,7 @@ import android.util.Log;
public class RsBenchRS {
public class RsBenchRS {


    private static final String TAG = "RsBenchRS";
    private static final String TAG = "RsBenchRS";
    private static final String SAMPLE_TEXT = "Bench Test";


    int mWidth;
    int mWidth;
    int mHeight;
    int mHeight;
@@ -125,7 +126,8 @@ public class RsBenchRS {
    Font mFontSerif;
    Font mFontSerif;
    private Allocation mTextAlloc;
    private Allocation mTextAlloc;


    private ScriptField_TexAllocs_s mTextureAllocs;
    private ScriptField_ListAllocs_s mTextureAllocs;
    private ScriptField_ListAllocs_s mSampleTextAllocs;


    private ScriptC_rsbench mScript;
    private ScriptC_rsbench mScript;


@@ -445,7 +447,7 @@ public class RsBenchRS {
        mScript.set_g100by100Mesh(m100by100Mesh);
        mScript.set_g100by100Mesh(m100by100Mesh);
        mWbyHMesh= getMbyNMesh(mBenchmarkDimX, mBenchmarkDimY, mBenchmarkDimX/4, mBenchmarkDimY/4);
        mWbyHMesh= getMbyNMesh(mBenchmarkDimX, mBenchmarkDimY, mBenchmarkDimX/4, mBenchmarkDimY/4);
        mScript.set_gWbyHMesh(mWbyHMesh);
        mScript.set_gWbyHMesh(mWbyHMesh);
        mSingleMesh = getSingleMesh(50, 50);
        mSingleMesh = getSingleMesh(1, 1);  // a unit size mesh
        mScript.set_gSingleMesh(mSingleMesh);
        mScript.set_gSingleMesh(mSingleMesh);


        FileA3D model = FileA3D.createFromResource(mRS, mRes, R.raw.torus);
        FileA3D model = FileA3D.createFromResource(mRS, mRes, R.raw.torus);
@@ -547,15 +549,24 @@ public class RsBenchRS {
        mScript.set_gRenderBufferDepth(offscreen);
        mScript.set_gRenderBufferDepth(offscreen);




        mTextureAllocs = new ScriptField_TexAllocs_s(mRS, 100);
        mTextureAllocs = new ScriptField_ListAllocs_s(mRS, 100);
        for (int i = 0; i < 100; i++) {
        for (int i = 0; i < 100; i++) {
            ScriptField_TexAllocs_s.Item texElem = new ScriptField_TexAllocs_s.Item();
            ScriptField_ListAllocs_s.Item texElem = new ScriptField_ListAllocs_s.Item();
            texElem.texture = loadTextureRGB(R.drawable.globe);
            texElem.item = loadTextureRGB(R.drawable.globe);
            mTextureAllocs.set(texElem, i, false);
            mTextureAllocs.set(texElem, i, false);
        }
        }
        mTextureAllocs.copyAll();
        mTextureAllocs.copyAll();
        mScript.bind_gTexList100(mTextureAllocs);
        mScript.bind_gTexList100(mTextureAllocs);


        mSampleTextAllocs = new ScriptField_ListAllocs_s(mRS, 100);
        for (int i = 0; i < 100; i++) {
            ScriptField_ListAllocs_s.Item textElem = new ScriptField_ListAllocs_s.Item();
            textElem.item = Allocation.createFromString(mRS, SAMPLE_TEXT, Allocation.USAGE_SCRIPT);
            mSampleTextAllocs.set(textElem, i, false);
        }
        mSampleTextAllocs.copyAll();
        mScript.bind_gSampleTextList100(mSampleTextAllocs);

        mRS.bindRootScript(mScript);
        mRS.bindRootScript(mScript);
    }
    }
}
}
+97 −16
Original line number Original line Diff line number Diff line
@@ -23,7 +23,7 @@
const int RS_MSG_TEST_DONE = 100;
const int RS_MSG_TEST_DONE = 100;
const int RS_MSG_RESULTS_READY = 101;
const int RS_MSG_RESULTS_READY = 101;


const int gMaxModes = 27;
const int gMaxModes = 29;
int gMaxLoops;
int gMaxLoops;


// Allocation to send test names back to java
// Allocation to send test names back to java
@@ -46,11 +46,12 @@ rs_allocation gTexTransparent;
rs_allocation gTexChecker;
rs_allocation gTexChecker;
rs_allocation gTexGlobe;
rs_allocation gTexGlobe;


typedef struct TexAllocs_s {
typedef struct ListAllocs_s {
    rs_allocation texture;
    rs_allocation item;
} TexAllocs;
} ListAllocs;


TexAllocs *gTexList100;
ListAllocs *gTexList100;
ListAllocs *gSampleTextList100;


rs_mesh g10by10Mesh;
rs_mesh g10by10Mesh;
rs_mesh g100by100Mesh;
rs_mesh g100by100Mesh;
@@ -195,6 +196,7 @@ static void displayMeshSamples(int meshNum) {
    rsgBindProgramStore(gProgStoreBlendNone);
    rsgBindProgramStore(gProgStoreBlendNone);
    rsgBindProgramFragment(gProgFragmentTexture);
    rsgBindProgramFragment(gProgFragmentTexture);
    rsgBindSampler(gProgFragmentTexture, 0, gLinearClamp);
    rsgBindSampler(gProgFragmentTexture, 0, gLinearClamp);

    rsgBindTexture(gProgFragmentTexture, 0, gTexOpaque);
    rsgBindTexture(gProgFragmentTexture, 0, gTexOpaque);


    if (meshNum == 0) {
    if (meshNum == 0) {
@@ -207,7 +209,7 @@ static void displayMeshSamples(int meshNum) {
}
}


// Display sample images in a mesh with different texture
// Display sample images in a mesh with different texture
static void displayMeshWithMultiTexture(int meshMode) {
static void displayIcons(int meshMode) {
    bindProgramVertexOrtho();
    bindProgramVertexOrtho();


    // Fragment shader with texture
    // Fragment shader with texture
@@ -217,22 +219,90 @@ static void displayMeshWithMultiTexture(int meshMode) {


    int meshCount = (int)pow(10.0f, (float)(meshMode + 1));
    int meshCount = (int)pow(10.0f, (float)(meshMode + 1));


    float size = 50.0;
    rs_matrix4x4 matrix;
    rsMatrixLoadScale(&matrix, size, size, 1.0);

    float yPos = 0;
    float yPos = 0;
    for (int y = 0; y < meshCount; y++) {
    for (int y = 0; y < meshCount; y++) {
        yPos = (y + 1) * 50;
        yPos = (y + 1) * 50;
        float xPos = 0;
        float xPos = 0;
        for (int x = 0; x < meshCount; x++) {
        for (int x = 0; x < meshCount; x++) {
            xPos = (x + 1) * 50;
            xPos = (x + 1) * 50;
            rs_matrix4x4 matrix;
            rs_matrix4x4 transMatrix;
            rsMatrixLoadTranslate(&matrix, xPos, yPos, 0);
            rsMatrixLoadTranslate(&transMatrix, xPos, yPos, 0);
            rsgProgramVertexLoadModelMatrix(&matrix);
            rsMatrixMultiply(&transMatrix, &matrix);
            rsgProgramVertexLoadModelMatrix(&transMatrix);
            int i = (x + y * meshCount) % 100;
            int i = (x + y * meshCount) % 100;
            rsgBindTexture(gProgFragmentTexture, 0, gTexList100[i].texture);
            rsgBindTexture(gProgFragmentTexture, 0, gTexList100[i].item);
            rsgDrawMesh(gSingleMesh);
            rsgDrawMesh(gSingleMesh);
        }
        }
    }
    }
}
}


// Draw meshes in a single page with top left corner coordinates (xStart, yStart)
static void drawMeshInPage(float xStart, float yStart, int wResolution, int hResolution) {
    // Draw wResolution * hResolution meshes in one page
    float wMargin = 100.0f;
    float hMargin = 100.0f;
    float xPad = 50.0f;
    float yPad = 20.0f;
    float size = 100.0f;  // size of images

    // font info
    rs_font font = gFontSans;
    rsgBindFont(font);
    rsgFontColor(1.0f, 1.0f, 1.0f, 1.0f);

    // Measure text size
    int left = 0, right = 0, top = 0, bottom = 0;
    rsgMeasureText(gSampleTextList100[0].item, &left, &right, &top, &bottom);
    float textHeight = (float)(top - bottom);
    float textWidth = (float)(right - left);

    rs_matrix4x4 matrix;
    rsMatrixLoadScale(&matrix, size, size, 1.0);

    for (int y = 0; y < hResolution; y++) {
        float yPos = yStart + hMargin + y * size + y * yPad;
        for (int x = 0; x < wResolution; x++) {
            float xPos = xStart + wMargin + x * size + x * xPad;

            rs_matrix4x4 transMatrix;
            rsMatrixLoadTranslate(&transMatrix, xPos + size/2, yPos + size/2, 0);
            rsMatrixMultiply(&transMatrix, &matrix);  // scale the mesh
            rsgProgramVertexLoadModelMatrix(&transMatrix);

            int i = (y * wResolution + x) % 100;
            rsgBindTexture(gProgFragmentTexture, 0, gTexList100[i].item);
            rsgDrawMesh(gSingleMesh);
            rsgDrawText(gSampleTextList100[i].item, xPos, yPos + size + yPad/2 + textHeight);
        }
    }
}

// Display both images and text as shown in launcher and homepage
// meshMode will decide how many pages we draw
// meshMode = 0: draw 3 pages of meshes
// meshMode = 1: draw 5 pages of meshes
static void displayImageWithText(int wResolution, int hResolution, int meshMode) {
    bindProgramVertexOrtho();

    // Fragment shader with texture
    rsgBindProgramStore(gProgStoreBlendAlpha);
    rsgBindProgramFragment(gProgFragmentTexture);
    rsgBindSampler(gProgFragmentTexture, 0, gLinearClamp);

    drawMeshInPage(0, 0, wResolution, hResolution);
    drawMeshInPage(-1.0f*gRenderSurfaceW, 0, wResolution, hResolution);
    drawMeshInPage(1.0f*gRenderSurfaceW, 0, wResolution, hResolution);
    if (meshMode == 1) {
        // draw another two pages of meshes
        drawMeshInPage(-2.0f*gRenderSurfaceW, 0, wResolution, hResolution);
        drawMeshInPage(2.0f*gRenderSurfaceW, 0, wResolution, hResolution);
    }
}

static float gTorusRotation = 0;
static float gTorusRotation = 0;
static void updateModelMatrix(rs_matrix4x4 *matrix, void *buffer) {
static void updateModelMatrix(rs_matrix4x4 *matrix, void *buffer) {
    if (buffer == 0) {
    if (buffer == 0) {
@@ -532,8 +602,14 @@ static const char *testNames[] = {
    "Geo test 25.6k heavy fragment heavy vertex",
    "Geo test 25.6k heavy fragment heavy vertex",
    "Geo test 51.2k heavy fragment heavy vertex",
    "Geo test 51.2k heavy fragment heavy vertex",
    "Geo test 204.8k small tries heavy fragment heavy vertex",
    "Geo test 204.8k small tries heavy fragment heavy vertex",
    "Mesh with 10 by 10 texture",
    "UI test with icon display 10 by 10",     // 25
    "Mesh with 100 by 100 texture",
    "UI test with icon display 100 by 100",   // 26
    "UI test with image and text display 3 pages",  // 27
    "UI test with image and text display 5 pages",  // 28
    "UI test with list view",                       // 29
//    "UI test with live wallpaper",                  // 30
//    "Mesh with 10 by 10 texture",
//    "Mesh with 100 by 100 texture",
};
};


void getTestName(int testIndex) {
void getTestName(int testIndex) {
@@ -627,10 +703,16 @@ static void runTest(int index) {
        displayPixelLightSamples(8, true);
        displayPixelLightSamples(8, true);
        break;
        break;
    case 25:
    case 25:
        displayMeshWithMultiTexture(0);
        displayIcons(0);
        break;
        break;
    case 26:
    case 26:
        displayMeshWithMultiTexture(1);
        displayIcons(1);
        break;
    case 27:
        displayImageWithText(7, 5, 0);
        break;
    case 28:
        displayImageWithText(7, 5, 1);
        break;
        break;
    }
    }
}
}
@@ -683,6 +765,7 @@ int root(void) {
        gRenderSurfaceW = rsgGetWidth();
        gRenderSurfaceW = rsgGetWidth();
        gRenderSurfaceH = rsgGetHeight();
        gRenderSurfaceH = rsgGetHeight();
        int size = 8;
        int size = 8;
        // draw each frame at (8, 3/4 gRenderSurfaceH) with size
        drawOffscreenResult((drawPos+=size)%gRenderSurfaceW, (gRenderSurfaceH * 3) / 4, size, size);
        drawOffscreenResult((drawPos+=size)%gRenderSurfaceW, (gRenderSurfaceH * 3) / 4, size, size);
    }
    }


@@ -692,11 +775,9 @@ int root(void) {
    float fps = (float)(frameCount) / ((float)(end - start)*0.001f);
    float fps = (float)(frameCount) / ((float)(end - start)*0.001f);
    rsDebug(testNames[benchMode], fps);
    rsDebug(testNames[benchMode], fps);
    gResultBuffer[benchMode] = fps;
    gResultBuffer[benchMode] = fps;

    drawOffscreenResult(0, 0,
    drawOffscreenResult(0, 0,
                        gRenderSurfaceW / 2,
                        gRenderSurfaceW / 2,
                        gRenderSurfaceH / 2);
                        gRenderSurfaceH / 2);

    const char* text = testNames[benchMode];
    const char* text = testNames[benchMode];
    int left = 0, right = 0, top = 0, bottom = 0;
    int left = 0, right = 0, top = 0, bottom = 0;
    uint width = rsgGetWidth();
    uint width = rsgGetWidth();