blob: d93b453caf8ea94b7e7ccc651e68a4c3916613f5 [file] [log] [blame]
Jason Sams221a4b12012-02-22 15:22:41 -08001
2#include "RenderScript.h"
Jason Sams221a4b12012-02-22 15:22:41 -08003
Jason Samsf1e6d222012-02-24 14:24:56 -08004#include "ScriptC_mono.h"
5
Jason Sams69cccdf2012-04-02 19:11:49 -07006using namespace android;
Tim Murray9eb7f4b2012-11-16 14:02:18 -08007using namespace RSC;
Jason Sams69cccdf2012-04-02 19:11:49 -07008
Stephen Hines8a588bd2013-11-26 15:38:31 -08009int test_compute()
Jason Sams221a4b12012-02-22 15:22:41 -080010{
Stephen Hines43514cd2012-11-16 14:33:47 -080011 bool failed = false;
Stephen Hines43514cd2012-11-16 14:33:47 -080012
Stephen Hines43514cd2012-11-16 14:33:47 -080013 {
Tim Murraycaf41262013-12-13 12:54:37 -080014 sp<RS> rs = new RS();
15 printf("New RS %p\n", rs.get());
Stephen Hines43514cd2012-11-16 14:33:47 -080016
Tim Murraycaf41262013-12-13 12:54:37 -080017 // only legitimate because this is a standalone executable
18 bool r = rs->init("/system/bin");
19 printf("Init returned %i\n", r);
20
21 sp<const Element> e = Element::RGBA_8888(rs);
22 printf("Element %p\n", e.get());
23
24 Type::Builder tb(rs, e);
25 tb.setX(128);
26 tb.setY(128);
27 sp<const Type> t = tb.create();
28 printf("Type %p\n", t.get());
29
30
31 sp<Allocation> a1 = Allocation::createSized(rs, e, 1000);
32 printf("Allocation %p\n", a1.get());
33
34 sp<Allocation> ain = Allocation::createTyped(rs, t);
35 sp<Allocation> aout = Allocation::createTyped(rs, t);
36 printf("Allocation %p %p\n", ain.get(), aout.get());
37
38 sp<ScriptC_mono> sc = new ScriptC_mono(rs);
39 printf("new script\n");
40
41 sc->set_alloc(a1);
42 sc->set_elem(e);
43 sc->set_type(t);
44 sc->set_script(sc);
45 sc->set_script(NULL);
46 sp<const Sampler> samp = Sampler::CLAMP_NEAREST(rs);
47 sc->set_sampler(samp);
48
49 // We read back the status from the script-side via a "failed" allocation.
50 sp<const Element> failed_e = Element::BOOLEAN(rs);
51 Type::Builder failed_tb(rs, failed_e);
52 failed_tb.setX(1);
53 sp<const Type> failed_t = failed_tb.create();
54 sp<Allocation> failed_alloc = Allocation::createTyped(rs, failed_t);
55
56 failed_alloc->copy1DRangeFrom(0, failed_t->getCount(), &failed);
57 sc->bind_failed(failed_alloc);
58
59 uint32_t *buf = new uint32_t[t->getCount()];
Stephen Hines43514cd2012-11-16 14:33:47 -080060 for (uint32_t ct=0; ct < t->getCount(); ct++) {
Tim Murraycaf41262013-12-13 12:54:37 -080061 buf[ct] = ct | (ct << 16);
Stephen Hines43514cd2012-11-16 14:33:47 -080062 }
Tim Murraycaf41262013-12-13 12:54:37 -080063 ain->copy1DRangeFrom(0, t->getCount(), buf);
Stephen Hines43514cd2012-11-16 14:33:47 -080064 delete [] buf;
65
Tim Murraycaf41262013-12-13 12:54:37 -080066 sc->forEach_root(ain, aout);
Stephen Hines43514cd2012-11-16 14:33:47 -080067
Tim Murraycaf41262013-12-13 12:54:37 -080068 sc->invoke_foo(99, 3.1f);
69 sc->set_g_f(39.9f);
70 sc->set_g_i(-14);
71 sc->invoke_foo(99, 3.1f);
72 printf("for each done\n");
73
74 sc->invoke_bar(47, -3, 'c', -7, 14, -8);
75
76 // Verify a simple kernel.
77 {
78 static const uint32_t xDim = 7;
79 static const uint32_t yDim = 7;
80 sp<const Element> e = Element::I32(rs);
81 Type::Builder tb(rs, e);
82 tb.setX(xDim);
83 tb.setY(yDim);
84 sp<const Type> t = tb.create();
85 sp<Allocation> kern1_in = Allocation::createTyped(rs, t);
86 sp<Allocation> kern1_out = Allocation::createTyped(rs, t);
87
88 int *buf = new int[t->getCount()];
89 for (uint32_t ct=0; ct < t->getCount(); ct++) {
90 buf[ct] = 5;
91 }
92 kern1_in->copy2DRangeFrom(0, 0, xDim, yDim, buf);
93 delete [] buf;
94
95 sc->forEach_kern1(kern1_in, kern1_out);
96 sc->forEach_verify_kern1(kern1_out);
97
98 rs->finish();
99 failed_alloc->copy1DTo(&failed);
100 }
Stephen Hines43514cd2012-11-16 14:33:47 -0800101 }
102
Stephen Hines8a588bd2013-11-26 15:38:31 -0800103 return failed;
104}
105
106int main() {
107 bool failed = test_compute();
Stephen Hines43514cd2012-11-16 14:33:47 -0800108
109 if (failed) {
110 printf("TEST FAILED!\n");
111 } else {
112 printf("TEST PASSED!\n");
113 }
114
115 return failed;
Jason Sams221a4b12012-02-22 15:22:41 -0800116}