OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "gpu/command_buffer/service/buffer_manager.h" | 5 #include "gpu/command_buffer/service/buffer_manager.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <limits> | 9 #include <limits> |
10 | 10 |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
192 return NULL; | 192 return NULL; |
193 } | 193 } |
194 return shadow_.get() + offset; | 194 return shadow_.get() + offset; |
195 } | 195 } |
196 | 196 |
197 void Buffer::ClearCache() { | 197 void Buffer::ClearCache() { |
198 range_set_.clear(); | 198 range_set_.clear(); |
199 } | 199 } |
200 | 200 |
201 template <typename T> | 201 template <typename T> |
202 GLuint GetMaxValue(const void* data, GLuint offset, GLsizei count) { | 202 GLuint GetMaxValue(const void* data, GLuint offset, GLsizei count, |
203 GLuint primitive_restart_index) { | |
203 GLuint max_value = 0; | 204 GLuint max_value = 0; |
204 const T* element = | 205 const T* element = |
205 reinterpret_cast<const T*>(static_cast<const int8_t*>(data) + offset); | 206 reinterpret_cast<const T*>(static_cast<const int8_t*>(data) + offset); |
206 const T* end = element + count; | 207 const T* end = element + count; |
207 for (; element < end; ++element) { | 208 for (; element < end; ++element) { |
208 if (*element > max_value) { | 209 if (*element > max_value) { |
210 if (*element == primitive_restart_index) { | |
211 continue; | |
212 } | |
209 max_value = *element; | 213 max_value = *element; |
210 } | 214 } |
211 } | 215 } |
212 return max_value; | 216 return max_value; |
213 } | 217 } |
214 | 218 |
215 bool Buffer::GetMaxValueForRange( | 219 bool Buffer::GetMaxValueForRange( |
216 GLuint offset, GLsizei count, GLenum type, GLuint* max_value) { | 220 GLuint offset, GLsizei count, GLenum type, bool primitive_restart_enabled, |
217 Range range(offset, count, type); | 221 GLuint* max_value) { |
222 bool index_buffer = | |
223 this->initial_target() == GL_ELEMENT_ARRAY_BUFFER ? true : false; | |
piman
2016/03/19 00:56:11
nit: "? true : false" is redundant
piman
2016/03/19 00:56:11
What is this check for? This is only used for thin
Ken Russell (switch to Gerrit)
2016/03/19 04:06:52
Good point -- I copied this code from the original
yunchao
2016/03/21 15:11:35
I am not familiar with GetMaxValueInBufferCHROMIUM
Ken Russell (switch to Gerrit)
2016/03/21 17:41:46
GetMaxValueInBufferCHROMIUM is used to emulate cli
| |
224 GLuint primitive_restart_index = 0; | |
225 if (index_buffer && primitive_restart_enabled) { | |
226 switch (type) { | |
227 case GL_UNSIGNED_BYTE: | |
228 primitive_restart_index = 0xFF; | |
229 break; | |
230 case GL_UNSIGNED_SHORT: | |
231 primitive_restart_index = 0xFFFF; | |
232 break; | |
233 case GL_UNSIGNED_INT: | |
234 primitive_restart_index = 0xFFFFFFFF; | |
235 break; | |
236 default: | |
237 NOTREACHED(); // should never get here by validation. | |
238 break; | |
239 } | |
240 } | |
241 | |
242 Range range(offset, count, type, primitive_restart_enabled); | |
218 RangeToMaxValueMap::iterator it = range_set_.find(range); | 243 RangeToMaxValueMap::iterator it = range_set_.find(range); |
219 if (it != range_set_.end()) { | 244 if (it != range_set_.end()) { |
220 *max_value = it->second; | 245 *max_value = it->second; |
221 return true; | 246 return true; |
222 } | 247 } |
248 // Optimization. If: | |
249 // - primitive restart is enabled | |
250 // - we don't have an entry in the range set for these parameters | |
251 // for the situation when primitive restart is enabled | |
252 // - we do have an entry in the range set for these parameters for | |
253 // the situation when primitive restart is disabled | |
254 // - this entry is less than the primitive restart index | |
255 // Then we can repurpose this entry for the situation when primitive | |
256 // restart is enabled. Otherwise, we need to compute the max index | |
257 // from scratch. | |
258 if (primitive_restart_enabled) { | |
259 Range disabled_range(offset, count, type, false); | |
260 RangeToMaxValueMap::iterator it = range_set_.find(disabled_range); | |
261 if (it != range_set_.end() && it->second < primitive_restart_index) { | |
262 // This reuses the max value for the case where primitive | |
263 // restart is enabled. | |
264 range_set_.insert(std::make_pair(range, it->second)); | |
265 *max_value = it->second; | |
266 return true; | |
267 } | |
268 } | |
223 | 269 |
224 uint32_t size; | 270 uint32_t size; |
225 if (!SafeMultiplyUint32( | 271 if (!SafeMultiplyUint32( |
226 count, GLES2Util::GetGLTypeSizeForBuffers(type), &size)) { | 272 count, GLES2Util::GetGLTypeSizeForBuffers(type), &size)) { |
227 return false; | 273 return false; |
228 } | 274 } |
229 | 275 |
230 if (!SafeAddUint32(offset, size, &size)) { | 276 if (!SafeAddUint32(offset, size, &size)) { |
231 return false; | 277 return false; |
232 } | 278 } |
233 | 279 |
234 if (size > static_cast<uint32_t>(size_)) { | 280 if (size > static_cast<uint32_t>(size_)) { |
235 return false; | 281 return false; |
236 } | 282 } |
237 | 283 |
238 if (!shadowed_) { | 284 if (!shadowed_) { |
239 return false; | 285 return false; |
240 } | 286 } |
241 | 287 |
242 // Scan the range for the max value and store | 288 // Scan the range for the max value and store |
243 GLuint max_v = 0; | 289 GLuint max_v = 0; |
244 switch (type) { | 290 switch (type) { |
245 case GL_UNSIGNED_BYTE: | 291 case GL_UNSIGNED_BYTE: |
246 max_v = GetMaxValue<uint8_t>(shadow_.get(), offset, count); | 292 max_v = GetMaxValue<uint8_t>(shadow_.get(), offset, count, |
293 primitive_restart_index); | |
247 break; | 294 break; |
248 case GL_UNSIGNED_SHORT: | 295 case GL_UNSIGNED_SHORT: |
249 // Check we are not accessing an odd byte for a 2 byte value. | 296 // Check we are not accessing an odd byte for a 2 byte value. |
250 if ((offset & 1) != 0) { | 297 if ((offset & 1) != 0) { |
251 return false; | 298 return false; |
252 } | 299 } |
253 max_v = GetMaxValue<uint16_t>(shadow_.get(), offset, count); | 300 max_v = GetMaxValue<uint16_t>(shadow_.get(), offset, count, |
301 primitive_restart_index); | |
254 break; | 302 break; |
255 case GL_UNSIGNED_INT: | 303 case GL_UNSIGNED_INT: |
256 // Check we are not accessing a non aligned address for a 4 byte value. | 304 // Check we are not accessing a non aligned address for a 4 byte value. |
257 if ((offset & 3) != 0) { | 305 if ((offset & 3) != 0) { |
258 return false; | 306 return false; |
259 } | 307 } |
260 max_v = GetMaxValue<uint32_t>(shadow_.get(), offset, count); | 308 max_v = GetMaxValue<uint32_t>(shadow_.get(), offset, count, |
309 primitive_restart_index); | |
261 break; | 310 break; |
262 default: | 311 default: |
263 NOTREACHED(); // should never get here by validation. | 312 NOTREACHED(); // should never get here by validation. |
264 break; | 313 break; |
265 } | 314 } |
266 range_set_.insert(std::make_pair(range, max_v)); | 315 range_set_.insert(std::make_pair(range, max_v)); |
267 *max_value = max_v; | 316 *max_value = max_v; |
268 return true; | 317 return true; |
269 } | 318 } |
270 | 319 |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
554 auto guid = gfx::GetGLBufferGUIDForTracing( | 603 auto guid = gfx::GetGLBufferGUIDForTracing( |
555 memory_tracker_->ShareGroupTracingGUID(), client_buffer_id); | 604 memory_tracker_->ShareGroupTracingGUID(), client_buffer_id); |
556 pmd->CreateSharedGlobalAllocatorDump(guid); | 605 pmd->CreateSharedGlobalAllocatorDump(guid); |
557 pmd->AddOwnershipEdge(dump->guid(), guid); | 606 pmd->AddOwnershipEdge(dump->guid(), guid); |
558 } | 607 } |
559 return true; | 608 return true; |
560 } | 609 } |
561 | 610 |
562 } // namespace gles2 | 611 } // namespace gles2 |
563 } // namespace gpu | 612 } // namespace gpu |
OLD | NEW |