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

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

Issue 2550583002: gpu: Thread-safe command buffer state lookup. (Closed)
Patch Set: move cmd buffer helper memory dump to context provider Created 4 years 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
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 #ifndef GPU_COMMAND_BUFFER_COMMON_COMMAND_BUFFER_H_ 5 #ifndef GPU_COMMAND_BUFFER_COMMON_COMMAND_BUFFER_H_
6 #define GPU_COMMAND_BUFFER_COMMON_COMMAND_BUFFER_H_ 6 #define GPU_COMMAND_BUFFER_COMMON_COMMAND_BUFFER_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "gpu/command_buffer/common/buffer.h" 12 #include "gpu/command_buffer/common/buffer.h"
13 #include "gpu/command_buffer/common/constants.h" 13 #include "gpu/command_buffer/common/constants.h"
14 #include "gpu/gpu_export.h" 14 #include "gpu/gpu_export.h"
15 15
16 namespace gpu { 16 namespace gpu {
17 17
18 // Common interface for CommandBuffer implementations. 18 // Common interface for CommandBuffer implementations.
19 class GPU_EXPORT CommandBuffer { 19 class GPU_EXPORT CommandBuffer {
20 public: 20 public:
21 struct State { 21 struct State {
22 State() 22 State()
23 : get_offset(0), 23 : get_offset(0),
24 token(-1), 24 token(-1),
25 error(error::kNoError), 25 error(error::kNoError),
26 context_lost_reason(error::kUnknown), 26 context_lost_reason(error::kUnknown),
27 generation(0) { 27 generation(0) {
jbauman 2016/12/09 03:16:03 initialize release_count
sunnyps 2016/12/09 04:09:37 Done.
28 } 28 }
29 29
30 // The offset (in entries) from which the reader is reading. 30 // The offset (in entries) from which the reader is reading.
31 int32_t get_offset; 31 int32_t get_offset;
32 32
33 // The current token value. This is used by the writer to defer 33 // The current token value. This is used by the writer to defer
34 // changes to shared memory objects until the reader has reached a certain 34 // changes to shared memory objects until the reader has reached a certain
35 // point in the command buffer. The reader is responsible for updating the 35 // point in the command buffer. The reader is responsible for updating the
36 // token value, for example in response to an asynchronous set token command 36 // token value, for example in response to an asynchronous set token command
37 // embedded in the command buffer. The default token value is zero. 37 // embedded in the command buffer. The default token value is zero.
38 int32_t token; 38 int32_t token;
39 39
40 uint64_t release_count;
41
40 // Error status. 42 // Error status.
41 error::Error error; 43 error::Error error;
42 44
43 // Lost context detail information. 45 // Lost context detail information.
44 error::ContextLostReason context_lost_reason; 46 error::ContextLostReason context_lost_reason;
45 47
46 // Generation index of this state. The generation index is incremented every 48 // Generation index of this state. The generation index is incremented every
47 // time a new state is retrieved from the command processor, so that 49 // time a new state is retrieved from the command processor, so that
48 // consistency can be kept even if IPC messages are processed out-of-order. 50 // consistency can be kept even if IPC messages are processed out-of-order.
49 uint32_t generation; 51 uint32_t generation;
(...skipping 17 matching lines...) Expand all
67 static bool InRange(int32_t start, int32_t end, int32_t value) { 69 static bool InRange(int32_t start, int32_t end, int32_t value) {
68 if (start <= end) 70 if (start <= end)
69 return start <= value && value <= end; 71 return start <= value && value <= end;
70 else 72 else
71 return start <= value || value <= end; 73 return start <= value || value <= end;
72 } 74 }
73 75
74 // Returns the last state without synchronizing with the service. 76 // Returns the last state without synchronizing with the service.
75 virtual State GetLastState() = 0; 77 virtual State GetLastState() = 0;
76 78
77 // Returns the last token without synchronizing with the service. Note that
78 // while you could just call GetLastState().token, GetLastState needs to be
79 // fast as it is called for every command where GetLastToken is only called
80 // by code that needs to know the last token so it can be slower but more up
81 // to date than GetLastState.
82 virtual int32_t GetLastToken() = 0;
83
84 // The writer calls this to update its put offset. This ensures the reader 79 // The writer calls this to update its put offset. This ensures the reader
85 // sees the latest added commands, and will eventually process them. On the 80 // sees the latest added commands, and will eventually process them. On the
86 // service side, commands are processed up to the given put_offset before 81 // service side, commands are processed up to the given put_offset before
87 // subsequent Flushes on the same GpuChannel. 82 // subsequent Flushes on the same GpuChannel.
88 virtual void Flush(int32_t put_offset) = 0; 83 virtual void Flush(int32_t put_offset) = 0;
89 84
90 // As Flush, ensures that on the service side, commands up to put_offset 85 // As Flush, ensures that on the service side, commands up to put_offset
91 // are processed but before subsequent commands on the same GpuChannel but 86 // are processed but before subsequent commands on the same GpuChannel but
92 // flushing to the service may be deferred. 87 // flushing to the service may be deferred.
93 virtual void OrderingBarrier(int32_t put_offset) = 0; 88 virtual void OrderingBarrier(int32_t put_offset) = 0;
94 89
95 // The writer calls this to wait until the current token is within a 90 // The writer calls this to wait until the current token is within a
96 // specific range, inclusive. Can return early if an error is generated. 91 // specific range, inclusive. Can return early if an error is generated.
97 virtual void WaitForTokenInRange(int32_t start, int32_t end) = 0; 92 virtual State WaitForTokenInRange(int32_t start, int32_t end) = 0;
98 93
99 // The writer calls this to wait until the current get offset is within a 94 // The writer calls this to wait until the current get offset is within a
100 // specific range, inclusive. Can return early if an error is generated. 95 // specific range, inclusive. Can return early if an error is generated.
101 virtual void WaitForGetOffsetInRange(int32_t start, int32_t end) = 0; 96 virtual State WaitForGetOffsetInRange(int32_t start, int32_t end) = 0;
102 97
103 // Sets the buffer commands are read from. 98 // Sets the buffer commands are read from.
104 // Also resets the get and put offsets to 0. 99 // Also resets the get and put offsets to 0.
105 virtual void SetGetBuffer(int32_t transfer_buffer_id) = 0; 100 virtual void SetGetBuffer(int32_t transfer_buffer_id) = 0;
106 101
107 // Create a transfer buffer of the given size. Returns its ID or -1 on 102 // Create a transfer buffer of the given size. Returns its ID or -1 on
108 // error. 103 // error.
109 virtual scoped_refptr<gpu::Buffer> CreateTransferBuffer(size_t size, 104 virtual scoped_refptr<gpu::Buffer> CreateTransferBuffer(size_t size,
110 int32_t* id) = 0; 105 int32_t* id) = 0;
111 106
112 // Destroy a transfer buffer. The ID must be positive. 107 // Destroy a transfer buffer. The ID must be positive.
113 virtual void DestroyTransferBuffer(int32_t id) = 0; 108 virtual void DestroyTransferBuffer(int32_t id) = 0;
114 109
115 // The NaCl Win64 build only really needs the struct definitions above; having
116 // GetLastError declared would mean we'd have to also define it, and pull more
117 // of gpu in to the NaCl Win64 build.
118 #if !defined(NACL_WIN64)
119 // TODO(apatrick): this is a temporary optimization while skia is calling
120 // RendererGLContext::MakeCurrent prior to every GL call. It saves returning 6
121 // ints redundantly when only the error is needed for the CommandBufferProxy
122 // implementation.
123 virtual error::Error GetLastError();
124 #endif
125
126 private: 110 private:
127 DISALLOW_COPY_AND_ASSIGN(CommandBuffer); 111 DISALLOW_COPY_AND_ASSIGN(CommandBuffer);
128 }; 112 };
129 113
130 } // namespace gpu 114 } // namespace gpu
131 115
132 #endif // GPU_COMMAND_BUFFER_COMMON_COMMAND_BUFFER_H_ 116 #endif // GPU_COMMAND_BUFFER_COMMON_COMMAND_BUFFER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698