rs_structs.h revision 386e87ecf4114084c10dd385edc1c2baebe80a04
1#ifndef _RS_STRUCTS_H_
2#define _RS_STRUCTS_H_
3
4#include "rs_core.rsh"
5#include "rs_graphics.rsh"
6
7/*****************************************************************************
8 * CAUTION
9 *
10 * The following structure layout provides a more efficient way to access
11 * internal members of the C++ class Allocation owned by librs. Unfortunately,
12 * since this class has virtual members, we can't simply use offsetof() or any
13 * other compiler trickery to dynamically get the appropriate values at
14 * build-time. This layout may need to be updated whenever
15 * frameworks/base/libs/rs/rsAllocation.h is modified.
16 *
17 * Having the layout information available in this file allows us to
18 * accelerate functionality like rsAllocationGetDimX(). Without this
19 * information, we would not be able to inline the bitcode, thus resulting in
20 * potential runtime performance penalties for tight loops operating on
21 * allocations.
22 *
23 *****************************************************************************/
24typedef enum {
25    RS_ALLOCATION_MIPMAP_NONE = 0,
26    RS_ALLOCATION_MIPMAP_FULL = 1,
27    RS_ALLOCATION_MIPMAP_ON_SYNC_TO_TEXTURE = 2
28} rs_allocation_mipmap_control;
29
30typedef struct Allocation {
31#ifndef __LP64__
32    char __pad[32];
33#else
34    char __pad[56];
35#endif
36    struct {
37        void * drv;
38        struct {
39            const void *type;
40            uint32_t usageFlags;
41            rs_allocation_mipmap_control mipmapControl;
42            uint32_t yuv;
43            uint32_t elementSizeBytes;
44            bool hasMipmaps;
45            bool hasFaces;
46            bool hasReferences;
47            void * usrPtr;
48            int32_t surfaceTextureID;
49            void * nativeBuffer;
50            int64_t timestamp;
51
52            // Allocation adapter state
53            const void *baseAlloc;
54            uint32_t originX;
55            uint32_t originY;
56            uint32_t originZ;
57            uint32_t originLOD;
58            uint32_t originFace;
59            uint32_t originArray[4/*Type::mMaxArrays*/];
60        } state;
61
62        struct DrvState {
63            struct LodState {
64                void * mallocPtr;
65                size_t stride;
66                uint32_t dimX;
67                uint32_t dimY;
68                uint32_t dimZ;
69            } lod[16/*android::renderscript::Allocation::MAX_LOD*/];
70            size_t faceOffset;
71            uint32_t lodCount;
72            uint32_t faceCount;
73
74            struct YuvState {
75                uint32_t shift;
76                uint32_t step;
77            } yuv;
78
79            int grallocFlags;
80            uint32_t dimArray[4/*Type::mMaxArrays*/];
81        } drvState;
82    } mHal;
83} Allocation_t;
84
85#ifndef __LP64__
86/*****************************************************************************
87 * CAUTION
88 *
89 * The following structure layout provides a more efficient way to access
90 * internal members of the C++ class ProgramStore owned by librs. Unfortunately,
91 * since this class has virtual members, we can't simply use offsetof() or any
92 * other compiler trickery to dynamically get the appropriate values at
93 * build-time. This layout may need to be updated whenever
94 * frameworks/base/libs/rs/rsProgramStore.h is modified.
95 *
96 * Having the layout information available in this file allows us to
97 * accelerate functionality like rsgProgramStoreGetDepthFunc(). Without this
98 * information, we would not be able to inline the bitcode, thus resulting in
99 * potential runtime performance penalties for tight loops operating on
100 * program store.
101 *
102 *****************************************************************************/
103typedef struct ProgramStore {
104    char __pad[40];
105    struct {
106        struct {
107            bool ditherEnable;
108            bool colorRWriteEnable;
109            bool colorGWriteEnable;
110            bool colorBWriteEnable;
111            bool colorAWriteEnable;
112            rs_blend_src_func blendSrc;
113            rs_blend_dst_func blendDst;
114            bool depthWriteEnable;
115            rs_depth_func depthFunc;
116        } state;
117    } mHal;
118} ProgramStore_t;
119
120/*****************************************************************************
121 * CAUTION
122 *
123 * The following structure layout provides a more efficient way to access
124 * internal members of the C++ class ProgramRaster owned by librs. Unfortunately,
125 * since this class has virtual members, we can't simply use offsetof() or any
126 * other compiler trickery to dynamically get the appropriate values at
127 * build-time. This layout may need to be updated whenever
128 * frameworks/base/libs/rs/rsProgramRaster.h is modified.
129 *
130 * Having the layout information available in this file allows us to
131 * accelerate functionality like rsgProgramRasterGetCullMode(). Without this
132 * information, we would not be able to inline the bitcode, thus resulting in
133 * potential runtime performance penalties for tight loops operating on
134 * program raster.
135 *
136 *****************************************************************************/
137typedef struct ProgramRaster {
138    char __pad[36];
139    struct {
140        void * drv;
141        struct {
142            bool pointSprite;
143            rs_cull_mode cull;
144        } state;
145    } mHal;
146} ProgramRaster_t;
147#endif //__LP64__
148
149/*****************************************************************************
150 * CAUTION
151 *
152 * The following structure layout provides a more efficient way to access
153 * internal members of the C++ class Sampler owned by librs. Unfortunately,
154 * since this class has virtual members, we can't simply use offsetof() or any
155 * other compiler trickery to dynamically get the appropriate values at
156 * build-time. This layout may need to be updated whenever
157 * frameworks/base/libs/rs/rsSampler.h is modified.
158 *
159 * Having the layout information available in this file allows us to
160 * accelerate functionality like rsgProgramRasterGetMagFilter(). Without this
161 * information, we would not be able to inline the bitcode, thus resulting in
162 * potential runtime performance penalties for tight loops operating on
163 * samplers.
164 *
165 *****************************************************************************/
166typedef struct Sampler {
167#ifndef __LP64__
168    char __pad[32];
169#else
170    char __pad[56];
171#endif
172    struct {
173        void *drv;
174        struct {
175            rs_sampler_value magFilter;
176            rs_sampler_value minFilter;
177            rs_sampler_value wrapS;
178            rs_sampler_value wrapT;
179            rs_sampler_value wrapR;
180            float aniso;
181        } state;
182    } mHal;
183} Sampler_t;
184
185/*****************************************************************************
186 * CAUTION
187 *
188 * The following structure layout provides a more efficient way to access
189 * internal members of the C++ class Element owned by librs. Unfortunately,
190 * since this class has virtual members, we can't simply use offsetof() or any
191 * other compiler trickery to dynamically get the appropriate values at
192 * build-time. This layout may need to be updated whenever
193 * frameworks/base/libs/rs/rsElement.h is modified.
194 *
195 * Having the layout information available in this file allows us to
196 * accelerate functionality like rsElementGetSubElementCount(). Without this
197 * information, we would not be able to inline the bitcode, thus resulting in
198 * potential runtime performance penalties for tight loops operating on
199 * elements.
200 *
201 *****************************************************************************/
202typedef struct Element {
203#ifndef __LP64__
204    char __pad[32];
205#else
206    char __pad[56];
207#endif
208    struct {
209        void *drv;
210        struct {
211            rs_data_type dataType;
212            rs_data_kind dataKind;
213            uint32_t vectorSize;
214            uint32_t elementSizeBytes;
215
216            // Subelements
217            const void **fields;
218            uint32_t *fieldArraySizes;
219            const char **fieldNames;
220            uint32_t *fieldNameLengths;
221            uint32_t *fieldOffsetBytes;
222            uint32_t fieldsCount;
223        } state;
224    } mHal;
225} Element_t;
226
227/*****************************************************************************
228 * CAUTION
229 *
230 * The following structure layout provides a more efficient way to access
231 * internal members of the C++ class Type owned by librs. Unfortunately,
232 * since this class has virtual members, we can't simply use offsetof() or any
233 * other compiler trickery to dynamically get the appropriate values at
234 * build-time. This layout may need to be updated whenever
235 * frameworks/base/libs/rs/rsType.h is modified.
236 *
237 * Having the layout information available in this file allows us to
238 * accelerate functionality like rsAllocationGetElement(). Without this
239 * information, we would not be able to inline the bitcode, thus resulting in
240 * potential runtime performance penalties for tight loops operating on
241 * types.
242 *
243 *****************************************************************************/
244typedef struct Type {
245#ifndef __LP64__
246    char __pad[32];
247#else
248    char __pad[56];
249#endif
250    struct {
251        void *drv;
252        struct {
253            const void * element;
254            uint32_t dimX;
255            uint32_t dimY;
256            uint32_t dimZ;
257            uint32_t *lodDimX;
258            uint32_t *lodDimY;
259            uint32_t *lodDimZ;
260            uint32_t *arrays;
261            uint32_t lodCount;
262            uint32_t dimYuv;
263            uint32_t arrayCount;
264            bool faces;
265        } state;
266    } mHal;
267} Type_t;
268
269#ifndef __LP64__
270/*****************************************************************************
271 * CAUTION
272 *
273 * The following structure layout provides a more efficient way to access
274 * internal members of the C++ class Mesh owned by librs. Unfortunately,
275 * since this class has virtual members, we can't simply use offsetof() or any
276 * other compiler trickery to dynamically get the appropriate values at
277 * build-time. This layout may need to be updated whenever
278 * frameworks/base/libs/rs/rsMesh.h is modified.
279 *
280 * Having the layout information available in this file allows us to
281 * accelerate functionality like rsMeshGetVertexAllocationCount(). Without this
282 * information, we would not be able to inline the bitcode, thus resulting in
283 * potential runtime performance penalties for tight loops operating on
284 * meshes.
285 *
286 *****************************************************************************/
287typedef struct Mesh {
288    char __pad[32];
289    struct {
290        void *drv;
291        struct {
292            void **vertexBuffers;
293            uint32_t vertexBuffersCount;
294
295            // indexBuffers[i] could be nullptr, in which case only primitives[i] is used
296            void **indexBuffers;
297            uint32_t indexBuffersCount;
298            rs_primitive *primitives;
299            uint32_t primitivesCount;
300        } state;
301    } mHal;
302} Mesh_t;
303#endif //__LP64__
304#endif // _RS_CORE_H_
305