Start adding RS tests.

Change-Id: I025357407eca3e515823493ff63e4c78249e8126
This commit is contained in:
Jason Sams
2010-08-12 17:00:09 -07:00
parent 2cbd298f39
commit 2a114bdc64
9 changed files with 531 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
#
# Copyright (C) 2008 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.
#
ifneq ($(TARGET_SIMULATOR),true)
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES := $(call all-java-files-under, src) $(call all-renderscript-files-under, src)
LOCAL_PACKAGE_NAME := RSTest
include $(BUILD_PACKAGE)
endif

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.rs.test">
<application
android:label="_RS_Test"
android:icon="@drawable/test_pattern">
<activity android:name="RSTest">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

Binary file not shown.

After

Width:  |  Height:  |  Size: 307 B

View File

@@ -0,0 +1,85 @@
/*
* Copyright (C) 2008 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.
*/
package com.android.rs.test;
import android.renderscript.RSSurfaceView;
import android.renderscript.RenderScript;
import android.app.Activity;
import android.content.res.Configuration;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.provider.Settings.System;
import android.util.Config;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.ListView;
import java.lang.Runtime;
public class RSTest extends Activity {
//EventListener mListener = new EventListener();
private static final String LOG_TAG = "libRS_jni";
private static final boolean DEBUG = false;
private static final boolean LOG_ENABLED = DEBUG ? Config.LOGD : Config.LOGV;
private RSTestView mView;
// get the current looper (from your Activity UI thread for instance
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
// Create our Preview view and set it as the content of our
// Activity
mView = new RSTestView(this);
setContentView(mView);
}
@Override
protected void onResume() {
// Ideally a game should implement onResume() and onPause()
// to take appropriate action when the activity looses focus
super.onResume();
mView.onResume();
}
@Override
protected void onPause() {
// Ideally a game should implement onResume() and onPause()
// to take appropriate action when the activity looses focus
super.onPause();
mView.onPause();
}
static void log(String message) {
if (LOG_ENABLED) {
Log.v(LOG_TAG, message);
}
}
}

View File

@@ -0,0 +1,72 @@
/*
* Copyright (C) 2008 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.
*/
package com.android.rs.test;
import android.content.res.Resources;
import android.renderscript.*;
import android.util.Log;
public class RSTestCore {
public static final int PART_COUNT = 50000;
public RSTestCore() {
}
private Resources mRes;
private RenderScriptGL mRS;
private ScriptC_Test_root mRootScript;
private boolean fp_mad() {
ScriptC_Fp_mad s = new ScriptC_Fp_mad(mRS, mRes, R.raw.fp_mad, true);
s.invoke_doTest(0, 0);
return true;
}
//private ScriptC_Fountain mScript;
public void init(RenderScriptGL rs, Resources res, int width, int height) {
mRS = rs;
mRes = res;
mRootScript = new ScriptC_Test_root(mRS, mRes, R.raw.test_root, true);
fp_mad();
/*
ProgramFragment.Builder pfb = new ProgramFragment.Builder(rs);
pfb.setVaryingColor(true);
rs.contextBindProgramFragment(pfb.create());
ScriptField_Point points = new ScriptField_Point(mRS, PART_COUNT);
Mesh.AllocationBuilder smb = new Mesh.AllocationBuilder(mRS);
smb.addVertexAllocation(points.getAllocation());
smb.addIndexType(Primitive.POINT);
Mesh sm = smb.create();
mScript = new ScriptC_Fountain(mRS, mRes, R.raw.fountain, true);
mScript.set_partMesh(sm);
mScript.bind_point(points);
mRS.contextBindRootScript(mScript);
*/
}
public void newTouchPosition(float x, float y, float pressure, int id) {
}
}

View File

@@ -0,0 +1,106 @@
/*
* Copyright (C) 2008 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.
*/
package com.android.rs.test;
import java.io.Writer;
import java.util.ArrayList;
import java.util.concurrent.Semaphore;
import android.renderscript.RSSurfaceView;
import android.renderscript.RenderScript;
import android.renderscript.RenderScriptGL;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.os.Message;
import android.util.AttributeSet;
import android.util.Log;
import android.view.Surface;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.KeyEvent;
import android.view.MotionEvent;
public class RSTestView extends RSSurfaceView {
public RSTestView(Context context) {
super(context);
//setFocusable(true);
}
private RenderScriptGL mRS;
private RSTestCore mRender;
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
super.surfaceChanged(holder, format, w, h);
if (mRS == null) {
mRS = createRenderScript(false);
mRS.contextSetSurface(w, h, holder.getSurface());
mRender = new RSTestCore();
mRender.init(mRS, getResources(), w, h);
}
}
@Override
protected void onDetachedFromWindow() {
if(mRS != null) {
mRS = null;
destroyRenderScript();
}
}
/*
@Override
public boolean onTouchEvent(MotionEvent ev)
{
int act = ev.getActionMasked();
if (act == ev.ACTION_UP) {
mRender.newTouchPosition(0, 0, 0, ev.getPointerId(0));
return false;
} else if (act == MotionEvent.ACTION_POINTER_UP) {
// only one pointer going up, we can get the index like this
int pointerIndex = ev.getActionIndex();
int pointerId = ev.getPointerId(pointerIndex);
mRender.newTouchPosition(0, 0, 0, pointerId);
}
int count = ev.getHistorySize();
int pcount = ev.getPointerCount();
for (int p=0; p < pcount; p++) {
int id = ev.getPointerId(p);
mRender.newTouchPosition(ev.getX(p),
ev.getY(p),
ev.getPressure(p),
id);
for (int i=0; i < count; i++) {
mRender.newTouchPosition(ev.getHistoricalX(p, i),
ev.getHistoricalY(p, i),
ev.getHistoricalPressure(p, i),
id);
}
}
return true;
}
*/
}

View File

@@ -0,0 +1,173 @@
#include "shared.rsh"
const int TEST_COUNT = 1;
#pragma rs export_var(g_results)
#pragma rs export_func(doTest)
static float data_f1[1025];
static float4 data_f4[1025];
static void test_mad4(uint32_t index) {
start();
float total = 0;
// Do ~1 billion ops
for (int ct=0; ct < 1000 * (1000 / 80); ct++) {
for (int i=0; i < (1000); i++) {
data_f4[i] = (data_f4[i] * 0.02f +
data_f4[i+1] * 0.04f +
data_f4[i+2] * 0.05f +
data_f4[i+3] * 0.1f +
data_f4[i+4] * 0.2f +
data_f4[i+5] * 0.2f +
data_f4[i+6] * 0.1f +
data_f4[i+7] * 0.05f +
data_f4[i+8] * 0.04f +
data_f4[i+9] * 0.02f + 1.f);
}
}
float time = end(index);
rsDebug("fp_mad4 M ops", 1000.f / time);
}
static void test_mad(uint32_t index) {
start();
float total = 0;
// Do ~1 billion ops
for (int ct=0; ct < 1000 * (1000 / 20); ct++) {
for (int i=0; i < (1000); i++) {
data_f1[i] = (data_f1[i] * 0.02f +
data_f1[i+1] * 0.04f +
data_f1[i+2] * 0.05f +
data_f1[i+3] * 0.1f +
data_f1[i+4] * 0.2f +
data_f1[i+5] * 0.2f +
data_f1[i+6] * 0.1f +
data_f1[i+7] * 0.05f +
data_f1[i+8] * 0.04f +
data_f1[i+9] * 0.02f + 1.f);
}
}
float time = end(index);
rsDebug("fp_mad M ops", 1000.f / time);
}
static void test_norm(uint32_t index) {
start();
float total = 0;
// Do ~10 M ops
for (int ct=0; ct < 1000 * 10; ct++) {
for (int i=0; i < (1000); i++) {
data_f4[i] = normalize(data_f4[i]);
}
}
float time = end(index);
rsDebug("fp_norm M ops", 10.f / time);
}
static void test_sincos4(uint32_t index) {
start();
float total = 0;
// Do ~10 M ops
for (int ct=0; ct < 1000 * 10 / 4; ct++) {
for (int i=0; i < (1000); i++) {
data_f4[i] = sin(data_f4[i]) * cos(data_f4[i]);
}
}
float time = end(index);
rsDebug("fp_sincos4 M ops", 10.f / time);
}
static void test_sincos(uint32_t index) {
start();
float total = 0;
// Do ~10 M ops
for (int ct=0; ct < 1000 * 10; ct++) {
for (int i=0; i < (1000); i++) {
data_f1[i] = sin(data_f1[i]) * cos(data_f1[i]);
}
}
float time = end(index);
rsDebug("fp_sincos M ops", 10.f / time);
}
static void test_clamp(uint32_t index) {
start();
// Do ~100 M ops
for (int ct=0; ct < 1000 * 100; ct++) {
for (int i=0; i < (1000); i++) {
data_f1[i] = clamp(data_f1[i], -1.f, 1.f);
}
}
float time = end(index);
rsDebug("fp_clamp M ops", 100.f / time);
start();
// Do ~100 M ops
for (ct=0; ct < 1000 * 100; ct++) {
for (int i=0; i < (1000); i++) {
if (data_f1[i] < -1.f) data_f1[i] = -1.f;
if (data_f1[i] > -1.f) data_f1[i] = 1.f;
}
}
time = end(index);
rsDebug("fp_clamp ref M ops", 100.f / time);
}
static void test_clamp4(uint32_t index) {
start();
float total = 0;
// Do ~100 M ops
for (int ct=0; ct < 1000 * 100 /4; ct++) {
for (int i=0; i < (1000); i++) {
data_f4[i] = clamp(data_f4[i], -1.f, 1.f);
}
}
float time = end(index);
rsDebug("fp_clamp4 M ops", 100.f / time);
}
void doTest(uint32_t index, int test_num) {
for (int x=0; x < 1025; x++) {
data_f1[x] = (x & 0xf) * 0.1f;
data_f4[x].x = (x & 0xf) * 0.1f;
data_f4[x].y = (x & 0xf0) * 0.1f;
data_f4[x].z = (x & 0x33) * 0.1f;
data_f4[x].w = (x & 0x77) * 0.1f;
}
test_mad4(index);
test_mad(index);
for (x=0; x < 1025; x++) {
data_f1[x] = (x & 0xf) * 0.1f + 1.f;
data_f4[x].x = (x & 0xf) * 0.1f + 1.f;
data_f4[x].y = (x & 0xf0) * 0.1f + 1.f;
data_f4[x].z = (x & 0x33) * 0.1f + 1.f;
data_f4[x].w = (x & 0x77) * 0.1f + 1.f;
}
test_norm(index);
test_sincos4(index);
test_sincos(index);
test_clamp4(index);
test_clamp(index);
}

View File

@@ -0,0 +1,25 @@
#pragma version(1)
#pragma rs java_package_name(com.android.rs.test)
typedef struct TestResult_s {
rs_allocation name;
bool pass;
float score;
int64_t time;
} TestResult;
TestResult *g_results;
static int64_t g_time;
static void start(void) {
g_time = rsUptimeMillis();
}
static float end(uint32_t idx) {
int64_t t = rsUptimeMillis() - g_time;
//g_results[idx].time = t;
//rsDebug("test time", (int)t);
return ((float)t) / 1000.f;
}

View File

@@ -0,0 +1,26 @@
// Fountain test script
#pragma version(1)
#pragma rs java_package_name(com.android.rs.test)
#pragma stateFragment(parent)
#include "rs_graphics.rsh"
typedef struct TestResult {
rs_allocation name;
bool pass;
float score;
} TestResult_t;
TestResult_t *results;
#pragma rs export_var(results)
//#pragma rs export_func(addParticles)
int root() {
return 0;
}