Skip to content

Commit 5ef2f53

Browse files
author
Alex Sakhartchouk
committed
Remove ObjBaseRef from the hal struct
Change-Id: Idcac14ecfdd4d06a0f54bf50e3b9657be62e6638
1 parent a744ead commit 5ef2f53

14 files changed

+168
-116
lines changed

libs/rs/driver/rsdFrameBuffer.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ void setDepthAttachment(const Context *rsc, const FBOCache *fb) {
3333
RsdFrameBufferObj *fbo = (RsdFrameBufferObj*)fb->mHal.drv;
3434

3535
DrvAllocation *depth = NULL;
36-
if (fb->mHal.state.depthTarget.get() != NULL) {
36+
if (fb->mHal.state.depthTarget != NULL) {
3737
depth = (DrvAllocation *)fb->mHal.state.depthTarget->mHal.drv;
3838

3939
if (depth->uploadDeferred) {
40-
rsdAllocationSyncAll(rsc, fb->mHal.state.depthTarget.get(),
40+
rsdAllocationSyncAll(rsc, fb->mHal.state.depthTarget,
4141
RS_ALLOCATION_USAGE_SCRIPT);
4242
}
4343
}
@@ -49,11 +49,11 @@ void setColorAttachment(const Context *rsc, const FBOCache *fb) {
4949
// Now attach color targets
5050
for (uint32_t i = 0; i < fb->mHal.state.colorTargetsCount; i ++) {
5151
DrvAllocation *color = NULL;
52-
if (fb->mHal.state.colorTargets[i].get() != NULL) {
52+
if (fb->mHal.state.colorTargets[i] != NULL) {
5353
color = (DrvAllocation *)fb->mHal.state.colorTargets[i]->mHal.drv;
5454

5555
if (color->uploadDeferred) {
56-
rsdAllocationSyncAll(rsc, fb->mHal.state.colorTargets[i].get(),
56+
rsdAllocationSyncAll(rsc, fb->mHal.state.colorTargets[i],
5757
RS_ALLOCATION_USAGE_SCRIPT);
5858
}
5959
}
@@ -79,10 +79,10 @@ void rsdFrameBufferSetActive(const Context *rsc, const FBOCache *fb) {
7979
setColorAttachment(rsc, fb);
8080

8181
RsdFrameBufferObj *fbo = (RsdFrameBufferObj *)fb->mHal.drv;
82-
if (fb->mHal.state.colorTargets[0].get()) {
82+
if (fb->mHal.state.colorTargets[0]) {
8383
fbo->setDimensions(fb->mHal.state.colorTargets[0]->getType()->getDimX(),
8484
fb->mHal.state.colorTargets[0]->getType()->getDimY());
85-
} else if (fb->mHal.state.depthTarget.get()) {
85+
} else if (fb->mHal.state.depthTarget) {
8686
fbo->setDimensions(fb->mHal.state.depthTarget->getType()->getDimX(),
8787
fb->mHal.state.depthTarget->getType()->getDimY());
8888
}

libs/rs/driver/rsdMeshObj.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ void RsdMeshObj::renderPrimitiveRange(const Context *rsc, uint32_t primIndex,
138138
}
139139

140140
for (uint32_t ct=0; ct < mRSMesh->mHal.state.vertexBuffersCount; ct++) {
141-
const Allocation *alloc = mRSMesh->mHal.state.vertexBuffers[ct].get();
141+
const Allocation *alloc = mRSMesh->mHal.state.vertexBuffers[ct];
142142
DrvAllocation *drv = (DrvAllocation *)alloc->mHal.drv;
143143
if (drv->uploadDeferred) {
144144
rsdAllocationSyncAll(rsc, alloc, RS_ALLOCATION_USAGE_SCRIPT);
@@ -148,7 +148,7 @@ void RsdMeshObj::renderPrimitiveRange(const Context *rsc, uint32_t primIndex,
148148
// update attributes with either buffer information or data ptr based on their current state
149149
for (uint32_t ct=0; ct < mAttribCount; ct++) {
150150
uint32_t allocIndex = mAttribAllocationIndex[ct];
151-
Allocation *alloc = mRSMesh->mHal.state.vertexBuffers[allocIndex].get();
151+
Allocation *alloc = mRSMesh->mHal.state.vertexBuffers[allocIndex];
152152
DrvAllocation *drvAlloc = (DrvAllocation *)alloc->mHal.drv;
153153

154154
if (drvAlloc->bufferID) {
@@ -163,8 +163,7 @@ void RsdMeshObj::renderPrimitiveRange(const Context *rsc, uint32_t primIndex,
163163
RsdVertexArray va(mAttribs, mAttribCount);
164164
va.setup(rsc);
165165

166-
Mesh::Primitive_t *prim = mRSMesh->mHal.state.primitives[primIndex];
167-
const Allocation *idxAlloc = prim->mIndexBuffer.get();
166+
const Allocation *idxAlloc = mRSMesh->mHal.state.indexBuffers[primIndex];
168167
if (idxAlloc) {
169168
DrvAllocation *drvAlloc = (DrvAllocation *)idxAlloc->mHal.drv;
170169
if (drvAlloc->uploadDeferred) {
@@ -190,7 +189,7 @@ void RsdMeshObj::renderPrimitiveRange(const Context *rsc, uint32_t primIndex,
190189
void RsdMeshObj::updateGLPrimitives() {
191190
mGLPrimitives = new uint32_t[mRSMesh->mHal.state.primitivesCount];
192191
for (uint32_t i = 0; i < mRSMesh->mHal.state.primitivesCount; i ++) {
193-
switch (mRSMesh->mHal.state.primitives[i]->mPrimitive) {
192+
switch (mRSMesh->mHal.state.primitives[i]) {
194193
case RS_PRIMITIVE_POINT: mGLPrimitives[i] = GL_POINTS; break;
195194
case RS_PRIMITIVE_LINE: mGLPrimitives[i] = GL_LINES; break;
196195
case RS_PRIMITIVE_LINE_STRIP: mGLPrimitives[i] = GL_LINE_STRIP; break;

libs/rs/driver/rsdProgram.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ bool rsdProgramVertexInit(const Context *rsc, const ProgramVertex *pv,
4343

4444
static void SyncProgramConstants(const Context *rsc, const Program *p) {
4545
for (uint32_t ct=0; ct < p->mHal.state.texturesCount; ct++) {
46-
const Allocation *a = p->mHal.state.textures[ct].get();
46+
const Allocation *a = p->mHal.state.textures[ct];
4747
if (!a) {
4848
continue;
4949
}

libs/rs/driver/rsdShader.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ void RsdShader::init() {
6969
uint32_t attribCount = 0;
7070
uint32_t uniformCount = 0;
7171
for (uint32_t ct=0; ct < mRSProgram->mHal.state.inputElementsCount; ct++) {
72-
initAddUserElement(mRSProgram->mHal.state.inputElements[ct].get(), mAttribNames, NULL, &attribCount, RS_SHADER_ATTR);
72+
initAddUserElement(mRSProgram->mHal.state.inputElements[ct], mAttribNames, NULL, &attribCount, RS_SHADER_ATTR);
7373
}
7474
for (uint32_t ct=0; ct < mRSProgram->mHal.state.constantsCount; ct++) {
7575
initAddUserElement(mRSProgram->mHal.state.constantTypes[ct]->getElement(), mUniformNames, mUniformArraySizes, &uniformCount, RS_SHADER_UNI);
@@ -89,7 +89,7 @@ void RsdShader::init() {
8989
String8 RsdShader::getGLSLInputString() const {
9090
String8 s;
9191
for (uint32_t ct=0; ct < mRSProgram->mHal.state.inputElementsCount; ct++) {
92-
const Element *e = mRSProgram->mHal.state.inputElements[ct].get();
92+
const Element *e = mRSProgram->mHal.state.inputElements[ct];
9393
for (uint32_t field=0; field < e->getFieldCount(); field++) {
9494
const Element *f = e->getField(field);
9595

@@ -113,7 +113,7 @@ String8 RsdShader::getGLSLInputString() const {
113113

114114
void RsdShader::appendAttributes() {
115115
for (uint32_t ct=0; ct < mRSProgram->mHal.state.inputElementsCount; ct++) {
116-
const Element *e = mRSProgram->mHal.state.inputElements[ct].get();
116+
const Element *e = mRSProgram->mHal.state.inputElements[ct];
117117
for (uint32_t field=0; field < e->getFieldCount(); field++) {
118118
const Element *f = e->getField(field);
119119
const char *fn = e->getFieldName(field);
@@ -414,7 +414,7 @@ void RsdShader::setupTextures(const Context *rsc, RsdShaderCache *sc) {
414414
RSD_CALL_GL(glActiveTexture, GL_TEXTURE0 + ct);
415415
RSD_CALL_GL(glUniform1i, sc->fragUniformSlot(mTextureUniformIndexStart + ct), ct);
416416

417-
if (!mRSProgram->mHal.state.textures[ct].get()) {
417+
if (!mRSProgram->mHal.state.textures[ct]) {
418418
// if nothing is bound, reset to default GL texture
419419
RSD_CALL_GL(glBindTexture, mTextureTargets[ct], 0);
420420
continue;
@@ -427,9 +427,9 @@ void RsdShader::setupTextures(const Context *rsc, RsdShaderCache *sc) {
427427
}
428428
RSD_CALL_GL(glBindTexture, drvTex->glTarget, drvTex->textureID);
429429
rsdGLCheckError(rsc, "ProgramFragment::setup tex bind");
430-
if (mRSProgram->mHal.state.samplers[ct].get()) {
431-
setupSampler(rsc, mRSProgram->mHal.state.samplers[ct].get(),
432-
mRSProgram->mHal.state.textures[ct].get());
430+
if (mRSProgram->mHal.state.samplers[ct]) {
431+
setupSampler(rsc, mRSProgram->mHal.state.samplers[ct],
432+
mRSProgram->mHal.state.textures[ct]);
433433
} else {
434434
RSD_CALL_GL(glTexParameteri, drvTex->glTarget, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
435435
RSD_CALL_GL(glTexParameteri, drvTex->glTarget, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
@@ -448,7 +448,7 @@ void RsdShader::setupTextures(const Context *rsc, RsdShaderCache *sc) {
448448
void RsdShader::setupUserConstants(const Context *rsc, RsdShaderCache *sc, bool isFragment) {
449449
uint32_t uidx = 0;
450450
for (uint32_t ct=0; ct < mRSProgram->mHal.state.constantsCount; ct++) {
451-
Allocation *alloc = mRSProgram->mHal.state.constants[ct].get();
451+
Allocation *alloc = mRSProgram->mHal.state.constants[ct];
452452
if (!alloc) {
453453
LOGE("Attempting to set constants on shader id %u, but alloc at slot %u is not set",
454454
(uint32_t)this, ct);
@@ -504,7 +504,7 @@ void RsdShader::setup(const android::renderscript::Context *rsc, RsdShaderCache
504504
void RsdShader::initAttribAndUniformArray() {
505505
mAttribCount = 0;
506506
for (uint32_t ct=0; ct < mRSProgram->mHal.state.inputElementsCount; ct++) {
507-
const Element *elem = mRSProgram->mHal.state.inputElements[ct].get();
507+
const Element *elem = mRSProgram->mHal.state.inputElements[ct];
508508
for (uint32_t field=0; field < elem->getFieldCount(); field++) {
509509
if (elem->getFieldName(field)[0] != '#') {
510510
mAttribCount ++;

libs/rs/rsAllocation.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Allocation::Allocation(Context *rsc, const Type *type, uint32_t usages,
3030
mHal.state.usageFlags = usages;
3131
mHal.state.mipmapControl = mc;
3232

33-
mHal.state.type.set(type);
33+
setType(type);
3434
updateCache();
3535
}
3636

@@ -47,7 +47,7 @@ Allocation * Allocation::createAllocation(Context *rsc, const Type *type, uint32
4747
}
4848

4949
void Allocation::updateCache() {
50-
const Type *type = mHal.state.type.get();
50+
const Type *type = mHal.state.type;
5151
mHal.state.dimensionX = type->getDimX();
5252
mHal.state.dimensionY = type->getDimY();
5353
mHal.state.dimensionZ = type->getDimZ();
@@ -187,7 +187,7 @@ void Allocation::dumpLOGV(const char *prefix) const {
187187

188188
String8 s(prefix);
189189
s.append(" type ");
190-
if (mHal.state.type.get()) {
190+
if (mHal.state.type) {
191191
mHal.state.type->dumpLOGV(s.string());
192192
}
193193

@@ -314,7 +314,7 @@ void Allocation::resize1D(Context *rsc, uint32_t dimX) {
314314
decRefs(getPtr(), oldDimX - dimX, dimX);
315315
}
316316
rsc->mHal.funcs.allocation.resize(rsc, this, t.get(), mHal.state.hasReferences);
317-
mHal.state.type.set(t.get());
317+
setType(t.get());
318318
updateCache();
319319
}
320320

libs/rs/rsAllocation.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class Allocation : public ObjectBase {
4141
void * drv;
4242

4343
struct State {
44-
ObjectBaseRef<const Type> type;
44+
const Type * type;
4545

4646
uint32_t usageFlags;
4747
RsAllocationMipmapControl mipmapControl;
@@ -71,7 +71,7 @@ class Allocation : public ObjectBase {
7171
void updateCache();
7272

7373
void * getPtr() const {return mHal.drvState.mallocPtr;}
74-
const Type * getType() const {return mHal.state.type.get();}
74+
const Type * getType() const {return mHal.state.type;}
7575

7676
void syncAll(Context *rsc, RsAllocationUsageType src);
7777

@@ -126,6 +126,11 @@ class Allocation : public ObjectBase {
126126

127127
protected:
128128
Vector<const Program *> mToDirtyList;
129+
ObjectBaseRef<const Type> mType;
130+
void setType(const Type *t) {
131+
mType.set(t);
132+
mHal.state.type = t;
133+
}
129134

130135
private:
131136
void freeChildrenUnlocked();

libs/rs/rsFBOCache.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,14 @@ using namespace android::renderscript;
2626
FBOCache::FBOCache() {
2727
mDirty = true;
2828
mHal.state.colorTargetsCount = 1;
29-
mHal.state.colorTargets = new ObjectBaseRef<Allocation>[mHal.state.colorTargetsCount];
29+
mHal.state.colorTargets = new Allocation*[mHal.state.colorTargetsCount];
30+
mColorTargets = new ObjectBaseRef<Allocation>[mHal.state.colorTargetsCount];
31+
resetAll(NULL);
3032
}
3133

3234
FBOCache::~FBOCache() {
3335
delete[] mHal.state.colorTargets;
36+
delete[] mColorTargets;
3437
}
3538

3639
void FBOCache::init(Context *rsc) {
@@ -52,7 +55,8 @@ void FBOCache::bindColorTarget(Context *rsc, Allocation *a, uint32_t slot) {
5255
return;
5356
}
5457
}
55-
mHal.state.colorTargets[slot].set(a);
58+
mColorTargets[slot].set(a);
59+
mHal.state.colorTargets[slot] = a;
5660
mDirty = true;
5761
}
5862

@@ -63,15 +67,18 @@ void FBOCache::bindDepthTarget(Context *rsc, Allocation *a) {
6367
return;
6468
}
6569
}
66-
mHal.state.depthTarget.set(a);
70+
mDepthTarget.set(a);
71+
mHal.state.depthTarget = a;
6772
mDirty = true;
6873
}
6974

7075
void FBOCache::resetAll(Context *) {
7176
for (uint32_t i = 0; i < mHal.state.colorTargetsCount; i ++) {
72-
mHal.state.colorTargets[i].set(NULL);
77+
mColorTargets[i].set(NULL);
78+
mHal.state.colorTargets[i] = NULL;
7379
}
74-
mHal.state.depthTarget.set(NULL);
80+
mDepthTarget.set(NULL);
81+
mHal.state.depthTarget = NULL;
7582
mDirty = true;
7683
}
7784

libs/rs/rsFBOCache.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,17 @@ class FBOCache {
4444
mutable void *drv;
4545

4646
struct State {
47-
ObjectBaseRef<Allocation> *colorTargets;
47+
Allocation **colorTargets;
4848
uint32_t colorTargetsCount;
49-
ObjectBaseRef<Allocation> depthTarget;
49+
Allocation *depthTarget;
5050
};
5151
State state;
5252
};
5353
Hal mHal;
5454

5555
protected:
56+
ObjectBaseRef<Allocation> *mColorTargets;
57+
ObjectBaseRef<Allocation> mDepthTarget;
5658
bool mDirty;
5759
void checkError(Context *);
5860
void setColorAttachment(Context *rsc);

0 commit comments

Comments
 (0)