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

Side by Side Diff: gpu/command_buffer/tests/gl_manager.cc

Issue 1331843005: Implemented new fence syncs which replaces the old sync points. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Reverted mojo readme, changed wait() to take a pointer Created 5 years, 2 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/tests/gl_manager.h ('k') | gpu/gles2_conform_support/egl/display.h » ('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) 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/tests/gl_manager.h" 5 #include "gpu/command_buffer/tests/gl_manager.h"
6 6
7 #include <GLES2/gl2.h> 7 #include <GLES2/gl2.h>
8 #include <GLES2/gl2ext.h> 8 #include <GLES2/gl2ext.h>
9 #include <GLES2/gl2extchromium.h> 9 #include <GLES2/gl2extchromium.h>
10 10
(...skipping 10 matching lines...) Expand all
21 #include "gpu/command_buffer/common/gles2_cmd_utils.h" 21 #include "gpu/command_buffer/common/gles2_cmd_utils.h"
22 #include "gpu/command_buffer/common/value_state.h" 22 #include "gpu/command_buffer/common/value_state.h"
23 #include "gpu/command_buffer/service/command_buffer_service.h" 23 #include "gpu/command_buffer/service/command_buffer_service.h"
24 #include "gpu/command_buffer/service/context_group.h" 24 #include "gpu/command_buffer/service/context_group.h"
25 #include "gpu/command_buffer/service/gl_context_virtual.h" 25 #include "gpu/command_buffer/service/gl_context_virtual.h"
26 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" 26 #include "gpu/command_buffer/service/gles2_cmd_decoder.h"
27 #include "gpu/command_buffer/service/gpu_scheduler.h" 27 #include "gpu/command_buffer/service/gpu_scheduler.h"
28 #include "gpu/command_buffer/service/image_manager.h" 28 #include "gpu/command_buffer/service/image_manager.h"
29 #include "gpu/command_buffer/service/mailbox_manager_impl.h" 29 #include "gpu/command_buffer/service/mailbox_manager_impl.h"
30 #include "gpu/command_buffer/service/memory_tracking.h" 30 #include "gpu/command_buffer/service/memory_tracking.h"
31 #include "gpu/command_buffer/service/sync_point_manager.h"
31 #include "gpu/command_buffer/service/transfer_buffer_manager.h" 32 #include "gpu/command_buffer/service/transfer_buffer_manager.h"
32 #include "gpu/command_buffer/service/valuebuffer_manager.h" 33 #include "gpu/command_buffer/service/valuebuffer_manager.h"
33 #include "testing/gtest/include/gtest/gtest.h" 34 #include "testing/gtest/include/gtest/gtest.h"
34 #include "ui/gfx/buffer_format_util.h" 35 #include "ui/gfx/buffer_format_util.h"
35 #include "ui/gfx/gpu_memory_buffer.h" 36 #include "ui/gfx/gpu_memory_buffer.h"
36 #include "ui/gl/gl_context.h" 37 #include "ui/gl/gl_context.h"
37 #include "ui/gl/gl_image_ref_counted_memory.h" 38 #include "ui/gl/gl_image_ref_counted_memory.h"
38 #include "ui/gl/gl_share_group.h" 39 #include "ui/gl/gl_share_group.h"
39 #include "ui/gl/gl_surface.h" 40 #include "ui/gl/gl_surface.h"
40 41
41 namespace gpu { 42 namespace gpu {
42 namespace { 43 namespace {
43 44
45 uint64_t g_next_command_buffer_id = 0;
46
44 class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer { 47 class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer {
45 public: 48 public:
46 GpuMemoryBufferImpl(base::RefCountedBytes* bytes, 49 GpuMemoryBufferImpl(base::RefCountedBytes* bytes,
47 const gfx::Size& size, 50 const gfx::Size& size,
48 gfx::BufferFormat format) 51 gfx::BufferFormat format)
49 : bytes_(bytes), size_(size), format_(format), mapped_(false) {} 52 : bytes_(bytes), size_(size), format_(format), mapped_(false) {}
50 53
51 static GpuMemoryBufferImpl* FromClientBuffer(ClientBuffer buffer) { 54 static GpuMemoryBufferImpl* FromClientBuffer(ClientBuffer buffer) {
52 return reinterpret_cast<GpuMemoryBufferImpl*>(buffer); 55 return reinterpret_cast<GpuMemoryBufferImpl*>(buffer);
53 } 56 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 99
97 } // namespace 100 } // namespace
98 101
99 int GLManager::use_count_; 102 int GLManager::use_count_;
100 scoped_refptr<gfx::GLShareGroup>* GLManager::base_share_group_; 103 scoped_refptr<gfx::GLShareGroup>* GLManager::base_share_group_;
101 scoped_refptr<gfx::GLSurface>* GLManager::base_surface_; 104 scoped_refptr<gfx::GLSurface>* GLManager::base_surface_;
102 scoped_refptr<gfx::GLContext>* GLManager::base_context_; 105 scoped_refptr<gfx::GLContext>* GLManager::base_context_;
103 106
104 GLManager::Options::Options() 107 GLManager::Options::Options()
105 : size(4, 4), 108 : size(4, 4),
109 sync_point_manager(NULL),
106 share_group_manager(NULL), 110 share_group_manager(NULL),
107 share_mailbox_manager(NULL), 111 share_mailbox_manager(NULL),
108 virtual_manager(NULL), 112 virtual_manager(NULL),
109 bind_generates_resource(false), 113 bind_generates_resource(false),
110 lose_context_when_out_of_memory(false), 114 lose_context_when_out_of_memory(false),
111 context_lost_allowed(false), 115 context_lost_allowed(false),
112 context_type(gles2::CONTEXT_TYPE_OPENGLES2) {} 116 context_type(gles2::CONTEXT_TYPE_OPENGLES2) {}
113 117
114 GLManager::GLManager() : context_lost_allowed_(false) { 118 GLManager::GLManager()
119 : sync_point_manager_(nullptr),
120 context_lost_allowed_(false),
121 command_buffer_id_(g_next_command_buffer_id++),
122 next_fence_sync_release_(1) {
115 SetupBaseContext(); 123 SetupBaseContext();
116 } 124 }
117 125
118 GLManager::~GLManager() { 126 GLManager::~GLManager() {
119 --use_count_; 127 --use_count_;
120 if (!use_count_) { 128 if (!use_count_) {
121 if (base_share_group_) { 129 if (base_share_group_) {
122 delete base_context_; 130 delete base_context_;
123 base_context_ = NULL; 131 base_context_ = NULL;
124 } 132 }
(...skipping 14 matching lines...) Expand all
139 gfx::BufferFormat format) { 147 gfx::BufferFormat format) {
140 std::vector<uint8> data(gfx::BufferSizeForBufferFormat(size, format), 0); 148 std::vector<uint8> data(gfx::BufferSizeForBufferFormat(size, format), 0);
141 scoped_refptr<base::RefCountedBytes> bytes(new base::RefCountedBytes(data)); 149 scoped_refptr<base::RefCountedBytes> bytes(new base::RefCountedBytes(data));
142 return make_scoped_ptr<gfx::GpuMemoryBuffer>( 150 return make_scoped_ptr<gfx::GpuMemoryBuffer>(
143 new GpuMemoryBufferImpl(bytes.get(), size, format)); 151 new GpuMemoryBufferImpl(bytes.get(), size, format));
144 } 152 }
145 153
146 void GLManager::Initialize(const GLManager::Options& options) { 154 void GLManager::Initialize(const GLManager::Options& options) {
147 InitializeWithCommandLine(options, nullptr); 155 InitializeWithCommandLine(options, nullptr);
148 } 156 }
157
149 void GLManager::InitializeWithCommandLine(const GLManager::Options& options, 158 void GLManager::InitializeWithCommandLine(const GLManager::Options& options,
150 base::CommandLine* command_line) { 159 base::CommandLine* command_line) {
151 const int32 kCommandBufferSize = 1024 * 1024; 160 const int32 kCommandBufferSize = 1024 * 1024;
152 const size_t kStartTransferBufferSize = 4 * 1024 * 1024; 161 const size_t kStartTransferBufferSize = 4 * 1024 * 1024;
153 const size_t kMinTransferBufferSize = 1 * 256 * 1024; 162 const size_t kMinTransferBufferSize = 1 * 256 * 1024;
154 const size_t kMaxTransferBufferSize = 16 * 1024 * 1024; 163 const size_t kMaxTransferBufferSize = 16 * 1024 * 1024;
155 164
156 context_lost_allowed_ = options.context_lost_allowed; 165 context_lost_allowed_ = options.context_lost_allowed;
157 166
158 gles2::MailboxManager* mailbox_manager = NULL; 167 gles2::MailboxManager* mailbox_manager = NULL;
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 } 255 }
247 ASSERT_TRUE(context_.get() != NULL) << "could not create GL context"; 256 ASSERT_TRUE(context_.get() != NULL) << "could not create GL context";
248 257
249 ASSERT_TRUE(context_->MakeCurrent(surface_.get())); 258 ASSERT_TRUE(context_->MakeCurrent(surface_.get()));
250 259
251 if (!decoder_->Initialize(surface_.get(), context_.get(), true, options.size, 260 if (!decoder_->Initialize(surface_.get(), context_.get(), true, options.size,
252 ::gpu::gles2::DisallowedFeatures(), attribs)) { 261 ::gpu::gles2::DisallowedFeatures(), attribs)) {
253 return; 262 return;
254 } 263 }
255 264
265 if (options.sync_point_manager) {
266 sync_point_manager_ = options.sync_point_manager;
267 sync_point_order_data_ = SyncPointOrderData::Create();
268 sync_point_client_ = sync_point_manager_->CreateSyncPointClient(
269 sync_point_order_data_, GetNamespaceID(), GetCommandBufferID());
270
271 decoder_->SetFenceSyncReleaseCallback(
272 base::Bind(&GLManager::OnFenceSyncRelease, base::Unretained(this)));
273 decoder_->SetWaitFenceSyncCallback(
274 base::Bind(&GLManager::OnWaitFenceSync, base::Unretained(this)));
275 } else {
276 sync_point_manager_ = nullptr;
277 sync_point_order_data_ = nullptr;
278 sync_point_client_ = nullptr;
279 }
280
256 command_buffer_->SetPutOffsetChangeCallback( 281 command_buffer_->SetPutOffsetChangeCallback(
257 base::Bind(&GLManager::PumpCommands, base::Unretained(this))); 282 base::Bind(&GLManager::PumpCommands, base::Unretained(this)));
258 command_buffer_->SetGetBufferChangeCallback( 283 command_buffer_->SetGetBufferChangeCallback(
259 base::Bind(&GLManager::GetBufferChanged, base::Unretained(this))); 284 base::Bind(&GLManager::GetBufferChanged, base::Unretained(this)));
260 285
261 // Create the GLES2 helper, which writes the command buffer protocol. 286 // Create the GLES2 helper, which writes the command buffer protocol.
262 gles2_helper_.reset(new gles2::GLES2CmdHelper(command_buffer_.get())); 287 gles2_helper_.reset(new gles2::GLES2CmdHelper(command_buffer_.get()));
263 ASSERT_TRUE(gles2_helper_->Initialize(kCommandBufferSize)); 288 ASSERT_TRUE(gles2_helper_->Initialize(kCommandBufferSize));
264 289
265 // Create a transfer buffer. 290 // Create a transfer buffer.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 gfx::GpuPreference gpu_preference(gfx::PreferDiscreteGpu); 322 gfx::GpuPreference gpu_preference(gfx::PreferDiscreteGpu);
298 base_context_ = new scoped_refptr<gfx::GLContext>( 323 base_context_ = new scoped_refptr<gfx::GLContext>(
299 gfx::GLContext::CreateGLContext(base_share_group_->get(), 324 gfx::GLContext::CreateGLContext(base_share_group_->get(),
300 base_surface_->get(), 325 base_surface_->get(),
301 gpu_preference)); 326 gpu_preference));
302 #endif 327 #endif
303 } 328 }
304 ++use_count_; 329 ++use_count_;
305 } 330 }
306 331
332 void GLManager::OnFenceSyncRelease(uint64_t release) {
333 DCHECK(sync_point_client_);
334 DCHECK(!sync_point_client_->client_state()->IsFenceSyncReleased(release));
335 sync_point_client_->ReleaseFenceSync(release);
336 }
337
338 bool GLManager::OnWaitFenceSync(gpu::CommandBufferNamespace namespace_id,
339 uint64_t command_buffer_id,
340 uint64_t release) {
341 DCHECK(sync_point_client_);
342 scoped_refptr<gpu::SyncPointClientState> release_state =
343 sync_point_manager_->GetSyncPointClientState(namespace_id,
344 command_buffer_id);
345 if (!release_state)
346 return true;
347
348 // GLManager does not support being multithreaded at this point, so the fence
349 // sync must be released by the time wait is called.
350 DCHECK(release_state->IsFenceSyncReleased(release));
351 return true;
352 }
353
307 void GLManager::MakeCurrent() { 354 void GLManager::MakeCurrent() {
308 ::gles2::SetGLContext(gles2_implementation_.get()); 355 ::gles2::SetGLContext(gles2_implementation_.get());
309 } 356 }
310 357
311 void GLManager::SetSurface(gfx::GLSurface* surface) { 358 void GLManager::SetSurface(gfx::GLSurface* surface) {
312 decoder_->SetSurface(surface); 359 decoder_->SetSurface(surface);
313 } 360 }
314 361
315 void GLManager::Destroy() { 362 void GLManager::Destroy() {
316 if (gles2_implementation_.get()) { 363 if (gles2_implementation_.get()) {
317 MakeCurrent(); 364 MakeCurrent();
318 EXPECT_TRUE(glGetError() == GL_NONE); 365 EXPECT_TRUE(glGetError() == GL_NONE);
319 gles2_implementation_->Flush(); 366 gles2_implementation_->Flush();
320 gles2_implementation_.reset(); 367 gles2_implementation_.reset();
321 } 368 }
322 transfer_buffer_.reset(); 369 transfer_buffer_.reset();
323 gles2_helper_.reset(); 370 gles2_helper_.reset();
324 command_buffer_.reset(); 371 command_buffer_.reset();
372 sync_point_manager_ = nullptr;
373 sync_point_client_ = nullptr;
374 if (sync_point_order_data_) {
375 sync_point_order_data_->Destroy();
376 sync_point_order_data_ = nullptr;
377 }
325 if (decoder_.get()) { 378 if (decoder_.get()) {
326 bool have_context = decoder_->GetGLContext() && 379 bool have_context = decoder_->GetGLContext() &&
327 decoder_->GetGLContext()->MakeCurrent(surface_.get()); 380 decoder_->GetGLContext()->MakeCurrent(surface_.get());
328 decoder_->Destroy(have_context); 381 decoder_->Destroy(have_context);
329 decoder_.reset(); 382 decoder_.reset();
330 } 383 }
331 } 384 }
332 385
333 const gpu::gles2::FeatureInfo::Workarounds& GLManager::workarounds() const { 386 const gpu::gles2::FeatureInfo::Workarounds& GLManager::workarounds() const {
334 return decoder_->GetContextGroup()->feature_info()->workarounds(); 387 return decoder_->GetContextGroup()->feature_info()->workarounds();
335 } 388 }
336 389
337 void GLManager::PumpCommands() { 390 void GLManager::PumpCommands() {
338 if (!decoder_->MakeCurrent()) { 391 if (!decoder_->MakeCurrent()) {
339 command_buffer_->SetContextLostReason(decoder_->GetContextLostReason()); 392 command_buffer_->SetContextLostReason(decoder_->GetContextLostReason());
340 command_buffer_->SetParseError(::gpu::error::kLostContext); 393 command_buffer_->SetParseError(::gpu::error::kLostContext);
341 return; 394 return;
342 } 395 }
396 uint32_t order_num = 0;
397 if (sync_point_manager_) {
398 // If sync point manager is supported, assign order numbers to commands.
399 order_num = sync_point_order_data_->GenerateUnprocessedOrderNumber(
400 sync_point_manager_);
401 sync_point_order_data_->BeginProcessingOrderNumber(order_num);
402 }
403
343 gpu_scheduler_->PutChanged(); 404 gpu_scheduler_->PutChanged();
344 ::gpu::CommandBuffer::State state = command_buffer_->GetLastState(); 405 ::gpu::CommandBuffer::State state = command_buffer_->GetLastState();
345 if (!context_lost_allowed_) { 406 if (!context_lost_allowed_) {
346 ASSERT_EQ(::gpu::error::kNoError, state.error); 407 ASSERT_EQ(::gpu::error::kNoError, state.error);
347 } 408 }
409
410 if (sync_point_manager_) {
411 // Finish processing order number here.
412 sync_point_order_data_->FinishProcessingOrderNumber(order_num);
413 }
348 } 414 }
349 415
350 bool GLManager::GetBufferChanged(int32 transfer_buffer_id) { 416 bool GLManager::GetBufferChanged(int32 transfer_buffer_id) {
351 return gpu_scheduler_->SetGetBuffer(transfer_buffer_id); 417 return gpu_scheduler_->SetGetBuffer(transfer_buffer_id);
352 } 418 }
353 419
354 Capabilities GLManager::GetCapabilities() { 420 Capabilities GLManager::GetCapabilities() {
355 return decoder_->GetCapabilities(); 421 return decoder_->GetCapabilities();
356 } 422 }
357 423
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 bool GLManager::IsGpuChannelLost() { 500 bool GLManager::IsGpuChannelLost() {
435 NOTIMPLEMENTED(); 501 NOTIMPLEMENTED();
436 return false; 502 return false;
437 } 503 }
438 504
439 gpu::CommandBufferNamespace GLManager::GetNamespaceID() const { 505 gpu::CommandBufferNamespace GLManager::GetNamespaceID() const {
440 return gpu::CommandBufferNamespace::IN_PROCESS; 506 return gpu::CommandBufferNamespace::IN_PROCESS;
441 } 507 }
442 508
443 uint64_t GLManager::GetCommandBufferID() const { 509 uint64_t GLManager::GetCommandBufferID() const {
444 return 0; 510 return command_buffer_id_;
511 }
512
513 uint64_t GLManager::GenerateFenceSyncRelease() {
514 return next_fence_sync_release_++;
515 }
516
517 bool GLManager::IsFenceSyncRelease(uint64_t release) {
518 return release > 0 && release < next_fence_sync_release_;
519 }
520
521 bool GLManager::IsFenceSyncFlushed(uint64_t release) {
522 return IsFenceSyncRelease(release);
445 } 523 }
446 524
447 } // namespace gpu 525 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/tests/gl_manager.h ('k') | gpu/gles2_conform_support/egl/display.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698