Chromium Code Reviews| 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 16 matching lines...) Expand all Loading... | |
| 27 | 27 |
| 28 BufferManager::BufferManager(MemoryTracker* memory_tracker, | 28 BufferManager::BufferManager(MemoryTracker* memory_tracker, |
| 29 FeatureInfo* feature_info) | 29 FeatureInfo* feature_info) |
| 30 : memory_type_tracker_( | 30 : memory_type_tracker_( |
| 31 new MemoryTypeTracker(memory_tracker)), | 31 new MemoryTypeTracker(memory_tracker)), |
| 32 memory_tracker_(memory_tracker), | 32 memory_tracker_(memory_tracker), |
| 33 feature_info_(feature_info), | 33 feature_info_(feature_info), |
| 34 allow_buffers_on_multiple_targets_(false), | 34 allow_buffers_on_multiple_targets_(false), |
| 35 allow_fixed_attribs_(false), | 35 allow_fixed_attribs_(false), |
| 36 buffer_count_(0), | 36 buffer_count_(0), |
| 37 primitive_restart_enabled_(false), | |
| 37 have_context_(true), | 38 have_context_(true), |
| 38 use_client_side_arrays_for_stream_buffers_( | 39 use_client_side_arrays_for_stream_buffers_( |
| 39 feature_info | 40 feature_info |
| 40 ? feature_info->workarounds() | 41 ? feature_info->workarounds() |
| 41 .use_client_side_arrays_for_stream_buffers | 42 .use_client_side_arrays_for_stream_buffers |
| 42 : 0) { | 43 : 0) { |
| 43 // When created from InProcessCommandBuffer, we won't have a |memory_tracker_| | 44 // When created from InProcessCommandBuffer, we won't have a |memory_tracker_| |
| 44 // so don't register a dump provider. | 45 // so don't register a dump provider. |
| 45 if (memory_tracker_) { | 46 if (memory_tracker_) { |
| 46 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( | 47 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 192 return NULL; | 193 return NULL; |
| 193 } | 194 } |
| 194 return shadow_.get() + offset; | 195 return shadow_.get() + offset; |
| 195 } | 196 } |
| 196 | 197 |
| 197 void Buffer::ClearCache() { | 198 void Buffer::ClearCache() { |
| 198 range_set_.clear(); | 199 range_set_.clear(); |
| 199 } | 200 } |
| 200 | 201 |
| 201 template <typename T> | 202 template <typename T> |
| 202 GLuint GetMaxValue(const void* data, GLuint offset, GLsizei count) { | 203 GLuint GetMaxValue(const void* data, GLuint offset, GLsizei count, |
| 204 GLuint primitive_restart_index) { | |
| 203 GLuint max_value = 0; | 205 GLuint max_value = 0; |
| 204 const T* element = | 206 const T* element = |
| 205 reinterpret_cast<const T*>(static_cast<const int8_t*>(data) + offset); | 207 reinterpret_cast<const T*>(static_cast<const int8_t*>(data) + offset); |
| 206 const T* end = element + count; | 208 const T* end = element + count; |
| 207 for (; element < end; ++element) { | 209 for (; element < end; ++element) { |
| 208 if (*element > max_value) { | 210 if (*element > max_value) { |
| 211 if (*element == primitive_restart_index) { | |
| 212 continue; | |
| 213 } | |
| 209 max_value = *element; | 214 max_value = *element; |
| 210 } | 215 } |
| 211 } | 216 } |
| 212 return max_value; | 217 return max_value; |
| 213 } | 218 } |
| 214 | 219 |
| 215 bool Buffer::GetMaxValueForRange( | 220 bool Buffer::GetMaxValueForRange( |
| 216 GLuint offset, GLsizei count, GLenum type, GLuint* max_value) { | 221 GLuint offset, GLsizei count, GLenum type, GLuint* max_value) { |
| 217 Range range(offset, count, type); | 222 Range range(offset, count, type); |
| 218 RangeToMaxValueMap::iterator it = range_set_.find(range); | 223 RangeToMaxValueMap::iterator it = range_set_.find(range); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 234 if (size > static_cast<uint32_t>(size_)) { | 239 if (size > static_cast<uint32_t>(size_)) { |
| 235 return false; | 240 return false; |
| 236 } | 241 } |
| 237 | 242 |
| 238 if (!shadowed_) { | 243 if (!shadowed_) { |
| 239 return false; | 244 return false; |
| 240 } | 245 } |
| 241 | 246 |
| 242 // Scan the range for the max value and store | 247 // Scan the range for the max value and store |
| 243 GLuint max_v = 0; | 248 GLuint max_v = 0; |
| 249 GLuint primitive_restart_index = 0; | |
| 244 switch (type) { | 250 switch (type) { |
| 245 case GL_UNSIGNED_BYTE: | 251 case GL_UNSIGNED_BYTE: |
| 246 max_v = GetMaxValue<uint8_t>(shadow_.get(), offset, count); | 252 if (manager_->primitive_restart_enabled_) { |
| 253 primitive_restart_index = 0xFF; | |
| 254 } | |
| 255 max_v = GetMaxValue<uint8_t>(shadow_.get(), offset, count, | |
| 256 primitive_restart_index); | |
| 247 break; | 257 break; |
| 248 case GL_UNSIGNED_SHORT: | 258 case GL_UNSIGNED_SHORT: |
| 249 // Check we are not accessing an odd byte for a 2 byte value. | 259 // Check we are not accessing an odd byte for a 2 byte value. |
| 250 if ((offset & 1) != 0) { | 260 if ((offset & 1) != 0) { |
| 251 return false; | 261 return false; |
| 252 } | 262 } |
| 253 max_v = GetMaxValue<uint16_t>(shadow_.get(), offset, count); | 263 if (manager_->primitive_restart_enabled_) { |
| 264 primitive_restart_index = 0xFFFF; | |
| 265 } | |
| 266 max_v = GetMaxValue<uint16_t>(shadow_.get(), offset, count, | |
| 267 primitive_restart_index); | |
| 254 break; | 268 break; |
| 255 case GL_UNSIGNED_INT: | 269 case GL_UNSIGNED_INT: |
| 256 // Check we are not accessing a non aligned address for a 4 byte value. | 270 // Check we are not accessing a non aligned address for a 4 byte value. |
| 257 if ((offset & 3) != 0) { | 271 if ((offset & 3) != 0) { |
| 258 return false; | 272 return false; |
| 259 } | 273 } |
| 260 max_v = GetMaxValue<uint32_t>(shadow_.get(), offset, count); | 274 if (manager_->primitive_restart_enabled_) { |
| 275 primitive_restart_index = 0xFFFFFFFF; | |
| 276 } | |
| 277 max_v = GetMaxValue<uint32_t>(shadow_.get(), offset, count, | |
| 278 primitive_restart_index); | |
| 261 break; | 279 break; |
| 262 default: | 280 default: |
| 263 NOTREACHED(); // should never get here by validation. | 281 NOTREACHED(); // should never get here by validation. |
| 264 break; | 282 break; |
| 265 } | 283 } |
| 266 range_set_.insert(std::make_pair(range, max_v)); | 284 range_set_.insert(std::make_pair(range, max_v)); |
| 267 *max_value = max_v; | 285 *max_value = max_v; |
| 268 return true; | 286 return true; |
| 269 } | 287 } |
| 270 | 288 |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 529 case GL_TRANSFORM_FEEDBACK_BUFFER: | 547 case GL_TRANSFORM_FEEDBACK_BUFFER: |
| 530 return state->bound_transform_feedback_buffer.get(); | 548 return state->bound_transform_feedback_buffer.get(); |
| 531 case GL_UNIFORM_BUFFER: | 549 case GL_UNIFORM_BUFFER: |
| 532 return state->bound_uniform_buffer.get(); | 550 return state->bound_uniform_buffer.get(); |
| 533 default: | 551 default: |
| 534 NOTREACHED(); | 552 NOTREACHED(); |
| 535 return nullptr; | 553 return nullptr; |
| 536 } | 554 } |
| 537 } | 555 } |
| 538 | 556 |
| 557 void BufferManager::SetPrimitiveRestartState(bool enabled) { | |
| 558 if (primitive_restart_enabled_ != enabled) { | |
| 559 primitive_restart_enabled_ = enabled; | |
| 560 | |
| 561 for (BufferMap::const_iterator it = buffers_.begin(); | |
| 562 it != buffers_.end(); ++it) { | |
|
Zhenyao Mo
2016/03/15 18:24:37
nit: wrong indent
yunchao
2016/03/16 16:05:39
Done.
| |
| 563 if (it->second->initial_target() == GL_ELEMENT_ARRAY_BUFFER) { | |
| 564 it->second->range_set_.clear(); | |
| 565 } | |
| 566 } | |
| 567 } | |
| 568 } | |
| 569 | |
| 539 bool BufferManager::OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, | 570 bool BufferManager::OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, |
| 540 base::trace_event::ProcessMemoryDump* pmd) { | 571 base::trace_event::ProcessMemoryDump* pmd) { |
| 541 const int client_id = memory_tracker_->ClientId(); | 572 const int client_id = memory_tracker_->ClientId(); |
| 542 for (const auto& buffer_entry : buffers_) { | 573 for (const auto& buffer_entry : buffers_) { |
| 543 const auto& client_buffer_id = buffer_entry.first; | 574 const auto& client_buffer_id = buffer_entry.first; |
| 544 const auto& buffer = buffer_entry.second; | 575 const auto& buffer = buffer_entry.second; |
| 545 | 576 |
| 546 std::string dump_name = base::StringPrintf( | 577 std::string dump_name = base::StringPrintf( |
| 547 "gpu/gl/buffers/client_%d/buffer_%d", client_id, client_buffer_id); | 578 "gpu/gl/buffers/client_%d/buffer_%d", client_id, client_buffer_id); |
| 548 base::trace_event::MemoryAllocatorDump* dump = | 579 base::trace_event::MemoryAllocatorDump* dump = |
| 549 pmd->CreateAllocatorDump(dump_name); | 580 pmd->CreateAllocatorDump(dump_name); |
| 550 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, | 581 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, |
| 551 base::trace_event::MemoryAllocatorDump::kUnitsBytes, | 582 base::trace_event::MemoryAllocatorDump::kUnitsBytes, |
| 552 static_cast<uint64_t>(buffer->size())); | 583 static_cast<uint64_t>(buffer->size())); |
| 553 | 584 |
| 554 auto guid = gfx::GetGLBufferGUIDForTracing( | 585 auto guid = gfx::GetGLBufferGUIDForTracing( |
| 555 memory_tracker_->ShareGroupTracingGUID(), client_buffer_id); | 586 memory_tracker_->ShareGroupTracingGUID(), client_buffer_id); |
| 556 pmd->CreateSharedGlobalAllocatorDump(guid); | 587 pmd->CreateSharedGlobalAllocatorDump(guid); |
| 557 pmd->AddOwnershipEdge(dump->guid(), guid); | 588 pmd->AddOwnershipEdge(dump->guid(), guid); |
| 558 } | 589 } |
| 559 return true; | 590 return true; |
| 560 } | 591 } |
| 561 | 592 |
| 562 } // namespace gles2 | 593 } // namespace gles2 |
| 563 } // namespace gpu | 594 } // namespace gpu |
| OLD | NEW |