diff options
author | Alex Sakhartchouk <alexst@google.com> | 2011-07-01 10:04:22 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2011-07-01 10:04:22 -0700 |
commit | dd79d52e346ee70a42126e387cb71b80b0c56d4c (patch) | |
tree | 5b8b38419d35330d2e546c10b897dd3c15101fa6 /tests | |
parent | f17bd971036384d55529d819727dde843f69b49c (diff) | |
parent | 46bd32ece2e6ae5ae95ac47dacf2801322d156e9 (diff) | |
download | frameworks_base-dd79d52e346ee70a42126e387cb71b80b0c56d4c.zip frameworks_base-dd79d52e346ee70a42126e387cb71b80b0c56d4c.tar.gz frameworks_base-dd79d52e346ee70a42126e387cb71b80b0c56d4c.tar.bz2 |
Merge "Adding some debug modes to the rs benchmark app."
Diffstat (limited to 'tests')
10 files changed, 632 insertions, 313 deletions
diff --git a/tests/RenderScriptTests/PerfTest/AndroidManifest.xml b/tests/RenderScriptTests/PerfTest/AndroidManifest.xml index aafd176..cc60396 100644 --- a/tests/RenderScriptTests/PerfTest/AndroidManifest.xml +++ b/tests/RenderScriptTests/PerfTest/AndroidManifest.xml @@ -9,8 +9,7 @@ android:icon="@drawable/test_pattern"> <uses-library android:name="android.test.runner" /> <activity android:name="RsBench" - android:label="RsBenchmark" - android:theme="@android:style/Theme.Black.NoTitleBar"> + android:label="RsBenchmark"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> diff --git a/tests/RenderScriptTests/PerfTest/res/menu/loader_menu.xml b/tests/RenderScriptTests/PerfTest/res/menu/loader_menu.xml new file mode 100644 index 0000000..8234677 --- /dev/null +++ b/tests/RenderScriptTests/PerfTest/res/menu/loader_menu.xml @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +--> + +<menu xmlns:android="http://schemas.android.com/apk/res/android"> + <item android:id="@+id/benchmark_mode" + android:title="@string/benchmark_mode" /> + <item android:id="@+id/debug_mode" + android:title="@string/debug_mode" /> +</menu> diff --git a/tests/RenderScriptTests/PerfTest/res/values/strings.xml b/tests/RenderScriptTests/PerfTest/res/values/strings.xml new file mode 100644 index 0000000..627ac21 --- /dev/null +++ b/tests/RenderScriptTests/PerfTest/res/values/strings.xml @@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +--> + +<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> + <skip /> + <string name="benchmark_mode">Benchmark Mode</string> + <string name="debug_mode">Debug Mode</string> +</resources> diff --git a/tests/RenderScriptTests/PerfTest/src/com/android/perftest/RsBench.java b/tests/RenderScriptTests/PerfTest/src/com/android/perftest/RsBench.java index d7393f8..b336a4d 100644 --- a/tests/RenderScriptTests/PerfTest/src/com/android/perftest/RsBench.java +++ b/tests/RenderScriptTests/PerfTest/src/com/android/perftest/RsBench.java @@ -31,10 +31,14 @@ import android.provider.Settings.System; import android.util.Log; import android.view.Menu; import android.view.MenuItem; +import android.view.MenuInflater; import android.view.View; import android.view.Window; import android.widget.Button; import android.widget.ListView; +import android.app.AlertDialog; +import android.content.DialogInterface; +import android.widget.Toast; import java.lang.Runtime; @@ -77,4 +81,37 @@ public class RsBench extends Activity { super.onPause(); mView.pause(); } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + MenuInflater inflater = getMenuInflater(); + inflater.inflate(R.menu.loader_menu, menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + // Handle item selection + switch (item.getItemId()) { + case R.id.benchmark_mode: + mView.setBenchmarkMode(); + return true; + case R.id.debug_mode: + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setTitle("Pick a Test"); + builder.setItems(mView.getTestNames(), + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int item) { + Toast.makeText(getApplicationContext(), + "Switching to: " + mView.getTestNames()[item], + Toast.LENGTH_SHORT).show(); + mView.setDebugMode(item); + } + }); + builder.show(); + return true; + default: + return super.onOptionsItemSelected(item); + } + } } diff --git a/tests/RenderScriptTests/PerfTest/src/com/android/perftest/RsBenchRS.java b/tests/RenderScriptTests/PerfTest/src/com/android/perftest/RsBenchRS.java index c706286..c375be5 100644 --- a/tests/RenderScriptTests/PerfTest/src/com/android/perftest/RsBenchRS.java +++ b/tests/RenderScriptTests/PerfTest/src/com/android/perftest/RsBenchRS.java @@ -84,12 +84,6 @@ public class RsBenchRS { private Resources mRes; private RenderScriptGL mRS; - private Sampler mLinearClamp; - private Sampler mLinearWrap; - private Sampler mMipLinearWrap; - private Sampler mNearestClamp; - private Sampler mNearesWrap; - private ProgramStore mProgStoreBlendNoneDepth; private ProgramStore mProgStoreBlendNone; private ProgramStore mProgStoreBlendAlpha; @@ -115,10 +109,6 @@ public class RsBenchRS { private ScriptField_FragentShaderConstants3_s mFSConstPixel; - private ProgramRaster mCullBack; - private ProgramRaster mCullFront; - private ProgramRaster mCullNone; - private Allocation mTexTorus; private Allocation mTexOpaque; private Allocation mTexTransparent; @@ -143,6 +133,8 @@ public class RsBenchRS { private ScriptC_rsbench mScript; + private ScriptC_text_test mTextScript; + private ScriptC_torus_test mTorusScript; private final BitmapFactory.Options mOptionsARGB = new BitmapFactory.Options(); @@ -310,6 +302,7 @@ public class RsBenchRS { mProgStoreBlendAdd = BLEND_ADD_DEPTH_NONE(mRS); mScript.set_gProgStoreBlendNoneDepth(mProgStoreBlendNoneDepth); + mScript.set_gProgStoreBlendNone(mProgStoreBlendNone); mScript.set_gProgStoreBlendAlpha(mProgStoreBlendAlpha); mScript.set_gProgStoreBlendAdd(mProgStoreBlendAdd); @@ -330,22 +323,24 @@ public class RsBenchRS { texBuilder.setTexture(ProgramFragmentFixedFunction.Builder.EnvMode.REPLACE, ProgramFragmentFixedFunction.Builder.Format.RGBA, 0); mProgFragmentTexture = texBuilder.create(); - mProgFragmentTexture.bindSampler(mLinearClamp, 0); + mProgFragmentTexture.bindSampler(Sampler.CLAMP_LINEAR(mRS), 0); ProgramFragmentFixedFunction.Builder colBuilder = new ProgramFragmentFixedFunction.Builder(mRS); colBuilder.setVaryingColor(false); mProgFragmentColor = colBuilder.create(); mScript.set_gProgFragmentColor(mProgFragmentColor); + mScript.set_gProgFragmentTexture(mProgFragmentTexture); + // For Galaxy live wallpaper drawing ProgramFragmentFixedFunction.Builder builder = new ProgramFragmentFixedFunction.Builder(mRS); builder.setTexture(ProgramFragmentFixedFunction.Builder.EnvMode.REPLACE, ProgramFragmentFixedFunction.Builder.Format.RGB, 0); ProgramFragment pfb = builder.create(); - pfb.bindSampler(mNearesWrap, 0); + pfb.bindSampler(Sampler.WRAP_NEAREST(mRS), 0); mScript.set_gPFBackground(pfb); builder = new ProgramFragmentFixedFunction.Builder(mRS); @@ -354,7 +349,7 @@ public class RsBenchRS { ProgramFragmentFixedFunction.Builder.Format.RGBA, 0); builder.setVaryingColor(true); ProgramFragment pfs = builder.create(); - pfs.bindSampler(mMipLinearWrap, 0); + pfs.bindSampler(Sampler.WRAP_LINEAR_MIP_LINEAR(mRS), 0); mScript.set_gPFStars(pfs); } @@ -404,6 +399,7 @@ public class RsBenchRS { mScript.set_gProgVertex(mProgVertex); + // For galaxy live wallpaper mPvStarAlloc = new ScriptField_VpConsts(mRS, 1); mScript.bind_vpConstants(mPvStarAlloc); @@ -447,13 +443,11 @@ public class RsBenchRS { private void initCustomShaders() { mVSConst = new ScriptField_VertexShaderConstants_s(mRS, 1); mFSConst = new ScriptField_FragentShaderConstants_s(mRS, 1); - mScript.bind_gVSConstants(mVSConst); - mScript.bind_gFSConstants(mFSConst); + mVSConstPixel = new ScriptField_VertexShaderConstants3_s(mRS, 1); mFSConstPixel = new ScriptField_FragentShaderConstants3_s(mRS, 1); - mScript.bind_gVSConstPixel(mVSConstPixel); - mScript.bind_gFSConstPixel(mFSConstPixel); + // Initialize the shader builder ProgramVertex.Builder pvbCustom = new ProgramVertex.Builder(mRS); @@ -506,11 +500,7 @@ public class RsBenchRS { } mProgFragmentMultitex = pfbCustom.create(); - mScript.set_gProgVertexCustom(mProgVertexCustom); - mScript.set_gProgFragmentCustom(mProgFragmentCustom); - mScript.set_gProgVertexPixelLight(mProgVertexPixelLight); - mScript.set_gProgVertexPixelLightMove(mProgVertexPixelLightMove); - mScript.set_gProgFragmentPixelLight(mProgFragmentPixelLight); + mScript.set_gProgFragmentMultitex(mProgFragmentMultitex); } @@ -587,39 +577,22 @@ public class RsBenchRS { Log.e("rs", "could not load model"); } else { mTorus = (Mesh)entry.getObject(); - mScript.set_gTorusMesh(mTorus); } createParticlesMesh(); } private void initSamplers() { - Sampler.Builder bs = new Sampler.Builder(mRS); - bs.setMinification(Sampler.Value.LINEAR); - bs.setMagnification(Sampler.Value.LINEAR); - bs.setWrapS(Sampler.Value.WRAP); - bs.setWrapT(Sampler.Value.WRAP); - mLinearWrap = bs.create(); - - mLinearClamp = Sampler.CLAMP_LINEAR(mRS); - mNearestClamp = Sampler.CLAMP_NEAREST(mRS); - mMipLinearWrap = Sampler.WRAP_LINEAR_MIP_LINEAR(mRS); - mNearesWrap = Sampler.WRAP_NEAREST(mRS); - - mScript.set_gLinearClamp(mLinearClamp); - mScript.set_gLinearWrap(mLinearWrap); - mScript.set_gMipLinearWrap(mMipLinearWrap); - mScript.set_gNearestClamp(mNearestClamp); + mScript.set_gLinearClamp(Sampler.CLAMP_LINEAR(mRS)); + mScript.set_gLinearWrap(Sampler.WRAP_LINEAR(mRS)); + mScript.set_gMipLinearWrap(Sampler.WRAP_LINEAR_MIP_LINEAR(mRS)); + mScript.set_gNearestClamp(Sampler.CLAMP_NEAREST(mRS)); } private void initProgramRaster() { - mCullBack = ProgramRaster.CULL_BACK(mRS); - mCullFront = ProgramRaster.CULL_FRONT(mRS); - mCullNone = ProgramRaster.CULL_NONE(mRS); - - mScript.set_gCullBack(mCullBack); - mScript.set_gCullFront(mCullFront); - mScript.set_gCullNone(mCullNone); + mScript.set_gCullBack(ProgramRaster.CULL_BACK(mRS)); + mScript.set_gCullFront(ProgramRaster.CULL_FRONT(mRS)); + mScript.set_gCullNone(ProgramRaster.CULL_NONE(mRS)); } private int strlen(byte[] array) { @@ -645,9 +618,47 @@ public class RsBenchRS { } } + public void setDebugMode(int num) { + mScript.invoke_setDebugMode(num); + } + + public void setBenchmarkMode() { + mScript.invoke_setBenchmarkMode(); + } + + void initTextScript() { + mTextScript = new ScriptC_text_test(mRS, mRes, R.raw.text_test); + mTextScript.set_gFontSans(mFontSans); + mTextScript.set_gFontSerif(mFontSerif); + } + + void initTorusScript() { + mTorusScript = new ScriptC_torus_test(mRS, mRes, R.raw.torus_test); + mTorusScript.set_gCullFront(ProgramRaster.CULL_FRONT(mRS)); + mTorusScript.set_gCullBack(ProgramRaster.CULL_BACK(mRS)); + mTorusScript.set_gLinearClamp(Sampler.CLAMP_LINEAR(mRS)); + mTorusScript.set_gTorusMesh(mTorus); + mTorusScript.set_gTexTorus(mTexTorus); + mTorusScript.set_gProgVertexCustom(mProgVertexCustom); + mTorusScript.set_gProgFragmentCustom(mProgFragmentCustom); + mTorusScript.set_gProgVertexPixelLight(mProgVertexPixelLight); + mTorusScript.set_gProgVertexPixelLightMove(mProgVertexPixelLightMove); + mTorusScript.set_gProgFragmentPixelLight(mProgFragmentPixelLight); + mTorusScript.bind_gVSConstPixel(mVSConstPixel); + mTorusScript.bind_gFSConstPixel(mFSConstPixel); + mTorusScript.bind_gVSConstants(mVSConst); + mTorusScript.bind_gFSConstants(mFSConst); + mTorusScript.set_gProgVertex(mProgVertex); + mTorusScript.set_gProgFragmentTexture(mProgFragmentTexture); + mTorusScript.set_gProgFragmentColor(mProgFragmentColor); + mTorusScript.set_gProgStoreBlendNoneDepth(mProgStoreBlendNoneDepth); + } + private void initRS() { mScript = new ScriptC_rsbench(mRS, mRes, R.raw.rsbench); + + mRS.setMessageHandler(mRsMessage); mMaxModes = mScript.get_gMaxModes(); @@ -709,6 +720,13 @@ public class RsBenchRS { mSampleListViewAllocs.copyAll(); mScript.bind_gListViewText(mSampleListViewAllocs); + initTextScript(); + initTorusScript(); + + mScript.set_gFontScript(mTextScript); + mScript.set_gTorusScript(mTorusScript); + mScript.set_gDummyAlloc(Allocation.createSized(mRS, Element.I32(mRS), 1)); + mRS.bindRootScript(mScript); } } diff --git a/tests/RenderScriptTests/PerfTest/src/com/android/perftest/RsBenchView.java b/tests/RenderScriptTests/PerfTest/src/com/android/perftest/RsBenchView.java index 2882b93..61aa3e1 100644 --- a/tests/RenderScriptTests/PerfTest/src/com/android/perftest/RsBenchView.java +++ b/tests/RenderScriptTests/PerfTest/src/com/android/perftest/RsBenchView.java @@ -105,4 +105,16 @@ public class RsBenchView extends RSSurfaceView { public boolean testIsFinished() { return mRender.testIsFinished(); } + + void setBenchmarkMode() { + mRender.setBenchmarkMode(); + } + + void setDebugMode(int num) { + mRender.setDebugMode(num); + } + + String[] getTestNames() { + return mRender.mTestNames; + } } diff --git a/tests/RenderScriptTests/PerfTest/src/com/android/perftest/rsbench.rs b/tests/RenderScriptTests/PerfTest/src/com/android/perftest/rsbench.rs index bb81862..eaafe1d 100644 --- a/tests/RenderScriptTests/PerfTest/src/com/android/perftest/rsbench.rs +++ b/tests/RenderScriptTests/PerfTest/src/com/android/perftest/rsbench.rs @@ -18,6 +18,7 @@ #include "rs_graphics.rsh" #include "shader_def.rsh" +#include "subtest_def.rsh" /* Message sent from script to renderscript */ const int RS_MSG_TEST_DONE = 100; @@ -98,7 +99,6 @@ ListAllocs *gListViewText; rs_mesh g10by10Mesh; rs_mesh g100by100Mesh; rs_mesh gWbyHMesh; -rs_mesh gTorusMesh; rs_mesh gSingleMesh; rs_font gFontSans; @@ -115,25 +115,15 @@ rs_program_raster gCullBack; rs_program_raster gCullFront; rs_program_raster gCullNone; -// Custom vertex shader compunents -VertexShaderConstants *gVSConstants; -FragentShaderConstants *gFSConstants; -VertexShaderConstants3 *gVSConstPixel; -FragentShaderConstants3 *gFSConstPixel; // Export these out to easily set the inputs to shader VertexShaderInputs *gVSInputs; -// Custom shaders we use for lighting -rs_program_vertex gProgVertexCustom; -rs_program_fragment gProgFragmentCustom; -rs_program_vertex gProgVertexPixelLight; -rs_program_vertex gProgVertexPixelLightMove; -rs_program_fragment gProgFragmentPixelLight; + rs_program_fragment gProgFragmentMultitex; rs_allocation gRenderBufferColor; rs_allocation gRenderBufferDepth; -float gDt = 0; +static float gDt = 0; void init() { } @@ -141,16 +131,6 @@ 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}; -static float textColors[] = {1.0f, 1.0f, 1.0f, 1.0f, - 0.5f, 0.7f, 0.5f, 1.0f, - 0.7f, 0.5f, 0.5f, 1.0f, - 0.5f, 0.5f, 0.7f, 1.0f, - 0.5f, 0.6f, 0.7f, 1.0f, -}; - /** * Methods to draw the galaxy live wall paper */ @@ -291,40 +271,16 @@ static void setupOffscreenTarget() { rsgBindDepthTarget(gRenderBufferDepth); } -static void displayFontSamples(int fillNum) { +rs_script gFontScript; +rs_script gTorusScript; +rs_allocation gDummyAlloc; - rs_font fonts[5]; - fonts[0] = gFontSans; - fonts[1] = gFontSerif; - fonts[2] = gFontSans; - fonts[3] = gFontSerif; - fonts[4] = gFontSans; - - uint width = gRenderSurfaceW; - uint height = gRenderSurfaceH; - int left = 0, right = 0, top = 0, bottom = 0; - rsgMeasureText(sampleText, &left, &right, &top, &bottom); - - int textHeight = top - bottom; - int textWidth = right - left; - int numVerticalLines = height / textHeight; - int yPos = top; - - int xOffset = 0, yOffset = 0; - for(int fillI = 0; fillI < fillNum; fillI ++) { - rsgBindFont(fonts[fillI]); - xOffset = textOffsets[fillI * 2]; - yOffset = textOffsets[fillI * 2 + 1]; - float *colPtr = textColors + fillI * 4; - rsgFontColor(colPtr[0], colPtr[1], colPtr[2], colPtr[3]); - for (int h = 0; h < 4; h ++) { - yPos = top + yOffset; - for (int v = 0; v < numVerticalLines; v ++) { - rsgDrawText(sampleText, xOffset + textWidth * h, yPos); - yPos += textHeight; - } - } - } +static void displayFontSamples(int fillNum) { + TestData testData; + testData.renderSurfaceW = gRenderSurfaceW; + testData.renderSurfaceH = gRenderSurfaceH; + testData.user = fillNum; + rsForEach(gFontScript, gDummyAlloc, gDummyAlloc, &testData); } static void bindProgramVertexOrtho() { @@ -555,212 +511,37 @@ static void displayLiveWallPaper(int wResolution, int hResolution) { drawMeshInPage(2.0f*gRenderSurfaceW, 0, wResolution, hResolution); } -static float gTorusRotation = 0; -static void updateModelMatrix(rs_matrix4x4 *matrix, void *buffer) { - if (buffer == 0) { - rsgProgramVertexLoadModelMatrix(matrix); - } else { - rsgAllocationSyncAll(rsGetAllocation(buffer)); - } -} - -static void drawToruses(int numMeshes, rs_matrix4x4 *matrix, void *buffer) { - - if (numMeshes == 1) { - rsMatrixLoadTranslate(matrix, 0.0f, 0.0f, -7.5f); - rsMatrixRotate(matrix, gTorusRotation, 1.0f, 0.0f, 0.0f); - updateModelMatrix(matrix, buffer); - rsgDrawMesh(gTorusMesh); - return; - } - - if (numMeshes == 2) { - rsMatrixLoadTranslate(matrix, -1.6f, 0.0f, -7.5f); - rsMatrixRotate(matrix, gTorusRotation, 1.0f, 0.0f, 0.0f); - updateModelMatrix(matrix, buffer); - rsgDrawMesh(gTorusMesh); - - rsMatrixLoadTranslate(matrix, 1.6f, 0.0f, -7.5f); - rsMatrixRotate(matrix, gTorusRotation, 1.0f, 0.0f, 0.0f); - updateModelMatrix(matrix, buffer); - rsgDrawMesh(gTorusMesh); - return; - } - - float startX = -5.0f; - float startY = -1.5f; - float startZ = -15.0f; - float dist = 3.2f; - - for (int h = 0; h < 4; h ++) { - for (int v = 0; v < 2; v ++) { - // Position our model on the screen - rsMatrixLoadTranslate(matrix, startX + dist * h, startY + dist * v, startZ); - rsMatrixRotate(matrix, gTorusRotation, 1.0f, 0.0f, 0.0f); - updateModelMatrix(matrix, buffer); - rsgDrawMesh(gTorusMesh); - } - } -} - // Quick hack to get some geometry numbers static void displaySimpleGeoSamples(bool useTexture, int numMeshes) { - rsgBindProgramVertex(gProgVertex); - rsgBindProgramRaster(gCullBack); - // Setup the projection matrix with 30 degree field of view - rs_matrix4x4 proj; - float aspect = (float)gRenderSurfaceW / (float)gRenderSurfaceH; - rsMatrixLoadPerspective(&proj, 30.0f, aspect, 0.1f, 100.0f); - rsgProgramVertexLoadProjectionMatrix(&proj); - - // Fragment shader with texture - rsgBindProgramStore(gProgStoreBlendNoneDepth); - if (useTexture) { - rsgBindProgramFragment(gProgFragmentTexture); - } else { - rsgBindProgramFragment(gProgFragmentColor); - rsgProgramFragmentConstantColor(gProgFragmentColor, 0.1, 0.7, 0.1, 1); - } - rsgBindSampler(gProgFragmentTexture, 0, gLinearClamp); - rsgBindTexture(gProgFragmentTexture, 0, gTexTorus); - - // Apply a rotation to our mesh - gTorusRotation += 50.0f * gDt; - if (gTorusRotation > 360.0f) { - gTorusRotation -= 360.0f; - } - - rs_matrix4x4 matrix; - drawToruses(numMeshes, &matrix, 0); -} - -float gLight0Rotation = 0; -float gLight1Rotation = 0; - -static void setupCustomShaderLights() { - float4 light0Pos = {-5.0f, 5.0f, -10.0f, 1.0f}; - float4 light1Pos = {2.0f, 5.0f, 15.0f, 1.0f}; - float4 light0DiffCol = {0.9f, 0.7f, 0.7f, 1.0f}; - float4 light0SpecCol = {0.9f, 0.6f, 0.6f, 1.0f}; - float4 light1DiffCol = {0.5f, 0.5f, 0.9f, 1.0f}; - float4 light1SpecCol = {0.5f, 0.5f, 0.9f, 1.0f}; - - gLight0Rotation += 50.0f * gDt; - if (gLight0Rotation > 360.0f) { - gLight0Rotation -= 360.0f; - } - gLight1Rotation -= 50.0f * gDt; - if (gLight1Rotation > 360.0f) { - gLight1Rotation -= 360.0f; - } - - rs_matrix4x4 l0Mat; - rsMatrixLoadRotate(&l0Mat, gLight0Rotation, 1.0f, 0.0f, 0.0f); - light0Pos = rsMatrixMultiply(&l0Mat, light0Pos); - rs_matrix4x4 l1Mat; - rsMatrixLoadRotate(&l1Mat, gLight1Rotation, 0.0f, 0.0f, 1.0f); - light1Pos = rsMatrixMultiply(&l1Mat, light1Pos); - - // Set light 0 properties - gVSConstants->light0_Posision = light0Pos; - gVSConstants->light0_Diffuse = 1.0f; - gVSConstants->light0_Specular = 0.5f; - gVSConstants->light0_CosinePower = 10.0f; - // Set light 1 properties - gVSConstants->light1_Posision = light1Pos; - gVSConstants->light1_Diffuse = 1.0f; - gVSConstants->light1_Specular = 0.7f; - gVSConstants->light1_CosinePower = 25.0f; - rsgAllocationSyncAll(rsGetAllocation(gVSConstants)); - - // Update fragment shader constants - // Set light 0 colors - gFSConstants->light0_DiffuseColor = light0DiffCol; - gFSConstants->light0_SpecularColor = light0SpecCol; - // Set light 1 colors - gFSConstants->light1_DiffuseColor = light1DiffCol; - gFSConstants->light1_SpecularColor = light1SpecCol; - rsgAllocationSyncAll(rsGetAllocation(gFSConstants)); - - // Set light 0 properties for per pixel lighting - gFSConstPixel->light0_Posision = light0Pos; - gFSConstPixel->light0_Diffuse = 1.0f; - gFSConstPixel->light0_Specular = 0.5f; - gFSConstPixel->light0_CosinePower = 10.0f; - gFSConstPixel->light0_DiffuseColor = light0DiffCol; - gFSConstPixel->light0_SpecularColor = light0SpecCol; - // Set light 1 properties - gFSConstPixel->light1_Posision = light1Pos; - gFSConstPixel->light1_Diffuse = 1.0f; - gFSConstPixel->light1_Specular = 0.7f; - gFSConstPixel->light1_CosinePower = 25.0f; - gFSConstPixel->light1_DiffuseColor = light1DiffCol; - gFSConstPixel->light1_SpecularColor = light1SpecCol; - rsgAllocationSyncAll(rsGetAllocation(gFSConstPixel)); + TestData testData; + testData.renderSurfaceW = gRenderSurfaceW; + testData.renderSurfaceH = gRenderSurfaceH; + testData.dt = gDt; + testData.user = 0; + testData.user1 = useTexture ? 1 : 0; + testData.user2 = numMeshes; + rsForEach(gTorusScript, gDummyAlloc, gDummyAlloc, &testData); } static void displayCustomShaderSamples(int numMeshes) { - - // Update vertex shader constants - // Load model matrix - // Apply a rotation to our mesh - gTorusRotation += 50.0f * gDt; - if (gTorusRotation > 360.0f) { - gTorusRotation -= 360.0f; - } - - // Setup the projection matrix - float aspect = (float)gRenderSurfaceW / (float)gRenderSurfaceH; - rsMatrixLoadPerspective(&gVSConstants->proj, 30.0f, aspect, 0.1f, 100.0f); - setupCustomShaderLights(); - - rsgBindProgramVertex(gProgVertexCustom); - - // Fragment shader with texture - rsgBindProgramStore(gProgStoreBlendNoneDepth); - rsgBindProgramFragment(gProgFragmentCustom); - rsgBindSampler(gProgFragmentCustom, 0, gLinearClamp); - rsgBindTexture(gProgFragmentCustom, 0, gTexTorus); - - // Use back face culling - rsgBindProgramRaster(gCullBack); - - drawToruses(numMeshes, &gVSConstants->model, gVSConstants); + TestData testData; + testData.renderSurfaceW = gRenderSurfaceW; + testData.renderSurfaceH = gRenderSurfaceH; + testData.dt = gDt; + testData.user = 1; + testData.user1 = numMeshes; + rsForEach(gTorusScript, gDummyAlloc, gDummyAlloc, &testData); } static void displayPixelLightSamples(int numMeshes, bool heavyVertex) { - - // Update vertex shader constants - // Load model matrix - // Apply a rotation to our mesh - gTorusRotation += 30.0f * gDt; - if (gTorusRotation > 360.0f) { - gTorusRotation -= 360.0f; - } - - gVSConstPixel->time = rsUptimeMillis()*0.005; - - // Setup the projection matrix - float aspect = (float)gRenderSurfaceW / (float)gRenderSurfaceH; - rsMatrixLoadPerspective(&gVSConstPixel->proj, 30.0f, aspect, 0.1f, 100.0f); - setupCustomShaderLights(); - - if (heavyVertex) { - rsgBindProgramVertex(gProgVertexPixelLightMove); - } else { - rsgBindProgramVertex(gProgVertexPixelLight); - } - - // Fragment shader with texture - rsgBindProgramStore(gProgStoreBlendNoneDepth); - rsgBindProgramFragment(gProgFragmentPixelLight); - rsgBindSampler(gProgFragmentPixelLight, 0, gLinearClamp); - rsgBindTexture(gProgFragmentPixelLight, 0, gTexTorus); - - // Use back face culling - rsgBindProgramRaster(gCullBack); - - drawToruses(numMeshes, &gVSConstPixel->model, gVSConstPixel); + TestData testData; + testData.renderSurfaceW = gRenderSurfaceW; + testData.renderSurfaceH = gRenderSurfaceH; + testData.dt = gDt; + testData.user = 2; + testData.user1 = numMeshes; + testData.user2 = heavyVertex ? 1 : 0; + rsForEach(gTorusScript, gDummyAlloc, gDummyAlloc, &testData); } static void displayMultitextureSample(bool blend, int quadCount) { @@ -862,6 +643,20 @@ static const char *testNames[] = { "UI test with live wallpaper", }; +static bool gIsDebugMode = false; +void setDebugMode(int testNumber) { + gIsDebugMode = true; + benchMode = testNumber; + rsgClearAllRenderTargets(); +} + +void setBenchmarkMode() { + gIsDebugMode = false; + benchMode = 0; + runningLoops = 0; +} + + void getTestName(int testIndex) { int bufferLen = rsAllocationGetDimX(rsGetAllocation(gStringBuffer)); if (testIndex >= gMaxModes) { @@ -932,7 +727,7 @@ static void runTest(int index) { displaySingletexFill(true, 10); break; case 18: - displayMultitextureSample(true, 8); + displayMultitextureSample(true, 10); break; case 19: displayPixelLightSamples(1, false); @@ -992,14 +787,7 @@ static void drawOffscreenResult(int posX, int posY, int width, int height) { startX + width, startY, 0, 1, 1); } -int root(void) { - gRenderSurfaceW = rsgGetWidth(); - gRenderSurfaceH = rsgGetHeight(); - rsgClearColor(0.2f, 0.2f, 0.2f, 1.0f); - rsgClearDepth(1.0f); - if(!checkInit()) { - return 1; - } +static void benchmark() { gDt = 1.0f / 60.0f; @@ -1045,8 +833,6 @@ int root(void) { benchMode ++; - gTorusRotation = 0; - if (benchMode == gMaxModes) { rsSendToClientBlocking(RS_MSG_RESULTS_READY, gResultBuffer, gMaxModes*sizeof(float)); benchMode = 0; @@ -1058,5 +844,30 @@ int root(void) { sendMsgFlag = true; } } + +} + +static void debug() { + gDt = rsGetDt(); + + rsgFinish(); + runTest(benchMode); +} + +int root(void) { + gRenderSurfaceW = rsgGetWidth(); + gRenderSurfaceH = rsgGetHeight(); + rsgClearColor(0.2f, 0.2f, 0.2f, 1.0f); + rsgClearDepth(1.0f); + if(!checkInit()) { + return 1; + } + + if (gIsDebugMode) { + debug(); + } else { + benchmark(); + } + return 1; } diff --git a/tests/RenderScriptTests/PerfTest/src/com/android/perftest/subtest_def.rsh b/tests/RenderScriptTests/PerfTest/src/com/android/perftest/subtest_def.rsh new file mode 100644 index 0000000..b635373 --- /dev/null +++ b/tests/RenderScriptTests/PerfTest/src/com/android/perftest/subtest_def.rsh @@ -0,0 +1,28 @@ +// Copyright (C) 2011 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma version(1) + +#pragma rs java_package_name(com.android.perftest) + +typedef struct TestData_s { + int renderSurfaceW; + int renderSurfaceH; + float dt; + int user; + int user1; + int user2; + int user3; +} TestData; + diff --git a/tests/RenderScriptTests/PerfTest/src/com/android/perftest/text_test.rs b/tests/RenderScriptTests/PerfTest/src/com/android/perftest/text_test.rs new file mode 100644 index 0000000..0df6b35 --- /dev/null +++ b/tests/RenderScriptTests/PerfTest/src/com/android/perftest/text_test.rs @@ -0,0 +1,82 @@ +// Copyright (C) 2011 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma version(1) + +#pragma rs java_package_name(com.android.perftest) + +#include "rs_graphics.rsh" +#include "subtest_def.rsh" + +rs_font gFontSans; +rs_font gFontSerif; + +void init() { +} + +static int gRenderSurfaceW = 1280; +static int gRenderSurfaceH = 720; + +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}; +static float textColors[] = {1.0f, 1.0f, 1.0f, 1.0f, + 0.5f, 0.7f, 0.5f, 1.0f, + 0.7f, 0.5f, 0.5f, 1.0f, + 0.5f, 0.5f, 0.7f, 1.0f, + 0.5f, 0.6f, 0.7f, 1.0f, +}; + +static void displayFontSamples(int fillNum) { + + rs_font fonts[5]; + fonts[0] = gFontSans; + fonts[1] = gFontSerif; + fonts[2] = gFontSans; + fonts[3] = gFontSerif; + fonts[4] = gFontSans; + + uint width = gRenderSurfaceW; + uint height = gRenderSurfaceH; + int left = 0, right = 0, top = 0, bottom = 0; + rsgMeasureText(sampleText, &left, &right, &top, &bottom); + + int textHeight = top - bottom; + int textWidth = right - left; + int numVerticalLines = height / textHeight; + int yPos = top; + + int xOffset = 0, yOffset = 0; + for(int fillI = 0; fillI < fillNum; fillI ++) { + rsgBindFont(fonts[fillI]); + xOffset = textOffsets[fillI * 2]; + yOffset = textOffsets[fillI * 2 + 1]; + float *colPtr = textColors + fillI * 4; + rsgFontColor(colPtr[0], colPtr[1], colPtr[2], colPtr[3]); + for (int h = 0; h < 4; h ++) { + yPos = top + yOffset; + for (int v = 0; v < numVerticalLines; v ++) { + rsgDrawText(sampleText, xOffset + textWidth * h, yPos); + yPos += textHeight; + } + } + } +} + +void root(const void *v_in, void *v_out, const void *usrData, uint32_t x, uint32_t y) { + TestData *testData = (TestData*)usrData; + gRenderSurfaceW = testData->renderSurfaceW; + gRenderSurfaceH = testData->renderSurfaceH; + displayFontSamples(testData->user); +} diff --git a/tests/RenderScriptTests/PerfTest/src/com/android/perftest/torus_test.rs b/tests/RenderScriptTests/PerfTest/src/com/android/perftest/torus_test.rs new file mode 100644 index 0000000..26d5680 --- /dev/null +++ b/tests/RenderScriptTests/PerfTest/src/com/android/perftest/torus_test.rs @@ -0,0 +1,283 @@ +// Copyright (C) 2011 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma version(1) + +#pragma rs java_package_name(com.android.perftest) + +#include "rs_graphics.rsh" +#include "subtest_def.rsh" +#include "shader_def.rsh" + +rs_program_vertex gProgVertex; +rs_program_fragment gProgFragmentColor; +rs_program_fragment gProgFragmentTexture; + +rs_program_store gProgStoreBlendNoneDepth; +rs_mesh gTorusMesh; + +rs_program_raster gCullBack; +rs_program_raster gCullFront; + +// Custom vertex shader compunents +VertexShaderConstants *gVSConstants; +FragentShaderConstants *gFSConstants; +VertexShaderConstants3 *gVSConstPixel; +FragentShaderConstants3 *gFSConstPixel; + +// Custom shaders we use for lighting +rs_program_vertex gProgVertexCustom; +rs_program_fragment gProgFragmentCustom; + +rs_sampler gLinearClamp; +rs_allocation gTexTorus; + +rs_program_vertex gProgVertexPixelLight; +rs_program_vertex gProgVertexPixelLightMove; +rs_program_fragment gProgFragmentPixelLight; + +static float gDt = 0.0f; + +static int gRenderSurfaceW; +static int gRenderSurfaceH; + + +static float gTorusRotation = 0; +static void updateModelMatrix(rs_matrix4x4 *matrix, void *buffer) { + if (buffer == 0) { + rsgProgramVertexLoadModelMatrix(matrix); + } else { + rsgAllocationSyncAll(rsGetAllocation(buffer)); + } +} + +static void drawToruses(int numMeshes, rs_matrix4x4 *matrix, void *buffer) { + + if (numMeshes == 1) { + rsMatrixLoadTranslate(matrix, 0.0f, 0.0f, -7.5f); + rsMatrixRotate(matrix, gTorusRotation, 1.0f, 0.0f, 0.0f); + updateModelMatrix(matrix, buffer); + rsgDrawMesh(gTorusMesh); + return; + } + + if (numMeshes == 2) { + rsMatrixLoadTranslate(matrix, -1.6f, 0.0f, -7.5f); + rsMatrixRotate(matrix, gTorusRotation, 1.0f, 0.0f, 0.0f); + updateModelMatrix(matrix, buffer); + rsgDrawMesh(gTorusMesh); + + rsMatrixLoadTranslate(matrix, 1.6f, 0.0f, -7.5f); + rsMatrixRotate(matrix, gTorusRotation, 1.0f, 0.0f, 0.0f); + updateModelMatrix(matrix, buffer); + rsgDrawMesh(gTorusMesh); + return; + } + + float startX = -5.0f; + float startY = -1.5f; + float startZ = -15.0f; + float dist = 3.2f; + + for (int h = 0; h < 4; h ++) { + for (int v = 0; v < 2; v ++) { + // Position our model on the screen + rsMatrixLoadTranslate(matrix, startX + dist * h, startY + dist * v, startZ); + rsMatrixRotate(matrix, gTorusRotation, 1.0f, 0.0f, 0.0f); + updateModelMatrix(matrix, buffer); + rsgDrawMesh(gTorusMesh); + } + } +} + + +// Quick hack to get some geometry numbers +static void displaySimpleGeoSamples(bool useTexture, int numMeshes) { + rsgBindProgramVertex(gProgVertex); + rsgBindProgramRaster(gCullBack); + // Setup the projection matrix with 30 degree field of view + rs_matrix4x4 proj; + float aspect = (float)gRenderSurfaceW / (float)gRenderSurfaceH; + rsMatrixLoadPerspective(&proj, 30.0f, aspect, 0.1f, 100.0f); + rsgProgramVertexLoadProjectionMatrix(&proj); + + // Fragment shader with texture + rsgBindProgramStore(gProgStoreBlendNoneDepth); + if (useTexture) { + rsgBindProgramFragment(gProgFragmentTexture); + } else { + rsgBindProgramFragment(gProgFragmentColor); + rsgProgramFragmentConstantColor(gProgFragmentColor, 0.1, 0.7, 0.1, 1); + } + rsgBindSampler(gProgFragmentTexture, 0, gLinearClamp); + rsgBindTexture(gProgFragmentTexture, 0, gTexTorus); + + // Apply a rotation to our mesh + gTorusRotation += 50.0f * gDt; + if (gTorusRotation > 360.0f) { + gTorusRotation -= 360.0f; + } + + rs_matrix4x4 matrix; + drawToruses(numMeshes, &matrix, 0); +} + +float gLight0Rotation = 0; +float gLight1Rotation = 0; + +static void setupCustomShaderLights() { + float4 light0Pos = {-5.0f, 5.0f, -10.0f, 1.0f}; + float4 light1Pos = {2.0f, 5.0f, 15.0f, 1.0f}; + float4 light0DiffCol = {0.9f, 0.7f, 0.7f, 1.0f}; + float4 light0SpecCol = {0.9f, 0.6f, 0.6f, 1.0f}; + float4 light1DiffCol = {0.5f, 0.5f, 0.9f, 1.0f}; + float4 light1SpecCol = {0.5f, 0.5f, 0.9f, 1.0f}; + + gLight0Rotation += 50.0f * gDt; + if (gLight0Rotation > 360.0f) { + gLight0Rotation -= 360.0f; + } + gLight1Rotation -= 50.0f * gDt; + if (gLight1Rotation > 360.0f) { + gLight1Rotation -= 360.0f; + } + + rs_matrix4x4 l0Mat; + rsMatrixLoadRotate(&l0Mat, gLight0Rotation, 1.0f, 0.0f, 0.0f); + light0Pos = rsMatrixMultiply(&l0Mat, light0Pos); + rs_matrix4x4 l1Mat; + rsMatrixLoadRotate(&l1Mat, gLight1Rotation, 0.0f, 0.0f, 1.0f); + light1Pos = rsMatrixMultiply(&l1Mat, light1Pos); + + // Set light 0 properties + gVSConstants->light0_Posision = light0Pos; + gVSConstants->light0_Diffuse = 1.0f; + gVSConstants->light0_Specular = 0.5f; + gVSConstants->light0_CosinePower = 10.0f; + // Set light 1 properties + gVSConstants->light1_Posision = light1Pos; + gVSConstants->light1_Diffuse = 1.0f; + gVSConstants->light1_Specular = 0.7f; + gVSConstants->light1_CosinePower = 25.0f; + rsgAllocationSyncAll(rsGetAllocation(gVSConstants)); + + // Update fragment shader constants + // Set light 0 colors + gFSConstants->light0_DiffuseColor = light0DiffCol; + gFSConstants->light0_SpecularColor = light0SpecCol; + // Set light 1 colors + gFSConstants->light1_DiffuseColor = light1DiffCol; + gFSConstants->light1_SpecularColor = light1SpecCol; + rsgAllocationSyncAll(rsGetAllocation(gFSConstants)); + + // Set light 0 properties for per pixel lighting + gFSConstPixel->light0_Posision = light0Pos; + gFSConstPixel->light0_Diffuse = 1.0f; + gFSConstPixel->light0_Specular = 0.5f; + gFSConstPixel->light0_CosinePower = 10.0f; + gFSConstPixel->light0_DiffuseColor = light0DiffCol; + gFSConstPixel->light0_SpecularColor = light0SpecCol; + // Set light 1 properties + gFSConstPixel->light1_Posision = light1Pos; + gFSConstPixel->light1_Diffuse = 1.0f; + gFSConstPixel->light1_Specular = 0.7f; + gFSConstPixel->light1_CosinePower = 25.0f; + gFSConstPixel->light1_DiffuseColor = light1DiffCol; + gFSConstPixel->light1_SpecularColor = light1SpecCol; + rsgAllocationSyncAll(rsGetAllocation(gFSConstPixel)); +} + +static void displayCustomShaderSamples(int numMeshes) { + + // Update vertex shader constants + // Load model matrix + // Apply a rotation to our mesh + gTorusRotation += 50.0f * gDt; + if (gTorusRotation > 360.0f) { + gTorusRotation -= 360.0f; + } + + // Setup the projection matrix + float aspect = (float)gRenderSurfaceW / (float)gRenderSurfaceH; + rsMatrixLoadPerspective(&gVSConstants->proj, 30.0f, aspect, 0.1f, 100.0f); + setupCustomShaderLights(); + + rsgBindProgramVertex(gProgVertexCustom); + + // Fragment shader with texture + rsgBindProgramStore(gProgStoreBlendNoneDepth); + rsgBindProgramFragment(gProgFragmentCustom); + rsgBindSampler(gProgFragmentCustom, 0, gLinearClamp); + rsgBindTexture(gProgFragmentCustom, 0, gTexTorus); + + // Use back face culling + rsgBindProgramRaster(gCullBack); + + drawToruses(numMeshes, &gVSConstants->model, gVSConstants); +} + +static void displayPixelLightSamples(int numMeshes, bool heavyVertex) { + + // Update vertex shader constants + // Load model matrix + // Apply a rotation to our mesh + gTorusRotation += 30.0f * gDt; + if (gTorusRotation > 360.0f) { + gTorusRotation -= 360.0f; + } + + gVSConstPixel->time = rsUptimeMillis()*0.005; + + // Setup the projection matrix + float aspect = (float)gRenderSurfaceW / (float)gRenderSurfaceH; + rsMatrixLoadPerspective(&gVSConstPixel->proj, 30.0f, aspect, 0.1f, 100.0f); + setupCustomShaderLights(); + + if (heavyVertex) { + rsgBindProgramVertex(gProgVertexPixelLightMove); + } else { + rsgBindProgramVertex(gProgVertexPixelLight); + } + + // Fragment shader with texture + rsgBindProgramStore(gProgStoreBlendNoneDepth); + rsgBindProgramFragment(gProgFragmentPixelLight); + rsgBindSampler(gProgFragmentPixelLight, 0, gLinearClamp); + rsgBindTexture(gProgFragmentPixelLight, 0, gTexTorus); + + // Use back face culling + rsgBindProgramRaster(gCullBack); + + drawToruses(numMeshes, &gVSConstPixel->model, gVSConstPixel); +} + + +void root(const void *v_in, void *v_out, const void *usrData, uint32_t x, uint32_t y) { + TestData *testData = (TestData*)usrData; + gRenderSurfaceW = testData->renderSurfaceW; + gRenderSurfaceH = testData->renderSurfaceH; + gDt = testData->dt; + + switch(testData->user) { + case 0: + displaySimpleGeoSamples(testData->user1 == 1 ? true : false, testData->user2); + break; + case 1: + displayCustomShaderSamples(testData->user1); + break; + case 2: + displayPixelLightSamples(testData->user1, testData->user2 == 1 ? true : false); + break; + } +} |