summaryrefslogtreecommitdiff
path: root/tests/lldb/cpp/KernelVariables/KernelVariables.cpp
blob: 095c1adaa19266e9160309451350c1a2a38d0db5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <RenderScript.h>

#include "ScriptC_simple.h"

int main()
{
    static const int size = 64;
    sp<RS> rs = new RS();

    rs->init("/data/rscache", RS_INIT_LOW_LATENCY | RS_INIT_WAIT_FOR_ATTACH);

    auto e = Element::RGBA_8888(rs);
    Type::Builder tb(rs, e);
    tb.setX(size);
    tb.setY(size);
    auto t = tb.create();

    auto a = Allocation::createTyped(rs, t);
    auto b = Allocation::createTyped(rs, t);

    sp<ScriptC_simple> s = new ScriptC_simple(rs);

    static const int buffer_int[] = {1, 2, 3, 4};
    sp<Allocation> int_allocation = Allocation::createSized(rs, Element::I32(rs), 4);
    int_allocation->copy1DRangeFrom(0, 4, buffer_int);
    s->set_allocation_1D_global(int_allocation);

    static const int buffer_int2[] = {5, 6, 7, 8};

    Type::Builder typeI32Builder2D(rs, Element::I32(rs));
    typeI32Builder2D.setX(2);
    typeI32Builder2D.setY(2);

    sp<Allocation> int_allocation2 = Allocation::createTyped(rs, typeI32Builder2D.create());
    int_allocation2->copy2DRangeFrom(0, 0, 2, 2, buffer_int2);
    s->set_allocation_1D_global2(int_allocation2);

    s->set_allocation_2D_global(a);
    s->set_allocation_2D_global2(b);

    static const int buffer_int3[] = {9, 10, 11, 12, 13, 14, 15, 16};

    Type::Builder typeI32Builder3D(rs, Element::I32(rs));
    typeI32Builder3D.setX(2);
    typeI32Builder3D.setY(2);
    typeI32Builder3D.setZ(2);

    sp<Allocation> int_allocation3 = Allocation::createTyped(rs, typeI32Builder3D.create());
    int_allocation3->copy3DRangeFrom(0, 0, 0, 2, 2, 2, buffer_int3);
    s->set_allocation_3D_global(int_allocation3);

    Type::Builder yuvTypeBuilder(rs, Element::YUV(rs));
    yuvTypeBuilder.setX(4);
    yuvTypeBuilder.setY(4);
    yuvTypeBuilder.setYuvFormat(RS_YUV_YV12);

    sp<Allocation> yuv_allocation = Allocation::createTyped(rs, yuvTypeBuilder.create());
    s->set_allocation_YUV_2D_global(yuv_allocation);

    s->set_sampler_global(Sampler::CLAMP_LINEAR(rs));

    // Script is executed once, then the data is copied back when finished
    s->forEach_kernel(a, b);
    rs->finish();
    uint32_t * output = new uint32_t[size*size];
    b->copy2DRangeTo(0, 0, size, size, output);
    delete [] output;

    return 0;
}