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