Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1 | /* |
Stephen Hines | 4419977 | 2012-02-21 20:13:12 -0800 | [diff] [blame] | 2 | * Copyright (C) 2009-2012 The Android Open Source Project |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 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 | #ifndef ANDROID_RS_SCRIPT_H |
| 18 | #define ANDROID_RS_SCRIPT_H |
| 19 | |
| 20 | #include "rsAllocation.h" |
Yang Ni | c31585b | 2015-02-15 11:43:50 -0800 | [diff] [blame] | 21 | #include "rsMap.h" |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 22 | |
Tobias Grosser | 47935ac | 2013-06-17 11:47:26 -0700 | [diff] [blame] | 23 | #include <utility> |
Jason Sams | a0a1b6f | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 24 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 25 | // --------------------------------------------------------------------------- |
| 26 | namespace android { |
| 27 | namespace renderscript { |
| 28 | |
Miao Wang | 59f6142 | 2017-03-14 14:23:52 -0700 | [diff] [blame] | 29 | #if !defined(RS_VENDOR_LIB) && !defined(RS_COMPATIBILITY_LIB) |
Jason Sams | a0a1b6f | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 30 | class ProgramVertex; |
| 31 | class ProgramFragment; |
| 32 | class ProgramRaster; |
Jason Sams | ccc010b | 2010-05-13 18:30:11 -0700 | [diff] [blame] | 33 | class ProgramStore; |
Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 34 | #endif |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 35 | |
Yang Ni | eb9aa67 | 2015-01-27 14:32:25 -0800 | [diff] [blame] | 36 | class IDBase : public ObjectBase { |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 37 | public: |
Yang Ni | eb9aa67 | 2015-01-27 14:32:25 -0800 | [diff] [blame] | 38 | IDBase(Context *rsc, Script *s, int slot) : |
| 39 | ObjectBase(rsc), mScript(s), mSlot(slot) {} |
| 40 | virtual ~IDBase() {} |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 41 | |
Yang Ni | eb9aa67 | 2015-01-27 14:32:25 -0800 | [diff] [blame] | 42 | virtual void serialize(Context *rsc, OStream *stream) const {} |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 43 | virtual RsA3DClassID getClassId() const; |
| 44 | |
| 45 | Script *mScript; |
| 46 | int mSlot; |
Yang Ni | eb9aa67 | 2015-01-27 14:32:25 -0800 | [diff] [blame] | 47 | }; |
| 48 | |
| 49 | class ScriptKernelID : public IDBase { |
| 50 | public: |
| 51 | ScriptKernelID(Context *rsc, Script *s, int slot, int sig); |
| 52 | virtual ~ScriptKernelID() {} |
| 53 | |
| 54 | virtual RsA3DClassID getClassId() const; |
| 55 | |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 56 | bool mHasKernelInput; |
| 57 | bool mHasKernelOutput; |
| 58 | }; |
| 59 | |
Yang Ni | eb9aa67 | 2015-01-27 14:32:25 -0800 | [diff] [blame] | 60 | class ScriptInvokeID : public IDBase { |
| 61 | public: |
| 62 | ScriptInvokeID(Context *rsc, Script *s, int slot); |
| 63 | virtual ~ScriptInvokeID() {} |
| 64 | |
| 65 | virtual RsA3DClassID getClassId() const; |
| 66 | }; |
| 67 | |
| 68 | class ScriptFieldID : public IDBase { |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 69 | public: |
| 70 | ScriptFieldID(Context *rsc, Script *s, int slot); |
Yang Ni | eb9aa67 | 2015-01-27 14:32:25 -0800 | [diff] [blame] | 71 | virtual ~ScriptFieldID() {} |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 72 | |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 73 | virtual RsA3DClassID getClassId() const; |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 74 | }; |
| 75 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 76 | class Script : public ObjectBase { |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 77 | public: |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 78 | |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 79 | struct Hal { |
| 80 | void * drv; |
| 81 | |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 82 | struct DriverInfo { |
| 83 | int mVersionMajor; |
| 84 | int mVersionMinor; |
| 85 | |
| 86 | size_t exportedVariableCount; |
Matt Wala | 14ce007 | 2015-07-30 17:30:25 -0700 | [diff] [blame] | 87 | size_t exportedForEachCount; |
| 88 | size_t exportedReduceCount; |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 89 | size_t exportedFunctionCount; |
| 90 | size_t exportedPragmaCount; |
| 91 | char const **exportedPragmaKeyList; |
| 92 | char const **exportedPragmaValueList; |
Yang Ni | c31585b | 2015-02-15 11:43:50 -0800 | [diff] [blame] | 93 | const Pair<const char *, uint32_t> *exportedForeachFuncList; |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 94 | |
| 95 | int (* root)(); |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 96 | }; |
| 97 | DriverInfo info; |
| 98 | }; |
| 99 | Hal mHal; |
| 100 | |
Chih-Hung Hsieh | 10ab8bb | 2016-07-01 12:20:20 -0700 | [diff] [blame] | 101 | explicit Script(Context *); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 102 | virtual ~Script(); |
| 103 | |
Jason Sams | 928b734 | 2009-06-08 18:50:13 -0700 | [diff] [blame] | 104 | struct Enviroment_t { |
Jason Sams | ef5867a | 2010-07-28 11:17:53 -0700 | [diff] [blame] | 105 | int64_t mStartTimeMillis; |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 106 | mutable int64_t mLastDtTime; |
Romain Guy | 98e10fd | 2009-07-30 18:45:01 -0700 | [diff] [blame] | 107 | |
Miao Wang | 59f6142 | 2017-03-14 14:23:52 -0700 | [diff] [blame] | 108 | #if !defined(RS_VENDOR_LIB) && !defined(RS_COMPATIBILITY_LIB) |
Jason Sams | a0a1b6f | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 109 | ObjectBaseRef<ProgramVertex> mVertex; |
| 110 | ObjectBaseRef<ProgramFragment> mFragment; |
Jason Sams | b681c8a | 2009-09-28 18:12:56 -0700 | [diff] [blame] | 111 | ObjectBaseRef<ProgramRaster> mRaster; |
Jason Sams | ccc010b | 2010-05-13 18:30:11 -0700 | [diff] [blame] | 112 | ObjectBaseRef<ProgramStore> mFragmentStore; |
Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 113 | #endif |
Jason Sams | 928b734 | 2009-06-08 18:50:13 -0700 | [diff] [blame] | 114 | }; |
| 115 | Enviroment_t mEnviroment; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 116 | |
Alex Sakhartchouk | 700ba38 | 2010-10-08 15:00:05 -0700 | [diff] [blame] | 117 | void setSlot(uint32_t slot, Allocation *a); |
Alex Sakhartchouk | b81a0eb | 2011-06-03 10:18:01 -0700 | [diff] [blame] | 118 | void setVar(uint32_t slot, const void *val, size_t len); |
Tim Murray | 9c64239 | 2013-04-11 13:29:59 -0700 | [diff] [blame] | 119 | void getVar(uint32_t slot, const void *val, size_t len); |
Stephen Hines | 2980f07 | 2012-04-09 18:26:29 -0700 | [diff] [blame] | 120 | void setVar(uint32_t slot, const void *val, size_t len, Element *e, |
Stephen Hines | f0a5078 | 2014-06-25 13:41:10 -0700 | [diff] [blame] | 121 | const uint32_t *dims, size_t dimLen); |
Jason Sams | a5eb6e1 | 2010-11-16 17:37:02 -0800 | [diff] [blame] | 122 | void setVarObj(uint32_t slot, ObjectBase *val); |
Jason Sams | 8c6bc69 | 2009-09-16 15:04:38 -0700 | [diff] [blame] | 123 | |
Stephen Hines | 4ee16ff | 2011-08-31 17:41:39 -0700 | [diff] [blame] | 124 | virtual bool freeChildren(); |
| 125 | |
Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame] | 126 | virtual void runForEach(Context* rsc, |
| 127 | uint32_t slot, |
Chris Wailes | f371213 | 2014-07-16 15:18:30 -0700 | [diff] [blame] | 128 | const Allocation ** ains, |
Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame] | 129 | size_t inLen, |
| 130 | Allocation* aout, |
| 131 | const void* usr, |
| 132 | size_t usrBytes, |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 133 | const RsScriptCall *sc = nullptr) = 0; |
Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame] | 134 | |
David Gross | fc7ab79 | 2016-06-01 14:45:47 -0700 | [diff] [blame] | 135 | virtual void runReduce(Context *rsc, uint32_t slot, |
| 136 | const Allocation **ains, size_t inLen, |
Matt Wala | 14ce007 | 2015-07-30 17:30:25 -0700 | [diff] [blame] | 137 | Allocation *aout, const RsScriptCall *sc) = 0; |
| 138 | |
Alex Sakhartchouk | b81a0eb | 2011-06-03 10:18:01 -0700 | [diff] [blame] | 139 | virtual void Invoke(Context *rsc, uint32_t slot, const void *data, size_t len) = 0; |
Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 140 | virtual void setupScript(Context *rsc) = 0; |
| 141 | virtual uint32_t run(Context *) = 0; |
Yang Ni | da0f069 | 2015-01-12 13:03:40 -0800 | [diff] [blame] | 142 | virtual bool isIntrinsic() const { return false; } |
Stephen Hines | c78839b | 2013-09-10 17:40:41 -0700 | [diff] [blame] | 143 | |
| 144 | bool hasObjectSlots() const { |
| 145 | return mHasObjectSlots; |
| 146 | } |
Jason Sams | a36c50a | 2014-06-17 12:06:06 -0700 | [diff] [blame] | 147 | virtual void callUpdateCacheObject(const Context *rsc, void *dstObj) const; |
| 148 | |
Stephen Hines | 5d95a78 | 2015-04-13 20:11:48 -0700 | [diff] [blame] | 149 | uint32_t getApiLevel() const { |
| 150 | return mApiLevel; |
| 151 | } |
| 152 | |
Alex Sakhartchouk | 700ba38 | 2010-10-08 15:00:05 -0700 | [diff] [blame] | 153 | protected: |
Jason Sams | 77020c5 | 2011-11-22 12:49:11 -0800 | [diff] [blame] | 154 | bool mInitialized; |
Stephen Hines | c78839b | 2013-09-10 17:40:41 -0700 | [diff] [blame] | 155 | bool mHasObjectSlots; |
Stephen Hines | 5d95a78 | 2015-04-13 20:11:48 -0700 | [diff] [blame] | 156 | uint32_t mApiLevel; |
Alex Sakhartchouk | 700ba38 | 2010-10-08 15:00:05 -0700 | [diff] [blame] | 157 | ObjectBaseRef<Allocation> *mSlots; |
| 158 | ObjectBaseRef<const Type> *mTypes; |
| 159 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 160 | }; |
| 161 | |
| 162 | |
Rahul Chaudhry | 7974fc0 | 2017-02-09 12:33:28 -0800 | [diff] [blame] | 163 | } // namespace renderscript |
| 164 | } // namespace android |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 165 | #endif |