Commit 23ba30e4 by Geoff Lang

Move the counting IB from IndexDataManager to Renderer9.

BUG=angle:520 Change-Id: Ice0a04b296af6c0a61a604f629b08603e594bb0b Reviewed-on: https://chromium-review.googlesource.com/216919Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Tested-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 157f9374
...@@ -78,15 +78,12 @@ IndexDataManager::IndexDataManager(Renderer *renderer) ...@@ -78,15 +78,12 @@ IndexDataManager::IndexDataManager(Renderer *renderer)
SafeDelete(mStreamingBufferInt); SafeDelete(mStreamingBufferInt);
ERR("Failed to allocate the streaming index buffer(s)."); ERR("Failed to allocate the streaming index buffer(s).");
} }
mCountingBuffer = NULL;
} }
IndexDataManager::~IndexDataManager() IndexDataManager::~IndexDataManager()
{ {
SafeDelete(mStreamingBufferShort); SafeDelete(mStreamingBufferShort);
SafeDelete(mStreamingBufferInt); SafeDelete(mStreamingBufferInt);
SafeDelete(mCountingBuffer);
} }
GLenum IndexDataManager::prepareIndexData(GLenum type, GLsizei count, gl::Buffer *buffer, const GLvoid *indices, TranslatedIndexData *translated) GLenum IndexDataManager::prepareIndexData(GLenum type, GLsizei count, gl::Buffer *buffer, const GLvoid *indices, TranslatedIndexData *translated)
...@@ -237,74 +234,4 @@ GLenum IndexDataManager::prepareIndexData(GLenum type, GLsizei count, gl::Buffer ...@@ -237,74 +234,4 @@ GLenum IndexDataManager::prepareIndexData(GLenum type, GLsizei count, gl::Buffer
return GL_NO_ERROR; return GL_NO_ERROR;
} }
StaticIndexBufferInterface *IndexDataManager::getCountingIndices(GLsizei count)
{
if (count <= 65536) // 16-bit indices
{
const unsigned int spaceNeeded = count * sizeof(unsigned short);
if (!mCountingBuffer || mCountingBuffer->getBufferSize() < spaceNeeded)
{
delete mCountingBuffer;
mCountingBuffer = new StaticIndexBufferInterface(mRenderer);
mCountingBuffer->reserveBufferSpace(spaceNeeded, GL_UNSIGNED_SHORT);
void* mappedMemory = NULL;
if (!mCountingBuffer->mapBuffer(spaceNeeded, &mappedMemory, NULL))
{
ERR("Failed to map counting buffer.");
return NULL;
}
unsigned short *data = reinterpret_cast<unsigned short*>(mappedMemory);
for(int i = 0; i < count; i++)
{
data[i] = i;
}
if (!mCountingBuffer->unmapBuffer())
{
ERR("Failed to unmap counting buffer.");
return NULL;
}
}
}
else if (mStreamingBufferInt) // 32-bit indices supported
{
const unsigned int spaceNeeded = count * sizeof(unsigned int);
if (!mCountingBuffer || mCountingBuffer->getBufferSize() < spaceNeeded)
{
delete mCountingBuffer;
mCountingBuffer = new StaticIndexBufferInterface(mRenderer);
mCountingBuffer->reserveBufferSpace(spaceNeeded, GL_UNSIGNED_INT);
void* mappedMemory = NULL;
if (!mCountingBuffer->mapBuffer(spaceNeeded, &mappedMemory, NULL))
{
ERR("Failed to map counting buffer.");
return NULL;
}
unsigned int *data = reinterpret_cast<unsigned int*>(mappedMemory);
for(int i = 0; i < count; i++)
{
data[i] = i;
}
if (!mCountingBuffer->unmapBuffer())
{
ERR("Failed to unmap counting buffer.");
return NULL;
}
}
}
else
{
return NULL;
}
return mCountingBuffer;
}
} }
...@@ -52,7 +52,6 @@ class IndexDataManager ...@@ -52,7 +52,6 @@ class IndexDataManager
virtual ~IndexDataManager(); virtual ~IndexDataManager();
GLenum prepareIndexData(GLenum type, GLsizei count, gl::Buffer *arrayElementBuffer, const GLvoid *indices, TranslatedIndexData *translated); GLenum prepareIndexData(GLenum type, GLsizei count, gl::Buffer *arrayElementBuffer, const GLvoid *indices, TranslatedIndexData *translated);
StaticIndexBufferInterface *getCountingIndices(GLsizei count);
private: private:
DISALLOW_COPY_AND_ASSIGN(IndexDataManager); DISALLOW_COPY_AND_ASSIGN(IndexDataManager);
...@@ -61,7 +60,6 @@ class IndexDataManager ...@@ -61,7 +60,6 @@ class IndexDataManager
StreamingIndexBufferInterface *mStreamingBufferShort; StreamingIndexBufferInterface *mStreamingBufferShort;
StreamingIndexBufferInterface *mStreamingBufferInt; StreamingIndexBufferInterface *mStreamingBufferInt;
StaticIndexBufferInterface *mCountingBuffer;
}; };
} }
......
...@@ -126,6 +126,7 @@ Renderer9::Renderer9(egl::Display *display, EGLNativeDisplayType hDc, EGLint req ...@@ -126,6 +126,7 @@ Renderer9::Renderer9(egl::Display *display, EGLNativeDisplayType hDc, EGLint req
mVertexDataManager = NULL; mVertexDataManager = NULL;
mIndexDataManager = NULL; mIndexDataManager = NULL;
mLineLoopIB = NULL; mLineLoopIB = NULL;
mCountingIB = NULL;
mMaxNullColorbufferLRU = 0; mMaxNullColorbufferLRU = 0;
for (int i = 0; i < NUM_NULL_COLORBUFFER_CACHE_ENTRIES; i++) for (int i = 0; i < NUM_NULL_COLORBUFFER_CACHE_ENTRIES; i++)
...@@ -1306,26 +1307,23 @@ void Renderer9::drawArrays(GLenum mode, GLsizei count, GLsizei instances, bool t ...@@ -1306,26 +1307,23 @@ void Renderer9::drawArrays(GLenum mode, GLsizei count, GLsizei instances, bool t
} }
else if (instances > 0) else if (instances > 0)
{ {
StaticIndexBufferInterface *countingIB = mIndexDataManager->getCountingIndices(count); StaticIndexBufferInterface *countingIB = getCountingIB(count);
if (countingIB) if (!countingIB)
{ {
if (mAppliedIBSerial != countingIB->getSerial()) return;
{ }
IndexBuffer9 *indexBuffer = IndexBuffer9::makeIndexBuffer9(countingIB->getIndexBuffer());
mDevice->SetIndices(indexBuffer->getBuffer()); if (mAppliedIBSerial != countingIB->getSerial())
mAppliedIBSerial = countingIB->getSerial(); {
} IndexBuffer9 *indexBuffer = IndexBuffer9::makeIndexBuffer9(countingIB->getIndexBuffer());
for (int i = 0; i < mRepeatDraw; i++) mDevice->SetIndices(indexBuffer->getBuffer());
{ mAppliedIBSerial = countingIB->getSerial();
mDevice->DrawIndexedPrimitive(mPrimitiveType, 0, 0, count, 0, mPrimitiveCount);
}
} }
else
for (int i = 0; i < mRepeatDraw; i++)
{ {
ERR("Could not create a counting index buffer for glDrawArraysInstanced."); mDevice->DrawIndexedPrimitive(mPrimitiveType, 0, 0, count, 0, mPrimitiveCount);
return gl::error(GL_OUT_OF_MEMORY);
} }
} }
else // Regular case else // Regular case
...@@ -1577,6 +1575,80 @@ void Renderer9::drawIndexedPoints(GLsizei count, GLenum type, const GLvoid *indi ...@@ -1577,6 +1575,80 @@ void Renderer9::drawIndexedPoints(GLsizei count, GLenum type, const GLvoid *indi
} }
} }
StaticIndexBufferInterface *Renderer9::getCountingIB(size_t count)
{
// Update the counting index buffer if it is not large enough or has not been created yet.
if (count <= 65536) // 16-bit indices
{
const unsigned int spaceNeeded = count * sizeof(unsigned short);
if (!mCountingIB || mCountingIB->getBufferSize() < spaceNeeded)
{
SafeDelete(mCountingIB);
mCountingIB = new StaticIndexBufferInterface(this);
mCountingIB->reserveBufferSpace(spaceNeeded, GL_UNSIGNED_SHORT);
void *mappedMemory = NULL;
if (!mCountingIB->mapBuffer(spaceNeeded, &mappedMemory, NULL))
{
ERR("Failed to map counting buffer.");
return NULL;
}
unsigned short *data = reinterpret_cast<unsigned short*>(mappedMemory);
for (int i = 0; i < count; i++)
{
data[i] = i;
}
if (!mCountingIB->unmapBuffer())
{
ERR("Failed to unmap counting buffer.");
return NULL;
}
}
return mCountingIB;
}
else if (getRendererExtensions().elementIndexUint)
{
const unsigned int spaceNeeded = count * sizeof(unsigned int);
if (!mCountingIB || mCountingIB->getBufferSize() < spaceNeeded)
{
SafeDelete(mCountingIB);
mCountingIB = new StaticIndexBufferInterface(this);
mCountingIB->reserveBufferSpace(spaceNeeded, GL_UNSIGNED_INT);
void *mappedMemory = NULL;
if (!mCountingIB->mapBuffer(spaceNeeded, &mappedMemory, NULL))
{
ERR("Failed to map counting buffer.");
return NULL;
}
unsigned int *data = reinterpret_cast<unsigned int*>(mappedMemory);
for (int i = 0; i < count; i++)
{
data[i] = i;
}
if (!mCountingIB->unmapBuffer())
{
ERR("Failed to unmap counting buffer.");
return NULL;
}
}
return mCountingIB;
}
else
{
ERR("Could not create a counting index buffer for glDrawArraysInstanced.");
return gl::error<StaticIndexBufferInterface*>(GL_OUT_OF_MEMORY, NULL);
}
}
void Renderer9::applyShaders(gl::ProgramBinary *programBinary, const gl::VertexFormat inputLayout[], const gl::Framebuffer *framebuffer, void Renderer9::applyShaders(gl::ProgramBinary *programBinary, const gl::VertexFormat inputLayout[], const gl::Framebuffer *framebuffer,
bool rasterizerDiscard, bool transformFeedbackActive) bool rasterizerDiscard, bool transformFeedbackActive)
{ {
...@@ -1982,6 +2054,7 @@ void Renderer9::releaseDeviceResources() ...@@ -1982,6 +2054,7 @@ void Renderer9::releaseDeviceResources()
SafeDelete(mVertexDataManager); SafeDelete(mVertexDataManager);
SafeDelete(mIndexDataManager); SafeDelete(mIndexDataManager);
SafeDelete(mLineLoopIB); SafeDelete(mLineLoopIB);
SafeDelete(mCountingIB);
for (int i = 0; i < NUM_NULL_COLORBUFFER_CACHE_ENTRIES; i++) for (int i = 0; i < NUM_NULL_COLORBUFFER_CACHE_ENTRIES; i++)
{ {
......
...@@ -27,6 +27,7 @@ namespace rx ...@@ -27,6 +27,7 @@ namespace rx
class VertexDataManager; class VertexDataManager;
class IndexDataManager; class IndexDataManager;
class StreamingIndexBufferInterface; class StreamingIndexBufferInterface;
class StaticIndexBufferInterface;
struct TranslatedAttribute; struct TranslatedAttribute;
class Blit9; class Blit9;
...@@ -211,6 +212,8 @@ class Renderer9 : public Renderer ...@@ -211,6 +212,8 @@ class Renderer9 : public Renderer
void drawLineLoop(GLsizei count, GLenum type, const GLvoid *indices, int minIndex, gl::Buffer *elementArrayBuffer); void drawLineLoop(GLsizei count, GLenum type, const GLvoid *indices, int minIndex, gl::Buffer *elementArrayBuffer);
void drawIndexedPoints(GLsizei count, GLenum type, const GLvoid *indices, int minIndex, gl::Buffer *elementArrayBuffer); void drawIndexedPoints(GLsizei count, GLenum type, const GLvoid *indices, int minIndex, gl::Buffer *elementArrayBuffer);
StaticIndexBufferInterface *getCountingIB(size_t count);
bool copyToRenderTarget(IDirect3DSurface9 *dest, IDirect3DSurface9 *source, bool fromManaged); bool copyToRenderTarget(IDirect3DSurface9 *dest, IDirect3DSurface9 *source, bool fromManaged);
gl::FramebufferAttachment *getNullColorbuffer(gl::FramebufferAttachment *depthbuffer); gl::FramebufferAttachment *getNullColorbuffer(gl::FramebufferAttachment *depthbuffer);
...@@ -321,6 +324,7 @@ class Renderer9 : public Renderer ...@@ -321,6 +324,7 @@ class Renderer9 : public Renderer
IndexDataManager *mIndexDataManager; IndexDataManager *mIndexDataManager;
StreamingIndexBufferInterface *mLineLoopIB; StreamingIndexBufferInterface *mLineLoopIB;
StaticIndexBufferInterface *mCountingIB;
enum { NUM_NULL_COLORBUFFER_CACHE_ENTRIES = 12 }; enum { NUM_NULL_COLORBUFFER_CACHE_ENTRIES = 12 };
struct NullColorbufferCacheEntry struct NullColorbufferCacheEntry
......
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