Skip to content

Commit 3b88729

Browse files
author
Alex Sakhartchouk
committed
Moving lod's into hal struct.
Change-Id: Iaec34fea7c002d7948d91df6b7a1af7f832f74ea
1 parent cd40f4a commit 3b88729

File tree

2 files changed

+66
-56
lines changed

2 files changed

+66
-56
lines changed

libs/rs/rsType.cpp

Lines changed: 44 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ using namespace android;
2020
using namespace android::renderscript;
2121

2222
Type::Type(Context *rsc) : ObjectBase(rsc) {
23-
mLODs = 0;
24-
mLODCount = 0;
25-
clear();
23+
memset(&mHal, 0, sizeof(mHal));
24+
mDimLOD = false;
2625
}
2726

2827
void Type::preDestroy() const {
@@ -35,16 +34,15 @@ void Type::preDestroy() const {
3534
}
3635

3736
Type::~Type() {
38-
if (mLODs) {
39-
delete [] mLODs;
40-
mLODs = NULL;
41-
}
37+
clear();
4238
}
4339

4440
void Type::clear() {
45-
if (mLODs) {
46-
delete [] mLODs;
47-
mLODs = NULL;
41+
if (mHal.state.lodCount) {
42+
delete [] mHal.state.lodDimX;
43+
delete [] mHal.state.lodDimY;
44+
delete [] mHal.state.lodDimZ;
45+
delete [] mHal.state.lodOffset;
4846
}
4947
mElement.clear();
5048
memset(&mHal, 0, sizeof(mHal));
@@ -63,33 +61,39 @@ size_t Type::getOffsetForFace(uint32_t face) const {
6361
}
6462

6563
void Type::compute() {
66-
uint32_t oldLODCount = mLODCount;
67-
if (mHal.state.dimLOD) {
64+
uint32_t oldLODCount = mHal.state.lodCount;
65+
if (mDimLOD) {
6866
uint32_t l2x = rsFindHighBit(mHal.state.dimX) + 1;
6967
uint32_t l2y = rsFindHighBit(mHal.state.dimY) + 1;
7068
uint32_t l2z = rsFindHighBit(mHal.state.dimZ) + 1;
7169

72-
mLODCount = rsMax(l2x, l2y);
73-
mLODCount = rsMax(mLODCount, l2z);
70+
mHal.state.lodCount = rsMax(l2x, l2y);
71+
mHal.state.lodCount = rsMax(mHal.state.lodCount, l2z);
7472
} else {
75-
mLODCount = 1;
73+
mHal.state.lodCount = 1;
7674
}
77-
if (mLODCount != oldLODCount) {
78-
if (mLODs){
79-
delete [] mLODs;
75+
if (mHal.state.lodCount != oldLODCount) {
76+
if (oldLODCount) {
77+
delete [] mHal.state.lodDimX;
78+
delete [] mHal.state.lodDimY;
79+
delete [] mHal.state.lodDimZ;
80+
delete [] mHal.state.lodOffset;
8081
}
81-
mLODs = new LOD[mLODCount];
82+
mHal.state.lodDimX = new uint32_t[mHal.state.lodCount];
83+
mHal.state.lodDimY = new uint32_t[mHal.state.lodCount];
84+
mHal.state.lodDimZ = new uint32_t[mHal.state.lodCount];
85+
mHal.state.lodOffset = new uint32_t[mHal.state.lodCount];
8286
}
8387

8488
uint32_t tx = mHal.state.dimX;
8589
uint32_t ty = mHal.state.dimY;
8690
uint32_t tz = mHal.state.dimZ;
8791
size_t offset = 0;
88-
for (uint32_t lod=0; lod < mLODCount; lod++) {
89-
mLODs[lod].mX = tx;
90-
mLODs[lod].mY = ty;
91-
mLODs[lod].mZ = tz;
92-
mLODs[lod].mOffset = offset;
92+
for (uint32_t lod=0; lod < mHal.state.lodCount; lod++) {
93+
mHal.state.lodDimX[lod] = tx;
94+
mHal.state.lodDimY[lod] = ty;
95+
mHal.state.lodDimZ[lod] = tz;
96+
mHal.state.lodOffset[lod] = offset;
9397
offset += tx * rsMax(ty, 1u) * rsMax(tz, 1u) * mElement->getSizeBytes();
9498
if (tx > 1) tx >>= 1;
9599
if (ty > 1) ty >>= 1;
@@ -107,27 +111,29 @@ void Type::compute() {
107111
}
108112

109113
uint32_t Type::getLODOffset(uint32_t lod, uint32_t x) const {
110-
uint32_t offset = mLODs[lod].mOffset;
114+
uint32_t offset = mHal.state.lodOffset[lod];
111115
offset += x * mElement->getSizeBytes();
112116
return offset;
113117
}
114118

115119
uint32_t Type::getLODOffset(uint32_t lod, uint32_t x, uint32_t y) const {
116-
uint32_t offset = mLODs[lod].mOffset;
117-
offset += (x + y * mLODs[lod].mX) * mElement->getSizeBytes();
120+
uint32_t offset = mHal.state.lodOffset[lod];
121+
offset += (x + y * mHal.state.lodDimX[lod]) * mElement->getSizeBytes();
118122
return offset;
119123
}
120124

121125
uint32_t Type::getLODOffset(uint32_t lod, uint32_t x, uint32_t y, uint32_t z) const {
122-
uint32_t offset = mLODs[lod].mOffset;
123-
offset += (x + y*mLODs[lod].mX + z*mLODs[lod].mX*mLODs[lod].mY) * mElement->getSizeBytes();
126+
uint32_t offset = mHal.state.lodOffset[lod];
127+
offset += (x +
128+
y * mHal.state.lodDimX[lod] +
129+
z * mHal.state.lodDimX[lod] * mHal.state.lodDimY[lod]) * mElement->getSizeBytes();
124130
return offset;
125131
}
126132

127133
uint32_t Type::getLODFaceOffset(uint32_t lod, RsAllocationCubemapFace face,
128134
uint32_t x, uint32_t y) const {
129-
uint32_t offset = mLODs[lod].mOffset;
130-
offset += (x + y * mLODs[lod].mX) * mElement->getSizeBytes();
135+
uint32_t offset = mHal.state.lodOffset[lod];
136+
offset += (x + y * mHal.state.lodDimX[lod]) * mElement->getSizeBytes();
131137

132138
if (face != 0) {
133139
uint32_t faceOffset = getSizeBytes() / 6;
@@ -143,7 +149,7 @@ void Type::dumpLOGV(const char *prefix) const {
143149
mHal.state.dimX,
144150
mHal.state.dimY,
145151
mHal.state.dimZ,
146-
mHal.state.dimLOD,
152+
mHal.state.lodCount,
147153
mHal.state.faces);
148154
snprintf(buf, sizeof(buf), "%s element: ", prefix);
149155
mElement->dumpLOGV(buf);
@@ -162,7 +168,7 @@ void Type::serialize(OStream *stream) const {
162168
stream->addU32(mHal.state.dimY);
163169
stream->addU32(mHal.state.dimZ);
164170

165-
stream->addU8((uint8_t)(mHal.state.dimLOD ? 1 : 0));
171+
stream->addU8((uint8_t)(mHal.state.lodCount ? 1 : 0));
166172
stream->addU8((uint8_t)(mHal.state.faces ? 1 : 0));
167173
}
168174

@@ -233,12 +239,12 @@ ObjectBaseRef<Type> Type::getTypeRef(Context *rsc, const Element *e,
233239

234240

235241
Type *nt = new Type(rsc);
242+
nt->mDimLOD = dimLOD;
236243
returnRef.set(nt);
237244
nt->mElement.set(e);
238245
nt->mHal.state.dimX = dimX;
239246
nt->mHal.state.dimY = dimY;
240247
nt->mHal.state.dimZ = dimZ;
241-
nt->mHal.state.dimLOD = dimLOD;
242248
nt->mHal.state.faces = dimFaces;
243249
nt->compute();
244250

@@ -251,14 +257,14 @@ ObjectBaseRef<Type> Type::getTypeRef(Context *rsc, const Element *e,
251257

252258
ObjectBaseRef<Type> Type::cloneAndResize1D(Context *rsc, uint32_t dimX) const {
253259
return getTypeRef(rsc, mElement.get(), dimX,
254-
mHal.state.dimY, mHal.state.dimZ, mHal.state.dimLOD, mHal.state.faces);
260+
mHal.state.dimY, mHal.state.dimZ, mHal.state.lodCount, mHal.state.faces);
255261
}
256262

257263
ObjectBaseRef<Type> Type::cloneAndResize2D(Context *rsc,
258264
uint32_t dimX,
259265
uint32_t dimY) const {
260266
return getTypeRef(rsc, mElement.get(), dimX, dimY,
261-
mHal.state.dimZ, mHal.state.dimLOD, mHal.state.faces);
267+
mHal.state.dimZ, mHal.state.lodCount, mHal.state.faces);
262268
}
263269

264270

@@ -280,13 +286,13 @@ RsType rsi_TypeCreate(Context *rsc, RsElement _e, uint32_t dimX,
280286
void rsaTypeGetNativeData(RsContext con, RsType type, uint32_t *typeData, uint32_t typeDataSize) {
281287
rsAssert(typeDataSize == 6);
282288
// Pack the data in the follofing way mHal.state.dimX; mHal.state.dimY; mHal.state.dimZ;
283-
// mHal.state.dimLOD; mHal.state.faces; mElement; into typeData
289+
// mHal.state.lodCount; mHal.state.faces; mElement; into typeData
284290
Type *t = static_cast<Type *>(type);
285291

286292
(*typeData++) = t->getDimX();
287293
(*typeData++) = t->getDimY();
288294
(*typeData++) = t->getDimZ();
289-
(*typeData++) = t->getDimLOD();
295+
(*typeData++) = t->getDimLOD() ? 1 : 0;
290296
(*typeData++) = t->getDimFaces() ? 1 : 0;
291297
(*typeData++) = (uint32_t)t->getElement();
292298
t->getElement()->incUserRef();

libs/rs/rsType.h

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ class Type : public ObjectBase {
4444
uint32_t dimX;
4545
uint32_t dimY;
4646
uint32_t dimZ;
47-
bool dimLOD;
47+
uint32_t *lodDimX;
48+
uint32_t *lodDimY;
49+
uint32_t *lodDimZ;
50+
uint32_t *lodOffset;
51+
uint32_t lodCount;
4852
bool faces;
4953
};
5054
State state;
@@ -62,15 +66,24 @@ class Type : public ObjectBase {
6266
uint32_t getDimX() const {return mHal.state.dimX;}
6367
uint32_t getDimY() const {return mHal.state.dimY;}
6468
uint32_t getDimZ() const {return mHal.state.dimZ;}
65-
uint32_t getDimLOD() const {return mHal.state.dimLOD;}
69+
bool getDimLOD() const {return mDimLOD;}
6670
bool getDimFaces() const {return mHal.state.faces;}
6771

68-
uint32_t getLODDimX(uint32_t lod) const {rsAssert(lod < mLODCount); return mLODs[lod].mX;}
69-
uint32_t getLODDimY(uint32_t lod) const {rsAssert(lod < mLODCount); return mLODs[lod].mY;}
70-
uint32_t getLODDimZ(uint32_t lod) const {rsAssert(lod < mLODCount); return mLODs[lod].mZ;}
71-
72+
uint32_t getLODDimX(uint32_t lod) const {
73+
rsAssert(lod < mHal.state.lodCount);
74+
return mHal.state.lodDimX[lod];
75+
}
76+
uint32_t getLODDimY(uint32_t lod) const {
77+
rsAssert(lod < mHal.state.lodCount);
78+
return mHal.state.lodDimY[lod];
79+
}
80+
uint32_t getLODDimZ(uint32_t lod) const {
81+
rsAssert(lod < mHal.state.lodCount);
82+
return mHal.state.lodDimZ[lod];
83+
}
7284
uint32_t getLODOffset(uint32_t lod) const {
73-
rsAssert(lod < mLODCount); return mLODs[lod].mOffset;
85+
rsAssert(lod < mHal.state.lodCount);
86+
return mHal.state.lodOffset[lod];
7487
}
7588
uint32_t getLODOffset(uint32_t lod, uint32_t x) const;
7689
uint32_t getLODOffset(uint32_t lod, uint32_t x, uint32_t y) const;
@@ -79,7 +92,7 @@ class Type : public ObjectBase {
7992
uint32_t getLODFaceOffset(uint32_t lod, RsAllocationCubemapFace face,
8093
uint32_t x, uint32_t y) const;
8194

82-
uint32_t getLODCount() const {return mLODCount;}
95+
uint32_t getLODCount() const {return mHal.state.lodCount;}
8396
bool getIsNp2() const;
8497

8598
void clear();
@@ -106,14 +119,8 @@ class Type : public ObjectBase {
106119
}
107120

108121
protected:
109-
struct LOD {
110-
size_t mX;
111-
size_t mY;
112-
size_t mZ;
113-
size_t mOffset;
114-
};
115-
116122
void makeLODTable();
123+
bool mDimLOD;
117124

118125
// Internal structure from most to least significant.
119126
// * Array dimensions
@@ -127,9 +134,6 @@ class Type : public ObjectBase {
127134

128135
size_t mMipChainSizeBytes;
129136
size_t mTotalSizeBytes;
130-
LOD *mLODs;
131-
uint32_t mLODCount;
132-
133137
protected:
134138
virtual void preDestroy() const;
135139
virtual ~Type();

0 commit comments

Comments
 (0)