Home | History | Annotate | Download | only in cppbasic-getpointer
      1 
      2 #include "RenderScript.h"
      3 
      4 #include "ScriptC_mono.h"
      5 
      6 #include <stdlib.h>
      7 
      8 const uint32_t DIMX = 128;
      9 const uint32_t DIMY = 128;
     10 
     11 int test_compute()
     12 {
     13     bool failed = false;
     14 
     15     sp<RS> rs = new RS();
     16     printf("New RS %p\n", rs.get());
     17 
     18     // only legitimate because this is a standalone executable
     19     bool r = rs->init("/system/bin");
     20     printf("Init returned %i\n", r);
     21 
     22     sp<const Element> e = Element::U32(rs);
     23     printf("Element %p\n", e.get());
     24 
     25     Type::Builder tb(rs, e);
     26     tb.setX(DIMX);
     27     tb.setY(DIMY);
     28     sp<const Type> t = tb.create();
     29     printf("Type %p\n", t.get());
     30 
     31 
     32     sp<Allocation> a1 = Allocation::createSized(rs, e, 1000);
     33     printf("Allocation %p\n", a1.get());
     34 
     35     sp<Allocation> ain = Allocation::createTyped(rs, t, RS_ALLOCATION_USAGE_SCRIPT | RS_ALLOCATION_USAGE_SHARED);
     36     sp<Allocation> aout = Allocation::createTyped(rs, t, RS_ALLOCATION_USAGE_SCRIPT | RS_ALLOCATION_USAGE_SHARED);
     37     printf("Allocation %p %p\n", ain.get(), aout.get());
     38 
     39     size_t inputStride, outputStride;
     40 
     41     uint32_t *input = (uint32_t*)ain->getPointer(&inputStride);
     42     uint32_t *output = (uint32_t*)aout->getPointer(&outputStride);
     43 
     44     printf("Input pointer: %p\n", input);
     45     printf("Input stride: %zu\n", inputStride);
     46     printf("Output pointer: %p\n", output);
     47     printf("Output stride: %zu\n", outputStride);
     48 
     49     inputStride /= sizeof(uint32_t);
     50     outputStride /= sizeof(uint32_t);
     51 
     52     for (size_t i = 0; i < DIMY; i++) {
     53         for (size_t j = 0; j < DIMX; j++) {
     54             input[i * inputStride + j] = rand();
     55             output[i * inputStride + j] = 0;
     56         }
     57     }
     58 
     59     ain->syncAll(RS_ALLOCATION_USAGE_SHARED);
     60     aout->syncAll(RS_ALLOCATION_USAGE_SHARED);
     61 
     62     printf("Launching script\n");
     63 
     64     sp<ScriptC_mono> sc = new ScriptC_mono(rs);
     65     sc->forEach_copyAndNot(ain, aout);
     66     rs->finish();
     67 
     68     printf("Script completed\n");
     69 
     70     ain->syncAll(RS_ALLOCATION_USAGE_SCRIPT);
     71     aout->syncAll(RS_ALLOCATION_USAGE_SCRIPT);
     72 
     73     for (size_t i = 0; i < DIMY; i++) {
     74         for (size_t j = 0; j < DIMX; j++) {
     75             if (input[i * inputStride + j] != ~(output[i * inputStride + j])) {
     76                 printf("Mismatch at location %zu, %zu\n", j, i);
     77                 failed = true;
     78                 return failed;
     79             }
     80         }
     81     }
     82 
     83 
     84     return failed;
     85 }
     86 
     87 int main() {
     88     bool failed = test_compute();
     89 
     90     if (failed) {
     91         printf("TEST FAILED!\n");
     92     } else {
     93         printf("TEST PASSED!\n");
     94     }
     95 
     96     return failed;
     97 }
     98