summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Alex Sakhartchouk <alexst@google.com> 2010-10-08 15:00:05 -0700
committer Alex Sakhartchouk <alexst@google.com> 2010-10-08 15:00:05 -0700
commit6f91cb6af7a8b20e3e001f90406e27f4580a1ccd (patch)
tree38b8d6feb2db2e9600205e5851ee69c62bcad585
parent026284745bb2f84e96fe132071f48a8cd4c1e715 (diff)
Removing fixed size arrays.
Change-Id: I5c65b29a197013de2517cfb6dbe7abb9e24a688b
-rw-r--r--libs/rs/rsScript.cpp38
-rw-r--r--libs/rs/rsScript.h12
-rw-r--r--libs/rs/rsScriptC.cpp10
-rw-r--r--libs/rs/rsScriptC.h5
-rw-r--r--libs/rs/rsType.cpp35
-rw-r--r--libs/rs/rsType.h3
6 files changed, 67 insertions, 36 deletions
diff --git a/libs/rs/rsScript.cpp b/libs/rs/rsScript.cpp
index 43bb09e14204..0e76daef1c27 100644
--- a/libs/rs/rsScript.cpp
+++ b/libs/rs/rsScript.cpp
@@ -24,10 +24,37 @@ Script::Script(Context *rsc) : ObjectBase(rsc)
mAllocFile = __FILE__;
mAllocLine = __LINE__;
memset(&mEnviroment, 0, sizeof(mEnviroment));
+
+ mSlots = NULL;
+ mTypes = NULL;
}
Script::~Script()
{
+ if(mSlots) {
+ delete [] mSlots;
+ mSlots = NULL;
+ }
+ if(mTypes) {
+ delete [] mTypes;
+ mTypes = NULL;
+ }
+}
+
+void Script::initSlots() {
+ if(mEnviroment.mFieldCount > 0) {
+ mSlots = new ObjectBaseRef<Allocation>[mEnviroment.mFieldCount];
+ mTypes = new ObjectBaseRef<const Type>[mEnviroment.mFieldCount];
+ }
+}
+
+void Script::setSlot(uint32_t slot, Allocation *a) {
+ if(slot >= mEnviroment.mFieldCount) {
+ LOGE("Script::setSlot unable to set allocation, invalid slot index");
+ return;
+ }
+
+ mSlots[slot].set(a);
}
void Script::setVar(uint32_t slot, const void *val, uint32_t len)
@@ -51,7 +78,7 @@ void rsi_ScriptBindAllocation(Context * rsc, RsScript vs, RsAllocation va, uint3
{
Script *s = static_cast<Script *>(vs);
Allocation *a = static_cast<Allocation *>(va);
- s->mSlots[slot].set(a);
+ s->setSlot(slot, a);
//LOGE("rsi_ScriptBindAllocation %i %p %p", slot, a, a->getPtr());
}
@@ -61,15 +88,6 @@ void rsi_ScriptSetTimeZone(Context * rsc, RsScript vs, const char * timeZone, ui
s->mEnviroment.mTimeZone = timeZone;
}
-void rsi_ScriptSetType(Context * rsc, RsType vt, uint32_t slot, bool writable, const char *name)
-{
- ScriptCState *ss = &rsc->mScriptC;
- const Type *t = static_cast<const Type *>(vt);
- ss->mConstantBufferTypes[slot].set(t);
- ss->mSlotWritable[slot] = writable;
- LOGE("rsi_ScriptSetType");
-}
-
void rsi_ScriptInvoke(Context *rsc, RsScript vs, uint32_t slot)
{
Script *s = static_cast<Script *>(vs);
diff --git a/libs/rs/rsScript.h b/libs/rs/rsScript.h
index 0a2034469e6a..c73bb5ea15bf 100644
--- a/libs/rs/rsScript.h
+++ b/libs/rs/rsScript.h
@@ -29,8 +29,6 @@ class ProgramFragment;
class ProgramRaster;
class ProgramStore;
-#define MAX_SCRIPT_BANKS 32
-
class Script : public ObjectBase
{
public:
@@ -61,10 +59,8 @@ public:
};
Enviroment_t mEnviroment;
- ObjectBaseRef<Allocation> mSlots[MAX_SCRIPT_BANKS];
- ObjectBaseRef<const Type> mTypes[MAX_SCRIPT_BANKS];
- bool mSlotWritable[MAX_SCRIPT_BANKS];
-
+ void initSlots();
+ void setSlot(uint32_t slot, Allocation *a);
void setVar(uint32_t slot, const void *val, uint32_t len);
virtual void runForEach(Context *rsc,
@@ -76,6 +72,10 @@ public:
virtual void Invoke(Context *rsc, uint32_t slot, const void *data, uint32_t len) = 0;
virtual void setupScript(Context *rsc) = 0;
virtual uint32_t run(Context *) = 0;
+protected:
+ ObjectBaseRef<Allocation> *mSlots;
+ ObjectBaseRef<const Type> *mTypes;
+
};
diff --git a/libs/rs/rsScriptC.cpp b/libs/rs/rsScriptC.cpp
index c6418be67f93..d961fed819a7 100644
--- a/libs/rs/rsScriptC.cpp
+++ b/libs/rs/rsScriptC.cpp
@@ -365,11 +365,6 @@ void ScriptCState::init(Context *rsc)
void ScriptCState::clear(Context *rsc)
{
rsAssert(rsc);
- for (uint32_t ct=0; ct < MAX_SCRIPT_BANKS; ct++) {
- mConstantBufferTypes[ct].clear();
- mSlotWritable[ct] = false;
- }
-
mScript.clear();
mScript.set(new ScriptC(rsc));
}
@@ -428,6 +423,7 @@ void ScriptCState::runCompiler(Context *rsc, ScriptC *s)
else {
s->mEnviroment.mFieldAddress = (void **) calloc(s->mEnviroment.mFieldCount, sizeof(void *));
bccGetExportVars(s->mBccScript, NULL, s->mEnviroment.mFieldCount, (BCCvoid **) s->mEnviroment.mFieldAddress);
+ s->initSlots();
}
s->mEnviroment.mFragment.set(rsc->getDefaultProgramFragment());
@@ -532,10 +528,6 @@ RsScript rsi_ScriptCCreate(Context * rsc)
ss->runCompiler(rsc, s.get());
s->incUserRef();
s->setContext(rsc);
- for (int ct=0; ct < MAX_SCRIPT_BANKS; ct++) {
- s->mTypes[ct].set(ss->mConstantBufferTypes[ct].get());
- s->mSlotWritable[ct] = ss->mSlotWritable[ct];
- }
ss->clear(rsc);
return s.get();
diff --git a/libs/rs/rsScriptC.h b/libs/rs/rsScriptC.h
index 7ec80aa65984..e5b5ba9f8933 100644
--- a/libs/rs/rsScriptC.h
+++ b/libs/rs/rsScriptC.h
@@ -81,11 +81,6 @@ public:
ObjectBaseRef<ScriptC> mScript;
- ObjectBaseRef<const Type> mConstantBufferTypes[MAX_SCRIPT_BANKS];
- //String8 mSlotNames[MAX_SCRIPT_BANKS];
- bool mSlotWritable[MAX_SCRIPT_BANKS];
- //String8 mInvokableNames[MAX_SCRIPT_BANKS];
-
void init(Context *rsc);
void clear(Context *rsc);
diff --git a/libs/rs/rsType.cpp b/libs/rs/rsType.cpp
index 8cdb48af36a6..33776c394629 100644
--- a/libs/rs/rsType.cpp
+++ b/libs/rs/rsType.cpp
@@ -31,6 +31,8 @@ Type::Type(Context *rsc) : ObjectBase(rsc)
mAllocLine = __LINE__;
mLODs = 0;
mLODCount = 0;
+ mAttribs = NULL;
+ mAttribsSize = 0;
clear();
}
@@ -44,6 +46,11 @@ Type::~Type()
}
if (mLODs) {
delete [] mLODs;
+ mLODs = NULL;
+ }
+ if(mAttribs) {
+ delete [] mAttribs;
+ mAttribs = NULL;
}
}
@@ -145,6 +152,21 @@ uint32_t Type::getLODOffset(uint32_t lod, uint32_t x, uint32_t y, uint32_t z) co
void Type::makeGLComponents()
{
+ // Count the number of gl attrs to initialize
+ mAttribsSize = 0;
+ for (uint32_t ct=0; ct < getElement()->getFieldCount(); ct++) {
+ if(getElement()->getFieldName(ct)[0] != '#') {
+ mAttribsSize ++;
+ }
+ }
+ if(mAttribs) {
+ delete [] mAttribs;
+ mAttribs = NULL;
+ }
+ if(mAttribsSize) {
+ mAttribs = new VertexArray::Attrib[mAttribsSize];
+ }
+
uint32_t userNum = 0;
for (uint32_t ct=0; ct < getElement()->getFieldCount(); ct++) {
const Component &c = getElement()->getField(ct)->getComponent();
@@ -160,11 +182,8 @@ void Type::makeGLComponents()
String8 tmp(RS_SHADER_ATTR);
tmp.append(getElement()->getFieldName(ct));
mAttribs[userNum].name.setTo(tmp.string());
- userNum ++;
- if(userNum == RS_MAX_ATTRIBS) {
- return;
- }
+ userNum ++;
}
}
@@ -172,7 +191,13 @@ void Type::makeGLComponents()
void Type::enableGLVertexBuffer(VertexArray *va) const
{
uint32_t stride = mElement->getSizeBytes();
- for (uint32_t ct=0; ct < RS_MAX_ATTRIBS; ct++) {
+ for (uint32_t ct=0; ct < mAttribsSize; ct++) {
+ // Load up to RS_MAX_ATTRIBS inputs
+ // TODO: grow vertexarray dynamically
+ if(ct >= RS_MAX_ATTRIBS) {
+ LOGE("More GL attributes than we can handle");
+ break;
+ }
if (mAttribs[ct].size) {
va->add(mAttribs[ct], stride);
}
diff --git a/libs/rs/rsType.h b/libs/rs/rsType.h
index b5548c0c15db..9099bf1f4470 100644
--- a/libs/rs/rsType.h
+++ b/libs/rs/rsType.h
@@ -119,7 +119,8 @@ protected:
LOD *mLODs;
uint32_t mLODCount;
- VertexArray::Attrib mAttribs[RS_MAX_ATTRIBS];
+ VertexArray::Attrib *mAttribs;
+ uint32_t mAttribsSize;
void makeGLComponents();
private: