Tim Murray | 16b9512 | 2012-10-31 16:02:59 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 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) |
Tim Murray | 4a92d12 | 2013-07-22 10:56:18 -0700 | [diff] [blame] | 18 | #pragma rs java_package_name(com.android.rs.cppbasic) |
Tim Murray | 16b9512 | 2012-10-31 16:02:59 -0700 | [diff] [blame] | 19 | #pragma rs_fp_relaxed |
| 20 | |
Stephen Hines | 43514cd | 2012-11-16 14:33:47 -0800 | [diff] [blame] | 21 | int g_i = 4; |
| 22 | |
| 23 | float g_f = 5.9; |
| 24 | |
Tim Murray | 16b9512 | 2012-10-31 16:02:59 -0700 | [diff] [blame] | 25 | const static float3 gMonoMult = {0.299f, 0.587f, 0.114f}; |
| 26 | |
Stephen Hines | 43514cd | 2012-11-16 14:33:47 -0800 | [diff] [blame] | 27 | bool *failed; |
| 28 | |
| 29 | #define _RS_ASSERT(b) \ |
| 30 | do { \ |
| 31 | if (!(b)) { \ |
| 32 | *failed = true; \ |
| 33 | rsDebug(#b " FAILED", 0); \ |
| 34 | } \ |
| 35 | \ |
| 36 | } while (0) |
| 37 | |
| 38 | struct myStruct { |
| 39 | int i; |
| 40 | int j; |
| 41 | float f; |
| 42 | char c[3]; |
| 43 | }; |
| 44 | |
Stephen Hines | 8a588bd | 2013-11-26 15:38:31 -0800 | [diff] [blame] | 45 | rs_allocation alloc; |
| 46 | rs_element elem; |
| 47 | rs_type type; |
| 48 | rs_sampler sampler; |
| 49 | rs_script script; |
| 50 | |
Tim Murray | 16b9512 | 2012-10-31 16:02:59 -0700 | [diff] [blame] | 51 | void root(const uchar4 *v_in, uchar4 *v_out) { |
| 52 | float4 f4 = rsUnpackColor8888(*v_in); |
| 53 | |
| 54 | float3 mono = dot(f4.rgb, gMonoMult); |
| 55 | *v_out = rsPackColorTo8888(mono); |
| 56 | } |
| 57 | |
Stephen Hines | 43514cd | 2012-11-16 14:33:47 -0800 | [diff] [blame] | 58 | void foo(int i, float f) { |
| 59 | rsDebug("g_i", g_i); |
| 60 | rsDebug("g_f", g_f); |
| 61 | rsDebug("i", i); |
| 62 | rsDebug("f", f); |
| 63 | } |
| 64 | |
| 65 | void bar(int i, int j, char k, int l, int m, int n) { |
| 66 | _RS_ASSERT(i == 47); |
| 67 | _RS_ASSERT(j == -3); |
| 68 | _RS_ASSERT(k == 'c'); |
| 69 | _RS_ASSERT(l == -7); |
| 70 | _RS_ASSERT(m == 14); |
| 71 | _RS_ASSERT(n == -8); |
| 72 | } |
| 73 | |
Chris Wailes | 025b5f8 | 2014-05-22 16:28:59 -0700 | [diff] [blame] | 74 | int RS_KERNEL kern1(int i, uint32_t x, uint32_t y) { |
Stephen Hines | 43514cd | 2012-11-16 14:33:47 -0800 | [diff] [blame] | 75 | return i + 10 * x + 100 *y; |
| 76 | } |
| 77 | |
Chris Wailes | 025b5f8 | 2014-05-22 16:28:59 -0700 | [diff] [blame] | 78 | void RS_KERNEL verify_kern1(int i, uint32_t x, uint32_t y) { |
Stephen Hines | a1302e2 | 2013-09-04 15:53:03 -0700 | [diff] [blame] | 79 | _RS_ASSERT(i == (5 + 10 * x + 100 * y)); |
Stephen Hines | 43514cd | 2012-11-16 14:33:47 -0800 | [diff] [blame] | 80 | rsDebug("i ", i); |
| 81 | } |
Tim Murray | 16b9512 | 2012-10-31 16:02:59 -0700 | [diff] [blame] | 82 | |