Commit 9eb8799c by Nicolas Capens

Lock the external buffer when dirty.

Optimize blitting by avoiding locking the internal buffer when the external one is dirty. Bug 21424351 Change-Id: Ib798418d0fa93ae5049102ca767dadc2806cd224 Reviewed-on: https://swiftshader-review.googlesource.com/3439Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <capn@google.com> Tested-by: 's avatarNicolas Capens <capn@google.com>
parent 3779ea9c
......@@ -398,8 +398,11 @@ namespace sw
BlitState state;
state.sourceFormat = source->getInternalFormat();
state.destFormat = dest->getInternalFormat();
bool useSourceInternal = !source->isExternalDirty();
bool useDestInternal = !dest->isExternalDirty();
state.sourceFormat = source->getFormat(useSourceInternal);
state.destFormat = dest->getFormat(useDestInternal);
state.filter = filter;
criticalSection.lock();
......@@ -424,10 +427,10 @@ namespace sw
BlitData data;
data.source = source->lockInternal(0, 0, sourceRect.slice, sw::LOCK_READONLY, sw::PUBLIC);
data.dest = dest->lockInternal(0, 0, destRect.slice, sw::LOCK_WRITEONLY, sw::PUBLIC);
data.sPitchB = source->getInternalPitchB();
data.dPitchB = dest->getInternalPitchB();
data.source = source->lock(0, 0, sourceRect.slice, sw::LOCK_READONLY, sw::PUBLIC, useSourceInternal);
data.dest = dest->lock(0, 0, destRect.slice, sw::LOCK_WRITEONLY, sw::PUBLIC, useDestInternal);
data.sPitchB = source->getPitchB(useSourceInternal);
data.dPitchB = dest->getPitchB(useDestInternal);
data.w = 1.0f / (dRect.x1 - dRect.x0) * (sRect.x1 - sRect.x0);
data.h = 1.0f / (dRect.y1 - dRect.y0) * (sRect.y1 - sRect.y0);
......@@ -444,8 +447,8 @@ namespace sw
blitFunction(&data);
source->unlockInternal();
dest->unlockInternal();
source->unlock(useSourceInternal);
dest->unlock(useDestInternal);
return true;
}
......
......@@ -165,9 +165,16 @@ namespace sw
virtual ~Surface();
inline void *lock(int x, int y, int z, Lock lock, Accessor client, bool internal = false);
inline void unlock(bool internal = false);
inline int getWidth() const;
inline int getHeight() const;
inline int getDepth() const;
inline Format getFormat(bool internal = false) const;
inline int getPitchB(bool internal = false) const;
inline int getPitchP(bool internal = false) const;
inline int getSliceB(bool internal = false) const;
inline int getSliceP(bool internal = false) const;
void *lockExternal(int x, int y, int z, Lock lock, Accessor client);
void unlockExternal();
......@@ -220,6 +227,7 @@ namespace sw
bool hasDirtyMipmaps() const;
void cleanMipmaps();
inline bool isExternalDirty() const;
Resource *getResource();
static int bytes(Format format);
......@@ -375,6 +383,16 @@ namespace sw
namespace sw
{
void *Surface::lock(int x, int y, int z, Lock lock, Accessor client, bool internal)
{
return internal ? lockInternal(x, y, z, lock, client) : lockExternal(x, y, z, lock, client);
}
void Surface::unlock(bool internal)
{
return internal ? unlockInternal() : unlockExternal();
}
int Surface::getWidth() const
{
return external.width;
......@@ -390,6 +408,31 @@ namespace sw
return external.depth;
}
Format Surface::getFormat(bool internal) const
{
return internal ? getInternalFormat() : getExternalFormat();
}
int Surface::getPitchB(bool internal) const
{
return internal ? getInternalPitchB() : getExternalPitchB();
}
int Surface::getPitchP(bool internal) const
{
return internal ? getInternalPitchP() : getExternalPitchB();
}
int Surface::getSliceB(bool internal) const
{
return internal ? getInternalSliceB() : getExternalSliceB();
}
int Surface::getSliceP(bool internal) const
{
return internal ? getInternalSliceP() : getExternalSliceB();
}
Format Surface::getExternalFormat() const
{
return external.format;
......@@ -464,6 +507,11 @@ namespace sw
{
return internal.depth > 4 ? internal.depth / 4 : 1;
}
bool Surface::isExternalDirty() const
{
return external.buffer && external.buffer != internal.buffer && external.dirty;
}
}
#endif // sw_Surface_hpp
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment