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

Commit 8e90f2bc authored by Alex Sakhartchouk's avatar Alex Sakhartchouk
Browse files

First draft of fbo in renderscript.

Updating samples and benchmark

Change-Id: I469bf8b842fca72b59475c8fa024c12cf0e14954
parent 397de169
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -99,6 +99,14 @@ public class Allocation extends BaseObj {
     */
    public static final int USAGE_GRAPHICS_CONSTANTS = 0x0008;

    /**
     * @hide
     * USAGE_GRAPHICS_RENDER_TARGET The allcation will be used as a
     * target for offscreen rendering
     *
     */
    public static final int USAGE_GRAPHICS_RENDER_TARGET = 0x0010;


    /**
     * Controls mipmap behavior when using the bitmap creation and
@@ -137,7 +145,8 @@ public class Allocation extends BaseObj {
        if ((usage & ~(USAGE_SCRIPT |
                       USAGE_GRAPHICS_TEXTURE |
                       USAGE_GRAPHICS_VERTEX |
                       USAGE_GRAPHICS_CONSTANTS)) != 0) {
                       USAGE_GRAPHICS_CONSTANTS |
                       USAGE_GRAPHICS_RENDER_TARGET)) != 0) {
            throw new RSIllegalArgumentException("Unknown usage specified.");
        }
        mType = t;
+19 −7
Original line number Diff line number Diff line
@@ -124,7 +124,8 @@ public class Element extends BaseObj {
        PIXEL_A (8),
        PIXEL_LA (9),
        PIXEL_RGB (10),
        PIXEL_RGBA (11);
        PIXEL_RGBA (11),
        PIXEL_DEPTH (12);

        int mID;
        DataKind(int id) {
@@ -536,10 +537,12 @@ public class Element extends BaseObj {
              dk == DataKind.PIXEL_A ||
              dk == DataKind.PIXEL_LA ||
              dk == DataKind.PIXEL_RGB ||
              dk == DataKind.PIXEL_RGBA)) {
              dk == DataKind.PIXEL_RGBA ||
              dk == DataKind.PIXEL_DEPTH)) {
            throw new RSIllegalArgumentException("Unsupported DataKind");
        }
        if (!(dt == DataType.UNSIGNED_8 ||
              dt == DataType.UNSIGNED_16 ||
              dt == DataType.UNSIGNED_5_6_5 ||
              dt == DataType.UNSIGNED_4_4_4_4 ||
              dt == DataType.UNSIGNED_5_5_5_1)) {
@@ -554,16 +557,25 @@ public class Element extends BaseObj {
        if (dt == DataType.UNSIGNED_4_4_4_4 && dk != DataKind.PIXEL_RGBA) {
            throw new RSIllegalArgumentException("Bad kind and type combo");
        }
        if (dt == DataType.UNSIGNED_16 &&
            dk != DataKind.PIXEL_DEPTH) {
            throw new RSIllegalArgumentException("Bad kind and type combo");
        }

        int size = 1;
        if (dk == DataKind.PIXEL_LA) {
        switch (dk) {
        case PIXEL_LA:
            size = 2;
        }
        if (dk == DataKind.PIXEL_RGB) {
            break;
        case PIXEL_RGB:
            size = 3;
        }
        if (dk == DataKind.PIXEL_RGBA) {
            break;
        case PIXEL_RGBA:
            size = 4;
            break;
        case PIXEL_DEPTH:
            size = 2;
            break;
        }

        boolean norm = true;
+1 −0
Original line number Diff line number Diff line
@@ -90,6 +90,7 @@ LOCAL_SRC_FILES:= \
	rsContext.cpp \
	rsDevice.cpp \
	rsElement.cpp \
	rsFBOCache.cpp \
	rsFileA3D.cpp \
	rsFont.cpp \
	rsLocklessFifo.cpp \
+2 −0
Original line number Diff line number Diff line
@@ -84,6 +84,7 @@ enum RsAllocationUsageType {
    RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE = 0x0002,
    RS_ALLOCATION_USAGE_GRAPHICS_VERTEX = 0x0004,
    RS_ALLOCATION_USAGE_GRAPHICS_CONSTANTS = 0x0008,
    RS_ALLOCATION_USAGE_GRAPHICS_RENDER_TARGET = 0x0010,

    RS_ALLOCATION_USAGE_ALL = 0x000F
};
@@ -147,6 +148,7 @@ enum RsDataKind {
    RS_KIND_PIXEL_LA,
    RS_KIND_PIXEL_RGB,
    RS_KIND_PIXEL_RGBA,
    RS_KIND_PIXEL_DEPTH,
};

enum RsSamplerParam {
+56 −18
Original line number Diff line number Diff line
@@ -56,7 +56,8 @@ void Allocation::init(Context *rsc, const Type *type) {

    mTextureID = 0;
    mBufferID = 0;
    mUploadDefered = false;
    mRenderTargetID = 0;
    mUploadDeferred = false;

    mUserBitmapCallback = NULL;
    mUserBitmapCallbackData = NULL;
@@ -93,6 +94,10 @@ Allocation::~Allocation() {
        glDeleteTextures(1, &mTextureID);
        mTextureID = 0;
    }
    if (mRenderTargetID) {
        glDeleteRenderbuffers(1, &mRenderTargetID);
        mRenderTargetID = 0;
    }
#endif //ANDROID_RS_SERIALIZE
}

@@ -112,9 +117,14 @@ bool Allocation::fixAllocation() {
    return false;
}

void Allocation::deferedUploadToTexture(const Context *rsc) {
void Allocation::deferredUploadToTexture(const Context *rsc) {
    mHal.state.usageFlags |= RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE;
    mUploadDefered = true;
    mUploadDeferred = true;
}

void Allocation::deferredAllocateRenderTarget(const Context *rsc) {
    mHal.state.usageFlags |= RS_ALLOCATION_USAGE_GRAPHICS_RENDER_TARGET;
    mUploadDeferred = true;
}

uint32_t Allocation::getGLTarget() const {
@@ -155,8 +165,11 @@ void Allocation::syncAll(Context *rsc, RsAllocationUsageType src) {
    if (getIsBufferObject()) {
        uploadToBufferObject(rsc);
    }
    if (getIsRenderTarget() && !getIsTexture()) {
        allocateRenderTarget(rsc);
    }

    mUploadDefered = false;
    mUploadDeferred = false;
}

void Allocation::uploadToTexture(const Context *rsc) {
@@ -184,7 +197,7 @@ void Allocation::uploadToTexture(const Context *rsc) {
            // Force a crash to 1: restart the app, 2: make sure we get a bugreport.
            LOGE("Upload to texture failed to gen mTextureID");
            rsc->dumpDebug();
            mUploadDefered = true;
            mUploadDeferred = true;
            return;
        }
        isFirstUpload = true;
@@ -200,6 +213,32 @@ void Allocation::uploadToTexture(const Context *rsc) {
#endif //ANDROID_RS_SERIALIZE
}

void Allocation::allocateRenderTarget(const Context *rsc) {
#ifndef ANDROID_RS_SERIALIZE
    mHal.state.usageFlags |= RS_ALLOCATION_USAGE_GRAPHICS_RENDER_TARGET;

    GLenum format = mHal.state.type->getElement()->getComponent().getGLFormat();
    if (!format) {
        return;
    }

    if (!mRenderTargetID) {
        glGenRenderbuffers(1, &mRenderTargetID);

        if (!mRenderTargetID) {
            // This should generally not happen
            LOGE("allocateRenderTarget failed to gen mRenderTargetID");
            rsc->dumpDebug();
            return;
        }
        glBindRenderbuffer(GL_RENDERBUFFER, mRenderTargetID);
        glRenderbufferStorage(GL_RENDERBUFFER, format,
                              mHal.state.type->getDimX(),
                              mHal.state.type->getDimY());
    }
#endif //ANDROID_RS_SERIALIZE
}

#ifndef ANDROID_RS_SERIALIZE
const static GLenum gFaceOrder[] = {
    GL_TEXTURE_CUBE_MAP_POSITIVE_X,
@@ -271,9 +310,9 @@ void Allocation::upload2DTexture(bool isFirstUpload) {
#endif //ANDROID_RS_SERIALIZE
}

void Allocation::deferedUploadToBufferObject(const Context *rsc) {
void Allocation::deferredUploadToBufferObject(const Context *rsc) {
    mHal.state.usageFlags |= RS_ALLOCATION_USAGE_GRAPHICS_VERTEX;
    mUploadDefered = true;
    mUploadDeferred = true;
}

void Allocation::uploadToBufferObject(const Context *rsc) {
@@ -288,7 +327,7 @@ void Allocation::uploadToBufferObject(const Context *rsc) {
    }
    if (!mBufferID) {
        LOGE("Upload to buffer object failed");
        mUploadDefered = true;
        mUploadDeferred = true;
        return;
    }
    GLenum target = (GLenum)getGLTarget();
@@ -300,7 +339,7 @@ void Allocation::uploadToBufferObject(const Context *rsc) {
}

void Allocation::uploadCheck(Context *rsc) {
    if (mUploadDefered) {
    if (mUploadDeferred) {
        syncAll(rsc, RS_ALLOCATION_USAGE_SCRIPT);
    }
}
@@ -329,7 +368,7 @@ void Allocation::data(Context *rsc, uint32_t xoff, uint32_t lod,

    memcpy(ptr, data, size);
    sendDirty();
    mUploadDefered = true;
    mUploadDeferred = true;
}

void Allocation::data(Context *rsc, uint32_t xoff, uint32_t yoff, uint32_t lod, RsAllocationCubemapFace face,
@@ -362,7 +401,7 @@ void Allocation::data(Context *rsc, uint32_t xoff, uint32_t yoff, uint32_t lod,
            dst += destW * eSize;
        }
        sendDirty();
        mUploadDefered = true;
        mUploadDeferred = true;
    } else {
        update2DTexture(data, xoff, yoff, lod, face, w, h);
    }
@@ -407,7 +446,7 @@ void Allocation::elementData(Context *rsc, uint32_t x, const void *data,

    memcpy(ptr, data, sizeBytes);
    sendDirty();
    mUploadDefered = true;
    mUploadDeferred = true;
}

void Allocation::elementData(Context *rsc, uint32_t x, uint32_t y,
@@ -450,7 +489,7 @@ void Allocation::elementData(Context *rsc, uint32_t x, uint32_t y,

    memcpy(ptr, data, sizeBytes);
    sendDirty();
    mUploadDefered = true;
    mUploadDeferred = true;
}

void Allocation::addProgramToDirty(const Program *p) {
@@ -617,12 +656,12 @@ namespace renderscript {

void rsi_AllocationUploadToTexture(Context *rsc, RsAllocation va, bool genmip, uint32_t baseMipLevel) {
    Allocation *alloc = static_cast<Allocation *>(va);
    alloc->deferedUploadToTexture(rsc);
    alloc->deferredUploadToTexture(rsc);
}

void rsi_AllocationUploadToBufferObject(Context *rsc, RsAllocation va) {
    Allocation *alloc = static_cast<Allocation *>(va);
    alloc->deferedUploadToBufferObject(rsc);
    alloc->deferredUploadToBufferObject(rsc);
}

static void mip565(const Adapter2D &out, const Adapter2D &in) {
@@ -792,7 +831,6 @@ RsAllocation rsaAllocationCreateTyped(RsContext con, RsType vtype,
    return alloc;
}


RsAllocation rsaAllocationCreateFromBitmap(RsContext con, RsType vtype,
                                           RsAllocationMipmapControl mips,
                                           const void *data, uint32_t usages) {
@@ -811,7 +849,7 @@ RsAllocation rsaAllocationCreateFromBitmap(RsContext con, RsType vtype,
        rsaAllocationGenerateScriptMips(rsc, texAlloc);
    }

    texAlloc->deferedUploadToTexture(rsc);
    texAlloc->deferredUploadToTexture(rsc);
    return texAlloc;
}

@@ -852,7 +890,7 @@ RsAllocation rsaAllocationCubeCreateFromBitmap(RsContext con, RsType vtype,
        rsaAllocationGenerateScriptMips(rsc, texAlloc);
    }

    texAlloc->deferedUploadToTexture(rsc);
    texAlloc->deferredUploadToTexture(rsc);
    return texAlloc;
}

Loading