Commit 83b61bc6 by jbauman@chromium.org

Avoid recreating constant vertex buffers unnecessarily.

To avoid continually recreating constant vertex buffers instead use streaming buffers to hold that data. BUG= TEST= Review URL: http://codereview.appspot.com/4437072 git-svn-id: https://angleproject.googlecode.com/svn/trunk@744 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent d8f3faad
#define MAJOR_VERSION 0 #define MAJOR_VERSION 0
#define MINOR_VERSION 0 #define MINOR_VERSION 0
#define BUILD_VERSION 0 #define BUILD_VERSION 0
#define BUILD_REVISION 743 #define BUILD_REVISION 744
#define STRINGIFY(x) #x #define STRINGIFY(x) #x
#define MACRO_STRINGIFY(x) STRINGIFY(x) #define MACRO_STRINGIFY(x) STRINGIFY(x)
......
...@@ -21,6 +21,8 @@ ...@@ -21,6 +21,8 @@
namespace namespace
{ {
enum { INITIAL_STREAM_BUFFER_SIZE = 1024*1024 }; enum { INITIAL_STREAM_BUFFER_SIZE = 1024*1024 };
// This has to be at least 4k or else it fails on ATI cards.
enum { CONSTANT_VERTEX_BUFFER_SIZE = 4096 };
} }
namespace gl namespace gl
...@@ -33,6 +35,7 @@ VertexDataManager::VertexDataManager(Context *context, IDirect3DDevice9 *device) ...@@ -33,6 +35,7 @@ VertexDataManager::VertexDataManager(Context *context, IDirect3DDevice9 *device)
{ {
mDirtyCurrentValue[i] = true; mDirtyCurrentValue[i] = true;
mCurrentValueBuffer[i] = NULL; mCurrentValueBuffer[i] = NULL;
mCurrentValueOffsets[i] = 0;
} }
const D3DCAPS9 &caps = context->getDeviceCaps(); const D3DCAPS9 &caps = context->getDeviceCaps();
...@@ -242,11 +245,28 @@ GLenum VertexDataManager::prepareVertexData(GLint start, GLsizei count, Translat ...@@ -242,11 +245,28 @@ GLenum VertexDataManager::prepareVertexData(GLint start, GLsizei count, Translat
} }
else else
{ {
if (!mCurrentValueBuffer[i])
{
mCurrentValueBuffer[i] = new StreamingVertexBuffer(mDevice, CONSTANT_VERTEX_BUFFER_SIZE);
}
StreamingVertexBuffer *buffer = mCurrentValueBuffer[i];
if (mDirtyCurrentValue[i]) if (mDirtyCurrentValue[i])
{ {
delete mCurrentValueBuffer[i]; const int requiredSpace = 4 * sizeof(float);
mCurrentValueBuffer[i] = new ConstantVertexBuffer(mDevice, attribs[i].mCurrentValue[0], attribs[i].mCurrentValue[1], attribs[i].mCurrentValue[2], attribs[i].mCurrentValue[3]); buffer->addRequiredSpace(requiredSpace);
mDirtyCurrentValue[i] = false; buffer->reserveRequiredSpace();
float *data = static_cast<float*>(buffer->map(VertexAttribute(), requiredSpace, &mCurrentValueOffsets[i]));
if (data)
{
data[0] = attribs[i].mCurrentValue[0];
data[1] = attribs[i].mCurrentValue[1];
data[2] = attribs[i].mCurrentValue[2];
data[3] = attribs[i].mCurrentValue[3];
buffer->unmap();
mDirtyCurrentValue[i] = false;
}
} }
translated[i].vertexBuffer = mCurrentValueBuffer[i]->getBuffer(); translated[i].vertexBuffer = mCurrentValueBuffer[i]->getBuffer();
...@@ -254,7 +274,7 @@ GLenum VertexDataManager::prepareVertexData(GLint start, GLsizei count, Translat ...@@ -254,7 +274,7 @@ GLenum VertexDataManager::prepareVertexData(GLint start, GLsizei count, Translat
translated[i].type = D3DDECLTYPE_FLOAT4; translated[i].type = D3DDECLTYPE_FLOAT4;
translated[i].stride = 0; translated[i].stride = 0;
translated[i].offset = 0; translated[i].offset = mCurrentValueOffsets[i];
} }
} }
} }
...@@ -564,37 +584,6 @@ unsigned int VertexBuffer::issueSerial() ...@@ -564,37 +584,6 @@ unsigned int VertexBuffer::issueSerial()
return mCurrentSerial++; return mCurrentSerial++;
} }
ConstantVertexBuffer::ConstantVertexBuffer(IDirect3DDevice9 *device, float x, float y, float z, float w) : VertexBuffer(device, 4 * sizeof(float), D3DUSAGE_WRITEONLY)
{
void *buffer = NULL;
if (mVertexBuffer)
{
HRESULT result = mVertexBuffer->Lock(0, 0, &buffer, 0);
if (FAILED(result))
{
ERR("Lock failed with error 0x%08x", result);
}
}
if (buffer)
{
float *vector = (float*)buffer;
vector[0] = x;
vector[1] = y;
vector[2] = z;
vector[3] = w;
mVertexBuffer->Unlock();
}
}
ConstantVertexBuffer::~ConstantVertexBuffer()
{
}
ArrayVertexBuffer::ArrayVertexBuffer(IDirect3DDevice9 *device, std::size_t size, DWORD usageFlags) : VertexBuffer(device, size, usageFlags) ArrayVertexBuffer::ArrayVertexBuffer(IDirect3DDevice9 *device, std::size_t size, DWORD usageFlags) : VertexBuffer(device, size, usageFlags)
{ {
mBufferSize = size; mBufferSize = size;
......
...@@ -56,13 +56,6 @@ class VertexBuffer ...@@ -56,13 +56,6 @@ class VertexBuffer
DISALLOW_COPY_AND_ASSIGN(VertexBuffer); DISALLOW_COPY_AND_ASSIGN(VertexBuffer);
}; };
class ConstantVertexBuffer : public VertexBuffer
{
public:
ConstantVertexBuffer(IDirect3DDevice9 *device, float x, float y, float z, float w);
~ConstantVertexBuffer();
};
class ArrayVertexBuffer : public VertexBuffer class ArrayVertexBuffer : public VertexBuffer
{ {
public: public:
...@@ -137,7 +130,8 @@ class VertexDataManager ...@@ -137,7 +130,8 @@ class VertexDataManager
StreamingVertexBuffer *mStreamingBuffer; StreamingVertexBuffer *mStreamingBuffer;
bool mDirtyCurrentValue[MAX_VERTEX_ATTRIBS]; bool mDirtyCurrentValue[MAX_VERTEX_ATTRIBS];
ConstantVertexBuffer *mCurrentValueBuffer[MAX_VERTEX_ATTRIBS]; StreamingVertexBuffer *mCurrentValueBuffer[MAX_VERTEX_ATTRIBS];
UINT mCurrentValueOffsets[MAX_VERTEX_ATTRIBS];
// Attribute format conversion // Attribute format conversion
struct FormatConverter struct FormatConverter
......
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