summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Hines <srhines@google.com>2013-09-10 17:40:41 -0700
committerStephen Hines <srhines@google.com>2013-09-10 18:13:28 -0700
commitc78839b5bbcffae7d64a5a1c9aa60c9a4c5d3918 (patch)
tree92c7b189452259dd5f103394ee4d5701275297a2
parent17e3cdc24776d8fdbf1ce16287b9b4dcd516708f (diff)
downloadandroid_frameworks_rs-c78839b5bbcffae7d64a5a1c9aa60c9a4c5d3918.tar.gz
android_frameworks_rs-c78839b5bbcffae7d64a5a1c9aa60c9a4c5d3918.tar.bz2
android_frameworks_rs-c78839b5bbcffae7d64a5a1c9aa60c9a4c5d3918.zip
Detect use of RS objects in kernels to disable a ScriptGroup optimization.
Bug: 10394865 This change disables a ScriptGroup optimization when we can't guarantee that there is no implicit ordering between two kernels. In this case, it is possible to communicate between kernels using the same bound global RS object (like Allocation). A subsequent kernel in the ScriptGroup could accidentally pick up stale data, leading to incorrect results. Now, we disable this optimization whenever we see binds/sets of variables that are potentiall RS object types for a given Script/kernel. This is overly conservative, but sufficient for now. This change also fixes a small issue with preLaunch/postLaunch missing for the default ScriptGroup execution case. Change-Id: I0d19d200cc8dc397d68008a4df6ea423b1e4d04f
-rw-r--r--cpu_ref/rsCpuScriptGroup.cpp13
-rw-r--r--rsScript.cpp3
-rw-r--r--rsScript.h5
3 files changed, 21 insertions, 0 deletions
diff --git a/cpu_ref/rsCpuScriptGroup.cpp b/cpu_ref/rsCpuScriptGroup.cpp
index 1db6e16c..40eddf20 100644
--- a/cpu_ref/rsCpuScriptGroup.cpp
+++ b/cpu_ref/rsCpuScriptGroup.cpp
@@ -119,6 +119,11 @@ void CpuScriptGroupImpl::execute() {
for (size_t ct=0; ct < mSG->mNodes.size(); ct++) {
ScriptGroup::Node *n = mSG->mNodes[ct];
Script *s = n->mKernels[0]->mScript;
+ if (s->hasObjectSlots()) {
+ // Disable the ScriptGroup optimization if we have global RS
+ // objects that might interfere between kernels.
+ fieldDep = true;
+ }
//ALOGE("node %i, order %i, in %i out %i", (int)ct, n->mOrder, (int)n->mInputs.size(), (int)n->mOutputs.size());
@@ -136,6 +141,12 @@ void CpuScriptGroupImpl::execute() {
bool inExt = false;
bool outExt = false;
+ if (k->mScript->hasObjectSlots()) {
+ // Disable the ScriptGroup optimization if we have global RS
+ // objects that might interfere between kernels.
+ fieldDep = true;
+ }
+
for (size_t ct3=0; ct3 < n->mInputs.size(); ct3++) {
if (n->mInputs[ct3]->mDstKernel.get() == k) {
ain = n->mInputs[ct3]->mAlloc.get();
@@ -189,7 +200,9 @@ void CpuScriptGroupImpl::execute() {
si->forEachMtlsSetup(ins[ct], outs[ct], NULL, 0, NULL, &mtls);
si->forEachKernelSetup(slot, &mtls);
+ si->preLaunch(slot, ins[ct], outs[ct], mtls.fep.usr, mtls.fep.usrLen, NULL);
mCtx->launchThreads(ins[ct], outs[ct], NULL, &mtls);
+ si->postLaunch(slot, ins[ct], outs[ct], NULL, 0, NULL);
}
} else {
ScriptList sl;
diff --git a/rsScript.cpp b/rsScript.cpp
index 4e8ba1ec..7857667c 100644
--- a/rsScript.cpp
+++ b/rsScript.cpp
@@ -27,6 +27,7 @@ Script::Script(Context *rsc) : ObjectBase(rsc) {
mSlots = NULL;
mTypes = NULL;
mInitialized = false;
+ mHasObjectSlots = false;
}
Script::~Script() {
@@ -48,6 +49,7 @@ void Script::setSlot(uint32_t slot, Allocation *a) {
}
mSlots[slot].set(a);
+ mHasObjectSlots = true;
mRSC->mHal.funcs.script.setGlobalBind(mRSC, this, slot, a);
}
@@ -85,6 +87,7 @@ void Script::setVarObj(uint32_t slot, ObjectBase *val) {
ALOGE("Script::setVarObj unable to set allocation, invalid slot index");
return;
}
+ mHasObjectSlots = true;
//ALOGE("setvarobj %i %p", slot, val);
mRSC->mHal.funcs.script.setGlobalObj(mRSC, this, slot, val);
}
diff --git a/rsScript.h b/rsScript.h
index c868aaa9..ce4878a5 100644
--- a/rsScript.h
+++ b/rsScript.h
@@ -119,8 +119,13 @@ public:
virtual void Invoke(Context *rsc, uint32_t slot, const void *data, size_t len) = 0;
virtual void setupScript(Context *rsc) = 0;
virtual uint32_t run(Context *) = 0;
+
+ bool hasObjectSlots() const {
+ return mHasObjectSlots;
+ }
protected:
bool mInitialized;
+ bool mHasObjectSlots;
ObjectBaseRef<Allocation> *mSlots;
ObjectBaseRef<const Type> *mTypes;