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