rsd_cpu.h revision 44bef6fba6244292b751387f3d6c31cca96c28ad
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 23namespace llvm { 24 25class Module; 26 27} // end namespace llvm 28 29namespace bcc { 30 31class RSCompilerDriver; 32class RSScript; 33typedef llvm::Module* (*RSLinkRuntimeCallback) 34 (bcc::RSScript *, llvm::Module *, llvm::Module *); 35 36} // end namespace bcc; 37 38typedef const char* (*RSSelectRTCallback) (const char*, size_t); 39 40typedef void (*RSSetupCompilerCallback) (bcc::RSCompilerDriver *); 41#endif 42 43namespace android { 44namespace renderscript { 45 46class ScriptC; 47class Script; 48class ScriptGroup; 49class ScriptKernelID; 50 51 52class RsdCpuReference { 53public: 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 73 virtual void invokeForEach(uint32_t slot, 74 const Allocation ** ains, 75 uint32_t inLen, 76 Allocation * aout, 77 const void * usr, 78 uint32_t usrLen, 79 const RsScriptCall *sc) = 0; 80 81 virtual void invokeInit() = 0; 82 virtual void invokeFreeChildren() = 0; 83 84 virtual void setGlobalVar(uint32_t slot, const void *data, size_t dataLength) = 0; 85 virtual void getGlobalVar(uint32_t slot, void *data, size_t dataLength) = 0; 86 virtual void setGlobalVarWithElemDims(uint32_t slot, const void *data, size_t dataLength, 87 const Element *e, const uint32_t *dims, size_t dimLength) = 0; 88 virtual void setGlobalBind(uint32_t slot, Allocation *data) = 0; 89 virtual void setGlobalObj(uint32_t slot, ObjectBase *obj) = 0; 90 91 virtual Allocation * getAllocationForPointer(const void *ptr) const = 0; 92 virtual ~CpuScript() {} 93 94#ifndef RS_COMPATIBILITY_LIB 95 virtual void * getRSExecutable() = 0; 96#endif 97 }; 98 typedef CpuScript * (* script_lookup_t)(Context *, const Script *s); 99 100 class CpuScriptGroup { 101 public: 102 virtual void setInput(const ScriptKernelID *kid, Allocation *) = 0; 103 virtual void setOutput(const ScriptKernelID *kid, Allocation *) = 0; 104 virtual void execute() = 0; 105 virtual ~CpuScriptGroup() {}; 106 }; 107 108 static Context * getTlsContext(); 109 static const Script * getTlsScript(); 110 static pthread_key_t getThreadTLSKey(); 111 112 static RsdCpuReference * create(Context *c, uint32_t version_major, 113 uint32_t version_minor, sym_lookup_t lfn, script_lookup_t slfn 114#ifndef RS_COMPATIBILITY_LIB 115 , bcc::RSLinkRuntimeCallback pLinkRuntimeCallback = nullptr, 116 RSSelectRTCallback pSelectRTCallback = nullptr, 117 const char *pBccPluginName = nullptr 118#endif 119 ); 120 virtual ~RsdCpuReference(); 121 virtual void setPriority(int32_t priority) = 0; 122 123 virtual CpuScript * createScript(const ScriptC *s, char const *resName, char const *cacheDir, 124 uint8_t const *bitcode, size_t bitcodeSize, 125 uint32_t flags) = 0; 126 virtual CpuScript * createIntrinsic(const Script *s, RsScriptIntrinsicID iid, Element *e) = 0; 127 virtual CpuScriptGroup * createScriptGroup(const ScriptGroup *sg) = 0; 128 virtual bool getInForEach() = 0; 129 130#ifndef RS_COMPATIBILITY_LIB 131 virtual void setSetupCompilerCallback( 132 RSSetupCompilerCallback pSetupCompilerCallback) = 0; 133 virtual RSSetupCompilerCallback getSetupCompilerCallback() const = 0; 134#endif 135}; 136 137 138} 139} 140 141#endif 142