Loading libs/rs/driver/rsdAllocation.cpp +42 −16 Original line number Diff line number Diff line Loading @@ -41,13 +41,42 @@ const static GLenum gFaceOrder[] = { }; GLenum rsdTypeToGLType(RsDataType t) { switch (t) { case RS_TYPE_UNSIGNED_5_6_5: return GL_UNSIGNED_SHORT_5_6_5; case RS_TYPE_UNSIGNED_5_5_5_1: return GL_UNSIGNED_SHORT_5_5_5_1; case RS_TYPE_UNSIGNED_4_4_4_4: return GL_UNSIGNED_SHORT_4_4_4_4; //case RS_TYPE_FLOAT_16: return GL_HALF_FLOAT; case RS_TYPE_FLOAT_32: return GL_FLOAT; case RS_TYPE_UNSIGNED_8: return GL_UNSIGNED_BYTE; case RS_TYPE_UNSIGNED_16: return GL_UNSIGNED_SHORT; case RS_TYPE_SIGNED_8: return GL_BYTE; case RS_TYPE_SIGNED_16: return GL_SHORT; default: break; } return 0; } GLenum rsdKindToGLFormat(RsDataKind k) { switch (k) { case RS_KIND_PIXEL_L: return GL_LUMINANCE; case RS_KIND_PIXEL_A: return GL_ALPHA; case RS_KIND_PIXEL_LA: return GL_LUMINANCE_ALPHA; case RS_KIND_PIXEL_RGB: return GL_RGB; case RS_KIND_PIXEL_RGBA: return GL_RGBA; case RS_KIND_PIXEL_DEPTH: return GL_DEPTH_COMPONENT16; default: break; } return 0; } 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) { DrvAllocation *drv = (DrvAllocation *)alloc->mHal.drv; const GLenum type = alloc->mHal.state.type->getElement()->getComponent().getGLType(); const GLenum format = alloc->mHal.state.type->getElement()->getComponent().getGLFormat(); rsAssert(drv->textureID); glBindTexture(drv->glTarget, drv->textureID); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); Loading @@ -55,16 +84,13 @@ static void Update2DTexture(const Allocation *alloc, const void *ptr, uint32_t x if (alloc->mHal.state.hasFaces) { t = gFaceOrder[face]; } glTexSubImage2D(t, lod, xoff, yoff, w, h, format, type, ptr); 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; GLenum type = alloc->mHal.state.type->getElement()->getComponent().getGLType(); GLenum format = alloc->mHal.state.type->getElement()->getComponent().getGLFormat(); glBindTexture(drv->glTarget, drv->textureID); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); Loading @@ -85,15 +111,15 @@ static void Upload2DTexture(const Context *rsc, const Allocation *alloc, bool is } if (isFirstUpload) { glTexImage2D(t, lod, format, glTexImage2D(t, lod, drv->glFormat, alloc->mHal.state.type->getLODDimX(lod), alloc->mHal.state.type->getLODDimY(lod), 0, format, type, p); 0, drv->glFormat, drv->glType, p); } else { glTexSubImage2D(t, lod, 0, 0, alloc->mHal.state.type->getLODDimX(lod), alloc->mHal.state.type->getLODDimY(lod), format, type, p); drv->glFormat, drv->glType, p); } } } Loading @@ -107,10 +133,7 @@ static void Upload2DTexture(const Context *rsc, const Allocation *alloc, bool is static void UploadToTexture(const Context *rsc, const Allocation *alloc) { DrvAllocation *drv = (DrvAllocation *)alloc->mHal.drv; GLenum type = alloc->mHal.state.type->getElement()->getComponent().getGLType(); GLenum format = alloc->mHal.state.type->getElement()->getComponent().getGLFormat(); if (!type || !format) { if (!drv->glType || !drv->glFormat) { return; } Loading Loading @@ -139,8 +162,7 @@ static void UploadToTexture(const Context *rsc, const Allocation *alloc) { static void AllocateRenderTarget(const Context *rsc, const Allocation *alloc) { DrvAllocation *drv = (DrvAllocation *)alloc->mHal.drv; GLenum format = alloc->mHal.state.type->getElement()->getComponent().getGLFormat(); if (!format) { if (!drv->glFormat) { return; } Loading @@ -154,7 +176,7 @@ static void AllocateRenderTarget(const Context *rsc, const Allocation *alloc) { return; } glBindRenderbuffer(GL_RENDERBUFFER, drv->renderTargetID); glRenderbufferStorage(GL_RENDERBUFFER, format, glRenderbufferStorage(GL_RENDERBUFFER, drv->glFormat, alloc->mHal.state.dimensionX, alloc->mHal.state.dimensionY); } rsdGLCheckError(rsc, "AllocateRenderTarget"); Loading Loading @@ -208,6 +230,10 @@ bool rsdAllocationInit(const Context *rsc, Allocation *alloc, bool forceZero) { } } drv->glType = rsdTypeToGLType(alloc->mHal.state.type->getElement()->getComponent().getType()); drv->glFormat = rsdKindToGLFormat(alloc->mHal.state.type->getElement()->getComponent().getKind()); alloc->mHal.drvState.mallocPtr = ptr; drv->mallocPtr = (uint8_t *)ptr; alloc->mHal.drv = drv; Loading libs/rs/driver/rsdAllocation.h +7 −0 Original line number Diff line number Diff line Loading @@ -39,10 +39,17 @@ struct DrvAllocation { uint8_t * mallocPtr; GLenum glTarget; GLenum glType; GLenum glFormat; bool uploadDeferred; }; GLenum rsdTypeToGLType(RsDataType t); GLenum rsdKindToGLFormat(RsDataKind k); bool rsdAllocationInit(const android::renderscript::Context *rsc, android::renderscript::Allocation *alloc, bool forceZero); Loading libs/rs/driver/rsdMeshObj.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -114,7 +114,7 @@ bool RsdMeshObj::init() { mAttribs[userNum].size = c.getVectorSize(); mAttribs[userNum].offset = elem->getFieldOffsetBytes(fieldI); mAttribs[userNum].type = c.getGLType(); mAttribs[userNum].type = rsdTypeToGLType(c.getType()); mAttribs[userNum].normalized = c.getType() != RS_TYPE_FLOAT_32;//c.getIsNormalized(); mAttribs[userNum].stride = stride; String8 tmp(RS_SHADER_ATTR); Loading libs/rs/rsComponent.cpp +1 −39 Original line number Diff line number Diff line Loading @@ -16,11 +16,6 @@ #include "rsComponent.h" #ifndef ANDROID_RS_SERIALIZE #include <GLES/gl.h> #include <GLES2/gl2.h> #endif using namespace android; using namespace android::renderscript; Loading Loading @@ -181,40 +176,6 @@ bool Component::isReference() const { return (mType >= RS_TYPE_ELEMENT); } uint32_t Component::getGLType() const { #ifndef ANDROID_RS_SERIALIZE switch (mType) { case RS_TYPE_UNSIGNED_5_6_5: return GL_UNSIGNED_SHORT_5_6_5; case RS_TYPE_UNSIGNED_5_5_5_1: return GL_UNSIGNED_SHORT_5_5_5_1; case RS_TYPE_UNSIGNED_4_4_4_4: return GL_UNSIGNED_SHORT_4_4_4_4; //case RS_TYPE_FLOAT_16: return GL_HALF_FLOAT; case RS_TYPE_FLOAT_32: return GL_FLOAT; case RS_TYPE_UNSIGNED_8: return GL_UNSIGNED_BYTE; case RS_TYPE_UNSIGNED_16: return GL_UNSIGNED_SHORT; case RS_TYPE_SIGNED_8: return GL_BYTE; case RS_TYPE_SIGNED_16: return GL_SHORT; default: break; } #endif //ANDROID_RS_SERIALIZE return 0; } uint32_t Component::getGLFormat() const { #ifndef ANDROID_RS_SERIALIZE switch (mKind) { case RS_KIND_PIXEL_L: return GL_LUMINANCE; case RS_KIND_PIXEL_A: return GL_ALPHA; case RS_KIND_PIXEL_LA: return GL_LUMINANCE_ALPHA; case RS_KIND_PIXEL_RGB: return GL_RGB; case RS_KIND_PIXEL_RGBA: return GL_RGBA; case RS_KIND_PIXEL_DEPTH: return GL_DEPTH_COMPONENT16; default: break; } #endif //ANDROID_RS_SERIALIZE return 0; } String8 Component::getGLSLType() const { if (mType == RS_TYPE_SIGNED_32) { switch (mVectorSize) { Loading Loading @@ -244,6 +205,7 @@ String8 Component::getGLSLType() const { return String8(); } static const char * gTypeBasicStrings[] = { "NONE", "F16", Loading libs/rs/rsComponent.h +0 −2 Original line number Diff line number Diff line Loading @@ -32,8 +32,6 @@ public: void set(RsDataType dt, RsDataKind dk, bool norm, uint32_t vecSize=1); uint32_t getGLType() const; uint32_t getGLFormat() const; String8 getGLSLType() const; void dumpLOGV(const char *prefix) const; Loading Loading
libs/rs/driver/rsdAllocation.cpp +42 −16 Original line number Diff line number Diff line Loading @@ -41,13 +41,42 @@ const static GLenum gFaceOrder[] = { }; GLenum rsdTypeToGLType(RsDataType t) { switch (t) { case RS_TYPE_UNSIGNED_5_6_5: return GL_UNSIGNED_SHORT_5_6_5; case RS_TYPE_UNSIGNED_5_5_5_1: return GL_UNSIGNED_SHORT_5_5_5_1; case RS_TYPE_UNSIGNED_4_4_4_4: return GL_UNSIGNED_SHORT_4_4_4_4; //case RS_TYPE_FLOAT_16: return GL_HALF_FLOAT; case RS_TYPE_FLOAT_32: return GL_FLOAT; case RS_TYPE_UNSIGNED_8: return GL_UNSIGNED_BYTE; case RS_TYPE_UNSIGNED_16: return GL_UNSIGNED_SHORT; case RS_TYPE_SIGNED_8: return GL_BYTE; case RS_TYPE_SIGNED_16: return GL_SHORT; default: break; } return 0; } GLenum rsdKindToGLFormat(RsDataKind k) { switch (k) { case RS_KIND_PIXEL_L: return GL_LUMINANCE; case RS_KIND_PIXEL_A: return GL_ALPHA; case RS_KIND_PIXEL_LA: return GL_LUMINANCE_ALPHA; case RS_KIND_PIXEL_RGB: return GL_RGB; case RS_KIND_PIXEL_RGBA: return GL_RGBA; case RS_KIND_PIXEL_DEPTH: return GL_DEPTH_COMPONENT16; default: break; } return 0; } 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) { DrvAllocation *drv = (DrvAllocation *)alloc->mHal.drv; const GLenum type = alloc->mHal.state.type->getElement()->getComponent().getGLType(); const GLenum format = alloc->mHal.state.type->getElement()->getComponent().getGLFormat(); rsAssert(drv->textureID); glBindTexture(drv->glTarget, drv->textureID); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); Loading @@ -55,16 +84,13 @@ static void Update2DTexture(const Allocation *alloc, const void *ptr, uint32_t x if (alloc->mHal.state.hasFaces) { t = gFaceOrder[face]; } glTexSubImage2D(t, lod, xoff, yoff, w, h, format, type, ptr); 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; GLenum type = alloc->mHal.state.type->getElement()->getComponent().getGLType(); GLenum format = alloc->mHal.state.type->getElement()->getComponent().getGLFormat(); glBindTexture(drv->glTarget, drv->textureID); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); Loading @@ -85,15 +111,15 @@ static void Upload2DTexture(const Context *rsc, const Allocation *alloc, bool is } if (isFirstUpload) { glTexImage2D(t, lod, format, glTexImage2D(t, lod, drv->glFormat, alloc->mHal.state.type->getLODDimX(lod), alloc->mHal.state.type->getLODDimY(lod), 0, format, type, p); 0, drv->glFormat, drv->glType, p); } else { glTexSubImage2D(t, lod, 0, 0, alloc->mHal.state.type->getLODDimX(lod), alloc->mHal.state.type->getLODDimY(lod), format, type, p); drv->glFormat, drv->glType, p); } } } Loading @@ -107,10 +133,7 @@ static void Upload2DTexture(const Context *rsc, const Allocation *alloc, bool is static void UploadToTexture(const Context *rsc, const Allocation *alloc) { DrvAllocation *drv = (DrvAllocation *)alloc->mHal.drv; GLenum type = alloc->mHal.state.type->getElement()->getComponent().getGLType(); GLenum format = alloc->mHal.state.type->getElement()->getComponent().getGLFormat(); if (!type || !format) { if (!drv->glType || !drv->glFormat) { return; } Loading Loading @@ -139,8 +162,7 @@ static void UploadToTexture(const Context *rsc, const Allocation *alloc) { static void AllocateRenderTarget(const Context *rsc, const Allocation *alloc) { DrvAllocation *drv = (DrvAllocation *)alloc->mHal.drv; GLenum format = alloc->mHal.state.type->getElement()->getComponent().getGLFormat(); if (!format) { if (!drv->glFormat) { return; } Loading @@ -154,7 +176,7 @@ static void AllocateRenderTarget(const Context *rsc, const Allocation *alloc) { return; } glBindRenderbuffer(GL_RENDERBUFFER, drv->renderTargetID); glRenderbufferStorage(GL_RENDERBUFFER, format, glRenderbufferStorage(GL_RENDERBUFFER, drv->glFormat, alloc->mHal.state.dimensionX, alloc->mHal.state.dimensionY); } rsdGLCheckError(rsc, "AllocateRenderTarget"); Loading Loading @@ -208,6 +230,10 @@ bool rsdAllocationInit(const Context *rsc, Allocation *alloc, bool forceZero) { } } drv->glType = rsdTypeToGLType(alloc->mHal.state.type->getElement()->getComponent().getType()); drv->glFormat = rsdKindToGLFormat(alloc->mHal.state.type->getElement()->getComponent().getKind()); alloc->mHal.drvState.mallocPtr = ptr; drv->mallocPtr = (uint8_t *)ptr; alloc->mHal.drv = drv; Loading
libs/rs/driver/rsdAllocation.h +7 −0 Original line number Diff line number Diff line Loading @@ -39,10 +39,17 @@ struct DrvAllocation { uint8_t * mallocPtr; GLenum glTarget; GLenum glType; GLenum glFormat; bool uploadDeferred; }; GLenum rsdTypeToGLType(RsDataType t); GLenum rsdKindToGLFormat(RsDataKind k); bool rsdAllocationInit(const android::renderscript::Context *rsc, android::renderscript::Allocation *alloc, bool forceZero); Loading
libs/rs/driver/rsdMeshObj.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -114,7 +114,7 @@ bool RsdMeshObj::init() { mAttribs[userNum].size = c.getVectorSize(); mAttribs[userNum].offset = elem->getFieldOffsetBytes(fieldI); mAttribs[userNum].type = c.getGLType(); mAttribs[userNum].type = rsdTypeToGLType(c.getType()); mAttribs[userNum].normalized = c.getType() != RS_TYPE_FLOAT_32;//c.getIsNormalized(); mAttribs[userNum].stride = stride; String8 tmp(RS_SHADER_ATTR); Loading
libs/rs/rsComponent.cpp +1 −39 Original line number Diff line number Diff line Loading @@ -16,11 +16,6 @@ #include "rsComponent.h" #ifndef ANDROID_RS_SERIALIZE #include <GLES/gl.h> #include <GLES2/gl2.h> #endif using namespace android; using namespace android::renderscript; Loading Loading @@ -181,40 +176,6 @@ bool Component::isReference() const { return (mType >= RS_TYPE_ELEMENT); } uint32_t Component::getGLType() const { #ifndef ANDROID_RS_SERIALIZE switch (mType) { case RS_TYPE_UNSIGNED_5_6_5: return GL_UNSIGNED_SHORT_5_6_5; case RS_TYPE_UNSIGNED_5_5_5_1: return GL_UNSIGNED_SHORT_5_5_5_1; case RS_TYPE_UNSIGNED_4_4_4_4: return GL_UNSIGNED_SHORT_4_4_4_4; //case RS_TYPE_FLOAT_16: return GL_HALF_FLOAT; case RS_TYPE_FLOAT_32: return GL_FLOAT; case RS_TYPE_UNSIGNED_8: return GL_UNSIGNED_BYTE; case RS_TYPE_UNSIGNED_16: return GL_UNSIGNED_SHORT; case RS_TYPE_SIGNED_8: return GL_BYTE; case RS_TYPE_SIGNED_16: return GL_SHORT; default: break; } #endif //ANDROID_RS_SERIALIZE return 0; } uint32_t Component::getGLFormat() const { #ifndef ANDROID_RS_SERIALIZE switch (mKind) { case RS_KIND_PIXEL_L: return GL_LUMINANCE; case RS_KIND_PIXEL_A: return GL_ALPHA; case RS_KIND_PIXEL_LA: return GL_LUMINANCE_ALPHA; case RS_KIND_PIXEL_RGB: return GL_RGB; case RS_KIND_PIXEL_RGBA: return GL_RGBA; case RS_KIND_PIXEL_DEPTH: return GL_DEPTH_COMPONENT16; default: break; } #endif //ANDROID_RS_SERIALIZE return 0; } String8 Component::getGLSLType() const { if (mType == RS_TYPE_SIGNED_32) { switch (mVectorSize) { Loading Loading @@ -244,6 +205,7 @@ String8 Component::getGLSLType() const { return String8(); } static const char * gTypeBasicStrings[] = { "NONE", "F16", Loading
libs/rs/rsComponent.h +0 −2 Original line number Diff line number Diff line Loading @@ -32,8 +32,6 @@ public: void set(RsDataType dt, RsDataKind dk, bool norm, uint32_t vecSize=1); uint32_t getGLType() const; uint32_t getGLFormat() const; String8 getGLSLType() const; void dumpLOGV(const char *prefix) const; Loading