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