rsovAllocation.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /*
  2. * Copyright (C) 2016 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. #ifndef RSOV_ALLOCATION_H
  17. #define RSOV_ALLOCATION_H
  18. #include <vulkan/vulkan.h>
  19. #include "rsDefines.h"
  20. #include "rs_hal.h"
  21. #include "system/window.h"
  22. namespace android {
  23. namespace renderscript {
  24. class Allocation;
  25. class Context;
  26. class Type;
  27. namespace rsov {
  28. class RSoVContext;
  29. // Abstraction for a Vulkan Buffer
  30. class RSoVBuffer {
  31. public:
  32. RSoVBuffer(RSoVContext *context, size_t bufferSize);
  33. ~RSoVBuffer();
  34. const VkDescriptorBufferInfo *getBufferInfo() const { return &mBufferInfo; }
  35. char *getHostPtr() const { return mPtr; }
  36. private:
  37. void InitBuffer(size_t);
  38. char *mPtr; // Host pointer to mmapped device memory for the Buffer
  39. RSoVContext *mRSoV;
  40. VkDevice mDevice;
  41. VkDeviceMemory mMem;
  42. VkBuffer mBuf;
  43. VkDescriptorBufferInfo mBufferInfo;
  44. };
  45. class RSoVAllocation {
  46. public:
  47. RSoVAllocation(RSoVContext *context, const Type *type, size_t bufferSize);
  48. ~RSoVAllocation() { delete mBuffer; }
  49. const Type *getType() const { return mType; }
  50. uint32_t getWidth() const { return mWidth; }
  51. uint32_t getHeight() const { return mHeight; }
  52. uint32_t getDepth() const { return mDepth; }
  53. RSoVBuffer *getBuffer() const { return mBuffer; }
  54. char *getHostPtr() const { return mBuffer->getHostPtr(); }
  55. private:
  56. RSoVBuffer *mBuffer;
  57. const Type *mType;
  58. const uint32_t mWidth;
  59. const uint32_t mHeight;
  60. const uint32_t mDepth;
  61. };
  62. } // namespace rsov
  63. } // namespace renderscript
  64. } // namespace android
  65. extern bool rsovAllocationInit(const android::renderscript::Context *rsc,
  66. android::renderscript::Allocation *alloc,
  67. bool forceZero);
  68. extern void rsovAllocationDestroy(const android::renderscript::Context *rsc,
  69. android::renderscript::Allocation *alloc);
  70. extern void rsovAllocationData1D(const android::renderscript::Context *rsc,
  71. const android::renderscript::Allocation *alloc,
  72. uint32_t xoff, uint32_t lod, size_t count,
  73. const void *data, size_t sizeBytes);
  74. extern void rsovAllocationData2D(const android::renderscript::Context *rsc,
  75. const android::renderscript::Allocation *alloc,
  76. uint32_t xoff, uint32_t yoff, uint32_t lod,
  77. RsAllocationCubemapFace face, uint32_t w,
  78. uint32_t h, const void *data, size_t sizeBytes,
  79. size_t stride);
  80. extern void rsovAllocationData3D(const android::renderscript::Context *rsc,
  81. const android::renderscript::Allocation *alloc,
  82. uint32_t xoff, uint32_t yoff, uint32_t zoff,
  83. uint32_t lod, uint32_t w, uint32_t h,
  84. uint32_t d, const void *data, size_t sizeBytes,
  85. size_t stride);
  86. extern void rsovAllocationRead1D(const android::renderscript::Context *rsc,
  87. const android::renderscript::Allocation *alloc,
  88. uint32_t xoff, uint32_t lod, size_t count,
  89. void *data, size_t sizeBytes);
  90. extern void rsovAllocationRead2D(const android::renderscript::Context *rsc,
  91. const android::renderscript::Allocation *alloc,
  92. uint32_t xoff, uint32_t yoff, uint32_t lod,
  93. RsAllocationCubemapFace face, uint32_t w,
  94. uint32_t h, void *data, size_t sizeBytes,
  95. size_t stride);
  96. extern void rsovAllocationRead3D(const android::renderscript::Context *rsc,
  97. const android::renderscript::Allocation *alloc,
  98. uint32_t xoff, uint32_t yoff, uint32_t zoff,
  99. uint32_t lod, uint32_t w, uint32_t h,
  100. uint32_t d, void *data, size_t sizeBytes,
  101. size_t stride);
  102. extern void *rsovAllocationLock1D(
  103. const android::renderscript::Context *rsc,
  104. const android::renderscript::Allocation *alloc);
  105. extern void rsovAllocationUnlock1D(
  106. const android::renderscript::Context *rsc,
  107. const android::renderscript::Allocation *alloc);
  108. extern void rsovAllocationData1D_alloc(
  109. const android::renderscript::Context *rsc,
  110. const android::renderscript::Allocation *dstAlloc, uint32_t dstXoff,
  111. uint32_t dstLod, size_t count,
  112. const android::renderscript::Allocation *srcAlloc, uint32_t srcXoff,
  113. uint32_t srcLod);
  114. extern void rsovAllocationData2D_alloc_script(
  115. const android::renderscript::Context *rsc,
  116. const android::renderscript::Allocation *dstAlloc, uint32_t dstXoff,
  117. uint32_t dstYoff, uint32_t dstLod, RsAllocationCubemapFace dstFace,
  118. uint32_t w, uint32_t h, const android::renderscript::Allocation *srcAlloc,
  119. uint32_t srcXoff, uint32_t srcYoff, uint32_t srcLod,
  120. RsAllocationCubemapFace srcFace);
  121. extern void rsovAllocationData2D_alloc(
  122. const android::renderscript::Context *rsc,
  123. const android::renderscript::Allocation *dstAlloc, uint32_t dstXoff,
  124. uint32_t dstYoff, uint32_t dstLod, RsAllocationCubemapFace dstFace,
  125. uint32_t w, uint32_t h, const android::renderscript::Allocation *srcAlloc,
  126. uint32_t srcXoff, uint32_t srcYoff, uint32_t srcLod,
  127. RsAllocationCubemapFace srcFace);
  128. extern void rsovAllocationData3D_alloc_script(
  129. const android::renderscript::Context *rsc,
  130. const android::renderscript::Allocation *dstAlloc, uint32_t dstXoff,
  131. uint32_t dstYoff, uint32_t dstZoff, uint32_t dstLod, uint32_t w, uint32_t h,
  132. uint32_t d, const android::renderscript::Allocation *srcAlloc,
  133. uint32_t srcXoff, uint32_t srcYoff, uint32_t srcZoff, uint32_t srcLod);
  134. extern void rsovAllocationData3D_alloc(
  135. const android::renderscript::Context *rsc,
  136. const android::renderscript::Allocation *dstAlloc, uint32_t dstXoff,
  137. uint32_t dstYoff, uint32_t dstZoff, uint32_t dstLod, uint32_t w, uint32_t h,
  138. uint32_t d, const android::renderscript::Allocation *srcAlloc,
  139. uint32_t srcXoff, uint32_t srcYoff, uint32_t srcZoff, uint32_t srcLod);
  140. extern void rsovAllocationAdapterOffset(
  141. const android::renderscript::Context *rsc,
  142. const android::renderscript::Allocation *alloc);
  143. extern bool rsovAllocationAdapterInit(const android::renderscript::Context *rsc,
  144. android::renderscript::Allocation *alloc);
  145. extern void rsovAllocationSyncAll(
  146. const android::renderscript::Context *rsc,
  147. const android::renderscript::Allocation *alloc, RsAllocationUsageType src);
  148. extern void rsovAllocationMarkDirty(
  149. const android::renderscript::Context *rsc,
  150. const android::renderscript::Allocation *alloc);
  151. extern void rsovAllocationResize(const android::renderscript::Context *rsc,
  152. const android::renderscript::Allocation *alloc,
  153. const android::renderscript::Type *newType,
  154. bool zeroNew);
  155. extern void rsovAllocationGenerateMipmaps(
  156. const android::renderscript::Context *rsc,
  157. const android::renderscript::Allocation *alloc);
  158. extern uint32_t rsovAllocationGrallocBits(
  159. const android::renderscript::Context *rsc,
  160. android::renderscript::Allocation *alloc);
  161. extern void rsovAllocationUpdateCachedObject(
  162. const android::renderscript::Context *rsc,
  163. const android::renderscript::Allocation *alloc,
  164. android::renderscript::rs_allocation *obj);
  165. extern void rsovAllocationSetSurface(const android::renderscript::Context *rsc,
  166. android::renderscript::Allocation *alloc,
  167. ANativeWindow *nw);
  168. extern void rsovAllocationIoSend(const android::renderscript::Context *rsc,
  169. android::renderscript::Allocation *alloc);
  170. extern void rsovAllocationIoReceive(const android::renderscript::Context *rsc,
  171. android::renderscript::Allocation *alloc);
  172. extern void rsovAllocationElementData(
  173. const android::renderscript::Context *rsc,
  174. const android::renderscript::Allocation *alloc, uint32_t x, uint32_t y,
  175. uint32_t z, const void *data, uint32_t cIdx, size_t sizeBytes);
  176. extern void rsovAllocationElementRead(
  177. const android::renderscript::Context *rsc,
  178. const android::renderscript::Allocation *alloc, uint32_t x, uint32_t y,
  179. uint32_t z, void *data, uint32_t cIdx, size_t sizeBytes);
  180. #endif // RSOV_ALLOCATION_H