diff options
author | Alex Sakhartchouk <alexst@google.com> | 2010-10-01 10:54:06 -0700 |
---|---|---|
committer | Alex Sakhartchouk <alexst@google.com> | 2010-10-01 14:11:52 -0700 |
commit | feede2aee6fe3e721ee71ffc35b277f1d9260e03 (patch) | |
tree | c6df2da8461c6ae5578dac9a999a040cd903e32d /libs/rs | |
parent | e0ad63bf1e038dd84ec2502243236f86104f990d (diff) | |
download | frameworks_base-feede2aee6fe3e721ee71ffc35b277f1d9260e03.zip frameworks_base-feede2aee6fe3e721ee71ffc35b277f1d9260e03.tar.gz frameworks_base-feede2aee6fe3e721ee71ffc35b277f1d9260e03.tar.bz2 |
fixing bugs 3053960, 3044804, 3044798
shader cleanup and removing unnecessary state setup.
Change-Id: Ibddf2ad3a26bb983fc43bdeb58b1cec6224920b4
Diffstat (limited to 'libs/rs')
-rw-r--r-- | libs/rs/rsContext.cpp | 4 | ||||
-rw-r--r-- | libs/rs/rsContext.h | 1 | ||||
-rw-r--r-- | libs/rs/rsProgram.cpp | 8 | ||||
-rw-r--r-- | libs/rs/rsProgramFragment.cpp | 3 | ||||
-rw-r--r-- | libs/rs/rsProgramVertex.cpp | 12 | ||||
-rw-r--r-- | libs/rs/rsScriptC_LibGL.cpp | 8 | ||||
-rw-r--r-- | libs/rs/rsShaderCache.cpp | 74 | ||||
-rw-r--r-- | libs/rs/rsShaderCache.h | 7 |
8 files changed, 63 insertions, 54 deletions
diff --git a/libs/rs/rsContext.cpp b/libs/rs/rsContext.cpp index 4752b35..6940033 100644 --- a/libs/rs/rsContext.cpp +++ b/libs/rs/rsContext.cpp @@ -241,6 +241,10 @@ bool Context::setupCheck() return true; } +void Context::setupProgramStore() { + mFragmentStore->setupGL2(this, &mStateFragmentStore); +} + static bool getProp(const char *str) { char buf[PROPERTY_VALUE_MAX]; diff --git a/libs/rs/rsContext.h b/libs/rs/rsContext.h index f90e4af..dabe196 100644 --- a/libs/rs/rsContext.h +++ b/libs/rs/rsContext.h @@ -118,6 +118,7 @@ public: Font * getFont() {return mFont.get();} bool setupCheck(); + void setupProgramStore(); bool checkDriver() const {return mEGL.mSurface != 0;} void pause(); diff --git a/libs/rs/rsProgram.cpp b/libs/rs/rsProgram.cpp index 2531a9b..10e00e6 100644 --- a/libs/rs/rsProgram.cpp +++ b/libs/rs/rsProgram.cpp @@ -115,6 +115,14 @@ Program::Program(Context *rsc, const char * shaderText, uint32_t shaderLength, Program::~Program() { + if(mRSC->props.mLogShaders) { + LOGV("Program::~Program with shader id %u", mShaderID); + } + + if(mShaderID) { + glDeleteShader(mShaderID); + } + for (uint32_t ct=0; ct < MAX_UNIFORMS; ct++) { bindAllocation(NULL, NULL, ct); } diff --git a/libs/rs/rsProgramFragment.cpp b/libs/rs/rsProgramFragment.cpp index 275a1df..c94f294 100644 --- a/libs/rs/rsProgramFragment.cpp +++ b/libs/rs/rsProgramFragment.cpp @@ -49,6 +49,9 @@ ProgramFragment::ProgramFragment(Context *rsc, const char * shaderText, ProgramFragment::~ProgramFragment() { + if(mShaderID) { + mRSC->mShaderCache.cleanupFragment(mShaderID); + } } void ProgramFragment::setConstantColor(Context *rsc, float r, float g, float b, float a) diff --git a/libs/rs/rsProgramVertex.cpp b/libs/rs/rsProgramVertex.cpp index bd12989..d3dbfb2 100644 --- a/libs/rs/rsProgramVertex.cpp +++ b/libs/rs/rsProgramVertex.cpp @@ -45,15 +45,9 @@ ProgramVertex::ProgramVertex(Context *rsc, const char * shaderText, ProgramVertex::~ProgramVertex() { -} - -static void logMatrix(const char *txt, const float *f) -{ - LOGV("Matrix %s, %p", txt, f); - LOGV("%6.4f, %6.4f, %6.4f, %6.4f", f[0], f[4], f[8], f[12]); - LOGV("%6.4f, %6.4f, %6.4f, %6.4f", f[1], f[5], f[9], f[13]); - LOGV("%6.4f, %6.4f, %6.4f, %6.4f", f[2], f[6], f[10], f[14]); - LOGV("%6.4f, %6.4f, %6.4f, %6.4f", f[3], f[7], f[11], f[15]); + if(mShaderID) { + mRSC->mShaderCache.cleanupVertex(mShaderID); + } } void ProgramVertex::loadShader(Context *rsc) { diff --git a/libs/rs/rsScriptC_LibGL.cpp b/libs/rs/rsScriptC_LibGL.cpp index 7fd6406..88db761 100644 --- a/libs/rs/rsScriptC_LibGL.cpp +++ b/libs/rs/rsScriptC_LibGL.cpp @@ -319,9 +319,7 @@ static void SC_uploadToBufferObject(RsAllocation va) static void SC_ClearColor(float r, float g, float b, float a) { GET_TLS(); - if (!rsc->setupCheck()) { - return; - } + rsc->setupProgramStore(); glClearColor(r, g, b, a); glClear(GL_COLOR_BUFFER_BIT); @@ -330,9 +328,7 @@ static void SC_ClearColor(float r, float g, float b, float a) static void SC_ClearDepth(float v) { GET_TLS(); - if (!rsc->setupCheck()) { - return; - } + rsc->setupProgramStore(); glClearDepthf(v); glClear(GL_DEPTH_BUFFER_BIT); diff --git a/libs/rs/rsShaderCache.cpp b/libs/rs/rsShaderCache.cpp index 28e3b1d..45f6207 100644 --- a/libs/rs/rsShaderCache.cpp +++ b/libs/rs/rsShaderCache.cpp @@ -29,20 +29,15 @@ using namespace android::renderscript; ShaderCache::ShaderCache() { - mEntryCount = 0; - mEntryAllocationCount = 16; - mEntries = (entry_t *)calloc(mEntryAllocationCount, sizeof(entry_t)); + mEntries.setCapacity(16); } ShaderCache::~ShaderCache() { - for (uint32_t ct=0; ct < mEntryCount; ct++) { - glDeleteProgram(mEntries[ct].program); + for (uint32_t ct=0; ct < mEntries.size(); ct++) { + glDeleteProgram(mEntries[ct]->program); + free(mEntries[ct]); } - - mEntryCount = 0; - mEntryAllocationCount = 0; - free(mEntries); } bool ShaderCache::lookup(Context *rsc, ProgramVertex *vtx, ProgramFragment *frag) @@ -59,44 +54,30 @@ bool ShaderCache::lookup(Context *rsc, ProgramVertex *vtx, ProgramFragment *frag return false; } //LOGV("ShaderCache lookup vtx %i, frag %i", vtx->getShaderID(), frag->getShaderID()); - - for (uint32_t ct=0; ct < mEntryCount; ct++) { - if ((mEntries[ct].vtx == vtx->getShaderID()) && - (mEntries[ct].frag == frag->getShaderID())) { - - //LOGV("SC using program %i", mEntries[ct].program); - glUseProgram(mEntries[ct].program); - mCurrent = &mEntries[ct]; + uint32_t entryCount = mEntries.size(); + for(uint32_t ct = 0; ct < entryCount; ct ++) { + if ((mEntries[ct]->vtx == vtx->getShaderID()) && + (mEntries[ct]->frag == frag->getShaderID())) { + + //LOGV("SC using program %i", mEntries[ct]->program); + glUseProgram(mEntries[ct]->program); + mCurrent = mEntries[ct]; //LOGV("ShaderCache hit, using %i", ct); rsc->checkError("ShaderCache::lookup (hit)"); return true; } } - // Not in cache, add it. - - if (mEntryAllocationCount == mEntryCount) { - // Out of space, make some. - mEntryAllocationCount *= 2; - entry_t *e = (entry_t *)calloc(mEntryAllocationCount, sizeof(entry_t)); - if (!e) { - LOGE("Out of memory for ShaderCache::lookup"); - return false; - } - memcpy(e, mEntries, sizeof(entry_t) * mEntryCount); - free(mEntries); - mEntries = e; - } - //LOGV("ShaderCache miss, using %i", mEntryCount); + //LOGV("ShaderCache miss"); //LOGE("e0 %x", glGetError()); - - entry_t *e = &mEntries[mEntryCount]; + entry_t *e = (entry_t *)malloc(sizeof(entry_t)); + mEntries.push(e); mCurrent = e; e->vtx = vtx->getShaderID(); e->frag = frag->getShaderID(); e->program = glCreateProgram(); e->vtxAttrCount = vtx->getAttribCount(); - if (mEntries[mEntryCount].program) { + if (e->program) { GLuint pgm = e->program; glAttachShader(pgm, vtx->getShaderID()); //LOGE("e1 %x", glGetError()); @@ -155,7 +136,6 @@ bool ShaderCache::lookup(Context *rsc, ProgramVertex *vtx, ProgramFragment *frag e->mIsValid = true; //LOGV("SC made program %i", e->program); glUseProgram(e->program); - mEntryCount++; rsc->checkError("ShaderCache::lookup (miss)"); return true; } @@ -171,10 +151,32 @@ int32_t ShaderCache::vtxAttribSlot(const String8 &attrName) const { void ShaderCache::cleanupVertex(uint32_t id) { + int32_t numEntries = (int32_t)mEntries.size(); + for(int32_t ct = 0; ct < numEntries; ct ++) { + if (mEntries[ct]->vtx == id) { + glDeleteProgram(mEntries[ct]->program); + + free(mEntries[ct]); + mEntries.removeAt(ct); + numEntries = (int32_t)mEntries.size(); + ct --; + } + } } void ShaderCache::cleanupFragment(uint32_t id) { + int32_t numEntries = (int32_t)mEntries.size(); + for(int32_t ct = 0; ct < numEntries; ct ++) { + if (mEntries[ct]->frag == id) { + glDeleteProgram(mEntries[ct]->program); + + free(mEntries[ct]); + mEntries.removeAt(ct); + numEntries = (int32_t)mEntries.size(); + ct --; + } + } } void ShaderCache::cleanupAll() diff --git a/libs/rs/rsShaderCache.h b/libs/rs/rsShaderCache.h index 312c251..35ff95b 100644 --- a/libs/rs/rsShaderCache.h +++ b/libs/rs/rsShaderCache.h @@ -58,11 +58,12 @@ protected: int32_t mFragUniformSlots[Program::MAX_UNIFORMS]; bool mIsValid; } entry_t; - entry_t *mEntries; + //entry_t *mEntries; + Vector<entry_t*> mEntries; entry_t *mCurrent; - uint32_t mEntryCount; - uint32_t mEntryAllocationCount; + /*uint32_t mEntryCount; + uint32_t mEntryAllocationCount;*/ }; |