blob: 4fdb0ca820baed73e0fa614cc6efe1e2784f0968 [file] [log] [blame]
Geoff Langf23eb282013-07-22 10:52:19 -04001#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
16namespace rx
17{
18
Geoff Langb23fc092013-08-06 10:43:14 -040019void IndexRangeCache::addRange(GLenum type, unsigned int offset, GLsizei count, unsigned int minIdx, unsigned int maxIdx,
Geoff Langf23eb282013-07-22 10:52:19 -040020 unsigned int streamOffset)
21{
22 mIndexRangeCache[IndexRange(type, offset, count)] = IndexBounds(minIdx, maxIdx, streamOffset);
23}
24
25void 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;
Geoff Lang5d601382014-07-22 15:14:06 -040034 unsigned int rangeEnd = i->second.streamOffset + (gl::GetTypeInfo(i->first.type).bytes * i->first.count);
Geoff Langf23eb282013-07-22 10:52:19 -040035
36 if (invalidateEnd < rangeStart || invalidateStart > rangeEnd)
37 {
38 ++i;
39 }
40 else
41 {
42 i = mIndexRangeCache.erase(i);
43 }
44 }
45}
46
Geoff Langb23fc092013-08-06 10:43:14 -040047bool IndexRangeCache::findRange(GLenum type, unsigned int offset, GLsizei count, unsigned int *outMinIndex,
Geoff Langf23eb282013-07-22 10:52:19 -040048 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
67void IndexRangeCache::clear()
68{
69 mIndexRangeCache.clear();
70}
71
72IndexRangeCache::IndexRange::IndexRange()
73 : type(GL_NONE), offset(0), count(0)
74{
75}
76
77IndexRangeCache::IndexRange::IndexRange(GLenum typ, intptr_t off, GLsizei c)
78 : type(typ), offset(off), count(c)
79{
80}
81
82bool 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
87IndexRangeCache::IndexBounds::IndexBounds()
88 : minIndex(0), maxIndex(0), streamOffset(0)
89{
90}
91
92IndexRangeCache::IndexBounds::IndexBounds(unsigned int minIdx, unsigned int maxIdx, unsigned int offset)
93 : minIndex(minIdx), maxIndex(maxIdx), streamOffset(offset)
94{
95}
96
97}