diff options
author | Alex Sakhartchouk <alexst@google.com> | 2011-04-04 14:33:19 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2011-04-04 14:33:19 -0700 |
commit | 78a9f6a8227d1e9b465acb84f8476a30c5af9c13 (patch) | |
tree | 4bb01528d4691740ec94528d0816f65706be34ed /tests/RenderScriptTests/PerfTest/src/com/android/perftest | |
parent | fb2e9d23e03c93fd11d79545a07ae776721117f9 (diff) | |
parent | 8e90f2bc1fa35a2dc7bd2aab8b8241b628800218 (diff) | |
download | frameworks_base-78a9f6a8227d1e9b465acb84f8476a30c5af9c13.zip frameworks_base-78a9f6a8227d1e9b465acb84f8476a30c5af9c13.tar.gz frameworks_base-78a9f6a8227d1e9b465acb84f8476a30c5af9c13.tar.bz2 |
Merge "First draft of fbo in renderscript. Updating samples and benchmark"
Diffstat (limited to 'tests/RenderScriptTests/PerfTest/src/com/android/perftest')
-rw-r--r-- | tests/RenderScriptTests/PerfTest/src/com/android/perftest/RsBenchRS.java | 19 | ||||
-rw-r--r-- | tests/RenderScriptTests/PerfTest/src/com/android/perftest/rsbench.rs | 218 |
2 files changed, 152 insertions, 85 deletions
diff --git a/tests/RenderScriptTests/PerfTest/src/com/android/perftest/RsBenchRS.java b/tests/RenderScriptTests/PerfTest/src/com/android/perftest/RsBenchRS.java index 9757ec6..5443ef8 100644 --- a/tests/RenderScriptTests/PerfTest/src/com/android/perftest/RsBenchRS.java +++ b/tests/RenderScriptTests/PerfTest/src/com/android/perftest/RsBenchRS.java @@ -22,6 +22,8 @@ import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.renderscript.*; +import android.renderscript.Element.DataKind; +import android.renderscript.Element.DataType; import android.renderscript.Allocation.MipmapControl; import android.renderscript.Program.TextureType; import android.renderscript.ProgramStore.DepthFunc; @@ -399,6 +401,23 @@ public class RsBenchRS { initProgramRaster(); initCustomShaders(); + Type.Builder b = new Type.Builder(mRS, Element.RGBA_8888(mRS)); + b.setX(1280).setY(720); + Allocation offscreen = Allocation.createTyped(mRS, + b.create(), + Allocation.USAGE_GRAPHICS_TEXTURE | + Allocation.USAGE_GRAPHICS_RENDER_TARGET); + mScript.set_gRenderBufferColor(offscreen); + + b = new Type.Builder(mRS, + Element.createPixel(mRS, DataType.UNSIGNED_16, + DataKind.PIXEL_DEPTH)); + b.setX(1280).setY(720); + offscreen = Allocation.createTyped(mRS, + b.create(), + Allocation.USAGE_GRAPHICS_RENDER_TARGET); + mScript.set_gRenderBufferDepth(offscreen); + mRS.bindRootScript(mScript); } } diff --git a/tests/RenderScriptTests/PerfTest/src/com/android/perftest/rsbench.rs b/tests/RenderScriptTests/PerfTest/src/com/android/perftest/rsbench.rs index 3c92725..fd0f16f 100644 --- a/tests/RenderScriptTests/PerfTest/src/com/android/perftest/rsbench.rs +++ b/tests/RenderScriptTests/PerfTest/src/com/android/perftest/rsbench.rs @@ -76,11 +76,17 @@ rs_program_vertex gProgVertexPixelLightMove; rs_program_fragment gProgFragmentPixelLight; rs_program_fragment gProgFragmentMultitex; +rs_allocation gRenderBufferColor; +rs_allocation gRenderBufferDepth; + float gDt = 0; void init() { } +static int gRenderSurfaceW; +static int gRenderSurfaceH; + static const char *sampleText = "This is a sample of small text for performace"; // Offsets for multiple layer of text static int textOffsets[] = { 0, 0, -5, -5, 5, 5, -8, -8, 8, 8}; @@ -91,6 +97,11 @@ static float textColors[] = {1.0f, 1.0f, 1.0f, 1.0f, 0.5f, 0.6f, 0.7f, 1.0f, }; +static void setupOffscreenTarget() { + rsgBindColorTarget(gRenderBufferColor, 0); + rsgBindDepthTarget(gRenderBufferDepth); +} + static void displayFontSamples(int fillNum) { rs_font fonts[5]; @@ -100,8 +111,8 @@ static void displayFontSamples(int fillNum) { rsSetObject(&fonts[3], gFontSerifBoldItalic); rsSetObject(&fonts[4], gFontSans); - uint width = rsgGetWidth(); - uint height = rsgGetHeight(); + uint width = gRenderSurfaceW; + uint height = gRenderSurfaceH; int left = 0, right = 0, top = 0, bottom = 0; rsgMeasureText(sampleText, &left, &right, &top, &bottom); @@ -136,7 +147,7 @@ static void bindProgramVertexOrtho() { rsgBindProgramVertex(gProgVertex); // Setup the projection matrix rs_matrix4x4 proj; - rsMatrixLoadOrtho(&proj, 0, rsgGetWidth(), rsgGetHeight(), 0, -500, 500); + rsMatrixLoadOrtho(&proj, 0, gRenderSurfaceW, gRenderSurfaceH, 0, -500, 500); rsgProgramVertexLoadProjectionMatrix(&proj); } @@ -158,7 +169,7 @@ static void displaySingletexFill(bool blend, int quadCount) { for (int i = 0; i < quadCount; i ++) { float startX = 10 * i, startY = 10 * i; - float width = rsgGetWidth() - startX, height = rsgGetHeight() - startY; + float width = gRenderSurfaceW - startX, height = gRenderSurfaceH - startY; rsgDrawQuadTexCoords(startX, startY, 0, 0, 0, startX, startY + height, 0, 0, 1, startX + width, startY + height, 0, 1, 1, @@ -216,7 +227,7 @@ static void displayMeshSamples(int meshNum) { bindProgramVertexOrtho(); rs_matrix4x4 matrix; - rsMatrixLoadTranslate(&matrix, rsgGetWidth()/2, rsgGetHeight()/2, 0); + rsMatrixLoadTranslate(&matrix, gRenderSurfaceW/2, gRenderSurfaceH/2, 0); rsgProgramVertexLoadModelMatrix(&matrix); // Fragment shader with texture @@ -344,7 +355,7 @@ static void displaySimpleGeoSamples(bool useTexture, int numMeshes) { rsgBindProgramRaster(gCullBack); // Setup the projection matrix with 30 degree field of view rs_matrix4x4 proj; - float aspect = (float)rsgGetWidth() / (float)rsgGetHeight(); + float aspect = (float)gRenderSurfaceW / (float)gRenderSurfaceH; rsMatrixLoadPerspective(&proj, 30.0f, aspect, 0.1f, 100.0f); rsgProgramVertexLoadProjectionMatrix(&proj); @@ -445,7 +456,7 @@ static void displayCustomShaderSamples(int numMeshes) { } // Setup the projection matrix - float aspect = (float)rsgGetWidth() / (float)rsgGetHeight(); + float aspect = (float)gRenderSurfaceW / (float)gRenderSurfaceH; rsMatrixLoadPerspective(&gVSConstants->proj, 30.0f, aspect, 0.1f, 100.0f); setupCustomShaderLights(); @@ -476,7 +487,7 @@ static void displayPixelLightSamples(int numMeshes, bool heavyVertex) { gVSConstPixel->time = rsUptimeMillis()*0.005; // Setup the projection matrix - float aspect = (float)rsgGetWidth() / (float)rsgGetHeight(); + float aspect = (float)gRenderSurfaceW / (float)gRenderSurfaceH; rsMatrixLoadPerspective(&gVSConstPixel->proj, 30.0f, aspect, 0.1f, 100.0f); setupCustomShaderLights(); @@ -520,7 +531,7 @@ static void displayMultitextureSample(bool blend, int quadCount) { for (int i = 0; i < quadCount; i ++) { float startX = 10 * i, startY = 10 * i; - float width = rsgGetWidth() - startX, height = rsgGetHeight() - startY; + float width = gRenderSurfaceW - startX, height = gRenderSurfaceH - startY; rsgDrawQuadTexCoords(startX, startY, 0, 0, 0, startX, startY + height, 0, 0, 1, startX + width, startY + height, 0, 1, 1, @@ -535,7 +546,7 @@ static void displayAnisoSample() { gAnisoTime += gDt; rsgBindProgramVertex(gProgVertex); - float aspect = (float)rsgGetWidth() / (float)rsgGetHeight(); + float aspect = (float)gRenderSurfaceW / (float)gRenderSurfaceH; rs_matrix4x4 proj; rsMatrixLoadPerspective(&proj, 30.0f, aspect, 0.1f, 100.0f); rsgProgramVertexLoadProjectionMatrix(&proj); @@ -592,10 +603,6 @@ static bool checkInit() { static int countdown = 5; - if (countdown == 0) { - gDt = 0; - countdown --; - } // Perform all the uploads so we only measure rendered time if(countdown > 1) { displayFontSamples(5); @@ -612,19 +619,13 @@ static bool checkInit() { countdown --; rsgClearColor(0.2f, 0.2f, 0.2f, 0.0f); - // Now use text metrics to center the text - uint width = rsgGetWidth(); - uint height = rsgGetHeight(); - int left = 0, right = 0, top = 0, bottom = 0; - rsgFontColor(0.9f, 0.9f, 0.95f, 1.0f); rsgBindFont(gFontSerifBoldItalic); - - const char* text = "Initializing"; - rsgMeasureText(text, &left, &right, &top, &bottom); - int centeredPosX = width / 2 - (right - left) / 2; - int centeredPosY = height / 2 - (top - bottom) / 2; - rsgDrawText(text, centeredPosX, centeredPosY); + if (countdown == 1) { + rsgDrawText("Rendering", 50, 50); + } else { + rsgDrawText("Initializing", 50, 50); + } return false; } @@ -632,70 +633,40 @@ static bool checkInit() { return true; } -static int frameCount = 0; -static int totalFramesRendered = 0; static int benchMode = 0; -#define testTime 5.0f -static float curTestTime = testTime; - static const char *testNames[] = { - "Finished text fill 1", - "Finished text fill 2", - "Finished text fill 3", - "Finished text fill 4", - "Finished text fill 5", - "Finished 25.6k geo flat color", - "Finished 51.2k geo flat color", - "Finished 204.8k geo raster load flat color", - "Finished 25.6k geo texture", - "Finished 51.2k geo texture", - "Finished 204.8k geo raster load texture", - "Finished full screen mesh 10 by 10", - "Finished full screen mesh 100 by 100", - "Finished full screen mesh W / 4 by H / 4", - "Finished 25.6k geo heavy vertex", - "Finished 51.2k geo heavy vertex", - "Finished 204.8k geo raster load heavy vertex", - "Finished singletexture 5x fill", - "Finished 3tex multitexture 5x fill", - "Finished blend singletexture 5x fill", - "Finished blend 3tex multitexture 5x fill", - "Finished 25.6k geo heavy fragment", - "Finished 51.2k geo heavy fragment", - "Finished 204.8k geo raster load heavy fragment", - "Finished 25.6k geo heavy fragment, heavy vertex", - "Finished 51.2k geo heavy fragment, heavy vertex", - "Finished 204.8k geo raster load heavy fragment, heavy vertex", + "Finished text fill 1,", + "Finished text fill 2,", + "Finished text fill 3,", + "Finished text fill 4,", + "Finished text fill 5,", + "Finished 25.6k geo flat color,", + "Finished 51.2k geo flat color,", + "Finished 204.8k geo raster load flat color,", + "Finished 25.6k geo texture,", + "Finished 51.2k geo texture,", + "Finished 204.8k geo raster load texture,", + "Finished full screen mesh 10 by 10,", + "Finished full screen mesh 100 by 100,", + "Finished full screen mesh W / 4 by H / 4,", + "Finished 25.6k geo heavy vertex,", + "Finished 51.2k geo heavy vertex,", + "Finished 204.8k geo raster load heavy vertex,", + "Finished singletexture 5x fill,", + "Finished 3tex multitexture 5x fill,", + "Finished blend singletexture 5x fill,", + "Finished blend 3tex multitexture 5x fill,", + "Finished 25.6k geo heavy fragment,", + "Finished 51.2k geo heavy fragment,", + "Finished 204.8k geo raster load heavy fragment,", + "Finished 25.6k geo heavy fragment heavy vertex,", + "Finished 51.2k geo heavy fragment heavy vertex,", + "Finished 204.8k geo raster load heavy fragment heavy vertex,", }; -int root(int launchID) { - - gDt = rsGetDt(); - - rsgClearColor(0.2f, 0.2f, 0.2f, 0.0f); - rsgClearDepth(1.0f); - - if(!checkInit()) { - return 1; - } - - curTestTime -= gDt; - if(curTestTime < 0.0f) { - float fps = (float)(frameCount) / (testTime - curTestTime); - rsDebug(testNames[benchMode], fps); - benchMode ++; - curTestTime = testTime; - totalFramesRendered += frameCount; - frameCount = 0; - gTorusRotation = 0; - - if (benchMode > gMaxModes) { - benchMode = 0; - } - } - - switch (benchMode) { +static void runTest(int index) { + switch (index) { case 0: displayFontSamples(1); break; @@ -777,10 +748,87 @@ int root(int launchID) { case 26: displayPixelLightSamples(8, true); break; + } +} + +static void drawOffscreenResult(int posX, int posY, int width, int height) { + bindProgramVertexOrtho(); + rs_matrix4x4 matrix; + rsMatrixLoadIdentity(&matrix); + rsgProgramVertexLoadModelMatrix(&matrix); + + rsgBindProgramFragment(gProgFragmentTexture); + + rsgBindSampler(gProgFragmentTexture, 0, gLinearClamp); + rsgBindTexture(gProgFragmentTexture, 0, gRenderBufferColor); + + float startX = posX, startY = posY; + rsgDrawQuadTexCoords(startX, startY, 0, 0, 1, + startX, startY + height, 0, 0, 0, + startX + width, startY + height, 0, 1, 0, + startX + width, startY, 0, 1, 1); +} + +int root(int launchID) { + + gRenderSurfaceW = rsgGetWidth(); + gRenderSurfaceH = rsgGetHeight(); + rsgClearColor(0.2f, 0.2f, 0.2f, 1.0f); + rsgClearDepth(1.0f); + if(!checkInit()) { + return 1; + } + + rsgFinish(); + int64_t start = rsUptimeMillis(); + rsGetDt(); + + int drawPos = 0; + int frameCount = 100; + for(int i = 0; i < frameCount; i ++) { + setupOffscreenTarget(); + gRenderSurfaceW = rsAllocationGetDimX(gRenderBufferColor); + gRenderSurfaceH = rsAllocationGetDimY(gRenderBufferColor); + rsgClearColor(0.1f, 0.1f, 0.1f, 1.0f); + rsgClearDepth(1.0f); + + runTest(benchMode); + rsgClearAllRenderTargets(); + gRenderSurfaceW = rsgGetWidth(); + gRenderSurfaceH = rsgGetHeight(); + int size = 8; + drawOffscreenResult((drawPos+=size)%gRenderSurfaceW, (gRenderSurfaceH * 3) / 4, size, size); + gDt = rsGetDt(); } - frameCount ++; + rsgFinish(); + + int64_t end = rsUptimeMillis(); + float fps = (float)(frameCount) / ((float)(end - start)*0.001f); + rsDebug(testNames[benchMode], fps); + + drawOffscreenResult(0, 0, + gRenderSurfaceW / 2, + gRenderSurfaceH / 2); + + const char* text = testNames[benchMode]; + int left = 0, right = 0, top = 0, bottom = 0; + uint width = rsgGetWidth(); + uint height = rsgGetHeight(); + rsgFontColor(0.9f, 0.9f, 0.95f, 1.0f); + rsgBindFont(gFontSerifBoldItalic); + rsgMeasureText(text, &left, &right, &top, &bottom); + rsgFontColor(1.0f, 1.0f, 1.0f, 1.0f); + rsgDrawText(text, 2 -left, height - 2 + bottom); + + benchMode ++; + + gTorusRotation = 0; + + if (benchMode > gMaxModes) { + benchMode = 0; + } return 1; } |