1// This file is automatically generated from
2// frameworks/rs/tests/java_api/RSUnitTests/RSUnitTests.py
3/*
4 * Copyright (C) 2017 The Android Open Source Project
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 *      http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19#include "shared.rsh"
20
21int dimX;
22int dimY;
23
24rs_allocation gAllocOut;
25
26void oldFoo(const int* in, int* out, uint32_t x, uint32_t y) {
27  out[0] = in[0] * 3;
28}
29
30int __attribute__((kernel)) foo(int a) {
31    return a * 2;
32}
33
34void oldGoo(const int* a, int* out) {
35  *out = *a + 47;
36}
37
38int __attribute__((kernel)) goo(int a, int b) {
39    return a + b;
40}
41
42void __attribute__((kernel)) bar(int x, int y) {
43  int a = rsGetElementAt_int(gAllocOut, x, y);
44  a++;
45  rsSetElementAt_int(gAllocOut, a, x, y);
46}
47
48void validate(rs_allocation out) {
49    bool failed = false;
50
51    int i, j;
52
53    for (j = 0; j < dimY; j++) {
54        for (i = 0; i < dimX; i++) {
55            const int actual = rsGetElementAt_int(out, i, j);
56            int expected = (i + j * dimX) * 4;
57            if (j < dimY / 2) {
58                expected *= 2;
59            }
60            expected += (i + j * dimX) + 1;
61            expected *= 3;
62            expected += 47;
63            if (actual != expected) {
64                failed = true;
65                rsDebug("row     ", j);
66                rsDebug("column  ", i);
67                rsDebug("expects ", expected);
68                rsDebug("got     ", actual);
69            }
70        }
71    }
72
73    if (failed) {
74        rsDebug("FAILED", 0);
75    } else {
76        rsDebug("PASSED", 0);
77    }
78
79    if (failed) {
80        rsSendToClientBlocking(RS_MSG_TEST_FAILED);
81    } else {
82        rsSendToClientBlocking(RS_MSG_TEST_PASSED);
83    }
84}
85
86void entrypoint(rs_allocation in, rs_allocation out) {
87    int i, j;
88    for (i = 0; i < dimX; i++) {
89        for (j = 0; j < dimY; j++) {
90            rsSetElementAt_int(in, j * dimX + i, i, j);
91        }
92    }
93
94    rsForEach(foo, in, out);
95    rsForEach(foo, out, out);
96
97    rs_script_call_t opts = {0};
98    opts.xStart = 0;
99    opts.xEnd = dimX;
100    opts.yStart = 0;
101    opts.yEnd = dimY / 2;
102    rsForEachWithOptions(foo, &opts, out, out);
103
104    rsForEach(goo, in, out, out);
105
106    gAllocOut = out;
107    rs_script_call_t opts2 = {0};
108    opts2.xStart = 0;
109    opts2.xEnd = dimX;
110    opts2.yStart = 0;
111    opts2.yEnd = dimY;
112    rsForEachWithOptions(bar, &opts2);
113}
114