upload android base code part1
This commit is contained in:
parent
e02f198e2d
commit
0a1de6c4b3
48159 changed files with 9071466 additions and 0 deletions
3
android/frameworks/rs/tests/cpp_api/Android.mk
Normal file
3
android/frameworks/rs/tests/cpp_api/Android.mk
Normal file
|
@ -0,0 +1,3 @@
|
|||
LOCAL_PATH:=$(call my-dir)
|
||||
|
||||
include $(call all-makefiles-under,$(LOCAL_PATH))
|
7
android/frameworks/rs/tests/cpp_api/common.mk
Normal file
7
android/frameworks/rs/tests/cpp_api/common.mk
Normal file
|
@ -0,0 +1,7 @@
|
|||
LOCAL_MODULE_TAGS := tests
|
||||
|
||||
LOCAL_CFLAGS += -std=c++11 -Werror -Wall -Wextra
|
||||
LOCAL_LDFLAGS += -llog
|
||||
|
||||
intermediates := $(call intermediates-dir-for,STATIC_LIBRARIES,libRS,TARGET,)
|
||||
LOCAL_C_INCLUDES += $(intermediates)
|
|
@ -0,0 +1,19 @@
|
|||
LOCAL_PATH:= $(call my-dir)
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_MODULE:= rstest-cpp-globalguard
|
||||
|
||||
LOCAL_SDK_VERSION := 21
|
||||
LOCAL_NDK_STL_VARIANT := stlport_static
|
||||
|
||||
LOCAL_SRC_FILES:= \
|
||||
multiply.rs \
|
||||
compute.cpp
|
||||
|
||||
LOCAL_STATIC_LIBRARIES := \
|
||||
libRScpp_static
|
||||
|
||||
LOCAL_LDFLAGS += -llog
|
||||
|
||||
include frameworks/rs/tests/cpp_api/common.mk
|
||||
include $(BUILD_EXECUTABLE)
|
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* Copyright (C) 2017 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.
|
||||
*/
|
||||
|
||||
// This file is based on frameworks/rs/tests/cpp_api/cppallocation/compute.cpp.
|
||||
|
||||
#include "RenderScript.h"
|
||||
|
||||
#include "ScriptC_multiply.h"
|
||||
|
||||
sp<RS> rs;
|
||||
sp<const Element> e;
|
||||
sp<const Type> t;
|
||||
sp<Allocation> ain;
|
||||
sp<Allocation> aout;
|
||||
sp<ScriptC_multiply> sc;
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
uint32_t numElems = 1024;
|
||||
|
||||
if (argc >= 2) {
|
||||
int tempNumElems = atoi(argv[1]);
|
||||
if (tempNumElems < 1) {
|
||||
printf("numElems must be greater than 0\n");
|
||||
return 1;
|
||||
}
|
||||
numElems = (uint32_t) tempNumElems;
|
||||
}
|
||||
|
||||
rs = new RS();
|
||||
|
||||
if (!rs->init("/system/bin")) {
|
||||
printf("Could not initialize RenderScript\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
e = Element::U32(rs);
|
||||
|
||||
Type::Builder tb(rs, e);
|
||||
tb.setX(numElems);
|
||||
t = tb.create();
|
||||
|
||||
ain = Allocation::createTyped(rs, t);
|
||||
aout = Allocation::createTyped(rs, t);
|
||||
|
||||
sc = new ScriptC_multiply(rs);
|
||||
|
||||
uint32_t* buf = new uint32_t[numElems];
|
||||
for (uint32_t ct=0; ct < numElems; ct++) {
|
||||
buf[ct] = (uint32_t)ct;
|
||||
}
|
||||
|
||||
ain->copy1DRangeFrom(0, numElems, buf);
|
||||
|
||||
sc->forEach_multiply(ain, aout);
|
||||
|
||||
aout->copy1DRangeTo(0, numElems, buf);
|
||||
|
||||
for (uint32_t ct=0; ct < numElems; ct++) {
|
||||
if (buf[ct] != ct * 2) {
|
||||
printf("Mismatch at location %d: %u\n", ct, buf[ct]);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
printf("Test successful with %u elems!\n", numElems);
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* Copyright (C) 2017 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(unused)
|
||||
#pragma rs_fp_relaxed
|
||||
|
||||
uint32_t RS_KERNEL multiply(uint32_t in) {
|
||||
return in * 2;
|
||||
}
|
||||
|
||||
|
19
android/frameworks/rs/tests/cpp_api/cppallocation/Android.mk
Normal file
19
android/frameworks/rs/tests/cpp_api/cppallocation/Android.mk
Normal file
|
@ -0,0 +1,19 @@
|
|||
LOCAL_PATH:= $(call my-dir)
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_MODULE:= rstest-cppallocation
|
||||
|
||||
LOCAL_SDK_VERSION := 21
|
||||
LOCAL_NDK_STL_VARIANT := stlport_static
|
||||
|
||||
LOCAL_SRC_FILES:= \
|
||||
multiply.rs \
|
||||
compute.cpp
|
||||
|
||||
LOCAL_STATIC_LIBRARIES := \
|
||||
libRScpp_static
|
||||
|
||||
LOCAL_LDFLAGS += -llog
|
||||
|
||||
include frameworks/rs/tests/cpp_api/common.mk
|
||||
include $(BUILD_EXECUTABLE)
|
|
@ -0,0 +1,63 @@
|
|||
|
||||
#include "RenderScript.h"
|
||||
|
||||
#include "ScriptC_multiply.h"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
|
||||
uint32_t numElems = 1024;
|
||||
|
||||
if (argc >= 2) {
|
||||
int tempNumElems = atoi(argv[1]);
|
||||
if (tempNumElems < 1) {
|
||||
printf("numElems must be greater than 0\n");
|
||||
return 1;
|
||||
}
|
||||
numElems = (uint32_t) tempNumElems;
|
||||
}
|
||||
|
||||
sp<RS> rs = new RS();
|
||||
|
||||
if (!rs->init("/system/bin")) {
|
||||
printf("Could not initialize RenderScript\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
sp<const Element> e = Element::U32(rs);
|
||||
|
||||
Type::Builder tb(rs, e);
|
||||
tb.setX(numElems);
|
||||
sp<const Type> t = tb.create();
|
||||
|
||||
sp<Allocation> ain = Allocation::createTyped(rs, t);
|
||||
sp<Allocation> aout = Allocation::createTyped(rs, t);
|
||||
|
||||
sp<ScriptC_multiply> sc = new ScriptC_multiply(rs);
|
||||
|
||||
uint32_t* buf = new uint32_t[numElems];
|
||||
for (uint32_t ct=0; ct < numElems; ct++) {
|
||||
buf[ct] = (uint32_t)ct;
|
||||
}
|
||||
|
||||
ain->copy1DRangeFrom(0, numElems, buf);
|
||||
|
||||
sc->forEach_multiply(ain, aout);
|
||||
|
||||
aout->copy1DRangeTo(0, numElems, buf);
|
||||
|
||||
for (uint32_t ct=0; ct < numElems; ct++) {
|
||||
if (buf[ct] != ct * 2) {
|
||||
printf("Mismatch at location %d: %u\n", ct, buf[ct]);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
printf("Test successful with %u elems!\n", numElems);
|
||||
|
||||
sc.clear();
|
||||
t.clear();
|
||||
e.clear();
|
||||
ain.clear();
|
||||
aout.clear();
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* Copyright (C) 2012 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(unused)
|
||||
#pragma rs_fp_relaxed
|
||||
|
||||
uint32_t RS_KERNEL multiply(uint32_t in) {
|
||||
return in * 2;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
LOCAL_PATH:= $(call my-dir)
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_MODULE:= rstest-compute-getpointer
|
||||
|
||||
LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
|
||||
|
||||
LOCAL_SRC_FILES:= \
|
||||
mono.rs \
|
||||
compute.cpp
|
||||
|
||||
LOCAL_SHARED_LIBRARIES := \
|
||||
libRScpp
|
||||
|
||||
include frameworks/rs/tests/cpp_api/common.mk
|
||||
include $(BUILD_EXECUTABLE)
|
|
@ -0,0 +1,97 @@
|
|||
|
||||
#include "RenderScript.h"
|
||||
|
||||
#include "ScriptC_mono.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
const uint32_t DIMX = 128;
|
||||
const uint32_t DIMY = 128;
|
||||
|
||||
int test_compute()
|
||||
{
|
||||
bool failed = false;
|
||||
|
||||
sp<RS> rs = new RS();
|
||||
printf("New RS %p\n", rs.get());
|
||||
|
||||
// only legitimate because this is a standalone executable
|
||||
bool r = rs->init("/system/bin");
|
||||
printf("Init returned %i\n", r);
|
||||
|
||||
sp<const Element> e = Element::U32(rs);
|
||||
printf("Element %p\n", e.get());
|
||||
|
||||
Type::Builder tb(rs, e);
|
||||
tb.setX(DIMX);
|
||||
tb.setY(DIMY);
|
||||
sp<const Type> t = tb.create();
|
||||
printf("Type %p\n", t.get());
|
||||
|
||||
|
||||
sp<Allocation> a1 = Allocation::createSized(rs, e, 1000);
|
||||
printf("Allocation %p\n", a1.get());
|
||||
|
||||
sp<Allocation> ain = Allocation::createTyped(rs, t, RS_ALLOCATION_USAGE_SCRIPT | RS_ALLOCATION_USAGE_SHARED);
|
||||
sp<Allocation> aout = Allocation::createTyped(rs, t, RS_ALLOCATION_USAGE_SCRIPT | RS_ALLOCATION_USAGE_SHARED);
|
||||
printf("Allocation %p %p\n", ain.get(), aout.get());
|
||||
|
||||
size_t inputStride, outputStride;
|
||||
|
||||
uint32_t *input = (uint32_t*)ain->getPointer(&inputStride);
|
||||
uint32_t *output = (uint32_t*)aout->getPointer(&outputStride);
|
||||
|
||||
printf("Input pointer: %p\n", input);
|
||||
printf("Input stride: %zu\n", inputStride);
|
||||
printf("Output pointer: %p\n", output);
|
||||
printf("Output stride: %zu\n", outputStride);
|
||||
|
||||
inputStride /= sizeof(uint32_t);
|
||||
outputStride /= sizeof(uint32_t);
|
||||
|
||||
for (size_t i = 0; i < DIMY; i++) {
|
||||
for (size_t j = 0; j < DIMX; j++) {
|
||||
input[i * inputStride + j] = rand();
|
||||
output[i * inputStride + j] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
ain->syncAll(RS_ALLOCATION_USAGE_SHARED);
|
||||
aout->syncAll(RS_ALLOCATION_USAGE_SHARED);
|
||||
|
||||
printf("Launching script\n");
|
||||
|
||||
sp<ScriptC_mono> sc = new ScriptC_mono(rs);
|
||||
sc->forEach_copyAndNot(ain, aout);
|
||||
rs->finish();
|
||||
|
||||
printf("Script completed\n");
|
||||
|
||||
ain->syncAll(RS_ALLOCATION_USAGE_SCRIPT);
|
||||
aout->syncAll(RS_ALLOCATION_USAGE_SCRIPT);
|
||||
|
||||
for (size_t i = 0; i < DIMY; i++) {
|
||||
for (size_t j = 0; j < DIMX; j++) {
|
||||
if (input[i * inputStride + j] != ~(output[i * inputStride + j])) {
|
||||
printf("Mismatch at location %zu, %zu\n", j, i);
|
||||
failed = true;
|
||||
return failed;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return failed;
|
||||
}
|
||||
|
||||
int main() {
|
||||
bool failed = test_compute();
|
||||
|
||||
if (failed) {
|
||||
printf("TEST FAILED!\n");
|
||||
} else {
|
||||
printf("TEST PASSED!\n");
|
||||
}
|
||||
|
||||
return failed;
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* Copyright (C) 2012 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.rs.cppbasic)
|
||||
#pragma rs_fp_relaxed
|
||||
|
||||
uint32_t RS_KERNEL copyAndNot(uint32_t in) {
|
||||
return ~in;
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
LOCAL_PATH:= $(call my-dir)
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_MODULE:= rstest-compute-shared
|
||||
|
||||
LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
|
||||
|
||||
LOCAL_SRC_FILES:= \
|
||||
mono.rs \
|
||||
compute.cpp
|
||||
|
||||
LOCAL_SHARED_LIBRARIES := \
|
||||
libRScpp
|
||||
|
||||
include frameworks/rs/tests/cpp_api/common.mk
|
||||
include $(BUILD_EXECUTABLE)
|
113
android/frameworks/rs/tests/cpp_api/cppbasic-shared/compute.cpp
Normal file
113
android/frameworks/rs/tests/cpp_api/cppbasic-shared/compute.cpp
Normal file
|
@ -0,0 +1,113 @@
|
|||
|
||||
#include "RenderScript.h"
|
||||
|
||||
#include "ScriptC_mono.h"
|
||||
|
||||
int test_compute()
|
||||
{
|
||||
bool failed = false;
|
||||
|
||||
{
|
||||
sp<RS> rs = new RS();
|
||||
printf("New RS %p\n", rs.get());
|
||||
|
||||
// only legitimate because this is a standalone executable
|
||||
bool r = rs->init("/system/bin");
|
||||
printf("Init returned %i\n", r);
|
||||
|
||||
sp<const Element> e = Element::RGBA_8888(rs);
|
||||
printf("Element %p\n", e.get());
|
||||
|
||||
Type::Builder tb(rs, e);
|
||||
tb.setX(128);
|
||||
tb.setY(128);
|
||||
sp<const Type> t = tb.create();
|
||||
printf("Type %p\n", t.get());
|
||||
|
||||
|
||||
sp<Allocation> a1 = Allocation::createSized(rs, e, 1000);
|
||||
printf("Allocation %p\n", a1.get());
|
||||
|
||||
sp<Allocation> ain = Allocation::createTyped(rs, t);
|
||||
sp<Allocation> aout = Allocation::createTyped(rs, t);
|
||||
printf("Allocation %p %p\n", ain.get(), aout.get());
|
||||
|
||||
sp<ScriptC_mono> sc = new ScriptC_mono(rs);
|
||||
printf("new script\n");
|
||||
|
||||
sc->set_alloc(a1);
|
||||
sc->set_elem(e);
|
||||
sc->set_type(t);
|
||||
sc->set_script(sc);
|
||||
sc->set_script(nullptr);
|
||||
sp<const Sampler> samp = Sampler::CLAMP_NEAREST(rs);
|
||||
sc->set_sampler(samp);
|
||||
|
||||
// We read back the status from the script-side via a "failed" allocation.
|
||||
sp<const Element> failed_e = Element::BOOLEAN(rs);
|
||||
Type::Builder failed_tb(rs, failed_e);
|
||||
failed_tb.setX(1);
|
||||
sp<const Type> failed_t = failed_tb.create();
|
||||
sp<Allocation> failed_alloc = Allocation::createTyped(rs, failed_t);
|
||||
|
||||
failed_alloc->copy1DRangeFrom(0, failed_t->getCount(), &failed);
|
||||
sc->bind_failed(failed_alloc);
|
||||
|
||||
uint32_t *buf = new uint32_t[t->getCount()];
|
||||
for (uint32_t ct=0; ct < t->getCount(); ct++) {
|
||||
buf[ct] = ct | (ct << 16);
|
||||
}
|
||||
ain->copy1DRangeFrom(0, t->getCount(), buf);
|
||||
delete [] buf;
|
||||
|
||||
sc->forEach_root(ain, aout);
|
||||
|
||||
sc->invoke_foo(99, 3.1f);
|
||||
sc->set_g_f(39.9f);
|
||||
sc->set_g_i(-14);
|
||||
sc->invoke_foo(99, 3.1f);
|
||||
printf("for each done\n");
|
||||
|
||||
sc->invoke_bar(47, -3, 'c', -7, 14, -8);
|
||||
|
||||
// Verify a simple kernel.
|
||||
{
|
||||
static const uint32_t xDim = 7;
|
||||
static const uint32_t yDim = 7;
|
||||
sp<const Element> e = Element::I32(rs);
|
||||
Type::Builder tb(rs, e);
|
||||
tb.setX(xDim);
|
||||
tb.setY(yDim);
|
||||
sp<const Type> t = tb.create();
|
||||
sp<Allocation> kern1_in = Allocation::createTyped(rs, t);
|
||||
sp<Allocation> kern1_out = Allocation::createTyped(rs, t);
|
||||
|
||||
int *buf = new int[t->getCount()];
|
||||
for (uint32_t ct=0; ct < t->getCount(); ct++) {
|
||||
buf[ct] = 5;
|
||||
}
|
||||
kern1_in->copy2DRangeFrom(0, 0, xDim, yDim, buf);
|
||||
delete [] buf;
|
||||
|
||||
sc->forEach_kern1(kern1_in, kern1_out);
|
||||
sc->forEach_verify_kern1(kern1_out);
|
||||
|
||||
rs->finish();
|
||||
failed_alloc->copy1DTo(&failed);
|
||||
}
|
||||
}
|
||||
|
||||
return failed;
|
||||
}
|
||||
|
||||
int main() {
|
||||
bool failed = test_compute();
|
||||
|
||||
if (failed) {
|
||||
printf("TEST FAILED!\n");
|
||||
} else {
|
||||
printf("TEST PASSED!\n");
|
||||
}
|
||||
|
||||
return failed;
|
||||
}
|
82
android/frameworks/rs/tests/cpp_api/cppbasic-shared/mono.rs
Normal file
82
android/frameworks/rs/tests/cpp_api/cppbasic-shared/mono.rs
Normal file
|
@ -0,0 +1,82 @@
|
|||
/*
|
||||
* Copyright (C) 2012 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.rs.cppbasic)
|
||||
#pragma rs_fp_relaxed
|
||||
|
||||
int g_i = 4;
|
||||
|
||||
float g_f = 5.9;
|
||||
|
||||
const static float3 gMonoMult = {0.299f, 0.587f, 0.114f};
|
||||
|
||||
bool *failed;
|
||||
|
||||
#define _RS_ASSERT(b) \
|
||||
do { \
|
||||
if (!(b)) { \
|
||||
*failed = true; \
|
||||
rsDebug(#b " FAILED", 0); \
|
||||
} \
|
||||
\
|
||||
} while (0)
|
||||
|
||||
struct myStruct {
|
||||
int i;
|
||||
int j;
|
||||
float f;
|
||||
char c[3];
|
||||
};
|
||||
|
||||
rs_allocation alloc;
|
||||
rs_element elem;
|
||||
rs_type type;
|
||||
rs_sampler sampler;
|
||||
rs_script script;
|
||||
|
||||
void root(const uchar4 *v_in, uchar4 *v_out) {
|
||||
float4 f4 = rsUnpackColor8888(*v_in);
|
||||
|
||||
float3 mono = dot(f4.rgb, gMonoMult);
|
||||
*v_out = rsPackColorTo8888(mono);
|
||||
}
|
||||
|
||||
void foo(int i, float f) {
|
||||
rsDebug("g_i", g_i);
|
||||
rsDebug("g_f", g_f);
|
||||
rsDebug("i", i);
|
||||
rsDebug("f", f);
|
||||
}
|
||||
|
||||
void bar(int i, int j, char k, int l, int m, int n) {
|
||||
_RS_ASSERT(i == 47);
|
||||
_RS_ASSERT(j == -3);
|
||||
_RS_ASSERT(k == 'c');
|
||||
_RS_ASSERT(l == -7);
|
||||
_RS_ASSERT(m == 14);
|
||||
_RS_ASSERT(n == -8);
|
||||
}
|
||||
|
||||
int RS_KERNEL kern1(int i, uint32_t x, uint32_t y) {
|
||||
return i + 10 * x + 100 *y;
|
||||
}
|
||||
|
||||
void RS_KERNEL verify_kern1(int i, uint32_t x, uint32_t y) {
|
||||
_RS_ASSERT(i == (5 + 10 * x + 100 * y));
|
||||
rsDebug("i ", i);
|
||||
}
|
||||
|
17
android/frameworks/rs/tests/cpp_api/cppbasic/Android.mk
Normal file
17
android/frameworks/rs/tests/cpp_api/cppbasic/Android.mk
Normal file
|
@ -0,0 +1,17 @@
|
|||
LOCAL_PATH:= $(call my-dir)
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_MODULE:= rstest-compute
|
||||
|
||||
LOCAL_SDK_VERSION := 21
|
||||
LOCAL_NDK_STL_VARIANT := stlport_static
|
||||
|
||||
LOCAL_SRC_FILES:= \
|
||||
mono.rs \
|
||||
compute.cpp
|
||||
|
||||
LOCAL_STATIC_LIBRARIES := \
|
||||
libRScpp_static
|
||||
|
||||
include frameworks/rs/tests/cpp_api/common.mk
|
||||
include $(BUILD_EXECUTABLE)
|
113
android/frameworks/rs/tests/cpp_api/cppbasic/compute.cpp
Normal file
113
android/frameworks/rs/tests/cpp_api/cppbasic/compute.cpp
Normal file
|
@ -0,0 +1,113 @@
|
|||
|
||||
#include "RenderScript.h"
|
||||
|
||||
#include "ScriptC_mono.h"
|
||||
|
||||
int test_compute()
|
||||
{
|
||||
bool failed = false;
|
||||
|
||||
{
|
||||
sp<RS> rs = new RS();
|
||||
printf("New RS %p\n", rs.get());
|
||||
|
||||
// only legitimate because this is a standalone executable
|
||||
bool r = rs->init("/system/bin");
|
||||
printf("Init returned %i\n", r);
|
||||
|
||||
sp<const Element> e = Element::RGBA_8888(rs);
|
||||
printf("Element %p\n", e.get());
|
||||
|
||||
Type::Builder tb(rs, e);
|
||||
tb.setX(128);
|
||||
tb.setY(128);
|
||||
sp<const Type> t = tb.create();
|
||||
printf("Type %p\n", t.get());
|
||||
|
||||
|
||||
sp<Allocation> a1 = Allocation::createSized(rs, e, 1000);
|
||||
printf("Allocation %p\n", a1.get());
|
||||
|
||||
sp<Allocation> ain = Allocation::createTyped(rs, t);
|
||||
sp<Allocation> aout = Allocation::createTyped(rs, t);
|
||||
printf("Allocation %p %p\n", ain.get(), aout.get());
|
||||
|
||||
sp<ScriptC_mono> sc = new ScriptC_mono(rs);
|
||||
printf("new script\n");
|
||||
|
||||
sc->set_alloc(a1);
|
||||
sc->set_elem(e);
|
||||
sc->set_type(t);
|
||||
sc->set_script(sc);
|
||||
sc->set_script(nullptr);
|
||||
sp<const Sampler> samp = Sampler::CLAMP_NEAREST(rs);
|
||||
sc->set_sampler(samp);
|
||||
|
||||
// We read back the status from the script-side via a "failed" allocation.
|
||||
sp<const Element> failed_e = Element::BOOLEAN(rs);
|
||||
Type::Builder failed_tb(rs, failed_e);
|
||||
failed_tb.setX(1);
|
||||
sp<const Type> failed_t = failed_tb.create();
|
||||
sp<Allocation> failed_alloc = Allocation::createTyped(rs, failed_t);
|
||||
|
||||
failed_alloc->copy1DRangeFrom(0, failed_t->getCount(), &failed);
|
||||
sc->bind_failed(failed_alloc);
|
||||
|
||||
uint32_t *buf = new uint32_t[t->getCount()];
|
||||
for (uint32_t ct=0; ct < t->getCount(); ct++) {
|
||||
buf[ct] = ct | (ct << 16);
|
||||
}
|
||||
ain->copy1DRangeFrom(0, t->getCount(), buf);
|
||||
delete [] buf;
|
||||
|
||||
sc->forEach_root(ain, aout);
|
||||
|
||||
sc->invoke_foo(99, 3.1f);
|
||||
sc->set_g_f(39.9f);
|
||||
sc->set_g_i(-14);
|
||||
sc->invoke_foo(99, 3.1f);
|
||||
printf("for each done\n");
|
||||
|
||||
sc->invoke_bar(47, -3, 'c', -7, 14, -8);
|
||||
|
||||
// Verify a simple kernel.
|
||||
{
|
||||
static const uint32_t xDim = 7;
|
||||
static const uint32_t yDim = 7;
|
||||
sp<const Element> e = Element::I32(rs);
|
||||
Type::Builder tb(rs, e);
|
||||
tb.setX(xDim);
|
||||
tb.setY(yDim);
|
||||
sp<const Type> t = tb.create();
|
||||
sp<Allocation> kern1_in = Allocation::createTyped(rs, t);
|
||||
sp<Allocation> kern1_out = Allocation::createTyped(rs, t);
|
||||
|
||||
int *buf = new int[t->getCount()];
|
||||
for (uint32_t ct=0; ct < t->getCount(); ct++) {
|
||||
buf[ct] = 5;
|
||||
}
|
||||
kern1_in->copy2DRangeFrom(0, 0, xDim, yDim, buf);
|
||||
delete [] buf;
|
||||
|
||||
sc->forEach_kern1(kern1_in, kern1_out);
|
||||
sc->forEach_verify_kern1(kern1_out);
|
||||
|
||||
rs->finish();
|
||||
failed_alloc->copy1DTo(&failed);
|
||||
}
|
||||
}
|
||||
|
||||
return failed;
|
||||
}
|
||||
|
||||
int main() {
|
||||
bool failed = test_compute();
|
||||
|
||||
if (failed) {
|
||||
printf("TEST FAILED!\n");
|
||||
} else {
|
||||
printf("TEST PASSED!\n");
|
||||
}
|
||||
|
||||
return failed;
|
||||
}
|
82
android/frameworks/rs/tests/cpp_api/cppbasic/mono.rs
Normal file
82
android/frameworks/rs/tests/cpp_api/cppbasic/mono.rs
Normal file
|
@ -0,0 +1,82 @@
|
|||
/*
|
||||
* Copyright (C) 2012 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.rs.cppbasic)
|
||||
#pragma rs_fp_relaxed
|
||||
|
||||
int g_i = 4;
|
||||
|
||||
float g_f = 5.9;
|
||||
|
||||
const static float3 gMonoMult = {0.299f, 0.587f, 0.114f};
|
||||
|
||||
bool *failed;
|
||||
|
||||
#define _RS_ASSERT(b) \
|
||||
do { \
|
||||
if (!(b)) { \
|
||||
*failed = true; \
|
||||
rsDebug(#b " FAILED", 0); \
|
||||
} \
|
||||
\
|
||||
} while (0)
|
||||
|
||||
struct myStruct {
|
||||
int i;
|
||||
int j;
|
||||
float f;
|
||||
char c[3];
|
||||
};
|
||||
|
||||
rs_allocation alloc;
|
||||
rs_element elem;
|
||||
rs_type type;
|
||||
rs_sampler sampler;
|
||||
rs_script script;
|
||||
|
||||
void root(const uchar4 *v_in, uchar4 *v_out) {
|
||||
float4 f4 = rsUnpackColor8888(*v_in);
|
||||
|
||||
float3 mono = dot(f4.rgb, gMonoMult);
|
||||
*v_out = rsPackColorTo8888(mono);
|
||||
}
|
||||
|
||||
void foo(int i, float f) {
|
||||
rsDebug("g_i", g_i);
|
||||
rsDebug("g_f", g_f);
|
||||
rsDebug("i", i);
|
||||
rsDebug("f", f);
|
||||
}
|
||||
|
||||
void bar(int i, int j, char k, int l, int m, int n) {
|
||||
_RS_ASSERT(i == 47);
|
||||
_RS_ASSERT(j == -3);
|
||||
_RS_ASSERT(k == 'c');
|
||||
_RS_ASSERT(l == -7);
|
||||
_RS_ASSERT(m == 14);
|
||||
_RS_ASSERT(n == -8);
|
||||
}
|
||||
|
||||
int RS_KERNEL kern1(int i, uint32_t x, uint32_t y) {
|
||||
return i + 10 * x + 100 *y;
|
||||
}
|
||||
|
||||
void RS_KERNEL verify_kern1(int i, uint32_t x, uint32_t y) {
|
||||
_RS_ASSERT(i == (5 + 10 * x + 100 * y));
|
||||
rsDebug("i ", i);
|
||||
}
|
||||
|
17
android/frameworks/rs/tests/cpp_api/cppf16/Android.mk
Normal file
17
android/frameworks/rs/tests/cpp_api/cppf16/Android.mk
Normal file
|
@ -0,0 +1,17 @@
|
|||
LOCAL_PATH:= $(call my-dir)
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_MODULE:= rstest-cppf16
|
||||
|
||||
LOCAL_NDK_STL_VARIANT := stlport_static
|
||||
|
||||
LOCAL_SRC_FILES:= \
|
||||
compute.cpp
|
||||
|
||||
LOCAL_STATIC_LIBRARIES := \
|
||||
libRScpp_static
|
||||
|
||||
LOCAL_LDFLAGS += -llog -ldl
|
||||
|
||||
include frameworks/rs/tests/cpp_api/common.mk
|
||||
include $(BUILD_EXECUTABLE)
|
47
android/frameworks/rs/tests/cpp_api/cppf16/compute.cpp
Normal file
47
android/frameworks/rs/tests/cpp_api/cppf16/compute.cpp
Normal file
|
@ -0,0 +1,47 @@
|
|||
#include "RenderScript.h"
|
||||
|
||||
using android::RSC::Allocation;
|
||||
using android::RSC::Element;
|
||||
using android::RSC::RS;
|
||||
using android::RSC::Type;
|
||||
using android::RSC::sp;
|
||||
|
||||
static const uint32_t dimX = 7, dimY = 5, dimZ = 3;
|
||||
|
||||
void testAllocationCreation(const sp<RS>& rs, const sp<const Element>& e, uint32_t nDims) {
|
||||
Type::Builder tb(rs, e);
|
||||
tb.setX(dimX);
|
||||
if (nDims >= 2)
|
||||
tb.setY(dimY);
|
||||
if (nDims >= 3)
|
||||
tb.setZ(dimZ);
|
||||
|
||||
sp<const Type> t = tb.create();
|
||||
sp<Allocation> alloc = Allocation::createTyped(rs, t);
|
||||
}
|
||||
|
||||
int main(int , char** )
|
||||
{
|
||||
sp<RS> rs = new RS();
|
||||
|
||||
if (!rs->init("/system/bin")) {
|
||||
printf("Could not initialize RenderScript\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Test ability to create 1D, 2D and 3D allocations of f16 scalars and
|
||||
// vectors
|
||||
sp<const Element> half = Element::F16(rs);
|
||||
sp<const Element> half2 = Element::F16_2(rs);
|
||||
sp<const Element> half3 = Element::F16_3(rs);
|
||||
sp<const Element> half4 = Element::F16_4(rs);
|
||||
|
||||
for (uint32_t nDims = 1; nDims <= 3; nDims ++) {
|
||||
testAllocationCreation(rs, half, nDims);
|
||||
testAllocationCreation(rs, half2, nDims);
|
||||
testAllocationCreation(rs, half3, nDims);
|
||||
testAllocationCreation(rs, half4, nDims);
|
||||
}
|
||||
|
||||
printf("Test successful!");
|
||||
}
|
17
android/frameworks/rs/tests/cpp_api/cppstrided/Android.mk
Normal file
17
android/frameworks/rs/tests/cpp_api/cppstrided/Android.mk
Normal file
|
@ -0,0 +1,17 @@
|
|||
LOCAL_PATH:= $(call my-dir)
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_MODULE:= rstest-cppstrided
|
||||
|
||||
LOCAL_SDK_VERSION := 21
|
||||
LOCAL_NDK_STL_VARIANT := stlport_static
|
||||
|
||||
LOCAL_SRC_FILES:= \
|
||||
multiply.rs \
|
||||
compute.cpp
|
||||
|
||||
LOCAL_STATIC_LIBRARIES := \
|
||||
libRScpp_static
|
||||
|
||||
include frameworks/rs/tests/cpp_api/common.mk
|
||||
include $(BUILD_EXECUTABLE)
|
74
android/frameworks/rs/tests/cpp_api/cppstrided/compute.cpp
Normal file
74
android/frameworks/rs/tests/cpp_api/cppstrided/compute.cpp
Normal file
|
@ -0,0 +1,74 @@
|
|||
|
||||
#include "RenderScript.h"
|
||||
|
||||
#include "ScriptC_multiply.h"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
|
||||
uint32_t numElems = 1024;
|
||||
uint32_t stride = 1025;
|
||||
|
||||
if (argc >= 2) {
|
||||
int tempStride = atoi(argv[1]);
|
||||
if (tempStride < 1024) {
|
||||
printf("stride must be greater than or equal to 1024\n");
|
||||
return 1;
|
||||
}
|
||||
stride = (uint32_t) tempStride;
|
||||
}
|
||||
|
||||
sp<RS> rs = new RS();
|
||||
|
||||
if (!rs->init("/system/bin")) {
|
||||
printf("Could not initialize RenderScript\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
sp<const Element> e = Element::U32(rs);
|
||||
|
||||
Type::Builder tb(rs, e);
|
||||
tb.setX(numElems);
|
||||
tb.setY(numElems);
|
||||
sp<const Type> t = tb.create();
|
||||
|
||||
sp<Allocation> ain = Allocation::createTyped(rs, t);
|
||||
sp<Allocation> aout = Allocation::createTyped(rs, t);
|
||||
|
||||
sp<ScriptC_multiply> sc = new ScriptC_multiply(rs);
|
||||
|
||||
uint32_t* buf = (uint32_t*) malloc(stride * numElems * sizeof(uint32_t));
|
||||
if (!buf) {
|
||||
printf("malloc failed\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < numElems; i++) {
|
||||
for (uint32_t ct=0; ct < numElems; ct++) {
|
||||
*(buf+(stride*i)+ct) = (uint32_t)ct + (i * numElems);
|
||||
}
|
||||
}
|
||||
|
||||
ain->copy2DStridedFrom(buf, stride * sizeof(uint32_t));
|
||||
|
||||
sc->forEach_multiply(ain, aout);
|
||||
|
||||
aout->copy2DStridedTo(buf, stride * sizeof(uint32_t));
|
||||
|
||||
for (uint32_t i = 0; i < numElems; i++) {
|
||||
for (uint32_t ct=0; ct < numElems; ct++) {
|
||||
if (*(buf+(stride*i)+ct) != (uint32_t)(ct + (i * numElems)) * 2) {
|
||||
printf("Mismatch at location %d, %d: %u\n", i, ct, *(buf+(stride*i)+ct));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printf("Test successful with %u stride!\n", stride);
|
||||
|
||||
sc.clear();
|
||||
t.clear();
|
||||
e.clear();
|
||||
ain.clear();
|
||||
aout.clear();
|
||||
}
|
25
android/frameworks/rs/tests/cpp_api/cppstrided/multiply.rs
Normal file
25
android/frameworks/rs/tests/cpp_api/cppstrided/multiply.rs
Normal file
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* Copyright (C) 2012 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(unused)
|
||||
#pragma rs_fp_relaxed
|
||||
|
||||
uint32_t RS_KERNEL multiply(uint32_t in) {
|
||||
return in * 2;
|
||||
}
|
||||
|
||||
|
17
android/frameworks/rs/tests/cpp_api/latency/Android.mk
Normal file
17
android/frameworks/rs/tests/cpp_api/latency/Android.mk
Normal file
|
@ -0,0 +1,17 @@
|
|||
LOCAL_PATH:= $(call my-dir)
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_MODULE:= rstest-latency
|
||||
|
||||
LOCAL_SDK_VERSION := 21
|
||||
LOCAL_NDK_STL_VARIANT := stlport_static
|
||||
|
||||
LOCAL_SRC_FILES:= \
|
||||
latency.rs \
|
||||
latency.cpp
|
||||
|
||||
LOCAL_STATIC_LIBRARIES := \
|
||||
libRScpp_static
|
||||
|
||||
include frameworks/rs/tests/cpp_api/common.mk
|
||||
include $(BUILD_EXECUTABLE)
|
111
android/frameworks/rs/tests/cpp_api/latency/latency.cpp
Normal file
111
android/frameworks/rs/tests/cpp_api/latency/latency.cpp
Normal file
|
@ -0,0 +1,111 @@
|
|||
#include "RenderScript.h"
|
||||
#include <sys/time.h>
|
||||
|
||||
#include "ScriptC_latency.h"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int iters = 100;
|
||||
int numElems = 1000;
|
||||
bool forceCpu = false;
|
||||
bool synchronous = false;
|
||||
|
||||
if (argc >= 2) {
|
||||
iters = atoi(argv[1]);
|
||||
if (iters <= 0) {
|
||||
printf("iters must be positive\n");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
printf("iters = %d\n", iters);
|
||||
|
||||
if (argc >= 3) {
|
||||
numElems = atoi(argv[2]);
|
||||
if (numElems <= 0) {
|
||||
printf("numElems must be positive\n");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (argc >= 4) {
|
||||
int temp = atoi(argv[3]);
|
||||
if (temp != 0)
|
||||
forceCpu = true;
|
||||
}
|
||||
|
||||
if (argc >= 5) {
|
||||
int temp = atoi(argv[4]);
|
||||
if (temp != 0)
|
||||
synchronous = true;
|
||||
}
|
||||
|
||||
if (forceCpu)
|
||||
printf("forcing CPU\n");
|
||||
|
||||
if (synchronous)
|
||||
printf("forcing synchronous\n");
|
||||
|
||||
printf("numElems = %d\n", numElems);
|
||||
|
||||
sp<RS> rs = new RS();
|
||||
|
||||
uint32_t flags = 0;
|
||||
if (forceCpu) flags |= RS_INIT_LOW_LATENCY;
|
||||
if (synchronous) flags |= RS_INIT_SYNCHRONOUS;
|
||||
|
||||
if (!rs->init("/system/bin", flags)) {
|
||||
printf("Could not initialize RenderScript\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
sp<const Element> e = Element::U32(rs);
|
||||
|
||||
Type::Builder tb(rs, e);
|
||||
tb.setX(numElems);
|
||||
sp<const Type> t = tb.create();
|
||||
|
||||
uint32_t *buf = new uint32_t[numElems];
|
||||
|
||||
sp<Allocation> ain = Allocation::createTyped(rs, t);
|
||||
sp<Allocation> aout = Allocation::createTyped(rs, t);
|
||||
|
||||
sp<ScriptC_latency> sc = new ScriptC_latency(rs);
|
||||
|
||||
struct timeval start, stop;
|
||||
|
||||
gettimeofday(&start, nullptr);
|
||||
|
||||
for (int i = 0; i < iters; i++) {
|
||||
sc->forEach_root(ain, aout);
|
||||
}
|
||||
|
||||
rs->finish();
|
||||
|
||||
gettimeofday(&stop, nullptr);
|
||||
|
||||
long long elapsed = (stop.tv_sec * 1000000) - (start.tv_sec * 1000000) + (stop.tv_usec - start.tv_usec);
|
||||
printf("elapsed time : %lld microseconds\n", elapsed);
|
||||
printf("time per iter: %f microseconds\n", (double)elapsed / iters);
|
||||
|
||||
gettimeofday(&start, nullptr);
|
||||
|
||||
for (int i = 0; i < iters; i++) {
|
||||
ain->copy1DFrom(buf);
|
||||
sc->forEach_root(ain, aout);
|
||||
aout->copy1DTo(buf);
|
||||
}
|
||||
|
||||
rs->finish();
|
||||
|
||||
gettimeofday(&stop, nullptr);
|
||||
elapsed = (stop.tv_sec * 1000000) - (start.tv_sec * 1000000) + (stop.tv_usec - start.tv_usec);
|
||||
printf("elapsed time with copy : %lld microseconds\n", elapsed);
|
||||
printf("time per iter with copy: %f microseconds\n", (double)elapsed / iters);
|
||||
|
||||
sc.clear();
|
||||
t.clear();
|
||||
e.clear();
|
||||
ain.clear();
|
||||
aout.clear();
|
||||
}
|
25
android/frameworks/rs/tests/cpp_api/latency/latency.rs
Normal file
25
android/frameworks/rs/tests/cpp_api/latency/latency.rs
Normal file
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* Copyright (C) 2012 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.rs.cpptests)
|
||||
#pragma rs_fp_relaxed
|
||||
|
||||
void root(const uint32_t *v_in, uint32_t *v_out) {
|
||||
|
||||
}
|
||||
|
||||
|
17
android/frameworks/rs/tests/cpp_api/typecheck/Android.mk
Normal file
17
android/frameworks/rs/tests/cpp_api/typecheck/Android.mk
Normal file
|
@ -0,0 +1,17 @@
|
|||
LOCAL_PATH:= $(call my-dir)
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_MODULE:= rstest-typecheck
|
||||
|
||||
LOCAL_SDK_VERSION := 21
|
||||
LOCAL_NDK_STL_VARIANT := stlport_static
|
||||
|
||||
LOCAL_SRC_FILES:= \
|
||||
kernels.rs \
|
||||
typecheck.cpp
|
||||
|
||||
LOCAL_STATIC_LIBRARIES := \
|
||||
libRScpp_static
|
||||
|
||||
include frameworks/rs/tests/cpp_api/common.mk
|
||||
include $(BUILD_EXECUTABLE)
|
145
android/frameworks/rs/tests/cpp_api/typecheck/kernels.rs
Normal file
145
android/frameworks/rs/tests/cpp_api/typecheck/kernels.rs
Normal file
|
@ -0,0 +1,145 @@
|
|||
/*
|
||||
* Copyright (C) 2013 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.rs.typecheck)
|
||||
#pragma rs_fp_relaxed
|
||||
|
||||
// Test initialized and uninitialized variables
|
||||
char c1;
|
||||
char c1i = 1;
|
||||
char2 c2;
|
||||
char2 c2i = {1, 2};
|
||||
char3 c3;
|
||||
char3 c3i = {1, 2, 3};
|
||||
char4 c4;
|
||||
char4 c4i = {1, 2, 3, 4};
|
||||
|
||||
uchar uc1;
|
||||
uchar uc1i = 1;
|
||||
uchar2 uc2;
|
||||
uchar2 uc2i = {1, 2};
|
||||
uchar3 uc3;
|
||||
uchar3 uc3i = {1, 2, 3};
|
||||
uchar4 uc4;
|
||||
uchar4 uc4i = {1, 2, 3, 4};
|
||||
|
||||
short s1;
|
||||
short s1i = 1;
|
||||
short2 s2;
|
||||
short2 s2i = {1, 2};
|
||||
short3 s3;
|
||||
short3 s3i = {1, 2, 3};
|
||||
short4 s4;
|
||||
short4 s4i = {1, 2, 3, 4};
|
||||
|
||||
ushort us1;
|
||||
ushort us1i = 1;
|
||||
ushort2 us2;
|
||||
ushort2 us2i = {1, 2};
|
||||
ushort3 us3;
|
||||
ushort3 us3i = {1, 2, 3};
|
||||
ushort4 us4;
|
||||
ushort4 us4i = {1, 2, 3, 4};
|
||||
|
||||
int i1;
|
||||
int i1i = 1;
|
||||
int2 i2;
|
||||
int2 i2i = {1, 2};
|
||||
int3 i3;
|
||||
int3 i3i = {1, 2, 3};
|
||||
int4 i4;
|
||||
int4 i4i = {1, 2, 3, 4};
|
||||
|
||||
uint ui1;
|
||||
uint ui1i = 1;
|
||||
uint2 ui2;
|
||||
uint2 ui2i = {1, 2};
|
||||
uint3 ui3;
|
||||
uint3 ui3i = {1, 2, 3};
|
||||
uint4 ui4;
|
||||
uint4 ui4i = {1, 2, 3, 4};
|
||||
|
||||
long l1;
|
||||
long l1i = 1;
|
||||
long2 l2;
|
||||
long2 l2i = {1, 2};
|
||||
long3 l3;
|
||||
long3 l3i = {1, 2, 3};
|
||||
long4 l4;
|
||||
long4 l4i = {1, 2, 3, 4};
|
||||
|
||||
ulong ul1;
|
||||
ulong ul1i = 1;
|
||||
ulong2 ul2;
|
||||
ulong2 ul2i = {1, 2};
|
||||
ulong3 ul3;
|
||||
ulong3 ul3i = {1, 2, 3};
|
||||
ulong4 ul4;
|
||||
ulong4 ul4i = {1, 2, 3, 4};
|
||||
|
||||
float f1;
|
||||
float f1i = 3.141592265358979f;
|
||||
float2 f2;
|
||||
float2 f2i = {1.f, 2.f};
|
||||
float3 f3;
|
||||
float3 f3i = {1.f, 2.f, 3.f};
|
||||
float4 f4;
|
||||
float4 f4i = {1.f, 2.f, 3.f, 4.f};
|
||||
|
||||
double d1;
|
||||
double d1i = 3.141592265358979;
|
||||
double2 d2;
|
||||
double2 d2i = {1, 2};
|
||||
double3 d3;
|
||||
double3 d3i = {1, 2, 3};
|
||||
double4 d4;
|
||||
double4 d4i = {1, 2, 3, 4};
|
||||
|
||||
|
||||
void RS_KERNEL test_BOOLEAN(bool in) {
|
||||
}
|
||||
|
||||
void RS_KERNEL test_I8(char in) {
|
||||
}
|
||||
|
||||
void RS_KERNEL test_U8(uchar in) {
|
||||
}
|
||||
|
||||
void RS_KERNEL test_I16(short in) {
|
||||
}
|
||||
|
||||
void RS_KERNEL test_U16(ushort in) {
|
||||
}
|
||||
|
||||
void RS_KERNEL test_I32(int in) {
|
||||
}
|
||||
|
||||
void RS_KERNEL test_U32(uint in) {
|
||||
}
|
||||
|
||||
void RS_KERNEL test_I64(long in) {
|
||||
}
|
||||
|
||||
void RS_KERNEL test_U64(ulong in) {
|
||||
}
|
||||
|
||||
void RS_KERNEL test_F32(float in) {
|
||||
}
|
||||
|
||||
void RS_KERNEL test_F64(double in) {
|
||||
}
|
||||
|
110
android/frameworks/rs/tests/cpp_api/typecheck/typecheck.cpp
Normal file
110
android/frameworks/rs/tests/cpp_api/typecheck/typecheck.cpp
Normal file
|
@ -0,0 +1,110 @@
|
|||
/*
|
||||
* Copyright (C) 2013 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.
|
||||
*/
|
||||
|
||||
#include "RenderScript.h"
|
||||
#include "ScriptC_kernels.h"
|
||||
|
||||
const static uint32_t x = 7;
|
||||
|
||||
sp<Allocation> createAlloc(const sp<RS>& rs, const sp<const Element>& e) {
|
||||
Type::Builder tb(rs, e);
|
||||
tb.setX(x);
|
||||
sp<const Type> t = tb.create();
|
||||
return Allocation::createTyped(rs, t);
|
||||
}
|
||||
|
||||
#define TEST_ELEM(KERNELNAME, ENAME) \
|
||||
bool test_elem_##KERNELNAME##_##ENAME() { \
|
||||
printf("Verifying forEach_test_" #KERNELNAME "() with " #ENAME "\n"); \
|
||||
sp<RS> rs = new RS(); \
|
||||
if (!rs->init("/system/bin")) { \
|
||||
printf("Could not initialize RenderScript\n"); \
|
||||
return true; \
|
||||
} \
|
||||
sp<Allocation> a = createAlloc(rs, Element::ENAME(rs)); \
|
||||
ScriptC_kernels sc(rs); \
|
||||
sc.forEach_test_##KERNELNAME(a); \
|
||||
rs->finish(); \
|
||||
bool shouldPass = !strcmp(#KERNELNAME, #ENAME); \
|
||||
if (shouldPass != (rs->getError() == RS_SUCCESS)) { \
|
||||
printf("Failed forEach_test_" #KERNELNAME "() with " #ENAME "\n"); \
|
||||
return true; \
|
||||
} \
|
||||
return false; \
|
||||
}
|
||||
|
||||
#define TEST_ELEM_ALL(ENAME) \
|
||||
TEST_ELEM(ENAME, BOOLEAN) \
|
||||
TEST_ELEM(ENAME, I8) \
|
||||
TEST_ELEM(ENAME, U8) \
|
||||
TEST_ELEM(ENAME, I16) \
|
||||
TEST_ELEM(ENAME, U16) \
|
||||
TEST_ELEM(ENAME, I32) \
|
||||
TEST_ELEM(ENAME, U32) \
|
||||
TEST_ELEM(ENAME, I64) \
|
||||
TEST_ELEM(ENAME, U64) \
|
||||
TEST_ELEM(ENAME, F32) \
|
||||
TEST_ELEM(ENAME, F64)
|
||||
|
||||
TEST_ELEM_ALL(BOOLEAN)
|
||||
TEST_ELEM_ALL(I8)
|
||||
TEST_ELEM_ALL(U8)
|
||||
TEST_ELEM_ALL(I16)
|
||||
TEST_ELEM_ALL(U16)
|
||||
TEST_ELEM_ALL(I32)
|
||||
TEST_ELEM_ALL(U32)
|
||||
TEST_ELEM_ALL(I64)
|
||||
TEST_ELEM_ALL(U64)
|
||||
TEST_ELEM_ALL(F32)
|
||||
TEST_ELEM_ALL(F64)
|
||||
|
||||
int main()
|
||||
{
|
||||
bool failed = false;
|
||||
|
||||
#define EXECUTE_TEST_ELEM_ALL(ENAME) \
|
||||
failed |= test_elem_##ENAME##_BOOLEAN(); \
|
||||
failed |= test_elem_##ENAME##_I8(); \
|
||||
failed |= test_elem_##ENAME##_U8(); \
|
||||
failed |= test_elem_##ENAME##_I16(); \
|
||||
failed |= test_elem_##ENAME##_U16(); \
|
||||
failed |= test_elem_##ENAME##_I32(); \
|
||||
failed |= test_elem_##ENAME##_U32(); \
|
||||
failed |= test_elem_##ENAME##_I64(); \
|
||||
failed |= test_elem_##ENAME##_U64(); \
|
||||
failed |= test_elem_##ENAME##_F32(); \
|
||||
failed |= test_elem_##ENAME##_F64(); \
|
||||
|
||||
EXECUTE_TEST_ELEM_ALL(BOOLEAN);
|
||||
EXECUTE_TEST_ELEM_ALL(I8);
|
||||
EXECUTE_TEST_ELEM_ALL(U8);
|
||||
EXECUTE_TEST_ELEM_ALL(I16);
|
||||
EXECUTE_TEST_ELEM_ALL(U16);
|
||||
EXECUTE_TEST_ELEM_ALL(I32);
|
||||
EXECUTE_TEST_ELEM_ALL(U32);
|
||||
EXECUTE_TEST_ELEM_ALL(I64);
|
||||
EXECUTE_TEST_ELEM_ALL(U64);
|
||||
EXECUTE_TEST_ELEM_ALL(F32);
|
||||
EXECUTE_TEST_ELEM_ALL(F64);
|
||||
|
||||
if (failed) {
|
||||
printf("TEST FAILED!\n");
|
||||
} else {
|
||||
printf("TEST PASSED!\n");
|
||||
}
|
||||
|
||||
return failed;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue