Commit 53cabecc by Corentin Wallez

BufferD3D: reinit static data only when the usage is static

Previously, once a dynamic buffer had an associated static data, it would be considered as static and the static data would be always be reinitialized just after having been invalidated. BUG=510585 Change-Id: I403e91d35d11efe17f52947b2182f7b8febd7922 Reviewed-on: https://chromium-review.googlesource.com/288351Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Tested-by: 's avatarCorentin Wallez <cwallez@chromium.org>
parent cab7e1d1
...@@ -22,7 +22,8 @@ BufferD3D::BufferD3D(BufferFactoryD3D *factory) ...@@ -22,7 +22,8 @@ BufferD3D::BufferD3D(BufferFactoryD3D *factory)
mFactory(factory), mFactory(factory),
mStaticVertexBuffer(nullptr), mStaticVertexBuffer(nullptr),
mStaticIndexBuffer(nullptr), mStaticIndexBuffer(nullptr),
mUnmodifiedDataUse(0) mUnmodifiedDataUse(0),
mUsage(D3D_BUFFER_USAGE_STATIC)
{ {
updateSerial(); updateSerial();
} }
...@@ -38,6 +39,30 @@ void BufferD3D::updateSerial() ...@@ -38,6 +39,30 @@ void BufferD3D::updateSerial()
mSerial = mNextSerial++; mSerial = mNextSerial++;
} }
void BufferD3D::updateD3DBufferUsage(GLenum usage)
{
switch (usage)
{
case GL_STATIC_DRAW:
case GL_STATIC_READ:
case GL_STATIC_COPY:
mUsage = D3D_BUFFER_USAGE_STATIC;
initializeStaticData();
break;
case GL_STREAM_DRAW:
case GL_STREAM_READ:
case GL_STREAM_COPY:
case GL_DYNAMIC_READ:
case GL_DYNAMIC_COPY:
case GL_DYNAMIC_DRAW:
mUsage = D3D_BUFFER_USAGE_DYNAMIC;
break;
default:
UNREACHABLE();
}
}
void BufferD3D::initializeStaticData() void BufferD3D::initializeStaticData()
{ {
if (!mStaticVertexBuffer) if (!mStaticVertexBuffer)
...@@ -57,8 +82,12 @@ void BufferD3D::invalidateStaticData() ...@@ -57,8 +82,12 @@ void BufferD3D::invalidateStaticData()
SafeDelete(mStaticVertexBuffer); SafeDelete(mStaticVertexBuffer);
SafeDelete(mStaticIndexBuffer); SafeDelete(mStaticIndexBuffer);
// Re-init static data to track that we're in a static buffer // If the buffer was created with a static usage then we recreate the static
initializeStaticData(); // buffers so that they are populated the next time we use this buffer.
if (mUsage == D3D_BUFFER_USAGE_STATIC)
{
initializeStaticData();
}
} }
mUnmodifiedDataUse = 0; mUnmodifiedDataUse = 0;
......
...@@ -20,6 +20,12 @@ class BufferFactoryD3D; ...@@ -20,6 +20,12 @@ class BufferFactoryD3D;
class StaticIndexBufferInterface; class StaticIndexBufferInterface;
class StaticVertexBufferInterface; class StaticVertexBufferInterface;
enum D3DBufferUsage
{
D3D_BUFFER_USAGE_STATIC,
D3D_BUFFER_USAGE_DYNAMIC,
};
class BufferD3D : public BufferImpl class BufferD3D : public BufferImpl
{ {
public: public:
...@@ -44,6 +50,7 @@ class BufferD3D : public BufferImpl ...@@ -44,6 +50,7 @@ class BufferD3D : public BufferImpl
protected: protected:
void updateSerial(); void updateSerial();
void updateD3DBufferUsage(GLenum usage);
BufferFactoryD3D *mFactory; BufferFactoryD3D *mFactory;
unsigned int mSerial; unsigned int mSerial;
...@@ -52,6 +59,7 @@ class BufferD3D : public BufferImpl ...@@ -52,6 +59,7 @@ class BufferD3D : public BufferImpl
StaticVertexBufferInterface *mStaticVertexBuffer; StaticVertexBufferInterface *mStaticVertexBuffer;
StaticIndexBufferInterface *mStaticIndexBuffer; StaticIndexBufferInterface *mStaticIndexBuffer;
unsigned int mUnmodifiedDataUse; unsigned int mUnmodifiedDataUse;
D3DBufferUsage mUsage;
}; };
} }
......
...@@ -275,11 +275,7 @@ gl::Error Buffer11::setData(const void *data, size_t size, GLenum usage) ...@@ -275,11 +275,7 @@ gl::Error Buffer11::setData(const void *data, size_t size, GLenum usage)
return error; return error;
} }
if (usage == GL_STATIC_DRAW) updateD3DBufferUsage(usage);
{
initializeStaticData();
}
return error; return error;
} }
......
...@@ -40,11 +40,7 @@ gl::Error Buffer9::setData(const void* data, size_t size, GLenum usage) ...@@ -40,11 +40,7 @@ gl::Error Buffer9::setData(const void* data, size_t size, GLenum usage)
invalidateStaticData(); invalidateStaticData();
if (usage == GL_STATIC_DRAW) updateD3DBufferUsage(usage);
{
initializeStaticData();
}
return gl::Error(GL_NO_ERROR); return gl::Error(GL_NO_ERROR);
} }
......
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