OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_SYNC_TOKEN_H_ | 5 #ifndef GPU_COMMAND_BUFFER_COMMON_SYNC_TOKEN_H_ |
6 #define GPU_COMMAND_BUFFER_COMMON_SYNC_TOKEN_H_ | 6 #define GPU_COMMAND_BUFFER_COMMON_SYNC_TOKEN_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <string.h> | 9 #include <string.h> |
10 | 10 |
11 #include "gpu/command_buffer/common/constants.h" | 11 #include "gpu/command_buffer/common/constants.h" |
12 #include "gpu/gpu_export.h" | 12 #include "gpu/gpu_export.h" |
13 | 13 |
14 // From glextchromium.h. | 14 // From glextchromium.h. |
15 #ifndef GL_SYNC_TOKEN_SIZE_CHROMIUM | 15 #ifndef GL_SYNC_TOKEN_SIZE_CHROMIUM |
16 #define GL_SYNC_TOKEN_SIZE_CHROMIUM 24 | 16 #define GL_SYNC_TOKEN_SIZE_CHROMIUM 24 |
17 #endif | 17 #endif |
18 | 18 |
19 namespace gpu { | 19 namespace gpu { |
20 | 20 |
21 // A Sync Token is a binary blob which represents a waitable fence sync | 21 // A Sync Token is a binary blob which represents a waitable fence sync |
22 // on a particular command buffer namespace and id. | 22 // on a particular command buffer namespace and id. |
23 // See src/gpu/GLES2/extensions/CHROMIUM/CHROMIUM_sync_point.txt for more | 23 // See src/gpu/GLES2/extensions/CHROMIUM/CHROMIUM_sync_point.txt for more |
24 // details. | 24 // details. |
25 struct GPU_EXPORT SyncToken { | 25 struct GPU_EXPORT SyncToken { |
26 SyncToken() | 26 SyncToken() |
27 : verified_flush_(false), | 27 : verified_flush_(false), |
28 namespace_id_(CommandBufferNamespace::INVALID), | 28 namespace_id_(CommandBufferNamespace::INVALID), |
| 29 extra_data_field_(0), |
29 command_buffer_id_(0), | 30 command_buffer_id_(0), |
30 release_count_(0) {} | 31 release_count_(0) {} |
31 | 32 |
32 // TODO(dyen): This is an intermediate conversion constructor while we | 33 // TODO(dyen): This is an intermediate conversion constructor while we |
33 // are converting from the old sync point system. Remove once conversion | 34 // are converting from the old sync point system. Remove once conversion |
34 // is finished. | 35 // is finished. |
35 explicit SyncToken(uint32_t sync_point) | 36 explicit SyncToken(uint32_t sync_point) |
36 : verified_flush_(sync_point ? true : false), | 37 : verified_flush_(sync_point ? true : false), |
37 namespace_id_(sync_point ? gpu::CommandBufferNamespace::OLD_SYNC_POINTS | 38 namespace_id_(sync_point ? gpu::CommandBufferNamespace::OLD_SYNC_POINTS |
38 : gpu::CommandBufferNamespace::INVALID), | 39 : gpu::CommandBufferNamespace::INVALID), |
| 40 extra_data_field_(0), |
39 command_buffer_id_(0), | 41 command_buffer_id_(0), |
40 release_count_(sync_point) {} | 42 release_count_(sync_point) {} |
41 | 43 |
42 SyncToken(CommandBufferNamespace namespace_id, | 44 SyncToken(CommandBufferNamespace namespace_id, |
| 45 int32_t extra_data_field, |
43 uint64_t command_buffer_id, | 46 uint64_t command_buffer_id, |
44 uint64_t release_count) | 47 uint64_t release_count) |
45 : verified_flush_(false), | 48 : verified_flush_(false), |
46 namespace_id_(namespace_id), | 49 namespace_id_(namespace_id), |
| 50 extra_data_field_(extra_data_field), |
47 command_buffer_id_(command_buffer_id), | 51 command_buffer_id_(command_buffer_id), |
48 release_count_(release_count) {} | 52 release_count_(release_count) {} |
49 | 53 |
50 void Set(CommandBufferNamespace namespace_id, | 54 void Set(CommandBufferNamespace namespace_id, |
| 55 int32_t extra_data_field, |
51 uint64_t command_buffer_id, | 56 uint64_t command_buffer_id, |
52 uint64_t release_count) { | 57 uint64_t release_count) { |
53 namespace_id_ = namespace_id; | 58 namespace_id_ = namespace_id; |
| 59 extra_data_field_ = extra_data_field; |
54 command_buffer_id_ = command_buffer_id; | 60 command_buffer_id_ = command_buffer_id; |
55 release_count_ = release_count; | 61 release_count_ = release_count; |
56 } | 62 } |
57 | 63 |
58 void Clear() { | 64 void Clear() { |
59 verified_flush_ = false; | 65 verified_flush_ = false; |
60 namespace_id_ = CommandBufferNamespace::INVALID; | 66 namespace_id_ = CommandBufferNamespace::INVALID; |
| 67 extra_data_field_ = 0; |
61 command_buffer_id_ = 0; | 68 command_buffer_id_ = 0; |
62 release_count_ = 0; | 69 release_count_ = 0; |
63 } | 70 } |
64 | 71 |
65 void SetVerifyFlush() { | 72 void SetVerifyFlush() { |
66 verified_flush_ = true; | 73 verified_flush_ = true; |
67 } | 74 } |
68 | 75 |
69 bool HasData() const { | 76 bool HasData() const { |
70 return namespace_id_ != CommandBufferNamespace::INVALID; | 77 return namespace_id_ != CommandBufferNamespace::INVALID; |
71 } | 78 } |
72 | 79 |
73 int8_t* GetData() { return reinterpret_cast<int8_t*>(this); } | 80 int8_t* GetData() { return reinterpret_cast<int8_t*>(this); } |
74 | 81 |
75 const int8_t* GetConstData() const { | 82 const int8_t* GetConstData() const { |
76 return reinterpret_cast<const int8_t*>(this); | 83 return reinterpret_cast<const int8_t*>(this); |
77 } | 84 } |
78 | 85 |
79 bool verified_flush() const { return verified_flush_; } | 86 bool verified_flush() const { return verified_flush_; } |
80 CommandBufferNamespace namespace_id() const { return namespace_id_; } | 87 CommandBufferNamespace namespace_id() const { return namespace_id_; } |
81 uint64_t command_buffer_id() const { return command_buffer_id_; } | 88 uint64_t command_buffer_id() const { return command_buffer_id_; } |
82 uint64_t release_count() const { return release_count_; } | 89 uint64_t release_count() const { return release_count_; } |
83 | 90 |
| 91 // This extra data field can be used by command buffers to add extra |
| 92 // information to identify unverified sync tokens. The current purpose |
| 93 // of this field is only for unverified sync tokens which only exist within |
| 94 // the same process so this information will not survive cross-process IPCs. |
| 95 int32_t extra_data_field() const { return extra_data_field_; } |
| 96 |
84 bool operator<(const SyncToken& other) const { | 97 bool operator<(const SyncToken& other) const { |
85 // TODO(dyen): Once all our compilers support c++11, we can replace this | 98 // TODO(dyen): Once all our compilers support c++11, we can replace this |
86 // long list of comparisons with std::tie(). | 99 // long list of comparisons with std::tie(). |
87 return (namespace_id_ < other.namespace_id()) || | 100 return (namespace_id_ < other.namespace_id()) || |
88 ((namespace_id_ == other.namespace_id()) && | 101 ((namespace_id_ == other.namespace_id()) && |
89 ((command_buffer_id_ < other.command_buffer_id()) || | 102 ((command_buffer_id_ < other.command_buffer_id()) || |
90 ((command_buffer_id_ == other.command_buffer_id()) && | 103 ((command_buffer_id_ == other.command_buffer_id()) && |
91 (release_count_ < other.release_count())))); | 104 (release_count_ < other.release_count())))); |
92 } | 105 } |
93 | 106 |
94 bool operator==(const SyncToken& other) const { | 107 bool operator==(const SyncToken& other) const { |
95 return verified_flush_ == other.verified_flush() && | 108 return verified_flush_ == other.verified_flush() && |
96 namespace_id_ == other.namespace_id() && | 109 namespace_id_ == other.namespace_id() && |
| 110 extra_data_field_ == other.extra_data_field() && |
97 command_buffer_id_ == other.command_buffer_id() && | 111 command_buffer_id_ == other.command_buffer_id() && |
98 release_count_ == other.release_count(); | 112 release_count_ == other.release_count(); |
99 } | 113 } |
100 | 114 |
101 bool operator!=(const SyncToken& other) const { return !(*this == other); } | 115 bool operator!=(const SyncToken& other) const { return !(*this == other); } |
102 | 116 |
103 private: | 117 private: |
104 bool verified_flush_; | 118 bool verified_flush_; |
105 CommandBufferNamespace namespace_id_; | 119 CommandBufferNamespace namespace_id_; |
| 120 int32_t extra_data_field_; |
106 uint64_t command_buffer_id_; | 121 uint64_t command_buffer_id_; |
107 uint64_t release_count_; | 122 uint64_t release_count_; |
108 }; | 123 }; |
109 | 124 |
110 static_assert(sizeof(SyncToken) <= GL_SYNC_TOKEN_SIZE_CHROMIUM, | 125 static_assert(sizeof(SyncToken) <= GL_SYNC_TOKEN_SIZE_CHROMIUM, |
111 "SyncToken size must not exceed GL_SYNC_TOKEN_SIZE_CHROMIUM"); | 126 "SyncToken size must not exceed GL_SYNC_TOKEN_SIZE_CHROMIUM"); |
112 | 127 |
113 } // namespace gpu | 128 } // namespace gpu |
114 | 129 |
115 #endif // GPU_COMMAND_BUFFER_COMMON_SYNC_TOKEN_H_ | 130 #endif // GPU_COMMAND_BUFFER_COMMON_SYNC_TOKEN_H_ |
OLD | NEW |