rsdBcc.cpp 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /*
  2. * Copyright (C) 2011-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. #include "../cpu_ref/rsd_cpu.h"
  17. #include "rsdCore.h"
  18. #include "rsdBcc.h"
  19. #include "rsdAllocation.h"
  20. #include "rsContext.h"
  21. #include "rsElement.h"
  22. #include "rsScriptC.h"
  23. using android::renderscript::Allocation;
  24. using android::renderscript::Context;
  25. using android::renderscript::Element;
  26. using android::renderscript::ObjectBase;
  27. using android::renderscript::RsdCpuReference;
  28. using android::renderscript::Script;
  29. using android::renderscript::ScriptC;
  30. using android::renderscript::rs_script;
  31. bool rsdScriptInit(const Context *rsc,
  32. ScriptC *script,
  33. char const *resName,
  34. char const *cacheDir,
  35. uint8_t const *bitcode,
  36. size_t bitcodeSize,
  37. uint32_t flags) {
  38. RsdHal *dc = (RsdHal *)rsc->mHal.drv;
  39. RsdCpuReference::CpuScript * cs =
  40. dc->mCpuRef->createScript(script, resName, cacheDir, bitcode,
  41. bitcodeSize, flags);
  42. if (cs == nullptr) {
  43. return false;
  44. }
  45. script->mHal.drv = cs;
  46. cs->populateScript(script);
  47. return true;
  48. }
  49. bool rsdInitIntrinsic(const Context *rsc, Script *s, RsScriptIntrinsicID iid,
  50. Element *e) {
  51. RsdHal *dc = (RsdHal *)rsc->mHal.drv;
  52. RsdCpuReference::CpuScript * cs = dc->mCpuRef->createIntrinsic(s, iid, e);
  53. if (cs == nullptr) {
  54. return false;
  55. }
  56. s->mHal.drv = cs;
  57. cs->populateScript(s);
  58. return true;
  59. }
  60. void rsdScriptInvokeForEach(const Context *rsc,
  61. Script *s,
  62. uint32_t slot,
  63. const Allocation * ain,
  64. Allocation * aout,
  65. const void * usr,
  66. size_t usrLen,
  67. const RsScriptCall *sc) {
  68. if (ain == nullptr) {
  69. rsdScriptInvokeForEachMulti(rsc, s, slot, nullptr, 0, aout, usr, usrLen,
  70. sc);
  71. } else {
  72. const Allocation *ains[1] = {ain};
  73. rsdScriptInvokeForEachMulti(rsc, s, slot, ains, 1, aout, usr, usrLen,
  74. sc);
  75. }
  76. }
  77. void rsdScriptInvokeForEachMulti(const Context *rsc,
  78. Script *s,
  79. uint32_t slot,
  80. const Allocation ** ains,
  81. size_t inLen,
  82. Allocation * aout,
  83. const void * usr,
  84. size_t usrLen,
  85. const RsScriptCall *sc) {
  86. RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv;
  87. cs->invokeForEach(slot, ains, inLen, aout, usr, usrLen, sc);
  88. }
  89. int rsdScriptInvokeRoot(const Context *dc, Script *s) {
  90. RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv;
  91. return cs->invokeRoot();
  92. }
  93. void rsdScriptInvokeInit(const Context *dc, Script *s) {
  94. RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv;
  95. cs->invokeInit();
  96. }
  97. void rsdScriptInvokeFreeChildren(const Context *dc, Script *s) {
  98. RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv;
  99. cs->invokeFreeChildren();
  100. }
  101. void rsdScriptInvokeFunction(const Context *dc, Script *s,
  102. uint32_t slot,
  103. const void *params,
  104. size_t paramLength) {
  105. RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv;
  106. cs->invokeFunction(slot, params, paramLength);
  107. }
  108. void rsdScriptInvokeReduce(const Context *dc, Script *s,
  109. uint32_t slot,
  110. const Allocation ** ains, size_t inLen,
  111. Allocation *aout,
  112. const RsScriptCall *sc) {
  113. RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv;
  114. cs->invokeReduce(slot, ains, inLen, aout, sc);
  115. }
  116. void rsdScriptSetGlobalVar(const Context *dc, const Script *s,
  117. uint32_t slot, void *data, size_t dataLength) {
  118. RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv;
  119. cs->setGlobalVar(slot, data, dataLength);
  120. }
  121. void rsdScriptGetGlobalVar(const Context *dc, const Script *s,
  122. uint32_t slot, void *data, size_t dataLength) {
  123. RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv;
  124. cs->getGlobalVar(slot, data, dataLength);
  125. }
  126. void rsdScriptSetGlobalVarWithElemDims(const Context *dc, const Script *s,
  127. uint32_t slot, void *data, size_t dataLength,
  128. const android::renderscript::Element *elem,
  129. const uint32_t *dims, size_t dimLength) {
  130. RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv;
  131. cs->setGlobalVarWithElemDims(slot, data, dataLength, elem, dims, dimLength);
  132. }
  133. void rsdScriptSetGlobalBind(const Context *dc, const Script *s, uint32_t slot, Allocation *data) {
  134. RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv;
  135. cs->setGlobalBind(slot, data);
  136. }
  137. void rsdScriptSetGlobalObj(const Context *dc, const Script *s, uint32_t slot, ObjectBase *data) {
  138. RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv;
  139. cs->setGlobalObj(slot, data);
  140. }
  141. void rsdScriptDestroy(const Context *dc, Script *s) {
  142. RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv;
  143. delete cs;
  144. s->mHal.drv = nullptr;
  145. }
  146. Allocation * rsdScriptGetAllocationForPointer(const android::renderscript::Context *dc,
  147. const android::renderscript::Script *sc,
  148. const void *ptr) {
  149. RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)sc->mHal.drv;
  150. return cs->getAllocationForPointer(ptr);
  151. }
  152. void rsdScriptUpdateCachedObject(const Context *rsc,
  153. const Script *script,
  154. rs_script *obj)
  155. {
  156. obj->p = script;
  157. #ifdef __LP64__
  158. obj->unused1 = nullptr;
  159. obj->unused2 = nullptr;
  160. obj->unused3 = nullptr;
  161. #endif
  162. }