Commit 39b43463 by Jamie Madill

Use Range type for index ranges.

This compacts a lot of parameter passing. Refactoring patch only. BUG=angle:571 Change-Id: Ic918478d0c6b81093bfea6154ce0f6bf1d2b5be2 Reviewed-on: https://chromium-review.googlesource.com/210645Tested-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent f41522b6
...@@ -503,15 +503,21 @@ inline unsigned int averageFloat10(unsigned int a, unsigned int b) ...@@ -503,15 +503,21 @@ inline unsigned int averageFloat10(unsigned int a, unsigned int b)
namespace rx namespace rx
{ {
template <typename T>
struct Range struct Range
{ {
Range() {} Range() {}
Range(int lo, int hi) : start(lo), end(hi) { ASSERT(lo <= hi); } Range(T lo, T hi) : start(lo), end(hi) { ASSERT(lo <= hi); }
T start;
T end;
int start; T length() const { return end - start; }
int end;
}; };
typedef Range<int> RangeI;
typedef Range<unsigned int> RangeUI;
template <typename T> template <typename T>
T roundUp(const T value, const T alignment) T roundUp(const T value, const T alignment)
{ {
......
...@@ -1832,8 +1832,10 @@ void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid ...@@ -1832,8 +1832,10 @@ void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid
return gl::error(err); return gl::error(err);
} }
GLsizei vertexCount = indexInfo.maxIndex - indexInfo.minIndex + 1; GLsizei vertexCount = indexInfo.indexRange.length() + 1;
err = mRenderer->applyVertexBuffer(programBinary, vao->getVertexAttributes(), mState.getVertexAttribCurrentValues(), indexInfo.minIndex, vertexCount, instances); err = mRenderer->applyVertexBuffer(programBinary, vao->getVertexAttributes(),
mState.getVertexAttribCurrentValues(),
indexInfo.indexRange.start, vertexCount, instances);
if (err != GL_NO_ERROR) if (err != GL_NO_ERROR)
{ {
return gl::error(err); return gl::error(err);
......
...@@ -16,10 +16,10 @@ ...@@ -16,10 +16,10 @@
namespace rx namespace rx
{ {
void IndexRangeCache::addRange(GLenum type, unsigned int offset, GLsizei count, unsigned int minIdx, unsigned int maxIdx, void IndexRangeCache::addRange(GLenum type, unsigned int offset, GLsizei count, const RangeUI &range,
unsigned int streamOffset) unsigned int streamOffset)
{ {
mIndexRangeCache[IndexRange(type, offset, count)] = IndexBounds(minIdx, maxIdx, streamOffset); mIndexRangeCache[IndexRange(type, offset, count)] = IndexBounds(range, streamOffset);
} }
void IndexRangeCache::invalidateRange(unsigned int offset, unsigned int size) void IndexRangeCache::invalidateRange(unsigned int offset, unsigned int size)
...@@ -44,21 +44,19 @@ void IndexRangeCache::invalidateRange(unsigned int offset, unsigned int size) ...@@ -44,21 +44,19 @@ void IndexRangeCache::invalidateRange(unsigned int offset, unsigned int size)
} }
} }
bool IndexRangeCache::findRange(GLenum type, unsigned int offset, GLsizei count, unsigned int *outMinIndex, bool IndexRangeCache::findRange(GLenum type, unsigned int offset, GLsizei count,
unsigned int *outMaxIndex, unsigned int *outStreamOffset) const RangeUI *outRange, unsigned int *outStreamOffset) const
{ {
IndexRangeMap::const_iterator i = mIndexRangeCache.find(IndexRange(type, offset, count)); IndexRangeMap::const_iterator i = mIndexRangeCache.find(IndexRange(type, offset, count));
if (i != mIndexRangeCache.end()) if (i != mIndexRangeCache.end())
{ {
if (outMinIndex) *outMinIndex = i->second.minIndex; if (outRange) *outRange = i->second.range;
if (outMaxIndex) *outMaxIndex = i->second.maxIndex;
if (outStreamOffset) *outStreamOffset = i->second.streamOffset; if (outStreamOffset) *outStreamOffset = i->second.streamOffset;
return true; return true;
} }
else else
{ {
if (outMinIndex) *outMinIndex = 0; if (outRange) *outRange = RangeUI(0, 0);
if (outMaxIndex) *outMaxIndex = 0;
if (outStreamOffset) *outStreamOffset = 0; if (outStreamOffset) *outStreamOffset = 0;
return false; return false;
} }
...@@ -85,12 +83,13 @@ bool IndexRangeCache::IndexRange::operator<(const IndexRange& rhs) const ...@@ -85,12 +83,13 @@ bool IndexRangeCache::IndexRange::operator<(const IndexRange& rhs) const
} }
IndexRangeCache::IndexBounds::IndexBounds() IndexRangeCache::IndexBounds::IndexBounds()
: minIndex(0), maxIndex(0), streamOffset(0) : range(0, 0),
streamOffset(0)
{ {
} }
IndexRangeCache::IndexBounds::IndexBounds(unsigned int minIdx, unsigned int maxIdx, unsigned int offset) IndexRangeCache::IndexBounds::IndexBounds(const RangeUI &rangeIn, unsigned int offset)
: minIndex(minIdx), maxIndex(maxIdx), streamOffset(offset) : range(rangeIn), streamOffset(offset)
{ {
} }
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#define LIBGLESV2_RENDERER_INDEXRANGECACHE_H_ #define LIBGLESV2_RENDERER_INDEXRANGECACHE_H_
#include "common/angleutils.h" #include "common/angleutils.h"
#include "common/mathutil.h"
#include <map> #include <map>
namespace rx namespace rx
...@@ -19,10 +20,10 @@ namespace rx ...@@ -19,10 +20,10 @@ namespace rx
class IndexRangeCache class IndexRangeCache
{ {
public: public:
void addRange(GLenum type, unsigned int offset, GLsizei count, unsigned int minIdx, unsigned int maxIdx, void addRange(GLenum type, unsigned int offset, GLsizei count, const RangeUI &range,
unsigned int streamOffset); unsigned int streamOffset);
bool findRange(GLenum type, unsigned int offset, GLsizei count, unsigned int *outMinIndex, bool findRange(GLenum type, unsigned int offset, GLsizei count, RangeUI *rangeOut,
unsigned int *outMaxIndex, unsigned int *outStreamOffset) const; unsigned int *outStreamOffset) const;
void invalidateRange(unsigned int offset, unsigned int size); void invalidateRange(unsigned int offset, unsigned int size);
void clear(); void clear();
...@@ -42,12 +43,11 @@ class IndexRangeCache ...@@ -42,12 +43,11 @@ class IndexRangeCache
struct IndexBounds struct IndexBounds
{ {
unsigned int minIndex; RangeUI range;
unsigned int maxIndex;
unsigned int streamOffset; unsigned int streamOffset;
IndexBounds(); IndexBounds();
IndexBounds(unsigned int minIdx, unsigned int maxIdx, unsigned int offset); IndexBounds(const RangeUI &range, unsigned int offset);
}; };
typedef std::map<IndexRange, IndexBounds> IndexRangeMap; typedef std::map<IndexRange, IndexBounds> IndexRangeMap;
......
...@@ -95,33 +95,34 @@ static void convertIndices(GLenum sourceType, GLenum destinationType, const void ...@@ -95,33 +95,34 @@ static void convertIndices(GLenum sourceType, GLenum destinationType, const void
} }
template <class IndexType> template <class IndexType>
static void computeRange(const IndexType *indices, GLsizei count, GLuint *minIndex, GLuint *maxIndex) static RangeUI computeRange(const IndexType *indices, GLsizei count)
{ {
*minIndex = indices[0]; unsigned int minIndex = indices[0];
*maxIndex = indices[0]; unsigned int maxIndex = indices[0];
for (GLsizei i = 0; i < count; i++) for (GLsizei i = 1; i < count; i++)
{ {
if (*minIndex > indices[i]) *minIndex = indices[i]; if (minIndex > indices[i]) minIndex = indices[i];
if (*maxIndex < indices[i]) *maxIndex = indices[i]; if (maxIndex < indices[i]) maxIndex = indices[i];
} }
return RangeUI(minIndex, maxIndex);
} }
static void computeRange(GLenum type, const GLvoid *indices, GLsizei count, GLuint *minIndex, GLuint *maxIndex) static RangeUI computeRange(GLenum type, const GLvoid *indices, GLsizei count)
{ {
if (type == GL_UNSIGNED_BYTE) switch (type)
{
computeRange(static_cast<const GLubyte*>(indices), count, minIndex, maxIndex);
}
else if (type == GL_UNSIGNED_INT)
{ {
computeRange(static_cast<const GLuint*>(indices), count, minIndex, maxIndex); case GL_UNSIGNED_BYTE:
return computeRange(static_cast<const GLubyte*>(indices), count);
case GL_UNSIGNED_INT:
return computeRange(static_cast<const GLuint*>(indices), count);
case GL_UNSIGNED_SHORT:
return computeRange(static_cast<const GLushort*>(indices), count);
default:
UNREACHABLE();
return RangeUI();
} }
else if (type == GL_UNSIGNED_SHORT)
{
computeRange(static_cast<const GLushort*>(indices), count, minIndex, maxIndex);
}
else UNREACHABLE();
} }
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)
...@@ -183,35 +184,31 @@ GLenum IndexDataManager::prepareIndexData(GLenum type, GLsizei count, gl::Buffer ...@@ -183,35 +184,31 @@ GLenum IndexDataManager::prepareIndexData(GLenum type, GLsizei count, gl::Buffer
{ {
streamOffset = offset; streamOffset = offset;
if (!storage->getIndexRangeCache()->findRange(type, offset, count, &translated->minIndex, if (!storage->getIndexRangeCache()->findRange(type, offset, count, &translated->indexRange, NULL))
&translated->maxIndex, NULL))
{ {
computeRange(type, indices, count, &translated->minIndex, &translated->maxIndex); translated->indexRange = computeRange(type, indices, count);
storage->getIndexRangeCache()->addRange(type, offset, count, translated->minIndex, storage->getIndexRangeCache()->addRange(type, offset, count, translated->indexRange, offset);
translated->maxIndex, offset);
} }
} }
else if (staticBuffer && staticBuffer->getBufferSize() != 0 && staticBuffer->getIndexType() == type && alignedOffset) else if (staticBuffer && staticBuffer->getBufferSize() != 0 && staticBuffer->getIndexType() == type && alignedOffset)
{ {
indexBuffer = staticBuffer; indexBuffer = staticBuffer;
if (!staticBuffer->getIndexRangeCache()->findRange(type, offset, count, &translated->minIndex, if (!staticBuffer->getIndexRangeCache()->findRange(type, offset, count, &translated->indexRange, &streamOffset))
&translated->maxIndex, &streamOffset))
{ {
streamOffset = (offset / typeInfo.bytes) * gl::GetTypeInfo(destinationIndexType).bytes; streamOffset = (offset / typeInfo.bytes) * gl::GetTypeInfo(destinationIndexType).bytes;
computeRange(type, indices, count, &translated->minIndex, &translated->maxIndex); translated->indexRange = computeRange(type, indices, count);
staticBuffer->getIndexRangeCache()->addRange(type, offset, count, translated->minIndex, staticBuffer->getIndexRangeCache()->addRange(type, offset, count, translated->indexRange, streamOffset);
translated->maxIndex, streamOffset);
} }
} }
else else
{ {
computeRange(type, indices, count, &translated->minIndex, &translated->maxIndex); translated->indexRange = computeRange(type, indices, count);
} }
// Avoid D3D11's primitive restart index value // Avoid D3D11's primitive restart index value
// see http://msdn.microsoft.com/en-us/library/windows/desktop/bb205124(v=vs.85).aspx // see http://msdn.microsoft.com/en-us/library/windows/desktop/bb205124(v=vs.85).aspx
if (translated->maxIndex == 0xFFFF && type == GL_UNSIGNED_SHORT && mRenderer->getMajorShaderModel() > 3) if (translated->indexRange.end == 0xFFFF && type == GL_UNSIGNED_SHORT && mRenderer->getMajorShaderModel() > 3)
{ {
destinationIndexType = GL_UNSIGNED_INT; destinationIndexType = GL_UNSIGNED_INT;
directStorage = false; directStorage = false;
...@@ -277,8 +274,7 @@ GLenum IndexDataManager::prepareIndexData(GLenum type, GLsizei count, gl::Buffer ...@@ -277,8 +274,7 @@ GLenum IndexDataManager::prepareIndexData(GLenum type, GLsizei count, gl::Buffer
if (staticBuffer) if (staticBuffer)
{ {
streamOffset = (offset / typeInfo.bytes) * destTypeInfo.bytes; streamOffset = (offset / typeInfo.bytes) * destTypeInfo.bytes;
staticBuffer->getIndexRangeCache()->addRange(type, offset, count, translated->minIndex, staticBuffer->getIndexRangeCache()->addRange(type, offset, count, translated->indexRange, streamOffset);
translated->maxIndex, streamOffset);
} }
} }
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#define LIBGLESV2_INDEXDATAMANAGER_H_ #define LIBGLESV2_INDEXDATAMANAGER_H_
#include "common/angleutils.h" #include "common/angleutils.h"
#include "common/mathutil.h"
namespace namespace
{ {
...@@ -32,8 +33,7 @@ class Renderer; ...@@ -32,8 +33,7 @@ class Renderer;
struct TranslatedIndexData struct TranslatedIndexData
{ {
unsigned int minIndex; RangeUI indexRange;
unsigned int maxIndex;
unsigned int startIndex; unsigned int startIndex;
unsigned int startOffset; // In bytes unsigned int startOffset; // In bytes
......
...@@ -1067,21 +1067,23 @@ void Renderer11::drawArrays(GLenum mode, GLsizei count, GLsizei instances, bool ...@@ -1067,21 +1067,23 @@ void Renderer11::drawArrays(GLenum mode, GLsizei count, GLsizei instances, bool
void Renderer11::drawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, void Renderer11::drawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices,
gl::Buffer *elementArrayBuffer, const TranslatedIndexData &indexInfo, GLsizei instances) gl::Buffer *elementArrayBuffer, const TranslatedIndexData &indexInfo, GLsizei instances)
{ {
int minIndex = static_cast<int>(indexInfo.indexRange.start);
if (mode == GL_LINE_LOOP) if (mode == GL_LINE_LOOP)
{ {
drawLineLoop(count, type, indices, indexInfo.minIndex, elementArrayBuffer); drawLineLoop(count, type, indices, minIndex, elementArrayBuffer);
} }
else if (mode == GL_TRIANGLE_FAN) else if (mode == GL_TRIANGLE_FAN)
{ {
drawTriangleFan(count, type, indices, indexInfo.minIndex, elementArrayBuffer, instances); drawTriangleFan(count, type, indices, minIndex, elementArrayBuffer, instances);
} }
else if (instances > 0) else if (instances > 0)
{ {
mDeviceContext->DrawIndexedInstanced(count, instances, 0, -static_cast<int>(indexInfo.minIndex), 0); mDeviceContext->DrawIndexedInstanced(count, instances, 0, -minIndex, 0);
} }
else else
{ {
mDeviceContext->DrawIndexed(count, 0, -static_cast<int>(indexInfo.minIndex)); mDeviceContext->DrawIndexed(count, 0, -minIndex);
} }
} }
......
...@@ -1329,20 +1329,22 @@ void Renderer9::drawElements(GLenum mode, GLsizei count, GLenum type, const GLvo ...@@ -1329,20 +1329,22 @@ void Renderer9::drawElements(GLenum mode, GLsizei count, GLenum type, const GLvo
{ {
startScene(); startScene();
int minIndex = static_cast<int>(indexInfo.indexRange.start);
if (mode == GL_POINTS) if (mode == GL_POINTS)
{ {
drawIndexedPoints(count, type, indices, indexInfo.minIndex, elementArrayBuffer); drawIndexedPoints(count, type, indices, minIndex, elementArrayBuffer);
} }
else if (mode == GL_LINE_LOOP) else if (mode == GL_LINE_LOOP)
{ {
drawLineLoop(count, type, indices, indexInfo.minIndex, elementArrayBuffer); drawLineLoop(count, type, indices, minIndex, elementArrayBuffer);
} }
else else
{ {
for (int i = 0; i < mRepeatDraw; i++) for (int i = 0; i < mRepeatDraw; i++)
{ {
GLsizei vertexCount = indexInfo.maxIndex - indexInfo.minIndex + 1; GLsizei vertexCount = static_cast<int>(indexInfo.indexRange.length()) + 1;
mDevice->DrawIndexedPrimitive(mPrimitiveType, -(INT)indexInfo.minIndex, indexInfo.minIndex, vertexCount, indexInfo.startIndex, mPrimitiveCount); mDevice->DrawIndexedPrimitive(mPrimitiveType, -minIndex, minIndex, vertexCount, indexInfo.startIndex, mPrimitiveCount);
} }
} }
} }
......
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