Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(178)

Side by Side Diff: gpu/command_buffer/client/ring_buffer.cc

Issue 1168853002: Use mapped memory for uploading large textures. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added dcheck and improved other error messages Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « gpu/command_buffer/client/ring_buffer.h ('k') | gpu/command_buffer/client/ring_buffer_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // This file contains the implementation of the RingBuffer class. 5 // This file contains the implementation of the RingBuffer class.
6 6
7 #include "gpu/command_buffer/client/ring_buffer.h" 7 #include "gpu/command_buffer/client/ring_buffer.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 DCHECK(block.state == IN_USE) 96 DCHECK(block.state == IN_USE)
97 << "block that corresponds to offset already freed"; 97 << "block that corresponds to offset already freed";
98 block.token = token; 98 block.token = token;
99 block.state = FREE_PENDING_TOKEN; 99 block.state = FREE_PENDING_TOKEN;
100 return; 100 return;
101 } 101 }
102 } 102 }
103 NOTREACHED() << "attempt to free non-existant block"; 103 NOTREACHED() << "attempt to free non-existant block";
104 } 104 }
105 105
106 void RingBuffer::DiscardBlock(void* pointer) {
107 Offset offset = GetOffset(pointer);
108 offset -= base_offset_;
109 DCHECK(!blocks_.empty()) << "no allocations to discard";
110 for (Container::reverse_iterator it = blocks_.rbegin();
111 it != blocks_.rend();
112 ++it) {
113 Block& block = *it;
114 if (block.offset == offset) {
115 DCHECK(block.state != PADDING)
116 << "block that corresponds to offset already discarded";
117 block.state = PADDING;
118
119 // Remove block if it were in the back along with any extra padding.
120 while (!blocks_.empty() && blocks_.back().state == PADDING) {
121 free_offset_= blocks_.back().offset;
122 blocks_.pop_back();
123 }
124
125 // Remove blocks if it were in the front along with extra padding.
126 while (!blocks_.empty() && blocks_.front().state == PADDING) {
127 blocks_.pop_front();
128 if (blocks_.empty())
129 break;
130
131 in_use_offset_ = blocks_.front().offset;
132 }
133
134 // In the special case when there are no blocks, we should be reset it.
135 if (blocks_.empty()) {
136 in_use_offset_ = 0;
137 free_offset_ = 0;
138 }
139 return;
140 }
141 }
142 NOTREACHED() << "attempt to discard non-existant block";
143 }
144
106 unsigned int RingBuffer::GetLargestFreeSizeNoWaiting() { 145 unsigned int RingBuffer::GetLargestFreeSizeNoWaiting() {
107 unsigned int last_token_read = helper_->last_token_read(); 146 unsigned int last_token_read = helper_->last_token_read();
108 while (!blocks_.empty()) { 147 while (!blocks_.empty()) {
109 Block& block = blocks_.front(); 148 Block& block = blocks_.front();
110 if (block.token > last_token_read || block.state == IN_USE) break; 149 if (block.token > last_token_read || block.state == IN_USE) break;
111 FreeOldestBlock(); 150 FreeOldestBlock();
112 } 151 }
113 if (free_offset_ == in_use_offset_) { 152 if (free_offset_ == in_use_offset_) {
114 if (blocks_.empty()) { 153 if (blocks_.empty()) {
115 // The entire buffer is free. 154 // The entire buffer is free.
116 DCHECK_EQ(free_offset_, 0u); 155 DCHECK_EQ(free_offset_, 0u);
117 return size_; 156 return size_;
118 } else { 157 } else {
119 // The entire buffer is in use. 158 // The entire buffer is in use.
120 return 0; 159 return 0;
121 } 160 }
122 } else if (free_offset_ > in_use_offset_) { 161 } else if (free_offset_ > in_use_offset_) {
123 // It's free from free_offset_ to size_ and from 0 to in_use_offset_ 162 // It's free from free_offset_ to size_ and from 0 to in_use_offset_
124 return std::max(size_ - free_offset_, in_use_offset_); 163 return std::max(size_ - free_offset_, in_use_offset_);
125 } else { 164 } else {
126 // It's free from free_offset_ -> in_use_offset_; 165 // It's free from free_offset_ -> in_use_offset_;
127 return in_use_offset_ - free_offset_; 166 return in_use_offset_ - free_offset_;
128 } 167 }
129 } 168 }
130 169
131 } // namespace gpu 170 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/client/ring_buffer.h ('k') | gpu/command_buffer/client/ring_buffer_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698