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