1 #include "precompiled.h" 2 // 3 // Copyright (c) 2013 The ANGLE Project Authors. All rights reserved. 4 // Use of this source code is governed by a BSD-style license that can be 5 // found in the LICENSE file. 6 // 7 8 // IndexRangeCache.cpp: Defines the rx::IndexRangeCache class which stores information about 9 // ranges of indices. 10 11 #include "libGLESv2/renderer/IndexRangeCache.h" 12 #include "libGLESv2/formatutils.h" 13 #include "common/debug.h" 14 #include <tuple> 15 16 namespace rx 17 { 18 19 void IndexRangeCache::addRange(GLenum type, unsigned int offset, GLsizei count, unsigned int minIdx, unsigned int maxIdx, 20 unsigned int streamOffset) 21 { 22 mIndexRangeCache[IndexRange(type, offset, count)] = IndexBounds(minIdx, maxIdx, streamOffset); 23 } 24 25 void IndexRangeCache::invalidateRange(unsigned int offset, unsigned int size) 26 { 27 unsigned int invalidateStart = offset; 28 unsigned int invalidateEnd = offset + size; 29 30 IndexRangeMap::iterator i = mIndexRangeCache.begin(); 31 while (i != mIndexRangeCache.end()) 32 { 33 unsigned int rangeStart = i->second.streamOffset; 34 unsigned int rangeEnd = i->second.streamOffset + (gl::GetTypeBytes(i->first.type) * i->first.count); 35 36 if (invalidateEnd < rangeStart || invalidateStart > rangeEnd) 37 { 38 ++i; 39 } 40 else 41 { 42 i = mIndexRangeCache.erase(i); 43 } 44 } 45 } 46 47 bool IndexRangeCache::findRange(GLenum type, unsigned int offset, GLsizei count, unsigned int *outMinIndex, 48 unsigned int *outMaxIndex, unsigned int *outStreamOffset) const 49 { 50 IndexRangeMap::const_iterator i = mIndexRangeCache.find(IndexRange(type, offset, count)); 51 if (i != mIndexRangeCache.end()) 52 { 53 if (outMinIndex) *outMinIndex = i->second.minIndex; 54 if (outMaxIndex) *outMaxIndex = i->second.maxIndex; 55 if (outStreamOffset) *outStreamOffset = i->second.streamOffset; 56 return true; 57 } 58 else 59 { 60 if (outMinIndex) *outMinIndex = 0; 61 if (outMaxIndex) *outMaxIndex = 0; 62 if (outStreamOffset) *outStreamOffset = 0; 63 return false; 64 } 65 } 66 67 void IndexRangeCache::clear() 68 { 69 mIndexRangeCache.clear(); 70 } 71 72 IndexRangeCache::IndexRange::IndexRange() 73 : type(GL_NONE), offset(0), count(0) 74 { 75 } 76 77 IndexRangeCache::IndexRange::IndexRange(GLenum typ, intptr_t off, GLsizei c) 78 : type(typ), offset(off), count(c) 79 { 80 } 81 82 bool IndexRangeCache::IndexRange::operator<(const IndexRange& rhs) const 83 { 84 return std::make_tuple(type, offset, count) < std::make_tuple(rhs.type, rhs.offset, rhs.count); 85 } 86 87 IndexRangeCache::IndexBounds::IndexBounds() 88 : minIndex(0), maxIndex(0), streamOffset(0) 89 { 90 } 91 92 IndexRangeCache::IndexBounds::IndexBounds(unsigned int minIdx, unsigned int maxIdx, unsigned int offset) 93 : minIndex(minIdx), maxIndex(maxIdx), streamOffset(offset) 94 { 95 } 96 97 } 98