1/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.rs.unittest;
18
19import android.content.Context;
20import android.renderscript.Allocation;
21import android.renderscript.Element;
22import android.renderscript.RenderScript;
23import android.renderscript.Type;
24
25public class UT_kernel3d extends UnitTest {
26    private Type T;
27    private Allocation A;
28    private Allocation B;
29
30    public UT_kernel3d(Context ctx) {
31        super("Kernel 3d (pass-by-value)", ctx);
32    }
33
34    private void initializeGlobals(RenderScript RS, ScriptC_kernel3d s) {
35        Type.Builder typeBuilder = new Type.Builder(RS, Element.I32(RS));
36        int X = 2;
37        s.set_gDimX(X);
38        typeBuilder.setX(X);
39        int Y = 5;
40        s.set_gDimY(Y);
41        typeBuilder.setY(Y);
42        int Z = 11;
43        s.set_gDimZ(Z);
44        typeBuilder.setZ(Z);
45
46        T = typeBuilder.create();
47        A = Allocation.createTyped(RS, T);
48        s.set_A(A);
49        B = Allocation.createTyped(RS, T);
50        s.set_B(B);
51        return;
52    }
53
54    public void run() {
55        RenderScript pRS = createRenderScript(true);
56        ScriptC_kernel3d s = new ScriptC_kernel3d(pRS);
57        initializeGlobals(pRS, s);
58        s.forEach_init_vars(A);
59        s.forEach_root(A, B);
60        s.invoke_verify_root();
61        s.invoke_kernel_test();
62        pRS.finish();
63        T.destroy();
64        A.destroy();
65        B.destroy();
66        s.destroy();
67        pRS.destroy();
68    }
69}
70