Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5316b9ee authored by Jason Sams's avatar Jason Sams
Browse files

Add RS watchdog.

Change-Id: I4c912beb84fa8a37ada0088049f7776132e994b6
parent 53fc3e18
Loading
Loading
Loading
Loading
+23 −23
Original line number Diff line number Diff line
@@ -73,27 +73,27 @@ GLenum rsdKindToGLFormat(RsDataKind k) {
}


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

    rsAssert(drv->textureID);
    glBindTexture(drv->glTarget, drv->textureID);
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    RSD_CALL_GL(glBindTexture, drv->glTarget, drv->textureID);
    RSD_CALL_GL(glPixelStorei, GL_UNPACK_ALIGNMENT, 1);
    GLenum t = GL_TEXTURE_2D;
    if (alloc->mHal.state.hasFaces) {
        t = gFaceOrder[face];
    }
    glTexSubImage2D(t, lod, xoff, yoff, w, h, drv->glFormat, drv->glType, ptr);
    RSD_CALL_GL(glTexSubImage2D, t, lod, xoff, yoff, w, h, drv->glFormat, drv->glType, ptr);
}


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

    glBindTexture(drv->glTarget, drv->textureID);
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    RSD_CALL_GL(glBindTexture, drv->glTarget, drv->textureID);
    RSD_CALL_GL(glPixelStorei, GL_UNPACK_ALIGNMENT, 1);

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

            if (isFirstUpload) {
                glTexImage2D(t, lod, drv->glFormat,
                RSD_CALL_GL(glTexImage2D, t, lod, drv->glFormat,
                             alloc->mHal.state.type->getLODDimX(lod),
                             alloc->mHal.state.type->getLODDimY(lod),
                             0, drv->glFormat, drv->glType, p);
            } else {
                glTexSubImage2D(t, lod, 0, 0,
                RSD_CALL_GL(glTexSubImage2D, t, lod, 0, 0,
                                alloc->mHal.state.type->getLODDimX(lod),
                                alloc->mHal.state.type->getLODDimY(lod),
                                drv->glFormat, drv->glType, p);
@@ -126,7 +126,7 @@ static void Upload2DTexture(const Context *rsc, const Allocation *alloc, bool is
    }

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

    if (!drv->textureID) {
        glGenTextures(1, &drv->textureID);
        RSD_CALL_GL(glGenTextures, 1, &drv->textureID);
        isFirstUpload = true;
    }

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

    if (!drv->renderTargetID) {
        glGenRenderbuffers(1, &drv->renderTargetID);
        RSD_CALL_GL(glGenRenderbuffers, 1, &drv->renderTargetID);

        if (!drv->renderTargetID) {
            // This should generally not happen
@@ -176,8 +176,8 @@ static void AllocateRenderTarget(const Context *rsc, const Allocation *alloc) {
            rsc->dumpDebug();
            return;
        }
        glBindRenderbuffer(GL_RENDERBUFFER, drv->renderTargetID);
        glRenderbufferStorage(GL_RENDERBUFFER, drv->glFormat,
        RSD_CALL_GL(glBindRenderbuffer, GL_RENDERBUFFER, drv->renderTargetID);
        RSD_CALL_GL(glRenderbufferStorage, GL_RENDERBUFFER, drv->glFormat,
                              alloc->mHal.state.dimensionX, alloc->mHal.state.dimensionY);
    }
    rsdGLCheckError(rsc, "AllocateRenderTarget");
@@ -192,17 +192,17 @@ static void UploadToBufferObject(const Context *rsc, const Allocation *alloc) {
    //alloc->mHal.state.usageFlags |= RS_ALLOCATION_USAGE_GRAPHICS_VERTEX;

    if (!drv->bufferID) {
        glGenBuffers(1, &drv->bufferID);
        RSD_CALL_GL(glGenBuffers, 1, &drv->bufferID);
    }
    if (!drv->bufferID) {
        LOGE("Upload to buffer object failed");
        drv->uploadDeferred = true;
        return;
    }
    glBindBuffer(drv->glTarget, drv->bufferID);
    glBufferData(drv->glTarget, alloc->mHal.state.type->getSizeBytes(),
    RSD_CALL_GL(glBindBuffer, drv->glTarget, drv->bufferID);
    RSD_CALL_GL(glBufferData, drv->glTarget, alloc->mHal.state.type->getSizeBytes(),
                 drv->mallocPtr, GL_DYNAMIC_DRAW);
    glBindBuffer(drv->glTarget, 0);
    RSD_CALL_GL(glBindBuffer, drv->glTarget, 0);
    rsdGLCheckError(rsc, "UploadToBufferObject");
}

@@ -261,11 +261,11 @@ void rsdAllocationDestroy(const Context *rsc, Allocation *alloc) {
        //mBufferID = 0;
    }
    if (drv->textureID) {
        glDeleteTextures(1, &drv->textureID);
        RSD_CALL_GL(glDeleteTextures, 1, &drv->textureID);
        drv->textureID = 0;
    }
    if (drv->renderTargetID) {
        glDeleteRenderbuffers(1, &drv->renderTargetID);
        RSD_CALL_GL(glDeleteRenderbuffers, 1, &drv->renderTargetID);
        drv->renderTargetID = 0;
    }

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

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

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

+6 −5
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@

#include "rsdFrameBufferObj.h"
#include "rsdAllocation.h"
#include "rsdGL.h"

#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
@@ -124,9 +125,9 @@ void RsdFrameBufferObj::setActive(const Context *rsc) {
    bool framebuffer = renderToFramebuffer();
    if (!framebuffer) {
        if(mFBOId == 0) {
            glGenFramebuffers(1, &mFBOId);
            RSD_CALL_GL(glGenFramebuffers, 1, &mFBOId);
        }
        glBindFramebuffer(GL_FRAMEBUFFER, mFBOId);
        RSD_CALL_GL(glBindFramebuffer, GL_FRAMEBUFFER, mFBOId);

        if (mDirty) {
            setDepthAttachment();
@@ -134,10 +135,10 @@ void RsdFrameBufferObj::setActive(const Context *rsc) {
            mDirty = false;
        }

        glViewport(0, 0, mWidth, mHeight);
        RSD_CALL_GL(glViewport, 0, 0, mWidth, mHeight);
        checkError(rsc);
    } else {
        glBindFramebuffer(GL_FRAMEBUFFER, 0);
        glViewport(0, 0, rsc->getWidth(), rsc->getHeight());
        RSD_CALL_GL(glBindFramebuffer, GL_FRAMEBUFFER, 0);
        RSD_CALL_GL(glViewport, 0, 0, rsc->getWidth(), rsc->getHeight());
    }
}
+25 −7
Original line number Diff line number Diff line
@@ -135,18 +135,19 @@ void rsdGLShutdown(const Context *rsc) {
    LOGV("%p, deinitEGL", rsc);

    if (dc->gl.egl.context != EGL_NO_CONTEXT) {
        eglMakeCurrent(dc->gl.egl.display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
        eglDestroySurface(dc->gl.egl.display, dc->gl.egl.surfaceDefault);
        RSD_CALL_GL(eglMakeCurrent, dc->gl.egl.display,
                    EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
        RSD_CALL_GL(eglDestroySurface, dc->gl.egl.display, dc->gl.egl.surfaceDefault);
        if (dc->gl.egl.surface != EGL_NO_SURFACE) {
            eglDestroySurface(dc->gl.egl.display, dc->gl.egl.surface);
            RSD_CALL_GL(eglDestroySurface, dc->gl.egl.display, dc->gl.egl.surface);
        }
        eglDestroyContext(dc->gl.egl.display, dc->gl.egl.context);
        RSD_CALL_GL(eglDestroyContext, dc->gl.egl.display, dc->gl.egl.context);
        checkEglError("eglDestroyContext");
    }

    gGLContextCount--;
    if (!gGLContextCount) {
        eglTerminate(dc->gl.egl.display);
        RSD_CALL_GL(eglTerminate, dc->gl.egl.display);
    }
}

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

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

    eglInitialize(dc->gl.egl.display, &dc->gl.egl.majorVersion, &dc->gl.egl.minorVersion);
    RSD_CALL_GL(eglInitialize, dc->gl.egl.display,
                &dc->gl.egl.majorVersion, &dc->gl.egl.minorVersion);
    checkEglError("eglInitialize");

    EGLBoolean ret;

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

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

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

    rsc->setWatchdogGL("eglCreateContext", __LINE__, __FILE__);
    dc->gl.egl.context = eglCreateContext(dc->gl.egl.display, dc->gl.egl.config,
                                          EGL_NO_CONTEXT, context_attribs2);
    checkEglError("eglCreateContext");
    if (dc->gl.egl.context == EGL_NO_CONTEXT) {
        LOGE("%p, eglCreateContext returned EGL_NO_CONTEXT", rsc);
        rsc->setWatchdogGL(NULL, 0, NULL);
        return false;
    }
    gGLContextCount++;


    EGLint pbuffer_attribs[] = { EGL_WIDTH, 1, EGL_HEIGHT, 1, EGL_NONE };
    rsc->setWatchdogGL("eglCreatePbufferSurface", __LINE__, __FILE__);
    dc->gl.egl.surfaceDefault = eglCreatePbufferSurface(dc->gl.egl.display, dc->gl.egl.config,
                                                        pbuffer_attribs);
    checkEglError("eglCreatePbufferSurface");
    if (dc->gl.egl.surfaceDefault == EGL_NO_SURFACE) {
        LOGE("eglCreatePbufferSurface returned EGL_NO_SURFACE");
        rsdGLShutdown(rsc);
        rsc->setWatchdogGL(NULL, 0, NULL);
        return false;
    }

    rsc->setWatchdogGL("eglMakeCurrent", __LINE__, __FILE__);
    ret = eglMakeCurrent(dc->gl.egl.display, dc->gl.egl.surfaceDefault,
                         dc->gl.egl.surfaceDefault, dc->gl.egl.context);
    if (ret == EGL_FALSE) {
        LOGE("eglMakeCurrent returned EGL_FALSE");
        checkEglError("eglMakeCurrent", ret);
        rsdGLShutdown(rsc);
        rsc->setWatchdogGL(NULL, 0, NULL);
        return false;
    }

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

    LOGV("initGLThread end %p", rsc);
    rsc->setWatchdogGL(NULL, 0, NULL);
    return true;
}

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

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

@@ -385,6 +400,7 @@ bool rsdGLSetSurface(const Context *rsc, uint32_t w, uint32_t h, RsNativeWindow
        dc->gl.width = w;
        dc->gl.height = h;

        rsc->setWatchdogGL("eglCreateWindowSurface", __LINE__, __FILE__);
        dc->gl.egl.surface = eglCreateWindowSurface(dc->gl.egl.display, dc->gl.egl.config,
                                                    dc->gl.wndSurface, NULL);
        checkEglError("eglCreateWindowSurface");
@@ -392,16 +408,18 @@ bool rsdGLSetSurface(const Context *rsc, uint32_t w, uint32_t h, RsNativeWindow
            LOGE("eglCreateWindowSurface returned EGL_NO_SURFACE");
        }

        rsc->setWatchdogGL("eglMakeCurrent", __LINE__, __FILE__);
        ret = eglMakeCurrent(dc->gl.egl.display, dc->gl.egl.surface,
                             dc->gl.egl.surface, dc->gl.egl.context);
        checkEglError("eglMakeCurrent", ret);
    }
    rsc->setWatchdogGL(NULL, 0, NULL);
    return true;
}

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

void rsdGLCheckError(const android::renderscript::Context *rsc,
+2 −1
Original line number Diff line number Diff line
@@ -20,6 +20,8 @@
#include <rs_hal.h>
#include <EGL/egl.h>

#define RSD_CALL_GL(x, ...) rsc->setWatchdogGL(#x, __LINE__, __FILE__); x(__VA_ARGS__); rsc->setWatchdogGL(NULL, 0, NULL)

class RsdShaderCache;
class RsdVertexArrayState;
class RsdFrameBufferObj;
@@ -73,7 +75,6 @@ typedef struct RsdGLRec {
} RsdGL;



bool rsdGLInit(const android::renderscript::Context *rsc);
void rsdGLShutdown(const android::renderscript::Context *rsc);
bool rsdGLSetSurface(const android::renderscript::Context *rsc,
+9 −6
Original line number Diff line number Diff line
@@ -130,7 +130,8 @@ bool RsdMeshObj::init() {
    return true;
}

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

        if (drvAlloc->bufferID) {
            glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, drvAlloc->bufferID);
            glDrawElements(mGLPrimitives[primIndex], len, GL_UNSIGNED_SHORT, (uint16_t *)(start * 2));
            RSD_CALL_GL(glBindBuffer, GL_ELEMENT_ARRAY_BUFFER, drvAlloc->bufferID);
            RSD_CALL_GL(glDrawElements, mGLPrimitives[primIndex], len, GL_UNSIGNED_SHORT,
                        (uint16_t *)(start * 2));
        } else {
            glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
            glDrawElements(mGLPrimitives[primIndex], len, GL_UNSIGNED_SHORT, drvAlloc->mallocPtr);
            RSD_CALL_GL(glBindBuffer, GL_ELEMENT_ARRAY_BUFFER, 0);
            RSD_CALL_GL(glDrawElements, mGLPrimitives[primIndex], len, GL_UNSIGNED_SHORT,
                        drvAlloc->mallocPtr);
        }
    } else {
        glDrawArrays(mGLPrimitives[primIndex], start, len);
        RSD_CALL_GL(glDrawArrays, mGLPrimitives[primIndex], start, len);
    }

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