1 /* 2 * Copyright (C) 2016 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 17 #pragma version(1) 18 #pragma rs java_package_name(com.android.rs.singlesource) 19 #pragma rs_fp_full 20 21 // global allocation used for void kernel 22 rs_allocation global_alloc; 23 24 static void check_in() 25 { 26 // debugger check point 27 return; 28 } 29 30 float __attribute__((kernel)) kernel_1(float a) 31 { 32 // square 33 return a * a; 34 } 35 36 float __attribute__((kernel)) kernel_2(float a, float b) 37 { 38 // product 39 return a * b; 40 } 41 42 void __attribute__((kernel)) void_kernel_1(uint32_t x) 43 { 44 // allocation[x] = x 45 rsSetElementAt_float(global_alloc, (float)x, x); 46 } 47 48 void script_invoke_1(rs_allocation out, rs_allocation in1, rs_allocation in2) 49 { 50 // invoke kernel taking one argument 51 rsForEach(kernel_1, out, in1); 52 53 check_in(); 54 55 // invoke kernel taking two arguments 56 rsForEach(kernel_2, out, in1, in2); 57 58 check_in(); 59 } 60 61 void script_invoke_2() 62 { 63 // invoke kernel that takes no arguments and no return type 64 rs_script_call_t options = { 65 .strategy=RS_FOR_EACH_STRATEGY_DONT_CARE, 66 .xStart=0, 67 .xEnd=4 68 }; 69 rsForEachWithOptions(void_kernel_1, &options); 70 71 check_in(); 72 } 73