Skip to content

Commit c759949

Browse files
Jason SamsAndroid (Google) Code Review
authored andcommitted
Merge "Add RS watchdog."
2 parents 48c5fb1 + 5316b9e commit c759949

15 files changed

+186
-106
lines changed

libs/rs/driver/rsdAllocation.cpp

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -73,27 +73,27 @@ GLenum rsdKindToGLFormat(RsDataKind k) {
7373
}
7474

7575

76-
static void Update2DTexture(const Allocation *alloc, const void *ptr, uint32_t xoff, uint32_t yoff,
77-
uint32_t lod, RsAllocationCubemapFace face,
78-
uint32_t w, uint32_t h) {
76+
static void Update2DTexture(const Context *rsc, const Allocation *alloc, const void *ptr,
77+
uint32_t xoff, uint32_t yoff, uint32_t lod,
78+
RsAllocationCubemapFace face, uint32_t w, uint32_t h) {
7979
DrvAllocation *drv = (DrvAllocation *)alloc->mHal.drv;
8080

8181
rsAssert(drv->textureID);
82-
glBindTexture(drv->glTarget, drv->textureID);
83-
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
82+
RSD_CALL_GL(glBindTexture, drv->glTarget, drv->textureID);
83+
RSD_CALL_GL(glPixelStorei, GL_UNPACK_ALIGNMENT, 1);
8484
GLenum t = GL_TEXTURE_2D;
8585
if (alloc->mHal.state.hasFaces) {
8686
t = gFaceOrder[face];
8787
}
88-
glTexSubImage2D(t, lod, xoff, yoff, w, h, drv->glFormat, drv->glType, ptr);
88+
RSD_CALL_GL(glTexSubImage2D, t, lod, xoff, yoff, w, h, drv->glFormat, drv->glType, ptr);
8989
}
9090

9191

9292
static void Upload2DTexture(const Context *rsc, const Allocation *alloc, bool isFirstUpload) {
9393
DrvAllocation *drv = (DrvAllocation *)alloc->mHal.drv;
9494

95-
glBindTexture(drv->glTarget, drv->textureID);
96-
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
95+
RSD_CALL_GL(glBindTexture, drv->glTarget, drv->textureID);
96+
RSD_CALL_GL(glPixelStorei, GL_UNPACK_ALIGNMENT, 1);
9797

9898
uint32_t faceCount = 1;
9999
if (alloc->mHal.state.hasFaces) {
@@ -112,12 +112,12 @@ static void Upload2DTexture(const Context *rsc, const Allocation *alloc, bool is
112112
}
113113

114114
if (isFirstUpload) {
115-
glTexImage2D(t, lod, drv->glFormat,
115+
RSD_CALL_GL(glTexImage2D, t, lod, drv->glFormat,
116116
alloc->mHal.state.type->getLODDimX(lod),
117117
alloc->mHal.state.type->getLODDimY(lod),
118118
0, drv->glFormat, drv->glType, p);
119119
} else {
120-
glTexSubImage2D(t, lod, 0, 0,
120+
RSD_CALL_GL(glTexSubImage2D, t, lod, 0, 0,
121121
alloc->mHal.state.type->getLODDimX(lod),
122122
alloc->mHal.state.type->getLODDimY(lod),
123123
drv->glFormat, drv->glType, p);
@@ -126,7 +126,7 @@ static void Upload2DTexture(const Context *rsc, const Allocation *alloc, bool is
126126
}
127127

128128
if (alloc->mHal.state.mipmapControl == RS_ALLOCATION_MIPMAP_ON_SYNC_TO_TEXTURE) {
129-
glGenerateMipmap(drv->glTarget);
129+
RSD_CALL_GL(glGenerateMipmap, drv->glTarget);
130130
}
131131
rsdGLCheckError(rsc, "Upload2DTexture");
132132
}
@@ -145,7 +145,7 @@ static void UploadToTexture(const Context *rsc, const Allocation *alloc) {
145145
bool isFirstUpload = false;
146146

147147
if (!drv->textureID) {
148-
glGenTextures(1, &drv->textureID);
148+
RSD_CALL_GL(glGenTextures, 1, &drv->textureID);
149149
isFirstUpload = true;
150150
}
151151

@@ -168,16 +168,16 @@ static void AllocateRenderTarget(const Context *rsc, const Allocation *alloc) {
168168
}
169169

170170
if (!drv->renderTargetID) {
171-
glGenRenderbuffers(1, &drv->renderTargetID);
171+
RSD_CALL_GL(glGenRenderbuffers, 1, &drv->renderTargetID);
172172

173173
if (!drv->renderTargetID) {
174174
// This should generally not happen
175175
LOGE("allocateRenderTarget failed to gen mRenderTargetID");
176176
rsc->dumpDebug();
177177
return;
178178
}
179-
glBindRenderbuffer(GL_RENDERBUFFER, drv->renderTargetID);
180-
glRenderbufferStorage(GL_RENDERBUFFER, drv->glFormat,
179+
RSD_CALL_GL(glBindRenderbuffer, GL_RENDERBUFFER, drv->renderTargetID);
180+
RSD_CALL_GL(glRenderbufferStorage, GL_RENDERBUFFER, drv->glFormat,
181181
alloc->mHal.state.dimensionX, alloc->mHal.state.dimensionY);
182182
}
183183
rsdGLCheckError(rsc, "AllocateRenderTarget");
@@ -192,17 +192,17 @@ static void UploadToBufferObject(const Context *rsc, const Allocation *alloc) {
192192
//alloc->mHal.state.usageFlags |= RS_ALLOCATION_USAGE_GRAPHICS_VERTEX;
193193

194194
if (!drv->bufferID) {
195-
glGenBuffers(1, &drv->bufferID);
195+
RSD_CALL_GL(glGenBuffers, 1, &drv->bufferID);
196196
}
197197
if (!drv->bufferID) {
198198
LOGE("Upload to buffer object failed");
199199
drv->uploadDeferred = true;
200200
return;
201201
}
202-
glBindBuffer(drv->glTarget, drv->bufferID);
203-
glBufferData(drv->glTarget, alloc->mHal.state.type->getSizeBytes(),
202+
RSD_CALL_GL(glBindBuffer, drv->glTarget, drv->bufferID);
203+
RSD_CALL_GL(glBufferData, drv->glTarget, alloc->mHal.state.type->getSizeBytes(),
204204
drv->mallocPtr, GL_DYNAMIC_DRAW);
205-
glBindBuffer(drv->glTarget, 0);
205+
RSD_CALL_GL(glBindBuffer, drv->glTarget, 0);
206206
rsdGLCheckError(rsc, "UploadToBufferObject");
207207
}
208208

@@ -261,11 +261,11 @@ void rsdAllocationDestroy(const Context *rsc, Allocation *alloc) {
261261
//mBufferID = 0;
262262
}
263263
if (drv->textureID) {
264-
glDeleteTextures(1, &drv->textureID);
264+
RSD_CALL_GL(glDeleteTextures, 1, &drv->textureID);
265265
drv->textureID = 0;
266266
}
267267
if (drv->renderTargetID) {
268-
glDeleteRenderbuffers(1, &drv->renderTargetID);
268+
RSD_CALL_GL(glDeleteRenderbuffers, 1, &drv->renderTargetID);
269269
drv->renderTargetID = 0;
270270
}
271271

@@ -323,7 +323,7 @@ static void rsdAllocationSyncFromFBO(const Context *rsc, const Allocation *alloc
323323
drv->readBackFBO->setActive(rsc);
324324

325325
// Do the readback
326-
glReadPixels(0, 0, alloc->getType()->getDimX(), alloc->getType()->getDimY(),
326+
RSD_CALL_GL(glReadPixels, 0, 0, alloc->getType()->getDimX(), alloc->getType()->getDimY(),
327327
drv->glFormat, drv->glType, alloc->getPtr());
328328

329329
// Revert framebuffer to its original
@@ -414,7 +414,7 @@ void rsdAllocationData2D(const Context *rsc, const Allocation *alloc,
414414
}
415415
drv->uploadDeferred = true;
416416
} else {
417-
Update2DTexture(alloc, data, xoff, yoff, lod, face, w, h);
417+
Update2DTexture(rsc, alloc, data, xoff, yoff, lod, face, w, h);
418418
}
419419
}
420420

libs/rs/driver/rsdFrameBufferObj.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include "rsdFrameBufferObj.h"
1919
#include "rsdAllocation.h"
20+
#include "rsdGL.h"
2021

2122
#include <GLES2/gl2.h>
2223
#include <GLES2/gl2ext.h>
@@ -124,20 +125,20 @@ void RsdFrameBufferObj::setActive(const Context *rsc) {
124125
bool framebuffer = renderToFramebuffer();
125126
if (!framebuffer) {
126127
if(mFBOId == 0) {
127-
glGenFramebuffers(1, &mFBOId);
128+
RSD_CALL_GL(glGenFramebuffers, 1, &mFBOId);
128129
}
129-
glBindFramebuffer(GL_FRAMEBUFFER, mFBOId);
130+
RSD_CALL_GL(glBindFramebuffer, GL_FRAMEBUFFER, mFBOId);
130131

131132
if (mDirty) {
132133
setDepthAttachment();
133134
setColorAttachment();
134135
mDirty = false;
135136
}
136137

137-
glViewport(0, 0, mWidth, mHeight);
138+
RSD_CALL_GL(glViewport, 0, 0, mWidth, mHeight);
138139
checkError(rsc);
139140
} else {
140-
glBindFramebuffer(GL_FRAMEBUFFER, 0);
141-
glViewport(0, 0, rsc->getWidth(), rsc->getHeight());
141+
RSD_CALL_GL(glBindFramebuffer, GL_FRAMEBUFFER, 0);
142+
RSD_CALL_GL(glViewport, 0, 0, rsc->getWidth(), rsc->getHeight());
142143
}
143144
}

libs/rs/driver/rsdGL.cpp

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,18 +135,19 @@ void rsdGLShutdown(const Context *rsc) {
135135
LOGV("%p, deinitEGL", rsc);
136136

137137
if (dc->gl.egl.context != EGL_NO_CONTEXT) {
138-
eglMakeCurrent(dc->gl.egl.display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
139-
eglDestroySurface(dc->gl.egl.display, dc->gl.egl.surfaceDefault);
138+
RSD_CALL_GL(eglMakeCurrent, dc->gl.egl.display,
139+
EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
140+
RSD_CALL_GL(eglDestroySurface, dc->gl.egl.display, dc->gl.egl.surfaceDefault);
140141
if (dc->gl.egl.surface != EGL_NO_SURFACE) {
141-
eglDestroySurface(dc->gl.egl.display, dc->gl.egl.surface);
142+
RSD_CALL_GL(eglDestroySurface, dc->gl.egl.display, dc->gl.egl.surface);
142143
}
143-
eglDestroyContext(dc->gl.egl.display, dc->gl.egl.context);
144+
RSD_CALL_GL(eglDestroyContext, dc->gl.egl.display, dc->gl.egl.context);
144145
checkEglError("eglDestroyContext");
145146
}
146147

147148
gGLContextCount--;
148149
if (!gGLContextCount) {
149-
eglTerminate(dc->gl.egl.display);
150+
RSD_CALL_GL(eglTerminate, dc->gl.egl.display);
150151
}
151152
}
152153

@@ -202,21 +203,25 @@ bool rsdGLInit(const Context *rsc) {
202203
rsAssert(configAttribsPtr < (configAttribs + (sizeof(configAttribs) / sizeof(EGLint))));
203204

204205
LOGV("%p initEGL start", rsc);
206+
rsc->setWatchdogGL("eglGetDisplay", __LINE__, __FILE__);
205207
dc->gl.egl.display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
206208
checkEglError("eglGetDisplay");
207209

208-
eglInitialize(dc->gl.egl.display, &dc->gl.egl.majorVersion, &dc->gl.egl.minorVersion);
210+
RSD_CALL_GL(eglInitialize, dc->gl.egl.display,
211+
&dc->gl.egl.majorVersion, &dc->gl.egl.minorVersion);
209212
checkEglError("eglInitialize");
210213

211214
EGLBoolean ret;
212215

213216
EGLint numConfigs = -1, n = 0;
217+
rsc->setWatchdogGL("eglChooseConfig", __LINE__, __FILE__);
214218
ret = eglChooseConfig(dc->gl.egl.display, configAttribs, 0, 0, &numConfigs);
215219
checkEglError("eglGetConfigs", ret);
216220

217221
if (numConfigs) {
218222
EGLConfig* const configs = new EGLConfig[numConfigs];
219223

224+
rsc->setWatchdogGL("eglChooseConfig", __LINE__, __FILE__);
220225
ret = eglChooseConfig(dc->gl.egl.display,
221226
configAttribs, configs, numConfigs, &n);
222227
if (!ret || !n) {
@@ -261,32 +266,38 @@ bool rsdGLInit(const Context *rsc) {
261266
}
262267
//}
263268

269+
rsc->setWatchdogGL("eglCreateContext", __LINE__, __FILE__);
264270
dc->gl.egl.context = eglCreateContext(dc->gl.egl.display, dc->gl.egl.config,
265271
EGL_NO_CONTEXT, context_attribs2);
266272
checkEglError("eglCreateContext");
267273
if (dc->gl.egl.context == EGL_NO_CONTEXT) {
268274
LOGE("%p, eglCreateContext returned EGL_NO_CONTEXT", rsc);
275+
rsc->setWatchdogGL(NULL, 0, NULL);
269276
return false;
270277
}
271278
gGLContextCount++;
272279

273280

274281
EGLint pbuffer_attribs[] = { EGL_WIDTH, 1, EGL_HEIGHT, 1, EGL_NONE };
282+
rsc->setWatchdogGL("eglCreatePbufferSurface", __LINE__, __FILE__);
275283
dc->gl.egl.surfaceDefault = eglCreatePbufferSurface(dc->gl.egl.display, dc->gl.egl.config,
276284
pbuffer_attribs);
277285
checkEglError("eglCreatePbufferSurface");
278286
if (dc->gl.egl.surfaceDefault == EGL_NO_SURFACE) {
279287
LOGE("eglCreatePbufferSurface returned EGL_NO_SURFACE");
280288
rsdGLShutdown(rsc);
289+
rsc->setWatchdogGL(NULL, 0, NULL);
281290
return false;
282291
}
283292

293+
rsc->setWatchdogGL("eglMakeCurrent", __LINE__, __FILE__);
284294
ret = eglMakeCurrent(dc->gl.egl.display, dc->gl.egl.surfaceDefault,
285295
dc->gl.egl.surfaceDefault, dc->gl.egl.context);
286296
if (ret == EGL_FALSE) {
287297
LOGE("eglMakeCurrent returned EGL_FALSE");
288298
checkEglError("eglMakeCurrent", ret);
289299
rsdGLShutdown(rsc);
300+
rsc->setWatchdogGL(NULL, 0, NULL);
290301
return false;
291302
}
292303

@@ -314,6 +325,7 @@ bool rsdGLInit(const Context *rsc) {
314325
if (!verptr) {
315326
LOGE("Error, OpenGL ES Lite not supported");
316327
rsdGLShutdown(rsc);
328+
rsc->setWatchdogGL(NULL, 0, NULL);
317329
return false;
318330
} else {
319331
sscanf(verptr, " %i.%i", &dc->gl.gl.majorVersion, &dc->gl.gl.minorVersion);
@@ -352,6 +364,7 @@ bool rsdGLInit(const Context *rsc) {
352364
dc->gl.currentFrameBuffer = NULL;
353365

354366
LOGV("initGLThread end %p", rsc);
367+
rsc->setWatchdogGL(NULL, 0, NULL);
355368
return true;
356369
}
357370

@@ -363,10 +376,12 @@ bool rsdGLSetSurface(const Context *rsc, uint32_t w, uint32_t h, RsNativeWindow
363376
// WAR: Some drivers fail to handle 0 size surfaces correcntly.
364377
// Use the pbuffer to avoid this pitfall.
365378
if ((dc->gl.egl.surface != NULL) || (w == 0) || (h == 0)) {
379+
rsc->setWatchdogGL("eglMakeCurrent", __LINE__, __FILE__);
366380
ret = eglMakeCurrent(dc->gl.egl.display, dc->gl.egl.surfaceDefault,
367381
dc->gl.egl.surfaceDefault, dc->gl.egl.context);
368382
checkEglError("eglMakeCurrent", ret);
369383

384+
rsc->setWatchdogGL("eglDestroySurface", __LINE__, __FILE__);
370385
ret = eglDestroySurface(dc->gl.egl.display, dc->gl.egl.surface);
371386
checkEglError("eglDestroySurface", ret);
372387

@@ -385,23 +400,26 @@ bool rsdGLSetSurface(const Context *rsc, uint32_t w, uint32_t h, RsNativeWindow
385400
dc->gl.width = w;
386401
dc->gl.height = h;
387402

403+
rsc->setWatchdogGL("eglCreateWindowSurface", __LINE__, __FILE__);
388404
dc->gl.egl.surface = eglCreateWindowSurface(dc->gl.egl.display, dc->gl.egl.config,
389405
dc->gl.wndSurface, NULL);
390406
checkEglError("eglCreateWindowSurface");
391407
if (dc->gl.egl.surface == EGL_NO_SURFACE) {
392408
LOGE("eglCreateWindowSurface returned EGL_NO_SURFACE");
393409
}
394410

411+
rsc->setWatchdogGL("eglMakeCurrent", __LINE__, __FILE__);
395412
ret = eglMakeCurrent(dc->gl.egl.display, dc->gl.egl.surface,
396413
dc->gl.egl.surface, dc->gl.egl.context);
397414
checkEglError("eglMakeCurrent", ret);
398415
}
416+
rsc->setWatchdogGL(NULL, 0, NULL);
399417
return true;
400418
}
401419

402420
void rsdGLSwap(const android::renderscript::Context *rsc) {
403421
RsdHal *dc = (RsdHal *)rsc->mHal.drv;
404-
eglSwapBuffers(dc->gl.egl.display, dc->gl.egl.surface);
422+
RSD_CALL_GL(eglSwapBuffers, dc->gl.egl.display, dc->gl.egl.surface);
405423
}
406424

407425
void rsdGLCheckError(const android::renderscript::Context *rsc,

libs/rs/driver/rsdGL.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#include <rs_hal.h>
2121
#include <EGL/egl.h>
2222

23+
#define RSD_CALL_GL(x, ...) rsc->setWatchdogGL(#x, __LINE__, __FILE__); x(__VA_ARGS__); rsc->setWatchdogGL(NULL, 0, NULL)
24+
2325
class RsdShaderCache;
2426
class RsdVertexArrayState;
2527
class RsdFrameBufferObj;
@@ -73,7 +75,6 @@ typedef struct RsdGLRec {
7375
} RsdGL;
7476

7577

76-
7778
bool rsdGLInit(const android::renderscript::Context *rsc);
7879
void rsdGLShutdown(const android::renderscript::Context *rsc);
7980
bool rsdGLSetSurface(const android::renderscript::Context *rsc,

libs/rs/driver/rsdMeshObj.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ bool RsdMeshObj::init() {
130130
return true;
131131
}
132132

133-
void RsdMeshObj::renderPrimitiveRange(const Context *rsc, uint32_t primIndex, uint32_t start, uint32_t len) const {
133+
void RsdMeshObj::renderPrimitiveRange(const Context *rsc, uint32_t primIndex,
134+
uint32_t start, uint32_t len) const {
134135
if (len < 1 || primIndex >= mRSMesh->mHal.state.primitivesCount || mAttribCount == 0) {
135136
LOGE("Invalid mesh or parameters");
136137
return;
@@ -171,14 +172,16 @@ void RsdMeshObj::renderPrimitiveRange(const Context *rsc, uint32_t primIndex, ui
171172
}
172173

173174
if (drvAlloc->bufferID) {
174-
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, drvAlloc->bufferID);
175-
glDrawElements(mGLPrimitives[primIndex], len, GL_UNSIGNED_SHORT, (uint16_t *)(start * 2));
175+
RSD_CALL_GL(glBindBuffer, GL_ELEMENT_ARRAY_BUFFER, drvAlloc->bufferID);
176+
RSD_CALL_GL(glDrawElements, mGLPrimitives[primIndex], len, GL_UNSIGNED_SHORT,
177+
(uint16_t *)(start * 2));
176178
} else {
177-
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
178-
glDrawElements(mGLPrimitives[primIndex], len, GL_UNSIGNED_SHORT, drvAlloc->mallocPtr);
179+
RSD_CALL_GL(glBindBuffer, GL_ELEMENT_ARRAY_BUFFER, 0);
180+
RSD_CALL_GL(glDrawElements, mGLPrimitives[primIndex], len, GL_UNSIGNED_SHORT,
181+
drvAlloc->mallocPtr);
179182
}
180183
} else {
181-
glDrawArrays(mGLPrimitives[primIndex], start, len);
184+
RSD_CALL_GL(glDrawArrays, mGLPrimitives[primIndex], start, len);
182185
}
183186

184187
rsdGLCheckError(rsc, "Mesh::renderPrimitiveRange");

libs/rs/driver/rsdProgramRaster.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,18 @@ bool rsdProgramRasterInit(const Context *, const ProgramRaster *) {
3232
return true;
3333
}
3434

35-
void rsdProgramRasterSetActive(const Context *, const ProgramRaster *pr) {
35+
void rsdProgramRasterSetActive(const Context *rsc, const ProgramRaster *pr) {
3636
switch (pr->mHal.state.cull) {
3737
case RS_CULL_BACK:
38-
glEnable(GL_CULL_FACE);
39-
glCullFace(GL_BACK);
38+
RSD_CALL_GL(glEnable, GL_CULL_FACE);
39+
RSD_CALL_GL(glCullFace, GL_BACK);
4040
break;
4141
case RS_CULL_FRONT:
42-
glEnable(GL_CULL_FACE);
43-
glCullFace(GL_FRONT);
42+
RSD_CALL_GL(glEnable, GL_CULL_FACE);
43+
RSD_CALL_GL(glCullFace, GL_FRONT);
4444
break;
4545
case RS_CULL_NONE:
46-
glDisable(GL_CULL_FACE);
46+
RSD_CALL_GL(glDisable, GL_CULL_FACE);
4747
break;
4848
}
4949

0 commit comments

Comments
 (0)