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

Side by Side Diff: gpu/command_buffer/common/command_buffer_shared.h

Issue 9380037: Use shared memory to update the renderer's view of the command buffer state. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix hang when last_state_.error accidentally overwritten Created 8 years, 10 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef GPU_COMMAND_BUFFER_COMMON_COMMAND_BUFFER_SHARED_H_
6 #define GPU_COMMAND_BUFFER_COMMON_COMMAND_BUFFER_SHARED_H_
7
8 #include "command_buffer.h"
9 #include "base/atomicops.h"
10
11 namespace gpu {
12
13 // This is a standard 4-slot asynchronous communication mechanism, used to
14 // ensure that the reader gets a consistent copy of what the writer wrote.
15 template<typename T>
16 class SharedState {
17 T states_[2][2];
18 base::subtle::Atomic32 reading_;
19 base::subtle::Atomic32 latest_;
20 base::subtle::Atomic32 slots_[2];
21
22 public:
23
24 void Initialize() {
25 for (int i = 0; i < 2; ++i) {
26 for (int j = 0; j < 2; ++j) {
27 states_[i][j] = T();
28 }
29 }
30 base::subtle::NoBarrier_Store(&reading_, 0);
31 base::subtle::NoBarrier_Store(&latest_, 0);
32 base::subtle::NoBarrier_Store(&slots_[0], 0);
33 base::subtle::Acquire_Store(&slots_[1], 0);
34 }
35
36 void Write(const T& state) {
37 int towrite = !base::subtle::Acquire_Load(&reading_);
38 int index = !base::subtle::Acquire_Load(&slots_[towrite]);
39 states_[towrite][index] = state;
40 base::subtle::MemoryBarrier();
41 base::subtle::Acquire_Store(&slots_[towrite], index);
42 base::subtle::Acquire_Store(&latest_, towrite);
43 }
44
45 // Attempt to update the state, updating only if the generation counter is
46 // newer.
47 void Read(T* state) {
48 base::subtle::MemoryBarrier();
49 int toread = !!base::subtle::Acquire_Load(&latest_);
50 base::subtle::Acquire_Store(&reading_, toread);
51 int index = !!base::subtle::Acquire_Load(&slots_[toread]);
52 if (states_[toread][index].generation - state->generation < 0x80000000U)
53 *state = states_[toread][index];
54 }
55 };
56
57 typedef SharedState<CommandBuffer::State> CommandBufferSharedState;
58
59 } // namespace gpu
60
61 #endif // GPU_COMMAND_BUFFER_COMMON_COMMAND_BUFFER_SHARED_H_
OLDNEW
« no previous file with comments | « content/common/gpu/gpu_messages.h ('k') | gpu/command_buffer/common/command_buffer_shared_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698