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 #ifndef RSD_CPU_H 18 #define RSD_CPU_H 19 20 #include "rsAllocation.h" 21 22 #ifndef RS_COMPATIBILITY_LIB 23 namespace llvm { 24 25 class Module; 26 27 } // end namespace llvm 28 29 namespace bcc { 30 31 class RSCompilerDriver; 32 class RSScript; 33 typedef llvm::Module* (*RSLinkRuntimeCallback) 34 (bcc::RSScript *, llvm::Module *, llvm::Module *); 35 36 } // end namespace bcc; 37 38 typedef const char* (*RSSelectRTCallback) (const char*, size_t); 39 40 typedef void (*RSSetupCompilerCallback) (bcc::RSCompilerDriver *); 41 #endif 42 43 namespace android { 44 namespace renderscript { 45 46 class ScriptC; 47 class Script; 48 class ScriptGroup; 49 class ScriptKernelID; 50 51 52 class RsdCpuReference { 53 public: 54 struct CpuSymbol { 55 const char * name; 56 void * fnPtr; 57 bool threadable; 58 }; 59 60 typedef const CpuSymbol * (* sym_lookup_t)(Context *, const char *name); 61 62 struct CpuTls { 63 Context *rsc; 64 const ScriptC * sc; 65 }; 66 67 class CpuScript { 68 public: 69 virtual void populateScript(Script *) = 0; 70 virtual void invokeFunction(uint32_t slot, const void *params, size_t paramLength) = 0; 71 virtual int invokeRoot() = 0; 72 virtual void invokeForEach(uint32_t slot, 73 const Allocation * ain, 74 Allocation * aout, 75 const void * usr, 76 uint32_t usrLen, 77 const RsScriptCall *sc) = 0; 78 virtual void invokeInit() = 0; 79 virtual void invokeFreeChildren() = 0; 80 81 virtual void setGlobalVar(uint32_t slot, const void *data, size_t dataLength) = 0; 82 virtual void getGlobalVar(uint32_t slot, void *data, size_t dataLength) = 0; 83 virtual void setGlobalVarWithElemDims(uint32_t slot, const void *data, size_t dataLength, 84 const Element *e, const size_t *dims, size_t dimLength) = 0; 85 virtual void setGlobalBind(uint32_t slot, Allocation *data) = 0; 86 virtual void setGlobalObj(uint32_t slot, ObjectBase *obj) = 0; 87 88 virtual Allocation * getAllocationForPointer(const void *ptr) const = 0; 89 virtual ~CpuScript() {} 90 91 #ifndef RS_COMPATIBILITY_LIB 92 virtual void * getRSExecutable() = 0; 93 #endif 94 }; 95 typedef CpuScript * (* script_lookup_t)(Context *, const Script *s); 96 97 class CpuScriptGroup { 98 public: 99 virtual void setInput(const ScriptKernelID *kid, Allocation *) = 0; 100 virtual void setOutput(const ScriptKernelID *kid, Allocation *) = 0; 101 virtual void execute() = 0; 102 virtual ~CpuScriptGroup() {}; 103 }; 104 105 static Context * getTlsContext(); 106 static const Script * getTlsScript(); 107 static pthread_key_t getThreadTLSKey(); 108 109 static RsdCpuReference * create(Context *c, uint32_t version_major, 110 uint32_t version_minor, sym_lookup_t lfn, script_lookup_t slfn 111 #ifndef RS_COMPATIBILITY_LIB 112 , bcc::RSLinkRuntimeCallback pLinkRuntimeCallback = NULL, 113 RSSelectRTCallback pSelectRTCallback = NULL 114 #endif 115 ); 116 virtual ~RsdCpuReference(); 117 virtual void setPriority(int32_t priority) = 0; 118 119 virtual CpuScript * createScript(const ScriptC *s, char const *resName, char const *cacheDir, 120 uint8_t const *bitcode, size_t bitcodeSize, 121 uint32_t flags) = 0; 122 virtual CpuScript * createIntrinsic(const Script *s, RsScriptIntrinsicID iid, Element *e) = 0; 123 virtual CpuScriptGroup * createScriptGroup(const ScriptGroup *sg) = 0; 124 virtual bool getInForEach() = 0; 125 126 #ifndef RS_COMPATIBILITY_LIB 127 virtual void setSetupCompilerCallback( 128 RSSetupCompilerCallback pSetupCompilerCallback) = 0; 129 virtual RSSetupCompilerCallback getSetupCompilerCallback() const = 0; 130 #endif 131 }; 132 133 134 } 135 } 136 137 #endif 138